MacLO/src/GameWindow.c
Jon Thysell 3542861603 Added level select scene and more
I've added a new level select scene after picking your set, and I've
updated the engine to store the result of each puzzle separately. The
level select is paged (can't fit all 50 on one screen), so needed to add
a new "previous button" graphic.

Added confirmation prompts, so I can prompt before quitting, and for a
new menu option to clear your scores if you want to reset your progress.

Progress is still not persisted when you exit, as I haven't figured out
how to do that yet.

I've also rearranged the title screen a bit.
2021-11-30 18:38:36 -08:00

144 lines
3.7 KiB
C

// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#include "GameWindow.h"
#include "TitleScene.h"
#include "LevelSelectScene.h"
#include "PlayScene.h"
#include "LevelEndScene.h"
#include "GameEndScene.h"
void GameWindow_Init(GameWindow *pGameWindow)
{
if (pGameWindow->Window != nil)
{
ShowError("\pGameWindow already initialized!", false);
}
pGameWindow->Window = GetNewWindow(BaseResID, nil, MoveToFront);
if (pGameWindow->Window == nil)
{
ShowError("\pGameWindow WIND resource missing!", true);
}
// Initialize window buffer
WindowBuffer_Init(&(pGameWindow->WindowBuffer), pGameWindow->Window);
// Initialize game engine
GameEngine_Init(&(pGameWindow->Engine));
// Load PICT resources
Bitmaps_Init(&(pGameWindow->Bitmaps));
// Load snd resources
Sounds_Init(&(pGameWindow->Sounds));
// Setup graphics before first draw
SetPort(pGameWindow->Window);
FillRect(&(pGameWindow->Window->portRect), WindowPattern);
GameWindow_SetScene(pGameWindow, Title);
}
void GameWindow_Draw(const GameWindow *pGameWindow, bool fullRefresh)
{
GrafPtr oldPort;
const Rect *pContentRect = &(pGameWindow->Window->portRect);
// Save the current port
GetPort(&oldPort);
WindowBuffer_StartDraw(&(pGameWindow->WindowBuffer));
if (fullRefresh)
{
// Fill background
FillRect(pContentRect, WindowPattern);
}
switch (pGameWindow->CurrentSceneId)
{
case Title:
TitleScene_Draw(pGameWindow, fullRefresh);
break;
case LevelSelect:
LevelSelectScene_Draw(pGameWindow, fullRefresh);
break;
case Play:
PlayScene_Draw(pGameWindow, fullRefresh);
break;
case LevelEnd:
LevelEndScene_Draw(pGameWindow, fullRefresh);
break;
case GameEnd:
GameEndScene_Draw(pGameWindow, fullRefresh);
break;
}
WindowBuffer_EndDraw(&(pGameWindow->WindowBuffer));
SetPort(oldPort);
}
void GameWindow_Click(GameWindow *pGameWindow, const Point *pPosition)
{
switch (pGameWindow->CurrentSceneId)
{
case Title:
TitleScene_Click(pGameWindow, pPosition);
break;
case LevelSelect:
LevelSelectScene_Click(pGameWindow, pPosition);
break;
case Play:
PlayScene_Click(pGameWindow, pPosition);
break;
case LevelEnd:
LevelEndScene_Click(pGameWindow, pPosition);
break;
case GameEnd:
GameEndScene_Click(pGameWindow, pPosition);
break;
}
}
void GameWindow_SetScene(GameWindow *pGameWindow, const SceneId sceneId)
{
switch (sceneId)
{
case Title:
TitleScene_Init(pGameWindow);
break;
case LevelSelect:
LevelSelectScene_Init(pGameWindow);
break;
case Play:
PlayScene_Init(pGameWindow);
break;
case LevelEnd:
LevelEndScene_Init(pGameWindow);
break;
case GameEnd:
GameEndScene_Init(pGameWindow);
break;
}
pGameWindow->CurrentSceneId = sceneId;
GameWindow_Draw(pGameWindow, true); // Always force a full refresh when changing scenes
}
void GameWindow_Show(const GameWindow *pGameWindow)
{
ShowWindow(pGameWindow->Window);
}
void GameWindow_ClearScores(GameWindow *pGameWindow)
{
if (ShowConfirm("\pClear all scores?"))
{
GameEngine_ResetGame(&(pGameWindow->Engine));
GameWindow_SetScene(pGameWindow, Title);
}
}