aboutsummaryrefslogtreecommitdiff
path: root/src/entities/antifaShip.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-10-11 18:54:50 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-10-11 18:54:50 -0600
commitbbb2c70cd1a0603d57d0fc7615ad8994bfaf39bc (patch)
tree903a18ad8e33f240a278401fa7114b86f5733dc1 /src/entities/antifaShip.c
parent720467f4b295d86aac8acb75c78822c21fcba281 (diff)
Made player gun a bit better
Diffstat (limited to 'src/entities/antifaShip.c')
-rw-r--r--src/entities/antifaShip.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index e7f6d91..cf63698 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -30,6 +30,7 @@ void initAntifaShip(Entity * entity, Game * game) {
data->lastMouse = GetMousePosition();
data->forwardSpeed = 0.0;
data->shouldInitMousePosition = true;
+ data->timeSinceLastBullet = GetTime();
}
void closeAntifaShip(Entity * entity) {
@@ -40,6 +41,31 @@ void closeAntifaShip(Entity * entity) {
entityFreeCollisionModel(entity->transformedCollisionModel);
}
+// This fucker will fire a bullet!!!
+void fireBulletAntifa(Game * game, Entity * entity) {
+ double t = GetTime();
+ AntifaShip * data = (AntifaShip*)entity->data;
+
+ // Let it cool down.
+ if (t - data->timeSinceLastBullet < ANTIFA_BULLET_COOLDOWN)
+ return;
+
+ puts("shoot shoot");
+
+ Bullet bullet = createBulletFromEntity(*entity, 1.0);
+ BulletHitInfo info = shootBullet(&game->world, bullet);
+ data->lastBulletShot = bullet;
+
+ if (info.hit) {
+ Entity * hitEntity = getEntityFromWorld(game->world, info.hitId);
+ printVector3(hitEntity->position);
+ } else {
+ puts("you stink");
+ }
+
+ data->timeSinceLastBullet = t;
+}
+
void controlAntifaShipJoystick(Game * game, Entity * entity) {
Settings settings = game->settings;
int gamePadNum = settings.gamePadNum;
@@ -51,17 +77,8 @@ void controlAntifaShipJoystick(Game * game, Entity * entity) {
float speedStick = GetGamepadAxisMovement(gamePadNum, settings.speedStick);
// Shoot button.
- if (IsGamepadButtonPressed(gamePadNum, 8)) {
- Bullet bullet = createBulletFromEntity(*entity, 1.0);
- BulletHitInfo info = shootBullet(&game->world, bullet);
-
- if (info.hit) {
- Entity * hitEntity = getEntityFromWorld(game->world, info.hitId);
- printVector3(hitEntity->position);
- } else {
- puts("no stink");
- }
- }
+ if (IsGamepadButtonPressed(gamePadNum, 8))
+ fireBulletAntifa(game, entity);
Vector3 stick = (Vector3){
pitchStick,
@@ -85,6 +102,10 @@ void controlAntifaShipKeyboardAndMouse(Game * game, Entity * entity) {
data->lastMouse = Vector2Zero();
}
+ // Shoot bullet.
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ fireBulletAntifa(game, entity);
+
// Get mouse values.
Vector2 mouse = GetMousePosition();
float speed = GetMouseWheelMove();
@@ -134,4 +155,10 @@ void updateAntifaShip(Game * game, Entity * entity) {
void drawAntifaShip(Game * game, Entity * entity) {
entityDraw(entity);
+
+ // Draw bullet.
+ AntifaShip * data = (AntifaShip*)entity->data;
+
+ if (GetTime() - data->timeSinceLastBullet <= ANTIFA_DRAW_BULLET_FOR)
+ DrawRay(data->lastBulletShot.ray, BLUE);
}