mirror of
https://github.com/jonthysell/MacLO.git
synced 2024-06-26 08:29:27 +00:00
Updated TitleScene and PlayScene with new graphic chars
TitleScene now shows A and B "buttons" to start a game. PlayScene now shows just the level name in the HUD. Lots of new helpers added to scale and align rects where I want them.
This commit is contained in:
parent
eab519a40d
commit
d3b5a77eaa
|
@ -3,14 +3,14 @@
|
|||
|
||||
#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_DrawScaledPic(const PicHandle pic, const uint8_t scale);
|
||||
|
||||
void Bitmaps_Init(Bitmaps *pBitmaps)
|
||||
{
|
||||
int16_t i;
|
||||
|
@ -53,3 +53,94 @@ void Bitmaps_Init(Bitmaps *pBitmaps)
|
|||
ShowError("\pSlash char PICT resource missing!", true);
|
||||
}
|
||||
}
|
||||
|
||||
void Bitmaps_DrawScaledPic(const PicHandle pic, const uint8_t scale)
|
||||
{
|
||||
Point penPosition;
|
||||
Rect destRect;
|
||||
|
||||
GetPen(&penPosition);
|
||||
GetScaledPicFrame(pic, scale, &destRect);
|
||||
|
||||
OffsetRect(&destRect, penPosition.h, penPosition.v);
|
||||
|
||||
DrawPicture(pic, &destRect);
|
||||
MoveTo(destRect.right, destRect.top);
|
||||
}
|
||||
|
||||
void Bitmaps_GetNumberRect(const Bitmaps *pBitmaps, const uint32_t number, const uint8_t scale, Rect *pDestRect)
|
||||
{
|
||||
bool started;
|
||||
uint32_t k, digit, remainder;
|
||||
Rect digitRect;
|
||||
|
||||
pDestRect->top = 0;
|
||||
pDestRect->left = 0;
|
||||
pDestRect->bottom = 0;
|
||||
pDestRect->right = 0;
|
||||
|
||||
if (number == 0)
|
||||
{
|
||||
GetScaledPicFrame(pBitmaps->NumCharPicts[0], scale, &digitRect);
|
||||
ConcatenateRect(pDestRect, &digitRect, pDestRect);
|
||||
return;
|
||||
}
|
||||
|
||||
started = false;
|
||||
remainder = number;
|
||||
|
||||
for (k = 1000000000UL; k > 0; k = k / 10)
|
||||
{
|
||||
digit = remainder / k;
|
||||
remainder = remainder % k;
|
||||
|
||||
if (started || (digit > 0 && digit < 10))
|
||||
{
|
||||
GetScaledPicFrame(pBitmaps->NumCharPicts[digit], scale, &digitRect);
|
||||
ConcatenateRect(pDestRect, &digitRect, pDestRect);
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bitmaps_DrawNumber(const Bitmaps *pBitmaps, const uint32_t number, const uint8_t scale)
|
||||
{
|
||||
bool started;
|
||||
uint32_t k, digit, remainder;
|
||||
|
||||
if (number == 0)
|
||||
{
|
||||
Bitmaps_DrawScaledPic(pBitmaps->NumCharPicts[0], scale);
|
||||
return;
|
||||
}
|
||||
|
||||
started = false;
|
||||
remainder = number;
|
||||
|
||||
for (k = 1000000000UL; k > 0; k = k / 10)
|
||||
{
|
||||
digit = remainder / k;
|
||||
remainder = remainder % k;
|
||||
|
||||
if (started || (digit > 0 && digit < 10))
|
||||
{
|
||||
Bitmaps_DrawScaledPic(pBitmaps->NumCharPicts[digit], scale);
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bitmaps_DrawAChar(const Bitmaps *pBitmaps, const uint8_t scale)
|
||||
{
|
||||
Bitmaps_DrawScaledPic(pBitmaps->ACharPict, scale);
|
||||
}
|
||||
|
||||
void Bitmaps_DrawBChar(const Bitmaps *pBitmaps, const uint8_t scale)
|
||||
{
|
||||
Bitmaps_DrawScaledPic(pBitmaps->BCharPict, scale);
|
||||
}
|
||||
|
||||
void Bitmaps_DrawSlashChar(const Bitmaps *pBitmaps, const uint8_t scale)
|
||||
{
|
||||
Bitmaps_DrawScaledPic(pBitmaps->SlashCharPict, scale);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
#include "MacCommon.h"
|
||||
|
||||
#define NumChars 10
|
||||
|
||||
typedef struct sBitmaps
|
||||
{
|
||||
PicHandle TitlePict;
|
||||
PicHandle NumCharPicts[10];
|
||||
PicHandle NumCharPicts[NumChars];
|
||||
PicHandle ACharPict;
|
||||
PicHandle BCharPict;
|
||||
PicHandle SlashCharPict;
|
||||
|
@ -17,4 +19,11 @@ typedef struct sBitmaps
|
|||
|
||||
void Bitmaps_Init(Bitmaps *pBitmaps);
|
||||
|
||||
void Bitmaps_GetNumberRect(const Bitmaps *pBitmaps, const uint32_t number, const uint8_t scale, Rect *pDestRect);
|
||||
void Bitmaps_DrawNumber(const Bitmaps *pBitmaps, const uint32_t number, const uint8_t scale);
|
||||
|
||||
void Bitmaps_DrawAChar(const Bitmaps *pBitmaps, const uint8_t scale);
|
||||
void Bitmaps_DrawBChar(const Bitmaps *pBitmaps, const uint8_t scale);
|
||||
void Bitmaps_DrawSlashChar(const Bitmaps *pBitmaps, const uint8_t scale);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,11 +3,6 @@
|
|||
|
||||
#include "MacCommon.h"
|
||||
|
||||
int32_t GetThemeID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ShowError(Str255 message, bool isFatal)
|
||||
{
|
||||
ParamText(message, EmptyString, EmptyString, EmptyString);
|
||||
|
@ -37,6 +32,18 @@ void CenterRectV(const Rect *pOuterRect, Rect *pInnerRect)
|
|||
OffsetRect(pInnerRect, 0, (pOuterRect->bottom - pInnerRect->bottom) / 2);
|
||||
}
|
||||
|
||||
void ConcatenateRect(const Rect *pLeftRect, const Rect *pRightRect, Rect *pDestRect)
|
||||
{
|
||||
Rect newRightRect;
|
||||
|
||||
newRightRect.top = pLeftRect->top;
|
||||
newRightRect.left = pLeftRect->right;
|
||||
newRightRect.bottom = newRightRect.top + (pRightRect->bottom - pRightRect->top);
|
||||
newRightRect.right = newRightRect.left + (pRightRect->right - pRightRect->left);
|
||||
|
||||
UnionRect(pLeftRect, &newRightRect, pDestRect);
|
||||
}
|
||||
|
||||
void GetBoxRect(const Rect *pOuterRect, const BoxAlignment boxAlignment, Rect *pBoxRect)
|
||||
{
|
||||
int32_t boxWidth, boxHeight;
|
||||
|
@ -102,3 +109,11 @@ void GetBoxRect(const Rect *pOuterRect, const BoxAlignment boxAlignment, Rect *p
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GetScaledPicFrame(const PicHandle picHandle, const uint8_t scale, Rect *pDestRect)
|
||||
{
|
||||
*pDestRect = (**(picHandle)).picFrame;
|
||||
|
||||
pDestRect->right = pDestRect->left + ((pDestRect->right - pDestRect->left) * max(scale, 1));
|
||||
pDestRect->bottom = pDestRect->top + ((pDestRect->bottom - pDestRect->top) * max(scale, 1));
|
||||
}
|
||||
|
|
|
@ -29,14 +29,16 @@ typedef enum eBoxAlignment
|
|||
|
||||
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 ConcatenateRect(const Rect *pLeftRect, const Rect *pRightRect, Rect *pDestRect);
|
||||
|
||||
void GetBoxRect(const Rect *pOuterRect, const BoxAlignment boxAlignment, Rect *pBoxRect);
|
||||
|
||||
void GetScaledPicFrame(const PicHandle picHandle, const uint8_t scale, Rect *pDestRect);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,18 +15,32 @@
|
|||
#define HUDCornerSize PlayfieldCornerSize
|
||||
#define HUDPattern PlayfieldPattern
|
||||
|
||||
#define LevelTextScale 2
|
||||
|
||||
void PlayScene_Init(GameWindow *pGameWindow)
|
||||
{
|
||||
// Setup rects
|
||||
Rect r1, r2;
|
||||
|
||||
// Setup Playfield
|
||||
pGameWindow->PlayScene.PlayfieldRect.top = PlayfieldMargin;
|
||||
pGameWindow->PlayScene.PlayfieldRect.bottom = pGameWindow->Window->portRect.bottom - PlayfieldMargin;
|
||||
pGameWindow->PlayScene.PlayfieldRect.left = pGameWindow->PlayScene.PlayfieldRect.top;
|
||||
pGameWindow->PlayScene.PlayfieldRect.right = pGameWindow->PlayScene.PlayfieldRect.bottom;
|
||||
|
||||
// Setup HUD
|
||||
pGameWindow->PlayScene.HUDRect.top = HUDMargin;
|
||||
pGameWindow->PlayScene.HUDRect.bottom = pGameWindow->Window->portRect.bottom - HUDMargin;
|
||||
pGameWindow->PlayScene.HUDRect.left = pGameWindow->PlayScene.PlayfieldRect.right + HUDMargin;
|
||||
pGameWindow->PlayScene.HUDRect.right = pGameWindow->Window->portRect.right - HUDMargin;
|
||||
|
||||
// Setup Level
|
||||
GetScaledPicFrame(pGameWindow->Engine.SetB ? pGameWindow->Bitmaps.BCharPict : pGameWindow->Bitmaps.ACharPict, LevelTextScale, &r1);
|
||||
Bitmaps_GetNumberRect(&(pGameWindow->Bitmaps), 1 + pGameWindow->Engine.Level, LevelTextScale, &r2);
|
||||
ConcatenateRect(&r1, &r2, &(pGameWindow->PlayScene.LevelRect));
|
||||
|
||||
GetBoxRect(&(pGameWindow->PlayScene.HUDRect), Top, &r1);
|
||||
GetBoxRect(&r1, Bottom, &r2);
|
||||
CenterRect(&r2, &(pGameWindow->PlayScene.LevelRect));
|
||||
}
|
||||
|
||||
void PlayScene_SetLightRect(const GameWindow *pGameWindow, Rect *pRect, const int8_t c, const int8_t r)
|
||||
|
@ -41,13 +55,12 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
{
|
||||
int8_t r, c;
|
||||
Rect lightRect;
|
||||
Str255 levelStr, parStr, movesStr, halfStarsStr, scoreStr;
|
||||
|
||||
if (fullRefresh)
|
||||
{
|
||||
// Fill backgrounds
|
||||
FillRoundRect(&(pGameWindow->PlayScene.PlayfieldRect), PlayfieldCornerSize, PlayfieldCornerSize, PlayfieldPattern);
|
||||
FillRoundRect(&(pGameWindow->PlayScene.HUDRect), HUDCornerSize, HUDCornerSize, HUDPattern);
|
||||
//FillRoundRect(&(pGameWindow->PlayScene.HUDRect), HUDCornerSize, HUDCornerSize, HUDPattern);
|
||||
}
|
||||
|
||||
// Draw Playfield
|
||||
|
@ -74,43 +87,19 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
|
||||
// Draw HUD
|
||||
|
||||
ForeColor(blackColor);
|
||||
TextFace(bold + outline);
|
||||
|
||||
// Draw Level
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 20);
|
||||
DrawString("\pLevel: ");
|
||||
NumToString(1L + pGameWindow->Engine.Level, &levelStr);
|
||||
DrawString(levelStr);
|
||||
DrawString("\p/50");
|
||||
|
||||
// Draw Par
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 40);
|
||||
DrawString("\pPar: ");
|
||||
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((int32_t)(pGameWindow->Engine.Moves), &movesStr);
|
||||
DrawString(movesStr);
|
||||
DrawString("\p/");
|
||||
DrawString(parStr);
|
||||
MoveTo(pGameWindow->PlayScene.LevelRect.left, pGameWindow->PlayScene.LevelRect.top);
|
||||
if (pGameWindow->Engine.SetB)
|
||||
{
|
||||
Bitmaps_DrawBChar(&(pGameWindow->Bitmaps), LevelTextScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
Bitmaps_DrawAChar(&(pGameWindow->Bitmaps), LevelTextScale);
|
||||
}
|
||||
Bitmaps_DrawNumber(&(pGameWindow->Bitmaps), 1 + pGameWindow->Engine.Level, LevelTextScale);
|
||||
|
||||
// Draw Stars
|
||||
MoveTo(pGameWindow->PlayScene.HUDRect.left + 10, pGameWindow->PlayScene.HUDRect.top + 80);
|
||||
DrawString("\pStars: ");
|
||||
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((int32_t)(pGameWindow->Engine.Score), &scoreStr);
|
||||
DrawString(scoreStr);
|
||||
DrawString("\p/300");
|
||||
}
|
||||
|
||||
void PlayScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
|
|
|
@ -17,12 +17,15 @@ typedef enum eSceneId
|
|||
typedef struct sTitleScene
|
||||
{
|
||||
Rect TitleRect;
|
||||
Rect SetARect;
|
||||
Rect SetBRect;
|
||||
} TitleScene;
|
||||
|
||||
typedef struct sPlayScene
|
||||
{
|
||||
Rect PlayfieldRect;
|
||||
Rect HUDRect;
|
||||
Rect LevelRect;
|
||||
} PlayScene;
|
||||
|
||||
typedef struct sLevelEndScene
|
||||
|
|
|
@ -4,13 +4,25 @@
|
|||
#include "TitleScene.h"
|
||||
#include "Bitmaps.h"
|
||||
|
||||
#define TitleTextScale 2
|
||||
|
||||
void TitleScene_Init(GameWindow *pGameWindow)
|
||||
{
|
||||
Rect r;
|
||||
|
||||
const Rect *pContentRect = &(pGameWindow->Window->portRect);
|
||||
|
||||
// Setup rects
|
||||
pGameWindow->TitleScene.TitleRect = (**(pGameWindow->Bitmaps.TitlePict)).picFrame;
|
||||
GetScaledPicFrame(pGameWindow->Bitmaps.TitlePict, 1, &(pGameWindow->TitleScene.TitleRect));
|
||||
CenterRect(pContentRect, &(pGameWindow->TitleScene.TitleRect));
|
||||
|
||||
GetBoxRect(pContentRect, BottomLeft, &r);
|
||||
GetScaledPicFrame(pGameWindow->Bitmaps.ACharPict, TitleTextScale, &(pGameWindow->TitleScene.SetARect));
|
||||
CenterRect(&r, &(pGameWindow->TitleScene.SetARect));
|
||||
|
||||
GetBoxRect(pContentRect, BottomRight, &r);
|
||||
GetScaledPicFrame(pGameWindow->Bitmaps.BCharPict, TitleTextScale, &(pGameWindow->TitleScene.SetBRect));
|
||||
CenterRect(&r, &(pGameWindow->TitleScene.SetBRect));
|
||||
}
|
||||
|
||||
void TitleScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
|
@ -20,34 +32,28 @@ void TitleScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
|||
{
|
||||
}
|
||||
|
||||
// Draw Title PICT
|
||||
// Draw Title
|
||||
DrawPicture(pGameWindow->Bitmaps.TitlePict, &(pGameWindow->TitleScene.TitleRect));
|
||||
|
||||
TextFace(bold + outline);
|
||||
// Draw Set A
|
||||
MoveTo(pGameWindow->TitleScene.SetARect.left, pGameWindow->TitleScene.SetARect.top);
|
||||
Bitmaps_DrawAChar(&(pGameWindow->Bitmaps), TitleTextScale);
|
||||
|
||||
MoveTo(100, pGameWindow->TitleScene.TitleRect.bottom + 30);
|
||||
DrawString("\pSet A");
|
||||
|
||||
MoveTo(350, pGameWindow->TitleScene.TitleRect.bottom + 30);
|
||||
DrawString("\pSet B");
|
||||
// Draw Set B
|
||||
MoveTo(pGameWindow->TitleScene.SetBRect.left, pGameWindow->TitleScene.SetBRect.top);
|
||||
Bitmaps_DrawBChar(&(pGameWindow->Bitmaps), TitleTextScale);
|
||||
}
|
||||
|
||||
void TitleScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
{
|
||||
bool setB;
|
||||
|
||||
// TODO: Proper click handling
|
||||
|
||||
if (pPosition->h < ((pGameWindow->Window->portRect.right - pGameWindow->Window->portRect.left) / 2))
|
||||
if (PtInRect(*pPosition, &(pGameWindow->TitleScene.SetARect)))
|
||||
{
|
||||
setB = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
setB = true;
|
||||
}
|
||||
|
||||
GameEngine_NewGame(&(pGameWindow->Engine), setB);
|
||||
|
||||
GameEngine_NewGame(&(pGameWindow->Engine), false);
|
||||
GameWindow_SetScene(pGameWindow, Play);
|
||||
}
|
||||
else if (PtInRect(*pPosition, &(pGameWindow->TitleScene.SetBRect)))
|
||||
{
|
||||
GameEngine_NewGame(&(pGameWindow->Engine), true);
|
||||
GameWindow_SetScene(pGameWindow, Play);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user