March 01, 2021, 10:57:19 PM

Author Topic: [bb] Pong by Jonathan Nguyen [ 1+ years ago ]  (Read 418 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Pong by Jonathan Nguyen [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Pong
Author : Jonathan Nguyen
Posted : 1+ years ago

Description : Badly commented, had trouble figuring out all the variables myself when I looked at it again. Might interest a few.

Code :
Code: BlitzBasic
  1. ; Setup
  2. Graphics 320,240,16,0
  3. SeedRnd MilliSecs()
  4. Print "Pong by Jonathan Nguyen"
  5. Print "Difficulty (0.0 hardest, 1.0+ easiest)"
  6. difficulty#=Float#(Input("  ")) ;difficulty#=0.0 ; DIFFICULTY: 0.0 being the hardest, 1.0+ being the easiest
  7. Print "Sensitivity (default 100[%])"
  8. sensitivity#=Float#(Input("  "))/100.0
  9. ; Initiate
  10. hold=1 : sync=CreateTimer(60)
  11. SetBuffer BackBuffer()
  12. FlushMouse
  13. ; Program Loop
  14. While Not KeyDown(1)=True
  15.         WaitTimer sync
  16.         Cls : Color 96,96,96 : Line 160,0,160,240
  17.         Text 160-2-StringWidth(Str$(playerscore)),228,Str$(playerscore) : Text 160+2,228,Str$(computerscore)
  18.         Color 255,255,255
  19.         paddlespeed#=MouseYSpeed()*sensitivity# : playery#=playery#+paddlespeed#
  20.         If playery#<24 Then playery#=24
  21.         If playery#>216 Then playery#=216
  22.         Rect 4,playery#-24,8,48
  23.         If hold=-1 Then computerai#=computerai#-1 : compspeed#=Cos(computerai#*8+30)*12/(difficulty#*2+1.0) Else compspeed#=(bally#-computery#)/Rnd(8.0,64.0)/((320.0+difficulty#*100-ballx#)/320.0)
  24.         If compspeed#>30 Then compspeed#=30
  25.         If compspeed#<-30 Then compspeed#=-30
  26.         computery#=computery#+compspeed#
  27.         If computery#<24 Then computery#=24
  28.         If computery#>216 Then computery#=216
  29.         Rect 308,computery#-24,8,48
  30.         ; State
  31.         Select hold
  32.                 Case 1
  33.                         ballx#=22
  34.                         bally#=playery#
  35.                         If MouseHit(1)=True Then ballxv#=8 : ballyv#=paddlespeed# : hold=0
  36.                 Case 0
  37.                         ballx#=ballx#+ballxv# : bally#=bally#+ballyv#
  38.                         If bally#<8 Then bally#=8 : ballyv#=ballyv#*-1.0
  39.                         If bally#>232 Then bally#=232 : ballyv#=ballyv#*-1.0
  40.                         If bally#=>playery#-30 And bally#=<playery#+30 And ballx#<28 Then ballx#=28 : ballxv#=ballxv#*-1.025 : ballyv#=(ballyv#+paddlespeed#)*0.5+Rnd(-0.5,0.5)
  41.                         If bally#=>computery#-30 And bally#=<computery#+30 And ballx#>292 Then ballx#=292 : ballxv#=ballxv#*-1.025 : ballyv#=(ballyv#+compspeed#)*0.5+Rnd(-0.5,0.5)
  42.                         If ballx#=<0 Then computerscore=computerscore+1 : difficulty#=difficulty#+0.05 : totdifficulty#=totdifficulty#+difficulty# : hold=1
  43.                         If ballx#=>320 Then playerscore=playerscore+1 : difficulty#=difficulty#-0.05 : totdifficulty#=totdifficulty#+difficulty# : hold=-1 : computerai#=Rnd(120,240)
  44.                         If difficulty#<0 Then difficulty#=0
  45.                 Case -1
  46.                         ballx#=292
  47.                         bally#=computery#
  48.                         If computerai#=<0 Then ballxv#=8 : ballyv#=compspeed# : hold=0
  49.         End Select
  50.         Text 0,0,difficulty#
  51.         Oval ballx#-8,bally#-8,16,16 : Flip
  52. Wend
  53. ; Results
  54. FlushKeys
  55. avgdifficulty#=totdifficulty#/Float#(computerscore+playerscore)
  56. SetBuffer FrontBuffer() : Text 160,96,"Average Difficulty",True : Text 160,108,Str$(avgdifficulty#),True : Text 160,132,"Press any key...",True : WaitKey


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal