summaryrefslogtreecommitdiffhomepage
path: root/src/bullet.c
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-05-12 17:34:21 -0400
committerrealtradam <[email protected]>2024-05-12 17:34:21 -0400
commit8475767975a0f07507908ba53dba894b97b48795 (patch)
tree4d5bf2f8c49eb92f8d9777e0606d944dca01905d /src/bullet.c
parentf5311cc940fd94aa70808f19a38581c80b764615 (diff)
downloadtojam2024-8475767975a0f07507908ba53dba894b97b48795.tar.gz
tojam2024-8475767975a0f07507908ba53dba894b97b48795.zip
shooting bullets
Diffstat (limited to 'src/bullet.c')
-rw-r--r--src/bullet.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/bullet.c b/src/bullet.c
new file mode 100644
index 0000000..5cff129
--- /dev/null
+++ b/src/bullet.c
@@ -0,0 +1,68 @@
+#include "bullet.h"
+
+typedef
+struct
+{
+ int team; // 0 means not in use
+ Vector3 position;
+ Vector3 direction;
+ int lifetime;
+}
+Bullet;
+
+Bullet bullets[100];
+
+ void
+spawn_bullet(int team, Vector3 position, Vector3 direction)
+{
+ if(team == 0)
+ {
+ return;
+ }
+ for(int i = 0; i < 100; ++i)
+ {
+ if(bullets[i].team != 0)
+ {
+ continue;
+ }
+ bullets[i].team = team;
+ bullets[i].position = position;
+ bullets[i].direction = direction;
+ bullets[i].lifetime = 100;
+ return;
+ };
+}
+
+ void
+render_bullets(void)
+{
+ for(int i = 0; i < 100; ++i)
+ {
+ if(bullets[i].team == 0)
+ {
+ continue;
+ }
+ DrawCube(bullets[i].position, 0.25, 0.25, 0.25, RED);
+ }
+}
+
+ void
+bullet_collision_check(void)
+{
+ for(int i = 0; i < 100; ++i)
+ {
+ if(bullets[i].team == 0)
+ {
+ continue;
+ }
+ bullets[i].lifetime -= 1;
+ if(bullets[i].lifetime <= 0)
+ {
+ bullets[i].team = 0;
+ }
+ bullets[i].position.x += bullets[i].direction.x * 0.25;
+ bullets[i].position.y += bullets[i].direction.y * 0.25;
+ bullets[i].position.z += bullets[i].direction.z * 0.25;
+ }
+
+}