Hello, this week I am going to make a catching apples game through a micro:bit. Let’s see how it works below:
Drag the sprite bricks in the MakeCode drawer.
Create two sprites(One as the falling apple, another as the basket to catch the apples)
In on start brick, set the basket at the bottom side by fixing Y as 4 and X at a random value, here we assign 0 to it. And we set the apple at the top side by fixing Y as 0 and X at a random value (here we assign 0 to X).
Movement of the basket: Control it via the buttons and set them as below:
Apple’s movement: After powering on, it moves down from the position (0,0). During this process, only the Y coordinate changes, while the X coordinate maintains the original value. To fall to the bottom, it needs to change to 1, 2, 3 and 4(four times in total), thus we use repeated execution in four times and increase its Y coordinate by 1. In this way, an apple lands off. After one finished progress, another needs to follow, set the Y coordinate of this sprite to 0 (back to the top), and take a random number from 0 to 4 for the X coordinate. In this way, when the apple returns to the top, it locates randomly and is displayed on the top 5 LED lights.
By judging whether the two sprites are in contact, you would know if the apple is catched(Here I give a sound feedback once the apple gets catched by the basket).
Completed program:
https://makecode.microbit.org/_VLP1ijMebJuF
If you have any ideas or opinions, please feel free to contact us via [email protected].