Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

jeu numworks

from kandinsky import *
from ion import *
from random import randint

# --- CONSTANTES ---
W, H = 320, 240
LANES = [-70, 0, 70]
PLAYER_Y = 170

# --- SKINS (nom, couleur, prix) ---
skins = [
    ["JAUNE", color(255,200,0), 0],
    ["BLEU", color(0,200,255), 100],
    ["ROUGE", color(255,80,80), 200],
    ["VERT", color(180,255,100), 300],
]
unlocked = [True, False, False, False]
skin = 0

# --- VARIABLES ---
lane = 1
speed = 3
ultra = False
score = 0
best = 0
money = 0

obstacles = []
coins = []

jump = 0
slide = 0

# --- COULEURS ---
BG = color(10,10,30)
OBSTACLE = color(255,50,50)
COIN = color(255,220,0)

# --- ROUTE ---
def road_color(y):
    c = min(255, 40 + y + speed*8)
    return color(c//2, c//2, c)

def draw_road():
    for y in range(0, H, 20):
        fill_rect(0, y, W, 20, road_color(y))

# --- PLAYER ---
def draw_player():
    x = W//2 + LANES[lane]
    h = 30 if slide else 50
    y = PLAYER_Y - (30 if jump else 0)
    fill_rect(x-10, y-h, 20, h, skins[skin][1])

# --- OBSTACLES ---
def spawn_obstacle():
    obstacles.append([randint(0,2), -40, randint(0,1)])

def draw_obstacles():
    global obstacles
    new = []
    for o in obstacles:
        o[1] += speed
        if o[1] < H:
            size = 20 + o[1]//6
            x = W//2 + LANES[o[0]] - size//2
            y = o[1] - (30 if o[2] else 0)
            fill_rect(x, y, size, size, OBSTACLE)
            new.append(o)
    obstacles = new

# --- COINS ---
def spawn_coin():
    coins.append([randint(0,2), -30])

def draw_coins():
    global coins, money
    new = []
    for c in coins:
        c[1] += speed
        if c[1] < H:
            size = 12 + c[1]//8
            x = W//2 + LANES[c[0]] - size//2
            y = c[1]
            fill_rect(x, y, size, size, COIN)
            if c[0] == lane and PLAYER_Y-30 < y < PLAYER_Y+20:
                money += 10
            else:
                new.append(c)
    coins = new

# --- COLLISION ---
def collision():
    for o in obstacles:
        if o[0] == lane:
            if jump and o[2] == 0: continue
            if slide and o[2] == 1: continue
            if PLAYER_Y-40 < o[1]+30 < PLAYER_Y+10:
                return True
    return False

# --- MENU ---
while True:
    fill_rect(0,0,W,H,BG)
    draw_string("SUBWAY RUNNER", 90, 30, color(255,255,255))
    draw_string("SKIN :", 130, 80, color(200,200,200))
    draw_string(skins[skin][0], 130, 110, skins[skin][1])

    if not unlocked[skin]:
        draw_string(str(skins[skin][2])+" COINS", 110, 140, COIN)
        draw_string("OK POUR ACHETER", 80, 170, color(255,255,255))
    else:
        draw_string("OK POUR JOUER", 95, 170, color(255,255,255))

    draw_string("COINS:"+str(money), 5, 210, COIN)

    if keydown(KEY_LEFT):
        skin = (skin-1) % len(skins)
    if keydown(KEY_RIGHT):
        skin = (skin+1) % len(skins)
    if keydown(KEY_OK):
        if unlocked[skin]:
            break
        elif money >= skins[skin][2]:
            money -= skins[skin][2]
            unlocked[skin] = True

# --- JEU ---
while True:
    obstacles = []
    coins = []
    score = 0
    speed = 3
    ultra = False
    jump = 0
    slide = 0

    while True:
        fill_rect(0,0,W,H,BG)
        draw_road()

        # INPUT
        if keydown(KEY_LEFT) and lane > 0: lane -= 1
        if keydown(KEY_RIGHT) and lane < 2: lane += 1
        if keydown(KEY_UP) and not jump: jump = 15
        if keydown(KEY_DOWN) and not slide: slide = 15
        if keydown(KEY_OK): ultra = not ultra

        if jump: jump -= 1
        if slide: slide -= 1

        speed = 7 if ultra else 3 + score//200

        if score % 25 == 0: spawn_obstacle()
        if score % 40 == 0: spawn_coin()

        draw_obstacles()
        draw_coins()
        draw_player()

        score += 1
        if score > best: best = score

        draw_string("Score:"+str(score),5,5,color(255,255,255))
        draw_string("Best:"+str(best),5,25,color(255,215,0))
        draw_string("Coins:"+str(money),200,25,COIN)

        if collision():
            try: vibrate(0.4)
            except: pass
            fill_rect(0,0,W,H,color(200,0,0))
            draw_string("CRASH",130,100,color(255,255,255))
            break

Créé il y a 5 jours.

Rechercher un Pastebin

Aucun paste trouvé.