70 lines
1.7 KiB
Rust
70 lines
1.7 KiB
Rust
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);
|
|
});
|
|
}
|
|
}
|