Adding A Timer and WIN!

You will be adding a timer and score to your game. The timer will count down from 25. When you reach the penguin, the cat will meow and say, “I Win!"

  • If you touch the rock the game ends.

  • If the timer gets to 0 before you reach the penguin, the game ends.

BE SURE TO SAVE YOUR WORK AS YOU COMPLETE EACH STEP!

Step 1: Create a timer variable.

  • Click on Variables.

  • Click "Make a Variable".

  • Name it "Timer" and select "For all sprites".

Step 2. Set the Time to 25.

  • Click the rock sprite.

  • EVENTS →Drag when green flag clicked.

  • Variables →Drag Variable “set timer to (25).” You will find “timer” in the drop down menu.

  • Control →Drag a Forever block.

  • Inside the forever block drag two more blocks.

    • Control → “wait (1) seconds.”

    • Variable →k “change timer by (-1)”

      • Test the game. You should see the timer counting down from 25 to 0 as long cat does not touch the rock. If the cat touches the block, the timer will stop.

Step 3: Add the Penguin.

  • Click on the spite icon.

  • Find the penguin and click on it.

  • Move the penguin to the right side of the stage as shown.

  • You do not need to code the penguin because it never moves.

Step 4: Set How to Win the Game

  • Click the Cat Sprite.

  • Motion→Move the cat to the left side of the stage. Replace the “go to x:” with a new “go to” block to show the new position on the left.

  • Control →Drag a “if - then” block.

  • Sensing → Drag "touching" and choose “penguin” from the drop down menu.

  • Sound→ Drag "play sound" and choose “meow” from the drop down menu.

  • Looks→ Drag “say” and type “I Win!” and choose 2 seconds.

  • Test the code.

Step 5: Moving the Cat Forward

  • Click the Cat Sprite.

  • Motion → Drag "change x by" and fill in 50. This will move the cat forward 50 pixels each time it goes down.

  • Play the game to test your code.

Step 6: Stop the Timer

You have one last step to take. You need to stop the timer at 0 so you can play the game again and try to win.

  • Click the Cat Sprite.

  • Motion → Drag "change x by" and fill in 50. This will move the cat forward 50 pixels each time it goes down.

  • Play the game to test your code.

GOOD JOB!

You have now made your first working game. Here are some things you can do to “remix,” or make the game your own.

  • Choose a different spite to replace the cat. Drag all of the coding for the cat to the new sprite. You should see your new sprite on the stage. Click on the cat and then click the trash can.

  • Choose a sprite to replace the penguin. Click on the penguin and then the trash can.

  • Choose a spite to replace the moving rock. Click on the rock. Drag the rock’s coding to the new sprite. Click the trash can on the rock sprite. Delete the rock by clicking the trash can.

  • Change the background.

  • Play the game!

    Now you have a game that is designed and coded completely by you!

Well done! You’ve made your first game!

Wrap Up

With this lesson you learned:

1) how to add a timer variable,

2) how make a sprite move forward,

3) how to set up a game win.

Learning Check