Christian Kroll
15 years ago
6 changed files with 166 additions and 108 deletions
@ -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"); |
|
||||
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(pszNick, "AAA"); |
||||
sprintf(tmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c", |
while (!nDone) |
||||
xpos, (!blink && pos == 0) ? ' ' : nick[0], |
{ |
||||
xpos-8, (!blink && pos == 1 ) ? ' ' : nick[1], |
// we need our own blink interval
|
||||
xpos-15, (!blink && pos == 2 ) ? ' ' : nick[2]); |
nBlink = (nBlink + 1) % 4; |
||||
scrolltext(tmp); |
|
||||
|
|
||||
|
// 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; |
||||
|
} |
||||
|
|
||||
// up and down control current char
|
// construct command for scrolltext and execute
|
||||
if (JOYISUP) |
sprintf(pszTmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c", nOffset, |
||||
{ |
(!nBlink && nPos == 0) ? ' ' : pszNick[0], nOffset - 8, |
||||
nick[pos]++; |
(!nBlink && nPos == 1) ? ' ' : pszNick[1], nOffset - 15, |
||||
if (nick[pos] == '`') nick[pos] = 'A'; |
(!nBlink && nPos == 2) ? ' ' : pszNick[2]); |
||||
if (nick[pos] == '[') nick[pos] = '_'; |
scrolltext(pszTmp); |
||||
} |
|
||||
if (JOYISDOWN) |
|
||||
{ |
|
||||
nick[pos]--; |
|
||||
if (nick[pos] == '@') nick[pos] = '_'; |
|
||||
if (nick[pos] == '^') nick[pos] = 'Z'; |
|
||||
} |
|
||||
|
|
||||
// left and right control char selections
|
// up and down control current char
|
||||
if (JOYISLEFT && pos > 0) pos--; |
if (JOYISUP) |
||||
if (JOYISRIGHT && pos < 2) pos++; |
{ |
||||
|
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
|
// fire switches to next char or exits
|
||||
if (JOYISFIRE&&!hadfire) |
if (JOYISFIRE && !nHadfire) |
||||
{ |
{ |
||||
hadfire=1; |
nHadfire = 1; |
||||
switch (pos) |
switch (nPos) |
||||
{ |
{ |
||||
case 0: pos=1; break; |
case 0: |
||||
case 1: pos=2; break; |
nPos = 1; |
||||
case 2: done=1; break; |
break; |
||||
} |
case 1: |
||||
} |
nPos = 2; |
||||
|
break; |
||||
|
case 2: |
||||
|
nDone = 1; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
if (hadfire&&!JOYISFIRE) |
if (nHadfire && !JOYISFIRE) |
||||
hadfire=0; |
{ |
||||
|
nHadfire = 0; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
// return result
|
// return result
|
||||
return( |
return (pszNick[0] - 65) << 10 | (pszNick[1] - 65) << 5 | (pszNick[2] - 65); |
||||
(nick[0]-65)<<10 | |
|
||||
(nick[1]-65)<<5 | |
|
||||
(nick[2]-65) |
|
||||
); |
|
||||
} |
} |
||||
|
@ -1,6 +1,10 @@ |
|||||
#ifndef TETRIS_HIGHSCORE_H_ |
#ifndef TETRIS_HIGHSCORE_H_ |
||||
#define 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); |
uint16_t tetris_highscore_inputName(void); |
||||
|
|
||||
#endif /*TETRIS_HIGHSCORE_H_*/ |
#endif /*TETRIS_HIGHSCORE_H_*/ |
||||
|
Loading…
Reference in new issue