|
25 | 25 | is_pback = True |
26 | 26 |
|
27 | 27 |
|
| 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 | + |
28 | 41 | def get_tile(tile_x, tile_y): |
| 42 | + # TODO: blocksで判定 |
29 | 43 | return pyxel.tilemaps[0].pget(tile_x, tile_y) |
30 | 44 |
|
31 | 45 |
|
@@ -92,9 +106,11 @@ def push_back(x, y, dx, dy, use_radder): |
92 | 106 | return x, y |
93 | 107 |
|
94 | 108 |
|
95 | | - |
96 | | -def is_wall(x, y): |
| 109 | +# @dbg |
| 110 | +def is_wall(x, y, *, include_ladder=False): |
97 | 111 | tile = get_tile(x // 8, y // 8) |
| 112 | + if tile == TILE_RADDER and include_ladder: |
| 113 | + return True |
98 | 114 | return tile == TILE_FLOOR or tile[0] >= WALL_TILE_X |
99 | 115 |
|
100 | 116 |
|
@@ -131,11 +147,11 @@ def update(self): |
131 | 147 | self.dy = min(self.dy + 1, 3) |
132 | 148 | if is_wall(self.x, self.y + 8) or is_wall(self.x + 7, self.y + 8): |
133 | 149 | 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) |
135 | 151 | ): |
136 | 152 | self.direction = 1 |
137 | 153 | 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) |
139 | 155 | ): |
140 | 156 | self.direction = -1 |
141 | 157 | self.x, self.y = push_back(self.x, self.y, self.dx, self.dy, False) |
|
0 commit comments