Level 05 Lesson 01 [Timing Things with Counters and Alarms]

In the previous lesson/s you used random numbers in the step event to make objects perform tasks at random times. But sometimes you want an object to perform a task at specific time intervals. This lesson will cover two popular methods for making objects ‘time’ their actions.

Part A – Using Counters
Watch the video:  05-01-A
Donefile:  L05-01-A-Done.gmk


Challenge 1– Redo the Video without watching

Grab the pre-made starting file
L05-01-StartHere.gmk

Re-add the these three tasks that were showing in the lesson video. If you have trouble, re-watch the video.

a) paddle will fire a ball every one second
b) player is limited to firing every 15 steps
c) bomb will explode 2 seconds after it is created

Challenge 1 Solution
Solution: Watch the video again! These tasks are very commonly used, and very useful to know. Practice until you can do it without using the video for help.


Part B – Using Alarms
Watch the video:  05-01-B
Donefile: L05-01-B-Done


Challenge 2 – Alarm Tasks

Continue adding to the file from the end of the video lesson
L05-01-B-Done.gmk

Add the following using alarms:

a) make a ball add 30 degrees to its direction every 15 steps. This should make it move in a circle-ish (not a real word) shape.  Use the line direction = direction + 30  to make the ball’s direction change.

b) After the old man presses the “D” key, he will self destruct in 3 seconds.

c) Make it so that the left and right arrow keys make the man move at a speed of 1 to the left and right. Now limit the use of the keys so that they can only be used after waiting 3 seconds. For example: if the user presses the right arrow key, they will start to move right BUT the arrow keys will not work again until 3 seconds has past. Run the completed project if you’re not sure you understand!

Challenge 2 Solution
Solution Video: 05-01-X2Solution
Solution File: L05-01-X2-Done.gmk


Challenge 3 – Repeat with Counters

Remember those last three tasks you did with alarms? Repeat them with counters instead. Task two (the destruction of the man) might be trickier than you think, be creative! So open up
L05-01-B-Done2.gmk
and see if you can repeat these tasks using counters (no alarms!).

Challenge 3 Solution
Solution Video: 05-01-X3Solution
Solution File: L05-01-X3-Done.gmk