Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need some help with bullets...

Started by Dwarf with Axe Feb 16, 2002 at 1:05 PM 7 replies 800+ views
Original Post
Dwarf with Axe
Dwarf with Axe
Well I''ve tried other forums and they''re no help. I''m trying to create a galaxian/space invader clone, and everything should be pretty easy EXCEPT the bullets! I can''t think of how to implement the shooting... Are there any tutorials on the net (sure they''re are) and could you link me to them? THanks.
Jason Zelos
Jason Zelos
Try looking up projectiles.

Why don''t you write a bullet class and spawn/delete bullets as nessesary. The class would include position, direction , velocity as well as sounds/graphics (or pointers to) and damage information/type (explosion radius etc).

,Jay
Dwarf with Axe
Dwarf with Axe
Thanks!

That''s what I have so far, but I think I am thinking too technically . It has to be easier than I am thinking, because right now, I have about 3 different classes and structs just to manage the bullets...

And they still don''t work!

~Dwarf
mickey
mickey
hiya dwarf, do you already have a timer control in your game? well, everytime the player presses the spacebar, activate the timer for the bullet, ie,

when the user presses spacebar:
fire = true;

if(fire = true)
{
bullet_Y -= (your variable here)
}

well, that''s all what i can think off, hey if you''re still having a problem, ICQ me, 141451718, i''ll happily help you out,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Aphelion
Aphelion
You could implement a linked list... I don''t know if you have already...
Example:

class Bullet
{
public:
float x, y;
float xvel, yvel;
Bullet *next_bullet;
Bullet *last_bullet;
void AddBullet(Bullet *pParent);
void DeleteBullet(void);
};
void Bullet::AddBullet(Bullet *pParent)
{
Bullet *pNew;
pNew = new Bullet;
pNew->last_bullet = pParent;
pNew->next_bullet = NULL;
}
void Bullet::DeleteBullet
{
Bullet *next;
Bullet *last;
next = this->next_bullet;
last = this->last_bullet;

// skip current bullet, then delete
next->last_bullet = last;
last->next_bullet = next;
delete [] this;
}

This probably won''t work (so don''t compile it! ), but it might get the idea across... And then during the gameloop you''d have to create some kind of loop that walks through each bullet and does its ai. Look up a linked list tutorial in the Articles section if you don''t understand them...
Goodluck!
-Jesse


| The Hitchhiker''''s Guide to Programming |
"That is not dead which can eternal lie,
And with strange aeons even death may die."
-H.P. Lovecraft
| The Hitchhiker''s Guide to Programming |"That is not dead which can eternal lie,And with strange aeons even death may die."-H.P. Lovecraft
Jason Zelos
Jason Zelos
If you have a copy of UnrealEd look at the weapon classes there, they are all subclassed from a standard weapon class with different Touch (bullet projectile hit) etc. methods.

It makes it very easy to add new weapons etc (Exploding Pigeon Crossbow).

,Jay

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.