]> localhost Git - miss-le-hell.git/commitdiff
Final update to Miss(le) Hell before v0.1.1
authortf2spi <[email protected]>
Mon, 13 Oct 2025 19:39:32 +0000 (15:39 -0400)
committerMisomosi <[email protected]>
Mon, 13 Oct 2025 22:27:10 +0000 (18:27 -0400)
We introduce handle tables, arenas, and fonts
into the engine and use/test them for the game.
Bleh... What a mess.

game/game_callbacks.c
game/sprite.c

index a78d0eadfcc1c007ccd54d22b09293a576d33d16..7a20a79f23301f812590bf4fd7c5cff442d6f134 100644 (file)
@@ -4,6 +4,7 @@
 #include "afx.h"
 #include "input.h"
 #include "sprite.h"
+#include <stdio.h>
 
 // Exported for sprite.c
 union gfx_sampler g_sampler;
@@ -23,7 +24,9 @@ static union gfx_font g_font;
 
 static float timeprev;
 static float timedelta;
+static int bullets_exploded = 0;
 static float reset_tick = 0.0f;
+static float death_tick = 0.0f;
 
 #define FLAG_LEFT 1
 #define FLAG_RIGHT 2
@@ -209,8 +212,10 @@ static void update_projectiles(struct projectiles *projectiles)
                                                        continue;
                                                struct vector2f32 delta = v2f32sub(enemy->pos, p->pos);
                                                // TODO: Yes, I also know this isn't exact. I'll fix that... Maybe.
-                                               if (v2f32mag2(delta) < (EXPLOSION_RADIUS * EXPLOSION_RADIUS))
+                                               if (v2f32mag2(delta) < (EXPLOSION_RADIUS * EXPLOSION_RADIUS)) {
+                                                       bullets_exploded++;
                                                        remove_projectile(&g_enemy, i);
+                                               }
                                        }
                                }
                                break;
@@ -223,6 +228,7 @@ static void update_projectiles(struct projectiles *projectiles)
                                } else if (g_ship.destroyed <= EPSILON) {
                                        struct vector2f32 delta = v2f32sub(p->pellet.pos, g_ship.pos);
                                        if (v2f32mag2(delta) < SHIP_RADIUS * SHIP_RADIUS) {
+                                               death_tick = timeprev;
                                                g_ship.destroyed = EPSILON * 2.0f;
                                                add_explosion(&g_friendly, p->pellet.pos);
                                                remove_projectile(projectiles, i);
@@ -348,6 +354,8 @@ static void reset_game()
        g_flags = 0;
        g_pellet_spawn_time = PELLET_SPAWN_BASE;
        reset_tick = os_timef(OS_TIME_TICK);
+       death_tick = 0.0f;
+       bullets_exploded = 0;
 }
 static void on_key(uint32_t keyboard, uint32_t key, bool down)
 {
@@ -537,6 +545,9 @@ void game_callback_render(void)
 
        // Now bind the pipeline for fonts and render
        gfx_pipeline_bind(g_font_pipeline);
-       text_draw(g_font, STRLIT("Hello World!\nHow are you?"), (struct vector2f32){64.0f,64.0f});
+       char prompt[128];
+       float time_alive = (death_tick ? death_tick : timeprev) - reset_tick;
+       snprintf(prompt, sizeof(prompt), "Seconds Alive: %d\nBullets Exploded: %d\n", (int)time_alive, bullets_exploded);
+       text_draw(g_font, CSTR2STRC(prompt), (struct vector2f32){4.0f-CAM_DIM_X/2,-4.0f+CAM_DIM_Y/2});
        sprite_flush();
 }
index 0721b49820174302538ace379dcd206a35f1cf21..6e7b5123beccea47cfabe3a2717e8fded0f031af 100644 (file)
@@ -96,6 +96,7 @@ void text_draw(union gfx_font f, struct stringc text, struct vector2f32 loc)
        float pxscale = info.fontsize / (info.ascent - info.descent);
        float line_height = pxscale * (info.ascent - info.descent + info.linegap);
        float xbase = loc.x;
+       loc.y -= line_height;
        for (size_t i = 0; i < text.len; i++) {
                if (text.data[i] == '\n') {
                        loc.y -= line_height;