aboutsummaryrefslogtreecommitdiff
path: root/src/entities
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-14 18:31:35 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-14 18:31:35 -0600
commite94be85251a3905c3750487ecbdba628644a0582 (patch)
tree1a919f98cefa30db5f8d41a95a90c11874032e4e /src/entities
parent34ce13444db7525b2dc37183675ea6e907fea642 (diff)
More generale laser stuff
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/generale.c53
-rw-r--r--src/entities/generale.h9
2 files changed, 58 insertions, 4 deletions
diff --git a/src/entities/generale.c b/src/entities/generale.c
index bc7c0f0..c49faba 100644
--- a/src/entities/generale.c
+++ b/src/entities/generale.c
@@ -33,6 +33,9 @@ void initGenerale(Entity * entity, Game * game) {
data->zigzag = GENERALE_ZIG;
data->targetNotSet = true;
+
+ data->laserDirection = Vector3One();
+ data->isLaserOn = false;
}
void closeGenerale(Entity * entity) {
@@ -44,12 +47,52 @@ void closeGenerale(Entity * entity) {
}
void updateGeneraleLaser(Game * game, Entity * entity) {
+ float t = GetFrameTime();
Entity * player = getEntityFromWorld(game->world, 0);
Generale * data = (Generale*)entity->data;
- Vector3 direction = Vector3Subtract(player->position, entity->position);
+ // Not within distance.
+ data->isLaserOn = Vector3Distance(player->position, entity->position) <= GENERALE_LASER_MAX_DISTANCE;
+
+ if (!data->isLaserOn)
+ return;
+
+ // Direction to player.
+ Vector3 targetDirection = Vector3Normalize(Vector3Subtract(player->position, entity->position));
+
+ // Update laser direction.
+ data->laserDirection = Vector3Lerp(data->laserDirection, targetDirection, t * GENERALE_LASER_TRACKING_SPEED);
+
+ // Check if hits player
+ Ray ray = (Ray){
+ .position = entity->position,
+ .direction = data->laserDirection
+ };
+
+ RayCollision collision = traceRayToEntity(*player, ray);
+
+ // Do damage.
+ if (collision.hit)
+ player->health -= t * GENERALE_LASER_DAMAGE;
+
+ printf("%d\n", collision.hit);
+}
+
+void drawGeneraleLaser(Entity * entity) {
+ Generale * data = (Generale*)entity->data;
+
+ if (!data->isLaserOn)
+ return;
- DrawLine3D(entity->position, Vector3Add(entity->position, direction), RED);
+ // Draw the evil laser of doom.
+ DrawCylinderEx(
+ Vector3Add(entity->position, Vector3Scale(data->laserDirection, entity->radius)),
+ Vector3Add(entity->position, Vector3Scale(data->laserDirection, GENERALE_LASER_MAX_DISTANCE)),
+ GENERALE_LASER_THICKNESS,
+ GENERALE_LASER_THICKNESS,
+ GENERALE_LASER_SIDES,
+ RED
+ );
}
void updateGenerale(Game * game, Entity * entity) {
@@ -73,13 +116,15 @@ void updateGenerale(Game * game, Entity * entity) {
// Spin this fucker.
entityUpdateRotation(entity);
+ // THE EVIL LASER OF DOOM!!!!!
+ updateGeneraleLaser(game, entity);
+
entityCheckTransformedCollisionModel(entity);
}
void drawGenerale(Game * game, Entity * entity) {
entityDraw(entity);
-
- updateGeneraleLaser(game, entity);
+ drawGeneraleLaser(entity);
/*
Generale * data = (Generale*)entity->data;
diff --git a/src/entities/generale.h b/src/entities/generale.h
index bb8ba05..f400e31 100644
--- a/src/entities/generale.h
+++ b/src/entities/generale.h
@@ -8,6 +8,12 @@
#define GENERALE_ZIGZAG_SIZE_MAX 100.0
#define GENERALE_NEXT_POINT_THRESHOLD 1.0
+#define GENERALE_LASER_TRACKING_SPEED 10.0
+#define GENERALE_LASER_MAX_DISTANCE 100.0
+#define GENERALE_LASER_THICKNESS 0.25
+#define GENERALE_LASER_SIDES 8
+#define GENERALE_LASER_DAMAGE 1.0
+
typedef enum GeneraleZigZag {
GENERALE_ZIG,
GENERALE_ZAG
@@ -18,6 +24,9 @@ typedef struct Generale {
GeneraleZigZag zigzag;
Vector3 target;
bool targetNotSet;
+
+ Vector3 laserDirection;
+ bool isLaserOn;
} Generale;
void initGenerale(Entity * entity, Game * game);