Pong Game
Compressed
R: :sync on :sync rate 60 :X1=320:X2=320:X#=320:Y#=240:XS#=0:YS#=2 :do :cls :if rightkey():inc X1,5 :endif :if leftkey() :dec X1,5 :endif :if X#>X2 :inc X2,5 :endif
if X#<X2 : dec X2,5 : endif : if X1>600 : X1=600 : endif : if X1<40 : X1=40 : endif : if X2>600 : X2=600 : endif : if X2<40 : X2=40 : endif : inc X#,XS# : inc Y#,YS#
if X#<=20 : XS#=-XS# : endif : if X#>=620 : XS#=-XS# : endif : if X#>=X1-30 and X#<=X1+30 and Y#>=445 and Y#<=455 : B=1 : endif
if X#>=X2-30 and X#<=X2+30 and Y#>=25 and Y#<=35 : B=1 : endif : if B=1 : inc XS#,(rnd(20)-10.0)/10.0 : YS#=-YS# : if YS#>0 : inc YS#,rnd(10)/50.0 : endif
if YS#<0:dec YS#,rnd(10)/50.0 :endif :if YS#>9:YS#=9:endif :if YS#<-9:YS#=-9:endif :B=0 :endif :print "Player Score: ";S;" Com Score: ";C :if Y#>480 :inc C,1 :endif
if Y#<0 : inc S,1 : endif : if Y#<0 or Y#>480 : goto R : endif : box X#-3,Y#-3,X#+3,Y#+3 : box X1-30,445,X1+30,455 : box X2-30,25,X2+30,35 : sync : loop
Uncompressed
sync on : sync rate 60 `Syncronize the game to 60 frames per second
Reset:
PX1 = 320 : PX2 = 320 `Centers the player and the computer
PX# = 320 : PY# = 240 `Centers the ball
XS# = 0 : YS# = 2 `Ball starting speed
do `The Game Play Loop
cls `Clears the screen
if rightkey() then inc PX1,5 `The Players controls
if leftkey() then dec PX1,5
if PX# > PX2 then inc PX2,5 `The Computers AI
if PX# < PX2 then dec PX2,5
if PX1 > 600 then PX1 = 600 `The Players X boundries
if PX1 < 40 then PX1 = 40
if PX2 > 600 then PX2 = 600 `The Computers X boundries
if PX2 < 40 then PX2 = 40
inc PX#,XS# : inc PY#,YS# `Move the ball
if PX# <= 20 then XS# = -XS# `Bounce the ball off of the walls
if PX# >= 620 then XS# = -XS#
`Detect collision with the ball and the player/computer
if PX# >= PX1-30 and PX# <= PX1+30 and PY# >= 445 and PY# <= 455 then Bounce = 1
if PX# >= PX2-30 and PX# <= PX2+30 and PY# >= 25 and PY# <= 35 then Bounce = 1
if Bounce = 1 `Bounce the ball off of the player/computer
inc XS#,(rnd(20)-10.0)/10.0 `Randomizes an increase/decrease of the x-speed
YS# = -YS# `Bounces the ball
if YS# > 0 then inc YS#,rnd(10)/50.0 `increases the y-speed of the ball
if YS# < 0 then dec YS#,rnd(10)/50.0 `increases the y-speed of the ball when it is moving up
if YS# > 9 then YS# = 9 `maximum y-speed
if YS# <-9 then YS# =-9 `minimum y-speed
Bounce = 0 `All done bouncing
endif
print "Player Score: ";PScore;" Com Score: ";CScore `Displays the scores
if PY# > 480 then inc CScore,1 `The computer got a goal
if PY# < 0 then inc PScore,1 `The player got a goal
if PY# < 0 or PY# > 480 then goto reset `Resets the positions of the players and the ball
box PX#-3,PY#-3,PX#+3,PY#+3 `draw the ball
box PX1-30,445,PX1+30,455 `draw the player
box PX2-30,25,PX2+30,35 `draw the computer
sync `Syncronize the game
loop `End of the main loop
I like games, and stuff.