From: AynRandDuran Date: Mon, 5 Jul 2021 03:46:27 +0000 (-0400) Subject: decent enough asteroid explosions X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=acbcd8f0a6f8ed2feb3e920db810affc52062ccf;p=assteroids decent enough asteroid explosions --- diff --git a/assteroids.h b/assteroids.h index bae7b6a..22cf945 100644 --- a/assteroids.h +++ b/assteroids.h @@ -24,5 +24,9 @@ const int MAX_ASTEROIDS = 16; Vector4* dead_ship; const int SHIP_DEBRIS = 6; + +Vector4 dead_astr[MAX_ASTEROIDS][6]; +void explode_asteroid(Vector4* astr); +void update_explosions(); #endif //__ass diff --git a/game.cpp b/game.cpp index 3ea4657..3d8f693 100644 --- a/game.cpp +++ b/game.cpp @@ -13,6 +13,11 @@ Vector4 translate(Vector4 v1, Vector4 v2) { return translation; } +bool onscreen(Vector2 v) { + // Ensure v is still onscreen + return CheckCollisionPointRec(v, screenspace); +} + void init_ship(){ ship_alive = true; throttle = false; @@ -29,12 +34,16 @@ void init_ship(){ memset(bullets, 0, sizeof(Vector4) * MAX_BULLETS); memset(asteroids, 0, sizeof(Vector4) * MAX_ASTEROIDS); - + memset(dead_ship, 0, sizeof(Vector4) * SHIP_DEBRIS); + + memset(dead_astr, 0, sizeof(Vector4) * SHIP_DEBRIS * MAX_ASTEROIDS); } void die(){ ship_alive = false; for(int i = 0; i < SHIP_DEBRIS; i++) { + if (!onscreen(flatten(dead_ship[i]))) + continue; dead_ship[i].x = center.x; dead_ship[i].y = center.y; dead_ship[i].z = (360/SHIP_DEBRIS) * (i + 1); dead_ship[i].w = 8; @@ -55,11 +64,6 @@ void spin_ship(int az_delta){ } -bool onscreen(Vector2 v) { - // Ensure v is still onscreen - return CheckCollisionPointRec(v, screenspace); -} - void update_v4(Vector4* origin, Vector4* v_body, int speed){ Vector2 heading = v2_normal(flatten(*origin)); v_body->x += heading.x * (speed*throttle); @@ -95,6 +99,7 @@ void update_bullets(){ asteroids[a].w = 0; bullets[i].w = 0; score++; + explode_asteroid(&asteroids[a]); break; } } @@ -143,8 +148,9 @@ void update_astrs() { astr->y += sin(astr->z * (PI/180)) *3; DrawPolyLines(flatten(*astr), 7, astr->w, 0, RAYWHITE); } - if(!onscreen(flatten(*astr))) + if(!onscreen(flatten(*astr))) { astr->w = 0; + } if(ship_collision(astr) && ship_alive){ die(); @@ -198,6 +204,7 @@ int main(void) { astr_spawner = rand() & 1000 + 1; } else { DrawText("YOU DIED", (scrW/2)-(MeasureText("YOU DIED", 64)/2), (scrH/2)-64, 64, RED); + DrawText("FUCK YOU", (scrW/2)-(MeasureText("FUCK YOU", 16)/2), (scrH/2)-8, 16, RED); explode_ship(); } if(throttle && astr_spawner > 989) { @@ -205,6 +212,7 @@ int main(void) { } update_bullets(); update_astrs(); + update_explosions(); DrawText(TextFormat("%d", score), 4, scrH-34, 32, WHITE); DrawFPS(0, 0); @@ -218,3 +226,36 @@ int main(void) { return 0; } + +void explode_asteroid(Vector4* astr) { + for(int i = 0; i < MAX_ASTEROIDS; i++) { + if(dead_astr[i][0].w == 0) { + for (int a = 0; a < SHIP_DEBRIS; a++) { + dead_astr[i][a].x = astr->x; + dead_astr[i][a].y = astr->y; + dead_astr[i][a].z = (360/SHIP_DEBRIS) * a; + dead_astr[i][a].w = 1; + } + break; + } + } +} + +void update_explosions() { + int offscreen_bubbles = 0; + for(int i = 0; i < MAX_ASTEROIDS; i++) { + if(dead_astr[i][0].w == 1) { + for (int a = 0; a < SHIP_DEBRIS; a++) { + dead_astr[i][a].x += cos(dead_astr[i][a].z * (PI/180)) * 5; + dead_astr[i][a].y += sin(dead_astr[i][a].z * (PI/180)) * 5; + DrawCircleLines(dead_astr[i][a].x, dead_astr[i][a].y, 8, RAYWHITE); + if(!onscreen(flatten(dead_astr[i][a]))) + offscreen_bubbles++; + if(offscreen_bubbles == SHIP_DEBRIS-1) + memset(&dead_astr[i], 0, sizeof(Vector4) * SHIP_DEBRIS); + } + } + offscreen_bubbles=0; + } + +}