diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-08-06 19:15:14 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-08-06 19:15:14 -0600 |
commit | f12d27b1d87d3bf436abb8ded2d16b8c01746138 (patch) | |
tree | 89cbad01569b0cf10a881bc571da5344ebbbe3f2 /src | |
parent | 0fae2327bbb24572f5c40236dcdaba4f4f8afb80 (diff) |
Generale working
Diffstat (limited to 'src')
-rw-r--r-- | src/entities/generale.c | 50 | ||||
-rw-r--r-- | src/entities/generale.h | 5 | ||||
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/playerCamera.c | 6 |
4 files changed, 56 insertions, 7 deletions
diff --git a/src/entities/generale.c b/src/entities/generale.c index dee37ee..39f38c1 100644 --- a/src/entities/generale.c +++ b/src/entities/generale.c @@ -19,7 +19,7 @@ void initGenerale(Entity * entity, Game * game) { Generale * data = (Generale*)entity->data; data->flyToPoint = (EntityFlyToPointInfo){ - .controller.bangbang.speed = 85.0, + .controller.bangbang.speed = 100.0, .controller.bangbang.stopAt = 0.0, .controlType = ENTITY_FLY_TO_POINT_BANG_BANG, .rotationSpeed = 0.0, @@ -27,6 +27,7 @@ void initGenerale(Entity * entity, Game * game) { }; data->zigzag = GENERALE_ZIG; + data->targetNotSet = true; } void closeGenerale(Entity * entity) { @@ -40,15 +41,60 @@ void closeGenerale(Entity * entity) { void updateGenerale(Game * game, Entity * entity) { entityUpdateLastValues(entity); + Generale * data = (Generale*)entity->data; + + // Next point. + if (data->targetNotSet) { + getTargetGenerale(game, entity); + data->targetNotSet = false; + } else if (Vector3Distance(entity->position, data->target) <= GENERALE_NEXT_POINT_THRESHOLD ) + getTargetGenerale(game, entity); + + entityFlyToPoint( + entity, + data->target, + &data->flyToPoint + ); + entityCheckTransformedCollisionModel(entity); } void drawGenerale(Game * game, Entity * entity) { entityDraw(entity); + + //Generale * data = (Generale*)entity->data; + + //DrawLine3D( + // entity->position, + // data->target, + // BLUE + //); + + //DrawCubeV(data->target, Vector3One(), BLUE); } void getTargetGenerale(Game * game, Entity * entity) { Entity * player = getEntityFromWorld(game->world, 0); + Generale * data = (Generale*)entity->data; + + Vector3 dis = Vector3Subtract(player->position, entity->position); + Vector3 dir = Vector3Normalize(dis); + + SetRandomSeed(time(NULL)); + float targetDis = GetRandomValue(GENERALE_ZIGZAG_SIZE_MIN, GENERALE_ZIGZAG_SIZE_MAX); + float distance = Vector3Distance(entity->position, player->position); + + if (distance < targetDis) + targetDis = distance; + + if (data->zigzag == GENERALE_ZIG) { + dir = Vector3RotateByAxisAngle(dir, Vector3One(), PI/4); + data->zigzag = GENERALE_ZAG; + } else { + dir = Vector3RotateByAxisAngle(dir, Vector3One(), -PI/4); + data->zigzag = GENERALE_ZIG; + } - //Vector3 dis = Vector3Subtract( + dir = Vector3Scale(dir, targetDis); + data->target = Vector3Add(entity->position, dir); } diff --git a/src/entities/generale.h b/src/entities/generale.h index 2266e98..943ff04 100644 --- a/src/entities/generale.h +++ b/src/entities/generale.h @@ -4,7 +4,9 @@ #ifndef GENERALE_H #define GENERALE_H -#define GENERALE_ZIGZAG_SIZE 10.0 +#define GENERALE_ZIGZAG_SIZE_MIN 5.0 +#define GENERALE_ZIGZAG_SIZE_MAX 100.0 +#define GENERALE_NEXT_POINT_THRESHOLD 0.1 typedef enum GeneraleZigZag { GENERALE_ZIG, @@ -15,6 +17,7 @@ typedef struct Generale { EntityFlyToPointInfo flyToPoint; GeneraleZigZag zigzag; Vector3 target; + bool targetNotSet; } Generale; void initGenerale(Entity * entity, Game * game); @@ -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, 10.0}, QuaternionIdentity()} + (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 100.0}, QuaternionIdentity()} }; addEntriesToWorld( diff --git a/src/playerCamera.c b/src/playerCamera.c index 6b165f3..f759166 100644 --- a/src/playerCamera.c +++ b/src/playerCamera.c @@ -23,7 +23,7 @@ void updatePlayerCamera(Camera3D * camera, Game * game) { // Up. camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation); - //camera->target = player->position; - //camera->position = (Vector3){10.0, 10.0, 10.0}; - //camera->up = (Vector3){0.0, 1.0, 0.0}; + camera->target = player->position; + camera->position = (Vector3){10.0, 10.0, 10.0}; + camera->up = (Vector3){0.0, 1.0, 0.0}; } |