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