aboutsummaryrefslogtreecommitdiff
path: root/src/entities/soldato.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-07-30 23:51:37 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-07-30 23:51:37 -0600
commitfc6e0037a2f0769fdbd4c18bd96f49d55f630757 (patch)
tree79f6561d192c3e6e5887422c6b31beac35eab046 /src/entities/soldato.c
parentf6dc479873edc98704dcf1ffb116ba5da03805b2 (diff)
Started caporale circling thingy
Diffstat (limited to 'src/entities/soldato.c')
-rw-r--r--src/entities/soldato.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c
index 69dd99a..f4ef912 100644
--- a/src/entities/soldato.c
+++ b/src/entities/soldato.c
@@ -20,6 +20,8 @@ void initSoldato(Entity * entity, Game * game) {
Soldato * data = (Soldato*)entity->data;
+ data->timeSinceLastShot = GetTime();
+
PIDConfig followingPID = (PIDConfig){
.kP = 1.0,
.kI = 0.0,
@@ -100,6 +102,36 @@ void handleFollower(Game * game, Entity * entity) {
}
}
+void updateSoldatoGuns(Game * game, Entity * entity) {
+ double t = GetTime();
+ Entity * player = getEntityFromWorld(game->world, 0);
+ Soldato * data = (Soldato*)entity->data;
+
+ // Needs more time.
+ if (t - data->timeSinceLastShot < SOLDATO_COOLDOWN)
+ return;
+
+ Bullet bullet = createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE);
+ shootBulletAtEntity(player, bullet);
+ data->timeSinceLastShot = t;
+
+ /*
+ // See if ray hits player radius.
+ Ray ray = (Ray){
+ entity->position,
+ Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation)
+ };
+
+ RayCollision collision = traceRayToEntityRadius(*player, ray, SOLDATO_AIM_RADIOUS);
+
+ // Shoots bullet is ray hits.
+ if (collision.hit) {
+ shootBulletAtEntity(player, createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE));
+ data->timeSinceLastShot = t;
+ }
+ */
+}
+
void updateSoldato(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
@@ -108,22 +140,21 @@ void updateSoldato(Game * game, Entity * entity) {
// Fly to player if no leader.
if (entity->follow.leaderId == ENTITY_NONE) {
- entityFlyToPoint(
- entity,
- player->position,
- &data->flyToPointLeading
- );
+ entityFlyToPoint(entity, player->position, &data->flyToPointLeading);
} else {
soldatoFollowLeader(game, entity);
handleFollower(game, entity);
}
+ updateSoldatoGuns(game, entity);
+
entityCheckTransformedCollisionModel(entity);
}
void drawSoldato(Game * game, Entity * entity) {
entityDraw(entity);
+ /*
Entity * leader;
// Debug line.
@@ -135,6 +166,7 @@ void drawSoldato(Game * game, Entity * entity) {
DrawLine3D(entity->position, leader->position, BLUE);
}
+ */
}
void setSoldatoLeader(Entity * entity1, Entity * entity2) {