Advertisement

Shooting more than one bullet at a time!!

Started by February 05, 2000 02:44 AM
3 comments, last by Nightwolf 25 years, 1 month ago
Well, I finally got the bullet working, I was forgetting about vsync..hehe.. I really haven''t programmed for a long time. Anyways.. heres my next question... How do I make it so I can fire more than one bullet at a time. Do I use a for loop or a while loop. I wouldnt mind a good example!!! Thanks for all your help guys.. kirk for me..first came QBASIC, then C w/ DJGPP and Allegro, now DirectX and C++.. what a life!!
for me..first came QBASIC, then C w/ DJGPP and Allegro, now DirectX and C++.. what a life!!
Please help!!!
for me..first came QBASIC, then C w/ DJGPP and Allegro, now DirectX and C++.. what a life!!
Advertisement
whats a bullet have to do with vsync? what type of game is this? 2d shooter? there are many ways of handling multiple bullets. here''s a general way... keep a list of the active bullets. when 1 is shot, add it to the list. when it goes away, remove it from the list. the entries in the list can hold whatever data you need. the simplest 2 ways to store the list would be with a linked list or an array.
Carl "trixter"[email=carl@trixoft.com]carl@trixoft.com[/email]http://www.trixoft.com
My sugggestion to you would be to write some psuedo code (half English, half tech), so that you don''t get bogged down in the details. That way you can concentrate on the higher level design stuff, before tackling things which might be have a negative effect overall in working with other parts of the code.
I''m guessing that you''re the guy of the ship''n bullet post
If not ignore
else
{
you have to store the bullets information (like in an array of bullet structs(or class))
then you have to go through the array, moving each bullet, then drawing.(by the way, if you use an array, you''ll need to mark wich bullets are valid and wich aren''t, also there are some issues with the number of bullets you can have flying at a time, what you do when you have to add a new bullet and there is no space in the array...)
anyway with an array you''ll probably be better of with a for loop (though for and whiles are basically the same)
something like

struct bullet
{
int x,y;
...
};

bullet bullet_array[100];

for(int i = 0 ; i < ARRAY_SIZE; i++)
{
movebullet(bullet_array + i);
drawbullet(bullet_array + i);
}

(note: in an array, bullet_array + i will return a pointer to the bullet struct)


Alexandre Moura
alexmoura@hotmail.com

This topic is closed to new replies.

Advertisement