space invaders game
play

Space Invaders Game Instructions Set up the Environment Delete - PowerPoint PPT Presentation

Space Invaders Game Instructions Set up the Environment Delete Scratchy Sprite (right click, delete) Create backdrop Select Backdrop from tabs Edit it Make it completely black If you want, add some stars (small white dots)


  1. Space Invaders Game Instructions

  2. Set up the Environment • Delete Scratchy Sprite (right click, delete) • Create backdrop • Select Backdrop from tabs • Edit it • Make it completely black • If you want, add some stars (small white dots) to the backdrop • Create new sprite for ship • Import “ship” from the USB drive • Create missile sprite • Import “arrow” from the USB drive

  3. Concepts • Space Invaders has a lot of different objects on the screen • The aliens • The ship that shoots • The missile that the ship shoots • Each item has their own set of events • It’s kind of like each has a mind of their own! • When you want to make an object do something, make sure you are creating events and actions in that specific sprite

  4. Game Play – Events for your space ship • Right Arrow • Move 5 steps to the right • Left Arrow • Move 5 steps to the left

  5. Space Ship Code

  6. Game Play – Events for your arrow • When Space Bar Clicked you want the arrow to shoot up the screen • How do you do this? • Create space key hit event for this sprite • Repeat 40 times • Change Y by 10 • This moves the arrow up the screen in increments of 10 • BUT • You want the arrow to come out of the space ship so use a secret command • Go to Ship! • You could speed it up or slow it down • How?

  7. Arrow Code

  8. Creating an Alien • Import Sprite Invader1 from the USB drive • Place on top left of screen

  9. Moving the Alien • Aliens move back and forth on their own so • You need to programmatically determine their direction • Create a variable called direction • Start the Alien at position -201, 120 • Set direction = 10 (that’s 10 steps to the right) • In a forever loop • If the x position > 200, move the Alien down 25 spaces and change the direction to -10 (that’s 10 steps to the left) • Likewise, if the x position < 200, move the Alien down 25 spaces and change the direction to 10 (that’s 10 steps to the right)

  10. Moving the Alien • When you run this, the Alien goes across the screen in a very smooth way • This will make shooting him hard so • Let’s add a pause after he moves • Command is wait • Do it for .5 seconds • You might want to also wait when you move the alien down a row

  11. Moving the Alien - Code

  12. Shooting the Alien – SCORE! • When you shoot the arrow at the Alien, you should score a point • The Alien should also die and disappear from the screen • Steps • Create a variable called score and initialize it to 0 when the game starts • In the Alien sprite, create a script that is executed when the flag is clicked (yes, you now have 2 flag clicked events) • Check to see if the arrow and Alien are touching and if they are • Increment the score by 1 • Hide the Alien sprite

  13. Score! - Code

  14. Add More Aliens! • Duplicate or Clone the Aliens • But • You will need to move the new Aliens to a new starting position • What X position (recommend they are 50 spaces apart and 25 spaces on the Y axis) • Create a few rows • What happens?

  15. Personalize Your Game • Want to stop here and perfect your game play? • Do the aliens move the way you want them to move? • If not, change it now • Does the missile move fast (or slow) enough? • If not, change it now • Do you have enough aliens? • Too close together? • Too far apart? • Make the game your own!

  16. Taking Your Game to the Next Level Advanced Concepts

  17. Making Everyone Do the Same Thing at the Same Time…Broadcast • When you put multiple rows of Aliens on your screen, they centipede down the screen. We need our Aliens to all move at the same time! • Do this using a Broadcast message • Create a Broadcast called moveDown • Instead of moving down and changing direction, simply call moveDown

  18. The moveDown Event

  19. But Something is Wrong… • The Aliens are going crazy on the screen! • Why? • Aliens do not change direction until they read the end of the screen • So you still get crazy behavior • How do you fix this?

  20. Fixing the Aliens - Code

  21. Problem 2 – Magic Bullets! • If you have multiple rows of Aliens, one bullet seems to kill more than one Alien. Let’s make the game harder. • Once you hit an Alien, the bullet needs to stop • Create a Broadcast called hitAlien and call it when an Alien is hit • In the Arrow scripts, add a variable called stopFire. When this is set to 0, let the bullet continue. When it is set to 1, the bullet will stop. • When we receive the hitAlien Broadcast, set stopFire to 1 • In the space key event • Show the Arrow • Set stopFire to 0 • In the repeat, check if stopFire is 1. If it is, hide the bullet and stop this script.

  22. Fixing the Magic Bullet - Code

  23. Adding Barriers • Let’s add some barriers so we can hide from Alien fire! • A barrier will protect us from Alien fire (will absorb the missile) but will also absorb fire from the ship • Use Sprite barrier from the USB drive • Place on screen • Adjust arrow to sense the barriers • If it is touching the arrow, stop the bullet, just like you did when you hit an Alien!

  24. Barriers - Code

  25. What if the Alien Could Shoot? • Let’s make the Aliens drop bombs • If a bomb hits the ship, the game is over • How to do this • Import sprite alienFire from the USB drive • The alienFire sprite will receive two broadcasts that you will create • alienFire (when an Alien fires a missile – this happens every time it moves) • stopAlienFire (when the missile hits something) • The Barrier sprite will need to broadcast stopAlienFire when it touches the bomb • The Ship sprite needs to broadcast stopAlienFire when it touches the bomb and it needs to end the game

  26. Code Samples

  27. More Code Samples

  28. Ghost Aliens! • We made it so one alien is shooting, but • What happens if that alien is shot? • He still shoots! He’s a ghost shooter! • How do we fix this? • Create a variable called alienVisible and set it to 1 • When the alien is shot (and hidden) change this to 0 • Before you fire, check alienVisible and ONLY shoot if it equals 1

  29. The Code

  30. Personalize It • Which aliens should be shooting at the ship? • Change this around if you want

  31. Other Things to Try • There are more graphics on the USB drive • Want to change the alien’s appearance as they move across the screen? • Add sounds • Give your ship multiple lives and end the game once all lives have been used • Add more barriers

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend