1个不稳定版本
0.1.0 | 2023年7月21日 |
---|
#383 在 图形API
96KB
2.5K SLoC
Rustic Mountain Core
这是一个用于模拟2015年游戏竞赛发布的Celeste Classic游戏物理和图形的Rust库
安装
cargo add rustic-mountain-core
基本用法(例如,创建端口)
fn main(){
// consts are not included in the core library. see examples here: https://github.com/CoolElectronics/rustic-mountain/blob/main/standalone/src/consts.rs
let mut engine = Celeste::new(
consts::MAPDATA.into(),
consts::SPRITES.into(),
consts::FLAGS.into(),
consts::FONTATLAS.into(),
);
let pallete: [(u8, u8, u8); 16] = [
(0, 0, 0),
(29, 43, 83),
(126, 37, 83),
(0, 135, 81),
(171, 82, 54),
(95, 87, 79),
(194, 195, 199),
(255, 241, 232),
(255, 0, 77),
(255, 163, 0),
(255, 236, 85),
(0, 228, 54),
(41, 173, 255),
(131, 118, 156),
(255, 119, 168),
(255, 204, 170),
];
loop {
// advance the game logic
engine.next_tick();
// render the screen
engine.draw();
// screen buffer is a 128x128 array
for (i, col) in engine.mem.graphics.iter().enumerate() {
// look up rgb color from pallete
let color = pallete[*col as usize];
let xpixel = i % 128;
let ypixel = i / 128;
// do rendering to screen here
}
engine.mem.buttons[0] = is_left_arrow_pressed;
engine.mem.buttons[1] = is_right_arrow_pressed;
engine.mem.buttons[2] = is_up_arrow_pressed;
engine.mem.buttons[3] = is_down_arrow_pressed;
engine.mem.buttons[4] = is_jump_pressed;
engine.mem.buttons[5] = is_dash_key_pressed;
// constrain to 30fps
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 30));
}
}
高级用法
大多数方法和字段都标记为公开,因此游戏可以被轻松修改和扩展。例如,您可以通过遍历celeste.objects
向量来找到玩家位置,创建自己的地图等。我并没有编写文档,只是阅读代码,主要部分只有1k多行
依赖项
~1–2MB
~43K SLoC