A shooting question

Started by
3 comments, last by LordBanshee 22 years, 5 months ago
i am tring to make a Space-Invaders(type game) and i am so mad that i can not figure out an algrithom for shooting infinite bullets? i am using directx and visual C++ when i shoot it just shoot one bullet then then i shoot again that bullet already shot will disapear and shot form where i was. I know it has something to do with arrays of some sort. but if u can help me out please do thanks
Advertisement
Heh, i remember being stumbled by this one back in the day.

Essentially what you need to do is make an array of bullets. Then each time the user presses fire you add it to the array (or linked list) then when it comes time to draw the bullets you loop through the array, drawing the bullets.

When a bullet comes to the end of the screen or hits a target you remove it from the array.

Good luck! and have fun
i tired that, but every time i did that and hold down the fire button it will shot rappidly then stop and shoot rappidly again going smaller and smaller each much of rapid fire''s. It didn''t matter how big i mad the array :/ hmmmm..... i''ll get thier
the original space invaders only allowed the player to shoot one bullet at a time, and they couldn''t fire again until the bullet hit something or went off the screen...
but, you didn''t ask that, so:
you have to limit how fast you can shoot the bullets. i don''t know how you are getting your input, or where your "fire the bullet now" code is... do you want it so the player can hold down the button to keep firing, or do you want the player to have to hit the button for each shot?
post how you are getting the input, and which way you want the bullets to fire, and i''ll get back to you (please don''t put all your code though, just the important parts; or describe how you are doing it).

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
i am using winproc right now(going to upgrade to direct input later) my code is something like



case VK_SPACE
then
ShootBullet[LastShootIndex+1].Activate = 1
LastShootIndex++
break


.....
Game Main()
....
....
//Checking if player shoots
for (int counter = 0; (MaxShootIndex-1);counter++)
{
if (ShootBullet[counter].Activate ==1)
{
Shot(ShootBullet[counter].x,ShootBullet[counter].y,ShootBullet[counter].Type)
}
}
....
....


it will be nice for me to have where the player can hold down the shoot button. i know of one way it is using a mod in my GameMain code.

This topic is closed to new replies.

Advertisement