Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fwar

I am super stuck with bullets

This topic is 6937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a game in which i want bullets to fly up and hit things, but i have it set up so when i press the spacebar it puts the bullet where the gun is and when the space bar is released the bullet fly up, i want to set it up so that it will repeatedly shoot when i hold the spacebar, i don''t know how to do it... i tried setting up different blits for each bullet(which sounds wrong) and it still doesn''t work because when i press the button its moves all the bullets to the gun, i want it to shoot up, and be able to press the spacebar and the past bullet keep flyin up and away, while a new bullet comes out of the barrel i''m really stuck, please help me. THANKS

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure if I understand your question.

Are you using DirectX and DirectInput for your input? If so, I''m not sure what''s wrong because when you hold down a key, the program is supposed to recognize that the key is being pressed and to repeatedly "act upon it," for lack of better words.

As the above posters said, it would be easier if you posted the source.

Martin

Share this post


Link to post
Share on other sites
I think i understand what he is saying. I think he means that the bullets don''t move after he presses the space bar. If i''m right in interpreting you question you want to have an array of bullets and then every cycle (or everyother cycle) move them up one space (decrease the y-value). Code would be something like this:
*************
bulletType bullets[50]; // 50 bullets

void MoveBullets(void)
{
for(int index=0;index<50;index++)
{
if(bullets.active==true)
bullets.y-=2; // move the bullet 2 pixels up
}
}

********
This assumes that when you hit space you set a bullet in the sructure to true (active). You also have to make sure to turn off the bullets and reset their position when they hit something or go out of bounds. Hope this helps if it was your question!

Share this post


Link to post
Share on other sites
This is the simplest method to do it, it is not optimized, etc. (that's your job! )

I will give it to you in pseudo (C) code:

set up an array of integers and bools
int ShotInfo[2][100];
bool ShotAlive[100];

ShotInfo: the first dimension (ie. the [2] represent the x and y coordinate of the shot, the [100] means there's a max of 100 shots).
ShotAlive: this is so we know if the shot is alive or not.

At the beginning set all elements in ShotAlive to FALSE.
When the player hits spacebar, look for an element in ShotAlive that is FALSE and set that to TRUE. For example, let's say the player presses spacebar for the first time and element 0 is FALSE, so we set that to true. Now we take that element number (in this case it's 0) and go into the ShotInfo array. I'm going to call the element number ID.
Set ShotInfo[0][ID]=X coordinate of gun;
Set ShotInfo[1][ID]=Y coordinate of gun;

Now, in your main loop somewhere:
Go through the entire ShotAlive array. If something is TRUE, update it:
ShotInfo[1][ID]--;

When the shot hits something, or it has gone off the screen set it's ShotAlive[] to FALSE.

I hope you understand this and I hope this helps you out.
Later,
Queasy.

Edited by - Queasy on 4/26/00 10:53:28 PM

Share this post


Link to post
Share on other sites
Queasy, declaring "int ShotInfo[2][100];" is the "Basic" programming way of creating multi dimentional arrays. In C you would want to declare it like this:

int ShotInfo[100][2];

I''m throwing up the red flag because new programmers could be reading this.

Share this post


Link to post
Share on other sites
quote:
Original post by WhatEver

Queasy, declaring "int ShotInfo[2][100];" is the "Basic" programming way of creating multi dimentional arrays. In C you would want to declare it like this:

int ShotInfo[100][2];

I''m throwing up the red flag because new programmers could be reading this.


Why? It looks like it stores the same amount to me.
Beginner here in C.

Thanks



Share this post


Link to post
Share on other sites
I retract my comment...you''re right . I''m just used to looking at it the other way arround. Now that I look at it again, indexing it his way would work just fine.

You learn something new every day :D. Maybe I can use his method to my advatage some day.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!