Bullets in 2D

Started by
5 comments, last by level10boy 22 years, 6 months ago
Anyone know the best way to do bullets in say a 2D sprite based shooter like Xenon. Cheers
Advertisement
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)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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
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
Mike BarelaMikeB@yaya.com
Thanks, I''ll consider all your replies.
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
Thanks
Look at EDIA Postmortem. There I explained how it worked in my old game EDIA.

There are a few things there that I''d do differently now, but back then I did it the way I explain in the document.


--DK
--H. Hernán Moraldo
http://www.hhm.com.ar/
--DK--H. Hernán Moraldohttp://www.hhm.com.ar/Sign up to the HHM's developers' newsletter.

This topic is closed to new replies.

Advertisement