Home
Products
Community
Manuals
Contact
Login or Signup

Code archives/Graphics/Simplest bullet code in the world

This code has been declared by its author to be Public Domain code.

Download source code

Simplest bullet code in the world by Rob(Posted 1+ years ago)
Good reading for beginners needing a simple method to keep track of things, and as an introduction to types.
;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
	b\x=x
	b\y=y
End Function

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

Comments

None.

Code Archives Forum