OK, lets have a competition. Most complex PONG

Miscellaneous Forums/General Discussion/OK, lets have a competition. Most complex PONG

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

i call this "Pong1"! couldn't think of anything else. i have updated this to have proper serves. use up/down arrows and space. the game also now ends after first to 2 games. it's not very complex, but hmm, i'm working on it i guess. this is my first 2d game btw.

;Pong1, by markcw on 23/9/06

width=640
height=480

Graphics width,height,0,2
SetBuffer BackBuffer()

playery=height/2
cpuy=height/2

SeedRnd MilliSecs()

While Not KeyHit(1)
 Cls

 ;court line
 Rect width/2,0,1,height

 ;ball
 Oval ballx,bally,15,15

 If serve=0 Then ballx=60 : bally=playery+20
 If serve=2 Then ballx=width-60 : bally=cpuy+20

 ballx=ballx+ballxspd
 bally=bally+ballyspd
 If bally<0 Or bally>height-15 Then ballyspd=-ballyspd
 If ballyspd>8 Then ballyspd=8
 If ballyspd<-8 Then ballyspd=-8

 ;computer
 Rect width-50,cpuy,10,60

 If ballx>width-50 And ballx<width-40
  If bally>cpuy-8 And bally<cpuy+52
   ballxspd=-3 : ballyspd=ballyspd+(cpuyspd/2)
  EndIf
 EndIf

 If ballx>width/2
  If bally>cpuy+20 Then cpuyspd=4
  If bally<cpuy+20 Then cpuyspd=-4
  If Abs(cpuy+20-bally)<10 Then cpuyspd=cpuyspd/4
  If ballx>width-60 And Abs(ballyspd)<2 Then cpuyspd=2*(Rand(0,4)-2)
  If cpuy<0 Then cpuy=0
  If cpuy>height-60 Then cpuy=height-60
  cpuy=cpuy+cpuyspd
 Else
  If cpuy>height/2 Then cpuy=cpuy-2
  If cpuy<height/2 Then cpuy=cpuy+2
 EndIf

 If serve=2
  cpuyspd=2*(Rand(0,4)-2)
  serve=1 : ballxspd=-3 : ballyspd=ballyspd+(cpuyspd/2)
 EndIf

 ;player
 Rect 50,playery,10,60

 If ballx>50 And ballx<60
  If bally>playery-8 And bally<playery+52
   ballxspd=3 : ballyspd=ballyspd+(playeryspd/2)
  EndIf
 EndIf

 If KeyDown(200) Then playeryspd=-4 ;up key
 If KeyDown(208) Then playeryspd=4 ;down key
 If Not KeyDown(200) Or KeyDown(208) Then playeryspd=0
 If playery<0 Then playery=0
 If playery>height-60 Then playery=height-60
 playery=playery+playeryspd

 If serve=0 And KeyHit(57) ;space key
  serve=1 : ballxspd=3 : ballyspd=ballyspd+(playeryspd/2)
 EndIf

 ;points
 If nextpoint=0
  If ballx<0 Then cpupoint=cpupoint+1 : nextpoint=1
  If ballx>width Then playerpoint=playerpoint+1 : nextpoint=1
 EndIf
 If nextpoint>0 Then nextpoint=nextpoint+1
 If nextpoint>60
  nextpoint=0
  If cpupoint>10
   cpupoint=0 : playerpoint=0 : cpugame=cpugame+1
  EndIf
  If playerpoint>10
   cpupoint=0 : playerpoint=0 : playergame=playergame+1
  EndIf
  If cpupoint+playerpoint<5 Then serve=0 Else serve=2
  If cpupoint+playerpoint>9 Then serve=0
  ballxspd=0 : ballyspd=0
  If cpugame>1 Or playergame>1
   serve=3 : ballx=width/2-7 : bally=height/2-7
  EndIf
 EndIf

 If serve=3 And KeyDown(57) ;space key
  serve=0 : cpupoint=0 : cpugame=0 : playerpoint=0 : playergame=0
 EndIf

 Text width/2-140,0,"Player = "+playergame+" : "+playerpoint
 Text width/2+20,0,"Computer = "+cpugame+" : "+cpupoint
 If serve=3 Then Text width/2-40,40,"GAME  OVER"

 Flip
Wend