Last active
July 30, 2025 07:40
-
-
Save chrisoldwood/7bee57cd61c473ac274f36b75fbd5fbe to your computer and use it in GitHub Desktop.
Falling rocks game for the Microbit by my son
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#todo | |
#score, restart, speed/playability, winning? | |
from microbit import * | |
import random | |
import music | |
left_edge = 0 | |
right_edge = 4 | |
top_edge = 0 | |
bottom_edge = 4 | |
display.clear() | |
music.play(music.CHASE) | |
plr_x = 2 | |
plr_y = 4 | |
display.set_pixel(plr_x, plr_y, 9) | |
tick = 0 | |
lvl_spd = 10 | |
ship_cnt = 0 | |
ship_x = random.randint(left_edge, right_edge) | |
ship_y = top_edge | |
display.set_pixel(ship_x, ship_y, 7) | |
while True: | |
tick = tick+1 | |
if button_a.was_pressed(): | |
music.play(['g4:1'], wait=False) | |
display.set_pixel(plr_x,plr_y,0) | |
plr_x = plr_x - 1 | |
if plr_x < left_edge: | |
plr_x = right_edge | |
display.set_pixel(plr_x,plr_y,9) | |
if button_b.was_pressed(): | |
music.play(['a4:1'], wait=False) | |
display.set_pixel(plr_x,plr_y,0) | |
plr_x = plr_x + 1 | |
if plr_x > right_edge: | |
plr_x = left_edge | |
display.set_pixel(plr_x,plr_y,9) | |
if tick % lvl_spd == 0: | |
music.play(['g3:1'], wait=False) | |
display.set_pixel(ship_x,ship_y,0) | |
ship_y = ship_y + 1 | |
if ship_y > bottom_edge: | |
ship_x = random.randint(left_edge, right_edge) | |
ship_y = top_edge | |
ship_cnt = ship_cnt+1 | |
if ship_cnt == 3: | |
lvl_spd = lvl_spd-1 | |
ship_cnt = 0 | |
display.set_pixel(ship_x,ship_y,7) | |
if ship_x == plr_x and ship_y == plr_y: | |
display.show(Image.SAD) | |
music.play(music.PUNCHLINE,wait=False) | |
display.show("score = 0") | |
break | |
sleep(50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a game for the Microbit where you are a pixel at the bottom moving left-and-right to dodge the falling pixels which drop faster and faster over time.
This Gist contains the various evolutions of the game which my son essentially wrote in the summer of 2024, but with help from me as he was learning to program. (I don't know Python either so it may not be idiomatic 🙂.)