Archived

This topic is now archived and is closed to further replies.

level10boy

Bullets in 2D

Recommended Posts

do WHAT with bullets?
if you mean making them move, just store the coordinates of each bullet, and it''s velocity (which includes speed and direction; i usually keep them as a dX and dY value as long as they can;t change direction mid-flight). each iteration through the game loop, add the velocity to the coordinates. check for a collision.

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Sorry, I should have been more specific. I meant in terms of if you can fire so many that 100 or more say are on the screen at one time, what would be an efficient data structure for storing say all these bullets structures so that they can be efficiently checked for collision against all enemies on screen.

Thanks though

Share this post


Link to post
Share on other sites
Just make them a game object.

class GameObj
{
int m_pos_x;
int m_pos_y;
bool m_alive

...
...
}

Derive classes for the bullets, player, and enemies from the gameobject class with specific functionality for each. Hope this helps. Its a pretty standard way of doing sprite like objects in 2d. You can push the gameobjects onto lists or into arrays which makes keeping track of them easier. =)



Mike Barela
MikeB@yaya.com

Share this post


Link to post
Share on other sites
Well I use a similar method in my game. It runs under Direct X and I can get about 1000 particles on screen (most I have tried) without a slowdown.

I make an array of BULLET
typedef struct
{
int x,y; //position
int state;//1 is fired, 0 is not fired
RECT rect; //the bullet rectangle
} BULLET;

Then I draw each one as a rect on screen that travels with an automatic velocity of 3 in the X direction. Test if it hits something... If it hits a monster, set it to not fired and damage the monster, if it hits a wall just set it to not fired.

Basiclly run a for loop testing if the bullets are released... if so move them and check for them
More bullets become released the longer you hold down the space bar or whatever. Also use this effect for a flamethrower... Thats what I do anyway

Understand what I mean? If you don''t... ask questions I''m glad to help

Share this post


Link to post
Share on other sites