summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-04-28 13:39:34 -0400
committerLLLL Colonq <llll@colonq>2026-04-28 13:39:34 -0400
commitea5929c74a4e01bcbc776832b5597fceb5261a31 (patch)
tree12c94e3eb8a97665212a8bbac4f090638c53f6ce /src/game.rs
Initial commitHEADmaster
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/game.rs b/src/game.rs
new file mode 100644
index 0000000..1abe66e
--- /dev/null
+++ b/src/game.rs
@@ -0,0 +1,65 @@
+#![allow(dead_code, unused_variables)]
+use std::collections::HashMap;
+use teleia::*;
+
+struct Assets {
+ font: font::Bitmap,
+ shader_flat: shader::Shader,
+ mesh_square: mesh::Mesh,
+ texture_test: texture::Texture,
+}
+
+impl Assets {
+ fn new(ctx: &context::Context) -> Self {
+ Self {
+ font: font::Bitmap::default(ctx),
+ shader_flat: shader::Shader::new(
+ ctx,
+ include_str!("assets/shaders/flat/vert.glsl"),
+ include_str!("assets/shaders/flat/frag.glsl"),
+ ),
+ mesh_square: mesh::Mesh::from_obj(ctx, include_bytes!("assets/meshes/square.obj")),
+ texture_test: texture::Texture::new(ctx, include_bytes!("assets/textures/test.png")),
+ }
+ }
+}
+
+pub struct Game {
+ assets: Assets,
+}
+
+impl Game {
+ pub fn new(ctx: &context::Context) -> Self {
+ Self {
+ assets: Assets::new(ctx),
+ }
+ }
+}
+
+impl teleia::state::Game for Game {
+ fn initialize_audio(&self, ctx: &context::Context, st: &state::State, actx: &audio::Context) -> HashMap<String, audio::Audio> {
+ HashMap::from_iter(vec![
+ ("test".to_owned(), audio::Audio::new(&actx, include_bytes!("assets/audio/test.wav"))),
+ ])
+ }
+ fn update(&mut self, _ctx: &context::Context, _st: &mut state::State) -> Erm<()> {
+ Ok(())
+ }
+ fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Erm<()> {
+ ctx.clear();
+ self.assets.font.render_text(
+ ctx, st,
+ &glam::Vec2::new(0.0, 0.0),
+ "hello computer",
+ );
+ st.bind_2d(ctx, &self.assets.shader_flat);
+ self.assets.texture_test.bind(ctx);
+ self.assets.shader_flat.set_position_2d(
+ ctx, st,
+ &glam::Vec2::new(40.0, 40.0),
+ &glam::Vec2::new(16.0, 16.0),
+ );
+ self.assets.mesh_square.render(ctx);
+ Ok(())
+ }
+}