diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-14 21:18:54 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-14 21:18:54 -0600 |
commit | 0612480baf3d173b2d210693d6a234d76bb902cf (patch) | |
tree | 1b746dc002b749e6cb7d135751eda88df2cb1ff4 /src | |
parent | c160543a7982a62062aae978da08e4f18ae1e712 (diff) |
More configurable missile
Diffstat (limited to 'src')
-rw-r--r-- | src/entities/missile.c | 70 | ||||
-rw-r--r-- | src/entities/missile.h | 26 | ||||
-rw-r--r-- | src/entities/mussolini.c | 3 |
3 files changed, 92 insertions, 7 deletions
diff --git a/src/entities/missile.c b/src/entities/missile.c index c8e22ea..575fbdc 100644 --- a/src/entities/missile.c +++ b/src/entities/missile.c @@ -9,9 +9,28 @@ void initMissile(Entity * entity, Game * game) { 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); } @@ -19,8 +38,24 @@ void closeMissile(Entity * entity) { 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); } @@ -28,10 +63,17 @@ void drawMissile(Game * game, Entity * entity) { entityDraw(entity); } -void aimMissileAtTarget(Entity * entity, Vector3 target) { +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}); @@ -39,8 +81,28 @@ void setMissileDirection(Entity * entity, Vector3 direction) { // Set velocity. entity->velocity.velocity = (Vector3){ - matrix.m2 * MISSILE_SPEED, - matrix.m6 * MISSILE_SPEED, - matrix.m10 * MISSILE_SPEED + 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"); +} diff --git a/src/entities/missile.h b/src/entities/missile.h index 9c81b52..915e1ad 100644 --- a/src/entities/missile.h +++ b/src/entities/missile.h @@ -4,14 +4,36 @@ #ifndef MISSILE_H #define MISSILE_H -#define MISSILE_SPEED 100.0 +#define MISSILE_LIVE_FOREVER -1.0 + +#define MISSILE_DEFAULT_SPEED 100.0 +#define MISSILE_DEFAULT_TIME_TO_LIVE MISSILE_LIVE_FOREVER +#define MISSILE_DEFAULT_DAMAGE 5.0 +#define MISSILE_DEFAULT_BOOM_BOOM_AT 5.0 + +// I WANT TO BUILD A FUCKING MISSILE IN REAL LIFE!!! + +typedef struct Missile { + double timeToLive; + double birthDay; + float damage; + float boomBoomAt; +} Missile; void initMissile(Entity * entity, Game * game); void closeMissile(Entity * entity); void updateMissile(Game * game, Entity * entity); void drawMissile(Game * game, Entity * entity); -void aimMissileAtTarget(Entity * entity, Vector3 target); +void launchMissileAtTarget(Entity * entity, Vector3 target, float speed); + void setMissileDirection(Entity * entity, Vector3 direction); +void setMissileDamage(Entity * entity, float damage); +void setMissileBoomBoomAt(Entity * entity, float boomBoomAt); + +void startMissileCountDown(Entity * entity, double timeToLive); + +// Ok boomer +void missileGoBoomBoom(Game * game, Entity * entity); #endif diff --git a/src/entities/mussolini.c b/src/entities/mussolini.c index 151e050..ed137b1 100644 --- a/src/entities/mussolini.c +++ b/src/entities/mussolini.c @@ -44,7 +44,8 @@ void updateMussoliniGuns(Game * game, Entity * entity) { // Shoot missile. Entity missile = createEntity(ENTITY_MISSILE, game); missile.position = entity->position; - aimMissileAtTarget(&missile, player->position); + launchMissileAtTarget(&missile, player->position, 200.0); + startMissileCountDown(&missile, 4.0); scheduleEntityToAdd(&game->world, missile); puts("shoot shoot"); |