140 likes | 588 Vues
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…. Space invaders model. Your “ship” is moving on the screen’s floor
E N D
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…
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
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
Let’s start with the “ship” Reset the ship on the click of the flag Broadcasting “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
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…
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.
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)
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 turning sideways to make him harder to hit with missiles Alien moving back…
Missile A – see the next slide for a closer view at the blocks
Missile A blocks This makes the missile start its travel from whatever coordinates the ship is when it fires Take simple go to x, y and instead of numbers insert positions from Sensing 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
Key usage hint – remind player to use A to fire the first missile launcher You will need a variable to keep track of the Points scored 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.
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!