diff --git a/enemy.c b/enemy.c
new file mode 100644
index 0000000..7e64330
--- /dev/null
+++ b/enemy.c
@@ -0,0 +1,50 @@
+// 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 "enemy.h"
+#include "entity.h"
+
+Entity *spawn_enemy(void) {
+ Entity *e = malloc(sizeof(Entity));
+ e->name = "Enemy";
+ e->properties = malloc(sizeof(Entity));
+ EnemyProperties *props = (EnemyProperties*)e->properties;
+ props->position.x = 400;
+ props->position.y = 50;
+ props->position.width = 25;
+ props->position.height = 25;
+ props->velocity.x = 3;
+ props->velocity.y = 0;
+ e->draw = &draw_enemy;
+ e->tick = &tick_enemy;
+ e->free = &free_enemy;
+ return e;
+}
+
+void draw_enemy(Entity *e) {
+ EnemyProperties *props = e->properties;
+ DrawRectangleRec(props->position, RED);
+}
+
+void tick_enemy(Entity *e, float dt) {
+ EnemyProperties *props = e->properties;
+ if (props->position.x < 200) props->velocity.x = 3;
+ if (props->position.x > 600) props->velocity.x = -3;
+
+ props->position.x += props->velocity.x;
+}
+
+void free_enemy(Entity *e) {
+ free(e->properties);
+ free(e);
+}
diff --git a/enemy.h b/enemy.h
new file mode 100644
index 0000000..d74f35d
--- /dev/null
+++ b/enemy.h
@@ -0,0 +1,26 @@
+// 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 .
+#ifndef ENEMY_H
+#define ENEMY_H
+#include
+
+#include "entity.h"
+
+typedef struct EnemyProperties {
+ Rectangle position;
+ Vector2 velocity;
+} EnemyProperties;
+
+Entity *spawn_enemy(void);
+void draw_enemy(Entity *e);
+void tick_enemy(Entity *e, float dt);
+void free_enemy(Entity *e);
+
+#endif
diff --git a/entity.h b/entity.h
new file mode 100644
index 0000000..8cea678
--- /dev/null
+++ b/entity.h
@@ -0,0 +1,31 @@
+// 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 .
+
+#ifndef ENTITY_H
+#define ENTITY_H
+
+typedef struct Entity Entity;
+typedef struct Entities Entities;
+
+struct Entity {
+ char *name;
+ void *properties;
+ void (*draw)(Entity *e);
+ void (*tick)(Entity *e, float dt);
+ void (*free)(Entity *e);
+};
+
+struct Entities {
+ Entity **entities;
+ size_t count;
+ size_t capacity;
+};
+
+#endif
diff --git a/game.c b/game.c
index dc0e275..fd924a7 100644
--- a/game.c
+++ b/game.c
@@ -10,27 +10,55 @@
#include
#include
#include
+
#include "game.h"
+#include "enemy.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());
+ }
}
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();
}
diff --git a/game.h b/game.h
index ac38bb0..c3fb0e6 100644
--- a/game.h
+++ b/game.h
@@ -13,12 +13,13 @@
#include
#include "player.h"
+#include "entity.h"
typedef struct Game {
Player *player;
+ Entities *entities;
/*
Levels levels;
- Entities entities;
*/
bool should_close;
} Game;