diff --git a/gfx/atlas/atlas.png b/gfx/atlas/atlas.png index a72c726..0249774 100644 Binary files a/gfx/atlas/atlas.png and b/gfx/atlas/atlas.png differ diff --git a/music/Sadness.ogg b/music/Sadness.ogg new file mode 100644 index 0000000..79cd996 Binary files /dev/null and b/music/Sadness.ogg differ diff --git a/src/hub/postMission.c b/src/hub/postMission.c index 174f824..37cc5a9 100644 --- a/src/hub/postMission.c +++ b/src/hub/postMission.c @@ -71,16 +71,47 @@ void initPostMission(void) else { restoreGameState(); + + saveGame(); } - saveGame(); - destroyWorld(); initHub(); } } +void retryMission(void) +{ + restoreGameState(); + + saveGame(); + + initWorld(); +} + +void returnToHub(void) +{ + restoreGameState(); + + saveGame(); + + destroyWorld(); + + initHub(); +} + +void returnToTitle(void) +{ + restoreGameState(); + + saveGame(); + + destroyWorld(); + + initTitle(); +} + static void updateMissionStatus(void) { Tuple *t; diff --git a/src/hub/postMission.h b/src/hub/postMission.h index a2b279e..b71b557 100644 --- a/src/hub/postMission.h +++ b/src/hub/postMission.h @@ -35,6 +35,8 @@ extern void playSound(int snd, int ch); extern int isAcceptControl(void); extern void clearControls(void); extern void restoreGameState(void); +extern void initWorld(void); +extern void initTitle(void); extern App app; extern Colors colors; diff --git a/src/system/widgets.c b/src/system/widgets.c index 80aa8c0..d42800f 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -34,6 +34,7 @@ static int numWidgets; static Atlas *left; static Atlas *right; static Texture *atlasTexture; +static SDL_Rect frame; void initWidgets(void) { @@ -229,6 +230,13 @@ void drawWidgets(void) } } +void drawWidgetFrame(void) +{ + drawRect(frame.x, frame.y, frame.w, frame.h, 0, 0, 0, 192); + + drawOutlineRect(frame.x, frame.y, frame.w, frame.h, 255, 255, 255, 255); +} + static void selectWidget(int dir) { int oldWidgetIndex = widgetIndex; @@ -315,6 +323,8 @@ void hideAllWidgets(void) } selectedWidget = NULL; + + frame.x = frame.y = frame.w = frame.h = 0; } void showWidgetGroup(char *group) @@ -324,6 +334,9 @@ void showWidgetGroup(char *group) hideAllWidgets(); + frame.x = frame.y = SCREEN_WIDTH; + frame.w = frame.h = 0; + for (i = 0 ; i < numWidgets ; i++) { w = &widgets[i]; @@ -337,8 +350,17 @@ void showWidgetGroup(char *group) } w->visible = 1; + + frame.x = MIN(w->x - 25, frame.x); + frame.y = MIN(w->y - 25, frame.y); + frame.w = MAX(w->w + 50, frame.w); + frame.h = MAX(w->y + w->h + 25, frame.h); + } } + + + frame.h -= frame.y; } static void loadWidgets(void) diff --git a/src/world/world.c b/src/world/world.c index b8920e9..f7d2cd5 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -44,11 +44,17 @@ static void trophies(void); static void quit(void); static void returnFromTrophyStats(void); static void drawQuit(void); +static void drawGameOver(void); void quitMission(void); static void returnFromOptions(void); void autoCompleteMission(void); +static void retry(void); +static void hub(void); +static void title(void); static Texture *background; +static Texture *atlasTexture; +static Atlas *missionFailed; static int observationIndex; static int showing; @@ -64,6 +70,10 @@ void initWorld(void) background = getTexture(world.background); + atlasTexture = getTexture("gfx/atlas/atlas.png"); + + missionFailed = getImageFromAtlas("gfx/main/missionFailed.png"); + loadMusic(world.music); initQuadtree(&world.quadtree); @@ -102,6 +112,10 @@ void initWorld(void) getWidget("ok", "trophies")->action = returnFromTrophyStats; getWidget("ok", "gameQuit")->action = quitMission; getWidget("cancel", "gameQuit")->action = returnFromTrophyStats; + + getWidget("retry", "gameOver")->action = retry; + getWidget("hub", "gameOver")->action = hub; + getWidget("title", "gameOver")->action = title; if (world.missionType == MT_BOSS) { @@ -190,6 +204,11 @@ static void draw(void) drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 80, 24, TA_CENTER, colors.white, _("Press Fire to Continue")); break; + case WS_GAME_OVER: + drawNormal(); + drawGameOver(); + break; + default: if (world.betweenTimer == 0) { @@ -221,15 +240,9 @@ static void draw(void) static void drawInGameWidgets(void) { - int w, h; - - w = 300; - h = 550; - drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 128); - drawRect((SCREEN_WIDTH - w) / 2, (SCREEN_HEIGHT - h) / 2, w, h, 0, 0, 0, 192); - drawOutlineRect((SCREEN_WIDTH - w) / 2, (SCREEN_HEIGHT - h) / 2, w, h, 255, 255, 255, 255); + drawWidgetFrame(); drawWidgets(); } @@ -320,6 +333,10 @@ static void doWorldInProgress(void) if (world.allObjectivesComplete && world.state != WS_COMPLETE) { world.bob->flags |= EF_IMMUNE; + if (world.bob->stunTimer > 0) + { + world.bob->stunTimer = 0; + } if (strcmp(world.id, "teeka") == 0) { @@ -501,13 +518,27 @@ static void doGameComplete(void) static void doGameOver(void) { - world.gameOverTimer--; + if (world.gameOverTimer == -FPS) + { + stopMusic(); + } + else if (world.gameOverTimer == -FPS * 2) + { + loadMusic("music/Sadness.ogg"); + playMusic(0); + } + else if (world.gameOverTimer == -FPS * 3) + { + showWidgetGroup("gameOver"); + } + + world.gameOverTimer = MAX(-FPS * 5, world.gameOverTimer - 1); doCommon(); - - if (world.gameOverTimer <= -(FPS * 5)) + + if (world.gameOverTimer <= -FPS * 3) { - initTitle(); + doWidgets(); } } @@ -679,6 +710,30 @@ void observeActivation(Entity *e) } } +void drawGameOver(void) +{ + int fadeAmount; + + if (world.gameOverTimer <= -FPS) + { + fadeAmount = MIN((world.gameOverTimer + FPS) * -1, 128); + } + + drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, fadeAmount); + + if (world.gameOverTimer <= -FPS * 2) + { + blitRect(atlasTexture->texture, SCREEN_WIDTH / 2, 280, &missionFailed->rect, 1); + + if (world.gameOverTimer <= -FPS * 3) + { + drawWidgetFrame(); + + drawWidgets(); + } + } +} + void drawQuit(void) { SDL_Rect r; @@ -755,6 +810,21 @@ static void quit(void) showWidgetGroup("gameQuit"); } +static void retry(void) +{ + retryMission(); +} + +static void hub(void) +{ + returnToHub(); +} + +static void title(void) +{ + returnToTitle(); +} + static void returnFromTrophyStats(void) { showWidgetGroup("gamePaused"); diff --git a/src/world/world.h b/src/world/world.h index 3668506..e82b79b 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -105,6 +105,12 @@ extern void drawTrophies(void); extern void limitTextWidth(int width); extern void initOptions(void (*callback)(void)); extern int getMissionStatus(char *id); +extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center); +extern Atlas *getImageFromAtlas(char *filename); +extern void drawWidgetFrame(void); +extern void retryMission(void); +extern void returnToHub(void); +extern void returnToTitle(void); extern App app; extern Colors colors;