[bb] Simplest bullet code in the world by Rob [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

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) Select
;very simple bullet shooter code (rob@redflame.net)

Graphics 640,480,16,2
SetBuffer BackBuffer()
HidePointer()

; for the bullets
Type bullet
Field x,y
End Type

playerx=320
playery=240

While Not KeyHit(1)
Cls

playerx=MouseX()
playery=MouseY()

If MouseHit(1) Then fire_bullet(playerx,playery) ; needs an x and y pos to start from

Oval playerx,playery,8,8 ; draw the player

update_all_bullets() ; process bullets that have been created with fire_bullet

Flip
Wend
End

Function fire_bullet(x,y)
b.bullet=New bullet
bx=x
by=y
End Function

Function update_all_bullets()
For b.bullet=Each bullet
If bx>640
Delete b
Else
bx=bx+4
Plot bx,by
EndIf
Next
End Function


Comments : none...