aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-10-27 18:14:02 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-10-27 18:14:02 -0600
commit4c5b7bdbe8c1cfef9ed7a3ef639f3f83411b2b0e (patch)
tree015425e000fb05b5ef878a6b11b9b7c9be1383c3 /src
parent4a5bdb90ffdbd9974f86df14893e7287f2faa933 (diff)
Targeting info on screen
Diffstat (limited to 'src')
-rw-r--r--src/entities/antifaShip.c22
-rw-r--r--src/entities/antifaShip.h3
-rw-r--r--src/gameScreen.c5
-rw-r--r--src/levels/level1.c2
4 files changed, 26 insertions, 6 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index c89c820..fbcb138 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -33,8 +33,23 @@ void initAntifaShip(Entity * entity, Game * game) {
data->timeSinceLastBullet = GetTime();
data->doAutoTarget = false;
data->targetedEntityId = ENTITY_NONE;
+
+ // Targeting PID indeed (:
+ PIDConfig targetingPIDConfig = (PIDConfig){
+ .kP = 500.0,
+ .kI = 0.1,
+ .kD = 0.0,
+ .angleMode = false,
+ .doClamp = false,
+ .min = 0.0,
+ .max = 0.0
+ };
+
+ data->targetingPID = createPID(targetingPIDConfig);
}
+// Go back to burger king you elon musking loving mother fucker!
+
void closeAntifaShip(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
@@ -101,9 +116,12 @@ void updateAntifaShipTarget(Game * game, Entity * entity) {
}
Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, entity->position));
- data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, ANTIFA_AUTO_TARGET_SPEED * t);
- printf("%d %d\n", isAntifaShipGunInRange(entity, targetEntity), data->targetedEntityId);
+
+ // Run targeting PID and update target.
+ float speed = runPID(Vector3Distance(data->gunTarget, directionToTarget), 0.0, &data->targetingPID);
+ data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, speed * t);
} else {
+ resetPID(&data->targetingPID);
data->gunTarget = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation);
}
}
diff --git a/src/entities/antifaShip.h b/src/entities/antifaShip.h
index 89000c7..7474b00 100644
--- a/src/entities/antifaShip.h
+++ b/src/entities/antifaShip.h
@@ -1,6 +1,7 @@
#include "gameCommon.h"
#include "entity.h"
#include "bullets.h"
+#include "PID.h"
#ifndef ANTIFA_SHIP_H
#define ANTIFA_SHIP_H
@@ -11,7 +12,6 @@
// Auto target shit.
#define ANTIFA_START_AUTO_TARGET_MAX 0.5 // How far off auto target can be entail it drops.
-#define ANTIFA_AUTO_TARGET_SPEED 100.0
typedef struct AntifaShip {
Vector2 lastMouse;
@@ -23,6 +23,7 @@ typedef struct AntifaShip {
Vector3 gunTarget;
bool doAutoTarget;
+ PID targetingPID;
EntityId targetedEntityId;
EntityFingerprint targetedEntityFingerprint;
} AntifaShip;
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 70ea351..ec26fee 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -115,11 +115,12 @@ void drawGameScreenTargetInfo(Game * game, GameScreen * gameScreen) {
snprintf(
buf,
bufSize,
- "%s\nId: %d@%x\nDistance: %.2f\n",
+ "%s\nId: %d@%x\nDistance: %.2f\nOn Target: %s",
bufCopy,
data->targetedEntityId,
data->targetedEntityFingerprint,
- Vector3Distance(player->position, targetedEntity->position)
+ Vector3Distance(player->position, targetedEntity->position),
+ traceRayToEntity(*targetedEntity, (Ray){player->position, data->gunTarget}).hit ? "Yes" : "No"
);
}
}
diff --git a/src/levels/level1.c b/src/levels/level1.c
index 3ef8d64..f97c663 100644
--- a/src/levels/level1.c
+++ b/src/levels/level1.c
@@ -6,7 +6,7 @@
void initLevel1(Game * game, Levels * levels) {
WorldEntry entries[2] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 10.0, 500.0}, QuaternionIdentity()}
+ (WorldEntry){ENTITY_SERGENTE, (Vector3){0.0, 10.0, 500.0}, QuaternionIdentity()}
};
addEntriesToWorld(