Added sounds!
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 74 B After Width: | Height: | Size: 74 B |
Before Width: | Height: | Size: 80 B After Width: | Height: | Size: 80 B |
Before Width: | Height: | Size: 81 B After Width: | Height: | Size: 81 B |
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 81 B After Width: | Height: | Size: 81 B |
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 78 B After Width: | Height: | Size: 78 B |
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 83 B |
Before Width: | Height: | Size: 82 B After Width: | Height: | Size: 82 B |
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
Before Width: | Height: | Size: 85 B After Width: | Height: | Size: 85 B |
BIN
assets/click.wav
Normal file
BIN
assets/done.wav
Normal file
Before Width: | Height: | Size: 86 B After Width: | Height: | Size: 86 B |
Before Width: | Height: | Size: 82 B After Width: | Height: | Size: 82 B |
BIN
assets/retry.wav
Normal file
Before Width: | Height: | Size: 73 B After Width: | Height: | Size: 73 B |
Before Width: | Height: | Size: 62 B After Width: | Height: | Size: 62 B |
Before Width: | Height: | Size: 64 B After Width: | Height: | Size: 64 B |
Before Width: | Height: | Size: 71 B After Width: | Height: | Size: 71 B |
Before Width: | Height: | Size: 74 B After Width: | Height: | Size: 74 B |
Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 68 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -11,6 +11,8 @@
|
||||
#define StarPictBaseResID (SlashCharPictResID + 1)
|
||||
#define NextButtonPictResID (StarPictBaseResID + StarPictCount)
|
||||
#define RetryButtonPictResID (NextButtonPictResID + 1)
|
||||
#define SoundOffPictResID (RetryButtonPictResID + 1)
|
||||
#define SoundOnPictResID (SoundOffPictResID + 1)
|
||||
|
||||
#define StarRectPadding 2
|
||||
|
||||
@ -66,7 +68,7 @@ void Bitmaps_Init(Bitmaps *pBitmaps)
|
||||
}
|
||||
}
|
||||
|
||||
// Load next button
|
||||
// Load slash char
|
||||
pBitmaps->SlashCharPict = GetPicture(SlashCharPictResID);
|
||||
if (pBitmaps->SlashCharPict == nil)
|
||||
{
|
||||
@ -86,6 +88,20 @@ void Bitmaps_Init(Bitmaps *pBitmaps)
|
||||
{
|
||||
ShowError("\pRetry button PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Load sound off
|
||||
pBitmaps->SoundOffPict = GetPicture(SoundOffPictResID);
|
||||
if (pBitmaps->SoundOffPict == nil)
|
||||
{
|
||||
ShowError("\pSound off PICT resource missing!", true);
|
||||
}
|
||||
|
||||
// Load sound on
|
||||
pBitmaps->SoundOnPict = GetPicture(SoundOnPictResID);
|
||||
if (pBitmaps->SoundOnPict == nil)
|
||||
{
|
||||
ShowError("\pSound on PICT resource missing!", true);
|
||||
}
|
||||
}
|
||||
|
||||
void Bitmaps_GetNumberRect(const Bitmaps *pBitmaps, const uint32_t number, const uint8_t scale, Rect *pDestRect)
|
||||
@ -216,6 +232,35 @@ void Bitmaps_DrawHalfStars(const Bitmaps *pBitmaps, const uint8_t halfStars, con
|
||||
for (; drawn < maxStars; drawn++)
|
||||
{
|
||||
DrawScaledPic(pBitmaps->StarPicts[0], scale);
|
||||
GetPen(&penPosition);
|
||||
MoveTo(penPosition.h + (StarRectPadding * scale), penPosition.v);
|
||||
}
|
||||
}
|
||||
|
||||
void Bitmaps_GetSoundRect(const Bitmaps *pBitmaps, const bool enabled, const uint8_t scale, Rect *pDestRect)
|
||||
{
|
||||
Rect r;
|
||||
|
||||
GetScaledPicFrame(pBitmaps->SoundOffPict, scale, pDestRect);
|
||||
GetScaledPicFrame(pBitmaps->SoundOnPict, scale, &r);
|
||||
ConcatenateRect(pDestRect, &r, pDestRect);
|
||||
}
|
||||
|
||||
void Bitmaps_DrawSound(const Bitmaps *pBitmaps, const bool enabled, const uint8_t scale)
|
||||
{
|
||||
Point penPosition;
|
||||
Rect r;
|
||||
|
||||
DrawScaledPic(pBitmaps->SoundOffPict, scale);
|
||||
if (enabled)
|
||||
{
|
||||
DrawScaledPic(pBitmaps->SoundOnPict, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetScaledPicFrame(pBitmaps->SoundOnPict, scale, &r);
|
||||
GetPen(&penPosition);
|
||||
OffsetRect(&r, penPosition.h, penPosition.v);
|
||||
FillRect(&r, black);
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,7 @@ void Bitmaps_DrawSlashChar(const Bitmaps *pBitmaps, const uint8_t scale);
|
||||
void Bitmaps_GetHalfStarsRect(const Bitmaps *pBitmaps, const uint8_t halfStars, const uint8_t maxStars, const uint8_t scale, Rect *pDestRect);
|
||||
void Bitmaps_DrawHalfStars(const Bitmaps *pBitmaps, const uint8_t halfStars, const uint8_t maxStars, const uint8_t scale);
|
||||
|
||||
void Bitmaps_GetSoundRect(const Bitmaps *pBitmaps, const bool enabled, const uint8_t scale, Rect *pDestRect);
|
||||
void Bitmaps_DrawSound(const Bitmaps *pBitmaps, const bool enabled, const uint8_t scale);
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,9 @@ void GameEndScene_Init(GameWindow *pGameWindow)
|
||||
GetBoxRect(pContentRect, Bottom, &r);
|
||||
GetBoxRect(&r, Top, &r);
|
||||
CenterRect(&r, &(pGameWindow->GameEndScene.ScoreRect));
|
||||
|
||||
// Play done sound
|
||||
Sounds_PlayDoneSnd(&(pGameWindow->Sounds));
|
||||
}
|
||||
|
||||
void GameEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
|
@ -24,6 +24,9 @@ void GameWindow_Init(GameWindow *pGameWindow)
|
||||
// Load PICT resources
|
||||
Bitmaps_Init(&(pGameWindow->Bitmaps));
|
||||
|
||||
// Load snd resources
|
||||
Sounds_Init(&(pGameWindow->Sounds));
|
||||
|
||||
GameWindow_SetScene(pGameWindow, Title);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "MacCommon.h"
|
||||
#include "GameEngine.h"
|
||||
#include "Bitmaps.h"
|
||||
#include "Sounds.h"
|
||||
#include "Scenes.h"
|
||||
|
||||
#define WindowPattern black
|
||||
@ -16,6 +17,7 @@ typedef struct sGameWindow
|
||||
WindowPtr Window;
|
||||
GameEngine Engine;
|
||||
Bitmaps Bitmaps;
|
||||
Sounds Sounds;
|
||||
SceneId CurrentSceneId;
|
||||
TitleScene TitleScene;
|
||||
PlayScene PlayScene;
|
||||
|
@ -48,6 +48,9 @@ void LevelEndScene_Init(GameWindow *pGameWindow)
|
||||
|
||||
GetBoxRect(pContentRect, BottomRight, &r);
|
||||
CenterRect(&r, &(pGameWindow->LevelEndScene.NextButtonRect));
|
||||
|
||||
// Play done sound
|
||||
Sounds_PlayDoneSnd(&(pGameWindow->Sounds));
|
||||
}
|
||||
|
||||
void LevelEndScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
@ -85,11 +88,13 @@ void LevelEndScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
{
|
||||
if (PtInRect(*pPosition, &(pGameWindow->LevelEndScene.RetryButtonRect)))
|
||||
{
|
||||
Sounds_PlayRetrySnd(&(pGameWindow->Sounds));
|
||||
GameEngine_ResetLevel(&(pGameWindow->Engine));
|
||||
GameWindow_SetScene(pGameWindow, Play);
|
||||
}
|
||||
else if (PtInRect(*pPosition, &(pGameWindow->LevelEndScene.NextButtonRect)))
|
||||
{
|
||||
Sounds_PlayClickSnd(&(pGameWindow->Sounds));
|
||||
GameEngine_NextLevel(&(pGameWindow->Engine));
|
||||
GameWindow_SetScene(pGameWindow, GameEngine_IsGameOver(&(pGameWindow->Engine)) ? GameEnd : Play);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ void MacLO_HandleAppleMenuChoice(const int16_t item)
|
||||
void MacLO_ShowAboutDialog()
|
||||
{
|
||||
DialogPtr dialog;
|
||||
int itemHit;
|
||||
int32_t itemHit;
|
||||
|
||||
dialog = GetNewDialog(AboutDialogResID, nil, MoveToFront);
|
||||
|
||||
@ -222,7 +222,6 @@ void MacLO_LaunchAppleMenuItem(const int16_t item)
|
||||
appleMenu = GetMHandle(AppleMenuResID);
|
||||
GetItem(appleMenu, item, accName);
|
||||
OpenDeskAcc(accName);
|
||||
|
||||
}
|
||||
|
||||
void MacLO_HandleGameMenuChoice(const int16_t item)
|
||||
|
BIN
src/MacLO.pi.bin
@ -9,11 +9,9 @@
|
||||
#define LightMargin 6
|
||||
#define LightSize 50
|
||||
#define LightCornerSize 12
|
||||
#define PlayfieldPattern ltGray
|
||||
|
||||
#define HUDMargin PlayfieldMargin
|
||||
#define HUDCornerSize PlayfieldCornerSize
|
||||
#define HUDPattern PlayfieldPattern
|
||||
|
||||
#define LevelTextScale 3
|
||||
#define HalfStarScale 2
|
||||
@ -66,6 +64,11 @@ void PlayScene_Init(GameWindow *pGameWindow)
|
||||
|
||||
GetBoxRect(&(pGameWindow->PlayScene.HUDRect), BottomLeft, &r);
|
||||
CenterRect(&r, &(pGameWindow->PlayScene.RetryButtonRect));
|
||||
|
||||
// Setup sound button
|
||||
Bitmaps_GetSoundRect(&(pGameWindow->Bitmaps), pGameWindow->Sounds.Enabled, 1, &(pGameWindow->PlayScene.SoundButtonRect));
|
||||
GetBoxRect(&(pGameWindow->PlayScene.HUDRect), BottomRight, &r);
|
||||
CenterRect(&r, &(pGameWindow->PlayScene.SoundButtonRect));
|
||||
}
|
||||
|
||||
void PlayScene_SetLightRect(const GameWindow *pGameWindow, Rect *pRect, const int8_t c, const int8_t r)
|
||||
@ -86,7 +89,6 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
// Fill backgrounds
|
||||
ForeColor(whiteColor);
|
||||
FrameRoundRect(&(pGameWindow->PlayScene.PlayfieldRect), PlayfieldCornerSize, PlayfieldCornerSize);
|
||||
FrameRoundRect(&(pGameWindow->PlayScene.HUDRect), HUDCornerSize, HUDCornerSize);
|
||||
ForeColor(blackColor);
|
||||
}
|
||||
|
||||
@ -138,6 +140,11 @@ void PlayScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
|
||||
// Draw retry button
|
||||
DrawPicture(pGameWindow->Bitmaps.RetryButtonPict, &(pGameWindow->PlayScene.RetryButtonRect));
|
||||
|
||||
// Draw sound button
|
||||
MoveTo(pGameWindow->PlayScene.SoundButtonRect.left, pGameWindow->PlayScene.SoundButtonRect.top);
|
||||
Bitmaps_DrawSound(&(pGameWindow->Bitmaps), pGameWindow->Sounds.Enabled, 1);
|
||||
|
||||
}
|
||||
|
||||
void PlayScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
@ -156,6 +163,7 @@ void PlayScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
|
||||
if (PtInRect(*pPosition, &lightRect))
|
||||
{
|
||||
Sounds_PlayClickSnd(&(pGameWindow->Sounds));
|
||||
GameEngine_ToggleLights(&(pGameWindow->Engine), c, r);
|
||||
GameWindow_Draw(pGameWindow, false);
|
||||
break;
|
||||
@ -176,8 +184,14 @@ void PlayScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
|
||||
if (PtInRect(*pPosition, &(pGameWindow->PlayScene.RetryButtonRect)))
|
||||
{
|
||||
Sounds_PlayRetrySnd(&(pGameWindow->Sounds));
|
||||
GameEngine_ResetLevel(&(pGameWindow->Engine));
|
||||
GameWindow_Draw(pGameWindow, false);
|
||||
}
|
||||
else if (PtInRect(*pPosition, &(pGameWindow->PlayScene.SoundButtonRect)))
|
||||
{
|
||||
pGameWindow->Sounds.Enabled = !pGameWindow->Sounds.Enabled;
|
||||
GameWindow_Draw(pGameWindow, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ typedef struct sTitleScene
|
||||
Rect TitleRect;
|
||||
Rect SetARect;
|
||||
Rect SetBRect;
|
||||
Rect SoundButtonRect;
|
||||
} TitleScene;
|
||||
|
||||
typedef struct sPlayScene
|
||||
@ -29,6 +30,7 @@ typedef struct sPlayScene
|
||||
Rect HalfStarsRect;
|
||||
Rect ScoreRect;
|
||||
Rect RetryButtonRect;
|
||||
Rect SoundButtonRect;
|
||||
} PlayScene;
|
||||
|
||||
typedef struct sLevelEndScene
|
||||
|
60
src/Sounds.c
Normal file
@ -0,0 +1,60 @@
|
||||
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "Sounds.h"
|
||||
|
||||
#define ClickSndResID BaseResID
|
||||
#define RetrySndResID (ClickSndResID + 1)
|
||||
#define DoneSndResID (RetrySndResID + 1)
|
||||
|
||||
#define DefaultEnabled true
|
||||
#define PlaySoundsAsync true
|
||||
|
||||
void Sounds_Init(Sounds *pSounds)
|
||||
{
|
||||
pSounds->Enabled = DefaultEnabled;
|
||||
|
||||
SndNewChannel(&(pSounds->SndChannel), 0, 0, nil);
|
||||
|
||||
pSounds->ClickSnd = GetResource('snd ', ClickSndResID);
|
||||
if (pSounds->ClickSnd == nil)
|
||||
{
|
||||
ShowError("\pClick snd resource missing!", true);
|
||||
}
|
||||
|
||||
pSounds->RetrySnd = GetResource('snd ', RetrySndResID);
|
||||
if (pSounds->RetrySnd == nil)
|
||||
{
|
||||
ShowError("\pRetry snd resource missing!", true);
|
||||
}
|
||||
|
||||
pSounds->DoneSnd = GetResource('snd ', DoneSndResID);
|
||||
if (pSounds->DoneSnd == nil)
|
||||
{
|
||||
ShowError("\pDone snd resource missing!", true);
|
||||
}
|
||||
}
|
||||
|
||||
void Sounds_PlayClickSnd(const Sounds *pSounds)
|
||||
{
|
||||
if (pSounds->Enabled)
|
||||
{
|
||||
SndPlay(pSounds->SndChannel, pSounds->ClickSnd, PlaySoundsAsync);
|
||||
}
|
||||
}
|
||||
|
||||
void Sounds_PlayRetrySnd(const Sounds *pSounds)
|
||||
{
|
||||
if (pSounds->Enabled)
|
||||
{
|
||||
SndPlay(pSounds->SndChannel, pSounds->RetrySnd, PlaySoundsAsync);
|
||||
}
|
||||
}
|
||||
|
||||
void Sounds_PlayDoneSnd(const Sounds *pSounds)
|
||||
{
|
||||
if (pSounds->Enabled)
|
||||
{
|
||||
SndPlay(pSounds->SndChannel, pSounds->DoneSnd, PlaySoundsAsync);
|
||||
}
|
||||
}
|
26
src/Sounds.h
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef SOUNDS_H
|
||||
#define SOUNDS_H
|
||||
|
||||
#include <Sound.h>
|
||||
|
||||
#include "MacCommon.h"
|
||||
|
||||
typedef struct sSounds
|
||||
{
|
||||
bool Enabled;
|
||||
SndChannelPtr SndChannel;
|
||||
Handle ClickSnd;
|
||||
Handle RetrySnd;
|
||||
Handle DoneSnd;
|
||||
} Sounds;
|
||||
|
||||
void Sounds_Init(Sounds *pSounds);
|
||||
|
||||
void Sounds_PlayClickSnd(const Sounds *pSounds);
|
||||
void Sounds_PlayRetrySnd(const Sounds *pSounds);
|
||||
void Sounds_PlayDoneSnd(const Sounds *pSounds);
|
||||
|
||||
#endif
|
@ -12,17 +12,24 @@ void TitleScene_Init(GameWindow *pGameWindow)
|
||||
|
||||
const Rect *pContentRect = &(pGameWindow->Window->portRect);
|
||||
|
||||
// Setup rects
|
||||
// Setup Title
|
||||
GetPictureRect(pGameWindow->Bitmaps.TitlePict, &(pGameWindow->TitleScene.TitleRect));
|
||||
CenterRect(pContentRect, &(pGameWindow->TitleScene.TitleRect));
|
||||
|
||||
GetBoxRect(pContentRect, BottomLeft, &r);
|
||||
// Setup Set A
|
||||
GetScaledPicFrame(pGameWindow->Bitmaps.ACharPict, TitleTextScale, &(pGameWindow->TitleScene.SetARect));
|
||||
GetBoxRect(pContentRect, BottomLeft, &r);
|
||||
CenterRect(&r, &(pGameWindow->TitleScene.SetARect));
|
||||
|
||||
GetBoxRect(pContentRect, BottomRight, &r);
|
||||
// Setup Set B
|
||||
GetScaledPicFrame(pGameWindow->Bitmaps.BCharPict, TitleTextScale, &(pGameWindow->TitleScene.SetBRect));
|
||||
GetBoxRect(pContentRect, BottomRight, &r);
|
||||
CenterRect(&r, &(pGameWindow->TitleScene.SetBRect));
|
||||
|
||||
// Setup sound button
|
||||
Bitmaps_GetSoundRect(&(pGameWindow->Bitmaps), pGameWindow->Sounds.Enabled, TitleTextScale, &(pGameWindow->TitleScene.SoundButtonRect));
|
||||
GetBoxRect(pContentRect, Bottom, &r);
|
||||
CenterRect(&r, &(pGameWindow->TitleScene.SoundButtonRect));
|
||||
}
|
||||
|
||||
void TitleScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
@ -37,18 +44,29 @@ void TitleScene_Draw(const GameWindow *pGameWindow, bool fullRefresh)
|
||||
// Draw Set B
|
||||
MoveTo(pGameWindow->TitleScene.SetBRect.left, pGameWindow->TitleScene.SetBRect.top);
|
||||
Bitmaps_DrawBChar(&(pGameWindow->Bitmaps), TitleTextScale);
|
||||
|
||||
// Draw sound button
|
||||
MoveTo(pGameWindow->TitleScene.SoundButtonRect.left, pGameWindow->TitleScene.SoundButtonRect.top);
|
||||
Bitmaps_DrawSound(&(pGameWindow->Bitmaps), pGameWindow->Sounds.Enabled, TitleTextScale);
|
||||
}
|
||||
|
||||
void TitleScene_Click(GameWindow *pGameWindow, const Point *pPosition)
|
||||
{
|
||||
if (PtInRect(*pPosition, &(pGameWindow->TitleScene.SetARect)))
|
||||
{
|
||||
Sounds_PlayClickSnd(&(pGameWindow->Sounds));
|
||||
GameEngine_NewGame(&(pGameWindow->Engine), false);
|
||||
GameWindow_SetScene(pGameWindow, Play);
|
||||
}
|
||||
else if (PtInRect(*pPosition, &(pGameWindow->TitleScene.SetBRect)))
|
||||
{
|
||||
Sounds_PlayClickSnd(&(pGameWindow->Sounds));
|
||||
GameEngine_NewGame(&(pGameWindow->Engine), true);
|
||||
GameWindow_SetScene(pGameWindow, Play);
|
||||
}
|
||||
else if (PtInRect(*pPosition, &(pGameWindow->TitleScene.SoundButtonRect)))
|
||||
{
|
||||
pGameWindow->Sounds.Enabled = !pGameWindow->Sounds.Enabled;
|
||||
GameWindow_Draw(pGameWindow, false);
|
||||
}
|
||||
}
|
||||
|