1个不稳定版本
0.1.0 | 2022年12月29日 |
---|
#1169 in 游戏开发
98KB
2K SLoC
像素引擎游戏内控制台扩展
这个crate是pixel_engine的扩展。它提供了一个游戏内控制台,可以接收命令(字符串形式)。它还提供了一个简单的方法通过日志API将消息打印到控制台(crate中也包含宏)
此扩展旨在与未来的扩展完全兼容
extern crate pixel_engine;
extern crate pixel_engine_console;
struct Game;
impl pixel_engine::Game for Game {
fn create(engine: &mut Engine) -> Result<Self, Box<dyn std::error::Error>> {
Ok(Self)
}
fn update(&mut self, engine: &mut Engine) -> Result<bool, Box<dyn std::error::Error>> {
// Opens the console
engine.open_console(
Keycodes::Escape, // The key used to close the console
false, // Does the update function will be called when the console is opened
);
cinfo!("Hello console !"); // Print a info message into the console
}
}
impl ConsoleGame for Game {
fn receive_console_input(&mut self, engine: &mut Engine, input: String) {
// process the input
// for example the shlex crate allow you to split the input into arguments like a shell
}
}
fn main() {
pixel_engine::start::<Game>("Console Example", (500, 500), 2);
}
依赖项
~23–36MB
~400K SLoC