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

View File

@ -1,6 +1,6 @@
#include "colors.h"
#define DIMM_FACTOR 3
#define DIMM_FACTOR 5
.section ".rodata","a"
;; color definitions according to
;; 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
red:
.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 _white 0x0c
#define _red 0x0d
#define _flash 0x0e