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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "missile.h"
#include "game.h"
#include "assets.h"
// I luv deadly weapons (:
void initMissile(Entity * entity, Game * game) {
entity->model = &game->assets.models[MISSILE_ASSET];
entity->collisionModel = entityCreateCollisionModel(*entity->model);
entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model);
setEntityRadius(entity);
entity->data = KF_MALLOC(sizeof(Missile));
if (entity->data == NULL) {
ALLOCATION_ERROR;
return;
}
Missile * data = (Missile*)entity->data;
data->timeToLive = MISSILE_DEFAULT_TIME_TO_LIVE;
data->birthDay = GetTime();
data->damage = MISSILE_DEFAULT_DAMAGE;
data->boomBoomAt = MISSILE_DEFAULT_BOOM_BOOM_AT;
entity->velocity.speed = MISSILE_DEFAULT_SPEED;
}
void closeMissile(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
entityFreeCollisionModel(entity->collisionModel);
entityFreeCollisionModel(entity->transformedCollisionModel);
}
void updateMissile(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
Missile * data = (Missile*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
entityUpdatePosition(entity);
// Check the count death to death.
if (data->timeToLive != MISSILE_LIVE_FOREVER)
if (GetTime() - data->birthDay >= data->timeToLive) {
missileGoBoomBoom(game, entity);
puts("counted downa downasdjkfdjskl down");
}
// We are quite close to the player indeed.
if (Vector3Distance(player->position, entity->position) <= data->boomBoomAt) {
missileGoBoomBoom(game, entity);
puts("you were fucking hit by this big ass missile");
}
entityCheckTransformedCollisionModel(entity);
}
void drawMissile(Game * game, Entity * entity) {
entityDraw(entity);
}
void launchMissileAtTarget(Entity * entity, Vector3 target, float speed) {
entity->velocity.speed = speed;
setMissileDirection(entity, Vector3Normalize(Vector3Subtract(entity->position, target)));
}
// Yo Maggie, If you are reading this I want you to know I have a crush on you (:
// You are a good person to talk to (even though it's mostly me info dumping) and I like your smile.
// Don't worry if you hurt my feelings ever.
// I am not in the best head space most of the time but I can take a lot of punches before hitting the ground.
// Anyone else reading this: GO FUCK YOURSELF YOU MAGA TRUMP WALMART SHOPPPER!!!
void setMissileDirection(Entity * entity, Vector3 direction) {
// Get look at matrix and rotation.
Matrix matrix = MatrixLookAt(Vector3Zero(), direction, (Vector3){0.0, 1.0, 0.0});
entity->rotation = QuaternionInvert(QuaternionFromMatrix(matrix));
// Set velocity.
entity->velocity.velocity = (Vector3){
matrix.m2 * entity->velocity.speed,
matrix.m6 * entity->velocity.speed,
matrix.m10 * entity->velocity.speed
};
}
void setMissileDamage(Entity * entity, float damage) {
((Missile*)entity->data)->damage = damage;
}
void setMissileBoomBoomAt(Entity * entity, float boomBoomAt) {
((Missile*)entity->data)->boomBoomAt = boomBoomAt;
}
void startMissileCountDown(Entity * entity, double timeToLive) {
Missile * data = (Missile*)entity->data;
data->timeToLive = timeToLive;
data->birthDay = GetTime();
}
// Fucking boom boom time!!!!
void missileGoBoomBoom(Game * game, Entity * entity) {
entity->health = 0.0;
puts("boom boom like the boomers");
}
|