help..trying to loop sprites (space invaders)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Raven
Posts: 10
Joined: March 1st, 2012, 2:43 am

help..trying to loop sprites (space invaders)

Post by Raven » March 3rd, 2012, 1:27 pm

hey guys,

making a lame version of space invaders. except i only want one or 2 on at anyone time. now that isnt a problem. ive got the coding down for it. but when i shoot them down, i wish for them to "respawn" so to say. basically for the coding loop to go around again. instead of me having to type in 30 copy 'n' paste the sprite invaders. if that make sense.

ive tried the while loop and the for loop but ive had no luck with either. the while loop actually comes up with an exception error when i try and run it.

btw im using chili directx framework.

any help would be super awesome as its really doing my head in.

Raven
Posts: 10
Joined: March 1st, 2012, 2:43 am

Re: help..trying to loop sprites (space invaders)

Post by Raven » March 4th, 2012, 8:19 am

maybe im being too vague.
this is the code:
if (gunx + 20 > aix &&
gunx < aix + 24 && //now this part is the bullet or "gun" collision
guny +20 > aiy &&
guny < aiy +24 )
{
restartloop++;

gunfired = false; // this resets the bullet when hitting the target
}

drawai1 (aix, aiy); // this draws the ai ship or sprite.
aiy++; // this makes it move down.
}
now in order for me to make the sprites continue to fall down after ive shot them, i need to copy and paste this and obviously change the names eg ai2y , ai2x, and ai3y, ai3x and so forth.
this makes it quite messy in the code and of course i need to copy and paste a bunch of :

void Game::drawai1(int x, int y)

{
gfx.PutPixel blah blah
}

any ideas anyone on how to loop this with out having to type 40 billion lines of copy and paste code?

when i nail this, i'll be adding a number generator of some kind so the sprites will fall at different x values and different speeds.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: help..trying to loop sprites (space invaders)

Post by chili » March 4th, 2012, 10:33 am

Okay bro, there is a very good way to do exactly what you want to do, but in order to do it you'll have to understand arrays first. I will cover arrays in Lesson 13 or 14, so you'll have to hang in there. If you can't wait, look up "c arrays" and try and find a good tutorial that will get you started.
Chili

Raven
Posts: 10
Joined: March 1st, 2012, 2:43 am

Re: help..trying to loop sprites (space invaders)

Post by Raven » March 4th, 2012, 12:26 pm

Hey dude, thanks for the reply :D
i've done a bit of research on arrays, and from what i can tell its only used for storing multiple numbers in the one integer.

forgive my ignorance but i cant seem to relate it to finding a way for me to loop this one bit of code.

anyway, i'll keep trying.

Post Reply