aboutsummaryrefslogtreecommitdiff
path: root/src/entities/sergente.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/sergente.c')
-rw-r--r--src/entities/sergente.c62
1 files changed, 61 insertions, 1 deletions
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,