How to make Space Invaders In Scratch (based on the program by eeb3...

14
How to make Space Invaders In Scratch (based on the program by eeb3 http://scratch.mit.edu/projects/eeb3/708899 ) You can find other excellent programs there and download them…

Transcript of How to make Space Invaders In Scratch (based on the program by eeb3...

Page 1: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

How to make Space Invaders

In Scratch(based on the program by eeb3

http://scratch.mit.edu/projects/eeb3/708899)You can find other excellent programs there and download them…

Page 2: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Space invaders model

• Your “ship” is moving on the screen’s floor• The invaders go left and right, while

descending on your ship• You shoot with missiles and try to take them

out – in this game you get 4 missile launchers: A, S, D, F controlled by their keys

• You play is timed

Page 3: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Programming

• You only really program:– The “ship”– One of the “aliens”– One of the “missiles”– Reminder which keys to use– “Game over” message

• Then you duplicate the aliens and the missiles and slightly modify them

Page 4: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

The overall look of the project

Page 5: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Let’s start with the “ship”Reset the ship on the click of the flagBroadcasting “go” sets aliens moving

When the game is restarted, all messages (“say”) are cleared, all points are cleared, the timer is reset, the now dead invisible ship is shown again and sent to the front layer

Page 6: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

The main block of the “ship” code:Don’t forget to call it “Space Ship”, there are no other costumes in this game

The game is won if 500 points reached and it restarts then

As you can see, there 5 almost identical blocks of code. Each “IF” deals with touching an alien and dying from it. Remember: you can right click on the IF and choose “duplicate”, rather than make them all from scratch…

Page 7: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

The rest of the “Ship’s” code- moving around

Both of these blocks control movement left and right. Ignore the “play sound” as we don’t have speakers installed. However, if you game is otherwise complete, you can ask your teacher for headphones and try to include the sounds.

Again, a good idea is to right-click the first block and duplicated, then replace what’s needed.

Page 8: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Alien 1 – see the next slide for details

Page 9: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

When the game is started or restared, aliens get reset, too – placed in a particular spot and made visible again

The creator of this program could have combined these two blocks but professional programmers like to break their programs in smaller parts which can be individual fixed or adjusted.

If a missile touches the alien then this alien gets hidden and the player’s points increase. There are four missiles that can be launched (if we only had one missile we would have to wait for it to go off the screen before we can launch another one – not good)

Page 10: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

The broadcast of “go” also makes this alien move and turn around, and descend on the ship.Notice that this particular script doesn’t care about touching walls or anything like that.

Note the “nested repeats” – one repeat inside the other, inside the other again…. You might not need that many since you are not trying to make the aliens beep every few steps…

Alien moving back…

Alien turning sideways to make him harder to hit with missiles

Page 11: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Missile A – see the next slide for a closer view at the blocks

Page 12: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Missile A blocks

Take simple go to x, y and instead of numbers insert positions from Sensing

This makes the missile start its travel from whatever coordinates the ship is when it fires

The missile disappears when it reaches the end of the screen, after becoming invisible, the signal is broadcast “a clear” so that the missile can become available for firing again.

Missile available to be fired at start of game

Page 13: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

Key usage hint – remind player to use A to fire the first missile launcher

When the ”A” missile is fired, it becomes unavailable and the hint is hidden

Once the missile reaches an alien or edge of screen, the missile is clear to be launched again, so the hint is shown again.

You will need a variable to keep track of the Points scored

Page 14: How to make Space Invaders In Scratch (based on the program by eeb3 //scratch.mit.edu/projects/eeb3/708899)

The End

• Extension activities:– Change the background from simple black to the

starry sky– More missiles that can be launched at the same time– Big Bad Boss that descends faster than regular aliens– Aliens change their costume to “explosion” for a

second when hit with a missile before becoming invisible

– Next level – change the shapes of aliens– Aliens firing back!