mirror of https://github.com/jonthysell/MacLO.git
Importing image assets from ArduLO
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". :)
This commit is contained in:
parent
66794a2241
commit
eab519a40d
Binary file not shown.
After Width: | Height: | Size: 73 B |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
img/title.png
BIN
img/title.png
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB |
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "Bitmaps.h"
|
||||
|
||||
#define NumChars 10
|
||||
|
||||
#define TitlePictResID BaseResID
|
||||
#define NumCharPictBaseResID (TitlePictResID + 1)
|
||||
#define ACharPictResID (NumCharPictBaseResID + NumChars)
|
||||
#define BCharPictResID (ACharPictResID + 1)
|
||||
#define SlashCharPictResID (BCharPictResID + 1)
|
||||
|
||||
void Bitmaps_Init(Bitmaps *pBitmaps)
|
||||
{
|
||||
int16_t i;
|
||||
|
||||
// Load title
|
||||
pBitmaps->TitlePict = GetPicture(TitlePictResID);
|
||||
if (pBitmaps->TitlePict == nil)
|
||||
{
|
||||
ShowError("\pTitle PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Load number chars
|
||||
for (i = 0; i < NumChars; i++)
|
||||
{
|
||||
pBitmaps->NumCharPicts[i] = GetPicture(NumCharPictBaseResID + i);
|
||||
if (pBitmaps->NumCharPicts[i] == nil)
|
||||
{
|
||||
ShowError("\pNumber char PICT resource missing!", true);
|
||||
}
|
||||
}
|
||||
|
||||
// Load "A" char
|
||||
pBitmaps->ACharPict = GetPicture(ACharPictResID);
|
||||
if (pBitmaps->ACharPict == nil)
|
||||
{
|
||||
ShowError("\pA char PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Load "B" char
|
||||
pBitmaps->BCharPict = GetPicture(BCharPictResID);
|
||||
if (pBitmaps->BCharPict == nil)
|
||||
{
|
||||
ShowError("\pB char PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Load "/" char
|
||||
pBitmaps->SlashCharPict = GetPicture(SlashCharPictResID);
|
||||
if (pBitmaps->SlashCharPict == nil)
|
||||
{
|
||||
ShowError("\pSlash char PICT resource missing!", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef BITMAPS_H
|
||||
#define BITMAPS_H
|
||||
|
||||
#include "MacCommon.h"
|
||||
|
||||
typedef struct sBitmaps
|
||||
{
|
||||
PicHandle TitlePict;
|
||||
PicHandle NumCharPicts[10];
|
||||
PicHandle ACharPict;
|
||||
PicHandle BCharPict;
|
||||
PicHandle SlashCharPict;
|
||||
} Bitmaps;
|
||||
|
||||
void Bitmaps_Init(Bitmaps *pBitmaps);
|
||||
|
||||
#endif
|
|
@ -11,8 +11,6 @@ void GameEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
{
|
||||
Str255 scoreStr;
|
||||
|
||||
SetPort(pGameWindow->Window);
|
||||
|
||||
// TODO: Proper level end
|
||||
if (fullRefresh)
|
||||
{
|
||||
|
@ -23,7 +21,7 @@ void GameEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
|
||||
MoveTo(100, 125);
|
||||
DrawString("\pScore: ");
|
||||
NumToString((long)(pGameWindow->Engine.Score), &scoreStr);
|
||||
NumToString((int32_t)(pGameWindow->Engine.Score), &scoreStr);
|
||||
DrawString(scoreStr);
|
||||
DrawString("\p/300");
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ void GameWindow_Init(GameWindow *pGameWindow)
|
|||
ShowError("\pGameWindow WIND resource missing!", true);
|
||||
}
|
||||
|
||||
// Load PICT resources
|
||||
Bitmaps_Init(&(pGameWindow->Bitmaps));
|
||||
|
||||
GameWindow_SetScene(pGameWindow, Title);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,18 +6,22 @@
|
|||
|
||||
#include "MacCommon.h"
|
||||
#include "GameEngine.h"
|
||||
#include "Bitmaps.h"
|
||||
#include "Scenes.h"
|
||||
|
||||
#define WindowPattern black
|
||||
#define WindowPattern black
|
||||
|
||||
typedef struct GameWindow
|
||||
typedef struct sGameWindow
|
||||
{
|
||||
WindowPtr Window;
|
||||
GameEngine Engine;
|
||||
SceneId CurrentSceneId;
|
||||
bool SceneIsInitialized[NumScenes];
|
||||
TitleScene TitleScene;
|
||||
PlayScene PlayScene;
|
||||
WindowPtr Window;
|
||||
GameEngine Engine;
|
||||
Bitmaps Bitmaps;
|
||||
SceneId CurrentSceneId;
|
||||
bool SceneIsInitialized[NumScenes];
|
||||
TitleScene TitleScene;
|
||||
PlayScene PlayScene;
|
||||
LevelEndScene LevelEndScene;
|
||||
GameEndScene GameEndScene;
|
||||
} GameWindow;
|
||||
|
||||
void GameWindow_Init(GameWindow *pGameWindow);
|
||||
|
|
|
@ -11,8 +11,6 @@ void LevelEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
{
|
||||
Str255 halfStarsStr;
|
||||
|
||||
SetPort(pGameWindow->Window);
|
||||
|
||||
// TODO: Proper level end
|
||||
if (fullRefresh)
|
||||
{
|
||||
|
@ -23,7 +21,7 @@ void LevelEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
|
||||
MoveTo(100, 125);
|
||||
DrawString("\pReceived ");
|
||||
NumToString((long)GameEngine_GetHalfStars(&(pGameWindow->Engine)), &halfStarsStr);
|
||||
NumToString((int32_t)GameEngine_GetHalfStars(&(pGameWindow->Engine)), &halfStarsStr);
|
||||
DrawString(halfStarsStr);
|
||||
DrawString("\p/6 half-stars.");
|
||||
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
|
||||
#include "MacCommon.h"
|
||||
|
||||
void ShowError(Str255 message, Boolean isFatal)
|
||||
int32_t GetThemeID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ShowError(Str255 message, bool isFatal)
|
||||
{
|
||||
ParamText(message, EmptyString, EmptyString, EmptyString);
|
||||
StopAlert(ErrorAlertResID, NilFilterProc);
|
||||
|
@ -30,4 +35,70 @@ void CenterRectV(const Rect *pOuterRect, Rect *pInnerRect)
|
|||
{
|
||||
OffsetRect(pInnerRect, 0, pOuterRect->top - pInnerRect->top);
|
||||
OffsetRect(pInnerRect, 0, (pOuterRect->bottom - pInnerRect->bottom) / 2);
|
||||
}
|
||||
|
||||
void GetBoxRect(const Rect *pOuterRect, const BoxAlignment boxAlignment, Rect *pBoxRect)
|
||||
{
|
||||
int32_t boxWidth, boxHeight;
|
||||
|
||||
boxWidth = (pOuterRect->right - pOuterRect->left) / 3;
|
||||
boxHeight = (pOuterRect->bottom - pOuterRect->top) / 3;
|
||||
|
||||
switch (boxAlignment)
|
||||
{
|
||||
case Top:
|
||||
pBoxRect->top = pOuterRect->top;
|
||||
pBoxRect->left = pOuterRect->left + boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->top + boxHeight;
|
||||
pBoxRect->right = pOuterRect->right - boxWidth;
|
||||
break;
|
||||
case TopLeft:
|
||||
pBoxRect->top = pOuterRect->top;
|
||||
pBoxRect->left = pOuterRect->left;
|
||||
pBoxRect->bottom = pOuterRect->top + boxHeight;
|
||||
pBoxRect->right = pOuterRect->left + boxWidth;
|
||||
break;
|
||||
case Left:
|
||||
pBoxRect->top = pOuterRect->top + boxHeight;
|
||||
pBoxRect->left = pOuterRect->left;
|
||||
pBoxRect->bottom = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->right = pOuterRect->left + boxWidth;
|
||||
break;
|
||||
case BottomLeft:
|
||||
pBoxRect->top = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->left = pOuterRect->left;
|
||||
pBoxRect->bottom = pOuterRect->bottom;
|
||||
pBoxRect->right = pOuterRect->left + boxWidth;
|
||||
break;
|
||||
case Bottom:
|
||||
pBoxRect->top = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->left = pOuterRect->left + boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->bottom;
|
||||
pBoxRect->right = pOuterRect->right - boxWidth;
|
||||
break;
|
||||
case BottomRight:
|
||||
pBoxRect->top = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->left = pOuterRect->right - boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->bottom;
|
||||
pBoxRect->right = pOuterRect->right;
|
||||
break;
|
||||
case Right:
|
||||
pBoxRect->top = pOuterRect->top + boxHeight;
|
||||
pBoxRect->left = pOuterRect->right - boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->right = pOuterRect->right;
|
||||
break;
|
||||
case TopRight:
|
||||
pBoxRect->top = pOuterRect->top;
|
||||
pBoxRect->left = pOuterRect->right - boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->top + boxHeight;
|
||||
pBoxRect->right = pOuterRect->right;
|
||||
break;
|
||||
case Center:
|
||||
pBoxRect->top = pOuterRect->top + boxHeight;
|
||||
pBoxRect->left = pOuterRect->left + boxWidth;
|
||||
pBoxRect->bottom = pOuterRect->bottom - boxHeight;
|
||||
pBoxRect->right = pOuterRect->right - boxWidth;
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
#ifndef MACCOMMON_H
|
||||
#define MACCOMMON_H
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#define BaseResID 128
|
||||
#define MoveToFront (WindowPtr)-1L
|
||||
|
||||
|
@ -12,12 +14,29 @@
|
|||
|
||||
#define ErrorAlertResID BaseResID
|
||||
|
||||
pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, short newItem) = { 0x303C, 0x0304, 0xAA68 };
|
||||
typedef enum eBoxAlignment
|
||||
{
|
||||
Top,
|
||||
TopLeft,
|
||||
Left,
|
||||
BottomLeft,
|
||||
Bottom,
|
||||
BottomRight,
|
||||
Right,
|
||||
TopRight,
|
||||
Center
|
||||
} BoxAlignment;
|
||||
|
||||
void ShowError(Str255 message, Boolean isFatal);
|
||||
pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, int16_t newItem) = { 0x303C, 0x0304, 0xAA68 };
|
||||
|
||||
int32_t GetThemeID();
|
||||
|
||||
void ShowError(Str255 message, bool isFatal);
|
||||
|
||||
void CenterRect(const Rect *pOuterRect, Rect *pInnerRect);
|
||||
void CenterRectH(const Rect *pOuterRect, Rect *pInnerRect);
|
||||
void CenterRectV(const Rect *pOuterRect, Rect *pInnerRect);
|
||||
|
||||
void GetBoxRect(const Rect *pOuterRect, const BoxAlignment boxAlignment, Rect *pBoxRect);
|
||||
|
||||
#endif
|
||||
|
|
28
src/MacLO.c
28
src/MacLO.c
|
@ -21,13 +21,13 @@ void MacLO_HandleUpdate(const EventRecord *pEvent);
|
|||
void MacLO_HandleMouseDown(const EventRecord *pEvent);
|
||||
void MacLO_HandleMouseUp(const EventRecord *pEvent);
|
||||
|
||||
void MacLO_HandleMenuChoice(const long menuChoice);
|
||||
void MacLO_HandleAppleMenuChoice(const short item);
|
||||
void MacLO_HandleMenuChoice(const int32_t menuChoice);
|
||||
void MacLO_HandleAppleMenuChoice(const int16_t item);
|
||||
|
||||
void MacLO_ShowAboutDialog();
|
||||
void MacLO_LaunchAppleMenuItem(const short item);
|
||||
void MacLO_LaunchAppleMenuItem(const int16_t item);
|
||||
|
||||
void MacLO_HandleGameMenuChoice(const short item);
|
||||
void MacLO_HandleGameMenuChoice(const int16_t item);
|
||||
|
||||
void MacLO_ToolBoxInit()
|
||||
{
|
||||
|
@ -116,8 +116,8 @@ void MacLO_HandleUpdate(const EventRecord *pEvent)
|
|||
void MacLO_HandleMouseDown(const EventRecord *pEvent)
|
||||
{
|
||||
WindowPtr window;
|
||||
long windowPart;
|
||||
long menuChoice;
|
||||
int32_t windowPart;
|
||||
int32_t menuChoice;
|
||||
Point mousePosition;
|
||||
|
||||
windowPart = FindWindow(pEvent->where, &window);
|
||||
|
@ -140,7 +140,7 @@ void MacLO_HandleMouseDown(const EventRecord *pEvent)
|
|||
void MacLO_HandleMouseUp(const EventRecord *pEvent)
|
||||
{
|
||||
WindowPtr window;
|
||||
long windowPart;
|
||||
int32_t windowPart;
|
||||
Point mousePosition;
|
||||
|
||||
windowPart = FindWindow(pEvent->where, &window);
|
||||
|
@ -155,10 +155,10 @@ void MacLO_HandleMouseUp(const EventRecord *pEvent)
|
|||
}
|
||||
}
|
||||
|
||||
void MacLO_HandleMenuChoice(const long menuChoice)
|
||||
void MacLO_HandleMenuChoice(const int32_t menuChoice)
|
||||
{
|
||||
short menu;
|
||||
short item;
|
||||
int16_t menu;
|
||||
int16_t item;
|
||||
|
||||
if (menuChoice != 0)
|
||||
{
|
||||
|
@ -179,11 +179,11 @@ void MacLO_HandleMenuChoice(const long menuChoice)
|
|||
}
|
||||
}
|
||||
|
||||
void MacLO_HandleAppleMenuChoice(const short item)
|
||||
void MacLO_HandleAppleMenuChoice(const int16_t item)
|
||||
{
|
||||
MenuHandle appleMenu;
|
||||
Str255 accName;
|
||||
short accNumber;
|
||||
int16_t accNumber;
|
||||
|
||||
switch (item)
|
||||
{
|
||||
|
@ -214,7 +214,7 @@ void MacLO_ShowAboutDialog()
|
|||
DisposDialog(dialog);
|
||||
}
|
||||
|
||||
void MacLO_LaunchAppleMenuItem(const short item)
|
||||
void MacLO_LaunchAppleMenuItem(const int16_t item)
|
||||
{
|
||||
MenuHandle appleMenu;
|
||||
Str255 accName;
|
||||
|
@ -225,7 +225,7 @@ void MacLO_LaunchAppleMenuItem(const short item)
|
|||
|
||||
}
|
||||
|
||||
void MacLO_HandleGameMenuChoice(const short item)
|
||||
void MacLO_HandleGameMenuChoice(const int16_t item)
|
||||
{
|
||||
switch (item)
|
||||
{
|
||||
|
|
BIN
src/MacLO.pi.bin
BIN
src/MacLO.pi.bin
Binary file not shown.
Binary file not shown.
|
@ -43,8 +43,6 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
Rect lightRect;
|
||||
Str255 levelStr, parStr, movesStr, halfStarsStr, scoreStr;
|
||||
|
||||
SetPort(pGameWindow->Window);
|
||||
|
||||
if (fullRefresh)
|
||||
{
|
||||
// Fill backgrounds
|
||||
|
@ -89,13 +87,13 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
// Draw Par
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 40);
|
||||
DrawString("\pPar: ");
|
||||
NumToString((long)(pGameWindow->Engine.Par), &parStr);
|
||||
NumToString((int32_t)(pGameWindow->Engine.Par), &parStr);
|
||||
DrawString(parStr);
|
||||
|
||||
// Draw Moves
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 60);
|
||||
DrawString("\pMoves: ");
|
||||
NumToString((long)(pGameWindow->Engine.Moves), &movesStr);
|
||||
NumToString((int32_t)(pGameWindow->Engine.Moves), &movesStr);
|
||||
DrawString(movesStr);
|
||||
DrawString("\p/");
|
||||
DrawString(parStr);
|
||||
|
@ -103,14 +101,14 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
// Draw Stars
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 80);
|
||||
DrawString("\pStars: ");
|
||||
NumToString((long)GameEngine_GetHalfStars(&(pGameWindow->Engine)), &halfStarsStr);
|
||||
NumToString((int32_t)GameEngine_GetHalfStars(&(pGameWindow->Engine)), &halfStarsStr);
|
||||
DrawString(halfStarsStr);
|
||||
DrawString("\p/6");
|
||||
|
||||
// Draw Score
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 100);
|
||||
DrawString("\pScore: ");
|
||||
NumToString((long)(pGameWindow->Engine.Score), &scoreStr);
|
||||
NumToString((int32_t)(pGameWindow->Engine.Score), &scoreStr);
|
||||
DrawString(scoreStr);
|
||||
DrawString("\p/300");
|
||||
}
|
||||
|
|
17
src/Scenes.h
17
src/Scenes.h
|
@ -6,7 +6,7 @@
|
|||
|
||||
#define NumScenes 4
|
||||
|
||||
typedef enum SceneId
|
||||
typedef enum eSceneId
|
||||
{
|
||||
Title,
|
||||
Play,
|
||||
|
@ -14,16 +14,25 @@ typedef enum SceneId
|
|||
GameEnd
|
||||
} SceneId;
|
||||
|
||||
typedef struct TitleScene
|
||||
typedef struct sTitleScene
|
||||
{
|
||||
PicHandle TitlePict;
|
||||
Rect TitleRect;
|
||||
} TitleScene;
|
||||
|
||||
typedef struct PlayScene
|
||||
typedef struct sPlayScene
|
||||
{
|
||||
Rect PlayfieldRect;
|
||||
Rect HUDRect;
|
||||
} PlayScene;
|
||||
|
||||
typedef struct sLevelEndScene
|
||||
{
|
||||
Rect temp;
|
||||
} LevelEndScene;
|
||||
|
||||
typedef struct sGameEndScene
|
||||
{
|
||||
Rect temp;
|
||||
} GameEndScene;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,38 +2,27 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
#include "TitleScene.h"
|
||||
|
||||
#define TitlePictResID BaseResID
|
||||
#include "Bitmaps.h"
|
||||
|
||||
void TitleScene_Init(GameWindow *pGameWindow)
|
||||
{
|
||||
const Rect *pContentRect = &(pGameWindow->Window->portRect);
|
||||
|
||||
pGameWindow->TitleScene.TitlePict = GetPicture(TitlePictResID);
|
||||
|
||||
if (pGameWindow->TitleScene.TitlePict == nil)
|
||||
{
|
||||
ShowError("\pTitle PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Setup rects
|
||||
pGameWindow->TitleScene.TitleRect = (**(pGameWindow->TitleScene.TitlePict)).picFrame;
|
||||
pGameWindow->TitleScene.TitleRect = (**(pGameWindow->Bitmaps.TitlePict)).picFrame;
|
||||
CenterRect(pContentRect, &(pGameWindow->TitleScene.TitleRect));
|
||||
}
|
||||
|
||||
void TitleScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
{
|
||||
SetPort(pGameWindow->Window);
|
||||
|
||||
// TODO: Proper title
|
||||
if (fullRefresh)
|
||||
{
|
||||
}
|
||||
|
||||
// Draw Title PICT
|
||||
DrawPicture(pGameWindow->TitleScene.TitlePict, &(pGameWindow->TitleScene.TitleRect));
|
||||
DrawPicture(pGameWindow->Bitmaps.TitlePict, &(pGameWindow->TitleScene.TitleRect));
|
||||
|
||||
ForeColor(blackColor);
|
||||
TextFace(bold + outline);
|
||||
|
||||
MoveTo(100, pGameWindow->TitleScene.TitleRect.bottom + 30);
|
||||
|
|
Loading…
Reference in New Issue