add score
This commit is contained in:
parent
ff743e97b8
commit
dadc5d59db
3 changed files with 26 additions and 4 deletions
|
@ -86,6 +86,7 @@ impl Sub<i32> 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)
|
||||
|
|
|
@ -28,7 +28,8 @@ struct State {
|
|||
activity: Activity,
|
||||
ghost: Ghost,
|
||||
overworld: Overworld,
|
||||
house: HouseState
|
||||
house: HouseState,
|
||||
score: f32
|
||||
}
|
||||
|
||||
impl GameLoop for State {
|
||||
|
|
26
src/ui.rs
26
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue