diff --git a/examples/template_minimal/Cargo.toml b/examples/template_minimal/Cargo.toml new file mode 100644 index 0000000..1935b4e --- /dev/null +++ b/examples/template_minimal/Cargo.toml @@ -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" ] } + diff --git a/examples/template_minimal/README.md b/examples/template_minimal/README.md new file mode 100644 index 0000000..f8be64b --- /dev/null +++ b/examples/template_minimal/README.md @@ -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. diff --git a/examples/template_minimal/src/main.rs b/examples/template_minimal/src/main.rs new file mode 100644 index 0000000..9a77462 --- /dev/null +++ b/examples/template_minimal/src/main.rs @@ -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(()) +}