Skip to content

Commit

Permalink
TileType: Floor->Plain, Lava->Rocks + added 'execute::create_terrain'
Browse files Browse the repository at this point in the history
  • Loading branch information
ozkriff committed Dec 1, 2017
1 parent 33952d8 commit b40c7b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
12 changes: 11 additions & 1 deletion src/core/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -295,6 +295,16 @@ fn random_free_sector_pos(state: &State, player_id: PlayerId) -> Option<PosHex>
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<F>(state: &mut State, cb: &mut F)
where
Expand Down
13 changes: 4 additions & 9 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/core/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/screen/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -135,6 +135,7 @@ fn build_gui(context: &mut Context) -> Gui<GuiCommand> {

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);
Expand Down

0 comments on commit b40c7b9

Please sign in to comment.