Overworld Movement #9
2 changed files with 23 additions and 27 deletions
|
@ -1,14 +1,10 @@
|
||||||
use comfy::{
|
use comfy::{
|
||||||
draw_circle, draw_rect_outline, draw_sprite, main_camera_mut, EngineContext, IVec2,
|
draw_circle, draw_rect_outline, draw_sprite, is_key_down, is_key_pressed,
|
||||||
Vec2, RED, WHITE,
|
main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
use comfy::is_key_pressed;
|
|
||||||
use comfy::is_key_down;
|
|
||||||
use comfy::KeyCode;
|
|
||||||
|
|
||||||
use crate::game::Ghost;
|
use crate::game::{Ghost, ZLayer};
|
||||||
use crate::game::ZLayer;
|
|
||||||
|
|
||||||
pub mod worldgen;
|
pub mod worldgen;
|
||||||
|
|
||||||
|
@ -21,7 +17,7 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
|
||||||
coords.as_vec2(),
|
coords.as_vec2(),
|
||||||
WHITE,
|
WHITE,
|
||||||
ZLayer::MapMax - i,
|
ZLayer::MapMax - i,
|
||||||
Vec2::ONE,
|
Vec2::ONE
|
||||||
);
|
);
|
||||||
draw_rect_outline(coords.as_vec2(), Vec2::ONE, 0.1, RED, 10);
|
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(),
|
state.ghost.overworld_pos.as_vec2(),
|
||||||
0.5,
|
0.5,
|
||||||
RED,
|
RED,
|
||||||
ZLayer::Ghost.into(),
|
ZLayer::Ghost.into()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,32 +39,32 @@ pub fn update(state: &mut crate::State, _engine: &mut EngineContext<'_>) {
|
||||||
|
|
||||||
// move player
|
// move player
|
||||||
if is_key_down(KeyCode::Up) {
|
if is_key_down(KeyCode::Up) {
|
||||||
ghost_pos.y +=1;
|
ghost_pos.y += 1;
|
||||||
}
|
}
|
||||||
if is_key_down(KeyCode::Down) {
|
if is_key_down(KeyCode::Down) {
|
||||||
ghost_pos.y -=1;
|
ghost_pos.y -= 1;
|
||||||
}
|
}
|
||||||
if is_key_down(KeyCode::Left) {
|
if is_key_down(KeyCode::Left) {
|
||||||
ghost_pos.x -=1;
|
ghost_pos.x -= 1;
|
||||||
}
|
}
|
||||||
if is_key_down(KeyCode::Right) {
|
if is_key_down(KeyCode::Right) {
|
||||||
ghost_pos.x +=1;
|
ghost_pos.x += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate more chunks if needed
|
// generate more chunks if needed
|
||||||
{
|
{
|
||||||
let half_viewport = (camera.world_viewport() * 0.5 + 3.0).as_ivec2();
|
let half_viewport = (camera.world_viewport() * 0.5 + 3.0).as_ivec2();
|
||||||
state
|
state.overworld.get_or_generate_tile(
|
||||||
.overworld
|
*ghost_pos + IVec2::new(half_viewport.x, half_viewport.y)
|
||||||
.get_or_generate_tile(*ghost_pos + IVec2::new(half_viewport.x, half_viewport.y));
|
);
|
||||||
state
|
state.overworld.get_or_generate_tile(
|
||||||
.overworld
|
*ghost_pos + IVec2::new(half_viewport.x, -half_viewport.y)
|
||||||
.get_or_generate_tile(*ghost_pos + IVec2::new(half_viewport.x, -half_viewport.y));
|
);
|
||||||
state
|
state.overworld.get_or_generate_tile(
|
||||||
.overworld
|
*ghost_pos + IVec2::new(-half_viewport.x, half_viewport.y)
|
||||||
.get_or_generate_tile(*ghost_pos + IVec2::new(-half_viewport.x, half_viewport.y));
|
);
|
||||||
state
|
state.overworld.get_or_generate_tile(
|
||||||
.overworld
|
*ghost_pos + IVec2::new(-half_viewport.x, -half_viewport.y)
|
||||||
.get_or_generate_tile(*ghost_pos + IVec2::new(-half_viewport.x, -half_viewport.y));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct Ghost {
|
||||||
pub charge: f32,
|
pub charge: f32,
|
||||||
/// max electric charge of the Ghost
|
/// max electric charge of the Ghost
|
||||||
pub max_charge: f32,
|
pub max_charge: f32,
|
||||||
pub overworld_pos: IVec2,
|
pub overworld_pos: IVec2
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Ghost {
|
impl Default for Ghost {
|
||||||
|
@ -19,7 +19,7 @@ impl Default for Ghost {
|
||||||
Self {
|
Self {
|
||||||
charge: 1000.0,
|
charge: 1000.0,
|
||||||
max_charge: 1000.0,
|
max_charge: 1000.0,
|
||||||
overworld_pos: IVec2::ZERO,
|
overworld_pos: IVec2::ZERO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue