6个版本 (破坏性)
0.6.0 | 2023年7月3日 |
---|---|
0.5.0 | 2020年6月5日 |
0.4.0 | 2020年5月23日 |
0.3.0 | 2020年5月21日 |
0.1.0 | 2020年5月19日 |
#408 in 图像
55KB
1K SLoC
olcPixelGameEngine-rs
库为olcPixelGameEngine提供Rust API。我尽量使方法和常量与原始C++代码相似,以便API感觉熟悉,并易于遵循教程视频。
代码在Linux、Windows和macOS/OSX(任何10.x版本,包括旧版本,仅需X11)上构建,并使用我mac版本的像素游戏引擎https://github.com/sadikovi/olcPixelGameEngine-macos。macOS用户可能需要安装XQuartz以支持OpenGL。
您可以将crate作为依赖项链接,并扩展Application
特质以运行像素游戏引擎
extern crate olc_pixel_game_engine;
use crate::olc_pixel_game_engine as olc;
// Very simple example application that prints "Hello, World!" on screen.
struct ExampleProgram {}
impl olc::Application for ExampleProgram {
fn on_user_create(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserCreate`. Your code goes here.
Ok(())
}
fn on_user_update(&mut self, _elapsed_time: f32) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserUpdate`. Your code goes here.
// Clears screen and sets black colour.
olc::clear(olc::BLACK);
// Prints the string starting at the position (40, 40) and using white colour.
olc::draw_string(40, 40, "Hello, World!", olc::WHITE)?;
Ok(())
}
fn on_user_destroy(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserDestroy`. Your code goes here.
Ok(())
}
}
fn main() {
let mut example = ExampleProgram {};
// Launches the program in 200x100 "pixels" screen, where each "pixel" is 4x4 pixel square,
// and starts the main game loop.
olc::start("Hello, World!", &mut example, 200, 100, 4, 4).unwrap();
}
我建议查看文档以了解可用的API。
示例
您可以通过查看examples/目录中的示例来了解可用的API,务必也要查看文档。
我将在该目录中添加更多示例。其中一些是olcPixelGameEngine
示例和视频的直接移植。在探索像素游戏引擎时,请随时添加更多示例!
运行示例
例如,使用cargo run --example isometric_tiles
运行等距瓦片演示。
构建
运行cargo build
来构建项目。
测试
运行 cargo test
以执行项目的测试。
文档
运行 cargo doc --open
在本地构建和查看文档。
无运行时依赖
~180KB