Allow player to be pushed off moving blocks
This commit is contained in:
@@ -113,6 +113,46 @@ traps:
|
||||
assert g.player.rect.x < start_x # got shoved along
|
||||
|
||||
|
||||
def test_ride_into_wall_stops_no_crush(make_game):
|
||||
# Riding a horizontally-moving platform into a stationary wall must NOT
|
||||
# crush the player: they stop at the wall while the block slides underneath.
|
||||
# The wall sits one row *above* the platform's track (col 8, row 2), so it
|
||||
# catches the player's body while the platform passes below it.
|
||||
g = make_game("""
|
||||
name: t
|
||||
tile_size: 32
|
||||
map: |
|
||||
###########
|
||||
#.........#
|
||||
#.......#.#
|
||||
#.........#
|
||||
#........G#
|
||||
###########
|
||||
traps:
|
||||
- type: block
|
||||
at: [1, 3]
|
||||
move: [8, 0]
|
||||
speed: 200
|
||||
trigger: always
|
||||
""")
|
||||
# stand the player on top of the platform at its left end (body in row 2)
|
||||
place(g, 1, 2)
|
||||
g.player.fy = float(3 * 32 - g.player.h) # feet on the block's top
|
||||
g.player._sync_rect()
|
||||
wall_left = 8 * 32
|
||||
hit_wall = False
|
||||
for _ in range(180):
|
||||
step(g)
|
||||
if g.state != "playing":
|
||||
break
|
||||
assert not g.player.crushed # never crushed
|
||||
assert g.player.rect.right <= wall_left + 1 # stopped at the wall
|
||||
if g.player.rect.right >= wall_left - 1:
|
||||
hit_wall = True
|
||||
assert g.state == "playing" # survived the whole time
|
||||
assert hit_wall # actually reached the wall
|
||||
|
||||
|
||||
def test_corner_clip_does_not_warp(make_game):
|
||||
# Walking into a moving block near its corner must not fling the player
|
||||
# across it (the old velocity-sign resolver bug).
|
||||
|
||||
@@ -41,6 +41,21 @@ def test_dir_aligned():
|
||||
assert ev({"dir": "above"}, 400, 60) is True
|
||||
|
||||
|
||||
def test_dir_inclusive():
|
||||
# trap column spans x 100..132 (centre 116). A player standing *inside* the
|
||||
# column (centre 116) is neither strictly left nor strictly right of it.
|
||||
assert ev({"dir": "left"}, 106, 105) is False # centre 116, inside -> not left
|
||||
assert ev({"dir": "right"}, 106, 105) is False # inside -> not right
|
||||
# inclusive counts the trap's own tile as being on that side
|
||||
assert ev({"dir": "left", "inclusive": True}, 106, 105) is True
|
||||
assert ev({"dir": "right", "inclusive": True}, 106, 105) is True
|
||||
# and vertically, too (column spans y 100..132)
|
||||
assert ev({"dir": "above"}, 108, 106) is False
|
||||
assert ev({"dir": "above", "inclusive": True}, 108, 106) is True
|
||||
assert ev({"dir": "below"}, 108, 106) is False
|
||||
assert ev({"dir": "below", "inclusive": True}, 108, 106) is True
|
||||
|
||||
|
||||
def test_all_and_any():
|
||||
c = {"all": [{"within": 3}, {"dir": "above", "aligned": True}]}
|
||||
assert ev(c, 108, 80) is True
|
||||
|
||||
Reference in New Issue
Block a user