add gameover #20

Merged
LuckyTurtleDev merged 4 commits from gameover into main 2024-07-07 16:46:29 +00:00
2 changed files with 12 additions and 3 deletions
Showing only changes of commit fb5149945e - Show all commits

View file

@ -2,10 +2,10 @@ use super::{furniture::Furniture, grid::Grid};
use crate::game::{self, ZLayer};
use comfy::{
draw_rect, draw_rect_outline, draw_sprite, error, random_i32, vec2, EngineContext,
HashSet, Index, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE
PURPLE, RED, WHITE
HashSet, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE,
};
use indexmap::IndexSet;
use comfy::texture_id;
pub const SCALE: f32 = 4.0;

View file

@ -75,7 +75,8 @@ pub enum ZLayer {
MapMax = -1,
Human = 0,
Ghost = 1,
UI = 100
UI = 100,
GameOver = 1000,
}
impl From<ZLayer> for i32 {
@ -134,6 +135,8 @@ pub const HOUSE_DISCHARGE_RATE: f32 = 30.0;
pub const GHOST_CHARGE_RATE: f32 = 200.0;
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
if state.ghost.charge > 0.0 {
// Update the score. It's based on time.
state.score += ctx.delta * 10.0;
@ -168,6 +171,9 @@ pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
},
_ => {}
}
}}
else {
crate::game_over::update(state, ctx);
}
// Make sure the ghost's charge never drops below 0.
@ -180,4 +186,7 @@ pub fn draw(state: &State, engine: &EngineContext<'_>) {
Activity::Overworld => overworld::draw(state, engine)
}
crate::ui::draw(state, engine);
if state.ghost.charge <= 0.0 {
crate::game_over::draw(state, engine);
}
}