Houses have energy that interact with ghosts (#18)
Reviewed-on: #18 Co-authored-by: Dominic <git@msrd0.de> Co-committed-by: Dominic <git@msrd0.de>
This commit is contained in:
parent
2354e34142
commit
0c9624d511
5 changed files with 117 additions and 40 deletions
49
src/game.rs
49
src/game.rs
|
@ -107,12 +107,53 @@ pub fn setup(_state: &mut State, ctx: &mut EngineContext<'_>) {
|
|||
//house::setup(state, ctx);
|
||||
}
|
||||
|
||||
pub fn update(state: &mut State, engine: &mut EngineContext<'_>) {
|
||||
state.score += engine.delta * 10.0;
|
||||
/// The amount of energy a ghost consumes idle.
|
||||
pub const GHOST_DISCHARGE_RATE: f32 = 70.0;
|
||||
/// The amount of energy additionally consumed by a moving ghost.
|
||||
pub const GHOST_DISCHARGE_RATE_MOVEMENT: f32 = 70.0;
|
||||
/// The amount of energy a house consumes idle.
|
||||
pub const HOUSE_DISCHARGE_RATE: f32 = 30.0;
|
||||
/// The amount of energy a ghost can charge when inside a house.
|
||||
pub const GHOST_CHARGE_RATE: f32 = 200.0;
|
||||
|
||||
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||
// 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, engine),
|
||||
Activity::Overworld => overworld::update(state, engine)
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the ghost's charge never drops below 0.
|
||||
state.ghost.charge = state.ghost.charge.max(0.0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue