minor cleanups and some whitespace fun
This commit is contained in:
parent
187765a1ef
commit
9341dad54a
|
@ -1,85 +1,109 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <inttypes.h>
|
||||||
#include <inttypes.h>
|
#include "../../config.h"
|
||||||
#include "../../config.h"
|
#include "../../scrolltext/scrolltext.h"
|
||||||
#include "../../scrolltext/scrolltext.h"
|
#include "../../joystick/joystick.h"
|
||||||
#include "../../joystick/joystick.h"
|
#include "highscore.h"
|
||||||
#include "highscore.h"
|
|
||||||
|
|
||||||
/* Function: tetris_highscore_inputName
|
/* Function: tetris_highscore_inputName
|
||||||
* Description: let user input a three character name
|
* Description: let user input a three character name
|
||||||
* Return value: name packed into a uint16_t
|
* Return value: name packed into a uint16_t
|
||||||
*/
|
*/
|
||||||
uint16_t tetris_highscore_inputName(void)
|
uint16_t tetris_highscore_inputName(void)
|
||||||
{
|
{
|
||||||
char nick[4], tmp[40];
|
char pszNick[4], pszTmp[40];
|
||||||
uint8_t xpos;
|
uint8_t nOffset;
|
||||||
uint8_t pos=0, blink=0, done=0, hadfire=0;
|
uint8_t nPos = 0, nBlink = 0, nDone = 0, nHadfire = 0;
|
||||||
|
|
||||||
sprintf(nick, "AAA");
|
sprintf(pszNick, "AAA");
|
||||||
while(!done)
|
while (!nDone)
|
||||||
{
|
{
|
||||||
|
// we need our own blink interval
|
||||||
// We need to do our own blink interval
|
nBlink = (nBlink + 1) % 4;
|
||||||
blink = (blink+1) % 4;
|
|
||||||
|
// determine start position on screen depending on active character
|
||||||
// Determine start position on screen
|
switch (nPos)
|
||||||
// depending on active character
|
{
|
||||||
switch (pos)
|
case 0:
|
||||||
{
|
nOffset = 15;
|
||||||
case 0: xpos = 15; break;
|
break;
|
||||||
case 1: xpos = 19; break;
|
case 1:
|
||||||
case 2: xpos = 23; break;
|
nOffset = 19;
|
||||||
}
|
break;
|
||||||
|
case 2:
|
||||||
// Construct command for scrolltext and execute
|
nOffset = 23;
|
||||||
sprintf(tmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c",
|
break;
|
||||||
xpos, (!blink && pos == 0) ? ' ' : nick[0],
|
}
|
||||||
xpos-8, (!blink && pos == 1 ) ? ' ' : nick[1],
|
|
||||||
xpos-15, (!blink && pos == 2 ) ? ' ' : nick[2]);
|
// construct command for scrolltext and execute
|
||||||
scrolltext(tmp);
|
sprintf(pszTmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c", nOffset,
|
||||||
|
(!nBlink && nPos == 0) ? ' ' : pszNick[0], nOffset - 8,
|
||||||
|
(!nBlink && nPos == 1) ? ' ' : pszNick[1], nOffset - 15,
|
||||||
// up and down control current char
|
(!nBlink && nPos == 2) ? ' ' : pszNick[2]);
|
||||||
if (JOYISUP)
|
scrolltext(pszTmp);
|
||||||
{
|
|
||||||
nick[pos]++;
|
// up and down control current char
|
||||||
if (nick[pos] == '`') nick[pos] = 'A';
|
if (JOYISUP)
|
||||||
if (nick[pos] == '[') nick[pos] = '_';
|
{
|
||||||
}
|
pszNick[nPos]++;
|
||||||
if (JOYISDOWN)
|
if (pszNick[nPos] == '`')
|
||||||
{
|
{
|
||||||
nick[pos]--;
|
pszNick[nPos] = 'A';
|
||||||
if (nick[pos] == '@') nick[pos] = '_';
|
}
|
||||||
if (nick[pos] == '^') nick[pos] = 'Z';
|
if (pszNick[nPos] == '[')
|
||||||
}
|
{
|
||||||
|
pszNick[nPos] = '_';
|
||||||
// left and right control char selections
|
}
|
||||||
if (JOYISLEFT && pos > 0) pos--;
|
}
|
||||||
if (JOYISRIGHT && pos < 2) pos++;
|
else if (JOYISDOWN)
|
||||||
|
{
|
||||||
// fire switches to next char or exits
|
pszNick[nPos]--;
|
||||||
if (JOYISFIRE&&!hadfire)
|
if (pszNick[nPos] == '@')
|
||||||
{
|
{
|
||||||
hadfire=1;
|
pszNick[nPos] = '_';
|
||||||
switch (pos)
|
}
|
||||||
{
|
if (pszNick[nPos] == '^')
|
||||||
case 0: pos=1; break;
|
{
|
||||||
case 1: pos=2; break;
|
pszNick[nPos] = 'Z';
|
||||||
case 2: done=1; break;
|
}
|
||||||
}
|
}
|
||||||
}
|
// left and right control char selections
|
||||||
|
else if (JOYISLEFT && nPos > 0)
|
||||||
if (hadfire&&!JOYISFIRE)
|
{
|
||||||
hadfire=0;
|
nPos--;
|
||||||
}
|
}
|
||||||
|
else if (JOYISRIGHT && nPos < 2)
|
||||||
// return result
|
{
|
||||||
return(
|
nPos++;
|
||||||
(nick[0]-65)<<10 |
|
}
|
||||||
(nick[1]-65)<<5 |
|
|
||||||
(nick[2]-65)
|
// fire switches to next char or exits
|
||||||
);
|
if (JOYISFIRE && !nHadfire)
|
||||||
}
|
{
|
||||||
|
nHadfire = 1;
|
||||||
|
switch (nPos)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
nPos = 1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
nPos = 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
nDone = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nHadfire && !JOYISFIRE)
|
||||||
|
{
|
||||||
|
nHadfire = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return result
|
||||||
|
return (pszNick[0] - 65) << 10 | (pszNick[1] - 65) << 5 | (pszNick[2] - 65);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#ifndef TETRIS_HIGHSCORE_H_
|
#ifndef TETRIS_HIGHSCORE_H_
|
||||||
#define TETRIS_HIGHSCORE_H_
|
#define TETRIS_HIGHSCORE_H_
|
||||||
|
|
||||||
uint16_t tetris_highscore_inputName(void);
|
/* Function: tetris_highscore_inputName
|
||||||
|
* Description: let user input a three character name
|
||||||
#endif /*TETRIS_HIGHSCORE_H_*/
|
* Return value: name packed into a uint16_t
|
||||||
|
*/
|
||||||
|
uint16_t tetris_highscore_inputName(void);
|
||||||
|
|
||||||
|
#endif /*TETRIS_HIGHSCORE_H_*/
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#define TETRIS_INPUT_CHATTER_TICKS_LEFT 12
|
#define TETRIS_INPUT_CHATTER_TICKS_LEFT 12
|
||||||
#define TETRIS_INPUT_CHATTER_TICKS_RIGHT 12
|
#define TETRIS_INPUT_CHATTER_TICKS_RIGHT 12
|
||||||
#define TETRIS_INPUT_CHATTER_TICKS_DOWN 12
|
#define TETRIS_INPUT_CHATTER_TICKS_DOWN 12
|
||||||
#define TETRIS_INPUT_CHATTER_TICKS_DROP 24
|
#define TETRIS_INPUT_CHATTER_TICKS_DROP 48
|
||||||
|
|
||||||
// wait cycles per level (array of uint8_t)
|
// wait cycles per level (array of uint8_t)
|
||||||
#define TETRIS_INPUT_LVL_CYCLES 200, 133, 100, 80, 66, 57, 50, 44, 40, 36, 33, \
|
#define TETRIS_INPUT_LVL_CYCLES 200, 133, 100, 80, 66, 57, 50, 44, 40, 36, 33, \
|
||||||
|
@ -314,8 +314,8 @@ tetris_input_command_t tetris_input_getCommand(tetris_input_t *pIn,
|
||||||
// we ensure that the variable which holds that last command
|
// we ensure that the variable which holds that last command
|
||||||
// isn't touched. We use this as a flag so that the loop cycle
|
// isn't touched. We use this as a flag so that the loop cycle
|
||||||
// counter doesn't get incremented.
|
// counter doesn't get incremented.
|
||||||
// We count the number of pause cycles, though. If enough pause
|
// We count the number of pause cycles, though. If enough cycles
|
||||||
// cycles have been run, we enforce the continuation of the game.
|
// have been run, we enforce the continuation of the game.
|
||||||
if ((pIn->cmdLast != TETRIS_INCMD_PAUSE) ||
|
if ((pIn->cmdLast != TETRIS_INCMD_PAUSE) ||
|
||||||
(++pIn->nPauseCount > TETRIS_INPUT_PAUSE_CYCLES))
|
(++pIn->nPauseCount > TETRIS_INPUT_PAUSE_CYCLES))
|
||||||
{
|
{
|
||||||
|
@ -340,11 +340,11 @@ tetris_input_command_t tetris_input_getCommand(tetris_input_t *pIn,
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrement all ignore counters
|
// decrement all ignore counters
|
||||||
for (int nIgnoreIndex = 0; nIgnoreIndex < TETRIS_INCMD_NONE; ++nIgnoreIndex)
|
for (int nIgnIndex = 0; nIgnIndex < TETRIS_INCMD_NONE; ++nIgnIndex)
|
||||||
{
|
{
|
||||||
if (pIn->nIgnoreCmdCounter[nIgnoreIndex] != 0)
|
if (pIn->nIgnoreCmdCounter[nIgnIndex] != 0)
|
||||||
{
|
{
|
||||||
--pIn->nIgnoreCmdCounter[nIgnoreIndex];
|
--pIn->nIgnoreCmdCounter[nIgnIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,8 @@ tetris_input_command_t;
|
||||||
typedef enum tetris_input_pace_t
|
typedef enum tetris_input_pace_t
|
||||||
{
|
{
|
||||||
TETRIS_INPACE_HOVERING, // normal falling pace
|
TETRIS_INPACE_HOVERING, // normal falling pace
|
||||||
TETRIS_INPACE_GLIDING /* guarantees a minimum docking time to avoid that
|
TETRIS_INPACE_GLIDING /* guarantees a minimum docking time to avoid
|
||||||
pieces are docked immediately if they hit something
|
accidentally docked pieces in higher levels */
|
||||||
in higher levels */
|
|
||||||
}
|
}
|
||||||
tetris_input_pace_t;
|
tetris_input_pace_t;
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,12 @@ uint8_t tetris_logic_calculateLines(uint8_t nRowMask)
|
||||||
return nLines;
|
return nLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Function: tetris_logic_retrieveHighscore
|
||||||
|
* Description: retrieves the highscore from storate
|
||||||
|
* Argument nHighscoreIndex: highscore index (for different game variants)
|
||||||
|
* Return value: the highscore
|
||||||
|
*/
|
||||||
uint16_t tetris_logic_retrieveHighscore(uint8_t nHighscoreIndex)
|
uint16_t tetris_logic_retrieveHighscore(uint8_t nHighscoreIndex)
|
||||||
{
|
{
|
||||||
#ifdef EEMEM
|
#ifdef EEMEM
|
||||||
|
@ -105,21 +111,36 @@ uint16_t tetris_logic_retrieveHighscore(uint8_t nHighscoreIndex)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Function: tetris_logic_saveHighscore
|
||||||
|
* Description: saves the highscore into the storage
|
||||||
|
* Argument nHighscoreIndex: highscore index (for different game variants)
|
||||||
|
* Argument nHighscoreName: the highscore
|
||||||
|
* Return value: void
|
||||||
|
*/
|
||||||
void tetris_logic_saveHighscore(uint8_t nHighscoreIndex, uint16_t nHighscore)
|
void tetris_logic_saveHighscore(uint8_t nHighscoreIndex, uint16_t nHighscore)
|
||||||
{
|
{
|
||||||
#ifdef EEMEM
|
#ifdef EEMEM
|
||||||
if (nHighscore > tetris_logic_retrieveHighscore(nHighscoreIndex))
|
if (nHighscore > tetris_logic_retrieveHighscore(nHighscoreIndex))
|
||||||
{
|
{
|
||||||
eeprom_write_word(&tetris_logic_nHighscore[nHighscoreIndex], nHighscore);
|
eeprom_write_word(&tetris_logic_nHighscore[nHighscoreIndex],
|
||||||
|
nHighscore);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Function: tetris_logic_retrieveHighscoreName
|
||||||
|
* Description: retrieves the initials of the champion from storage
|
||||||
|
* Argument nHighscoreIndex: highscore index (for different game variants)
|
||||||
|
* Return value: the initials of the champion packed into a uint16_t
|
||||||
|
*/
|
||||||
uint16_t tetris_logic_retrieveHighscoreName(uint8_t nHighscoreIndex)
|
uint16_t tetris_logic_retrieveHighscoreName(uint8_t nHighscoreIndex)
|
||||||
{
|
{
|
||||||
#ifdef EEMEM
|
#ifdef EEMEM
|
||||||
uint16_t nHighscoreName = 0;
|
uint16_t nHighscoreName = 0;
|
||||||
nHighscoreName = eeprom_read_word(&tetris_logic_nHighscoreName[nHighscoreIndex]);
|
nHighscoreName =
|
||||||
|
eeprom_read_word(&tetris_logic_nHighscoreName[nHighscoreIndex]);
|
||||||
|
|
||||||
// a score of 65535 is most likely caused by uninitialized EEPROM addresses
|
// a score of 65535 is most likely caused by uninitialized EEPROM addresses
|
||||||
if (nHighscoreName == 65535)
|
if (nHighscoreName == 65535)
|
||||||
|
@ -133,10 +154,19 @@ uint16_t tetris_logic_retrieveHighscoreName(uint8_t nHighscoreIndex)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void tetris_logic_saveHighscoreName(uint8_t nHighscoreIndex, uint16_t nHighscoreName)
|
|
||||||
|
/* Function: tetris_logic_saveHighscoreName
|
||||||
|
* Description: saves the initials of the champion
|
||||||
|
* Argument nHighscoreIndex: highscore index (for different game variants)
|
||||||
|
* Argument nHighscoreName: the initials of the champion packed into a uint16_t
|
||||||
|
* Return value: void
|
||||||
|
*/
|
||||||
|
void tetris_logic_saveHighscoreName(uint8_t nHighscoreIndex,
|
||||||
|
uint16_t nHighscoreName)
|
||||||
{
|
{
|
||||||
#ifdef EEMEM
|
#ifdef EEMEM
|
||||||
eeprom_write_word(&tetris_logic_nHighscoreName[nHighscoreIndex], nHighscoreName);
|
eeprom_write_word(&tetris_logic_nHighscoreName[nHighscoreIndex],
|
||||||
|
nHighscoreName);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +321,8 @@ void tetris_main(int8_t nBastet)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
// make preview piece the current piece and create new preview piece
|
// make preview piece the current piece and create a new
|
||||||
|
// preview piece
|
||||||
pPiece = pNextPiece;
|
pPiece = pNextPiece;
|
||||||
pNextPiece = tetris_piece_construct(random8() % 7,
|
pNextPiece = tetris_piece_construct(random8() % 7,
|
||||||
TETRIS_PC_ANGLE_0);
|
TETRIS_PC_ANGLE_0);
|
||||||
|
@ -301,7 +332,8 @@ void tetris_main(int8_t nBastet)
|
||||||
tetris_piece_t *pOldPiece;
|
tetris_piece_t *pOldPiece;
|
||||||
tetris_playfield_insertPiece(pPl, pPiece, &pOldPiece);
|
tetris_playfield_insertPiece(pPl, pPiece, &pOldPiece);
|
||||||
|
|
||||||
// destruct old piece (if it exists) since we don't need it anymore
|
// destruct old piece (if it exists) since we don't need it
|
||||||
|
// anymore
|
||||||
if (pOldPiece != NULL)
|
if (pOldPiece != NULL)
|
||||||
{
|
{
|
||||||
tetris_piece_destruct(pOldPiece);
|
tetris_piece_destruct(pOldPiece);
|
||||||
|
|
|
@ -136,7 +136,7 @@ uint16_t tetris_logic_getHighscoreName(tetris_logic_t *pLogic);
|
||||||
* Argmument nHighscoreName: highscore name
|
* Argmument nHighscoreName: highscore name
|
||||||
*/
|
*/
|
||||||
void tetris_logic_setHighscoreName(tetris_logic_t *pLogic,
|
void tetris_logic_setHighscoreName(tetris_logic_t *pLogic,
|
||||||
uint16_t nHighscoreName);
|
uint16_t nHighscoreName);
|
||||||
|
|
||||||
|
|
||||||
/* Function: tetris_logic_getLevel
|
/* Function: tetris_logic_getLevel
|
||||||
|
@ -174,4 +174,3 @@ tetris_piece_t* tetris_logic_getPreviewPiece(tetris_logic_t *pLogic);
|
||||||
|
|
||||||
|
|
||||||
#endif /*TETRIS_LOGIC_H_*/
|
#endif /*TETRIS_LOGIC_H_*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue