Sign in to follow this  

Space Shooting (need help with algorithm)

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this