Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with "space invaders" type game? Unsure about how to implement certain functions...
- Susurration
-
10 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
http://scratch.mit.edu/projects/12474150/
I'm playing around with Scratch and I want to make a traditional, space-invaders style game, where the player moves along the bottom of the stage shooting projectiles at the enemies that advance from the top of the stage.
I'm not really sure how to accomplish some of the things that I want to do, though.
Things I'm unsure about:
-How to make the player have “lives”. I would like my player to have 3 lives
-I'm having problems with shooting projectiles. For some reason I cannot understand, the projectile shows up far away from the player sprite, which makes aiming a hassle. I want to make it so the projectile appears to be issued from the player, but nothing I do seems to work.
-If the enemy touches the player, the player should lose a life. All sprites should disappear from the stage and the game should restart.
-Again, here, I'm having issues with “lives”. Also, I'm not sure how to make the game reset. I can't figure out an efficient way to make the sprites go back to their original places once they've been destroyed, or when the player has been destroyed. How do I make the enemies reappear back at the top of the stage?
- I would like to implement a points system, so if the player destroys the enemy, the player should get a point. The score should be displayed on the stage.
-I have successfully implemented left and right motion, but I would like to implement up-and-down motion as well. However, I want to limit this up-and-down motion to the bottom fifth of the stage. How would this be accomplished?
-I would to like implement timed levels that get progressively more difficult. So far, I'm thinking about around three.
-Another idea I had was creating a kind of “bomb” that could be used a limited number of times throughout the game that would destroy everything on the screen. This could only be used 1 or 2 times throughout the game.
I'm playing around with Scratch and I want to make a traditional, space-invaders style game, where the player moves along the bottom of the stage shooting projectiles at the enemies that advance from the top of the stage.
I'm not really sure how to accomplish some of the things that I want to do, though.
Things I'm unsure about:
-How to make the player have “lives”. I would like my player to have 3 lives
-I'm having problems with shooting projectiles. For some reason I cannot understand, the projectile shows up far away from the player sprite, which makes aiming a hassle. I want to make it so the projectile appears to be issued from the player, but nothing I do seems to work.
-If the enemy touches the player, the player should lose a life. All sprites should disappear from the stage and the game should restart.
-Again, here, I'm having issues with “lives”. Also, I'm not sure how to make the game reset. I can't figure out an efficient way to make the sprites go back to their original places once they've been destroyed, or when the player has been destroyed. How do I make the enemies reappear back at the top of the stage?
- I would like to implement a points system, so if the player destroys the enemy, the player should get a point. The score should be displayed on the stage.
-I have successfully implemented left and right motion, but I would like to implement up-and-down motion as well. However, I want to limit this up-and-down motion to the bottom fifth of the stage. How would this be accomplished?
-I would to like implement timed levels that get progressively more difficult. So far, I'm thinking about around three.
-Another idea I had was creating a kind of “bomb” that could be used a limited number of times throughout the game that would destroy everything on the screen. This could only be used 1 or 2 times throughout the game.
- drmcw
-
1000+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
That's a lot of questions! Let's start with the simple ones. For lives and score you need to create a variable, call one lives and another score. At the start of the game initialise them so;
then whenever a live is lost
To get a projectile to gp to the player (let's assume its a sprite called gun) use
Let's see how you get on with that before attempting the rest.
then whenever a live is lost
and whenever you hit an invader for 10 ppoints say use
To get a projectile to gp to the player (let's assume its a sprite called gun) use
Let's see how you get on with that before attempting the rest.
- Susurration
-
10 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
Thank you for the help! 
Okay, I figured out why the projectile wasn't lining up with the sprite, it's just that the costume was oriented weird. Fixed that.
The scores seem to be working, but for some reason, the program doesn't register when touching the player sprite to decrease lives.
This is how I tried to approach it:
For the enemy sprites:
if touching Mouse1, then
change lives by -1
http://scratch.mit.edu/projects/12474150/#editor

Okay, I figured out why the projectile wasn't lining up with the sprite, it's just that the costume was oriented weird. Fixed that.
The scores seem to be working, but for some reason, the program doesn't register when touching the player sprite to decrease lives.
This is how I tried to approach it:
For the enemy sprites:
if touching Mouse1, then
change lives by -1
http://scratch.mit.edu/projects/12474150/#editor
- drmcw
-
1000+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
If you're going to use “if touch edge bounce” then you need to use the move block not change y. Your repeat loop is repeat until touching sprite 1 so that loop will only exit when the cat has been shot. You'll need to move the other if blocks inside that loop. I then foresee many more questions 

- joshuaho
-
1000+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
These are the scripts that you should use:
I hope this helps!
Last edited by joshuaho (Sept. 19, 2013 19:14:03)
- Susurration
-
10 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
Okay, thank you.
All of your suggestions have worked!
Does anyone have any ideas for the last few questions?
-I have successfully implemented left and right motion, but I would like to implement up-and-down motion as well. However, I want to limit this up-and-down motion to the bottom fifth of the stage. How would this be accomplished?
-I would to like implement timed levels that get progressively more difficult. So far, I'm thinking about around three.
-Another idea I had was creating a kind of “bomb” that could be used a limited number of times throughout the game that would destroy everything on the screen. This could only be used 1 or 2 times throughout the game.

Does anyone have any ideas for the last few questions?
-I have successfully implemented left and right motion, but I would like to implement up-and-down motion as well. However, I want to limit this up-and-down motion to the bottom fifth of the stage. How would this be accomplished?
-I would to like implement timed levels that get progressively more difficult. So far, I'm thinking about around three.
-Another idea I had was creating a kind of “bomb” that could be used a limited number of times throughout the game that would destroy everything on the screen. This could only be used 1 or 2 times throughout the game.
- drmcw
-
1000+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
Okay, thank you.All of your suggestions have worked!
Does anyone have any ideas for the last few questions?
-I have successfully implemented left and right motion, but I would like to implement up-and-down motion as well. However, I want to limit this up-and-down motion to the bottom fifth of the stage. How would this be accomplished?
-I would to like implement timed levels that get progressively more difficult. So far, I'm thinking about around three.
-Another idea I had was creating a kind of “bomb” that could be used a limited number of times throughout the game that would destroy everything on the screen. This could only be used 1 or 2 times throughout the game.
could be used when going up to limit movement..
For levels you'll need another variable and the broadcast block is your friend here. So you'd define a broadcast called “Start level” say and broadcast it when you want to start a level (set the level variable just before the broadcast). Then all the sprites/stage that need to be set for a level should have a “when I receive start level” and set themselves up appropriately, using the level variable if needed.
For the bomb then again a variable for the number of uses and set up a broadcast like “die”. If a bomb is available then broadcast die and have a when I receive die on anything that would be killed by the bomb.
Last edited by drmcw (Sept. 19, 2013 12:15:51)
- Reinfeld
-
41 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
I implemented many of these features in a game I made recently. Feel free to browse the thread here http://scratch.mit.edu/discuss/topic/15255/ and/or look at the code for any of the versions I posted. I left a number of versions “shared,” so you can see how I built the code/features over time.
I hope it can be of some help
I hope it can be of some help

Last edited by Reinfeld (Sept. 19, 2013 14:05:57)
- Disco-squid
-
4 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
Problem is that space invader making issue is that you need to do a massive cloning also using hard block to be able to generate faster than messages
- katscratch216
-
7 posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
I'm working on the same project. Thank you for asking. Hopefully this will help me.
- Jayden_cant_animate
-
1 post
Help with "space invaders" type game? Unsure about how to implement certain functions...
How do i make the bullets?
- pizza_king16
-
100+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
To make the player have lives you need to create a variable and call it lives. When the game starts it will need to get set to 3. Whenever the player touches the enemy/enemy projectiles, make the variable change by - 1. When it gets to 0 stop all
- pizza_king16
-
100+ posts
Help with "space invaders" type game? Unsure about how to implement certain functions...
To make the bullet/projectile go directly to the player, you need to make sure both the bullet and the player is centered exactly in the center.
- Discussion Forums
- » Help with Scripts
-
» Help with "space invaders" type game? Unsure about how to implement certain functions...