Display simple window
This commit is contained in:
commit
3106b01f3f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target/
|
||||||
|
**/*.rs.bk
|
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "rustenstein"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Fabien Freling <public@ffreling.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
piston_window = "0.70.0"
|
69
src/main.rs
Normal file
69
src/main.rs
Normal file
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue