diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-07-30 23:51:37 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-07-30 23:51:37 -0600 |
commit | fc6e0037a2f0769fdbd4c18bd96f49d55f630757 (patch) | |
tree | 79f6561d192c3e6e5887422c6b31beac35eab046 /src/entities | |
parent | f6dc479873edc98704dcf1ffb116ba5da03805b2 (diff) |
Started caporale circling thingy
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/antifaShip.c | 2 | ||||
-rw-r--r-- | src/entities/caporale.c | 34 | ||||
-rw-r--r-- | src/entities/caporale.h | 4 | ||||
-rw-r--r-- | src/entities/soldato.c | 42 | ||||
-rw-r--r-- | src/entities/soldato.h | 5 |
5 files changed, 80 insertions, 7 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c index 94fc8c8..6c017c8 100644 --- a/src/entities/antifaShip.c +++ b/src/entities/antifaShip.c @@ -120,6 +120,8 @@ void updateAntifaShip(Game * game, Entity * entity) { break; } + //printf("%f\n", entity->health); + entityCheckTransformedCollisionModel(entity); } diff --git a/src/entities/caporale.c b/src/entities/caporale.c index bd6fcd5..c8b4345 100644 --- a/src/entities/caporale.c +++ b/src/entities/caporale.c @@ -4,15 +4,45 @@ void initCaporale(Entity * entity, Game * game) { entity->model = &game->assets.models[CAPORATE_ASSET]; + entity->collisionModel = entityCreateCollisionModel(*entity->model); + entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model); setEntityRadius(entity); - entity->velocity.angularVelocity = (AxisAngle){(Vector3){1.0, 1.0, 1.0}, 1.0}; + + // Allocate data. + entity->data = KF_MALLOC(sizeof(Caporale)); + + if (entity->data == NULL) { + ALLOCATION_ERROR; + return; + } + + Caporale * data = (Caporale*)entity->data; + + data->flyToPlayer = (EntityFlyToPointInfo){ + .controller.bangbang.speed = 80, + .controller.bangbang.stopAt = 0.0, + .controlType = ENTITY_FLY_TO_POINT_BANG_BANG, + .rotationSpeed = 0.5 + }; } void closeCaporale(Entity * entity) { + if (entity->data != NULL) + KF_FREE(entity->data); + + entityFreeCollisionModel(entity->collisionModel); + entityFreeCollisionModel(entity->transformedCollisionModel); } void updateCaporale(Game * game, Entity * entity) { - entityUpdateRotation(entity); + entityUpdateLastValues(entity); + + Caporale * data = (Caporale*)entity->data; + Entity * player = getEntityFromWorld(game->world, 0); + + entityFlyToPoint(entity, player->position, &data->flyToPlayer); + + entityCheckTransformedCollisionModel(entity); } void drawCaporale(Game * game, Entity * entity) { diff --git a/src/entities/caporale.h b/src/entities/caporale.h index 13f86d1..e855b30 100644 --- a/src/entities/caporale.h +++ b/src/entities/caporale.h @@ -4,6 +4,10 @@ #ifndef CAPORALE_H #define CAPORALE_H +typedef struct Caporale { + EntityFlyToPointInfo flyToPlayer; +} Caporale; + void initCaporale(Entity * entity, Game * game); void closeCaporale(Entity * entity); void updateCaporale(Game * game, Entity * entity); 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) { diff --git a/src/entities/soldato.h b/src/entities/soldato.h index eb336db..f4228df 100644 --- a/src/entities/soldato.h +++ b/src/entities/soldato.h @@ -5,9 +5,14 @@ #ifndef SOLDATO_H #define SOLDATO_H +#define SOLDATO_COOLDOWN 1.0 +#define SOLDATO_AIM_RADIOUS 1.5 +#define SOLDATO_BULLET_DAMAGE 0.01 + typedef struct Soldato { EntityFlyToPointInfo flyToPointLeading; EntityFlyToPointInfo flyToPointFollowing; + double timeSinceLastShot; } Soldato; void initSoldato(Entity * entity, Game * game); |