// Copyright 2025 Bill Rossi // // This file is part of Starship Futuretime // // Starship Futuretime is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. // // Starship Futuretime is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Starship Futuretime. If not, see . #include #include #include #include "game.h" #include "enemy.h" #include "bullet.h" #define FOREACH_ENTITY for (size_t i = 0; i < g->entities->count; i++) #define INIT_ENTITY Entity *e = g->entities->entities[i] void initialize_game(Game *g) { g->should_close = false; g->player = malloc(sizeof(Player)); initialize_player(g->player); g->entities = malloc(sizeof(Entities)); g->entities->entities = malloc(10 * sizeof(Entity*)); g->entities->count = 0; g->entities->capacity = 10; } void add_entity(Game *g, Entity *e) { if (g->entities->count >= g->entities->capacity) { g->entities->capacity *= 2; g->entities->entities = realloc(g->entities->entities, g->entities->capacity * sizeof(Entity*)); } g->entities->entities[g->entities->count++] = e; } void handle_input(Game *g) { handle_player_input(g->player); if (IsKeyPressed(KEY_S)) { add_entity(g, spawn_enemy()); } if (IsKeyPressed(KEY_SPACE)) { add_entity(g, spawn_bullet(g->player->position)); } } void run_frame(Game *g) { handle_input(g); move_player(g->player); FOREACH_ENTITY { INIT_ENTITY; e->tick(e, GetFrameTime()); } } void draw_frame(Game *g) { BeginDrawing(); ClearBackground(RAYWHITE); draw_player(g->player); FOREACH_ENTITY { INIT_ENTITY; e->draw(e); } EndDrawing(); } void run_until_closing(Game *g) { while (!WindowShouldClose() && !g->should_close) { run_frame(g); draw_frame(g); } }