lode_runner.py

Created by fedyna-kevin

Created on February 13, 2021

2.83 KB

```""" CHANGE MAP HERE """

BITS = 20 # Ne pas changer

from random import randint

niveau = (
(0, 2**BITS - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), # cassable
(0, 0, 2**BITS - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), # échelle
(0, 0, 0, 2**BITS - 1, 0, 0, 0, 0, 0, 0, 0, 0), # tyrolienne
(0, 0, 0, 0, 2**BITS - 1, 0, 0, 0, 0, 0, 0, 0)  # incassable
)

""" Code """

from ion import keydown
from kandinsky import fill_rect
from time import sleep

sprites = ((((4,4,8),(6,10,4)),((2,0,4),(6,0,4),(8,0,16),(12,0,4),(4,12,4))),(((2, 6, 12),),((2,2,4),(6,2,10),(8,2,4),(12,4,2),(4,10,6),(8,10,4))),(((2,4,4),(0,6,2),(8,6,4)),((6,0,12),(8,0,6),(4,12,4),(8,10,6))),(((4,4,2),(2,14,2),(8,10,2),(10,6,2),(12,4,2),(4,12,2)),((6,0,12),(8,0,6),(2,6,4),(10,12,4))))

class Entity:
def __init__(self, spawn_x, spawn_y):
self.x = spawn_x
self.y = spawn_y

def move(self, key):
if key == 1:
self.y += 1
if key == 0:
self.x -= 1
if key == 2:
self.y -= 1
if key == 3:
self.x += 1

def blit(niveau):
for layout in range(len(niveau)):
for line in range(len(niveau[layout])):
for bit in range(BITS):
if (niveau[layout][line] >> BITS-1-bit) & 1:
fill_rect(bit*16, line*16, 16, 16, (0,0,0))
draw_sprite(layout, bit, line)

def draw_sprite(sprite, x, y):
if sprite == 0:
fill_rect(x*16, y*16, 16, 16, (194, 128, 92))
for i in range(16//2 - 2):
for j in range(16//2 - 2):
if randint(0,1):
fill_rect(x*16+2*i + 2, y*16 + 2*j + 2, 2, 2, (0,)*3)
elif sprite == 1:
fill_rect(x*16 + 2, y*16, 2, 16, (255,) * 3)
fill_rect(x*16 + 13, y*16, 2, 16, (255,) * 3)
fill_rect(x*16 + 2, y*16 + 4, 11, 2, (255,) * 3)
fill_rect(x*16 + 2, y*16 + 11, 11, 2, (255,) * 3)
elif sprite ==2:
fill_rect(x*16, y*16 + 2, 16, 2, (255,255,255))
else:
fill_rect(x*16, y*16, 16, 16, (255, 128, 92))

def draw_bonhomme(sprite, x, y): # perso (104, 195, 212)   (255,215,0)  (79, 157, 105)
global sprites
for h in sprites[sprite][0]:
fill_rect(x + h[0], y + h[1], h[2], 2, (179, 255, 179))
for v in sprites[sprite][1]:
fill_rect(x + v[0], y + v[1], 2, v[2], (179, 255, 179))

def draw_gold(x, y):
for i in range(4):
fill_rect(x+8-2*i, y+10+2*i, 2*i+2, 2, (255,215,0))

fill_rect(0,0,320,222,(0,)*3)
blit(niveau)
draw_gold(130, 200)

for i in range(20):
draw_bonhomme(0, i*16, 6*16)
draw_bonhomme(1, i*16, 7*16)
draw_bonhomme(2, i*16, 8*16)
draw_bonhomme(3, i*16, 9*16)

draw_gold(130, 200)

anim = 0
while True:
fill_rect(10*16, 11*16, 16, 16, (0,)*3)
draw_bonhomme(2 + anim, 10*16, 11*16)
anim = 1 - anim
sleep(0.1)```