- May
Posted By : Dave Hartburn
Project: Neopixel game

Given what we have learned about controlling the joystick and neopixel hardware in Micro:bit Joystick Module and Micro:bit Neopixels, can we construct a simple game? We need to consider the hardware, animation, random position generation and collision detection.

Step 1: Construct the hardware. Can you connect both the Neopixel grid and the joystick to the micro:bit? Is there any testing we can do to make sure they work?

Step 2: Start the game by positioning the ‘player’ in the top left corner. Pick a colour for the player and light up that LED. Be sure to use variables to describe the player position as we are going to move this soon.

Step 3: Can we move the player around with the joystick? In a loop detect joystick movement then adjust the coordinates of the players position accordingly. Be sure to put a delay in the loop, otherwise the player will move very fast! What happens when the player reaches the edge of the display? Can we stop the player leaving the screen?

Step 4: Can you make something happen to the player when you press the joystick down? Perhaps flash?

Step 5: Using a random number generator, can you put some ‘food’ at a random point on the screen? How can we check this food does not land on top of the player? Do we need to store the food coordinates for when we redraw the screen?

Step 6: Now lets look at collision detection. Can you detect when the player lands on the food? Can it ‘eat’ the food and then new food appears at another random location? Can you keep a score of food eaten on the micro:bit LEDs? End the game when the you reach 10 bits of food.

Step 7: Can you make the game more interesting or use what you have learned to make a different game? What if there were two players taking it in turn to move? What if the food made the player grow like a worm? Could painting the screen a different colour be part of the game?


Leave a Reply