help shooting bullet from ship
Hi ya
Im having this problem with my game I''m developing.The game im trying to code is something like asteroids. I can move my ship all abou the screen no problem. The problem im having is trying to shoot a bullet from the ship. I cant seem to do it at all. My ship has an
ShipAngle (angle ship is facing)
ShipXpos
ShipYpos ( were it is currenlty sitting)
I know i take what i do for moving the ship and just do it for the bullet but i can only get the bullet to move whenever i hold down the spacebar which is assigned to shhot bullet. Is there some kinda loop i can use so that after spacebar is hit then it travels on its own for a period of time or until it hits something. please help. Below i have some code that shows how i move my ship if thats any help
the DirectionX and DirectionY things are the just the ships angle * pi / 180
PLease can anyone help, really need it
void cShip::MoveShip()
{
double DirectionX[32] = {0,0.19509032201613,0.38268343236509,0.5555702330196,0.70710678118655,
0.83146961230255,0.92387953251129,0.98078528040323,1,0.98078528040323,
0.92387953251129,0.83146961230255,0.70710678118655,0.5555702330196,0.38268343236509,
0.19509032201613,0,-0.19509032201613,-0.382683432366509,-0.5555702330196,-0.70710678118655,
-0.83146961230255,-0.92387953251129,-0.98078528040323,-1,-0.98078528040323,-0.92387953251129,
-0.83146961230255,-0.70710678118655,-0.5555702330196,-0.38268343236509,-0.19509032201613};
double DirectionY[32] = {-1, -0.98078528040323, -0.92387953251129, -0.83146961230255, -0.70710678118655, -0.5555702330196,
-0.38268343236509, -0.19509032201613, 0, 0.19509032201613, 0.38268343236509, 0.5555702330196, 0.70710678118655,
0.83146961230255, 0.92387953251129, 0.98078528040323, 1, 0.98078528040323, 0.92387953251129, 0.83146961230255,
0.70710678118655, 0.5555702330196, 0.38268343236509, 0.19509032201613, 0, -0.19509032201613, -0.38268343236509,
-0.5555702330196, -0.70710678118655, -0.83146961230255, -0.92387953251129, -0.98078528040323};
if( Xmove != 0.0 || Ymove != 0.0)
{ //the ship is moving
ShipXPos += Xmove;
ShipYPos += Ymove;
if(ShipXPos < 50 || ShipXPos > (WINDOW_WIDTH - 50))
ShipXPos = WINDOW_WIDTH - ShipXPos;
if(ShipYPos < 50 || ShipYPos > (WINDOW_WIDTH - 50))
ShipYPos = WINDOW_HEIGHT - ShipYPos;
//DrawShip();
}
m_Keyboard.Process();
if (m_Keyboard.CheckKey(DIK_UP))
{
Xmove += (float)DirectionX[ShipAngle];
Ymove += (float)DirectionY[ShipAngle];
if(Xmove > 20.0) Xmove = 20.0;
if(Xmove < -20.0) Xmove = -20.0;
if(Ymove > 20.0) Ymove = 20.0;
if(Ymove < -20.0) Ymove = -20.0;
}
else //no thrust -- use friction
{
if(Xmove > 0) Xmove -= Friction;
if(Xmove < 0) Xmove += Friction;
if(Ymove > 0) Ymove -= Friction;
if(Ymove < 0) Ymove += Friction;
if(Xmove < .1 && Xmove > -.1)
{
Xmove = 0.0;
}
if(Ymove < .1 && Ymove > -.1)
{
Ymove = 0.0;
}
}
}
In order to have more than one bullet on screen at a time, you will have to create an array of bullets and loop through it accordingly. Treat each bullet as though it were a ship, except that it cannot accelerate (including changing its direction) in any way. You might want to check out particle systems if you have problems getting this working.
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
have a vector of bullets, each time you hit the space bar you add another instance. Every time you render update the vector of bullets by looping through it. After a set time just delete the necessary bullets.
quote:Original post by kiznore
whats this particle system that you are on about
Loosely, it''s just a simple methodology behind managing more-or-less identical objects that appear from a source and then move, change colors, interact, etc. in some way (obviously bullets coming from a ship could be considered particles).
Here is a quick search of the GameDev articles and resources section. However, this tutorial is probably better suited to getting you started.
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
quote:Original post by Thunder_HawkCan I request that this individual''s post be put on display somewhere as the ideal way to respond to a question that has already been asked and answered?
Loosely, it''s just a simple methodology behind managing more-or-less identical objects that appear from a source and then move, change colors, interact, etc. in some way (obviously bullets coming from a ship could be considered particles).
Here is a quick search of the GameDev articles and resources section. However, this tutorial is probably better suited to getting you started.
I''m not saying thats the case in this particular situation, but what Thunder_Hawk has done here is exactly what I like to see -- helpful comments preclude links to a relevant search as well as a specific Tutorial on the subject. Bravo, Thunder_Hawk.
PS: Sorry for the OT. Please don''t let this comment interfere with the discussion.
****************************************
Brian Lacy
ForeverDream Studios
Comments? Questions? Curious?
"I create. Therefore I am."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement