Start of game over handling.

This commit is contained in:
Steve 2018-02-25 12:12:31 +00:00
parent befea2ac65
commit b3e87f8cfb
7 changed files with 144 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 MiB

After

Width:  |  Height:  |  Size: 4.1 MiB

BIN
music/Sadness.ogg Normal file

Binary file not shown.

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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");

View File

@ -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;