aboutsummaryrefslogtreecommitdiff
path: root/src/entity.c
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-07-18 05:54:30 -0600
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-07-18 05:54:30 -0600
commitf3f5fedbf591c10fa675a32103bab9480b42abe8 (patch)
tree54b46a23279cc45091393762c0d01b9c3637b729 /src/entity.c
parent77a06748f9f394486cad833e2ca351e8dbcc7361 (diff)
Bullet system added
Diffstat (limited to 'src/entity.c')
-rw-r--r--src/entity.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/entity.c b/src/entity.c
index e918617..285744d 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -52,6 +52,7 @@ Entity createEntity(EntityType type, Game * game) {
// Set defaults.
Entity entity = (Entity){
.type = type,
+ .model = NULL,
.position = Vector3Zero(),
.rotation = QuaternionIdentity(),
.velocity = entityVelocityIdentity(),
@@ -59,6 +60,7 @@ Entity createEntity(EntityType type, Game * game) {
.useAcceleration = false,
.updateCb = info.updateCb,
.drawCb = info.drawCb,
+ .health = 1.0,
.data = NULL
};
@@ -152,7 +154,7 @@ void entityJoystickControl(Entity * entity, Vector3 stick, float speed) {
entityUpdatePosition(entity);
}
-void entityFlightToPoint(Entity * entity, Vector3 point, PID * speedPID, float rotationSpeed) {
+void entityFlyToPoint(Entity * entity, Vector3 point, EntityFlyToPointInfo * info) {
float t = GetFrameTime();
// Get distance and direction.
@@ -164,19 +166,37 @@ void entityFlightToPoint(Entity * entity, Vector3 point, PID * speedPID, float r
Quaternion rotation = QuaternionInvert(QuaternionFromMatrix(matrix));
// Rotate this fucker.
- if (rotationSpeed == 0.0)
+ if (info->rotationSpeed == 0.0)
entity->rotation = rotation;
else
- entity->rotation = QuaternionSlerp(entity->rotation, rotation, t * rotationSpeed);
+ entity->rotation = QuaternionSlerp(entity->rotation, rotation, t * info->rotationSpeed);
// Velocity control.
- float s = runPID(0.0, Vector3Length(dis), speedPID);
+ float speed = 0.0;
+
+ float distance = Vector3Length(dis);
+
+ switch (info->controlType) {
+ case ENTITY_FLY_TO_POINT_PID:
+ speed = runPID(0.0, -distance, &info->controller.speedPID);
+ break;
+ case ENTITY_FLY_TO_POINT_BANG_BANG:
+ speed = info->controller.bangbang.speed;
+
+ if (distance <= info->controller.bangbang.stopAt)
+ speed = 0.0;
+
+ break;
+ default: // Something is fucked up.
+ break;
+ }
+
Matrix m = QuaternionToMatrix(QuaternionInvert(entity->rotation));
// Accelerate.
if (entity->useAcceleration)
- s = accelerateValue(
- s,
+ speed = accelerateValue(
+ speed,
entity->lastVelocity.speed,
entity->acceleration.speedUp * t,
entity->acceleration.speedDown * t
@@ -184,13 +204,13 @@ void entityFlightToPoint(Entity * entity, Vector3 point, PID * speedPID, float r
// Velocity.
entity->velocity.velocity = (Vector3){
- m.m2 * s,
- m.m6 * s,
- m.m10 * s
+ m.m2 * speed,
+ m.m6 * speed,
+ m.m10 * speed
};
entityUpdatePosition(entity);
- entity->velocity.speed = s;
+ entity->velocity.speed = speed;
entity->lastVelocity = entity->velocity;
}