summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-10-26 11:04:14 -0400
committerMica White <botahamec@outlook.com>2026-10-26 11:04:14 -0400
commit2987e310e8e6eaeaa60546bb92a61d9c3713263a (patch)
tree530ff5abe1b584bc1a6da5babd328d71d1e1173c /src/main.rs
Snake exampleHEADmain
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..3b6605a
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,51 @@
+#![cfg_attr(target_arch = "wasm32", no_std)]
+#![cfg_attr(target_arch = "wasm32", no_main)]
+
+extern crate alloc;
+
+mod exit_on_escape;
+mod move_snake;
+mod render;
+mod snake_controller;
+
+use alloc::vec::Vec;
+use core::time::Duration;
+use tortuise_script::{entity::Entity, time::Instant, TortuiseScene};
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+struct Position {
+ pub x: i16,
+ pub y: i16,
+}
+
+const GRID_SIZE: u16 = 16;
+
+static APPLE_LOCATION: Entity<Position> =
+ Entity::new("apple_location", |_| Position { x: 2, y: 2 });
+static SNAKE_CELLS: Entity<Vec<Position>> = Entity::new("snake_cells", |_| {
+ alloc::vec![Position { x: 10, y: 5 }, Position { x: 9, y: 5 }]
+});
+static DIRECTION: Entity<Position> = Entity::new("direction", |_| Position { x: 1, y: 0 });
+static NEXT_MOVE_TIME: Entity<Instant> = Entity::new("next_move_time", |cx| {
+ Instant::now(cx) + Duration::from_millis(200)
+});
+
+tortuise_script::game! {
+ name: "snake",
+ author: "botahamec",
+ tld: "dev",
+ first_scene: "main",
+ scenes: {
+ "main" => TortuiseScene {
+ scripts: &["snake_controller", "exit_on_escape", "move_snake", "render"],
+ }
+ },
+ scripts: {
+ "snake_controller" => snake_controller::SNAKE_CONTROLLER,
+ "exit_on_escape" => exit_on_escape::EXIT_ON_ESCAPE,
+ "move_snake" => move_snake::MOVE_SNAKE,
+ "render" => render::RENDER
+ }
+}