Public Group

# Space Shooting (need help with algorithm)

This topic is 3970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

After finished 2D graphic board game, I decided to move to something little more complex than it. Now I have finally made up my mind; I want to create 2D Space Shooting game-like. However, before I get my hand into it, I want to make sure I will do it the right way. So I make a few algorithms and I want to see your comments from you guy. Bullets: I make player spaceship bullets into 50 elements array. Each bullet contains x,y,dx,dy,active. Where x,y are the current possition; dx,dy are the direction of the bullet will go; active is for telling whether the bullet is off the screen or not. Whenever player shoot, we will run through 50 of bullets, check which one is in-active, and use it. (Do you think it is good way to do it?)

##### Share on other sites
I've made a space shooting game a while back. In fact, my very first video game I ever made was a space shooter. It was really crappy at first, and it was in VB. XD But I've made some improvements on it, and did a C++ version. I can tell you you're on the right track. Only one thing I can comment on, technically you don't need to put in an "active" flag for the bullets. The way I made my shooter work is it would only detect collision by calculating if the bullet was on screen or not by looking at its "x" and "y" variables. I'll give you an example of the pseudocode:

if bullet's X > screen width OR
bullet's X < -(bullet's width) OR
bullet's Y > screen height OR
bullet's Y < -(bullet's height) THEN
//bullet is off screen
ELSE
//bullet is on screen
//Detect collisions here

Hope that helps you, good luck with your project.

##### Share on other sites
In a previous game project of mine I used a system very similar to that described by SSJMetroid. One difference, instead of storing dx and dy I actually stored what I called "angle" a.k.a the angle at which the projectile was fired. Same general effect, just going about it a different way.

##### Share on other sites
I would prefer a STL linked list to add/remove bullets. Because there is no reason for use an Array, you will always loop throug and check every bullet for collision and activity. If it becomes invalid just remove it from the list.

In my spaceshooter the bullets get an active value but thats for special type of bullets that have a small range. I decremented it every 0,1sec and if it falls to zero it becomes inactive and i remove it. But in your case i wouldn´t use an active flag because no bullet will come back to screen just remove it completly.

sry for my english

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 14
• 9
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
632911
• Total Posts
3009182
• ### Who's Online (See full list)

There are no registered users currently online

×