diff --git a/src/activities/overworld/mod.rs b/src/activities/overworld/mod.rs index 803a452..2d39c97 100644 --- a/src/activities/overworld/mod.rs +++ b/src/activities/overworld/mod.rs @@ -1,14 +1,10 @@ use comfy::{ - draw_circle, draw_rect_outline, draw_sprite, main_camera_mut, EngineContext, IVec2, - Vec2, RED, WHITE, + draw_circle, draw_rect_outline, draw_sprite, is_key_down, is_key_pressed, + main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE }; use log::info; -use comfy::is_key_pressed; -use comfy::is_key_down; -use comfy::KeyCode; -use crate::game::Ghost; -use crate::game::ZLayer; +use crate::game::{Ghost, ZLayer}; pub mod worldgen; @@ -21,7 +17,7 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) { coords.as_vec2(), WHITE, ZLayer::MapMax - i, - Vec2::ONE, + Vec2::ONE ); draw_rect_outline(coords.as_vec2(), Vec2::ONE, 0.1, RED, 10); } @@ -30,7 +26,7 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) { state.ghost.overworld_pos.as_vec2(), 0.5, RED, - ZLayer::Ghost.into(), + ZLayer::Ghost.into() ); } @@ -43,32 +39,32 @@ pub fn update(state: &mut crate::State, _engine: &mut EngineContext<'_>) { // move player if is_key_down(KeyCode::Up) { - ghost_pos.y +=1; + ghost_pos.y += 1; } if is_key_down(KeyCode::Down) { - ghost_pos.y -=1; + ghost_pos.y -= 1; } if is_key_down(KeyCode::Left) { - ghost_pos.x -=1; + ghost_pos.x -= 1; } if is_key_down(KeyCode::Right) { - ghost_pos.x +=1; + ghost_pos.x += 1; } // generate more chunks if needed { let half_viewport = (camera.world_viewport() * 0.5 + 3.0).as_ivec2(); - state - .overworld - .get_or_generate_tile(*ghost_pos + IVec2::new(half_viewport.x, half_viewport.y)); - state - .overworld - .get_or_generate_tile(*ghost_pos + IVec2::new(half_viewport.x, -half_viewport.y)); - state - .overworld - .get_or_generate_tile(*ghost_pos + IVec2::new(-half_viewport.x, half_viewport.y)); - state - .overworld - .get_or_generate_tile(*ghost_pos + IVec2::new(-half_viewport.x, -half_viewport.y)); + state.overworld.get_or_generate_tile( + *ghost_pos + IVec2::new(half_viewport.x, half_viewport.y) + ); + state.overworld.get_or_generate_tile( + *ghost_pos + IVec2::new(half_viewport.x, -half_viewport.y) + ); + state.overworld.get_or_generate_tile( + *ghost_pos + IVec2::new(-half_viewport.x, half_viewport.y) + ); + state.overworld.get_or_generate_tile( + *ghost_pos + IVec2::new(-half_viewport.x, -half_viewport.y) + ); } } diff --git a/src/game.rs b/src/game.rs index f21698c..aa9ac70 100644 --- a/src/game.rs +++ b/src/game.rs @@ -11,7 +11,7 @@ pub struct Ghost { pub charge: f32, /// max electric charge of the Ghost pub max_charge: f32, - pub overworld_pos: IVec2, + pub overworld_pos: IVec2 } impl Default for Ghost { @@ -19,7 +19,7 @@ impl Default for Ghost { Self { charge: 1000.0, max_charge: 1000.0, - overworld_pos: IVec2::ZERO, + overworld_pos: IVec2::ZERO } } }