Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post Posted: March 3rd, 2012, 1:27 pm 
 

Joined: March 1st, 2012, 2:43 am
Posts: 10
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.


Top 
 Profile  
Reply with quote  
 Post Posted: March 4th, 2012, 8:19 am 
 

Joined: March 1st, 2012, 2:43 am
Posts: 10
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.


Top 
 Profile  
Reply with quote  
 Post Posted: March 4th, 2012, 10:33 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
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


Top 
 Profile  
Reply with quote  
 Post Posted: March 4th, 2012, 12:26 pm 
 

Joined: March 1st, 2012, 2:43 am
Posts: 10
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.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 4 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: