score counter

This commit is contained in:
2024-03-22 22:49:43 +01:00
parent a32ef8fa5b
commit 85d243551e
5 changed files with 175 additions and 35 deletions

View File

@ -4,47 +4,23 @@
#include "spi.h"
uint16_t score;
void displayInit() {
score = 0;
spiSendBegin(e_SPI_DISPLAY);
// display test off
spiSendOctet(0x0f);
spiSendOctet(0x01);
// BCD decode for all digits
spiSendOctet(0x09);
spiSendOctet(0xff);
// scan limit to digits 0-3
spiSendOctet(0x0b);
spiSendOctet(0x03);
// intensity
spiSendOctet(0x0a);
spiSendOctet(0x0f);
// normal operation
spiSendOctet(0x0C);
spiSendOctet(0x01);
spiSendEnd(e_SPI_DISPLAY);
}
void displaySetValue(uint16_t v) {
union {
uint16_t value;
uint8_t sendBuffer[2];
} value;
void displaySetScore(uint16_t v) {
score = v;
value.value = v;
spiSendBegin(e_SPI_DISPLAY);
spiSendOctet(0x01);
spiSendOctet(0x07);
spiSendOctet(value.sendBuffer[0]);
spiSendOctet(value.sendBuffer[1]);
spiSendEnd(e_SPI_DISPLAY);
}

View File

@ -5,7 +5,7 @@
void displayInit();
void displaySetScore(uint16_t v);
void displaySetValue(uint16_t v);

View File

@ -33,6 +33,7 @@ void gameExec(void *handle) {
static uint8_t rowIndex;
static uint8_t proceedDelay;
static uint8_t level;
static uint16_t score;
// --- engine begin -------------------------------------------------------
switch (state) {
@ -40,6 +41,7 @@ void gameExec(void *handle) {
case e_Start:
canvasClear();
level = 1;
score = 0;
phase = e_Phase_Game;
state = e_NewStone;
break;
@ -112,13 +114,13 @@ void gameExec(void *handle) {
if (phase == e_Phase_Game) {
for (uint8_t r = 0; r < CANVAS_HEIGHT; r++) {
if (canvasIsRowFilled(r)) {
score += level;
displaySetValue(score);
canvasWipeRow(r);
canvasShow();
}
}
}
displaySetScore(7);
}
void gameInit() {