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"); |
sprintf(pszNick, "AAA"); |
||||
while(!done) |
while (!nDone) |
||||
{ |
{ |
||||
|
// we need our own blink interval
|
||||
|
nBlink = (nBlink + 1) % 4; |
||||
|
|
||||
// We need to do our own blink interval
|
// determine start position on screen depending on active character
|
||||
blink = (blink+1) % 4; |
switch (nPos) |
||||
|
|
||||
// Determine start position on screen
|
|
||||
// depending on active character
|
|
||||
switch (pos) |
|
||||
{ |
{ |
||||
case 0: xpos = 15; break; |
case 0: |
||||
case 1: xpos = 19; break; |
nOffset = 15; |
||||
case 2: xpos = 23; break; |
break; |
||||
|
case 1: |
||||
|
nOffset = 19; |
||||
|
break; |
||||
|
case 2: |
||||
|
nOffset = 23; |
||||
|
break; |
||||
} |
} |
||||
|
|
||||
// Construct command for scrolltext and execute
|
// construct command for scrolltext and execute
|
||||
sprintf(tmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c", |
sprintf(pszTmp, "x%d+p1#%c#x%d+p1#%c#x%dp1#%c", nOffset, |
||||
xpos, (!blink && pos == 0) ? ' ' : nick[0], |
(!nBlink && nPos == 0) ? ' ' : pszNick[0], nOffset - 8, |
||||
xpos-8, (!blink && pos == 1 ) ? ' ' : nick[1], |
(!nBlink && nPos == 1) ? ' ' : pszNick[1], nOffset - 15, |
||||
xpos-15, (!blink && pos == 2 ) ? ' ' : nick[2]); |
(!nBlink && nPos == 2) ? ' ' : pszNick[2]); |
||||
scrolltext(tmp); |
scrolltext(pszTmp); |
||||
|
|
||||
|
|
||||
// up and down control current char
|
// up and down control current char
|
||||
if (JOYISUP) |
if (JOYISUP) |
||||
{ |
{ |
||||
nick[pos]++; |
pszNick[nPos]++; |
||||
if (nick[pos] == '`') nick[pos] = 'A'; |
if (pszNick[nPos] == '`') |
||||
if (nick[pos] == '[') nick[pos] = '_'; |
{ |
||||
|
pszNick[nPos] = 'A'; |
||||
} |
} |
||||
if (JOYISDOWN) |
if (pszNick[nPos] == '[') |
||||
{ |
{ |
||||
nick[pos]--; |
pszNick[nPos] = '_'; |
||||
if (nick[pos] == '@') nick[pos] = '_'; |
} |
||||
if (nick[pos] == '^') nick[pos] = 'Z'; |
} |
||||
|
else if (JOYISDOWN) |
||||
|
{ |
||||
|
pszNick[nPos]--; |
||||
|
if (pszNick[nPos] == '@') |
||||
|
{ |
||||
|
pszNick[nPos] = '_'; |
||||
|
} |
||||
|
if (pszNick[nPos] == '^') |
||||
|
{ |
||||
|
pszNick[nPos] = 'Z'; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
// left and right control char selections
|
// left and right control char selections
|
||||
if (JOYISLEFT && pos > 0) pos--; |
else if (JOYISLEFT && nPos > 0) |
||||
if (JOYISRIGHT && pos < 2) pos++; |
{ |
||||
|
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