Browse Source

Render map

master
Garrit Franke 3 years ago
parent
commit
3f96954bcf
  1. 1
      .gitignore
  2. 36
      src/main.rs

1
.gitignore vendored

@ -1,2 +1,3 @@
/target
log
.vscode/

36
src/main.rs

@ -16,10 +16,13 @@ use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::{clear, cursor, screen};
const MAP_SIZE_X: usize = 100;
const MAP_SIZE_Y: usize = 100;
struct GOL {
screen: Box<dyn Write>,
player: Player,
map: NoiseMap,
map: Box<[[char; MAP_SIZE_X]; MAP_SIZE_Y]>,
}
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
@ -39,20 +42,29 @@ impl GOL {
let fbm = Fbm::new();
let map_size_x = 100;
let map_size_y = 100;
let map = PlaneMapBuilder::new(&fbm)
.set_size(map_size_x, map_size_y)
let noise_map = PlaneMapBuilder::new(&fbm)
.set_size(MAP_SIZE_X, MAP_SIZE_Y)
.set_x_bounds(-5.0, 5.0)
.set_y_bounds(-5.0, 5.0)
.build();
let mut map: Box<[[char; MAP_SIZE_X]; MAP_SIZE_Y]> =
Box::new([[' '; MAP_SIZE_X]; MAP_SIZE_Y]);
for (i, row) in map.clone().iter().enumerate() {
for (j, _) in row.iter().enumerate() {
map[i][j] = match noise_map.get_value(i, j) {
v if v > 0.0 => '#',
_ => ' ',
}
}
}
let mut s = Self {
screen: Box::new(screen),
player: Player {
pos: Pos { x: 0, y: 0 },
},
map,
map: map,
};
s.write(&termion::clear::All);
@ -134,14 +146,10 @@ fn draw(game: &mut GOL) {
game.write(&'X');
for col in 1..size.0 {
for row in 1..size.1 {
if game.map.get_value(
(row + game.player.pos.x).into(),
(col + game.player.pos.y).into(),
) > 0.1
{
game.write(&cursor::Goto(row, col));
game.write(&'#');
}
let cell: char =
game.map[(row + game.player.pos.x) as usize][(col + game.player.pos.y) as usize];
game.write(&cursor::Goto(row, col));
game.write(&cell);
}
}
game.flush();

Loading…
Cancel
Save