turtlegame/src/main.rs

93 lines
1.8 KiB
Rust
Raw Normal View History

#![warn(rust_2018_idioms)]
#![deny(clippy::wildcard_imports)]
#![forbid(elided_lifetimes_in_paths, unsafe_code)]
mod assets {
include!(env!("ASSETS_RS"));
}
2024-07-06 13:33:58 +02:00
mod activities;
2024-07-05 23:10:25 +02:00
mod game;
mod ui;
2024-07-05 23:10:25 +02:00
use self::{
activities::{house::HouseState, overworld::worldgen::Overworld, Activity},
game::Ghost
};
use comfy::{
2024-07-07 14:59:39 +02:00
etagere::euclid::default, init_game_config, pollster, run_comfy_main_async,
DevConfig, EngineContext, EngineState, GameConfig, GameLoop, HashMap, IVec2
};
2024-07-05 23:10:25 +02:00
const GAME_NAME: &str = "Powercreep";
#[derive(Debug, Default)]
2024-07-06 13:33:58 +02:00
struct State {
setup_called: bool,
activity: Activity,
ghost: Ghost,
overworld: Overworld,
houses: HashMap<IVec2, HouseState>,
2024-07-07 12:02:48 +02:00
score: f32
2024-07-06 13:33:58 +02:00
}
2024-07-05 23:10:25 +02:00
impl State {
fn get_house_pos(&self) -> Option<IVec2> {
match self.activity {
Activity::House(pos) => Some(pos),
_ => None
}
}
fn house(&self) -> Option<&HouseState> {
self.houses.get(&self.get_house_pos()?)
}
fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> &mut HouseState {
self.houses
.entry(self.get_house_pos().unwrap())
.or_insert_with(|| HouseState::generate_new_house(ctx))
}
}
2024-07-05 23:10:25 +02:00
impl GameLoop for State {
fn new(_c: &mut EngineState) -> Self {
2024-07-06 13:33:58 +02:00
Self::default()
2024-07-05 23:10:25 +02:00
}
fn update(&mut self, ctx: &mut EngineContext<'_>) {
if !self.setup_called {
game::setup(self, ctx);
self.setup_called = true;
}
game::update(self, ctx);
game::draw(self, ctx);
2024-07-05 23:10:25 +02:00
}
}
fn config(config: GameConfig) -> GameConfig {
2024-07-07 14:59:39 +02:00
let dev = DevConfig {
#[cfg(debug_assertions)]
show_fps: true,
..Default::default()
};
GameConfig {
tonemapping_enabled: true,
dev,
2024-07-07 15:03:24 +02:00
target_framerate: 165,
..config
2024-07-07 14:59:39 +02:00
}
2024-07-05 23:10:25 +02:00
}
async fn run() {
init_game_config(GAME_NAME.to_string(), env!("CARGO_PKG_VERSION"), config);
let mut engine = EngineState::new();
let game = State::new(&mut engine);
run_comfy_main_async(game, engine).await;
}
2024-07-05 19:01:09 +02:00
fn main() {
2024-07-05 23:10:25 +02:00
pollster::block_on(run());
}