aboutsummaryrefslogtreecommitdiff
path: root/src/entities
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-08-18 00:38:54 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-08-18 00:38:54 -0600
commit97c711ab6b6823d09893582281203dcade1cfe9a (patch)
treee4aa0dbe639592834b5c8d7faf196a5c8caa2c43 /src/entities
parentf98e6d4ea4ee52b298a7d9a9731da4c020bb4dfe (diff)
Using random thingy instead
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/antifaShip.c2
-rw-r--r--src/entities/caporale.c74
-rw-r--r--src/entities/caporale.h13
3 files changed, 14 insertions, 75 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index 6e8c239..fba84aa 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -117,7 +117,7 @@ void updateAntifaShip(Game * game, Entity * entity) {
break;
}
- //printf("%f\n", entity->health);
+ printf("%f\n", entity->health);
entityCheckTransformedCollisionModel(entity);
}
diff --git a/src/entities/caporale.c b/src/entities/caporale.c
index 1203b61..ff5e6b2 100644
--- a/src/entities/caporale.c
+++ b/src/entities/caporale.c
@@ -29,22 +29,6 @@ void initCaporale(Entity * entity, Game * game) {
};
data->timeSinceLastShot = 0.0;
-
- PIDConfig aimPIDConfig = (PIDConfig){
- .kP = 2.0,
- .kI = 0.0,
- .kD = 0.0,
- .angleMode = false,
- .doClamp = false,
- .min = 0.0,
- .max = 0.0
- };
-
- data->aimXPID = createPID(aimPIDConfig);
- data->aimYPID = createPID(aimPIDConfig);
- data->aimZPID = createPID(aimPIDConfig);
-
- data->initTarget = true;
}
void closeCaporale(Entity * entity) {
@@ -60,59 +44,27 @@ void updateGunsCaporale(Game * game, Entity * entity) {
Caporale * data = (Caporale*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
- DrawRay(data->ray, BLUE);
-
- // Get target.
- Vector3 target = Vector3Subtract(player->position, entity->position);
- target = Vector3Normalize(target);
- target = Vector3Scale(target, CAPORALE_TARGET_POINTER_DIS);
- data->targetSetpoint = target;
-
// Cool down.
if (t - data->timeSinceLastShot < CAPORALE_COOLDOWN)
return;
- // Get direction.
- target = Vector3Add(entity->position, data->target); // Transform to entity.
- Vector3 direction = Vector3Subtract(target, entity->position);
- direction = Vector3Normalize(direction);
-
- // Create bullet and shoot.
- Bullet bullet = createBulletFromDirection(*entity, direction, CAPORALE_BULLET_DAMAGE);
- BulletHitInfo info = shootBulletAtEntity(player, bullet);
-
- printf("%d\n", info.hit);
-
- data->ray = bullet.ray;
data->timeSinceLastShot = t;
-}
-void updateAimCaporale(Game * game, Entity * entity) {
- float t = GetFrameTime();
- Caporale * data = (Caporale*)entity->data;
- Entity * player = getEntityFromWorld(game->world, 0);
+ // Use random number to decide if hit.
+ SetRandomSeed(time(NULL));
- // Init.
- if (data->initTarget) {
- data->initTarget = false;
- data->target = Vector3Zero();
- data->targetVelocity = Vector3Zero();
+ if (GetRandomValue(1, CAPORALE_CHANGE_OF_HIT) != 1)
return;
- }
- // Move target closer to player.
- data->targetVelocity = (Vector3){
- runPID(data->targetSetpoint.x, data->target.x, &data->aimXPID),
- runPID(data->targetSetpoint.y, data->target.y, &data->aimYPID),
- runPID(data->targetSetpoint.z, data->target.z, &data->aimZPID)
- };
+ // If random thingy shoot bullet that can't miss.
- data->target = Vector3Add(data->target, Vector3Scale(data->targetVelocity, t));
+ // Get direction.
+ Vector3 direction = Vector3Subtract(player->position, entity->position);
+ direction = Vector3Normalize(direction);
- // debug.
- Vector3 target = Vector3Add(entity->position, data->target);
- DrawCubeV(target, Vector3One(), BLUE);
- DrawLine3D(entity->position, target, BLUE);
+ // Create bullet and shoot.
+ Bullet bullet = createBulletFromDirection(*entity, direction, CAPORALE_BULLET_DAMAGE);
+ shootBulletAtEntity(player, bullet);
}
void updateCaporale(Game * game, Entity * entity) {
@@ -121,14 +73,12 @@ void updateCaporale(Game * game, Entity * entity) {
Caporale * data = (Caporale*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
- //entityFlyToPoint(entity, player->position, &data->flyToPlayer);
+ entityFlyToPoint(entity, player->position, &data->flyToPlayer);
+ updateGunsCaporale(game, entity);
entityCheckTransformedCollisionModel(entity);
}
void drawCaporale(Game * game, Entity * entity) {
entityDraw(entity);
-
- updateAimCaporale(game, entity);
- updateGunsCaporale(game, entity);
}
diff --git a/src/entities/caporale.h b/src/entities/caporale.h
index 3999436..effba16 100644
--- a/src/entities/caporale.h
+++ b/src/entities/caporale.h
@@ -8,22 +8,11 @@
#define CAPORALE_COOLDOWN 0.5
#define CAPORALE_BULLET_DAMAGE 0.01
-#define CAPORALE_TARGET_POINTER_DIS 10.0
+#define CAPORALE_CHANGE_OF_HIT 10
typedef struct Caporale {
EntityFlyToPointInfo flyToPlayer;
double timeSinceLastShot;
-
- bool initTarget;
- Vector3 targetSetpoint;
- Vector3 target;
- Vector3 targetVelocity;
-
- PID aimXPID;
- PID aimYPID;
- PID aimZPID;
-
- Ray ray;
} Caporale;
void initCaporale(Entity * entity, Game * game);