|
|
|
@ -4,6 +4,7 @@ mod inventory;
|
|
|
|
|
mod map; |
|
|
|
|
mod traits; |
|
|
|
|
use crate::inventory::Inventory; |
|
|
|
|
use crate::inventory::InventoryView; |
|
|
|
|
use crate::map::Chunk; |
|
|
|
|
use crate::traits::Render; |
|
|
|
|
use map::TileType; |
|
|
|
@ -24,7 +25,7 @@ pub struct State {
|
|
|
|
|
world_pos: (i32, i32), |
|
|
|
|
seed: u64, |
|
|
|
|
// @cleanup: Move to player struct
|
|
|
|
|
player_inventory: Inventory, |
|
|
|
|
player_inventory: InventoryView, |
|
|
|
|
player_position: usize, |
|
|
|
|
selected_object: Option<TileType>, |
|
|
|
|
visible: Vec<bool>, |
|
|
|
@ -56,13 +57,26 @@ impl State {
|
|
|
|
|
chunks.insert(key, chunk); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mut player_inventory = Inventory::new(); |
|
|
|
|
player_inventory.push(inventory::Item { |
|
|
|
|
name: "Axe".to_string(), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
player_inventory.push(inventory::Item { |
|
|
|
|
name: "Water".to_string(), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
player_inventory.push(inventory::Item { |
|
|
|
|
name: "Wood".to_string(), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let state = State { |
|
|
|
|
mode: DisplayMode::Game, |
|
|
|
|
world_pos: (0, 0), |
|
|
|
|
view: chunks.get(&(0, 0)).unwrap().to_vec(), |
|
|
|
|
loaded_chunks: Box::new(chunks), |
|
|
|
|
seed, |
|
|
|
|
player_inventory: Inventory::new(), |
|
|
|
|
player_inventory: InventoryView::new(player_inventory), |
|
|
|
|
player_position: (25 * 80) + 40, // Equivalent to point2d_to_index(40, 25) but we haven't initialized it yet
|
|
|
|
|
visible: vec![false; 80 * 50], |
|
|
|
|
selected_object: None, |
|
|
|
@ -139,36 +153,48 @@ impl GameState for State {
|
|
|
|
|
None => {} // Nothing happened
|
|
|
|
|
Some(key) => { |
|
|
|
|
// A key is pressed or held
|
|
|
|
|
match key { |
|
|
|
|
// Numpad
|
|
|
|
|
VirtualKeyCode::Numpad8 => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::Numpad4 => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::Numpad6 => self.move_player(Point::new(1, 0)), |
|
|
|
|
VirtualKeyCode::Numpad2 => self.move_player(Point::new(0, 1)), |
|
|
|
|
|
|
|
|
|
// Numpad diagonals
|
|
|
|
|
VirtualKeyCode::Numpad7 => self.move_player(Point::new(-1, -1)), |
|
|
|
|
VirtualKeyCode::Numpad9 => self.move_player(Point::new(1, -1)), |
|
|
|
|
VirtualKeyCode::Numpad1 => self.move_player(Point::new(-1, 1)), |
|
|
|
|
VirtualKeyCode::Numpad3 => self.move_player(Point::new(1, 1)), |
|
|
|
|
|
|
|
|
|
// Cursors
|
|
|
|
|
VirtualKeyCode::Up => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::Down => self.move_player(Point::new(0, 1)), |
|
|
|
|
VirtualKeyCode::Left => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::Right => self.move_player(Point::new(1, 0)), |
|
|
|
|
|
|
|
|
|
// L33t keys
|
|
|
|
|
VirtualKeyCode::W => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::S => self.move_player(Point::new(0, 1)), |
|
|
|
|
VirtualKeyCode::A => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::D => self.move_player(Point::new(1, 0)), |
|
|
|
|
|
|
|
|
|
VirtualKeyCode::I => self.mode = DisplayMode::Inventory, |
|
|
|
|
|
|
|
|
|
VirtualKeyCode::Escape => self.mode = DisplayMode::Game, |
|
|
|
|
|
|
|
|
|
_ => {} // Ignore all the other possibilities
|
|
|
|
|
// @cleanup: A LOT of redundant code
|
|
|
|
|
match self.mode { |
|
|
|
|
DisplayMode::Game => { |
|
|
|
|
match key { |
|
|
|
|
// Numpad
|
|
|
|
|
VirtualKeyCode::Numpad8 => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::Numpad4 => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::Numpad6 => self.move_player(Point::new(1, 0)), |
|
|
|
|
VirtualKeyCode::Numpad2 => self.move_player(Point::new(0, 1)), |
|
|
|
|
// Numpad diagonals
|
|
|
|
|
VirtualKeyCode::Numpad7 => self.move_player(Point::new(-1, -1)), |
|
|
|
|
VirtualKeyCode::Numpad9 => self.move_player(Point::new(1, -1)), |
|
|
|
|
VirtualKeyCode::Numpad1 => self.move_player(Point::new(-1, 1)), |
|
|
|
|
VirtualKeyCode::Numpad3 => self.move_player(Point::new(1, 1)), |
|
|
|
|
// Cursors
|
|
|
|
|
VirtualKeyCode::Up => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::Down => self.move_player(Point::new(0, 1)), |
|
|
|
|
VirtualKeyCode::Left => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::Right => self.move_player(Point::new(1, 0)), |
|
|
|
|
// L33t keys
|
|
|
|
|
VirtualKeyCode::W => self.move_player(Point::new(0, -1)), |
|
|
|
|
VirtualKeyCode::S => self.move_player(Point::new(0, 1)), |
|
|
|
|
VirtualKeyCode::A => self.move_player(Point::new(-1, 0)), |
|
|
|
|
VirtualKeyCode::D => self.move_player(Point::new(1, 0)), |
|
|
|
|
// Views
|
|
|
|
|
VirtualKeyCode::I => self.mode = DisplayMode::Inventory, |
|
|
|
|
_ => {} // Ignore all the other possibilities
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DisplayMode::Inventory => { |
|
|
|
|
match key { |
|
|
|
|
// Numpad
|
|
|
|
|
VirtualKeyCode::Numpad8 => self.player_inventory.selection_up(), |
|
|
|
|
VirtualKeyCode::Numpad2 => self.player_inventory.selection_down(), |
|
|
|
|
// Cursors
|
|
|
|
|
VirtualKeyCode::Up => self.player_inventory.selection_up(), |
|
|
|
|
VirtualKeyCode::Down => self.player_inventory.selection_down(), |
|
|
|
|
// Views
|
|
|
|
|
VirtualKeyCode::Escape => self.mode = DisplayMode::Game, |
|
|
|
|
_ => {} // Ignore all the other possibilities
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|