Since the “Burger” is gone after being eaten, we need it to reappear. The method is simple: just create another burger. Besides setting its position, remember to set its “Kind” correctly so it meets the “Overlap Conditions.”

However, you will notice the burger always appears in a fixed spot. In a normal game, it should be “Randomly Generated” in different places. We can find the convenient block “pick random ( 0 ) to ( 10 )” within the “Math” category in the Block Toolbox.

We can fill in two numbers, and it will randomly generate a new number between them. Quick thinkers might already know what to use this for!

That’s right! We can use it to “Generate Coordinates.” Place this block into the x and y coordinate fields respectively. Fill in the ranges: 0~160 for the x-coordinate and 0~120 for the y-coordinate (based on screen pixel size).

After finishing, run it in the Game Simulator. Test it a few times, and you might notice that sometimes the burger disappears or gets stuck, as shown below:

This is because we didn’t restrict it to appear strictly within the visible screen area. We can use the “set [mySprite] stay in screen <ON>” block found in the “Sprites” category.

Place this block after the “create sprite” block. This adds a restriction immediately when the burger is created, so it won’t go out of bounds when randomly positioning.
Remember to select the correct Variable Name (the target) at the beginning of the block.

Test it in the Game Simulator.

We have completed the scoring and random spawning functions, but the game feels a bit empty. Let’s add some sound! Specifically, when the burger is eaten. Add the “Music” block we learned earlier to the destruction event. You can find a suitable sound effect or design one yourself.

While you’re at it, add some background music to enrich the game presentation. Remember to set the “looping” option to “true” for continuous playback.

Adding a Challenge: The Countdown Gaining points endlessly without a result isn’t a game. Let’s add an element of excitement: a “Countdown Timer.” We will set a rule: if the score doesn’t meet the target when time runs out, the player loses.
Drag out the “start countdown ( 10 ) seconds” block from the “Info” category.

Place this block at the very bottom of the “on start” block. This means the countdown begins just as the game starts. Feel free to set the duration.

Then, we need to determine the result when the timer ends. Drag out the “on countdown end” block from “Info” and place it in the Workspace (empty area).

Next, we need to judge if our score meets the target. Drag out the “if… then… else” block from “Logic” and place it inside “on countdown end.”

Drag out the “score” block (the oval shape) from “Info.” This block stores our current score.

To compare the score, we need a “Comparison” block. Drag out the “< ( 0 ) = ( 0 ) >” block from “Logic.”

Combine these three blocks. In the dropdown menu of the comparison block, select “>” (greater than).

Choose your own target score.

Finally, the most critical block: select “game over <LOSE>” from the “Game” category. The option at the end determines whether the game is won or lost.

Add the different “Results” (Win/Lose) into the condition slots sequentially. Now, an exciting and fun game is complete!!🎉🎉🎉
