From 8cbe1b04318c8daf89f0ac4f3e35de40e07c8501 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 18 Oct 2025 17:43:22 +0100 Subject: [PATCH] Add huge asteroids --- game.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/game.c b/game.c index 0045d70..df4f322 100644 --- a/game.c +++ b/game.c @@ -9,6 +9,7 @@ #include #include #include +#include #define SHIP_COLLIDE_R 0.05 #define SHIP_MASS 0.5 @@ -22,11 +23,12 @@ #define ASTEROID_A_JITTER 0.8 #define ASTEROID_VEL_JITTER 0.001 #define ASTEROID_OMG_JITTER 0.005 -#define INIT_ASTEROIDS 8 +#define INIT_ASTEROIDS 1 -#define ASTEROID_SMALL 0.05 -#define ASTEROID_MEDIUM 0.1 -#define ASTEROID_LARGE 0.2 +#define ASTEROID_SMALL 0.05f +#define ASTEROID_MEDIUM 0.1f +#define ASTEROID_LARGE 0.2f +#define ASTEROID_HUGE 0.4f #define ASTEROID_R_JITTER 0.02 #define ASTEROID_MIN_DIST 0.8 @@ -222,12 +224,14 @@ static void spawn_asteroid() { float r; const float rnd = rng_canon(); - if (rnd < 0.2) + if (rnd < 0.1) r = ASTEROID_SMALL; - else if (rnd < 0.6) + else if (rnd < 0.5) r = ASTEROID_MEDIUM; - else + else if (rnd < 0.9) r = ASTEROID_LARGE; + else + r = ASTEROID_HUGE; unsigned id; entity_t *e = gen_asteroid(r, &id); @@ -344,9 +348,11 @@ static void destroy_asteroid(entity_t *a, vec2_t shot_vel) --asteroid_count; float r; - if (fabs(a->radius - ASTEROID_LARGE) < 1e-3) + if (a->radius == ASTEROID_HUGE) + r = ASTEROID_LARGE; + else if (a->radius == ASTEROID_LARGE) r = ASTEROID_MEDIUM; - else if (fabs(a->radius - ASTEROID_MEDIUM) < 1e-3) + else if (a->radius == ASTEROID_MEDIUM) r = ASTEROID_SMALL; else return; @@ -379,6 +385,8 @@ static void destroy_asteroid(entity_t *a, vec2_t shot_vel) ++asteroid_count; } + + printf("asteroid count: %u\n", asteroid_count); } static void handle_collisions(const collision_t *collisions, unsigned count) @@ -426,6 +434,7 @@ void game_init(float _aspect) dead = false; counter = 0; entity_count = shape_count = 0; + asteroid_count = 0; entity_t *ship = add_entity(&ship_entity_id); ship->radius = SHIP_COLLIDE_R;