Add some sound to the game.

This commit is contained in:
Jeremy Rand 2016-07-22 17:18:15 -05:00
parent 45688cb6ba
commit 3cd2430203
4 changed files with 50 additions and 13 deletions

View File

@ -11,6 +11,7 @@
#include <conio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "anim.h"
@ -67,6 +68,7 @@ typedef void (*tVblWaitFunction)(void);
// Globals
static tVblWaitFunction gVblWait = vblWait;
static bool gPlaySounds = true;
static tStarAnimState gStarAnimState;
static tClearGemAnimState gClearGemAnimState;
@ -95,6 +97,37 @@ void animInit(void)
}
void toggleSound(void)
{
gPlaySounds = !gPlaySounds;
}
void badThingHappened(void)
{
if (gPlaySounds)
printf("\007");
}
void playSound(int8_t startFreq, int8_t duration)
{
int8_t freq;
if (!gPlaySounds)
return;
while (duration > 0) {
asm ("STA %w", 0xc030);
freq = startFreq;
while (freq > 0) {
freq--;
}
duration--;
}
}
void drawGemAtSquare(tSquare square)
{
switch (gemTypeAtSquare(square)) {
@ -289,6 +322,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(30, 10);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -306,6 +340,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(25, 15);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -323,6 +358,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(20, 20);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -340,6 +376,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(30, 10);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -357,6 +394,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(30, 10);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -374,6 +412,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(30, 10);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -391,6 +430,7 @@ void endClearGemAnim(void)
bit = 1;
offset = 0;
playSound(30, 10);
gVblWait();
for (square = 0; square < NUM_SQUARES; square++) {
if ((gClearGemAnimState.squaresToClear[offset] & bit) != 0) {
@ -600,6 +640,7 @@ void endDropAnim(void)
if (gemInfo->y == gemInfo->endY) {
gemInfo->landed = true;
playSound(1, 1);
continue;
}

View File

@ -38,5 +38,8 @@ extern void dropSquareFromTo(tSquare srcSquare, tSquare tgtSquare, tGemType gemT
extern void dropSquareFromOffscreen(tSquare tgtSquare, tGemType gemType, bool starred);
extern void endDropAnim(void);
extern void toggleSound(void);
extern void badThingHappened(void);
#endif /* defined(__a2bejwld__anim__) */

View File

@ -39,6 +39,7 @@ typedef struct tGameCallbacks {
void (*addClearAtSquare)(tSquare square);
void (*undoClearAtSquare)(tSquare square);
void (*endClearGemAnim)(void);
void (*swapSquares)(tSquare square1, tGemType gemType1, bool starred1,
tSquare square2, tGemType gemType2, bool starred2);

View File

@ -32,7 +32,6 @@ static void refreshLevel(tLevel level);
// Globals
static tSquare gSelectedSquare = 0;
static bool gPlaySounds = true;
static uint8_t gScoreBar = 0;
static tGameCallbacks gCallbacks = {
@ -60,13 +59,6 @@ static void showAndClearDblLoRes(void)
}
static void badThingHappened(void)
{
if (gPlaySounds)
printf("\007");
}
void printInstructions(void)
{
@ -301,9 +293,9 @@ static void endGame(void)
{
mixedTextMode();
videomode(VIDEOMODE_80x24);
cputsxy(0, 20, " No more moves - GAME OVER!!");
cputsxy(0, 20, " No more moves - GAME OVER!!");
gotoxy(0,21);
cprintf( " You made it to level %u", getLevel());
cprintf( " You made it to level %u", getLevel());
cputsxy(0,23, " Play again (Y/N)?");
while (true) {
@ -345,8 +337,8 @@ static void refreshLevel(tLevel level)
mixedTextMode();
videomode(VIDEOMODE_80x24);
gotoxy(0, 20);
cprintf( " Completed level %u!!", level);
cputsxy(0,22, " Press space to continue to the next level...");
cprintf( " Completed level %u!!", level);
cputsxy(0,22, " Press space to continue to the next level...");
while (waiting) {
switch (cgetc()) {
@ -503,7 +495,7 @@ void playGame(void)
case 's':
case 'S':
gPlaySounds = !gPlaySounds;
toggleSound();
break;
case 'h':