2024-02-16 21:06:00 +00:00
|
|
|
use std::ffi::{c_char,CString};
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Color(pub u8, pub u8, pub u8, pub u8);
|
|
|
|
|
|
|
|
#[link(name = "raylib")]
|
|
|
|
extern {
|
|
|
|
fn InitWindow(width: u32, height: u32, title: *const c_char);
|
2024-02-18 10:38:05 +00:00
|
|
|
fn ClearBackground(color: Color);
|
2024-02-16 21:06:00 +00:00
|
|
|
fn WindowShouldClose() -> bool;
|
2024-02-18 10:38:05 +00:00
|
|
|
fn SetTargetFPS(fps: u32);
|
2024-02-16 21:06:00 +00:00
|
|
|
fn BeginDrawing();
|
|
|
|
fn EndDrawing();
|
|
|
|
fn DrawRectangle(pos_x: u32, pos_y: u32, width: u32, height: u32, color: Color);
|
2024-02-18 10:38:05 +00:00
|
|
|
fn IsKeyDown(key: u32) -> bool;
|
2024-02-16 21:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub enum Key {
|
2024-02-18 10:38:05 +00:00
|
|
|
W = 87,
|
|
|
|
S = 83,
|
|
|
|
A = 65,
|
|
|
|
D = 68,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod colors {
|
|
|
|
use super::Color;
|
|
|
|
pub const RED: Color = Color(255, 0, 0, 255);
|
|
|
|
pub const BLACK: Color = Color(0, 0, 0, 0);
|
2024-02-16 21:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_window(width: u32, height: u32, title: &str) {
|
|
|
|
unsafe {
|
|
|
|
let title = CString::new(title).unwrap();
|
|
|
|
InitWindow(width, height, title.as_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-18 10:38:05 +00:00
|
|
|
pub fn clear_background(c: Color) {
|
|
|
|
unsafe { ClearBackground(c); }
|
|
|
|
}
|
|
|
|
|
2024-02-16 21:06:00 +00:00
|
|
|
pub fn window_should_close() -> bool {
|
|
|
|
unsafe { WindowShouldClose() }
|
|
|
|
}
|
|
|
|
|
2024-02-18 10:38:05 +00:00
|
|
|
pub fn set_target_fps(fps: u32) {
|
|
|
|
unsafe { SetTargetFPS(fps); }
|
|
|
|
}
|
|
|
|
|
2024-02-16 21:06:00 +00:00
|
|
|
pub fn begin_drawing() {
|
|
|
|
unsafe { BeginDrawing(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn end_drawing() {
|
|
|
|
unsafe { EndDrawing(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn draw_rect(pos_x: u32, pos_y: u32, width:u32, height: u32, color: Color) {
|
|
|
|
unsafe { DrawRectangle(pos_x, pos_y, width, height, color); }
|
|
|
|
}
|
|
|
|
|
2024-02-18 10:38:05 +00:00
|
|
|
pub fn is_key_down(key: Key) -> bool {
|
|
|
|
unsafe { IsKeyDown(key as u32) }
|
2024-02-16 21:06:00 +00:00
|
|
|
}
|
|
|
|
|