Created
March 10, 2023 00:28
-
-
Save jdc-cunningham/355c5b4c599f2dacad6ed7597eee51d4 to your computer and use it in GitHub Desktop.
Flappy Bird for Monocle AR
This file contains 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
import time | |
import touch | |
import display | |
bird_up = True # EricAndre | |
col_pos_x = 600 | |
bird_pos_y = 280 | |
game_over = False | |
def move_up(arg): | |
global bird_pos_y | |
bird_pos_y -= 20 | |
def move_down(arg): | |
global bird_pos_y | |
bird_pos_y += 20 | |
touch.callback(touch.A, move_up) | |
touch.callback(touch.B, move_down) | |
def draw_bird_up(): | |
y_pos = bird_pos_y | |
display.line(2, y_pos - 20, 22, y_pos + 20, 0xffa500) | |
display.line(22, y_pos + 20, 42, y_pos - 20, 0xffa500) | |
def draw_bird_down(): | |
y_pos = bird_pos_y | |
display.line(2, y_pos + 20, 22, y_pos - 20, 0xffa500) | |
display.line(22, y_pos - 20, 42, y_pos + 20, 0xffa500) | |
def flap(): | |
global bird_up | |
bird_up = not bird_up | |
if bird_up: draw_bird_up() | |
if not bird_up: draw_bird_down() | |
def render(): | |
display.show() | |
def draw_column(): | |
global col_pos_x | |
col_pos_x -= 15 | |
display.vline(col_pos_x, 0, 160, 0xffffff) | |
display.hline(col_pos_x, 160, 100, 0xffffff) | |
display.vline(col_pos_x + 100, 0, 160, 0xffffff) | |
display.vline(col_pos_x, 240, 180, 0xffffff) | |
display.hline(col_pos_x, 240, 100, 0xffffff) | |
display.vline(col_pos_x + 100, 240, 180, 0xffffff) | |
def draw_game_over(): | |
display.text("GAME OVER", 200, 175, 0xffa500) | |
def check_game_over(): | |
global game_over | |
if ((bird_pos_y < 180 or bird_pos_y > 220) and col_pos_x < 90): | |
game_over = True | |
scenes = 60 | |
for scene in range(scenes): | |
check_game_over() | |
if (game_over): | |
draw_game_over() | |
render() | |
break | |
flap() | |
draw_column() | |
render() | |
time.sleep(0.001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment