sound works
This commit is contained in:
@ -49,7 +49,7 @@ static uint8_t buttonsMoveDownPressed() {
|
||||
void buttonsExec(void *handle) {
|
||||
static uint32_t unmuteTimestamp;
|
||||
uint32_t currentTimestamp = getSeconds();
|
||||
static bool unmuteFlag = false;
|
||||
static bool unmuteFlag = true;
|
||||
|
||||
|
||||
if (! stoneIsValid()) {
|
||||
@ -61,27 +61,27 @@ void buttonsExec(void *handle) {
|
||||
|
||||
if (buttonsMoveLeftPressed()) {
|
||||
stoneMoveLeft();
|
||||
soundCtrl(e_SOUND_STONE_MOVE_LEFT);
|
||||
soundCtrl(SOUND_MOTION);
|
||||
buttonPressed = 1;
|
||||
}
|
||||
if (buttonsMoveRightPressed()) {
|
||||
stoneMoveRight();
|
||||
soundCtrl(e_SOUND_STONE_MOVE_RIGHT);
|
||||
soundCtrl(SOUND_MOTION);
|
||||
buttonPressed = 1;
|
||||
}
|
||||
if (buttonsRotateLeftPressed()) {
|
||||
stoneRotateLeft();
|
||||
soundCtrl(e_SOUND_STONE_ROTATE_LEFT);
|
||||
soundCtrl(SOUND_MOTION);
|
||||
buttonPressed = 1;
|
||||
}
|
||||
if (buttonsRotateRightPressed()) {
|
||||
stoneRotateRight();
|
||||
soundCtrl(e_SOUND_STONE_ROTATE_RIGHT);
|
||||
soundCtrl(SOUND_MOTION);
|
||||
buttonPressed = 1;
|
||||
}
|
||||
if (buttonsMoveDownPressed()) {
|
||||
stoneMoveDown();
|
||||
soundCtrl(e_SOUND_STONE_MOVE_DOWN);
|
||||
soundCtrl(SOUND_MOTION);
|
||||
buttonPressed = 1;
|
||||
}
|
||||
|
||||
@ -89,14 +89,14 @@ void buttonsExec(void *handle) {
|
||||
canvasShow();
|
||||
|
||||
if (! unmuteFlag) {
|
||||
soundCtrl(e_SOUND_UNMUTE);
|
||||
soundCtrl(SOUND_UNMUTE);
|
||||
unmuteFlag = true;
|
||||
}
|
||||
unmuteTimestamp = currentTimestamp;
|
||||
}
|
||||
|
||||
if (unmuteFlag && (unmuteTimestamp + MUTE_DELAY < currentTimestamp)) {
|
||||
soundCtrl(e_SOUND_MUTE);
|
||||
soundCtrl(SOUND_MUTE);
|
||||
unmuteFlag = false;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void gameExec(void *handle) {
|
||||
// --- phase: game --------------------------------------------------------
|
||||
case e_Start:
|
||||
canvasClear();
|
||||
soundCtrl(e_SOUND_START_BACKGROUND);
|
||||
soundCtrl(SOUND_START);
|
||||
level = 1;
|
||||
score = 0;
|
||||
displaySetValue(score);
|
||||
@ -73,7 +73,7 @@ void gameExec(void *handle) {
|
||||
|
||||
case e_Down:
|
||||
if (! stoneMoveDown()) {
|
||||
soundCtrl(e_SOUND_STONE_LOCKED);
|
||||
soundCtrl(SOUND_LOCK);
|
||||
state = e_NewStone;
|
||||
} else {
|
||||
proceedDelay = delayFactor(level);
|
||||
@ -83,8 +83,7 @@ void gameExec(void *handle) {
|
||||
|
||||
// --- phase: game over ---------------------------------------------------
|
||||
case e_GameOver:
|
||||
soundCtrl(e_SOUND_STOP_BACKGROUND);
|
||||
soundCtrl(e_SOUND_START_GAMEOVER);
|
||||
soundCtrl(SOUND_GAMEOVER);
|
||||
rowIndex = CANVAS_HEIGHT;
|
||||
phase = e_Phase_GameOver;
|
||||
state = e_GameOverFill;
|
||||
@ -110,7 +109,6 @@ void gameExec(void *handle) {
|
||||
case e_GameOverDelay:
|
||||
gameOverDelay--;
|
||||
if (gameOverDelay == 0) {
|
||||
soundCtrl(e_SOUND_STOP_GAMEOVER);
|
||||
state = e_Start;
|
||||
}
|
||||
break;
|
||||
@ -129,10 +127,13 @@ void gameExec(void *handle) {
|
||||
wipeCnt += 1;
|
||||
}
|
||||
}
|
||||
soundCtrl(e_SOUND_FANFARE_BASE + wipeCnt);
|
||||
if (wipeCnt != 0) {
|
||||
soundCtrl(SOUND_FANFARE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gameInit() {
|
||||
schAdd(gameExec, NULL, 0, GAME_CYCLE_TIME);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <stdint.h>
|
||||
#include "sound.h"
|
||||
#include "spi.h"
|
||||
|
||||
@ -7,10 +8,10 @@ void soundInit() {
|
||||
}
|
||||
|
||||
|
||||
void soundCtrl(t_SoundCmd cmd) {
|
||||
void soundCtrl(uint8_t cmd) {
|
||||
spiSendBegin(e_SPI_SOUND);
|
||||
|
||||
spiSendOctet((uint8_t)cmd);
|
||||
spiSendOctet(cmd);
|
||||
|
||||
spiSendEnd(e_SPI_SOUND);
|
||||
}
|
||||
|
@ -1,32 +1,14 @@
|
||||
#ifndef _SOUND_H_
|
||||
#define _SOUND_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MUTE_DELAY 30 // seconds
|
||||
|
||||
typedef enum {
|
||||
e_SOUND_IDLE = 0,
|
||||
e_SOUND_MUTE = 1,
|
||||
e_SOUND_UNMUTE,
|
||||
e_SOUND_START_BACKGROUND,
|
||||
e_SOUND_STOP_BACKGROUND,
|
||||
e_SOUND_START_GAMEOVER,
|
||||
e_SOUND_STOP_GAMEOVER,
|
||||
e_SOUND_SPEED_UP,
|
||||
e_SOUND_FANFARE_BASE,
|
||||
e_SOUND_FANFARE_1,
|
||||
e_SOUND_FANFARE_2,
|
||||
e_SOUND_FANFARE_3,
|
||||
e_SOUND_FANFARE_4,
|
||||
e_SOUND_STONE_LOCKED,
|
||||
e_SOUND_STONE_MOVE_LEFT,
|
||||
e_SOUND_STONE_MOVE_RIGHT,
|
||||
e_SOUND_STONE_ROTATE_LEFT,
|
||||
e_SOUND_STONE_ROTATE_RIGHT,
|
||||
e_SOUND_STONE_MOVE_DOWN,
|
||||
} t_SoundCmd;
|
||||
#include "../sound-driver/soundCodes.h"
|
||||
|
||||
void soundInit();
|
||||
void soundCtrl(t_SoundCmd cmd);
|
||||
void soundCtrl(uint8_t cmd);
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user