diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-08 14:56:28 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-08 14:56:28 -0600 |
commit | 20be44ab48c3c8ec94f7eecddd48fc0c5ae18c6e (patch) | |
tree | d78962571412f1e05006f6f38b46c567e707487e /src | |
parent | cbc6853814b0d1c4cd58784ee8e5c619c6491323 (diff) |
Shot gun thingy working
Diffstat (limited to 'src')
-rw-r--r-- | src/entities/antifaShip.c | 2 | ||||
-rw-r--r-- | src/entities/generale.c | 16 | ||||
-rw-r--r-- | src/entities/generale.h | 2 | ||||
-rw-r--r-- | src/entities/sergente.c | 62 | ||||
-rw-r--r-- | src/entities/sergente.h | 13 | ||||
-rw-r--r-- | src/game.c | 16 | ||||
-rw-r--r-- | src/playerCamera.c | 6 | ||||
-rw-r--r-- | src/settings.c | 4 |
8 files changed, 96 insertions, 25 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c index fba84aa..6e8c239 100644 --- a/src/entities/antifaShip.c +++ b/src/entities/antifaShip.c @@ -117,7 +117,7 @@ void updateAntifaShip(Game * game, Entity * entity) { break; } - printf("%f\n", entity->health); + //printf("%f\n", entity->health); entityCheckTransformedCollisionModel(entity); } diff --git a/src/entities/generale.c b/src/entities/generale.c index 728d9aa..4868824 100644 --- a/src/entities/generale.c +++ b/src/entities/generale.c @@ -70,15 +70,17 @@ void updateGenerale(Game * game, Entity * entity) { void drawGenerale(Game * game, Entity * entity) { entityDraw(entity); - //Generale * data = (Generale*)entity->data; + /* + Generale * data = (Generale*)entity->data; - //DrawLine3D( - // entity->position, - // data->target, - // BLUE - //); + DrawLine3D( + entity->position, + data->target, + BLUE + ); - //DrawCubeV(data->target, Vector3One(), BLUE); + DrawCubeV(data->target, Vector3One(), BLUE); + */ } void getTargetGenerale(Game * game, Entity * entity) { diff --git a/src/entities/generale.h b/src/entities/generale.h index 943ff04..bb8ba05 100644 --- a/src/entities/generale.h +++ b/src/entities/generale.h @@ -6,7 +6,7 @@ #define GENERALE_ZIGZAG_SIZE_MIN 5.0 #define GENERALE_ZIGZAG_SIZE_MAX 100.0 -#define GENERALE_NEXT_POINT_THRESHOLD 0.1 +#define GENERALE_NEXT_POINT_THRESHOLD 1.0 typedef enum GeneraleZigZag { GENERALE_ZIG, diff --git a/src/entities/sergente.c b/src/entities/sergente.c index 0a50956..0336355 100644 --- a/src/entities/sergente.c +++ b/src/entities/sergente.c @@ -1,6 +1,10 @@ #include "sergente.h" #include "assets.h" #include "game.h" +#include <float.h> +#include <limits.h> +#include <raylib.h> +#include <raymath.h> void initSergente(Entity * entity, Game * game) { entity->model = &game->assets.models[SERGENTE_ASSET]; @@ -27,6 +31,8 @@ void initSergente(Entity * entity, Game * game) { }; createSergenteTarget(game, entity); + + data->timeSinceLastShot = 0.0; } void closeSergente(Entity * entity) { @@ -49,6 +55,58 @@ void updateRotationSergente(Game * game, Entity * entity) { entity->rotation = QuaternionSlerp(entity->rotation, rotation, t * SERGENTE_ROTATION_SPEED); } +Vector3 getSergenteShotSpread() { + return Vector3Scale( + (Vector3){ + (float)GetRandomValue(-UCHAR_MAX, UCHAR_MAX) / UCHAR_MAX, + (float)GetRandomValue(-UCHAR_MAX, UCHAR_MAX) / UCHAR_MAX, + (float)GetRandomValue(-UCHAR_MAX, UCHAR_MAX) / UCHAR_MAX + }, + SERGENTE_SPREAD + ); +} + +void updateGunsSergente(Game * game, Entity * entity) { + int i; + float t = GetTime(); + Sergente * data = (Sergente*)entity->data; + Entity * player = getEntityFromWorld(game->world, 0); + Bullet shots[SERGENTE_SHOT_COUNT]; + + // debug draw. + for (i = 0; i < SERGENTE_SHOT_COUNT; ++i) { + DrawRay(data->shots[i].ray, BLUE); + DrawCube(data->shots[i].ray.position, 1.0, 1.0, 1.0, BLUE); + } + + // Cool down. + if (t - data->timeSinceLastShot < SERGENTE_COOL_DOWN) + return; + + // We will use random numbers later. + SetRandomSeed(time(NULL)); + + // Get direction to player. + Vector3 dirToPlayer = Vector3Subtract(player->position, entity->position); + dirToPlayer = Vector3Normalize(dirToPlayer); + Vector3 direction; + + // Shot the shots because this is a fucking shot gun. + for (i = 0; i < SERGENTE_SHOT_COUNT; ++i) { + direction = Vector3Add(dirToPlayer, getSergenteShotSpread()); + + // Create shot. + shots[i] = createBulletFromDirection(*entity, direction, SERGENTE_DAMAGE); + + // Shoot it. + //printf("%d\n", shootBulletAtEntity(player, shots[i]).hit); + + data->shots[i] = shots[i]; + } + + data->timeSinceLastShot = t; +} + void updateSergente(Game * game, Entity * entity) { entityUpdateLastValues(entity); @@ -60,13 +118,15 @@ void updateSergente(Game * game, Entity * entity) { if (Vector3Distance(entity->position, data->target) <= SERGENTE_NEXT_POINT_THRESHOLD) createSergenteTarget(game, entity); - updateRotationSergente(game, entity); + //updateRotationSergente(game, entity); entityCheckTransformedCollisionModel(entity); } void drawSergente(Game * game, Entity * entity) { entityDraw(entity); + updateGunsSergente(game, entity); + // Test if facing player always. //DrawLine3D( // entity->position, diff --git a/src/entities/sergente.h b/src/entities/sergente.h index cc79c9a..f73a191 100644 --- a/src/entities/sergente.h +++ b/src/entities/sergente.h @@ -1,19 +1,28 @@ #include "gameCommon.h" #include "entity.h" +#include "bullets.h" #ifndef SERGENTE_H #define SERGENTE_H -#define SERGENTE_TARGET_DIS_MIN 1 +#define SERGENTE_TARGET_DIS_MIN 5 #define SERGENTE_TARGET_DIS_MAX 100 -#define SERGENTE_NEXT_POINT_THRESHOLD 0.1 +#define SERGENTE_NEXT_POINT_THRESHOLD 1.0 #define SERGENTE_COME_BACK_DIS 200.0 #define SERGENTE_COME_BACK_PERCENT 0.5 #define SERGENTE_ROTATION_SPEED 20.0 +// Gun stuff. +#define SERGENTE_COOL_DOWN 0.5 +#define SERGENTE_SHOT_COUNT 50 +#define SERGENTE_SPREAD 0.1 +#define SERGENTE_DAMAGE 0.001 + typedef struct Sergente { EntityFlyToPointInfo flyToPoint; Vector3 target; + double timeSinceLastShot; + Bullet shots[SERGENTE_SHOT_COUNT]; } Sergente; void initSergente(Entity * entity, Game * game); @@ -24,18 +24,18 @@ void initGame(Game * game) { initWorld(&game->world); // Debug. - /* WorldEntry entries[31] = { */ - /* (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, -100.0}, QuaternionIdentity()}, */ - /* (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 6.0}, QuaternionIdentity()}, */ - /* }; */ + // WorldEntry entries[31] = { + // (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, -100.0}, QuaternionIdentity()}, + // (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 6.0}, QuaternionIdentity()}, + // }; - /* for (int i = 2; i < 31; ++i) { */ - /* entries[i] = (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 0.0, i*10}, QuaternionIdentity()}; */ - /* } */ + // for (int i = 2; i < 31; ++i) { + // entries[i] = (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 0.0, i*10}, QuaternionIdentity()}; + // } WorldEntry entries[2] = { (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()}, - (WorldEntry){ENTITY_CAPORALE, (Vector3){0.0, 0.0, 100.0}, QuaternionIdentity()} + (WorldEntry){ENTITY_SERGENTE, (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}; } diff --git a/src/settings.c b/src/settings.c index a8f3978..ceda921 100644 --- a/src/settings.c +++ b/src/settings.c @@ -2,8 +2,8 @@ void initSettings(Settings * settings) { *settings = (Settings){ - .controlMode = JOYSTICK_CONTROL, - .mouseSensitivity = 0.3, + .controlMode = KEYBOARD_AND_MOUSE_CONTROL, + .mouseSensitivity = 0.1, .scrollBarSpeed = 10.0, .gamePadNum = 0, .pitchStick = 1, |