wavegd.py

Created by maelg0000

Created on February 25, 2026

2.65 KB


from ion import keydown, KEY_UP, KEY_OK
import kandinsky
import random
import time

# -------------------------------------------------
# CONFIG
# -------------------------------------------------
W, H = 320, 222

PLAYER_X = 60
SIZE = 8
SPEED = 4

BLACK = kandinsky.color(0,0,0)
CYAN  = kandinsky.color(0,255,255)
WHITE = kandinsky.color(255,255,255)
RED   = kandinsky.color(255,0,0)

# -------------------------------------------------
# INIT
# -------------------------------------------------
kandinsky.fill_rect(0,0,W,H,BLACK)

player_y = H//2
ceiling = 20
floor = H-20

walls = []   # [x, gap_y, gap_h]
spawn_timer = 0
score = 0

running = True

# -------------------------------------------------
# GAME LOOP
# -------------------------------------------------
while running:

    # --------- INPUT (45° parfait) ----------
    if keydown(KEY_UP) or keydown(KEY_OK):
        player_y -= SPEED
    else:
        player_y += SPEED

    # --------- COLLISION plafond/sol ----------
    if player_y < ceiling or player_y+SIZE > floor:
        running = False
        break

    # --------- SPAWN MURS ----------
    spawn_timer += 1
    if spawn_timer > 35:
        spawn_timer = 0
        gap_h = 60 - score//5
        if gap_h < 30:
            gap_h = 30
        gap_y = random.randint(ceiling+5, floor-gap_h-5)
        walls.append([W, gap_y, gap_h])

    # --------- DEPLACEMENT MURS ----------
    i = 0
    while i < len(walls):
        walls[i][0] -= SPEED
        if walls[i][0] < -20:
            walls.pop(i)
            score += 1
        else:
            i += 1

    # --------- DESSIN MURS (scroll propre) ----------
    # on efface seulement la colonne droite
    kandinsky.fill_rect(W-SPEED, 0, SPEED, H, BLACK)

    for w in walls:
        x, gap_y, gap_h = w

        # partie haute
        kandinsky.fill_rect(x, ceiling, 18, gap_y-ceiling, WHITE)

        # partie basse
        kandinsky.fill_rect(x, gap_y+gap_h, 18, floor-(gap_y+gap_h), WHITE)

        # collision
        if PLAYER_X+SIZE > x and PLAYER_X < x+18:
            if player_y < gap_y or player_y+SIZE > gap_y+gap_h:
                running = False

    # --------- DESSIN PLAFOND / SOL ----------
    kandinsky.fill_rect(0, ceiling, W, 2, WHITE)
    kandinsky.fill_rect(0, floor-2, W, 2, WHITE)

    # --------- TRAINÉE SOLIDE (NE S’EFFACE JAMAIS) ----------
    kandinsky.fill_rect(PLAYER_X, player_y, SIZE, SIZE, CYAN)

    # --------- SCORE ----------
    kandinsky.draw_string("S:"+str(score), 5, 5, WHITE, BLACK)

    time.sleep(0.016)

# -------------------------------------------------
# GAME OVER
# -------------------------------------------------
kandinsky.draw_string("GAME OVER", 100, 100, RED, BLACK)

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.