test/snake/snake.c

changeset 88
6234b7ea48f3
parent 86
943bf9d7c6d6
child 89
e1f682a8a145
--- a/test/snake/snake.c	Sat Apr 19 19:30:46 2025 +0200
+++ b/test/snake/snake.c	Sun Apr 20 15:41:16 2025 +0200
@@ -75,6 +75,33 @@
     asc_add_ui_node(node);
 }
 
+static void free_spaceship(AscSceneNode *node) {
+    asc_texture_destroy(&((AscSprite*)node)->tex);
+    free(node);
+}
+
+static void create_spaceship(void) {
+    // TODO: textures should be passed by pointers (and probably ref-counted)
+    AscTexture texture;
+    asc_texture_init_2d(&texture);
+    asc_texture_from_file(&texture, "ship.png");
+    AscSceneNode *sprite = asc_sprite(
+        .texture = texture,
+        .x = 250,
+        .y = 300,
+        .width = 64,
+        .height = 64
+    );
+
+    // TODO: add to 2D scene instead of UI scene, once we have one
+    asc_add_ui_node(sprite);
+
+    // TODO: remove this hack by refactoring how textures work
+    sprite->free_func = free_spaceship;
+
+    // TODO: return something
+}
+
 int main(int argc, char** argv) {
     asc_context_initialize();
     if (asc_has_error()) {
@@ -100,6 +127,9 @@
     create_fps_counter();
     create_score_counter();
 
+    // create spaceship
+    create_spaceship();
+
     // Main Loop
     do {
         // quit application on any error

mercurial