aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-11-04 20:25:08 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-11-04 20:25:08 -0600
commit5627fd8128957710c6f16330b2bc1bc3251c5355 (patch)
tree63a175c8e8f0e1cbee756dd89b841477feaa7159 /src
parent89162a2e733fdca7733a0ce57c610461baf2dfaa (diff)
Getting it ready for real level making
Diffstat (limited to 'src')
-rw-r--r--src/entities/antifaShip.c38
-rw-r--r--src/entities/antifaShip.h2
-rw-r--r--src/entities/soldato.c49
-rw-r--r--src/entities/soldato.h5
-rw-r--r--src/gameScreen.c2
-rw-r--r--src/levels/level1.c2
-rw-r--r--src/levels/testLevel.c11
-rw-r--r--src/settings.c2
8 files changed, 63 insertions, 48 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index 60f9957..5383537 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -46,8 +46,14 @@ void closeAntifaShip(Entity * entity) {
entityFreeCollisionModel(entity->transformedCollisionModel);
}
-// Returns closest entity to ship or none.
-EntityId getClosestShipToAntifaShip(Game * game, Entity * entity) {
+float getAntifaShipAimDistance(Entity * ship, Entity * targetEntity) {
+ Vector3 directionAiming = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, ship->rotation);
+ Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, ship->position));
+ return Vector3Distance(directionAiming, directionToTarget);
+}
+
+// Returns closest entity to ship and in range or none.
+EntityId getShipInRangeAntifaShip(Game * game, Entity * entity) {
int i;
// Needs at least two entities to work correctly.
@@ -56,19 +62,19 @@ EntityId getClosestShipToAntifaShip(Game * game, Entity * entity) {
// Start out with entity 1 as closest.
Entity * currentEntity = &game->world.entities[1];
- EntityId closestId = currentEntity->id;
- float closestDistance = Vector3Distance(currentEntity->position, entity->position);
+ EntityId closestId = ENTITY_NONE;
+ float closestDistance = (float)INT_MAX;
float distance;
- // This entity will only ever be at id 0 so skip it. Also skip the one after that (:
- for (i = 2; i < game->world.entitiesCount; ++i) {
+ // This entity will only ever be at id 0 so skip it.
+ for (i = 1; i < game->world.entitiesCount; ++i) {
// Get entity and distance.
currentEntity = &game->world.entities[i];
distance = Vector3Distance(currentEntity->position, entity->position);
- // Is closest.
- if (distance < closestDistance) {
+ // Is closest and in range.
+ if (distance < closestDistance && getAntifaShipAimDistance(entity, currentEntity) <= ANTIFA_START_AUTO_TARGET_MAX) {
closestDistance = distance;
closestId = currentEntity->id;
}
@@ -77,12 +83,6 @@ EntityId getClosestShipToAntifaShip(Game * game, Entity * entity) {
return closestId;
}
-float getAntifaShipAimDistance(Entity * ship, Entity * targetEntity) {
- Vector3 directionAiming = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, ship->rotation);
- Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, ship->position));
- return Vector3Distance(directionAiming, directionToTarget);
-}
-
void updateAntifaShipTarget(Game * game, Entity * entity) {
float t = GetFrameTime();
AntifaShip * data = (AntifaShip*)entity->data;
@@ -110,8 +110,9 @@ void updateAntifaShipTarget(Game * game, Entity * entity) {
Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, entity->position));
// Update target.
- float speed = powf(ANTIFA_TARGETING_SPEED / aimDistance, 2.0);
+ float speed = ANTIFA_TARGETING_SPEED / aimDistance;
data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, speed * t);
+ printf("%f\n", speed);
// Is on target.
data->isOnTarget = traceRayToEntity(*targetEntity, (Ray){entity->position, data->gunTarget}).hit;
@@ -130,8 +131,7 @@ void toggleAntifaShipAutoTarget(Game * game, Entity * entity) {
return;
}
- // Get closest entity to target on.
- EntityId closestId = getClosestShipToAntifaShip(game, entity);
+ EntityId closestId = getShipInRangeAntifaShip(game, entity);
if (closestId == ENTITY_NONE)
return;
@@ -140,9 +140,7 @@ void toggleAntifaShipAutoTarget(Game * game, Entity * entity) {
Entity * closestEntity = getEntityFromWorld(game->world, closestId);
data->targetedEntityFingerprint = closestEntity->fingerprint;
- // Lock on target if can.
- if (getAntifaShipAimDistance(entity, closestEntity) <= ANTIFA_START_AUTO_TARGET_MAX)
- data->doAutoTarget = true;
+ data->doAutoTarget = true;
}
// This fucker will fire a bullet!!!
diff --git a/src/entities/antifaShip.h b/src/entities/antifaShip.h
index 50941ca..2781584 100644
--- a/src/entities/antifaShip.h
+++ b/src/entities/antifaShip.h
@@ -11,7 +11,7 @@
// Auto target shit.
#define ANTIFA_START_AUTO_TARGET_MAX 0.5 // How far off auto target can be entail it drops.
-#define ANTIFA_TARGETING_SPEED 0.5
+#define ANTIFA_TARGETING_SPEED 6.0
typedef struct AntifaShip {
Vector2 lastMouse;
diff --git a/src/entities/soldato.c b/src/entities/soldato.c
index 4230177..8372345 100644
--- a/src/entities/soldato.c
+++ b/src/entities/soldato.c
@@ -29,24 +29,26 @@ void initSoldato(Entity * entity, Game * game) {
.angleMode = false,
.doClamp = true,
.min = 0.0,
- .max = 50.0
+ .max = 80.0
};
// Create fly to point.
data->flyToPointLeading = (EntityFlyToPointInfo){
- .controller.bangbang.speed = 50,
+ .controller.bangbang.speed = 80.0,
.controller.bangbang.stopAt = 0.0,
.controlType = ENTITY_FLY_TO_POINT_BANG_BANG,
- .rotationSpeed = 50.0,
+ .rotationSpeed = SOLDATO_ROTATION_SPEED,
.applyRotation = true
};
data->flyToPointFollowing = (EntityFlyToPointInfo){
.controller.speedPID = createPID(followingPID),
.controlType = ENTITY_FLY_TO_POINT_PID,
- .rotationSpeed = 50.0,
+ .rotationSpeed = SOLDATO_ROTATION_SPEED,
.applyRotation = true
};
+
+ data->gunTarget = Vector3One();
}
void closeSoldato(Entity * entity) {
@@ -108,30 +110,25 @@ void updateSoldatoGuns(Game * game, Entity * entity) {
double t = GetTime();
Entity * player = getEntityFromWorld(game->world, 0);
Soldato * data = (Soldato*)entity->data;
+
+ // Gun target shit.
+ Vector3 target = Vector3Normalize(Vector3Subtract(player->position, entity->position));
+ data->gunTarget = Vector3Lerp(data->gunTarget, target, GetFrameTime() * SOLDATO_GUN_TARGETING_SPEED);
// Needs more time.
if (t - data->timeSinceLastShot < SOLDATO_COOLDOWN)
return;
- Bullet bullet = createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE);
- shootBulletAtEntity(player, bullet);
- data->timeSinceLastShot = t;
+ // Shoot if in range.
+ if (Vector3Distance(entity->position, player->position) <= SOLDATO_GUN_MAX_RANGE) {
+ Bullet bullet = createBulletFromDirection(*entity, data->gunTarget, SOLDATO_BULLET_DAMAGE);
+ BulletHitInfo hit = shootBulletAtEntity(player, bullet);
- /*
- // 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;
+ if (hit.hit)
+ printf("This fucker hit %lf\n", t);
}
- */
+
+ data->timeSinceLastShot = t;
}
void updateSoldato(Game * game, Entity * entity) {
@@ -156,6 +153,16 @@ void updateSoldato(Game * game, Entity * entity) {
void drawSoldato(Game * game, Entity * entity) {
entityDraw(entity);
+ // Debug gun.
+ /*
+ Soldato * data = (Soldato*)entity->data;
+ DrawLine3D(
+ entity->position,
+ Vector3Add(entity->position, Vector3Scale(data->gunTarget, SOLDATO_GUN_MAX_RANGE)),
+ BLUE
+ );
+ */
+
/*
Entity * leader;
diff --git a/src/entities/soldato.h b/src/entities/soldato.h
index f4228df..44d1c08 100644
--- a/src/entities/soldato.h
+++ b/src/entities/soldato.h
@@ -8,11 +8,16 @@
#define SOLDATO_COOLDOWN 1.0
#define SOLDATO_AIM_RADIOUS 1.5
#define SOLDATO_BULLET_DAMAGE 0.01
+#define SOLDATO_GUN_TARGETING_SPEED 2.0
+#define SOLDATO_GUN_MAX_RANGE 400.0
+#define SOLDATO_ROTATION_SPEED 0.5
typedef struct Soldato {
EntityFlyToPointInfo flyToPointLeading;
EntityFlyToPointInfo flyToPointFollowing;
double timeSinceLastShot;
+
+ Vector3 gunTarget;
} Soldato;
void initSoldato(Entity * entity, Game * game);
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 7f574f2..2d42284 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -232,7 +232,7 @@ void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) {
void renderWorldGameScreen(Game * game, GameScreen * gameScreen) {
BeginMode3D(game->cameras[gameScreen->mainCamera]);
- DrawGrid(50, 25.0);
+ //DrawGrid(50, 25.0);
// Draw world.
drawWorld(&game->world, game);
diff --git a/src/levels/level1.c b/src/levels/level1.c
index f97c663..ef40174 100644
--- a/src/levels/level1.c
+++ b/src/levels/level1.c
@@ -6,7 +6,7 @@
void initLevel1(Game * game, Levels * levels) {
WorldEntry entries[2] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_SERGENTE, (Vector3){0.0, 10.0, 500.0}, QuaternionIdentity()}
+ (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 10.0, 50.0}, QuaternionIdentity()}
};
addEntriesToWorld(
diff --git a/src/levels/testLevel.c b/src/levels/testLevel.c
index f036b1f..dbec99b 100644
--- a/src/levels/testLevel.c
+++ b/src/levels/testLevel.c
@@ -3,11 +3,16 @@
#include "world.h"
void initTestLevel(Game * game, Levels * levels) {
- WorldEntry entries[] = {
- (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_MUSSOLINI, (Vector3){0.0, 0.0, 200.0}, QuaternionIdentity()}
+ int i;
+
+ WorldEntry entries[21] = {
+ (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()}
};
+ for (i = 1; i < 21; ++i) {
+ entries[i] = (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 10.0, i * 10.0 + 50.0}, QuaternionIdentity()};
+ }
+
addEntriesToWorld(
&game->world,
game,
diff --git a/src/settings.c b/src/settings.c
index b0c724d..3e3a178 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -16,7 +16,7 @@ void initSettings(Settings * settings) {
.drawFps = true,
.renderWidth = 480,
.renderHeight = 270,
- .useWorldRenderTexture = true
+ .useWorldRenderTexture = false
};
}