1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include "caporale.h"
#include "assets.h"
#include "game.h"
#include <raylib.h>
#include <raymath.h>
void initCaporale(Entity * entity, Game * game) {
entity->model = &game->assets.models[CAPORATE_ASSET];
entity->collisionModel = entityCreateCollisionModel(*entity->model);
entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model);
setEntityRadius(entity);
// Allocate data.
entity->data = KF_MALLOC(sizeof(Caporale));
if (entity->data == NULL) {
ALLOCATION_ERROR;
return;
}
Caporale * data = (Caporale*)entity->data;
data->flyToPlayer = (EntityFlyToPointInfo){
.controller.bangbang.speed = 80,
.controller.bangbang.stopAt = 0.0,
.controlType = ENTITY_FLY_TO_POINT_BANG_BANG,
.rotationSpeed = 0.5,
.applyRotation = true
};
data->timeSinceLastShot = 0.0;
data->gunTarget = Vector3One();
}
void closeCaporale(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
entityFreeCollisionModel(entity->collisionModel);
entityFreeCollisionModel(entity->transformedCollisionModel);
}
void updateGunsCaporale(Game * game, Entity * entity) {
double t = GetTime();
Caporale * data = (Caporale*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
// Update gun target.
Vector3 target = Vector3Normalize(Vector3Subtract(player->position, entity->position));
data->gunTarget = Vector3Lerp(data->gunTarget, target, GetFrameTime() * CAPORALE_GUN_TARGETING_SPEED);
// Cool down.
if (t - data->timeSinceLastShot < CAPORALE_COOLDOWN)
return;
data->timeSinceLastShot = t;
float damage = CAPORALE_BULLET_DAMAGE;
if (entity->health <= CAPORALE_LOW_HEALTH_THRESHOLD)
damage = CAPORALE_LOW_HEALTH_BULLET_DAMAGE;
// Create bullet and shoot.
Bullet bullet = createBulletFromDirection(*entity, data->gunTarget, damage);
shootBulletAtEntity(player, bullet);
}
void updateCaporale(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
Caporale * data = (Caporale*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
entityFlyToPoint(entity, player->position, &data->flyToPlayer);
updateGunsCaporale(game, entity);
entityCheckTransformedCollisionModel(entity);
}
void drawCaporale(Game * game, Entity * entity) {
entityDraw(entity);
}
|