November 25, 2020, 06:16:41 AM

Author Topic: [bb] Simplest bullet code in the world by Rob [ 1+ years ago ]  (Read 752 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Simplest bullet code in the world
Author : Rob
Posted : 1+ years ago

Description : Good reading for beginners needing a simple method to keep track of things, and as an introduction to types.

Code :
Code: BlitzBasic
  1. ;very simple bullet shooter code (rob@redflame.net)
  2.  
  3. Graphics 640,480,16,2
  4. SetBuffer BackBuffer()
  5. HidePointer()
  6.  
  7. ; for the bullets
  8. Type bullet
  9.         Field x,y
  10. End Type
  11.  
  12. playerx=320
  13. playery=240
  14.  
  15. While Not KeyHit(1)
  16.         Cls
  17.  
  18.         playerx=MouseX()
  19.         playery=MouseY()
  20.        
  21.         If MouseHit(1) Then fire_bullet(playerx,playery) ; needs an x and y pos to start from
  22.        
  23.         Oval playerx,playery,8,8 ; draw the player
  24.        
  25.         update_all_bullets() ; process bullets that have been created with fire_bullet
  26.  
  27.         Flip
  28. Wend
  29. End
  30.  
  31. Function fire_bullet(x,y)
  32.         b.bullet=New bullet
  33.         bx=x
  34.         by=y
  35. End Function
  36.  
  37. Function update_all_bullets()
  38.         For b.bullet=Each bullet
  39.                 If bx>640
  40.                         Delete b
  41.                 Else
  42.                         bx=bx+4
  43.                         Plot bx,by
  44.                 EndIf
  45.         Next
  46. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal