From 612d9e49138ef50df53e097499118497bb221d8d Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sun, 7 Jul 2024 18:45:40 +0200 Subject: [PATCH] fmt --- src/activities/house/room.rs | 5 ++- src/game.rs | 69 ++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/activities/house/room.rs b/src/activities/house/room.rs index 9618f25..7d3a06c 100644 --- a/src/activities/house/room.rs +++ b/src/activities/house/room.rs @@ -1,11 +1,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, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE, + draw_rect, draw_rect_outline, draw_sprite, error, random_i32, texture_id, vec2, + EngineContext, HashSet, RandomRange as _, Vec2, GREEN, PURPLE, RED, WHITE }; use indexmap::IndexSet; -use comfy::texture_id; pub const SCALE: f32 = 4.0; diff --git a/src/game.rs b/src/game.rs index 31a4634..534288d 100644 --- a/src/game.rs +++ b/src/game.rs @@ -76,7 +76,7 @@ pub enum ZLayer { Human = 0, Ghost = 1, UI = 100, - GameOver = 1000, + GameOver = 1000 } impl From for i32 { @@ -135,44 +135,43 @@ 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; - - // 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 score. It's based on time. + state.score += ctx.delta * 10.0; + // Update the currently active activity. 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; - } - }, - _ => {} + Activity::House(_) => house::update(state, ctx), + Activity::Overworld => overworld::update(state, ctx) } - }} - 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); }