Compare commits

..

2 commits

Author SHA1 Message Date
3c4ca4371f
add very ugly camera-follows-player effect
Some checks failed
CI / Docs (push) Has been cancelled
CI / Clippy lints (push) Has been cancelled
CI / Bevy lints (push) Has been cancelled
CI / Tests (push) Has been cancelled
CI / Check web (push) Has been cancelled
CI / Format (push) Failing after 11s
2025-07-17 22:49:06 +08:00
2718983cd1
Add minimal docs on coordinate translations for Gridvania levels 2025-07-17 22:35:42 +08:00
2 changed files with 76 additions and 3 deletions

67
docs/level-layout-doc.txt Normal file
View file

@ -0,0 +1,67 @@
Y ↑
│ Bevy world ↑ LDtk-World ↓
│ (Y increases upward) (increases downward)
│ -32 -16 0 16 32
│ ┌────────────┬─────────────┬─────────────┬─────────────┐ │
│ 32 │ │ │ L2 │ │-32│
│ │ │ │ (top-lvl) │ │ │
│ │ │ │ │ │ │
│ ├────────────┼─────────────┼─────────────┼─────────────┤ │
│ 16 │ │ L1 │ L0 │ L3 │-16│
│ │ │ │ │ │ │
│ │ │ │ (0,0) │ │ │
│ ├────────────┼─────────────O─────────────┼─────────────┤ │
│ 0 │ │ │ L4 │ │ 0 │
│ │ │ │ │ │ │
│ │ │ │ │ │ │
│ ├────────────┴─────────────┴─────────────┴─────────────┤ │
│ -16 │ L5 │ 16│
│ │ (bottom-lvl) │ │
│ │ │ │
│ └──────────────────────────────────────────────────────┘ ↓
└───────────────────────────────────────────────────────────────► X →
-32 -16 0 16 32
```
Legend
──────
• Each square = 16×16 tiles.
• **Bevy Y** increases **upward** (↑).
• **LDtk Y** (both world & inside level) increases **downward** (↓).
Coordinate examples
───────────────────
Level L0 (at origin)
LDtk world anchor (top-left) = (0, -16)
Top-left corner in Bevy world = (0, 16)
Level L1 (left of origin)
LDtk world anchor = (-16, -16)
Top-left corner in Bevy world = (-16, 16)
Level L2 (above origin)
LDtk world anchor = (0, -32 )
Top-left corner in Bevy world = (0, 32)
Level L3 (right origin)
LDtk world anchor = (16, -16)
Top-left corner in Bevy world = (16, -16)
Level L4 (below L3)
LDtk world anchor = (0, 16)
Top-left corner in Bevy world = (0, -16)
Level L5 (below L4, spanning 4 x levels)
LDtk world anchor = (-32, 32)
Top-left corner in Bevy world = (-32, -32)
Player's world-based gridcoords need to be converted to the internal coordinates for a level (so we can match it with
the cached walls HashMap).
To convert between world and in-level coords:
lX = wX - level_world_x
lY = wY - (-level_world_y - level_height)

View file

@ -62,13 +62,14 @@ impl Default for MovementController {
fn apply_movement(
_time: Res<Time>,
mut camera: Query<&mut Transform, With<Camera>>,
movement_query: Query<&MovementController, With<Player>>,
player_transform_query: Query<&Transform, With<Player>>,
player_transform_query: Query<&GlobalTransform, With<Player>>,
mut players: Query<&mut GridCoords, With<Player>>,
level_selection: Res<LevelSelection>,
// level_walls: Res<LevelWalls>,
level_walls: Res<MultiLevelWalls>,
) {
) -> Result {
let level_selection_iid = match level_selection.as_ref() {
LevelSelection::Iid(iid) => iid,
_ => panic!("level should be selected by iid"),
@ -93,7 +94,7 @@ fn apply_movement(
} else {
// unrecognized intent, log a warning
warn!("Unrecognized intent: {:?}", controller.intent);
return;
return Ok(());
};
info!("player old absolute coords: {:?}", player_abs_coords);
let destination = *player_abs_coords + movement_direction;
@ -107,12 +108,17 @@ fn apply_movement(
player_transform_query.single()
);
// transform.translation += velocity.extend(0.0) * time.delta_secs();
if let Ok(player_transform) = player_transform_query.single() {
let mut camera_transform = camera.single_mut()?;
camera_transform.translation = player_transform.translation();
}
} else {
info!("SDENG!");
}
level_walls.debug_collisions(level_selection_iid, &player_abs_coords);
}
}
Ok(())
}
#[derive(Component, Reflect)]