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
83
84
85
|
#include "guidedMissile.h"
#include "assets.h"
#include "game.h"
void initGuidedMissile(Entity * entity, Game * game) {
entity->model = &game->assets.models[GUIDED_MISSILE_ASSET];
entity->collisionModel = entityCreateCollisionModel(*entity->model);
entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model);
setEntityRadius(entity);
// Allocate data.
entity->data = KF_MALLOC(sizeof(GuidedMissile));
if (entity->data == NULL) {
ALLOCATION_ERROR;
return;
}
GuidedMissile * data = (GuidedMissile*)entity->data;
data->beenBorn = false; // NOT EVEN BORN YET! HA HA!!!
data->flyToPoint = (EntityFlyToPointInfo){
.controller.bangbang.speed = 80,
.controller.bangbang.stopAt = 0.0,
.controlType = ENTITY_FLY_TO_POINT_BANG_BANG,
.rotationSpeed = 10.0,
.applyRotation = true
};
}
void closeGuidedMissile(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
entityFreeCollisionModel(entity->collisionModel);
entityFreeCollisionModel(entity->transformedCollisionModel);
}
void updateGuidedMissile(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
Entity * player = getEntityFromWorld(game->world, 0);
GuidedMissile * data = (GuidedMissile*)entity->data;
// Life begins.
if (!data->beenBorn) {
data->beenBorn = true;
data->birthDay = GetTime();
}
entityFlyToPoint(entity, player->position, &data->flyToPoint);
// boom boom time
if (Vector3Distance(player->position, entity->position) <= GUIDED_MISSILE_BOOM_BOOM_AT)
guidedMissileGoBoomBoom(game, entity);
// Death countdown.
if (GetTime() - data->birthDay >= GUIDED_MISSILE_DEATH_DAY) {
guidedMissileGoBoomBoom(game, entity);
puts("Me is fucking dead!!!!");
}
entityCheckTransformedCollisionModel(entity);
}
void drawGuidedMissile(Game * game, Entity * entity) {
entityDraw(entity);
}
void guidedMissileGoBoomBoom(Game * game, Entity * entity) {
Entity * player = getEntityFromWorld(game->world, 0);
// Get player distance and get the damage the missile will do.
float distance = Vector3Distance(player->position, entity->position);
float damage = GUIDED_MISSILE_DAMAGE / distance;
// Hurt this mother fucker.
player->health -= damage;
// Remove its self from the world. I have thought of doing the same for years ):
entity->health = 0.0;
printf("This fucker died %f damage\n", damage);
}
|