6个版本 (1个稳定版)
| 1.0.0 | 2021年4月30日 | 
|---|---|
| 0.2.2 | 2020年1月26日 | 
| 0.1.1 | 2020年1月25日 | 
在游戏开发中排名1722
26KB
401 行
rain2d
用法
查看示例
鸣谢
lib.rs:
简单的2D框架/引擎
提供了一些绘制基本形状的工具,可能在某个时刻变成一个真正的游戏引擎
示例
use std::time::Duration;
use rain2d::core::*;
const WIDTH: usize = 640;
const HEIGHT: usize = 360;
// can be used to store application state
struct ExampleApp;
impl RainApp for ExampleApp {
    fn on_update(&mut self, rain: &mut RainCore, dt: Duration) {
        // drawing
        rain.fill_triangle(120, 300, 520, 300, 320, 100, WHITE);
        // keyboard input
        // gets all keys that are currently down
        if let Some(keys) = rain.get_keys() {
            for key in keys {
                match key {
                    Key::Space => println!("Spacebar down"),
                    Key::A => println!("A down"),
                    _ => (),
                }
            }
        }
        // only true on keypress, doesn't repeat
        if rain.key_pressed(Key::Key1) {
            println!("1 pressed");
        }
        // mouse input
        if rain.mouse_button_down(MouseButton::Left) {
            if let Some((x, y)) = rain.get_mouse_pos() {
                println!("Mouse x: {}, Mouse y: {}", x, y);
            }
        }
    }
}
let mut core = RainCore::init("example app",
    WIDTH,
    HEIGHT,
    true);
core.run(&mut ExampleApp {});
依赖项
~0.4–1MB
~15K SLoC