From 97c711ab6b6823d09893582281203dcade1cfe9a Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Fri, 18 Aug 2023 00:38:54 -0600 Subject: Using random thingy instead --- src/entities/caporale.c | 74 ++++++++----------------------------------------- 1 file changed, 12 insertions(+), 62 deletions(-) (limited to 'src/entities/caporale.c') diff --git a/src/entities/caporale.c b/src/entities/caporale.c index 1203b61..ff5e6b2 100644 --- a/src/entities/caporale.c +++ b/src/entities/caporale.c @@ -29,22 +29,6 @@ void initCaporale(Entity * entity, Game * game) { }; data->timeSinceLastShot = 0.0; - - PIDConfig aimPIDConfig = (PIDConfig){ - .kP = 2.0, - .kI = 0.0, - .kD = 0.0, - .angleMode = false, - .doClamp = false, - .min = 0.0, - .max = 0.0 - }; - - data->aimXPID = createPID(aimPIDConfig); - data->aimYPID = createPID(aimPIDConfig); - data->aimZPID = createPID(aimPIDConfig); - - data->initTarget = true; } void closeCaporale(Entity * entity) { @@ -60,59 +44,27 @@ void updateGunsCaporale(Game * game, Entity * entity) { Caporale * data = (Caporale*)entity->data; Entity * player = getEntityFromWorld(game->world, 0); - DrawRay(data->ray, BLUE); - - // Get target. - Vector3 target = Vector3Subtract(player->position, entity->position); - target = Vector3Normalize(target); - target = Vector3Scale(target, CAPORALE_TARGET_POINTER_DIS); - data->targetSetpoint = target; - // Cool down. if (t - data->timeSinceLastShot < CAPORALE_COOLDOWN) return; - // Get direction. - target = Vector3Add(entity->position, data->target); // Transform to entity. - Vector3 direction = Vector3Subtract(target, entity->position); - direction = Vector3Normalize(direction); - - // Create bullet and shoot. - Bullet bullet = createBulletFromDirection(*entity, direction, CAPORALE_BULLET_DAMAGE); - BulletHitInfo info = shootBulletAtEntity(player, bullet); - - printf("%d\n", info.hit); - - data->ray = bullet.ray; data->timeSinceLastShot = t; -} -void updateAimCaporale(Game * game, Entity * entity) { - float t = GetFrameTime(); - Caporale * data = (Caporale*)entity->data; - Entity * player = getEntityFromWorld(game->world, 0); + // Use random number to decide if hit. + SetRandomSeed(time(NULL)); - // Init. - if (data->initTarget) { - data->initTarget = false; - data->target = Vector3Zero(); - data->targetVelocity = Vector3Zero(); + if (GetRandomValue(1, CAPORALE_CHANGE_OF_HIT) != 1) return; - } - // Move target closer to player. - data->targetVelocity = (Vector3){ - runPID(data->targetSetpoint.x, data->target.x, &data->aimXPID), - runPID(data->targetSetpoint.y, data->target.y, &data->aimYPID), - runPID(data->targetSetpoint.z, data->target.z, &data->aimZPID) - }; + // If random thingy shoot bullet that can't miss. - data->target = Vector3Add(data->target, Vector3Scale(data->targetVelocity, t)); + // Get direction. + Vector3 direction = Vector3Subtract(player->position, entity->position); + direction = Vector3Normalize(direction); - // debug. - Vector3 target = Vector3Add(entity->position, data->target); - DrawCubeV(target, Vector3One(), BLUE); - DrawLine3D(entity->position, target, BLUE); + // Create bullet and shoot. + Bullet bullet = createBulletFromDirection(*entity, direction, CAPORALE_BULLET_DAMAGE); + shootBulletAtEntity(player, bullet); } void updateCaporale(Game * game, Entity * entity) { @@ -121,14 +73,12 @@ void updateCaporale(Game * game, Entity * entity) { Caporale * data = (Caporale*)entity->data; Entity * player = getEntityFromWorld(game->world, 0); - //entityFlyToPoint(entity, player->position, &data->flyToPlayer); + entityFlyToPoint(entity, player->position, &data->flyToPlayer); + updateGunsCaporale(game, entity); entityCheckTransformedCollisionModel(entity); } void drawCaporale(Game * game, Entity * entity) { entityDraw(entity); - - updateAimCaporale(game, entity); - updateGunsCaporale(game, entity); } -- cgit v1.2.3