Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computer Science Space School 2015 Programming a Lunar Lander Game.

Similar presentations


Presentation on theme: "School of Computer Science Space School 2015 Programming a Lunar Lander Game."— Presentation transcript:

1 School of Computer Science Space School 2015 Programming a Lunar Lander Game

2 School of Computer Science Programming Program –Series of instruction for a computer to follow Programming Language –Precise language designed to give instructions to computers –Very strict rules and vocabulary –Can be read and understood by people –May need to be compiled first so computer can understand it

3 School of Computer Science Programming Languages In Space missions –Apollo: AGC Assembly –Space Shuttle: HAL/S –Ariane 5: ADA At St Andrews –First year: Java –Second year: C, Haskell, assembly language –Third & Fourth year: Depends on chosen modules After graduation –Whatever your employer decides! Today –Scratch

4 School of Computer Science Your task Write a simple Lunar Lander Game –Learn how to build a program in Scratch –Become familiar with some basic programming structures –Understand the impact of changes in code on behaviour of program –And of course… Have some fun!

5 School of Computer Science What is Scratch? Visual Programming Language –Drag-and-drop –Easy to learn –Powerful Create –Interactive stories –Games –Animations

6 School of Computer Science How Does Scratch work? Create Backdrops –Still background images Create Sprites –Images / characters Control each sprite with a script –Drag-and-drop blocks to build your script –Blocks fit together like jigsaw pieces –Almost no typing! Run your program –Watch the results on the stage

7 School of Computer Science Stage Sprites Blocks Script Scratch Editor Backdrops

8 School of Computer Science Lunar Lander Backdrop Select the Space Theme Choose the space backdrop Find the Backdrops section –bottom left of the window Choose backdrop from library

9 School of Computer Science Sprites Find the Sprites section Remove the cat sprite –Right-click -> delete Choose sprite from library Select the Space Theme Choose the Spaceship Select the Things Category Choose the Rocks

10 School of Computer Science Sprites (2) Add 3 more Rocks Paint your own landing pad Draw 2 short horizontal lines –Choose 2 bright colours

11 School of Computer Science Sprites (3) Arrange the sprites on the stage Shrink the Spaceship –Select Shrink from the toolbar –Click on the Spaceship on the stage

12 School of Computer Science Moving the Spaceship Want to simulate what it is like to move in space Activate lateral thrusters to move ship left or right –Will not stop until it hits something! Activate vertical thrusters to move ship upwards –Has to fight against gravity –With no thrust it will fall to the ground faster and faster! The more thrust the faster the movement

13 School of Computer Science Moving the Spaceship Need to store: –Our lateral movement –Our vertical movement When left/right arrow is pressed –Decrease/increase the lateral movement When up arrow is pressed –Increase the vertical movement As time passes –Decrease the vertical movement to simulate gravity

14 School of Computer Science Adding Script Make sure the Spaceship is selected Make sure the Scripts tab is selected

15 School of Computer Science Adding Variables Make a new variable to store lateral thrust Select Data –Click Make a Variable –Type lateral_thrust –Click OK Make another new variable to store vertical thrust

16 School of Computer Science Vertical Movement: Gravity Start program when green flag is pressed Select Events –Drag-and-drop When clicked onto the script panel Select Data –Drag-and-drop Set vertical_thrust to 0 Select Control –Drag-and-drop a forever block

17 School of Computer Science Vertical Movement: Gravity (2) Select Data –Drag-and-drop Change vertical_thrust by 1 –Change value to -0.1 Select Motion –Drag-and-drop Change y by 10 Select Data –Drag-and-drop vertical_thrust Run your program by clicking the green flag above the Stage

18 School of Computer Science Vertical Movement: Thrust Move up when up arrow is pressed Select Events –Drag-and-drop When space key pressed –Change to up arrow Select Data –Drag-and-drop change vertical_thrust by 1 –Change value to 0.5 Run your program –press up arrow to see what happens!

19 School of Computer Science Lateral Movement Move sideways when left or right arrow is pressed Select Data –Drag-and-drop Set vertical_thrust to 0 –Change to lateral_thrust Select Motion –Drag-and-drop Change x by 10 Select Data –Drag-and-drop lateral_thrust

20 School of Computer Science Lateral Movement: Left Move left when left arrow is pressed Select Events –Drag-and-drop When space key pressed –Change space to left arrow Select Data –Drag-and-drop change vertical_thrust by 1 –Change values to lateral_thrust and -0.5 Run your program –press left arrow to see what happens!

21 School of Computer Science Lateral Movement: Right Move right when right arrow is pressed Select Events –Drag-and-drop When space key pressed –Change space to right arrow Select Data –Drag-and-drop change vertical_thrust by 1 –Change values to lateral_thrust and 0.5 Run your program –press right arrow to see what happens!

22 School of Computer Science Game Over So far… –Ship falls with gravity –Ship controlled with up, left & right arrow keys Game never finishes –forever block keeps going forever Need to stop repeating once our end conditions are met –Ship lands on landing pad - Win –Ship crashes into rocks - Lose

23 School of Computer Science You Win! End game when ship lands on landing pad Drag-and drop blocks out of forever Drag-and-drop the forever from script panel to blocks panel Select Control –Drag-and-drop repeat until Drag-and-drop blocks into repeat until

24 School of Computer Science You Win! (2) Select Sensing –Drag-and-drop touching color –Click on the little coloured box –Click on the bottom colour of your landing pad Select Looks –Drag-and-drop Say Hello! –Change to Yay! You win! Run your program –Try to land on the pad

25 School of Computer Science You Lose! End game when ship hits rocks Select Operators –Drag-and-drop or onto repeat until –Drag-and-drop touching color onto or

26 School of Computer Science You Lose! (2) Select Sensing –Drag-and-drop touching color –Click on the little coloured box –Click on the light-grey of the rocks

27 School of Computer Science You Lose! (3) Select Control –Drag-and-drop if then else –Duplicate touching color –Drag-and-drop onto if then else Select Looks –Drag-and-drop Say Hello! –Change to Oh No! You crashed!

28 School of Computer Science Finished!

29 School of Computer Science Challenges See if you can do any of the following: Make sure the ship is at the top each time the game starts Make the ship drift to the left or right when the game starts Only say You Win if the ship’s vertical speed is less than 2 Make ship use fuel – when you run out you cannot use thrusters Add an alien flying across the screen – if the ship hits it you lose

30 School of Computer Science Hints Make sure the ship is at the top each time the game starts –Hint: set the ship’s y before the repeat until Make the ship drift to the left or right when the game starts –Hint: set lateral thrust to a non-zero number before the repeat until Only say You Win if the ship’s vertical speed is less than 2 –Hint: you need another if then else after the repeat until

31 School of Computer Science Hints Make ship use fuel – when you run out you cannot use thrusters –Hint: you need another variable. Check it before changing thrust and reduce it after you change thrust Add an alien flying across the screen – if the ship hits it you lose –Hint: you need another sprite with its own script to make it move. –Hint: Add another condition to the spaceships repeat until to check whether it is touching the alien sprite


Download ppt "School of Computer Science Space School 2015 Programming a Lunar Lander Game."

Similar presentations


Ads by Google