Jump to content

  • Log In with Google      Sign In   
  • Create Account

Need some help with bullets...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 16 February 2002 - 07:05 AM

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.

Sponsor:

#2 Jason Zelos   Members   -  Reputation: 211

Like
Likes
Like

Posted 16 February 2002 - 07:52 AM

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

#3 Dwarf with Axe   Members   -  Reputation: 277

Like
Likes
Like

Posted 16 February 2002 - 04:14 PM

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

#4 mickey   Members   -  Reputation: 100

Like
Likes
Like

Posted 16 February 2002 - 05:20 PM

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,

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 16 February 2002 - 06:03 PM

Yes you can increment the Y by a static velocity like 5. (y-=5) but most of the time you want to have a velocity which can slow down & go faster depending on certian conditions. So it''s easier to do something like this

struct bullet
{
int x;
int y;
int vel;
};

bullet mybullet;
int InitialVelocity = 5;

// Do this in your startup initialization.
mybullet.vel = InitialVelocity;

// when the fired button is pressed.
mybullet.x = ( (ships.x1 + ships.x2)/2); // this puts the bullet at the middle location of your ship.

mybullet.y = ships.y1;


// do this in the frame update
mybullet.y += mybullet.vel;

now if you want the bullets to move faster say you pickup a "rapid fire" power up, you can just do...
mubullet.vel = 10; and your bullets will move alot faster. Or should you need to slow things down you can just do mybullet.vel = 2;







#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 16 February 2002 - 06:10 PM

I forgot some stuff so let me do this again..

// is the bullet alive or dead?
#define ALIVE = 0;
#define DEAD = 1;

struct bullet
{
int x;
int y;
int vel;
int state;
};

bullet mybullet;
int InitialVelocity = 5;

// Do this in your startup initialization.
mybullet.vel = InitialVelocity;

// when the fired button is pressed.
mybullet.x = ( (ships.x1 + ships.x2)/2); // this puts the bullet at the middle location of your ship.

mybullet.y = ships.y1;
mybullet.state = ALIVE;


// do this in the frame update
if(mybullet.state == ALIVE)
{
mybullet.y += mybullet.vel;
}

// check to see if the bullet is dead or not..
if( CollideWithAlienOROffScreen(mybullet) != FALSE )
{
// turn it off.
mybullet.state = DEAD;
}



now if you want the bullets to move faster say you pickup a "rapid fire" power up, you can just do...
mubullet.vel = 10; and your bullets will move alot faster. Or should you need to slow things down you can just do mybullet.vel = 2;




now keep in mind this is just one bullet, if you want more than one bullet you''ll need to use an array or linked list of bullet structures and modify the code accordingly.

#7 Aphelion   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 February 2002 - 06:12 PM

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

#8 Jason Zelos   Members   -  Reputation: 211

Like
Likes
Like

Posted 17 February 2002 - 06:18 AM

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

#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 17 February 2002 - 09:03 AM

quote:
Original post by 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


| <a href="http://www.angelfire.com/games4/parsec/index.html">The Hitchhiker''s Guide to Programming</a> |
"That is not dead which can eternal lie,
And with strange aeons even death may die."
-H.P. Lovecraft


The linked list is a good idea, just remember DO NOT call the ADDBULLET and DELETEBULLET functions in your main game loop. New and Delete as well as malloc and free are expensive time wise, and should never be done durring game play.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS