aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent34ce13444db7525b2dc37183675ea6e907fea642 (diff)
More generale laser stuff
Diffstat (limited to 'src')
-rw-r--r--src/entities/generale.c53
-rw-r--r--src/entities/generale.h9
-rw-r--r--src/game.c2
-rw-r--r--src/settings.c2
-rw-r--r--src/world.c8
5 files changed, 61 insertions, 13 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);
diff --git a/src/game.c b/src/game.c
index c820fef..0079e7f 100644
--- a/src/game.c
+++ b/src/game.c
@@ -35,7 +35,7 @@ void initGame(Game * game) {
WorldEntry entries[2] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_MARESCIALLO, (Vector3){0.0, 0.0, 100.0}, QuaternionIdentity()}
+ (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 10.0}, QuaternionIdentity()}
};
addEntriesToWorld(
diff --git a/src/settings.c b/src/settings.c
index 7aa10ea..35de96f 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -5,7 +5,7 @@ void initSettings(Settings * settings) {
.controlMode = KEYBOARD_AND_MOUSE_CONTROL,
.mouseSensitivity = 0.1,
.scrollBarSpeed = 10.0,
- .lockMouse = false,
+ .lockMouse = true,
.gamePadNum = 0,
.pitchStick = 1,
.yawStick = 0,
diff --git a/src/world.c b/src/world.c
index a07bfcd..c34f17b 100644
--- a/src/world.c
+++ b/src/world.c
@@ -343,15 +343,9 @@ void updateWorld(World * world, Game * game) {
}
}
- if (killCount != 0) {
- printf("%ld\n", killCount);
- debugWorld(world);
- }
-
// "bring out your dead!"
- for (i = 0; i < killCount; ++i) {
+ for (i = 0; i < killCount; ++i)
removeEntityFromWorld(world, kills[i]);
- }
// Handle some shit.
handleScheduledEntities(world);