enter house
This commit is contained in:
parent
dadc5d59db
commit
814d0f46f6
5 changed files with 52 additions and 12 deletions
|
@ -11,13 +11,16 @@ pub struct HouseState {
|
|||
}
|
||||
|
||||
pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
|
||||
//Draw Grid
|
||||
state.house.grid.draw();
|
||||
if let Some(house) = state.house() {
|
||||
//Draw Grid
|
||||
house.grid.draw();
|
||||
|
||||
//Draw Player
|
||||
state.house.player.draw();
|
||||
//Draw Player
|
||||
house.player.draw();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(state: &mut crate::State, _engine: &mut comfy::EngineContext<'_>) {
|
||||
state.house.player.update(&state.house.grid);
|
||||
let house = state.house_mut();
|
||||
house.player.update(&house.grid);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use comfy::IVec2;
|
||||
|
||||
pub mod house;
|
||||
pub mod overworld;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub enum Activity {
|
||||
#[allow(dead_code)]
|
||||
House,
|
||||
House(IVec2),
|
||||
#[default]
|
||||
Overworld
|
||||
}
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
use crate::{game::ZLayer, State};
|
||||
use crate::{
|
||||
activities::{
|
||||
house::{self, HouseState},
|
||||
Activity
|
||||
},
|
||||
game::ZLayer,
|
||||
State
|
||||
};
|
||||
use comfy::{
|
||||
draw_circle, draw_rect_outline, draw_sprite, error, info, is_key_down,
|
||||
main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE
|
||||
|
@ -146,6 +153,16 @@ fn update_move_player(state: &mut State) {
|
|||
y: requested_pos_diff.y as _
|
||||
};
|
||||
state.ghost.overworld_pos_last_update = now;
|
||||
|
||||
//move into house if player stepp at door
|
||||
{
|
||||
let current_tile = state.overworld.get_or_generate_tile(tile_pos);
|
||||
if current_tile.can_enter_house() {
|
||||
info!("enter house at {tile_pos}");
|
||||
state.activity = Activity::House(tile_pos);
|
||||
state.house_mut(); // gen new house
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(state: &mut State, _ctx: &mut EngineContext<'_>) {
|
||||
|
|
|
@ -88,14 +88,14 @@ 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::House(_) => house::update(state, engine),
|
||||
Activity::Overworld => overworld::update(state, engine)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(state: &State, engine: &EngineContext<'_>) {
|
||||
match state.activity {
|
||||
Activity::House => house::draw(state, engine),
|
||||
Activity::House(_) => house::draw(state, engine),
|
||||
Activity::Overworld => overworld::draw(state, engine)
|
||||
}
|
||||
crate::ui::draw(state, engine);
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -17,7 +17,7 @@ use self::{
|
|||
};
|
||||
use comfy::{
|
||||
init_game_config, pollster, run_comfy_main_async, EngineContext, EngineState,
|
||||
GameConfig, GameLoop
|
||||
GameConfig, GameLoop, HashMap, IVec2
|
||||
};
|
||||
|
||||
const GAME_NAME: &str = "Powercreep";
|
||||
|
@ -28,10 +28,29 @@ struct State {
|
|||
activity: Activity,
|
||||
ghost: Ghost,
|
||||
overworld: Overworld,
|
||||
house: HouseState,
|
||||
houses: HashMap<IVec2, HouseState>,
|
||||
score: f32
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn get_house_pos(&self) -> Option<IVec2> {
|
||||
match self.activity {
|
||||
Activity::House(pos) => Some(pos),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn house(&self) -> Option<&HouseState> {
|
||||
self.houses.get(&self.get_house_pos().unwrap())
|
||||
}
|
||||
|
||||
fn house_mut(&mut self) -> &mut HouseState {
|
||||
self.houses
|
||||
.entry(self.get_house_pos().unwrap())
|
||||
.or_insert_with(HouseState::default)
|
||||
}
|
||||
}
|
||||
|
||||
impl GameLoop for State {
|
||||
fn new(_c: &mut EngineState) -> Self {
|
||||
Self::default()
|
||||
|
|
Loading…
Reference in a new issue