Skip to content

Commit d1a5e75

Browse files
committed
update 05-anahori: enemy2 run over radder
1 parent 9c15be5 commit d1a5e75

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
5 Bytes
Binary file not shown.

10-anahori/main.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@
2525
is_pback = True
2626

2727

28+
def dbg(func):
29+
import sys
30+
import inspect
31+
def wrapper(*args, **kwargs):
32+
r = func(*args, **kwargs)
33+
argstr = ", ".join(f"{n}={v}" for n, v in zip(func.__code__.co_varnames, args))
34+
frame_info = inspect.getframeinfo(sys._getframe(1))
35+
print(f"{frame_info.lineno}: {frame_info.code_context[0].rstrip()}")
36+
print(f"{func.__code__.co_firstlineno}: {func.__name__}({argstr}, {kwargs}) -> {r}")
37+
return r
38+
return wrapper
39+
40+
2841
def get_tile(tile_x, tile_y):
42+
# TODO: blocksで判定
2943
return pyxel.tilemaps[0].pget(tile_x, tile_y)
3044

3145

@@ -92,9 +106,11 @@ def push_back(x, y, dx, dy, use_radder):
92106
return x, y
93107

94108

95-
96-
def is_wall(x, y):
109+
# @dbg
110+
def is_wall(x, y, *, include_ladder=False):
97111
tile = get_tile(x // 8, y // 8)
112+
if tile == TILE_RADDER and include_ladder:
113+
return True
98114
return tile == TILE_FLOOR or tile[0] >= WALL_TILE_X
99115

100116

@@ -131,11 +147,11 @@ def update(self):
131147
self.dy = min(self.dy + 1, 3)
132148
if is_wall(self.x, self.y + 8) or is_wall(self.x + 7, self.y + 8):
133149
if self.direction < 0 and (
134-
is_wall(self.x - 1, self.y + 4) or not is_wall(self.x - 1, self.y + 8)
150+
is_wall(self.x - 1, self.y + 4) or not is_wall(self.x - 1, self.y + 8, include_ladder=True)
135151
):
136152
self.direction = 1
137153
elif self.direction > 0 and (
138-
is_wall(self.x + 8, self.y + 4) or not is_wall(self.x + 7, self.y + 8)
154+
is_wall(self.x + 8, self.y + 4) or not is_wall(self.x + 7, self.y + 8, include_ladder=True)
139155
):
140156
self.direction = -1
141157
self.x, self.y = push_back(self.x, self.y, self.dx, self.dy, False)

0 commit comments

Comments
 (0)