aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-12-18 12:06:26 -0700
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-12-18 12:06:26 -0700
commit2016fd3e8a39205843f770df7e80df27f720abad (patch)
tree926eebf9d5c332f6827a88ed35fba24330ddebef /src
parentef8583564b648f6fdda73711a18b469416c1fdfc (diff)
Health from last level now saved
Diffstat (limited to 'src')
-rw-r--r--src/game.c2
-rw-r--r--src/gameScreen.c4
-rw-r--r--src/gameScreen.h3
3 files changed, 8 insertions, 1 deletions
diff --git a/src/game.c b/src/game.c
index ef61d45..594646d 100644
--- a/src/game.c
+++ b/src/game.c
@@ -33,7 +33,7 @@ void initGame(Game * game) {
// Levels.
initLevels(&game->levels);
- startLevel(game, &game->levels, 11);
+ startLevel(game, &game->levels, 0);
}
void closeGame(Game * game) {
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 609f145..d35a05d 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -1,6 +1,7 @@
#include "gameScreen.h"
#include "game.h"
#include "world.h"
+#include "entity.h"
#include "bullets.h"
#include "assets.h"
#include "killLog.h"
@@ -42,6 +43,7 @@ void initGameScreen(Game * game, GameScreen * gameScreen) {
gameScreen->gameOver = false;
gameScreen->mainCamera = THIRD_PERSON_CAMERA;
gameScreen->levelComplete = false;
+ gameScreen->healthAtLevelEnd = ENTITY_MAX_HEALTH;
// Gyroscope indeed
initGyroscope(&gameScreen->gyroscope);
@@ -238,6 +240,7 @@ void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) {
if (GetTime() - gameScreen->timeAtLevelComplete >= GAME_SCREEN_NEXT_LEVEL_DELAY) {
gameScreen->levelComplete = false;
startLevel(game, &game->levels, gameScreen->lastLevel + 1);
+ getEntityFromWorld(game->world, 0)->health = gameScreen->healthAtLevelEnd;
}
return;
@@ -248,6 +251,7 @@ void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) {
// This fucker been completed.
if (complete) {
gameScreen->lastLevel = game->levels.currentLevel;
+ gameScreen->healthAtLevelEnd = getEntityFromWorld(game->world, 0)->health;
endLevel(game, &game->levels);
gameScreen->levelComplete = true;
gameScreen->timeAtLevelComplete = GetTime();
diff --git a/src/gameScreen.h b/src/gameScreen.h
index 5890350..92e6934 100644
--- a/src/gameScreen.h
+++ b/src/gameScreen.h
@@ -33,6 +33,9 @@ typedef struct GameScreen {
double timeAtLevelComplete;
int lastLevel;
+ // Since the player entity gets reallocated each level we use this to remember its health.
+ float healthAtLevelEnd;
+
bool gameOver;
double gameOverAt;