Help with game...

Started by
13 comments, last by Topace 23 years, 10 months ago
I have a programming question about C++. I am currently wtiting a space "Shoot-Em-Up" game. It is a 3-person veiw, where you ship is on the bottom of the screen, and the enemies come from the top, i am having a problem with the laser firing. First of all i can get the first laser to fire, thats easy, but i need to get it to fire two lasers at a time. Im thinking i need an array that holds three numbers... laser[lasernumber][x][y]. Somthing like that where the lasernumber would be like 1, if it is the first laser, 2 if it is the second and so on... I dont really know if this would be the way i would want to hold the laser number and assosiate the x and y coordinates to them, if you know of a better way please tell me. Email Me!
Advertisement
I''m assuming you''ll also want the bad guys to fire weapons? Right? So what I''d do is create an array of "shots" so then each time AYNONE fires a weapon it fills in the next available shot in the array specifiying the x and y co-ords and the type of weapon and probably destination x and y co-ords and the speed of the weapon, then in your main game loop you would:
1.)Paint your terrain
2.)Paint all the untis
3.)Paint all the shots

When you paint the shots you simply go through the list and depending on which type of shot it is Blit a different sprite like a missile or bomb or bullet or whatever, now when you get to type laser you simply draw a line (Maybe red?) from the start x and y to the dest x and y and then check for a collision with other ships. Also if you use bullets, and especially if you have anysort of network play, it''s ridiculous to shoot a bullet gun and actually create 100 bullet objects and update them all, so most people consider the whole shot of bullets as one line of bullets, so draw bullets from start x and y to destination x and y and move them along according to the speed variable...
Missile would be similar just move the missile towards it''s destination x and y according to it''s speed variable..
Hope this helps!
See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Personally, I would use classes, so you have something like:
laser[LaserNum].x and laser[LaserNum].y
It''s not really a good idea to have 3 dimensional arrays.

Martee
Magnum Games
http://MagnumGames.8m.com
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Using linked list for this would be much faster then using an array.......
if you used an array say of size 100.....for max of 100 bullets on screen at any given time......then you would be restricted to only 100 bullets on screen......even if you only had 10 bullets being firedt........you would still have to cycle through your array 100 times
on the other hand....a linked list would allow unlimited bullets on your screen (well only limited by your RAM).......and if you only had 10 bullets on screen......then it would only cycle through your bullets 10 times


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Of course, with an array of shots, you have the limit on
how many shots can be fired at once. A linked list would
probably kick a lot more ass in that regard.

typedef struct MyShotStruct {
int x, //The bullet''s Horizontal position
y, //The bullet''s Vertical position
target, //What it can hit (0=air unit,1=ground unit
//2=player)
speed; //How fast is it moving (negative is up,positive is
//down

MyShotStruct *Next,*Prev; //Pointers for the linked list
} ShotListStruct;

But maybe that''s just me...



----------
Disco Love For Everyone
That last post put my tag in, but not my name????


----------
Disco Love For Everyone
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone
You probably put in your username but not password...
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Just use an array, or you''re going to have to allocate memory for each new link in the list and thats going to slow your game down.
the amount of time to allocate the memory is negligible.....
especially with the speed of todays computers, maybe if you have something pre-pentium....like an old 486 or something you MIGHT see a perofrmance hit.......but then if you are programming with an old 486 then that is a problem from the start.......
seriously......linked lists are much better to use in this case........the only place where I would use an array is for a gameMap because you have random access to all the elements in the map (i.e. gameMap[x][y] = whatever......)
but of course I would dynamically create the 2d array to save memory


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Thanks for all your help, but im still confused... i could struct something to hold all the values, but wouldnt it be faster just to make an array?

int move_laser = 0;
int laser[50];
int laser_height = 100;
int i = 0; //number of lasers
int x = 100; //Laser X Value
int y = 100; //Laser Y Value

void movelaser(void);
void main(void);

void main(){
while(1){
blah;
blah;
blah;
blah;

if(move_laser == 1){
while(laser[x] >= 0){
for(a=0;a;a++){ //do it for as many times as there are //lasers
BLT(laser[x], laser[y],bltfast);
laser[x] = laser[x] - 1;
}
}
}
}

void movelaser(){
for(a=0;a;a++){<br> laser[x] = ship_y - 10;<br> laser[y] = ship_x - 50;<br> }<br>move_laser = 1;<br>}<br><br>I was thinking something like that, no thats not my real code, its just a skeleton, but i think im resetting the value of the array too many times, i think i need an array thats like what i desribed the first time laser[#][X][Y] something like that, but im not sure, its not a 3-dimensional array, just one that can hold 2 others besides the first, if this helps any, please feel free to post more, sorry i wasnt very clear the first time… </i> <br><br><a href = "mailto: Wtopace@croswinds.net">Email Me!</a>

This topic is closed to new replies.

Advertisement