From 3106b01f3fdb1e6489bb3c5f16e5c5c6b58b9618 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 1 Oct 2017 22:13:34 +0200 Subject: [PATCH] Display simple window --- .gitignore | 2 ++ Cargo.toml | 7 ++++++ src/main.rs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eccd7b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target/ +**/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e260549 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "rustenstein" +version = "0.1.0" +authors = ["Fabien Freling "] + +[dependencies] +piston_window = "0.70.0" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5dca0c4 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,69 @@ +extern crate piston_window; + +use piston_window::*; + +enum Tile { + Empty, + Wall, +} + +struct Position { + x: f64, + y: f64, +} + +struct Player { + pos: Position, + angle: f64, +} + + +fn main() { + let mut window: PistonWindow = + WindowSettings::new("Rustenstein", [640, 480]) + .exit_on_esc(true) + .resizable(false) + .build().unwrap(); + + let level: [Tile; 5 * 5] = [ + Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall, + Tile::Wall, Tile::Empty, Tile::Empty, Tile::Empty, Tile::Wall, + Tile::Wall, Tile::Empty, Tile::Empty, Tile::Empty, Tile::Wall, + Tile::Wall, Tile::Empty, Tile::Empty, Tile::Empty, Tile::Wall, + Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall, Tile::Wall, + ]; + + let mut player: Player; + player.pos.x = 2.0; + player.pos.y = 2.0; + player.angle = 0.0; + + while let Some(event) = window.next() { + let window_size = window.size(); + let w = window_size.width as f64; + let h = window_size.height as f64; + + window.draw_2d(&event, |context, graphics| { + clear([1.0; 4], graphics); + + rectangle([1.0, 0.0, 0.0, 1.0], // red + [0.0, 0.0, 100.0, 100.0], + context.transform, + graphics); + + // Ceiling + let ceiling_color = [0.3, 0.3, 0.3, 1.0]; + rectangle(ceiling_color, + [0.0, 0.0, w, h / 2.0], + context.transform, + graphics); + + // Floor + let floor_color = [0.5, 0.5, 0.5, 1.0]; + rectangle(floor_color, + [0.0, h / 2.0, w, h / 2.0], + context.transform, + graphics); + }); + } +}