diff --git a/game.c b/game.c index 86ecf3e..440a5ff 100644 --- a/game.c +++ b/game.c @@ -51,6 +51,11 @@ #define MAX_SHAPES_PER_ENTITY 2 #define MAX_COLLISIONS 128U +#define GAME_OVER_WIDTH 24 +#define GAME_OVER_HEIGHT 8 +#define GAME_OVER_SCALE 0.025 +#define GAME_OVER_COUNTER_MASK (1 << 6) + #define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) typedef enum { @@ -98,6 +103,40 @@ static const vec2_t fire_verts[] = { }; static const vec2_t shot_verts[] = { { 0.0, -0.02 }, { 0.0, 0.02 } }; +static const vec2_t game_over_verts[][MAX_VERTS] = { + // G + { { -10, 4 }, { -12, 4 }, { -12, -4 }, { -10, -4 }, { -10, 0 } }, + // A + { { -9, -4 }, { -8, 4 }, { -7, -4 } }, + { { -8.75, -2 }, { -7.25, -2 } }, + // M + { { -6, -4 }, { -6, 4 }, { -5, -4 }, { -4, 4 }, { -4, -4 } }, + // E + { { -1, 4 }, { -3, 4 }, { -3, -4 }, { -1, -4 } }, + { { -3, 0 }, { -2, 0 } }, + // O + { { 1, 4 }, { 1, -4 }, { 3, -4 }, { 3, 4 }, { 1, 4 } }, + // V + { { 4, 4 }, { 5, -4 }, { 6, 4 } }, + // E + { { 9, 4 }, { 7, 4 }, { 7, -4 }, { 9, -4 } }, + { { 7, 0 }, { 8, 0 } }, + // R + { { 10, -4 }, { 10, 4 }, { 12, 4 }, { 12, -2 }, { 10, -2 }, { 12, -4 } }, +}; +static const unsigned game_over_lens[NELEMS(game_over_verts)] = { + 5, 3, 2, 5, 4, 2, 5, 3, 4, 2, 6, +}; +static const mat3_t game_over_transform = { + { GAME_OVER_SCALE, 0, 0 }, + { 0, GAME_OVER_SCALE, 0 }, + { 0, 0, 1 }, +}; +static const vec2_t game_over_bg = { + .x = (GAME_OVER_WIDTH + 2) * GAME_OVER_SCALE, + .y = (GAME_OVER_HEIGHT + 2) * GAME_OVER_SCALE, +}; + static entity_t entities[MAX_ENTITIES]; static mat3_t transforms[MAX_ENTITIES]; static shape_t shapes[MAX_SHAPES]; @@ -108,6 +147,7 @@ static unsigned asteroid_count; static bool dead; static float aspect; +static uint8_t counter; static unsigned ship_entity_id; static unsigned ship_shape_id; @@ -414,6 +454,7 @@ void game_init(float _aspect) aspect = _aspect; dead = false; + counter = 0; entity_count = shape_count = 0; entity_t *ship = add_entity(&ship_entity_id); @@ -438,8 +479,10 @@ void game_init(float _aspect) void game_update() { - if (dead) + if (dead) { + ++counter; return; + } ship_update(); @@ -480,4 +523,13 @@ void game_draw() shapes[i].verts, shapes[i].vert_count, transform, shapes[i].connect); } + + if (dead && !(counter & GAME_OVER_COUNTER_MASK)) { + renderer_clear_rect((vec2_t) { 0, 0 }, game_over_bg); + for (unsigned i = 0; i < NELEMS(game_over_verts); ++i) { + renderer_draw( + game_over_verts[i], game_over_lens[i], game_over_transform, + false); + } + } }