Bullet Tracking

Advanced game related topics
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tron.

Do any of you game programmers have some example code for bullet tracking? I am working on a space invaders type of game, but I can only shoot and track one bullet/keypress on the screen at a time. I know it's a strange request, but here is an example of my code:

#NUM_SHOTS = 6

Structure Shot
x.l
y.l
frame.l[1]
currframe.l
xspeed.l
yspeed.l
direction.l
visible.l
EndStructure

Dim Ship.Shot(#NUM_SHOTS)

Declare Shot_Init()
Declare Game_Run()
Declare Move_Ship(key)
Declare Display_Ship()
Declare Display_Shots()

Procedure Shot_Init()
for count = 1 to #NUM_SHOTS
Ship.Shot(count)\xspeed = 10
Ship.Shot(count)\yspeed = 10
Ship.Shot(count)\visible = 0
EndProcedure

Procedure Game_Run()
While quitgame = 0
Start_Clock() ;custom function that uses the API - you can remove
FlipBuffers()
ClearScreen(0,0,0)
DisplaySprite(background, 0, 0) ;just a backgroup bmp image
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
quitgame = 1
Delay(200)
EndIf
If KeyboardPushed(#PB_Key_Left):KEYPRESS=1:EndIf
If KeyboardPushed(#PB_Key_Right):KEYPRESS=2:EndIf
If KeyboardPushed(#PB_Key_Up):KEYPRESS=3:EndIf
If KeyboardPushed(#PB_Key_Down):KEYPRESS=4:EndIf
If KeyboardPushed(#PB_Key_LeftControl):KEYPRESS=5:EndIf
Move_Ship(KEYPRESS) ;sets a FIRING variable = 1 if the leftctrl pushed
Display_Ship() ;displays my ship on the screen
Display_Shots() ;displays my shots on the screen if FIRING = 1
Wait_Clock(33) ;you can remove
Wend
EndProcedure

;Main
Shot_Init()
Game_Run()

Let me know if you need more code or information. I just need to get an idea of what's the best method for getting the input, tracking the shots and then displaying the array of shots. Some of you may have already written Purebasic code that tracks shots on the screen, so I wanted to pick your brains.

Thanks,
Tron

"Honesty is the best policy, but insanity is a much better defense."
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

One little question -have you checked out the source code of 'Waponez II" on the PureBasic site(download section)? I believe you can find almost all the answers in that source code to the questions you ask in your post.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tron.
One little question -have you checked out the source code of 'Waponez II" on the PureBasic site(download section)? I believe you can find almost all the answers in that source code to the questions you ask in your post.
Doh!!! I should have looked there first! I knew there was some code around here somewhere. Thanks for putting my head back on straight.

Thanks again Pupil!

"Honesty is the best policy, but insanity is a much better defense."
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

You could check out my cheezy Space Invaders clone on the Resources Site (under Apps). It comes with Source and Graphics and compiles into a single executable.

http://www.reelmediaproductions.com/pb
Post Reply