fix merge
This commit is contained in:
parent
c13b96d88b
commit
a4a96c809d
5 changed files with 32 additions and 35 deletions
|
@ -3,10 +3,10 @@ mod grid;
|
|||
mod player;
|
||||
mod room;
|
||||
|
||||
use comfy::EngineContext;
|
||||
use grid::Grid;
|
||||
use player::Player;
|
||||
use room::Room;
|
||||
use self::{grid::Grid, player::Player, room::Room};
|
||||
use super::Activity;
|
||||
use crate::State;
|
||||
use comfy::{error, EngineContext};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HouseState {
|
||||
|
@ -15,18 +15,20 @@ pub struct HouseState {
|
|||
player: Player
|
||||
}
|
||||
|
||||
pub fn setup(state: &mut crate::State, ctx: &mut EngineContext<'_>) {
|
||||
if let Some(house) = state.house() {
|
||||
impl HouseState {
|
||||
pub fn generate_new_house(ctx: &mut EngineContext<'_>) -> Self {
|
||||
let room = Room::new(ctx);
|
||||
let player = Player::new(&room);
|
||||
HouseState { room, player }
|
||||
};
|
||||
|
||||
state.house = Some(house);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) {
|
||||
if let Some(house) = &state.house {
|
||||
pub fn draw(state: &State, _ctx: &comfy::EngineContext<'_>) {
|
||||
let Some(house) = state.house() else {
|
||||
error!("How can I render a house when I'm not in one?!?");
|
||||
return;
|
||||
};
|
||||
|
||||
//Draw House
|
||||
house.room.draw();
|
||||
|
||||
|
@ -35,12 +37,11 @@ pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) {
|
|||
|
||||
//Draw Player
|
||||
house.player.draw();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(state: &mut crate::State, ctx: &mut comfy::EngineContext<'_>) {
|
||||
let house = state.house_mut();
|
||||
house.player.update(&house.grid);
|
||||
pub fn update(state: &mut State, ctx: &mut comfy::EngineContext<'_>) {
|
||||
let house = state.house_mut(ctx);
|
||||
house.player.update(&house.room.grid);
|
||||
|
||||
if house.player.is_moving_to_right_room(&house.room) {
|
||||
house.room = Room::new(ctx);
|
||||
|
|
|
@ -7,7 +7,5 @@ pub mod overworld;
|
|||
pub enum Activity {
|
||||
House(IVec2),
|
||||
#[default]
|
||||
House,
|
||||
#[allow(dead_code)]
|
||||
Overworld
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
|
|||
draw_circle(state.ghost.overworld_pos, 0.5, RED, ZLayer::Ghost.into());
|
||||
}
|
||||
|
||||
fn update_move_player(state: &mut State) {
|
||||
fn update_move_player(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||
let now = Instant::now();
|
||||
|
||||
// Are there any pending position updates? If so, we ignore all user input and execute
|
||||
|
@ -160,18 +160,18 @@ fn update_move_player(state: &mut State) {
|
|||
if current_tile.can_enter_house() {
|
||||
info!("enter house at {tile_pos}");
|
||||
state.activity = Activity::House(tile_pos);
|
||||
state.house_mut(); // gen new house
|
||||
state.house_mut(ctx); // gen new house
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(state: &mut State, _ctx: &mut EngineContext<'_>) {
|
||||
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||
let mut camera = main_camera_mut();
|
||||
camera.center = Vec2::ZERO;
|
||||
camera.zoom = 30.0;
|
||||
|
||||
// move player
|
||||
update_move_player(state);
|
||||
update_move_player(state, ctx);
|
||||
|
||||
// generate more chunks if needed
|
||||
{
|
||||
|
|
|
@ -88,8 +88,6 @@ impl Sub<i32> for ZLayer {
|
|||
|
||||
pub fn setup(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||
Assets::load(ctx);
|
||||
|
||||
house::setup(state, ctx);
|
||||
}
|
||||
|
||||
pub fn update(state: &mut State, engine: &mut EngineContext<'_>) {
|
||||
|
|
|
@ -40,13 +40,13 @@ impl State {
|
|||
}
|
||||
|
||||
fn house(&self) -> Option<&HouseState> {
|
||||
self.houses.get(&self.get_house_pos().unwrap())
|
||||
self.houses.get(&self.get_house_pos()?)
|
||||
}
|
||||
|
||||
fn house_mut(&mut self) -> &mut HouseState {
|
||||
fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> &mut HouseState {
|
||||
self.houses
|
||||
.entry(self.get_house_pos().unwrap())
|
||||
.or_insert_with(HouseState::default)
|
||||
.or_insert_with(|| HouseState::generate_new_house(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue