1use std::path::Path;
2
3use fennel_engine::{EventHandler, Game, events, graphics};
4use sdl3::pixels::Color;
5use tokio::runtime::Handle;
6
7struct State {}
8
9#[async_trait::async_trait]
10impl EventHandler for State {
11 async fn update(&self, _game: &mut Game) -> anyhow::Result<()> {
12 Ok(())
13 }
14
15 async fn draw(&self, game: &mut Game) -> anyhow::Result<()> {
16 game.graphics.canvas.set_draw_color(Color::RGB(0, 0, 0));
17 game.graphics.canvas.clear();
18 game.graphics
19 .draw_image(
20 "examples/example.png".to_string(),
21 (0.0, 0.0),
22 )
23 .expect("failed to draw an image");
24 game.graphics.canvas.present();
25 Ok(())
26 }
27
28 fn key_down_event(
29 &self,
30 game: &mut Game,
31 _timestamp: u64,
32 _window_id: u32,
33 keycode: Option<sdl3::keyboard::Keycode>,
34 _scancode: Option<sdl3::keyboard::Scancode>,
35 _keymod: sdl3::keyboard::Mod,
36 _repeat: bool,
37 _which: u32,
38 _raw: u16,
39 ) -> anyhow::Result<()> {
40 println!("{:?}", keycode);
41 tokio::task::block_in_place(move || {
42 Handle::current().block_on(async move {
43 game.audio
44 .play_audio(
45 Path::new("examples/music.ogg"),
46 false,
47 )
48 .await
49 .unwrap();
50 })
51 });
52 Ok(())
53 }
54}
55
56#[tokio::main]
57async fn main() {
58 let graphics = graphics::Graphics::new(String::from("my cool game"), (500, 500));
59 let mut game = fennel_engine::Game::new(
60 String::from("my cool game"),
61 String::from("wiltshire"),
62 graphics.unwrap(),
63 );
64 events::run(&mut game, Box::new(State {})).await;
65}