Initial commit
This commit is contained in:
commit
5b7a331c7f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
||||
55
Cargo.lock
generated
Normal file
55
Cargo.lock
generated
Normal file
@ -0,0 +1,55 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a6577517ecd0ee0934f48a7295a89aaef3e6dfafeac404f94c0b3448518ddfe"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||
|
||||
[[package]]
|
||||
name = "roguelike"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tcod",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tcod"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44e518b0661949712e8dbc6d6d9d7c00a405dd88bc539102c1edfc2d22e5e144"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"lazy_static",
|
||||
"tcod-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tcod-sys"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "730fb27d2261f7c860ae7a61c3ae70277f0836173ceeccb594193abb4fa5f4aa"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "roguelike"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tcod = "*"
|
||||
BIN
arial10x10.png
Normal file
BIN
arial10x10.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
68
src/main.rs
Normal file
68
src/main.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use tcod::colors::*;
|
||||
use tcod::console::*;
|
||||
|
||||
const SCREEN_WIDTH: i32 = 80;
|
||||
const SCREEN_HEIGHT: i32 = 50;
|
||||
|
||||
const FPS: i32 = 20;
|
||||
|
||||
struct Tcod {
|
||||
root: Root,
|
||||
}
|
||||
|
||||
fn handle_keys(tcod: &mut Tcod, player_x: &mut i32, player_y: &mut i32) -> bool {
|
||||
use tcod::input::Key;
|
||||
use tcod::input::KeyCode::*;
|
||||
|
||||
// todo: handle keys
|
||||
let key = tcod.root.wait_for_keypress(true);
|
||||
match key {
|
||||
Key {
|
||||
code: Enter,
|
||||
alt: true,
|
||||
..
|
||||
} => {
|
||||
// Alt+Enter: toggle fullscreen
|
||||
let fullscreen = tcod.root.is_fullscreen();
|
||||
tcod.root.set_fullscreen(!fullscreen);
|
||||
}
|
||||
Key { code: Escape, .. } => return true, // exit game
|
||||
|
||||
Key { code: Up, .. } => *player_y -= 1,
|
||||
Key { code: Down, .. } => *player_y += 1,
|
||||
Key { code: Left, .. } => *player_x -= 1,
|
||||
Key { code: Right, .. } => *player_x += 1,
|
||||
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tcod::system::set_fps(FPS);
|
||||
|
||||
let root = Root::initializer()
|
||||
.font("arial10x10.png", FontLayout::Tcod)
|
||||
.font_type(FontType::Greyscale)
|
||||
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
|
||||
.title("Rust/libtcod tutorial")
|
||||
.init();
|
||||
|
||||
let mut tcod = Tcod { root };
|
||||
|
||||
let mut player_x = SCREEN_WIDTH / 2;
|
||||
let mut player_y = SCREEN_HEIGHT / 2;
|
||||
|
||||
while !tcod.root.window_closed() {
|
||||
tcod.root.set_default_foreground(WHITE);
|
||||
tcod.root.clear();
|
||||
tcod.root
|
||||
.put_char(player_x, player_y, '@', BackgroundFlag::None);
|
||||
tcod.root.flush();
|
||||
tcod.root.wait_for_keypress(true);
|
||||
let exit = handle_keys(&mut tcod, &mut player_x, &mut player_y);
|
||||
if exit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user