From 61e89820f4ce329fbba27b44aab0cb617eb0e098 Mon Sep 17 00:00:00 2001
From: Bill Rossi <bassguitarbill@gmail.com>
Date: Sat, 1 Mar 2025 09:03:41 -0500
Subject: [PATCH] Pew pew

---
 bullet.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 bullet.h | 26 ++++++++++++++++++++++++++
 game.c   |  4 ++++
 3 files changed, 77 insertions(+)
 create mode 100644 bullet.c
 create mode 100644 bullet.h

diff --git a/bullet.c b/bullet.c
new file mode 100644
index 0000000..b7893d9
--- /dev/null
+++ b/bullet.c
@@ -0,0 +1,47 @@
+//    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 <https://www.gnu.org/licenses/>. 
+#include <stdlib.h>
+
+#include <raylib.h>
+
+#include "bullet.h"
+#include "entity.h"
+
+Entity *spawn_bullet(Vector2 spawn_at) {
+  Entity *e = malloc(sizeof(Entity));
+  e->name = "Bullet";
+  e->properties = malloc(sizeof(Entity));
+  BulletProperties *props = (BulletProperties*)e->properties;
+  props->position.x = spawn_at.x;
+  props->position.y = spawn_at.y;
+  props->position.width = 4;
+  props->position.height = 10;
+  props->velocity.x = 0;
+  props->velocity.y = -10;
+  e->draw = &draw_bullet;
+  e->tick = &tick_bullet;
+  e->free = &free_bullet;
+  return e;
+}
+
+void draw_bullet(Entity *e) {
+  BulletProperties *props = e->properties;
+  DrawRectangleRec(props->position, BLACK);
+}
+
+void tick_bullet(Entity *e, float dt) {
+  BulletProperties *props = e->properties;
+  props->position.y += props->velocity.y;
+}
+
+void free_bullet(Entity *e) {
+  free(e->properties);
+  free(e);
+}
diff --git a/bullet.h b/bullet.h
new file mode 100644
index 0000000..36fddad
--- /dev/null
+++ b/bullet.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 <https://www.gnu.org/licenses/>. 
+#ifndef BULLET_H
+#define BULLET_H
+#include <raylib.h>
+
+#include "entity.h"
+
+typedef struct BulletProperties {
+  Rectangle position;
+  Vector2 velocity;
+} BulletProperties;
+
+Entity *spawn_bullet(Vector2 spawn_at);
+void draw_bullet(Entity *e);
+void tick_bullet(Entity *e, float dt);
+void free_bullet(Entity *e);
+
+#endif
diff --git a/game.c b/game.c
index fd924a7..9e1a210 100644
--- a/game.c
+++ b/game.c
@@ -13,6 +13,7 @@
 
 #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]
@@ -40,6 +41,9 @@ void handle_input(Game *g) {
   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) {