6 Commits

Author SHA1 Message Date
ba4248ff24 flash 2024-05-17 16:08:10 +02:00
2cc5a6a4f3 changes 2024-05-05 21:48:20 +02:00
5c86d55458 dark mode 2024-05-05 17:24:29 +02:00
b9e5813223 flash 2024-05-04 12:58:02 +02:00
1b4a93d9e1 types bigger 2024-05-04 11:35:29 +02:00
30d50dcc5e seems to work but some unpleasant delays 2024-05-04 11:31:27 +02:00
3 changed files with 63 additions and 30 deletions

View File

@ -1,3 +1,5 @@
// #define STATE_DEBUGGING
#include "stddef.h" #include "stddef.h"
#include "stdint.h" #include "stdint.h"
@ -12,17 +14,18 @@
#include "buttons.h" #include "buttons.h"
#define GAME_CYCLE_TIME 50 #define GAME_CYCLE_TIME 10
#define GAMEOVER_DELAY 10 #define GAMEOVER_DELAY 10
#define MAX_LEVEL 20 #define MAX_LEVEL 100
static uint8_t delayFactor(uint8_t level) { static uint16_t delayFactor(uint16_t level) {
return MAX_LEVEL + 1 - level; return MAX_LEVEL + 1 - level;
} }
typedef enum { typedef enum {
e_Start, e_NewStone, e_Down, e_DownDelay, e_ClearRows, e_Start, e_NewStone, e_Down, e_DownDelay,
e_ClearRowInit, e_ClearRowNext, e_ClearRowCheck, e_ClearRowFlash, e_ClearRowFlashDelay, e_ClearRowWipe,
e_GameOver, e_GameOverFill, e_GameOverWipe, e_GameOverDelay e_GameOver, e_GameOverFill, e_GameOverWipe, e_GameOverDelay
} state_t; } state_t;
@ -30,14 +33,17 @@ void gameExec(void *handle) {
static state_t state = e_Start; static state_t state = e_Start;
static uint8_t gameOverDelay; static uint8_t gameOverDelay;
static uint8_t rowIndex; static uint8_t rowIndex;
static uint8_t proceedDelay; static uint16_t proceedDelay;
static uint8_t level; static uint16_t level;
static uint16_t filledLines; static uint16_t filledLines;
static uint16_t score; static uint16_t score;
static bool newHighScoreAchieved; static bool newHighScoreAchieved;
bool wipedLines = false; static uint8_t clearCheckCnt;
#ifdef STATE_DEBUGGING
displaySetValue(state);
#endif
// --- engine begin ------------------------------------------------------- // --- engine begin -------------------------------------------------------
switch (state) { switch (state) {
// --- phase: game -------------------------------------------------------- // --- phase: game --------------------------------------------------------
@ -64,7 +70,6 @@ void gameExec(void *handle) {
case e_DownDelay: case e_DownDelay:
proceedDelay--; proceedDelay--;
if (proceedDelay == 0) { if (proceedDelay == 0) {
rowIndex = 0;
state = e_Down; state = e_Down;
} }
break; break;
@ -73,42 +78,63 @@ void gameExec(void *handle) {
if (! stoneMoveDown()) { if (! stoneMoveDown()) {
soundCtrl(SOUND_LOCK); soundCtrl(SOUND_LOCK);
stoneLock(); stoneLock();
state = e_ClearRows; state = e_ClearRowInit;
} else { } else {
proceedDelay = delayFactor(level); proceedDelay = delayFactor(level);
state = e_DownDelay; state = e_DownDelay;
} }
break; break;
case e_ClearRows: // --- phase: clear rows --------------------------------------------------
// clear filled lines case e_ClearRowInit:
for (uint8_t r = 0; r < CANVAS_HEIGHT; r++) { clearCheckCnt = 0;
if (canvasIsRowFilled(r)) { state = e_ClearRowCheck;
score += level; break;
if (score > eepromReadHighScore()) {
newHighScoreAchieved = true; case e_ClearRowNext:
eepromWriteHighScore(score); if (clearCheckCnt >= CANVAS_HEIGHT) {
} state = e_NewStone;
displaySetValue(score); } else {
canvasWipeRow(r); clearCheckCnt += 1;
canvasShow(); state = e_ClearRowCheck;
wipedLines = true; }
filledLines += 1; break;
case e_ClearRowCheck:
if (canvasIsRowFilled(clearCheckCnt)) {
score += level;
if (score > eepromReadHighScore()) {
newHighScoreAchieved = true;
eepromWriteHighScore(score);
} }
state = e_ClearRowFlash;
} else {
state = e_ClearRowNext;
} }
break;
if (wipedLines) { case e_ClearRowFlash:
soundCtrl(SOUND_PLING); canvasFillRow(clearCheckCnt, _flash);
} state = e_ClearRowFlashDelay;
break;
if (wipedLines && (filledLines > 0) && ((filledLines % 10) == 0)) { case e_ClearRowFlashDelay:
state = e_ClearRowWipe;
break;
case e_ClearRowWipe:
canvasWipeRow(clearCheckCnt);
filledLines += 1;
if ((filledLines > 0) && ((filledLines % 10) == 0)) {
if (level < MAX_LEVEL) { if (level < MAX_LEVEL) {
level += 1; level += 1;
} }
soundCtrl(SOUND_FANFARE); soundCtrl(SOUND_FANFARE);
} else {
soundCtrl(SOUND_PLING);
} }
state = e_ClearRowNext;
state = e_NewStone;
break; break;
// --- phase: game over --------------------------------------------------- // --- phase: game over ---------------------------------------------------
@ -146,11 +172,13 @@ void gameExec(void *handle) {
canvasShow(); canvasShow();
#ifndef STATE_DEBUGGING
if (isGameActive()) { if (isGameActive()) {
displaySetValue(score); displaySetValue(score);
} else { } else {
displaySetValue(eepromReadHighScore()); displaySetValue(eepromReadHighScore());
} }
#endif
} }
void gameInit() { void gameInit() {

View File

@ -1,6 +1,6 @@
#include "colors.h" #include "colors.h"
#define DIMM_FACTOR 3 #define DIMM_FACTOR 5
.section ".rodata","a" .section ".rodata","a"
;; color definitions according to ;; color definitions according to
;; https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide/3-custom-color-mixing ;; https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide/3-custom-color-mixing
@ -35,4 +35,8 @@ white:
.byte 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0 .byte 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
red: red:
.byte 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0 .byte 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0
flash:
.byte 0xff, 0xff, 0xff, 0
;; .byte 0x00, 0x00, 0x00, 0
;; .byte 0x80>>3, 0x00>>3, 0xff>>3, 0

View File

@ -16,6 +16,7 @@
#define _yellow 0x0b #define _yellow 0x0b
#define _white 0x0c #define _white 0x0c
#define _red 0x0d #define _red 0x0d
#define _flash 0x0e