Updated my
breakout game. Enjoy!
Edit- Code for whoever is interested:
rem First - Project created 2012/09/12
setDisplayAspect(-1)
type block
x#
y#
id
a
r
b
g
endtype
type tBall
x#
y#
xs#
ys#
id
endtype
global count = 0
global score = 0
dim b[9,6] as block
global p as block
global ball as tBall
setup()
do
Print ( "SCORE: " + str(score) )
game()
Sync()
loop
function setup()
// blocks
ox# = 75
oy# = 75
for n = 1 to 9
for o = 1 to 6
b[n,o].id = createObjectBox(10,5,5)
setObjectPosition(b[n,o].id, n*15-ox#, o*10-oy#, 160)
setObjectColor(b[n,o].id, n*30, 0, o*30, 255)
b[n,o].a = 255
b[n,o].r = n*30
b[n,o].g = 0
b[n,o].b = o*30
b[n,o].x# = n*15-ox#
b[n,o].y# = o*10-oy#
next o
next n
// paddle
p.id = createObjectBox(30, 5, 12)
setObjectColor(p.id, 0, 255, 0, 255)
p.x# = 0
p.y# = -170
setObjectPosition(p.id, p.x#, p.y#, 160)
// ball
ball.id = createObjectSphere(10,12, 12)
ball.x# = 0
ball.y# = -150
ball.xs# = 1
ball.ys# = 1
setObjectColor(ball.id, 255, 255, 0, 255)
setObjectPosition(ball.id, ball.x#, ball.y#, 160)
endfunction
function game()
for n = 1 to 9
for o = 1 to 6
if b[n,o].a > 0
if ball.x# > b[n,o].x#-7 and ball.x# < b[n,o].x# + 7
if ball.y# > b[n,o].y#-3 and ball.y# < b[n,o].y# + 3
b[n,o].a = 0
setObjectColor(b[n,o].id, 0, 0, 0, 0)
setObjectPosition(b[n,o].id, b[n,o].x#, b[n,o].y#, 200)
ball.ys# = ball.ys# *-1
inc count
inc score
endif
endif
endif
next o
next n
if count >= 54
reset()
count = 0
endif
if ball.x# > p.x#-20 and ball.x# < p.x# + 40
if ball.y# < p.y# and ball.y# > p.y# - 10
ball.ys# = ball.ys# *-1
ball.xs# = (ball.x#-p.x#)/6.0
endif
endif
// bounds
if ball.x# < -65 or ball.x# > 65 then ball.xs# = ball.xs# *-1
if ball.y# > 0 then ball.ys# = ball.ys# *-1
if ball.y# < -200
ball.x# = 0
ball.y# = -150
ball.xs# = 1
ball.ys# = 1
endif
// paddle
if getRawKeyState(37) then p.x# = p.x# - 4
if getRawKeyState(39) then p.x# = p.x# + 4
if p.x# < -70 then p.x# = -70
if p.x# > 70 then p.x# = 70
ball.x# = ball.x# + ball.xs#
ball.y# = ball.y# + ball.ys#
// position objects
setObjectPosition(ball.id, ball.x#, ball.y#, 160)
setObjectPosition(p.id, p.x#, p.y#, 160)
endfunction
function reset()
for n = 1 to 9
for o = 1 to 6
b[n,o].a = 255
temp = b[n,o].r
b[n,o].r = b[n,o].b
b[n,o].b = b[n,o].g
b[n,o].g = temp
setObjectColor(b[n,o].id, b[n,o].r, b[n,o].g, b[n,o].b, 255)
setObjectPosition(b[n,o].id, b[n,o].x#, b[n,o].y#, 160)
next o
next n
endfunction