add template_minimal example

This commit is contained in:
Gered 2022-05-26 18:43:22 -04:00
parent 246367b50b
commit 0afc7e822a
3 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,10 @@
[package]
name = "template_minimal"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.55"
libretrogd = { path = "../../libretrogd" }
sdl2 = { version = "0.34.5", features = ["static-link", "bundled", "unsafe_textures" ] }

View file

@ -0,0 +1,5 @@
# libretrogd - Minimal Template/Example
A very minimal usage example that can also serve as a new project template to get started using libretrogd.
Run `cargo run` from this directory to try it out.

View file

@ -0,0 +1,38 @@
use anyhow::Result;
use sdl2::keyboard::Scancode;
use libretrogd::{SCREEN_BOTTOM, SCREEN_RIGHT};
use libretrogd::graphics::*;
use libretrogd::system::*;
use libretrogd::utils::rnd_value;
fn main() -> Result<()> {
let mut system = SystemBuilder::new().window_title("Minimal Template").vsync(true).build()?;
let mut is_running = true;
let font = BitmaskFont::new_vga_font()?;
system.video.clear(0);
system.video.print_string("Hello, world!", 20, 20, 15, &font);
while is_running {
system.do_events_with(|event| {
if let sdl2::event::Event::Quit { .. } = event {
is_running = false;
}
});
if system.keyboard.is_key_pressed(Scancode::Escape) {
is_running = false;
}
let x = rnd_value(0, SCREEN_RIGHT) as i32;
let y = rnd_value(0, SCREEN_BOTTOM) as i32;
let color = rnd_value(0, 255);
system.video.set_pixel(x, y, color);
system.display()?;
}
Ok(())
}