diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-11-06 21:14:58 -0700 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-11-06 21:14:58 -0700 |
commit | c28b9fdb3c15248604d38717a03e98c78ac88961 (patch) | |
tree | adf29a1c533d0217403c37e2590028e7fa892586 | |
parent | 4ca42bd3b6a55ee92cdf1af0f3137ab815f0375d (diff) |
Added kill log
-rw-r--r-- | src/entity.c | 18 | ||||
-rw-r--r-- | src/entity.h | 3 | ||||
-rw-r--r-- | src/game.c | 23 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/gameScreen.c | 4 | ||||
-rw-r--r-- | src/gameScreen.h | 1 | ||||
-rw-r--r-- | src/killLog.c | 54 | ||||
-rw-r--r-- | src/killLog.h | 10 | ||||
-rw-r--r-- | src/levels.c | 2 | ||||
-rw-r--r-- | src/world.c | 5 |
10 files changed, 86 insertions, 36 deletions
diff --git a/src/entity.c b/src/entity.c index 4197444..7fbf966 100644 --- a/src/entity.c +++ b/src/entity.c @@ -4,15 +4,15 @@ // This fucker is used for creating entities. const EntityTypeInfo entityTypeInfo[ENTITY_TYPE_COUNT] = { - (EntityTypeInfo){initAntifaShip, closeAntifaShip, updateAntifaShip, drawAntifaShip}, - (EntityTypeInfo){initSoldato, closeSoldato, updateSoldato, drawSoldato}, - (EntityTypeInfo){initCaporale, closeCaporale, updateCaporale, drawCaporale}, - (EntityTypeInfo){initSergente, closeSergente, updateSergente, drawSergente}, - (EntityTypeInfo){initMaresciallo, closeMaresciallo, updateMaresciallo, drawMaresciallo}, - (EntityTypeInfo){initGenerale, closeGenerale, updateGenerale, drawGenerale}, - (EntityTypeInfo){initMussolini, closeMussolini, updateMussolini, drawMussolini}, - (EntityTypeInfo){initGuidedMissile, closeGuidedMissile, updateGuidedMissile, drawGuidedMissile}, - (EntityTypeInfo){initMissile, closeMissile, updateMissile, drawMissile} + (EntityTypeInfo){initAntifaShip, closeAntifaShip, updateAntifaShip, drawAntifaShip, "AntifaShip"}, + (EntityTypeInfo){initSoldato, closeSoldato, updateSoldato, drawSoldato, "Soldato"}, + (EntityTypeInfo){initCaporale, closeCaporale, updateCaporale, drawCaporale, "Caporale"}, + (EntityTypeInfo){initSergente, closeSergente, updateSergente, drawSergente, "Sergente"}, + (EntityTypeInfo){initMaresciallo, closeMaresciallo, updateMaresciallo, drawMaresciallo, "Maresciallo"}, + (EntityTypeInfo){initGenerale, closeGenerale, updateGenerale, drawGenerale, "Generale"}, + (EntityTypeInfo){initMussolini, closeMussolini, updateMussolini, drawMussolini, "Mussolini"}, + (EntityTypeInfo){initGuidedMissile, closeGuidedMissile, updateGuidedMissile, drawGuidedMissile, "GuidedMissile"}, + (EntityTypeInfo){initMissile, closeMissile, updateMissile, drawMissile, "Missile"} }; EntityVelocity entityVelocityIdentity() { diff --git a/src/entity.h b/src/entity.h index d78f308..dfc38a4 100644 --- a/src/entity.h +++ b/src/entity.h @@ -130,12 +130,15 @@ typedef struct Entity { typedef void (*EntityInitCb)(Entity * entity, Game * game); typedef void (*EntityCloseCb)(Entity * entity); +#define ENTITY_TYPE_INFO_NAME_MAX 30 + // Info for each entity type. typedef struct EntityTypeInfo { EntityInitCb initCb; EntityCloseCb closeCb; EntityUpdateCb updateCb; EntityDrawCb drawCb; + char name[ENTITY_TYPE_INFO_NAME_MAX]; // Best use pascal case for the names (: } EntityTypeInfo; const extern EntityTypeInfo entityTypeInfo[ENTITY_TYPE_COUNT]; @@ -28,27 +28,8 @@ void initGame(Game * game) { // World. initWorld(&game->world); - // Debug. - // WorldEntry entries[31] = { - // (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, -100.0}, QuaternionIdentity()}, - // (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 6.0}, QuaternionIdentity()}, - // }; - - // for (int i = 2; i < 31; ++i) { - // entries[i] = (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 0.0, i*10}, QuaternionIdentity()}; - // } - - // WorldEntry entries[2] = { - // (WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()}, - // (WorldEntry){ENTITY_MUSSOLINI, (Vector3){0.0, 0.0, 200.0}, QuaternionIdentity()} - // }; - // - // addEntriesToWorld( - // &game->world, - // game, - // entries, - // sizeof(entries) / sizeof(WorldEntry) - // ); + // Kill log lmao. + initKillLog(&game->killLog); // Levels. initLevels(&game->levels); @@ -8,6 +8,7 @@ #include "settings.h" #include "bullets.h" #include "levels.h" +#include "killLog.h" #ifndef GAME_H #define GAME_H @@ -26,6 +27,7 @@ typedef struct Game { World world; Levels levels; Settings settings; + KillLog killLog; } Game; void initGame(Game * game); diff --git a/src/gameScreen.c b/src/gameScreen.c index 64d285c..d02e9be 100644 --- a/src/gameScreen.c +++ b/src/gameScreen.c @@ -3,6 +3,7 @@ #include "world.h" #include "bullets.h" #include "assets.h" +#include "killLog.h" #include "entitiesInclude.h" void initGameScreenGui(GameScreen * gameScreen) { @@ -19,6 +20,8 @@ void initGameScreenGui(GameScreen * gameScreen) { gameScreen->zoomViewPosition = (Vector2){width - GAME_SCREEN_ZOOM_VIEW_UI_SIZE - 20.0, 10.0}; + gameScreen->killLogPosition = (Vector2){0.0, 40.0}; + // Gyroscope indeed initGyroscope(&gameScreen->gyroscope); @@ -171,6 +174,7 @@ void drawGameScreenGui(Game * game) { drawCrossHair(10.0, 2.0, color); } + drawKillLog(&game->killLog, gameScreen->killLogPosition); drawGameScreenInfoText(game, gameScreen); drawGameScreenTargetInfo(game, gameScreen); drawGyroscope(game, &gameScreen->gyroscope); diff --git a/src/gameScreen.h b/src/gameScreen.h index e23156f..6cf95de 100644 --- a/src/gameScreen.h +++ b/src/gameScreen.h @@ -20,6 +20,7 @@ typedef struct GameScreen { Vector2 infoTextPosition; Vector2 targetInfoPosition; + Vector2 killLogPosition; Gyroscope gyroscope; Radar radar; diff --git a/src/killLog.c b/src/killLog.c index 81ad7c1..d5e06e9 100644 --- a/src/killLog.c +++ b/src/killLog.c @@ -1,12 +1,62 @@ #include "killLog.h" #include "game.h" +#include "entity.h" void initKillLog(KillLog * killLog) { killLog->killCount = 0; } -void pushKill(KillLog * killLog, Kill kill) { +void pushKill(KillLog * killLog, Entity entity) { + int i; + + Kill kill = (Kill){ + .type = entity.type, + .id = entity.id, + .fingerPrint = entity.fingerprint, + .timeAtKill = GetTime() + }; + + ++killLog->killCount; + + // Push shit back if at max size. + if (killLog->killCount > KILL_LOG_MAX) { + for (i = 0; i < KILL_LOG_MAX - 1; ++i) + killLog->kills[i] = killLog->kills[i + 1]; + + killLog->killCount = KILL_LOG_MAX; + } + + killLog->kills[killLog->killCount - 1] = kill; +} + +void formatKillMessage(char killMessage[KILL_MESSAGE_MAX], Kill kill) { + // Get time since kill in minutes and seconds. + double timeSinceKill = GetTime() - kill.timeAtKill; + int minutes = timeSinceKill / 60; + int seconds = (int)timeSinceKill % 60; + + // Nicely format. + snprintf(killMessage, KILL_MESSAGE_MAX, "%s@%x %d:%d", entityTypeInfo[kill.type].name, kill.fingerPrint, minutes, seconds); +} + +void drawKillLog(KillLog * killLog, Vector2 position) { + int i; + char killMessage[KILL_MESSAGE_MAX]; + + // Format and draw each kill. + for (i = 0; i < killLog->killCount; ++i) { + formatKillMessage(killMessage, killLog->kills[i]); + + DrawText( + killMessage, + position.x, + position.y + (KILL_LOG_FONT_SIZE * i), + KILL_LOG_FONT_SIZE, + WHITE + ); + } } -void drawKillLog(KillLog * killLog) { +void resetKillLog(KillLog * killLog) { + killLog->killCount = 0; } diff --git a/src/killLog.h b/src/killLog.h index 22f2962..b6e920a 100644 --- a/src/killLog.h +++ b/src/killLog.h @@ -4,9 +4,12 @@ #ifndef KILL_LOG_H #define KILL_LOG_H -#define KILL_LOG_MAX 5 +#define KILL_LOG_MAX 10 +#define KILL_MESSAGE_MAX 100 +#define KILL_LOG_FONT_SIZE 16 typedef struct Kill { + EntityType type; EntityId id; EntityFingerprint fingerPrint; double timeAtKill; @@ -18,7 +21,8 @@ typedef struct KillLog { } KillLog; void initKillLog(KillLog * killLog); -void pushKill(KillLog * killLog, Kill kill); -void drawKillLog(KillLog * killLog); +void pushKill(KillLog * killLog, Entity entity); +void drawKillLog(KillLog * killLog, Vector2 position); +void resetKillLog(KillLog * killLog); #endif diff --git a/src/levels.c b/src/levels.c index a5b29d4..3e79e2c 100644 --- a/src/levels.c +++ b/src/levels.c @@ -1,6 +1,7 @@ #include "levels.h" #include "game.h" #include "world.h" +#include "killLog.h" #include "levelsInclude.h" const LevelInfo levelInfoList[LEVELS_COUNT] = { @@ -15,6 +16,7 @@ void initLevels(Levels * levels) { void startLevel(Game * game, Levels * levels, int levelNum) { levels->currentLevel = levelNum; + resetKillLog(&game->killLog); initWorld(&game->world); levelInfoList[levelNum].initCb(game, levels); } diff --git a/src/world.c b/src/world.c index 0148043..f104ec1 100644 --- a/src/world.c +++ b/src/world.c @@ -1,6 +1,7 @@ #include "world.h" #include "game.h" #include "entity.h" +#include "killLog.h" #include "entitiesInclude.h" void initWorld(World * world) { @@ -346,8 +347,10 @@ void updateWorld(World * world, Game * game) { } // "bring out your dead!" - for (i = 0; i < killCount; ++i) + for (i = 0; i < killCount; ++i) { + pushKill(&game->killLog, *getEntityFromWorld(*world, kills[i])); removeEntityFromWorld(world, kills[i]); + } // Handle some shit. handleScheduledEntities(world); |