2个版本
0.0.2 | 2022年2月21日 |
---|---|
0.0.1 | 2022年2月13日 |
#854 in 游戏开发
210KB
1.5K SLoC
Apparatus游戏引擎
Apparatus是一款游戏引擎,其灵感来源于多个来源,包括Dragonfly、olcPixelGameEngine和Arcade等。
入门
实现Game
特质,并告诉Apparatus
运行你的结构体
use anyhow::Result;
use log::info;
use apparatus::color::Color;
use apparatus::engine::apparatus::{Apparatus, ApparatusSettings};
use apparatus::engine::game::Game;
use apparatus::engine::key::Key;
use apparatus::errors::ApparatusError;
use apparatus::maths::clamp;
struct Example {
color: Color,
}
impl Game for Example {
fn on_create(app: &Apparatus) -> Result<Self, ApparatusError> {
let r = app.screen_width() % 255;
let g = app.screen_height() % 255;
let b = (app.screen_width() * app.screen_height()) % 255;
let color = Color::rgba(r as u8, g as u8, b as u8, 255);
let game = Example { color };
Ok(game)
}
fn on_update(&mut self, app: &mut Apparatus) {
info!("updating");
let dt = app.elapsed_time();
if app.is_key_held(Key::Up) {
let r = clamp(
0.0,
self.color.r() as f32 + (100.0 * dt.as_secs_f32()),
255.0,
) as u8;
let g = clamp(
0.0,
self.color.g() as f32 + (100.0 * dt.as_secs_f32()),
255.0,
) as u8;
let b = clamp(
0.0,
self.color.b() as f32 + (100.0 * dt.as_secs_f32()),
255.0,
) as u8;
self.color = Color::rgba(r, g, b, 255);
}
if app.is_key_held(Key::Down) {
let r = clamp(
0.0,
self.color.r() as f32 - (50.0 * dt.as_secs_f32()),
255.0,
) as u8;
let g = clamp(
0.0,
self.color.g() as f32 - (50.0 * dt.as_secs_f32()),
255.0,
) as u8;
let b = clamp(
0.0,
self.color.b() as f32 - (50.0 * dt.as_secs_f32()),
255.0,
) as u8;
self.color = Color::rgba(r, g, b, 255);
}
info!("rendering");
app.clear(self.color);
}
}
fn main() -> Result<()> {
let engine = Apparatus::new("Getting Started", ApparatusSettings::default())?;
engine.run::<Example>()?;
Ok(())
}
查看示例以获取更深入的用法。
示例
开发
运行测试
使用cargo从命令行运行测试
cargo test
版本控制
Apparatus处于非常早期的开发阶段,目前不遵循semver。它也没有承诺支持最低的Rust版本。
依赖项
~15–22MB
~165K SLoC