flappyyy.py

Created by 4244

Created on August 28, 2025

1.74 KB

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)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.