minor cleanups and some whitespace fun

This commit is contained in:
Christian Kroll 2010-01-11 23:34:36 +00:00
parent 187765a1ef
commit 9341dad54a
6 changed files with 166 additions and 108 deletions

View File

@ -1,85 +1,109 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#include "../../config.h"
#include "../../scrolltext/scrolltext.h"
#include "../../joystick/joystick.h"
#include "highscore.h"
/* Function: tetris_highscore_inputName
* Description: let user input a three character name
* Return value: name packed into a uint16_t
*/
uint16_t tetris_highscore_inputName(void)
{
char nick[4], tmp[40];
uint8_t xpos;
uint8_t pos=0, blink=0, done=0, hadfire=0;
sprintf(nick, "AAA");
while(!done)
{
// We need to do our own blink interval
blink = (blink+1) % 4;
// Determine start position on screen
// depending on active character
switch (pos)
{
case 0: xpos = 15; break;
case 1: xpos = 19; break;
case 2: xpos = 23; break;
}
// Construct command for scrolltext and execute
sprintf(tmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c",
xpos, (!blink && pos == 0) ? ' ' : nick[0],
xpos-8, (!blink && pos == 1 ) ? ' ' : nick[1],
xpos-15, (!blink && pos == 2 ) ? ' ' : nick[2]);
scrolltext(tmp);
// up and down control current char
if (JOYISUP)
{
nick[pos]++;
if (nick[pos] == '`') nick[pos] = 'A';
if (nick[pos] == '[') nick[pos] = '_';
}
if (JOYISDOWN)
{
nick[pos]--;
if (nick[pos] == '@') nick[pos] = '_';
if (nick[pos] == '^') nick[pos] = 'Z';
}
// left and right control char selections
if (JOYISLEFT && pos > 0) pos--;
if (JOYISRIGHT && pos < 2) pos++;
// fire switches to next char or exits
if (JOYISFIRE&&!hadfire)
{
hadfire=1;
switch (pos)
{
case 0: pos=1; break;
case 1: pos=2; break;
case 2: done=1; break;
}
}
if (hadfire&&!JOYISFIRE)
hadfire=0;
}
// return result
return(
(nick[0]-65)<<10 |
(nick[1]-65)<<5 |
(nick[2]-65)
);
}
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
#include "../../config.h"
#include "../../scrolltext/scrolltext.h"
#include "../../joystick/joystick.h"
#include "highscore.h"
/* Function: tetris_highscore_inputName
* Description: let user input a three character name
* Return value: name packed into a uint16_t
*/
uint16_t tetris_highscore_inputName(void)
{
char pszNick[4], pszTmp[40];
uint8_t nOffset;
uint8_t nPos = 0, nBlink = 0, nDone = 0, nHadfire = 0;
sprintf(pszNick, "AAA");
while (!nDone)
{
// we need our own blink interval
nBlink = (nBlink + 1) % 4;
// determine start position on screen depending on active character
switch (nPos)
{
case 0:
nOffset = 15;
break;
case 1:
nOffset = 19;
break;
case 2:
nOffset = 23;
break;
}
// construct command for scrolltext and execute
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,
(!nBlink && nPos == 2) ? ' ' : pszNick[2]);
scrolltext(pszTmp);
// up and down control current char
if (JOYISUP)
{
pszNick[nPos]++;
if (pszNick[nPos] == '`')
{
pszNick[nPos] = 'A';
}
if (pszNick[nPos] == '[')
{
pszNick[nPos] = '_';
}
}
else if (JOYISDOWN)
{
pszNick[nPos]--;
if (pszNick[nPos] == '@')
{
pszNick[nPos] = '_';
}
if (pszNick[nPos] == '^')
{
pszNick[nPos] = 'Z';
}
}
// left and right control char selections
else if (JOYISLEFT && nPos > 0)
{
nPos--;
}
else if (JOYISRIGHT && nPos < 2)
{
nPos++;
}
// 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);
}

View File

@ -1,6 +1,10 @@
#ifndef TETRIS_HIGHSCORE_H_
#define TETRIS_HIGHSCORE_H_
uint16_t tetris_highscore_inputName(void);
#endif /*TETRIS_HIGHSCORE_H_*/
#ifndef TETRIS_HIGHSCORE_H_
#define TETRIS_HIGHSCORE_H_
/* Function: tetris_highscore_inputName
* Description: let user input a three character name
* Return value: name packed into a uint16_t
*/
uint16_t tetris_highscore_inputName(void);
#endif /*TETRIS_HIGHSCORE_H_*/

View File

@ -40,7 +40,7 @@
#define TETRIS_INPUT_CHATTER_TICKS_LEFT 12
#define TETRIS_INPUT_CHATTER_TICKS_RIGHT 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)
#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
// isn't touched. We use this as a flag so that the loop cycle
// counter doesn't get incremented.
// We count the number of pause cycles, though. If enough pause
// cycles have been run, we enforce the continuation of the game.
// We count the number of pause cycles, though. If enough cycles
// have been run, we enforce the continuation of the game.
if ((pIn->cmdLast != TETRIS_INCMD_PAUSE) ||
(++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
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];
}
}

View File

@ -34,9 +34,8 @@ tetris_input_command_t;
typedef enum tetris_input_pace_t
{
TETRIS_INPACE_HOVERING, // normal falling pace
TETRIS_INPACE_GLIDING /* guarantees a minimum docking time to avoid that
pieces are docked immediately if they hit something
in higher levels */
TETRIS_INPACE_GLIDING /* guarantees a minimum docking time to avoid
accidentally docked pieces in higher levels */
}
tetris_input_pace_t;

View File

@ -87,6 +87,12 @@ uint8_t tetris_logic_calculateLines(uint8_t nRowMask)
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)
{
#ifdef EEMEM
@ -105,21 +111,36 @@ uint16_t tetris_logic_retrieveHighscore(uint8_t nHighscoreIndex)
#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)
{
#ifdef EEMEM
if (nHighscore > tetris_logic_retrieveHighscore(nHighscoreIndex))
{
eeprom_write_word(&tetris_logic_nHighscore[nHighscoreIndex], nHighscore);
eeprom_write_word(&tetris_logic_nHighscore[nHighscoreIndex],
nHighscore);
}
#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)
{
#ifdef EEMEM
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
if (nHighscoreName == 65535)
@ -133,10 +154,19 @@ uint16_t tetris_logic_retrieveHighscoreName(uint8_t nHighscoreIndex)
#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
eeprom_write_word(&tetris_logic_nHighscoreName[nHighscoreIndex], nHighscoreName);
eeprom_write_word(&tetris_logic_nHighscoreName[nHighscoreIndex],
nHighscoreName);
#endif
}
@ -291,7 +321,8 @@ void tetris_main(int8_t nBastet)
else
{
#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;
pNextPiece = tetris_piece_construct(random8() % 7,
TETRIS_PC_ANGLE_0);
@ -301,7 +332,8 @@ void tetris_main(int8_t nBastet)
tetris_piece_t *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)
{
tetris_piece_destruct(pOldPiece);

View File

@ -136,7 +136,7 @@ uint16_t tetris_logic_getHighscoreName(tetris_logic_t *pLogic);
* Argmument nHighscoreName: highscore name
*/
void tetris_logic_setHighscoreName(tetris_logic_t *pLogic,
uint16_t nHighscoreName);
uint16_t nHighscoreName);
/* Function: tetris_logic_getLevel
@ -174,4 +174,3 @@ tetris_piece_t* tetris_logic_getPreviewPiece(tetris_logic_t *pLogic);
#endif /*TETRIS_LOGIC_H_*/