-
Asteroids 1.0
Hi!
I made this little game in C (VS C++ .NET) just beacuse I'm going to recreate it in assembler for M68HC11 processor for my school project.
Can anyone please tell me how can I make 10 asteroids at once and that they are all moving from right to left?
Please take a look at the code.
Thanks.
-
Controls are:
8 - up
5 - down
4 - left
6 - right
S - shift (start)
ESC - escape (end game)
1,2,3 - select speed
-
Does really no one knows how to make 10 asteroids at once??
Help me!!
:confused: :confused:
-
Generally....
// you would probably have a struct of asteriod type
// an array of 10 asteroid types would be sufficient for 10 asteriod sprites
sAsteroid asprite = new sAsteroid[10];
// some where in update and or Init function
for(int i = 0; i < 10; i++) {
if(!asprite[i].active) {
// reinitalize asteriod var values
// for speed, position and vector etc.
// I suggest having an id var so you can
// grab asteroid id's for collision checks etc.
}
}
// some where in collision detection
for(int i = 0; i < 10; i++) {
if(collidesWithMe(asprite[i])) {
asprite[i].state = "explode";
}
}
// some where in your graphics method
for(int i = 0; i < 10; i++) {
if(asprite[i].state == "normal")
drawSprite();
if(asprite[i].state == "explode")
drawExplosion();
}
etc. etc., you should get the idea by now.