turtlegame/src/game.rs

62 lines
1.2 KiB
Rust
Raw Normal View History

2024-07-06 13:33:58 +02:00
use crate::{
activities::{house, overworld, Activity},
State
};
2024-07-07 00:52:19 +02:00
use comfy::{EngineContext, IVec2};
use std::ops::Sub;
#[derive(Debug)]
pub struct Ghost {
/// current electric charge of the Ghost
pub charge: f32,
/// max electric charge of the Ghost
2024-07-07 00:52:19 +02:00
pub max_charge: f32,
pub overworld_pos: IVec2,
}
impl Default for Ghost {
fn default() -> Self {
Self {
charge: 1000.0,
2024-07-07 00:52:19 +02:00
max_charge: 1000.0,
overworld_pos: IVec2::ZERO,
}
}
}
#[repr(i32)]
pub enum ZLayer {
MapMax = -1,
Human = 0,
Ghost = 1
}
impl From<ZLayer> for i32 {
fn from(value: ZLayer) -> Self {
// safe because #[repr(i32)]
value as i32
}
}
impl Sub<i32> for ZLayer {
type Output = i32;
fn sub(self, other: i32) -> Self::Output {
i32::from(self) - other
}
}
2024-07-05 23:10:25 +02:00
pub fn update(state: &mut State, engine: &mut EngineContext<'_>) {
2024-07-06 13:33:58 +02:00
match state.activity {
Activity::House => house::update(state, engine),
Activity::Overworld => overworld::update(state, engine)
}
}
2024-07-05 23:10:25 +02:00
pub fn draw(state: &State, engine: &EngineContext<'_>) {
2024-07-06 13:33:58 +02:00
match state.activity {
Activity::House => house::draw(state, engine),
Activity::Overworld => overworld::draw(state, engine)
}
crate::ui::draw(state, engine);
2024-07-05 23:10:25 +02:00
}