Made in Dbc
Hi again. This is my new thread about my breakout game. Now that the code actually works i won't be posting in the one that says "breakout won't get started" well because it is. Thanks to X_MEN and Darkcoder#5 for helping me so far. I changed the name to breakers by the way.
Bugs
1. Ball can go through the two blocks on left side if you do it right
Improvments
1. Put in the stupid bitmap fonts
2. try to make the ball correctly bounce off the side(right now it just bounces up or down)
3. Make level 3
4. Put in music and sound effects
Controls:
left and right arrow keys to move paddle
space to start next ball(you have 5 balls)
1 to restart when you die and 2 to exit when you die
Updated Code:
rem breaker!!!!
rem print stuff
hide mouse
set text font "arial"
set text size 15
ink rgb(0,255,0),rgb(0,0,0)
Text 200,200,"Welcome to Breaker by Cagel"
Text 200,230,"Left and right key moves"
Text 200,250,"Press space for next life"
Text 200,270,"Press any key to start"
Suspend for key
rem some stuff
sync on
game:
backdrop on
rem some variables
balla#=170
x=0
lives#=5
score#=0
ballx# = 0
ballz# = 0
pad# = 0
rem clear the screen
cls
rem make first,second, and third rows/ position them
for t = 1 to 10
if object exist(t) = 1 then delete object t
make object cube t,1
color object t,rgb(255,0,0)
make object collision box t,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object t,(t*1.1)-6,0,5
next t
for x = 11 to 20
if object exist(x) = 1 then delete object x
make object cube x,1
color object x,rgb(0,152,255)
make object collision box x,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object x,(x*1.1)-17,0,3.9
next x
for g = 41 to 45
if object exist(g) = 1 then delete object g
make object box g,2,1,1
color object g,rgb(255,115,70)
make object collision box g,-1,-0.5,-0.5,0.5,0.5,0.5,1
position object g,(g*2.2)-94.5,0,6.1
next g
rem make the paddle
if object exist(21) = 1 then delete object 21
make object box 21,2.5,1,0.3
make object collision box 21,-1.25,-0.5,-0.15,1.25,0.5,0.15,1
color object 21,rgb(0,255,0)
rem make the ball
gosub make_ball
make object collision box 22,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
rem make the side boxes, position them
if object exist(23) = 1 then delete object 23
make object box 23,1,1,15
color object 23,rgb(50,50,50)
position object 23,-6,0,1
if object exist(24) = 1 then delete object 24
make object box 24,1,1,15
color object 24,rgb(50,50,50)
position object 24,6.1,0,1
rem make top box
if object exist(25) = 1 then delete object 25
make object box 25,13.1,1,1
color object 25,rgb(50,50,50)
position object 25,0.05,0,9
rem make lives boxes
for z = 31 to 35
if object exist(z) = 1 then delete object z
make object cube z,1
color object z,rgb(150,0,150)
position object z,8,0,((z-30)*1.1) 1
next z
rem camera position
position camera 0,15,-5:point camera 0,0,0
wait 1000
do
rem pad movement and changing ball angle
if rightkey()=1 and pad#<4 then pad#=pad#+0.5
if leftkey()=1 and pad#>-4 then pad#=pad#-0.5
if rightkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#+8
if leftkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#-8
rem get the ball moving
ballx#=newxvalue(ballx#,balla#,0.3)
ballz#=newzvalue(ballz#,balla#,0.3)
rem bounce off paddle
if ballz#<-4 and ballz#>-4.2 and ABS(pad#-ballx#)<1.5 then balla#=180-balla#
rem bounce off walls and top
if ballx#<-5 or ballx#>5 then balla#=360-balla#
if ballz#>8 then balla#=180-balla#
balla#=wrapvalue(balla#)
rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#
rem position paddle
position object 21,pad#,0,-4.7
rem return the ball to the middle and delete a life
`if ballz#<-5.5
`gosub death
`endif
if ballz#<-5.5:gosub death
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=0 and object exist(35)=1 then delete object 35
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=1 then delete object 34
if object exist(31)=0 and object exist(32)=0 and object exist(33)=1 then delete object 33
if object exist(31)=0 and object exist(32)=1 then delete object 32
if object exist(31)=1 then delete object 31
endif
objcol=object hit(22,0)
rem collision
if objcol>0 and objcol<21 or objcol>39 and objcol<46 then delete object objcol:balla#=180-balla#:score#=score#+10
rem game ending
if lives#=0 then gosub gameover
if score#=250 then gosub win
sync
loop
make_ball:
if object exist(22) = 1 then delete object 22
make object sphere 22,1
color object 22,rgb(150,150,150)
return
death:
backdrop off
text 200,200,"Press space to restart!"
suspend for key
ballx# = 0
ballz# = 0
balla# = 170
pad# = 0
lives# = lives#-1
sync on
backdrop on
return
gameover:
backdrop off
cls
print "you lose!"
gosub restart
win:
backdrop off
cls
print "you win!"
gosub restart
restart:
print "press 1 to restart or 2 to exit":input overornot#
if overornot# = 1 then gosub Game
if overornot# = 2 then end
code with level 1 and 2 (buggy):
rem breaker!!!!
rem print stuff
hide mouse
set text font "arial"
set text size 15
ink rgb(0,255,0),rgb(0,0,0)
Text 200,200,"Welcome to Breaker by Cagel"
Text 200,230,"Left and right key moves"
Text 200,250,"Press space for next life"
Text 200,270,"Press any key to start"
Suspend for key
rem some stuff
sync on
game:
backdrop on
rem some variables
balla#=170
x=0
lives#=5
score#=0
ballx# = 0
ballz# = 0
pad# = 0
rem clear the screen
cls
rem make first,second, and third rows/ position them
for t = 1 to 10
if object exist(t) = 1 then delete object t
make object cube t,1
color object t,rgb(255,0,0)
make object collision box t,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object t,(t*1.1)-6,0,5
next t
for x = 11 to 20
if object exist(x) = 1 then delete object x
make object cube x,1
color object x,rgb(0,152,255)
make object collision box x,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object x,(x*1.1)-17,0,3.9
next x
for g = 41 to 45
if object exist(g) = 1 then delete object g
make object box g,2,1,1
color object g,rgb(255,115,70)
make object collision box g,-1,-0.5,-0.5,0.5,0.5,0.5,1
position object g,(g*2.2)-94.5,0,6.1
next g
rem make the paddle
if object exist(21) = 1 then delete object 21
make object box 21,2.5,1,0.3
make object collision box 21,-1.25,-0.5,-0.15,1.25,0.5,0.15,1
color object 21,rgb(0,255,0)
rem make the ball
gosub make_ball
make object collision box 22,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
rem make grid
if object exist(26) = 1 then delete object 26
make object box 26,17,0.1,20
color object 26,rgb(100,100,100)
position object 26,0,-3,3
rem make the side boxes, position them
if object exist(23) = 1 then delete object 23
make object box 23,1,1,15
color object 23,rgb(50,50,50)
position object 23,-6,0,1
if object exist(24) = 1 then delete object 24
make object box 24,1,1,15
color object 24,rgb(50,50,50)
position object 24,6.1,0,1
rem make top box
if object exist(25) = 1 then delete object 25
make object box 25,13.1,1,1
color object 25,rgb(50,50,50)
position object 25,0.05,0,9
rem make lives boxes
for z = 31 to 35
if object exist(z) = 1 then delete object z
make object cube z,1
color object z,rgb(150,0,150)
position object z,8,0,((z-30)*1.1) 1
next z
rem camera position
position camera 0,15,-5:point camera 0,0,0
wait 1000
do
rem pad movement and changing ball angle
if rightkey()=1 and pad#<4 then pad#=pad#+0.5
if leftkey()=1 and pad#>-4 then pad#=pad#-0.5
if rightkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#+8
if leftkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#-8
rem get the ball moving
ballx#=newxvalue(ballx#,balla#,0.3)
ballz#=newzvalue(ballz#,balla#,0.3)
rem bounce off paddle
if ballz#<-4 and ballz#>-4.2 and ABS(pad#-ballx#)<1.5 then balla#=180-balla#
rem bounce off walls and top
if ballx#<-5 or ballx#>5 then balla#=360-balla#
if ballz#>8 then balla#=180-balla#
balla#=wrapvalue(balla#)
rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#
rem position paddle
position object 21,pad#,0,-4.7
rem restore ball position and delete a life
if ballz#<-5.5:gosub death
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=0 and object exist(35)=1 then delete object 35
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=1 then delete object 34
if object exist(31)=0 and object exist(32)=0 and object exist(33)=1 then delete object 33
if object exist(31)=0 and object exist(32)=1 then delete object 32
if object exist(31)=1 then delete object 31
endif
objcol=object hit(22,0)
rem collision
if objcol>0 and objcol<21 or objcol>39 and objcol<46 then delete object objcol:balla#=180-balla#:score#=score#+10
rem game ending
if lives#=0 then gosub gameover
if score#=250 then gosub win
sync
loop
make_ball:
if object exist(22) = 1 then delete object 22
make object sphere 22,1
color object 22,rgb(150,150,150)
return
death:
backdrop off
text 200,200,"Press space to restart!"
suspend for key
ballx# = 0
ballz# = 0
balla# = 170
pad# = 0
lives# = lives#-1
sync on
backdrop on
return
gameover:
backdrop off
cls
print "you lose!"
gosub restart
win:
backdrop off
cls
print "you beat level 1!"
print "loading level 2"
wait 1000
gosub game2
win2:
backdrop off
cls
print "you win!"
gosub restart
restart:
print "press 1 to restart or 2 to exit":input overornot#
if overornot# = 1 then gosub Game
if overornot# = 2 then end
game2:
backdrop on
rem some variables
balla#=170
x=0
ballx# = 0
ballz# = 0
pad# = 0
rem clear the screen
cls
rem make first,second,third, and fourth rows/ position them
for t = 1 to 6
if object exist(t) = 1 then delete object t
make object cube t,1
color object t,rgb(255,0,0)
make object collision box t,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object t,(t*1.95)-6.75,0,7
next t
for x = 7 to 11
if object exist(x) = 1 then delete object x
make object cube x,1
color object x,rgb(0,255,0)
make object collision box x,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object x,(x*1.95)-17.5,0,5.9
next t
for l = 12 to 17
if object exist(l) = 1 then delete object l
make object cube l,1
color object l,rgb(0,0,255)
make object collision box l,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object l,(l*1.95)-28.25,0,4.8
next l
for b = 41 to 45
if object exist(b) = 1 then delete object b
make object cube b,1
color object b,rgb(255,255,0)
make object collision box b,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object b,(b*1.95)-83.85,0,3.7
next b
rem camera position
position camera 0,15,-5:point camera 0,0,0
wait 1000
do
rem pad movement and changing ball angle
if rightkey()=1 and pad#<4 then pad#=pad#+0.5
if leftkey()=1 and pad#>-4 then pad#=pad#-0.5
if rightkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#+8
if leftkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#-8
rem get the ball moving
ballx#=newxvalue(ballx#,balla#,0.3)
ballz#=newzvalue(ballz#,balla#,0.3)
rem bounce off paddle
if ballz#<-4 and ballz#>-4.2 and ABS(pad#-ballx#)<1.5 then balla#=180-balla#
rem bounce off walls and top
if ballx#<-5 or ballx#>5 then balla#=360-balla#
if ballz#>8 then balla#=180-balla#
balla#=wrapvalue(balla#)
rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#
rem position paddle
position object 21,pad#,0,-4.7
rem restore ball position and delete a life
if ballz#<-5.5:gosub death
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=0 and object exist(35)=1 then delete object 35
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=1 then delete object 34
if object exist(31)=0 and object exist(32)=0 and object exist(33)=1 then delete object 33
if object exist(31)=0 and object exist(32)=1 then delete object 32
if object exist(31)=1 then delete object 31
endif
rem collision
objcol=object hit(22,0)
if objcol>0 and objcol<18 or objcol>40 and objcol<46 then delete object objcol:balla#=180-balla#:score#=score#+10
rem game ending
if lives#=0 then gosub gameover
if score#=430 then gosub win2
rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#
rem position paddle
position object 21,pad#,0,-4.7
sync
loop