turtlegame/src/activities/house/mod.rs

46 lines
1,004 B
Rust
Raw Normal View History

mod grid;
mod player;
2024-07-07 00:01:46 +02:00
mod room;
use grid::Grid;
use player::Player;
2024-07-07 00:01:46 +02:00
use room::Room;
2024-07-07 00:48:37 +02:00
#[derive(Debug)]
pub struct HouseState {
2024-07-07 00:01:46 +02:00
room: Room,
//grid: Grid,
player: Player
}
2024-07-07 00:48:37 +02:00
impl Default for HouseState {
fn default() -> Self {
let room = Room::default();
let player = Player::new(&room);
Self { room, player}
}
}
pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
2024-07-07 00:01:46 +02:00
//Draw House
state.house.room.draw();
//Draw Grid
2024-07-07 00:01:46 +02:00
//state.house.grid.draw();
//Draw Player
state.house.player.draw();
}
pub fn update(state: &mut crate::State, _engine: &mut comfy::EngineContext<'_>) {
2024-07-07 00:01:46 +02:00
state.house.player.update(&state.house.room.grid);
2024-07-07 00:48:37 +02:00
if state.house.player.is_moving_to_right_room(&state.house.room) {
state.house.room = Room::default();
state.house.player.reset_on_room(&state.house.room, true);
} else if state.house.player.is_moving_to_left_room(&state.house.room) {
state.house.room = Room::default();
state.house.player.reset_on_room(&state.house.room, false);
}
}