Tests added: - physics_materials.rs: 15 tests (fire, smoke, steam, grass, dirt, bone, wood, stone, lava temp) - physics_interactions.rs: 12 tests (lava+water, fire spread, acid interactions, sand+water) - player_controls.rs: 12 tests (move L/R, jump, double jump, rapid input, wait, continuous) - collision_robust.rs: 10 tests (walls, ceiling, sliding, corridor, slope, dirt wall, unstick) - ragdoll_death.rs: 7 tests (death transition, ragdoll fall, progressive damage, corpse) - determinism.rs: 8 tests (same seed, replay exact, replay partial, recording, 100-tick) - edge_cases.rs: 19 tests (boundary, stress 20 goblins, fill/clear/paint, gravity, camera) - 6 new JSON scenarios (fire chain, lava pool, sand bury, entity fall, steam, acid wall) Fixes: - AABB resolve_aabb_y: add vertical overlap check (was pushing player down when jumping) - AABB resolve_aabb_x: velocity-aware resolution (player was stuck against walls) - check_on_ground: use fractional position check (was always true) - jump_force 1.5 (was 0.8) for 27-body entity - Gravity read from self.verlet (was from clone, SetGravity didn't work) - u8 overflow in lava color (saturating_add) 109 Rust tests, 14 JSON scenarios, 0 warnings, 0 failures
57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
use crate::entity::entity::{Entity, EntityKind, EntityManager, EntityId};
|
|
|
|
pub struct Player {
|
|
pub entity_id: EntityId,
|
|
pub move_speed: f32,
|
|
pub jump_force: f32,
|
|
}
|
|
|
|
impl Player {
|
|
pub fn new(manager: &mut EntityManager) -> Self {
|
|
let id = manager.spawn(EntityKind::Player);
|
|
Self {
|
|
entity_id: id,
|
|
move_speed: 0.3,
|
|
jump_force: 1.5,
|
|
}
|
|
}
|
|
|
|
pub fn spawn_at(&self, manager: &mut EntityManager, cx: f32, cy: f32) {
|
|
if let Some(e) = manager.get_mut(self.entity_id) {
|
|
e.build_humanoid(cx, cy);
|
|
}
|
|
}
|
|
|
|
pub fn move_left(&self, manager: &mut EntityManager) {
|
|
if let Some(e) = manager.get_mut(self.entity_id) {
|
|
e.move_center(-self.move_speed, 0.0);
|
|
}
|
|
}
|
|
|
|
pub fn move_right(&self, manager: &mut EntityManager) {
|
|
if let Some(e) = manager.get_mut(self.entity_id) {
|
|
e.move_center(self.move_speed, 0.0);
|
|
}
|
|
}
|
|
|
|
pub fn jump(&self, manager: &mut EntityManager, on_ground: bool) {
|
|
if on_ground {
|
|
if let Some(e) = manager.get_mut(self.entity_id) {
|
|
e.move_center(0.0, -self.jump_force);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn entity<'a>(&self, manager: &'a EntityManager) -> Option<&'a Entity> {
|
|
manager.get(self.entity_id)
|
|
}
|
|
|
|
pub fn entity_mut<'a>(&self, manager: &'a mut EntityManager) -> Option<&'a mut Entity> {
|
|
manager.get_mut(self.entity_id)
|
|
}
|
|
|
|
pub fn center(&self, manager: &EntityManager) -> (f32, f32) {
|
|
manager.get(self.entity_id).map(|e| e.center()).unwrap_or((0.0, 0.0))
|
|
}
|
|
}
|