Posted: Mon Aug 05, 2002 10:16 pm
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."
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."