Browse Source

Fix map directions

master
Garrit Franke 3 years ago
parent
commit
13af7e1ba9
  1. 52
      src/main.rs

52
src/main.rs

@ -29,8 +29,8 @@ pub struct Player {
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct Pos {
pub x: i16,
pub y: i16,
pub x: u16,
pub y: u16,
}
impl GOL {
@ -39,8 +39,10 @@ impl GOL {
let fbm = Fbm::new();
let map_size_x = 100;
let map_size_y = 100;
let map = PlaneMapBuilder::new(&fbm)
.set_size(100, 100)
.set_size(map_size_x, map_size_y)
.set_x_bounds(-5.0, 5.0)
.set_y_bounds(-5.0, 5.0)
.build();
@ -99,42 +101,48 @@ fn main() {
draw(&mut gol);
for c in stdin.keys() {
update(&gol);
draw(&mut gol);
let key = c.unwrap();
match key {
Key::Left => gol.player.pos.x -= 1,
Key::Right => gol.player.pos.x += 1,
Key::Up => gol.player.pos.y += 1,
Key::Down => gol.player.pos.y -= 1,
Key::Char('q') => break,
_ => {}
};
if let Err(_) = update(&mut gol, &key) {
break;
}
draw(&mut gol);
gol.flush();
}
gol.write(&termion::cursor::Show);
}
fn update(game: &GOL) {}
fn update(game: &mut GOL, key: &Key) -> Result<(), ()> {
match key {
Key::Left => game.player.pos.x -= 1,
Key::Right => game.player.pos.x += 1,
Key::Up => game.player.pos.y -= 1,
Key::Down => game.player.pos.y += 1,
Key::Char('q') => return Err(()),
_ => {}
};
Ok(())
}
fn draw(game: &mut GOL) {
game.write(&clear::All);
let size = termion::terminal_size().unwrap();
let x = size.0 / 2;
let y = size.1 / 2;
log(x);
log(y);
game.write(&cursor::Goto(size.0 / 2, size.1 / 2));
let center_x = size.0 / 2;
let center_y = size.1 / 2;
game.write(&cursor::Goto(center_x, center_y));
game.write(&'X');
game.flush();
for col in 1..size.0 {
for row in 1..size.1 {
if game.map.get_value(col.into(), row.into()) > 0.0 {
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(&'#');
}
}
}
game.flush();
}

Loading…
Cancel
Save