hui
# Type your text here# FLAPPY voor MicroPython (TV formaat scherm 320x240 of 240x240 afhankelijk toestel) import time, random from ti_draw import screen, clear, pixel, text, update # fictieve drawable API - pas aan naar jouw device W, H = 240, 128 bird_x = 40 bird_y = H//2 vel = 0 gravity = 0.7 jump = -8 pipes = [] score = 0 SPAWN = 70 def spawn_pipe(): gap_y = random.randint(20, H-40) pipes.append({'x':W, 'gap_y':gap_y, 'w':20}) def draw(): clear() # vogel pixel(bird_x, int(bird_y)) # pijpen for p in pipes: for y in range(0, p['gap_y']-20): for x in range(p['w']): pixel(int(p['x'])+x, y) for y in range(p['gap_y']+20, H): for x in range(p['w']): pixel(int(p['x'])+x, y) text(2,2,"Score: {}".format(score)) update() spawn_pipe() t0 = time.ticks_ms() while True: # input: toets omhoog (voorbeeld: button A) — pas aan naar jouw API if screen.get_button_up(): # Vervang met juiste API vel = jump vel += gravity bird_y += vel # verplaats pipes for p in pipes: p['x'] -= 2 # spawn if pipes==[] or pipes[-1]['x'] < W - SPAWN: spawn_pipe() # verwijder afgegleden pipes + score if pipes and pipes[0]['x'] < -pipes[0]['w']: pipes.pop(0) score += 1 # botsing detectie (vereenvoudigd) for p in pipes: bx = bird_x if p['x'] < bx < p['x'] + p['w']: if not (p['gap_y']-20 < bird_y < p['gap_y']+20): text(50, H//2, "GAME OVER") update() raise SystemExit if bird_y < 0 or bird_y > H: text(50, H//2, "GAME OVER") update() raise SystemExit draw() time.sleep(0.03)