tilemap-parser 5.2.0__tar.gz → 5.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/PKG-INFO +1 -1
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/pyproject.toml +1 -1
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/__init__.py +1 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/__init__.py +2 -1
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/__init__.py +2 -2
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/grounded.py +2 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/platformer.py +34 -10
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/queries.py +122 -22
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/rpg.py +2 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/runner.py +2 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/slide.py +2 -0
- tilemap_parser-5.2.1/src/tilemap_parser/runtime/movement/types.py +58 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/PKG-INFO +1 -1
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/SOURCES.txt +1 -0
- tilemap_parser-5.2.1/tests/test_ground_info.py +246 -0
- tilemap_parser-5.2.0/src/tilemap_parser/runtime/movement/types.py +0 -30
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/LICENSE +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/README.md +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/pypi-readme.md +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/setup.cfg +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/__init__.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/animation.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/collision_loader.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/map_parse.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/node_parse.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/particle.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/parser/tmx_converter.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/animation_player.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/area_node.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/body.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/camera.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/__init__.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/hit.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/manager.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/shapes.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision_cache.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/map_loader.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/map_object.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/__init__.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/nav_grid.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/path_follower.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/pathfinder.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/object_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/particles.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/polygon_query.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/protocols.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/renderer.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/tile_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/world.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/utils/__init__.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/utils/geometry.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/dependency_links.txt +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/requires.txt +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/top_level.txt +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_background_layer.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_body.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_camera.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_geometry.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_gid_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_gid_routing.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_integration_animation.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_integration_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_integration_map_loader.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_map_loader.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_map_object.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_move_grounded.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_navigation.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_object_animation.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_object_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_object_surfaces.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_particle_emitter.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_render_scale.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_tile_collision.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_tile_layer_renderer_y_sort.py +0 -0
- {tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/tests/test_tmx_converter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tilemap-parser
|
|
3
|
-
Version: 5.2.
|
|
3
|
+
Version: 5.2.1
|
|
4
4
|
Summary: Standalone parser/loader for tilemap-editor JSON maps, sprite animations, and collision detection runtime.
|
|
5
5
|
Author: tilemap parser contributors
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tilemap-parser"
|
|
7
|
-
version = "5.2.
|
|
7
|
+
version = "5.2.1"
|
|
8
8
|
description = "Standalone parser/loader for tilemap-editor JSON maps, sprite animations, and collision detection runtime."
|
|
9
9
|
readme = "pypi-readme.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -13,7 +13,7 @@ from .collision_cache import (
|
|
|
13
13
|
load_tileset_collision,
|
|
14
14
|
)
|
|
15
15
|
from .map_object import MapObject, load_map_objects
|
|
16
|
-
from .movement import CollisionResult, CollisionRunner, MovementMode
|
|
16
|
+
from .movement import CollisionResult, CollisionRunner, GroundInfo, MovementMode
|
|
17
17
|
from .polygon_query import rect_vs_tilemap
|
|
18
18
|
from .protocols import ICollidable, ICollidableObject, ICollidableSprite
|
|
19
19
|
from .map_loader import BackgroundLayer, TilemapData, load_map
|
|
@@ -50,6 +50,7 @@ __all__ = [
|
|
|
50
50
|
"CollisionHit",
|
|
51
51
|
"CollisionResult",
|
|
52
52
|
"CollisionRunner",
|
|
53
|
+
"GroundInfo",
|
|
53
54
|
"ICollidable",
|
|
54
55
|
"ICollidableObject",
|
|
55
56
|
"ICollidableSprite",
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/__init__.py
RENAMED
|
@@ -6,6 +6,6 @@ the runner remains the single public surface.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from .runner import CollisionRunner
|
|
9
|
-
from .types import CollisionResult, MovementMode
|
|
9
|
+
from .types import CollisionResult, GroundInfo, MovementMode
|
|
10
10
|
|
|
11
|
-
__all__ = ["CollisionResult", "CollisionRunner", "MovementMode"]
|
|
11
|
+
__all__ = ["CollisionResult", "CollisionRunner", "GroundInfo", "MovementMode"]
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/platformer.py
RENAMED
|
@@ -56,6 +56,8 @@ def move_platformer(
|
|
|
56
56
|
result.hit_ceiling = False
|
|
57
57
|
result.on_ground = False
|
|
58
58
|
result.slide_vector = None
|
|
59
|
+
result.ground_angle = None
|
|
60
|
+
result.ground_normal = None
|
|
59
61
|
result.final_x = sprite.x
|
|
60
62
|
result.final_y = sprite.y
|
|
61
63
|
|
|
@@ -343,10 +345,13 @@ def move_platformer_with_slide(
|
|
|
343
345
|
result.hit_ceiling = False
|
|
344
346
|
result.on_ground = False
|
|
345
347
|
result.slide_vector = None
|
|
348
|
+
result.ground_angle = None
|
|
349
|
+
result.ground_normal = None
|
|
346
350
|
result.final_x = sprite.x
|
|
347
351
|
result.final_y = sprite.y
|
|
348
352
|
|
|
349
353
|
skin = 0.01
|
|
354
|
+
support_info = None
|
|
350
355
|
old_x, old_y = sprite.x, sprite.y
|
|
351
356
|
_, _, _, old_bottom = get_shape_bounds(sprite)
|
|
352
357
|
was_on_ground = getattr(sprite, "on_ground", False)
|
|
@@ -380,13 +385,15 @@ def move_platformer_with_slide(
|
|
|
380
385
|
|
|
381
386
|
# Horizontal movement first. Grounded sprites are allowed to follow
|
|
382
387
|
# walkable floor contours, but only when a jump did not start this frame.
|
|
388
|
+
# World-X velocity is preserved (dx = vx * dt); ground following only
|
|
389
|
+
# derives dy. support_info tracks the already-selected surface.
|
|
383
390
|
if delta_x != 0.0:
|
|
384
391
|
sprite.x = old_x + delta_x
|
|
385
392
|
sprite.y = old_y
|
|
386
393
|
|
|
387
394
|
followed_ground = False
|
|
388
395
|
if was_on_ground and not jumped:
|
|
389
|
-
|
|
396
|
+
ground_info = self._find_walkable_ground_info(
|
|
390
397
|
sprite,
|
|
391
398
|
tileset_collision,
|
|
392
399
|
tile_map,
|
|
@@ -395,16 +402,17 @@ def move_platformer_with_slide(
|
|
|
395
402
|
include_one_way=True,
|
|
396
403
|
previous_bottom=old_bottom, world=world
|
|
397
404
|
)
|
|
398
|
-
if
|
|
399
|
-
sprite.y =
|
|
405
|
+
if ground_info is not None:
|
|
406
|
+
sprite.y = ground_info.y - bottom_offset - skin
|
|
400
407
|
followed_ground = True
|
|
408
|
+
support_info = ground_info
|
|
401
409
|
|
|
402
410
|
if self._collides_at_platformer(
|
|
403
411
|
sprite, tileset_collision, tile_map, include_one_way=False, world=world
|
|
404
412
|
):
|
|
405
413
|
sprite.x = old_x + delta_x
|
|
406
414
|
sprite.y = old_y - self.step_height
|
|
407
|
-
|
|
415
|
+
step_info = self._find_walkable_ground_info(
|
|
408
416
|
sprite,
|
|
409
417
|
tileset_collision,
|
|
410
418
|
tile_map,
|
|
@@ -413,6 +421,7 @@ def move_platformer_with_slide(
|
|
|
413
421
|
include_one_way=False,
|
|
414
422
|
previous_bottom=old_bottom, world=world
|
|
415
423
|
)
|
|
424
|
+
step_ground_y = step_info.y if step_info is not None else None
|
|
416
425
|
if step_ground_y is not None:
|
|
417
426
|
sprite.y = step_ground_y - bottom_offset - skin
|
|
418
427
|
if step_ground_y is None or self._collides_at_platformer(
|
|
@@ -423,8 +432,10 @@ def move_platformer_with_slide(
|
|
|
423
432
|
sprite.vx = 0.0
|
|
424
433
|
result.collided = True
|
|
425
434
|
result.hit_wall_x = True
|
|
435
|
+
support_info = None
|
|
426
436
|
else:
|
|
427
437
|
followed_ground = True
|
|
438
|
+
support_info = step_info
|
|
428
439
|
|
|
429
440
|
if followed_ground:
|
|
430
441
|
sprite.on_ground = True
|
|
@@ -438,6 +449,7 @@ def move_platformer_with_slide(
|
|
|
438
449
|
|
|
439
450
|
if jumped or sprite.vy < 0.0:
|
|
440
451
|
sprite.y = y_before_vertical + delta_y
|
|
452
|
+
support_info = None
|
|
441
453
|
if self._collides_at_platformer(
|
|
442
454
|
sprite, tileset_collision, tile_map, include_one_way=False, world=world
|
|
443
455
|
):
|
|
@@ -461,7 +473,7 @@ def move_platformer_with_slide(
|
|
|
461
473
|
sprite.on_ground = False
|
|
462
474
|
elif sprite.vy > 0.0:
|
|
463
475
|
sprite.y = y_before_vertical + delta_y
|
|
464
|
-
|
|
476
|
+
fall_info = self._find_walkable_ground_info(
|
|
465
477
|
sprite,
|
|
466
478
|
tileset_collision,
|
|
467
479
|
tile_map,
|
|
@@ -470,13 +482,14 @@ def move_platformer_with_slide(
|
|
|
470
482
|
include_one_way=True,
|
|
471
483
|
previous_bottom=previous_bottom, world=world
|
|
472
484
|
)
|
|
473
|
-
if
|
|
474
|
-
sprite.y =
|
|
485
|
+
if fall_info is not None:
|
|
486
|
+
sprite.y = fall_info.y - bottom_offset - skin
|
|
475
487
|
sprite.vy = 0.0
|
|
476
488
|
sprite.on_ground = True
|
|
477
489
|
result.on_ground = True
|
|
478
490
|
result.collided = True
|
|
479
491
|
result.hit_wall_y = True
|
|
492
|
+
support_info = fall_info
|
|
480
493
|
elif self._collides_at_platformer(
|
|
481
494
|
sprite,
|
|
482
495
|
tileset_collision,
|
|
@@ -505,10 +518,13 @@ def move_platformer_with_slide(
|
|
|
505
518
|
result.on_ground = True
|
|
506
519
|
result.collided = True
|
|
507
520
|
result.hit_wall_y = True
|
|
521
|
+
# Non-walkable collision landing: no walkable support to report.
|
|
522
|
+
support_info = None
|
|
508
523
|
else:
|
|
509
524
|
sprite.on_ground = False
|
|
525
|
+
support_info = None
|
|
510
526
|
elif not jumped:
|
|
511
|
-
|
|
527
|
+
snap_info = self._find_walkable_ground_info(
|
|
512
528
|
sprite,
|
|
513
529
|
tileset_collision,
|
|
514
530
|
tile_map,
|
|
@@ -517,16 +533,24 @@ def move_platformer_with_slide(
|
|
|
517
533
|
include_one_way=True,
|
|
518
534
|
previous_bottom=previous_bottom, world=world
|
|
519
535
|
)
|
|
520
|
-
if
|
|
521
|
-
sprite.y =
|
|
536
|
+
if snap_info is not None:
|
|
537
|
+
sprite.y = snap_info.y - bottom_offset - skin
|
|
522
538
|
sprite.vy = 0.0
|
|
523
539
|
sprite.on_ground = True
|
|
524
540
|
result.on_ground = True
|
|
541
|
+
support_info = snap_info
|
|
525
542
|
else:
|
|
526
543
|
sprite.on_ground = False
|
|
544
|
+
support_info = None
|
|
527
545
|
|
|
528
546
|
result.final_x = sprite.x
|
|
529
547
|
result.final_y = sprite.y
|
|
530
548
|
result.on_ground = getattr(sprite, "on_ground", False)
|
|
549
|
+
if result.on_ground and support_info is not None:
|
|
550
|
+
result.ground_angle = support_info.angle
|
|
551
|
+
result.ground_normal = support_info.normal
|
|
552
|
+
else:
|
|
553
|
+
result.ground_angle = None
|
|
554
|
+
result.ground_normal = None
|
|
531
555
|
return result
|
|
532
556
|
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/movement/queries.py
RENAMED
|
@@ -8,6 +8,7 @@ from ...parser.collision import CollisionPolygon, TileCollisionData, TilesetColl
|
|
|
8
8
|
from ..collision.hit import should_collide
|
|
9
9
|
from ..polygon_query import _check_sprite_polygon_offset, get_shape_bounds
|
|
10
10
|
from ..protocols import ICollidable, ICollidableSprite
|
|
11
|
+
from .types import GroundInfo
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
def _resolve_tile_data(
|
|
@@ -66,6 +67,7 @@ def _collides_at(
|
|
|
66
67
|
return True
|
|
67
68
|
return world is not None and world.collides_with_body(sprite) is not None
|
|
68
69
|
|
|
70
|
+
|
|
69
71
|
def _first_colliding_shape(
|
|
70
72
|
self,
|
|
71
73
|
sprite: ICollidable,
|
|
@@ -107,6 +109,7 @@ def _first_colliding_shape(
|
|
|
107
109
|
return (body.as_polygon(), 0.0, 0.0)
|
|
108
110
|
return None
|
|
109
111
|
|
|
112
|
+
|
|
110
113
|
def _collides_at_platformer(
|
|
111
114
|
self,
|
|
112
115
|
sprite: ICollidableSprite,
|
|
@@ -153,7 +156,19 @@ def _collides_at_platformer(
|
|
|
153
156
|
return True
|
|
154
157
|
return world is not None and world.collides_with_body(sprite) is not None
|
|
155
158
|
|
|
156
|
-
|
|
159
|
+
|
|
160
|
+
def _angle_from_normal(normal_x: float, normal_y: float) -> float:
|
|
161
|
+
"""Derive raw ground angle from an outward walkable normal.
|
|
162
|
+
|
|
163
|
+
Normal is authoritative; angle is derived. ``0.0`` = flat,
|
|
164
|
+
positive = rises toward ``+X``, negative = falls toward ``+X``
|
|
165
|
+
(screen coords, ``+Y`` down). No flat threshold applied.
|
|
166
|
+
"""
|
|
167
|
+
angle = math.degrees(math.atan2(-normal_x, -normal_y))
|
|
168
|
+
return 0.0 if angle == 0.0 else angle
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _walkable_edge_info_at_x(
|
|
157
172
|
self,
|
|
158
173
|
poly: CollisionPolygon,
|
|
159
174
|
ox: float,
|
|
@@ -161,14 +176,32 @@ def _walkable_edge_y_at_x(
|
|
|
161
176
|
world_x: float,
|
|
162
177
|
edge_index: int,
|
|
163
178
|
min_upness: float,
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
centroid: tuple[float, float] | None = None,
|
|
180
|
+
world_verts: list[tuple[float, float]] | None = None,
|
|
181
|
+
) -> tuple[float, float, float] | None:
|
|
182
|
+
"""Return ``(ground_y, normal_x, normal_y)`` for a walkable edge.
|
|
183
|
+
|
|
184
|
+
Identical selection semantics to the historic ``_walkable_edge_y_at_x``:
|
|
185
|
+
world transform via tile offset/``render_scale``, degenerate and
|
|
186
|
+
near-vertical rejection, outward normal via centroid, and
|
|
187
|
+
``upness >= min_upness`` walkability. The normal is the source of
|
|
188
|
+
truth; callers derive angle from it.
|
|
189
|
+
|
|
190
|
+
``centroid`` and ``world_verts`` are polygon-constant data shared by
|
|
191
|
+
every edge/sample evaluation of the same polygon (identical
|
|
192
|
+
expressions to the inline path); when omitted they are derived
|
|
193
|
+
inline.
|
|
194
|
+
"""
|
|
166
195
|
verts = poly.vertices
|
|
167
196
|
n = len(verts)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
197
|
+
if world_verts is None:
|
|
198
|
+
v1x = verts[edge_index][0] * self.render_scale + ox
|
|
199
|
+
v1y = verts[edge_index][1] * self.render_scale + oy
|
|
200
|
+
v2x = verts[(edge_index + 1) % n][0] * self.render_scale + ox
|
|
201
|
+
v2y = verts[(edge_index + 1) % n][1] * self.render_scale + oy
|
|
202
|
+
else:
|
|
203
|
+
v1x, v1y = world_verts[edge_index]
|
|
204
|
+
v2x, v2y = world_verts[(edge_index + 1) % n]
|
|
172
205
|
|
|
173
206
|
min_x = min(v1x, v2x)
|
|
174
207
|
max_x = max(v1x, v2x)
|
|
@@ -188,8 +221,11 @@ def _walkable_edge_y_at_x(
|
|
|
188
221
|
normal_x = -edge_y / edge_len
|
|
189
222
|
normal_y = edge_x / edge_len
|
|
190
223
|
|
|
191
|
-
|
|
192
|
-
|
|
224
|
+
if centroid is None:
|
|
225
|
+
cx = sum(v[0] for v in verts) / n * self.render_scale + ox
|
|
226
|
+
cy = sum(v[1] for v in verts) / n * self.render_scale + oy
|
|
227
|
+
else:
|
|
228
|
+
cx, cy = centroid
|
|
193
229
|
mid_x = (v1x + v2x) * 0.5
|
|
194
230
|
mid_y = (v1y + v2y) * 0.5
|
|
195
231
|
|
|
@@ -203,9 +239,25 @@ def _walkable_edge_y_at_x(
|
|
|
203
239
|
return None
|
|
204
240
|
|
|
205
241
|
t = (world_x - v1x) / edge_x
|
|
206
|
-
|
|
242
|
+
ground_y = v1y + (v2y - v1y) * t
|
|
243
|
+
return (ground_y, normal_x, normal_y)
|
|
207
244
|
|
|
208
|
-
|
|
245
|
+
|
|
246
|
+
def _walkable_edge_y_at_x(
|
|
247
|
+
self,
|
|
248
|
+
poly: CollisionPolygon,
|
|
249
|
+
ox: float,
|
|
250
|
+
oy: float,
|
|
251
|
+
world_x: float,
|
|
252
|
+
edge_index: int,
|
|
253
|
+
min_upness: float,
|
|
254
|
+
) -> float | None:
|
|
255
|
+
"""Return the world Y for a walkable polygon edge at world_x."""
|
|
256
|
+
info = self._walkable_edge_info_at_x(poly, ox, oy, world_x, edge_index, min_upness)
|
|
257
|
+
return info[0] if info is not None else None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _find_walkable_ground_info(
|
|
209
261
|
self,
|
|
210
262
|
sprite: ICollidableSprite,
|
|
211
263
|
tileset_collision: TilesetCollision,
|
|
@@ -215,8 +267,16 @@ def _find_walkable_ground_y(
|
|
|
215
267
|
include_one_way: bool = True,
|
|
216
268
|
previous_bottom: float | None = None,
|
|
217
269
|
world=None,
|
|
218
|
-
) ->
|
|
219
|
-
"""Find the
|
|
270
|
+
) -> GroundInfo | None:
|
|
271
|
+
"""Find the walkable supporting surface under/just above the sprite.
|
|
272
|
+
|
|
273
|
+
Same selection as the historic ``_find_walkable_ground_y`` (three
|
|
274
|
+
foot samples, vertical window, one-way gating, highest ``y`` wins,
|
|
275
|
+
existing body ``top_y_at`` handling). Returns the supporting edge's
|
|
276
|
+
``y`` plus its outward ``normal`` and derived ``angle``. Bodies keep
|
|
277
|
+
existing behavior with conservative flat ``(0.0, -1.0)`` / ``0.0``
|
|
278
|
+
(no new curved-body slope semantics).
|
|
279
|
+
"""
|
|
220
280
|
left, _, right, bottom = get_shape_bounds(sprite)
|
|
221
281
|
sample_xs = (left, (left + right) * 0.5, right)
|
|
222
282
|
|
|
@@ -227,7 +287,7 @@ def _find_walkable_ground_y(
|
|
|
227
287
|
max_tile_y = int((bottom + max_down + th) // th) + 1
|
|
228
288
|
min_upness = math.cos(math.radians(self.max_walk_angle))
|
|
229
289
|
|
|
230
|
-
|
|
290
|
+
best: GroundInfo | None = None
|
|
231
291
|
for tile_y in range(min_tile_y, max_tile_y + 1):
|
|
232
292
|
for tile_x in range(min_tile_x, max_tile_x + 1):
|
|
233
293
|
tile_id = tile_map.get((tile_x, tile_y))
|
|
@@ -241,22 +301,38 @@ def _find_walkable_ground_y(
|
|
|
241
301
|
continue
|
|
242
302
|
if poly.one_way and not include_one_way:
|
|
243
303
|
continue
|
|
304
|
+
# polygon constant data, shared by every edge/sample
|
|
305
|
+
verts = poly.vertices
|
|
306
|
+
n_verts = len(verts)
|
|
307
|
+
cx = sum(v[0] for v in verts) / n_verts * self.render_scale + ox
|
|
308
|
+
cy = sum(v[1] for v in verts) / n_verts * self.render_scale + oy
|
|
309
|
+
world_verts = [
|
|
310
|
+
(v[0] * self.render_scale + ox, v[1] * self.render_scale + oy)
|
|
311
|
+
for v in verts
|
|
312
|
+
]
|
|
244
313
|
for sample_x in sample_xs:
|
|
245
314
|
for i in range(len(poly.vertices)):
|
|
246
|
-
|
|
247
|
-
poly, ox, oy, sample_x, i, min_upness
|
|
315
|
+
edge = self._walkable_edge_info_at_x(
|
|
316
|
+
poly, ox, oy, sample_x, i, min_upness,
|
|
317
|
+
centroid=(cx, cy),
|
|
318
|
+
world_verts=world_verts,
|
|
248
319
|
)
|
|
249
|
-
if
|
|
320
|
+
if edge is None:
|
|
250
321
|
continue
|
|
322
|
+
ground_y, nx, ny = edge
|
|
251
323
|
one_way_from_above = True
|
|
252
324
|
if poly.one_way and previous_bottom is not None:
|
|
253
325
|
one_way_from_above = previous_bottom <= ground_y + 0.5
|
|
254
326
|
if not one_way_from_above:
|
|
255
327
|
continue
|
|
256
328
|
if (bottom - max_up <= ground_y <= bottom + max_down) and (
|
|
257
|
-
|
|
329
|
+
best is None or ground_y < best.y
|
|
258
330
|
):
|
|
259
|
-
|
|
331
|
+
best = GroundInfo(
|
|
332
|
+
y=ground_y,
|
|
333
|
+
normal=(nx, ny),
|
|
334
|
+
angle=_angle_from_normal(nx, ny),
|
|
335
|
+
)
|
|
260
336
|
if world is not None:
|
|
261
337
|
for body in world.bodies:
|
|
262
338
|
if body is sprite:
|
|
@@ -269,7 +345,31 @@ def _find_walkable_ground_y(
|
|
|
269
345
|
continue
|
|
270
346
|
if not bottom - max_up <= ground_y <= bottom + max_down:
|
|
271
347
|
continue
|
|
272
|
-
if
|
|
273
|
-
|
|
274
|
-
return
|
|
348
|
+
if best is None or ground_y < best.y:
|
|
349
|
+
best = GroundInfo(y=ground_y, normal=(0.0, -1.0), angle=0.0)
|
|
350
|
+
return best
|
|
275
351
|
|
|
352
|
+
|
|
353
|
+
def _find_walkable_ground_y(
|
|
354
|
+
self,
|
|
355
|
+
sprite: ICollidableSprite,
|
|
356
|
+
tileset_collision: TilesetCollision,
|
|
357
|
+
tile_map: dict,
|
|
358
|
+
max_up: float,
|
|
359
|
+
max_down: float,
|
|
360
|
+
include_one_way: bool = True,
|
|
361
|
+
previous_bottom: float | None = None,
|
|
362
|
+
world=None,
|
|
363
|
+
) -> float | None:
|
|
364
|
+
"""Find the nearest walkable floor surface under or just above the sprite."""
|
|
365
|
+
info = self._find_walkable_ground_info(
|
|
366
|
+
sprite,
|
|
367
|
+
tileset_collision,
|
|
368
|
+
tile_map,
|
|
369
|
+
max_up,
|
|
370
|
+
max_down,
|
|
371
|
+
include_one_way=include_one_way,
|
|
372
|
+
previous_bottom=previous_bottom,
|
|
373
|
+
world=world,
|
|
374
|
+
)
|
|
375
|
+
return info.y if info is not None else None
|
|
@@ -30,7 +30,9 @@ class CollisionRunner:
|
|
|
30
30
|
_first_colliding_shape = queries._first_colliding_shape
|
|
31
31
|
_collides_at_platformer = queries._collides_at_platformer
|
|
32
32
|
_walkable_edge_y_at_x = queries._walkable_edge_y_at_x
|
|
33
|
+
_walkable_edge_info_at_x = queries._walkable_edge_info_at_x
|
|
33
34
|
_find_walkable_ground_y = queries._find_walkable_ground_y
|
|
35
|
+
_find_walkable_ground_info = queries._find_walkable_ground_info
|
|
34
36
|
|
|
35
37
|
def __init__(
|
|
36
38
|
self,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Movement types shared by the collision runner."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
|
|
8
|
+
Vector2 = tuple[float, float]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MovementMode(Enum):
|
|
12
|
+
"""Movement modes for collision runner"""
|
|
13
|
+
|
|
14
|
+
SLIDE = "slide"
|
|
15
|
+
GROUNDED = "grounded"
|
|
16
|
+
PLATFORMER = "platformer"
|
|
17
|
+
RPG = "rpg"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class GroundInfo:
|
|
22
|
+
"""Walkable supporting surface selected by the ground query.
|
|
23
|
+
|
|
24
|
+
Single source of truth derived from the actual supporting polygon
|
|
25
|
+
edge (``edge -> normal -> angle``). The normal is authoritative;
|
|
26
|
+
``angle`` is derived from it.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
y: World Y of the supporting surface at the sampled foot X.
|
|
30
|
+
normal: Outward unit normal ``(nx, ny)`` of the supporting edge.
|
|
31
|
+
For tile edges this is the polygon outward normal; for
|
|
32
|
+
bodies the existing conservative ``(0.0, -1.0)`` is used
|
|
33
|
+
(no new circle/capsule slope semantics).
|
|
34
|
+
angle: Raw geometric angle in degrees. ``0.0`` = flat,
|
|
35
|
+
positive = surface rises toward ``+X``, negative = falls
|
|
36
|
+
toward ``+X`` (screen coords, ``+Y`` down). No flat
|
|
37
|
+
threshold is applied — consumers classify.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
y: float = 0.0
|
|
41
|
+
normal: Vector2 = (0.0, -1.0)
|
|
42
|
+
angle: float = 0.0
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class CollisionResult:
|
|
47
|
+
"""Result of collision detection and resolution"""
|
|
48
|
+
|
|
49
|
+
collided: bool = False
|
|
50
|
+
final_x: float = 0.0
|
|
51
|
+
final_y: float = 0.0
|
|
52
|
+
hit_wall_x: bool = False
|
|
53
|
+
hit_wall_y: bool = False
|
|
54
|
+
hit_ceiling: bool = False
|
|
55
|
+
on_ground: bool = False
|
|
56
|
+
slide_vector: Vector2 | None = None
|
|
57
|
+
ground_angle: float | None = None
|
|
58
|
+
ground_normal: Vector2 | None = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tilemap-parser
|
|
3
|
-
Version: 5.2.
|
|
3
|
+
Version: 5.2.1
|
|
4
4
|
Summary: Standalone parser/loader for tilemap-editor JSON maps, sprite animations, and collision detection runtime.
|
|
5
5
|
Author: tilemap parser contributors
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""Ground supporting-surface info for move_platformer_with_slide.
|
|
2
|
+
|
|
3
|
+
Covers the conservative contract:
|
|
4
|
+
- ground geometry comes from the already-selected walkable polygon edge
|
|
5
|
+
(edge -> normal -> angle), not tile identity / bounding box.
|
|
6
|
+
- CollisionResult.ground_angle / ground_normal are post-move state.
|
|
7
|
+
- World-X velocity preserved: no cos() scaling.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
|
17
|
+
|
|
18
|
+
from tilemap_parser.parser.collision import (
|
|
19
|
+
CollisionPolygon,
|
|
20
|
+
RectangleShape,
|
|
21
|
+
TileCollisionData,
|
|
22
|
+
TilesetCollision,
|
|
23
|
+
)
|
|
24
|
+
from tilemap_parser.runtime.body import Body
|
|
25
|
+
from tilemap_parser.runtime.movement import CollisionRunner
|
|
26
|
+
from tilemap_parser.runtime.world import PhysicsWorld
|
|
27
|
+
|
|
28
|
+
FULL = [(0.0, 0.0), (32.0, 0.0), (32.0, 32.0), (0.0, 32.0)]
|
|
29
|
+
SLOPE_UP = [(0.0, 32.0), (32.0, 0.0), (32.0, 32.0)] # rises toward +X
|
|
30
|
+
SLOPE_DOWN = [(0.0, 0.0), (32.0, 32.0), (0.0, 32.0)] # falls toward +X
|
|
31
|
+
# Nearly rectangular, but the supporting TOP edge is tilted ~5.36 deg.
|
|
32
|
+
TILTED_TOP = [(0.0, 3.0), (32.0, 0.0), (32.0, 32.0), (0.0, 32.0)]
|
|
33
|
+
# Steep hypotenuse ~76 deg from horizontal -> not walkable with 60 deg max.
|
|
34
|
+
STEEP = [(0.0, 32.0), (8.0, 0.0), (8.0, 32.0)]
|
|
35
|
+
ONE_WAY_TOP = [(0.0, 8.0), (32.0, 8.0), (32.0, 16.0), (0.0, 16.0)]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class MockSprite:
|
|
39
|
+
def __init__(self, x=0, y=0, w=24, h=32):
|
|
40
|
+
self.x = x
|
|
41
|
+
self.y = y
|
|
42
|
+
self.vx = 0
|
|
43
|
+
self.vy = 0
|
|
44
|
+
self.on_ground = False
|
|
45
|
+
self.collision_shape = RectangleShape(width=w, height=h)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def make_tileset():
|
|
49
|
+
return TilesetCollision(
|
|
50
|
+
tileset_name="ground_test",
|
|
51
|
+
tile_size=(32, 32),
|
|
52
|
+
tiles={
|
|
53
|
+
0: TileCollisionData(tile_id=0, shapes=[CollisionPolygon(vertices=FULL)]),
|
|
54
|
+
2: TileCollisionData(
|
|
55
|
+
tile_id=2, shapes=[CollisionPolygon(vertices=SLOPE_UP)]
|
|
56
|
+
),
|
|
57
|
+
3: TileCollisionData(
|
|
58
|
+
tile_id=3, shapes=[CollisionPolygon(vertices=SLOPE_DOWN)]
|
|
59
|
+
),
|
|
60
|
+
4: TileCollisionData(
|
|
61
|
+
tile_id=4, shapes=[CollisionPolygon(vertices=TILTED_TOP)]
|
|
62
|
+
),
|
|
63
|
+
5: TileCollisionData(tile_id=5, shapes=[CollisionPolygon(vertices=STEEP)]),
|
|
64
|
+
6: TileCollisionData(
|
|
65
|
+
tile_id=6,
|
|
66
|
+
shapes=[CollisionPolygon(vertices=ONE_WAY_TOP, one_way=True)],
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_flat_reports_zero():
|
|
73
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
74
|
+
ts = make_tileset()
|
|
75
|
+
s = MockSprite(x=160, y=160 - 32 - 0.01)
|
|
76
|
+
s.on_ground = True
|
|
77
|
+
res = r.move_platformer_with_slide(s, ts, {(5, 5): 0}, dt=0.016, input_x=0)
|
|
78
|
+
assert res.on_ground is True
|
|
79
|
+
assert res.ground_angle == 0.0
|
|
80
|
+
assert res.ground_normal == (0.0, -1.0)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_slope_up_reports_positive_45():
|
|
84
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
85
|
+
ts = make_tileset()
|
|
86
|
+
s = MockSprite(x=160, y=169.99, w=8, h=16)
|
|
87
|
+
s.on_ground = True
|
|
88
|
+
res = r.move_platformer_with_slide(s, ts, {(5, 5): 2}, dt=0.016, input_x=1)
|
|
89
|
+
assert res.on_ground is True
|
|
90
|
+
assert res.ground_angle == 45.0
|
|
91
|
+
assert res.ground_normal[0] == pytest.approx(-(2**0.5) / 2)
|
|
92
|
+
assert res.ground_normal[1] == pytest.approx(-(2**0.5) / 2)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_slope_down_reports_negative():
|
|
96
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
97
|
+
ts = make_tileset()
|
|
98
|
+
info = r._find_walkable_ground_info(
|
|
99
|
+
MockSprite(x=16, y=0 - 32, w=24, h=32),
|
|
100
|
+
ts,
|
|
101
|
+
{(0, 0): 3},
|
|
102
|
+
max_up=40.0,
|
|
103
|
+
max_down=40.0,
|
|
104
|
+
)
|
|
105
|
+
assert info is not None
|
|
106
|
+
assert info.angle == -45.0
|
|
107
|
+
assert info.normal[0] > 0
|
|
108
|
+
assert info.normal[1] < 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_nearly_rect_reports_actual_tilted_edge():
|
|
112
|
+
# Guards against tile-type / bbox slope classification.
|
|
113
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
114
|
+
ts = make_tileset()
|
|
115
|
+
s = MockSprite(x=8, y=1.5 - 32 - 0.01)
|
|
116
|
+
s.on_ground = True
|
|
117
|
+
res = r.move_platformer_with_slide(s, ts, {(0, 0): 4}, dt=0.016, input_x=0)
|
|
118
|
+
assert res.on_ground is True
|
|
119
|
+
assert res.ground_angle == math.degrees(math.atan2(3.0, 32.0))
|
|
120
|
+
assert abs(res.ground_angle - 5.36) < 0.01
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_steep_edge_is_not_walkable():
|
|
124
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
125
|
+
ts = make_tileset()
|
|
126
|
+
info = r._find_walkable_ground_info(
|
|
127
|
+
MockSprite(x=4, y=0 - 32, w=8, h=16),
|
|
128
|
+
ts,
|
|
129
|
+
{(0, 0): 5},
|
|
130
|
+
max_up=40.0,
|
|
131
|
+
max_down=40.0,
|
|
132
|
+
)
|
|
133
|
+
assert info is None
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_vertical_edge_rejected():
|
|
137
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
138
|
+
poly = CollisionPolygon(vertices=FULL)
|
|
139
|
+
minu = math.cos(math.radians(r.max_walk_angle))
|
|
140
|
+
# Edge 1 of FULL is (32,0)->(32,32): vertical wall.
|
|
141
|
+
assert r._walkable_edge_info_at_x(poly, 0, 0, 32.0, 1, minu) is None
|
|
142
|
+
# Edge 0 is the flat top.
|
|
143
|
+
assert r._walkable_edge_info_at_x(poly, 0, 0, 16.0, 0, minu) is not None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_airborne_reports_none():
|
|
147
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
148
|
+
ts = make_tileset()
|
|
149
|
+
s = MockSprite(x=100, y=100)
|
|
150
|
+
s.on_ground = False
|
|
151
|
+
res = r.move_platformer_with_slide(s, ts, {}, dt=0.016, input_x=0)
|
|
152
|
+
assert res.on_ground is False
|
|
153
|
+
assert res.ground_angle is None
|
|
154
|
+
assert res.ground_normal is None
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_jump_reports_none():
|
|
158
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
159
|
+
ts = make_tileset()
|
|
160
|
+
s = MockSprite(x=160, y=160 - 32 - 0.01)
|
|
161
|
+
s.on_ground = True
|
|
162
|
+
res = r.move_platformer_with_slide(
|
|
163
|
+
s, ts, {(5, 5): 0}, dt=0.016, input_x=0, jump_pressed=True
|
|
164
|
+
)
|
|
165
|
+
assert res.on_ground is False
|
|
166
|
+
assert res.ground_angle is None
|
|
167
|
+
assert res.ground_normal is None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_ledge_walkoff_clears_result():
|
|
171
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
172
|
+
ts = make_tileset()
|
|
173
|
+
# Stand at right edge of a single flat tile, then step past it.
|
|
174
|
+
s = MockSprite(x=160 + 32 - 24, y=160 - 32 - 0.01)
|
|
175
|
+
s.on_ground = True
|
|
176
|
+
first = r.move_platformer_with_slide(s, ts, {(5, 5): 0}, dt=0.016, input_x=0)
|
|
177
|
+
assert first.on_ground is True
|
|
178
|
+
assert first.ground_angle == 0.0
|
|
179
|
+
s.on_ground = True
|
|
180
|
+
res = r.move_platformer_with_slide(s, ts, {(5, 5): 0}, dt=0.5, input_x=1)
|
|
181
|
+
assert res.on_ground is False
|
|
182
|
+
assert res.ground_angle is None
|
|
183
|
+
assert res.ground_normal is None
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_one_way_from_above_reports_flat():
|
|
187
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
188
|
+
ts = make_tileset()
|
|
189
|
+
# Tile (0,0) one-way top at y=8; stand on it.
|
|
190
|
+
s = MockSprite(x=4, y=8 - 32 - 0.01)
|
|
191
|
+
s.on_ground = True
|
|
192
|
+
res = r.move_platformer_with_slide(s, ts, {(0, 0): 6}, dt=0.016, input_x=0)
|
|
193
|
+
assert res.on_ground is True
|
|
194
|
+
assert res.ground_angle == 0.0
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def test_explicit_velocity_participates_in_slope_follow():
|
|
198
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
199
|
+
ts = make_tileset()
|
|
200
|
+
s = MockSprite(x=160, y=169.99, w=8, h=16)
|
|
201
|
+
s.on_ground = True
|
|
202
|
+
res = r.move_platformer_with_slide(
|
|
203
|
+
s, ts, {(5, 5): 2}, dt=0.016, input_x=0, velocity=(200.0, 0.0)
|
|
204
|
+
)
|
|
205
|
+
assert res.on_ground is True
|
|
206
|
+
assert res.ground_angle == 45.0
|
|
207
|
+
assert s.x > 160
|
|
208
|
+
assert s.y < 169.99
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_world_x_preserved_flat_vs_slope():
|
|
212
|
+
# World-X semantics: same input gives same X displacement; slope adds Y.
|
|
213
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
214
|
+
ts = make_tileset()
|
|
215
|
+
flat = MockSprite(x=160, y=160 - 32 - 0.01)
|
|
216
|
+
flat.on_ground = True
|
|
217
|
+
r.move_platformer_with_slide(flat, ts, {(5, 5): 0}, dt=0.016, input_x=1)
|
|
218
|
+
sloped = MockSprite(x=160, y=169.99, w=8, h=16)
|
|
219
|
+
sloped.on_ground = True
|
|
220
|
+
r.move_platformer_with_slide(sloped, ts, {(5, 5): 2}, dt=0.016, input_x=1)
|
|
221
|
+
assert sloped.x == flat.x
|
|
222
|
+
assert sloped.y < 169.99
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def test_body_ground_stays_flat_conservative():
|
|
226
|
+
world = PhysicsWorld(tile_map={}, tileset_collision=None, tile_size=(32, 32))
|
|
227
|
+
world.add_body(
|
|
228
|
+
Body(collision_shape=RectangleShape(width=200, height=16), x=0, y=80)
|
|
229
|
+
)
|
|
230
|
+
runner = CollisionRunner.from_world(world, game_type="platformer")
|
|
231
|
+
s = MockSprite(x=50, y=80 - 32 - 0.01)
|
|
232
|
+
s.on_ground = True
|
|
233
|
+
res = runner.move_platformer_with_slide(s, None, None, dt=0.016, input_x=0)
|
|
234
|
+
assert res.on_ground is True
|
|
235
|
+
assert res.ground_angle == 0.0
|
|
236
|
+
assert res.ground_normal == (0.0, -1.0)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def test_y_query_delegates_to_info_query():
|
|
240
|
+
r = CollisionRunner.from_game_type("platformer", (32, 32))
|
|
241
|
+
ts = make_tileset()
|
|
242
|
+
s = MockSprite(x=160, y=160 - 32 - 5)
|
|
243
|
+
y = r._find_walkable_ground_y(s, ts, {(5, 5): 0}, max_up=10.0, max_down=10.0)
|
|
244
|
+
info = r._find_walkable_ground_info(s, ts, {(5, 5): 0}, max_up=10.0, max_down=10.0)
|
|
245
|
+
assert y is not None and info is not None
|
|
246
|
+
assert y == info.y
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""Movement types shared by the collision runner."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from enum import Enum
|
|
7
|
-
|
|
8
|
-
Vector2 = tuple[float, float]
|
|
9
|
-
|
|
10
|
-
class MovementMode(Enum):
|
|
11
|
-
"""Movement modes for collision runner"""
|
|
12
|
-
|
|
13
|
-
SLIDE = "slide"
|
|
14
|
-
GROUNDED = "grounded"
|
|
15
|
-
PLATFORMER = "platformer"
|
|
16
|
-
RPG = "rpg"
|
|
17
|
-
|
|
18
|
-
@dataclass
|
|
19
|
-
class CollisionResult:
|
|
20
|
-
"""Result of collision detection and resolution"""
|
|
21
|
-
|
|
22
|
-
collided: bool = False
|
|
23
|
-
final_x: float = 0.0
|
|
24
|
-
final_y: float = 0.0
|
|
25
|
-
hit_wall_x: bool = False
|
|
26
|
-
hit_wall_y: bool = False
|
|
27
|
-
hit_ceiling: bool = False
|
|
28
|
-
on_ground: bool = False
|
|
29
|
-
slide_vector: Vector2 | None = None
|
|
30
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/animation_player.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/manager.py
RENAMED
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/collision/shapes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/__init__.py
RENAMED
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/nav_grid.py
RENAMED
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/path_follower.py
RENAMED
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/navigation/pathfinder.py
RENAMED
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser/runtime/object_collision.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tilemap_parser-5.2.0 → tilemap_parser-5.2.1}/src/tilemap_parser.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|