fmt
Some checks failed
Rust / rustfmt (pull_request) Successful in 20s
Rust / clippy (pull_request) Failing after 1m38s
Rust / build (pull_request) Successful in 2m59s

This commit is contained in:
luckyturtledev 2024-07-07 18:45:40 +02:00
parent fb5149945e
commit 612d9e4913
2 changed files with 36 additions and 38 deletions

View file

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

View file

@ -76,7 +76,7 @@ pub enum ZLayer {
Human = 0, Human = 0,
Ghost = 1, Ghost = 1,
UI = 100, UI = 100,
GameOver = 1000, GameOver = 1000
} }
impl From<ZLayer> for i32 { impl From<ZLayer> for i32 {
@ -135,44 +135,43 @@ pub const HOUSE_DISCHARGE_RATE: f32 = 30.0;
pub const GHOST_CHARGE_RATE: f32 = 200.0; pub const GHOST_CHARGE_RATE: f32 = 200.0;
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) { pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
if state.ghost.charge > 0.0 { if state.ghost.charge > 0.0 {
// Update the score. It's based on time. // Update the score. It's based on time.
state.score += ctx.delta * 10.0; state.score += ctx.delta * 10.0;
// Update the currently active activity.
match state.activity {
Activity::House(_) => house::update(state, ctx),
Activity::Overworld => overworld::update(state, ctx)
}
// We update the charge of houses here - the charge will always decrease, even if the
// house is not the current activity.
for (house_pos, house) in &mut state.houses {
house.charge -= ctx.delta * HOUSE_DISCHARGE_RATE;
// Update the currently active activity.
match state.activity { match state.activity {
Activity::House(pos) if *house_pos == pos => { Activity::House(_) => house::update(state, ctx),
// The ghost is currently inside the house. Increase its discarge rate. Activity::Overworld => overworld::update(state, ctx)
house.charge -= ctx.delta * GHOST_DISCHARGE_RATE;
if house.charge < 0.0 {
state.ghost.charge += house.charge;
house.charge = 0.0;
}
// And possibly also charge the ghost when inside a house.
if state.ghost.charge < state.ghost.max_charge {
let charge_transfer = (ctx.delta * GHOST_CHARGE_RATE)
.min(state.ghost.max_charge - state.ghost.charge)
.min(house.charge);
state.ghost.charge += charge_transfer;
house.charge -= charge_transfer;
}
},
_ => {}
} }
}}
else { // We update the charge of houses here - the charge will always decrease, even if the
// house is not the current activity.
for (house_pos, house) in &mut state.houses {
house.charge -= ctx.delta * HOUSE_DISCHARGE_RATE;
match state.activity {
Activity::House(pos) if *house_pos == pos => {
// The ghost is currently inside the house. Increase its discarge rate.
house.charge -= ctx.delta * GHOST_DISCHARGE_RATE;
if house.charge < 0.0 {
state.ghost.charge += house.charge;
house.charge = 0.0;
}
// And possibly also charge the ghost when inside a house.
if state.ghost.charge < state.ghost.max_charge {
let charge_transfer = (ctx.delta * GHOST_CHARGE_RATE)
.min(state.ghost.max_charge - state.ghost.charge)
.min(house.charge);
state.ghost.charge += charge_transfer;
house.charge -= charge_transfer;
}
},
_ => {}
}
}
} else {
crate::game_over::update(state, ctx); crate::game_over::update(state, ctx);
} }