diff --git a/src/game.rs b/src/game.rs index 936373e..4e75fa3 100644 --- a/src/game.rs +++ b/src/game.rs @@ -86,6 +86,7 @@ impl Sub for ZLayer { } pub fn update(state: &mut State, engine: &mut EngineContext<'_>) { + state.score += engine.delta * 10.0; match state.activity { Activity::House => house::update(state, engine), Activity::Overworld => overworld::update(state, engine) diff --git a/src/main.rs b/src/main.rs index 0f0fe28..86d7b2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,8 @@ struct State { activity: Activity, ghost: Ghost, overworld: Overworld, - house: HouseState + house: HouseState, + score: f32 } impl GameLoop for State { diff --git a/src/ui.rs b/src/ui.rs index 7de61ee..9d434b2 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,10 +1,11 @@ use crate::State; use comfy::{ - draw_rect, draw_rect_outline, screen_height, screen_to_world, screen_width, - EngineContext, Vec2, BLUE, RED + draw_rect, draw_rect_outline, egui, screen_height, screen_to_world, screen_width, + EngineContext, Vec2, BLUE, RED, WHITE }; +use egui::widget_text::RichText; -pub fn draw(state: &State, _engine: &EngineContext<'_>) { +pub fn draw_batterie(state: &State, _engine: &EngineContext<'_>) { // seperate fill state into smaller section for better readability let section_count = 5; let mut start_positon = screen_to_world(Vec2::new(screen_width(), screen_height())); @@ -29,3 +30,22 @@ pub fn draw(state: &State, _engine: &EngineContext<'_>) { draw_rect_outline(position, section_size, 0.1, RED, 100); } } + +pub fn draw_highscore(state: &State, _engine: &EngineContext<'_>) { + egui::Area::new("score") + .anchor(egui::Align2::RIGHT_TOP, egui::vec2(0.0, 0.0)) + .show(egui(), |ui| { + ui.label( + RichText::new(format!("{:.0}", state.score)) + .color(WHITE) + .monospace() + .size(16.0) + .strong() + ); + }); +} + +pub fn draw(state: &State, engine: &EngineContext<'_>) { + draw_batterie(state, engine); + draw_highscore(state, engine); +}