REM Project: Breakout
REM Created: 04/02/2008 08:53:27
REM
REM ***** Main Source File *****
REM
`Setup the display
flush video memory
sync on : sync rate 60
set display mode 1024,768,32
color backdrop rgb(0,200,0)
GameStart:
sync
center text screen width()*.5,screen height()*.5,"Press any key to begin"
sync
wait key
rows=4
columns=14
global totalobjects
totalobjects =(rows*columns)+rows
global x as integer
modify=0
modifier=0
for x = 1 to totalobjects
make object cube x,1
color object x,rgb(0,0,230)
position object x,modify-(columns*.5),modifier+rows-1.5,8
modify=modify+1
if modify>columns
modify=0
modifier=modifier-1
endif
next x
global paddle=1025
global ball=1026
make object cube paddle,1
scale object paddle,250,50,100
position object paddle,0,-6,8
make object sphere ball,0.5
position object ball,0,-4,8
color object paddle,rgb(0,0,230)
color object ball,rgb(230,0,0)
global balls = 3
for x = 1 to totalobjects
set object collision on x
set object collision to boxes x
next x
set object collision on ball
set object collision to spheres ball
global score=0
global direction$="down"
global angle$="none"
global ballspeed#=0.15
global paddlespeed#=0.2
hide mouse
set text size 30
ink rgb(0,0,0),1
do
disp_scoreandballs()
paddlemove()
ballmove()
collision()
winofgame()
lossofball()
lossofgame()
newgame()
sync
loop
function disp_scoreandballs()
center text screen width()*.5,screen height()-40,str$(score)
center text screen width()*.1,screen height()-40,str$(balls)
endfunction
function paddlemove()
if leftkey()=1 then move object left paddle,paddlespeed#
if rightkey()=1 then move object right paddle,paddlespeed#
rem position object paddle,mousex()/70-7,-6,8
endfunction
function ballmove()
if direction$="down"
move object down (ball),ballspeed#
endif
if direction$="up"
move object up (ball),ballspeed#
endif
if angle$="left"
move object left ball,ballspeed#*.5
endif
if angle$="right"
move object right ball,ballspeed#*.5
endif
endfunction
function collision()
if object collision(paddle,ball)=1
if direction$="up" then direction$="down"
if direction$="down" then direction$="up"
if object position x(paddle)>object position x(ball)
angle$="left"
endif
if object position x(paddle)<object position x(ball)
angle$="right"
endif
if object position x(paddle)=object position x(ball)
angle$="none"
endif
endif
x as integer
for x = 1 to totalobjects
if object exist(x)
if object collision(x,ball)=1
delete object x
score=score+1
if direction$="down" then direction$="up"
if direction$="up" then direction$="down"
endif
endif
next x
if object position x(paddle)>7 then move object left paddle , paddlespeed#
if object position x(paddle)<-7 then move object right paddle , paddlespeed#
if object position x(ball)>7 and direction$="up"
angle$="left"
endif
if object position x(ball)<-7 and direction$="up"
angle$="right"
endif
if object position x(ball)>7 and direction$="down"
angle$="left"
endif
if object position x(ball)<-7 and direction$="down"
angle$="right"
endif
if object position y(ball)>5 then direction$="down"
endfunction
function winofgame()
if score=totalobjects
delete object paddle
delete object ball
goto GameStart
endif
endfunction
function lossofball()
if object position y(ball)<-7 and balls > 0
position object ball,0,-4,8
if direction$="up" then direction$="down"
if direction$="down" then direction$="up"
balls = balls-1
endif
endfunction
function lossofgame()
x as integer
if object position y(ball)<-7 and balls = 0
for x = 1 to ball
if object exist(x) then delete object x
next x
goto gamestart
endif
endfunction
function newgame()
x as integer
if spacekey()=1
for x = 1 to ball
if object exist(x) then delete object x
next x
goto gamestart
endif
endfunction
function highscorestable()
endfunction
1)sync on turns on manually sync, so I added 'sync' to your main loop
2)I declared x as an integer in your functions before you tried to loop with it
3)when you win, it now properly deletes all remaining objects (ball & paddle)
4)I commented out the mouse control because it was screwing with the starting position of the paddle
5)I split the total object declaration into two pieces so it gets assigned properly
It should work now, but the bouncing isn't quite right
@Invader Awesome
Just wondering, what makes you think he stole the code, not saying that he didn't, just asking
And just wondering in a slightly less nice way, what gives you the right to put
Quote: ""Valera Is Gay""
in your sig?