diff --git a/img/0.gif b/img/0.gif new file mode 100644 index 0000000..fef5607 Binary files /dev/null and b/img/0.gif differ diff --git a/img/1.gif b/img/1.gif new file mode 100644 index 0000000..9380c60 Binary files /dev/null and b/img/1.gif differ diff --git a/img/2.gif b/img/2.gif new file mode 100644 index 0000000..19d50a2 Binary files /dev/null and b/img/2.gif differ diff --git a/img/3.gif b/img/3.gif new file mode 100644 index 0000000..bd42644 Binary files /dev/null and b/img/3.gif differ diff --git a/img/4.gif b/img/4.gif new file mode 100644 index 0000000..dbf58ef Binary files /dev/null and b/img/4.gif differ diff --git a/img/5.gif b/img/5.gif new file mode 100644 index 0000000..a6e0d8c Binary files /dev/null and b/img/5.gif differ diff --git a/img/6.gif b/img/6.gif new file mode 100644 index 0000000..e8f2f9e Binary files /dev/null and b/img/6.gif differ diff --git a/img/7.gif b/img/7.gif new file mode 100644 index 0000000..e06ee54 Binary files /dev/null and b/img/7.gif differ diff --git a/img/8.gif b/img/8.gif new file mode 100644 index 0000000..057c5ce Binary files /dev/null and b/img/8.gif differ diff --git a/img/9.gif b/img/9.gif new file mode 100644 index 0000000..aa1c4dd Binary files /dev/null and b/img/9.gif differ diff --git a/img/a.gif b/img/a.gif new file mode 100644 index 0000000..bc072ed Binary files /dev/null and b/img/a.gif differ diff --git a/img/b.gif b/img/b.gif new file mode 100644 index 0000000..017ce2f Binary files /dev/null and b/img/b.gif differ diff --git a/img/slash.gif b/img/slash.gif new file mode 100644 index 0000000..cde8c7c Binary files /dev/null and b/img/slash.gif differ diff --git a/img/title.gif b/img/title.gif new file mode 100644 index 0000000..25de3cb Binary files /dev/null and b/img/title.gif differ diff --git a/img/title.png b/img/title.png deleted file mode 100644 index ab096a1..0000000 Binary files a/img/title.png and /dev/null differ diff --git a/src/Bitmaps.c b/src/Bitmaps.c new file mode 100644 index 0000000..64308bb --- /dev/null +++ b/src/Bitmaps.c @@ -0,0 +1,55 @@ +// Copyright (c) Jon Thysell +// 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); + } +} \ No newline at end of file diff --git a/src/Bitmaps.h b/src/Bitmaps.h new file mode 100644 index 0000000..1d8b2e6 --- /dev/null +++ b/src/Bitmaps.h @@ -0,0 +1,20 @@ +// Copyright (c) Jon Thysell +// 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 diff --git a/src/GameEndScene.c b/src/GameEndScene.c index 29a5900..d596cab 100644 --- a/src/GameEndScene.c +++ b/src/GameEndScene.c @@ -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"); } diff --git a/src/GameWindow.c b/src/GameWindow.c index b929d52..98d7380 100644 --- a/src/GameWindow.c +++ b/src/GameWindow.c @@ -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); } diff --git a/src/GameWindow.h b/src/GameWindow.h index e8af4f2..7e9ef54 100644 --- a/src/GameWindow.h +++ b/src/GameWindow.h @@ -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); diff --git a/src/LevelEndScene.c b/src/LevelEndScene.c index adfdaf5..16f90c7 100644 --- a/src/LevelEndScene.c +++ b/src/LevelEndScene.c @@ -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."); diff --git a/src/MacCommon.c b/src/MacCommon.c index 5d35cdf..892da58 100644 --- a/src/MacCommon.c +++ b/src/MacCommon.c @@ -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; + } } \ No newline at end of file diff --git a/src/MacCommon.h b/src/MacCommon.h index 40b6f4b..861d7b9 100644 --- a/src/MacCommon.h +++ b/src/MacCommon.h @@ -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 diff --git a/src/MacLO.c b/src/MacLO.c index 31fb129..4863ef9 100644 --- a/src/MacLO.c +++ b/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) { diff --git a/src/MacLO.pi.bin b/src/MacLO.pi.bin index d2cafb7..bdb822f 100644 Binary files a/src/MacLO.pi.bin and b/src/MacLO.pi.bin differ diff --git a/src/MacLO.pi.rsrc.bin b/src/MacLO.pi.rsrc.bin index 0324b38..35d86e7 100644 Binary files a/src/MacLO.pi.rsrc.bin and b/src/MacLO.pi.rsrc.bin differ diff --git a/src/PlayScene.c b/src/PlayScene.c index b8ac8a9..d7d2d22 100644 --- a/src/PlayScene.c +++ b/src/PlayScene.c @@ -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"); } diff --git a/src/Scenes.h b/src/Scenes.h index ef46def..2293bff 100644 --- a/src/Scenes.h +++ b/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 diff --git a/src/TitleScene.c b/src/TitleScene.c index cc2ef80..e0a50aa 100644 --- a/src/TitleScene.c +++ b/src/TitleScene.c @@ -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);