diff --git a/src/core/execute.rs b/src/core/execute.rs index f8825e7d..d7de4a07 100644 --- a/src/core/execute.rs +++ b/src/core/execute.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, VecDeque}; use std::iter::FromIterator; use rand::{thread_rng, Rng}; use core::map::PosHex; -use core::{self, Moves, ObjId, PlayerId, State}; +use core::{self, Moves, ObjId, PlayerId, State, TileType}; use core::command; use core::component::{self, Component}; use core::command::Command; @@ -295,6 +295,16 @@ fn random_free_sector_pos(state: &State, player_id: PlayerId) -> Option None } +pub fn create_terrain(state: &mut State) { + for _ in 0..15 { + let pos = match random_free_pos(state) { + Some(pos) => pos, + None => continue, + }; + state.map.set_tile(pos, TileType::Rocks); + } +} + // TODO: improve the API pub fn create_objects(state: &mut State, cb: &mut F) where diff --git a/src/core/mod.rs b/src/core/mod.rs index f75945c8..b1d1ce66 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -42,13 +42,13 @@ pub struct Jokers(pub i32); #[derive(Clone, Copy, Debug)] pub enum TileType { - Floor, - Lava, + Plain, + Rocks, } impl Default for TileType { fn default() -> Self { - TileType::Floor + TileType::Plain } } @@ -76,13 +76,8 @@ pub struct State { impl State { pub fn new(prototypes: Prototypes) -> Self { let radius = map::Distance(5); // TODO: pass `Options` struct - let mut map = HexMap::new(radius); - { - // TODO: load\generate maps - map.set_tile(PosHex { q: 0, r: 0 }, TileType::Lava); - } Self { - map, + map: HexMap::new(radius), player_id: PlayerId(0), players_count: 2, // TODO: Read from the `Options` struct parts: Parts::new(), diff --git a/src/core/movement.rs b/src/core/movement.rs index 61fc78f4..5f3251a1 100644 --- a/src/core/movement.rs +++ b/src/core/movement.rs @@ -39,8 +39,8 @@ pub fn max_cost() -> MovePoints { pub fn tile_cost(state: &State, _: ObjId, _: PosHex, pos: PosHex) -> MovePoints { match state.map().tile(pos) { - TileType::Floor => MovePoints(1), - TileType::Lava => MovePoints(3), + TileType::Plain => MovePoints(1), + TileType::Rocks => MovePoints(3), } } diff --git a/src/screen/game.rs b/src/screen/game.rs index 1cbae050..4e19824d 100644 --- a/src/screen/game.rs +++ b/src/screen/game.rs @@ -31,8 +31,8 @@ fn make_action_show_tile( let screen_pos = map::hex_to_point(view.tile_size(), at); let mut sprite = Sprite::from_path(context, "tile.png", view.tile_size() * 2.0); match state.map().tile(at) { - TileType::Floor => sprite.set_color([1.0, 1.0, 1.0, 1.0]), - TileType::Lava => sprite.set_color([1.0, 0.7, 0.7, 1.0]), + TileType::Plain => sprite.set_color([1.0, 1.0, 1.0, 1.0]), + TileType::Rocks => sprite.set_color([0.7, 0.7, 0.7, 1.0]), } sprite.set_pos(screen_pos); Box::new(action::Show::new(&view.layers().bg, &sprite)) @@ -135,6 +135,7 @@ fn build_gui(context: &mut Context) -> Gui { fn prepare_map_and_state(context: &mut Context, state: &mut State, view: &mut GameView) { let mut actions = Vec::new(); + execute::create_terrain(state); actions.push(make_action_create_map(state, view, context)); execute::create_objects(state, &mut |state, event, phase| { let action = visualize::visualize(state, view, context, event, phase);