resize bricks
This commit is contained in:
parent
4ef2aea6ee
commit
cc5afff252
@ -23,7 +23,6 @@ import os
|
||||
|
||||
from typing import NamedTuple
|
||||
from contextlib import contextmanager
|
||||
import types
|
||||
import tempfile
|
||||
import base64
|
||||
import pickle
|
||||
@ -81,6 +80,13 @@ class Point(NamedTuple):
|
||||
return self.__class__(self.x - other, self.y - other)
|
||||
return NotImplemented
|
||||
|
||||
def __floordiv__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
return self.__class__(self.x // other.x, self.y // other.y)
|
||||
if isinstance(other, (int, float)):
|
||||
return self.__class__(self.x // other, self.y // other)
|
||||
return NotImplemented
|
||||
|
||||
def swap(self):
|
||||
return self.__class__(self.y, self.x)
|
||||
|
||||
@ -103,9 +109,11 @@ data = {
|
||||
|
||||
|
||||
def make_level(scene_sz, hard):
|
||||
data["maze"] = maze_gen()
|
||||
data["maze"] = maze_gen(6, 6)
|
||||
|
||||
# размер ячейки
|
||||
box_sz = Point(scene_sz.x // len(data["maze"][0]), scene_sz.y // len(data["maze"]))
|
||||
maze_sz = Point(len(data["maze"][0]), len(data["maze"]))
|
||||
box_sz = scene_sz // maze_sz
|
||||
|
||||
data["hero_pos"] = find_start(data)
|
||||
data["hero_img_right"] = PIL.ImageTk.PhotoImage(
|
||||
@ -116,12 +124,16 @@ def make_level(scene_sz, hard):
|
||||
data["hero_moved"] = True
|
||||
|
||||
# отрисовка стен
|
||||
brick_img = PIL.Image.open(hard["assets/brick.png"])
|
||||
if brick_img.size != box_sz:
|
||||
brick_img = brick_img.resize(box_sz)
|
||||
brick_img.save(hard["assets/brick.png"])
|
||||
for i, row in enumerate(data["maze"]):
|
||||
for j, item in enumerate(row):
|
||||
if item < 1:
|
||||
continue
|
||||
p = Point(j, i).transform(box_sz)
|
||||
obj = image(*p, hard["assets/brick.png"])
|
||||
image(*p, hard["assets/brick.png"])
|
||||
|
||||
def update():
|
||||
# отрабатываем изменение направления
|
||||
@ -170,23 +182,22 @@ def move_hero(data, delta):
|
||||
|
||||
|
||||
def keyPressed(event):
|
||||
delta = None
|
||||
dx = dy = 0
|
||||
match event.keysym:
|
||||
case "Left" | "a":
|
||||
delta = Point(-1, 0)
|
||||
dx = -1
|
||||
data["right"] = False
|
||||
case "Right" | "d":
|
||||
delta = Point(1, 0)
|
||||
data["right"] = True
|
||||
dx = 1
|
||||
case "Up" | "w":
|
||||
delta = Point(0, -1)
|
||||
dy = -1
|
||||
case "Down" | "s":
|
||||
delta = Point(0, 1)
|
||||
dy = 1
|
||||
case "Escape" | "q":
|
||||
killTimer(data["update_timer"])
|
||||
close()
|
||||
if delta is not None:
|
||||
move_hero(data, delta)
|
||||
if dx or dy:
|
||||
move_hero(data, Point(dx, dy))
|
||||
|
||||
|
||||
def update():
|
||||
|
Loading…
Reference in New Issue
Block a user