Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Space Invaders with clones
- PUBYU
-
2 posts
Space Invaders with clones
I'm trying to create a space invaders style game (http://scratch.mit.edu/projects/26717067/#editor). I'm in the first steps but I've already run into a number of problems:
1) When two full rows of aliens are created (that's 28 of them) they fall out of lockstep as soon as they reach one of the borders.
2) If only one alien is created,
a) it moves down much before it reaches the border
b) it appears to be moving even after it has been killed (check the col_pos array)
In fact, when I examine the col_pos array (where the x position of the alien should be recorded) it looks as if two sets of coordinates were being tracked.
Also, how do I get rid of variables I'm not using?
1) When two full rows of aliens are created (that's 28 of them) they fall out of lockstep as soon as they reach one of the borders.
2) If only one alien is created,
a) it moves down much before it reaches the border
b) it appears to be moving even after it has been killed (check the col_pos array)
In fact, when I examine the col_pos array (where the x position of the alien should be recorded) it looks as if two sets of coordinates were being tracked.
Also, how do I get rid of variables I'm not using?
- coxy5
-
100+ posts
Space Invaders with clones
Hi,
I have created a simple space invaders game and have taken some shotcuts along the way but you can view that here: link.
My scripts move the invaders down at regular steps but it is not set to when they touch the edge.
Have a look it might help.
To get rid of variables you are not using just right click on them and click delete.
I have created a simple space invaders game and have taken some shotcuts along the way but you can view that here: link.
My scripts move the invaders down at regular steps but it is not set to when they touch the edge.
Have a look it might help.
To get rid of variables you are not using just right click on them and click delete.
- gtoal
-
1000+ posts
Space Invaders with clones
1) When two full rows of aliens are created (that's 28 of them) they fall out of lockstep as soon as they reach one of the borders.
I would suggest using a different control structure. Treat the group of invaders as a single object and have one thread update their coordinates in a single operation. In fact they could all have a relative offset within the group, to which is added a single global offset for the whole group, and the global offset is the only thing that you need to update. You can have a direction and a speed, and when any clone touches a side, just change the direction.
All the clones need to do is move themselves to the x,y coordinates that they've been assigned, detect hitting a side, and kill themselves if they are hit by a missile.
Actually after posting this suggestion, I remixed your project to try what I suggested - it's in http://scratch.mit.edu/projects/27107702/ - you're welcome to use that remix as the base of your game. There's lots still to do, I didn't write the game for you, just fixed the mechanics of moving the invaders around.
G
Last edited by gtoal (Sept. 21, 2014 16:02:12)
- PUBYU
-
2 posts
Space Invaders with clones
Thanks a lot, gtoal. In addition to solving the programming issue, I was also hoping to understand why this was happening. I couldn't see any problem with my coding.
- Discussion Forums
- » Help with Scripts
-
» Space Invaders with clones