Skip to content

Instantly share code, notes, and snippets.

@paezao

paezao/main.rs Secret

Created May 17, 2016 16:21
Show Gist options
  • Save paezao/0babb33796b588dbd3d812bde6b3e5ec to your computer and use it in GitHub Desktop.
Save paezao/0babb33796b588dbd3d812bde6b3e5ec to your computer and use it in GitHub Desktop.
extern crate tcod;
use tcod::console::*;
use tcod::colors;
const SCREEN_WIDTH: i32 = 80;
const SCREEN_HEIGHT: i32 = 50;
const LIMIT_FPS: i32 = 20;
fn handle_keys(root: &mut Root, player_x: &mut i32, player_y: &mut i32) -> bool {
use tcod::input::Key;
use tcod::input::KeyCode::*;
let key = root.wait_for_keypress(true);
match key {
Key { code: Up, .. } => *player_y -= 1,
Key { code: Down, .. } => *player_y += 1,
Key { code: Left, .. } => *player_x -= 1,
Key { code: Right, .. } => *player_x += 1,
Key { code: Escape, .. } => return true,
_ => {},
};
false
}
fn main() {
let mut root = Root::initializer()
.font("arial10x10.png", FontLayout::Tcod)
.font_type(FontType::Greyscale)
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
.title("Roguerust")
.init();
tcod::system::set_fps(LIMIT_FPS);
let mut player_x = SCREEN_WIDTH / 2;
let mut player_y = SCREEN_HEIGHT / 2;
while !root.window_closed() {
root.clear();
root.set_default_foreground(colors::WHITE);
root.put_char(player_x, player_y, '@', BackgroundFlag::None);
root.flush();
if handle_keys(&mut root, &mut player_x, &mut player_y) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment