rust-raylib-playground/rect.rs

36 lines
960 B
Rust
Raw Normal View History

mod raylib;
pub struct Vector2<S> {
pub x: S,
pub y: S,
}
fn main() {
let screen = Vector2::<u32> { x: 800, y: 600 };
let mut pos = Vector2::<u32> {
x: screen.x / 2,
y: screen.y / 2
};
raylib::init_window(screen.x, screen.y, "Hello, raylib");
raylib::set_target_fps(60);
while !raylib::window_should_close() {
raylib::begin_drawing();
raylib::clear_background(raylib::colors::BLACK);
if raylib::is_key_down(raylib::Key::W) {
pos.y -= 10;
} else if raylib::is_key_down(raylib::Key::S) {
pos.y += 10;
} else if raylib::is_key_down(raylib::Key::A) {
pos.x -= 10;
} else if raylib::is_key_down(raylib::Key::D) {
pos.x += 10;
}
raylib::draw_rect(pos.x, pos.y, 100, 100, raylib::colors::RED);
raylib::end_drawing();
}
}