hello/
hello.rs

1use fennel_engine::{EventHandler, Game, events, graphics};
2use sdl3::pixels::Color;
3
4struct State {}
5
6impl EventHandler for State {
7    fn update(&self, _game: &mut Game) -> anyhow::Result<()> {
8        Ok(())
9    }
10
11    fn draw(&self, game: &mut Game) -> anyhow::Result<()> {
12        game.graphics.canvas.set_draw_color(Color::RGB(0, 0, 0));
13        game.graphics.canvas.clear();
14        game.graphics
15            .draw_image("./examples/example.png".to_string(), (0.0, 0.0))
16            .expect("failed to draw an image");
17        game.graphics.canvas.present();
18        Ok(())
19    }
20
21    fn key_down_event(
22            &self,
23            _game: &mut Game,
24            _timestamp: u64,
25            _window_id: u32,
26            keycode: Option<sdl3::keyboard::Keycode>,
27            _scancode: Option<sdl3::keyboard::Scancode>,
28            _keymod: sdl3::keyboard::Mod,
29            _repeat: bool,
30            _which: u32,
31            _raw: u16,
32        ) -> anyhow::Result<()> {
33        println!("{:?}", keycode);
34        Ok(())
35    }
36}
37
38fn main() {
39    let graphics = graphics::Graphics::new(String::from("my cool game"), (500, 500));
40    let mut game = fennel_engine::Game::new(
41        String::from("my cool game"),
42        String::from("wiltshire"),
43        graphics.unwrap(),
44    );
45    events::run(&mut game, Box::new(State {}));
46}