mirror of
https://github.com/jonthysell/MacLO.git
synced 2024-06-01 20:41:28 +00:00
eab519a40d
I've imported some of the "character" images from ArduLO, converted to GIFs because they're easier to work with. They've been imported into a new Bitmaps structure so they only need to be loaded once at app start. I've also cleaned up some of the drawing code, and created a series of helpers for dividing Rects into a 3x3 grid, to make it easier to define the layout. I've also stubbed out "theme-support". :)
108 lines
2.7 KiB
C
108 lines
2.7 KiB
C
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
|
// Licensed under the MIT License.
|
|
|
|
#include "GameWindow.h"
|
|
#include "TitleScene.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);
|
|
}
|
|
|
|
// Load PICT resources
|
|
Bitmaps_Init(&(pGameWindow->Bitmaps));
|
|
|
|
GameWindow_SetScene(pGameWindow, Title);
|
|
}
|
|
|
|
void GameWindow_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|
{
|
|
const Rect *pContentRect = &(pGameWindow->Window->portRect);
|
|
|
|
SetPort(pGameWindow->Window);
|
|
|
|
if (fullRefresh)
|
|
{
|
|
// Fill background
|
|
FillRect(pContentRect, WindowPattern);
|
|
}
|
|
|
|
switch (pGameWindow->CurrentSceneId)
|
|
{
|
|
case Title:
|
|
TitleScene_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;
|
|
}
|
|
}
|
|
|
|
void GameWindow_Click(GameWindow *pGameWindow, const Point *pPosition)
|
|
{
|
|
switch (pGameWindow->CurrentSceneId)
|
|
{
|
|
case Title:
|
|
TitleScene_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)
|
|
{
|
|
GameWindow_Draw(pGameWindow, false);
|
|
if (!(pGameWindow->SceneIsInitialized[sceneId]))
|
|
{
|
|
switch (sceneId)
|
|
{
|
|
case Title:
|
|
TitleScene_Init(pGameWindow);
|
|
break;
|
|
case Play:
|
|
PlayScene_Init(pGameWindow);
|
|
break;
|
|
case LevelEnd:
|
|
LevelEndScene_Init(pGameWindow);
|
|
break;
|
|
case GameEnd:
|
|
GameEndScene_Init(pGameWindow);
|
|
break;
|
|
}
|
|
pGameWindow->SceneIsInitialized[sceneId] = true;
|
|
}
|
|
pGameWindow->CurrentSceneId = sceneId;
|
|
GameWindow_Draw(pGameWindow, true);
|
|
}
|
|
|
|
void GameWindow_Show(const GameWindow *pGameWindow)
|
|
{
|
|
ShowWindow(pGameWindow->Window);
|
|
}
|