home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 60 / supercd60_2.iso / BlitzBasic / Blitz2DPCP / data1.cab / Support / help / samples / solotennis.bb < prev    next >
Encoding:
Text File  |  2001-11-21  |  2.7 KB  |  98 lines

  1. ; Solo Tennis by Simon Harrison (si@si-design.co.uk)
  2.  
  3. ; Set display mode values
  4. Const width=640,height=480
  5.  
  6. ; Set display mode
  7. Graphics width,height
  8.  
  9. ; Draw to back buffer
  10. SetBuffer BackBuffer()
  11.  
  12. ; Load bat and ball images
  13. bat1=LoadImage("graphics/bat.bmp")
  14. bat2=CopyImage(bat1)
  15. ball=LoadImage("graphics/ball.bmp")
  16.  
  17. ; Load beep sounds
  18. beep1=LoadSound("sounds/beep.wav")
  19. beep2=LoadSound("sounds/beeplow.wav")
  20.  
  21. ; Load high score data
  22. load=ReadFile("sthighscore")
  23. high=ReadLine(load)
  24.  
  25. ; Set font to arial size 32
  26. font=LoadFont("arial",32)
  27. SetFont font
  28.  
  29. ; Set text colour to green
  30. Color 0,255,0 
  31.  
  32. ; Set initial ball position and movement values
  33. ballx#=width/2
  34. bally#=height/2
  35. ballmovx#=2
  36. ballmovy#=2
  37.  
  38. ; Set initial game values
  39. once=2
  40. score=0
  41.  
  42. ; Repeat following loop until escape key is pressed
  43. While Not KeyDown(1)
  44.  
  45. ; Clear screen
  46. Cls
  47.  
  48. ; Print current score to screen
  49. Text width/2,0,score,1
  50.  
  51. ; Print high score to screen
  52. Text width/2,height-32,"High: "+high,1
  53.  
  54. ; Get position of bats
  55. batx1=0
  56. batx2=width-16
  57. baty1=MouseY()
  58. baty2=height-MouseY()-64
  59.  
  60. ; Update ball position values
  61. ballx#=ballx#+ballmovx#
  62. bally#=bally#+ballmovy#
  63.  
  64. ; If ball image collides with either bat image then alter x ball movement value and play beep sound
  65. If once=1 And ImagesCollide(ball,ballx#,bally#,0,bat1,batx1,baty1,0) Then ballmovx#=Rnd(1,10) : PlaySound beep1 : score=score+1 : once=2  
  66. If once=2 And ImagesCollide(ball,ballx#,bally#,0,bat2,batx2,baty2,0) Then ballmovx#=Rnd(1,10)*-1 : PlaySound beep1 : score=score+1 : once=1
  67.  
  68. ; If ball touches top or bottom of screen then alter y ball movement value
  69. If bally#>height-16 Then ballmovy#=Rnd(1,10)*-1 : PlaySound beep2
  70. If bally#<0 Then ballmovy#=Rnd(1,10) : PlaySound beep2
  71.  
  72. ; If bats touch top or bottom of screen then prevent them from going outside of screen
  73. If baty1<0 Then baty1=0
  74. If baty2<0 Then baty2=0
  75. If baty1>height-64 Then baty1=height-64
  76. If baty2>height-64 Then baty2=height-64
  77.  
  78. ; If ball touches left side of screen then save high score if necessary, reset ball and score values
  79. If ballx#<0
  80. If score>high Then high=score : save=WriteFile("sthighscore") : WriteLine save,high : CloseFile save
  81. ballx#=width/2 : bally#=height/2 : ballmovx#=1 : ballmovy#=1 : once=2 : score=0
  82. EndIf
  83.  
  84. ; If ball touches right side of screen then save high score if necessary, reset ball and score values
  85. If ballx#>width-16
  86. If score>high Then high=score : save=WriteFile("sthighscore") : WriteLine save,high : CloseFile save
  87. ballx#=width/2 : bally#=height/2 : ballmovx#=1 : ballmovy#=1 : once=2 : score=0
  88. EndIf
  89.  
  90. ; Draw bat and ball images to screen
  91. DrawImage bat1,batx1,baty1
  92. DrawImage bat2,batx2,baty2
  93. DrawImage ball,ballx#,bally#
  94.  
  95. ; Flip screen buffers
  96. Flip
  97.  
  98. Wend