adjusted controls and level speeds

This commit is contained in:
Christian Kroll 2009-06-12 06:24:04 +00:00
parent b9614c669d
commit 9423737818
5 changed files with 47 additions and 15 deletions

View File

@ -30,8 +30,8 @@
#define TETRIS_INPUT_GLIDE_CYCLES 75 #define TETRIS_INPUT_GLIDE_CYCLES 75
// here you can adjust the delays (in loop cycles) for key repeat // here you can adjust the delays (in loop cycles) for key repeat
#define TETRIS_INPUT_REPEAT_INITIALDELAY 40 #define TETRIS_INPUT_REPEAT_INITIALDELAY 35
#define TETRIS_INPUT_REPEAT_DELAY 10 #define TETRIS_INPUT_REPEAT_DELAY 5
// Here you can adjust the amount of loop cycles a command is ignored after // Here you can adjust the amount of loop cycles a command is ignored after
// its button has been released (to reduce joystick chatter) // its button has been released (to reduce joystick chatter)
@ -42,6 +42,10 @@
#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 24
// wait cycles per level (array of uint8_t)
#define TETRIS_INPUT_LVL_CYCLES 200, 133, 100, 80, 66, 57, 50, 44, 40, 36, 33, \
30, 28, 26, 25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9
/*************************** /***************************
* non-interface functions * * non-interface functions *
@ -192,7 +196,7 @@ void tetris_input_destruct(tetris_input_t *pIn)
* input related functions * * input related functions *
***************************/ ***************************/
/* Function: retris_input_getCommand /* Function: tetris_input_getCommand
* Description: retrieves commands from joystick or loop interval * Description: retrieves commands from joystick or loop interval
* Argument pIn: pointer to an input object * Argument pIn: pointer to an input object
* Argument nPace: falling pace (see definition of tetris_input_pace_t) * Argument nPace: falling pace (see definition of tetris_input_pace_t)
@ -383,9 +387,26 @@ void tetris_input_setLevel(tetris_input_t *pIn,
{ {
assert(pIn != NULL); assert(pIn != NULL);
assert(nLvl <= TETRIS_INPUT_LEVELS - 1); assert(nLvl <= TETRIS_INPUT_LEVELS - 1);
static const uint8_t nCycles[] = {TETRIS_INPUT_LVL_CYCLES};
if (pIn->nLevel != nLvl) if (pIn->nLevel != nLvl)
{ {
pIn->nLevel = nLvl; pIn->nLevel = nLvl;
pIn->nMaxCycles = 400 / (nLvl + 2); pIn->nMaxCycles = nCycles[nLvl];
}
}
/* Function: tetris_input_resetDownKeyRepeat
* Description: resets the key repeat count for the down key
* Argument pIn: pointer to an input object
* Return value: void
*/
void tetris_input_resetDownKeyRepeat(tetris_input_t *pIn)
{
assert(pIn != NULL);
if (pIn->cmdLast == TETRIS_INCMD_DOWN)
{
pIn->nRepeatCount = -TETRIS_INPUT_REPEAT_INITIALDELAY;
} }
} }

View File

@ -9,7 +9,7 @@
***********/ ***********/
// number of levels // number of levels
#define TETRIS_INPUT_LEVELS 20 #define TETRIS_INPUT_LEVELS 30
/********* /*********
@ -50,7 +50,7 @@ typedef struct tetris_input_t
// set via the tetris_input_setLevel() function. // set via the tetris_input_setLevel() function.
uint8_t nMaxCycles; uint8_t nMaxCycles;
// This counter keeps track of the number of loop cycles whoch have been // This counter keeps track of the number of loop cycles which have been
// done since the last forced piece movement. It gets reset if it either // done since the last forced piece movement. It gets reset if it either
// reaches a well defined value (causing a gravity command to be issued) // reaches a well defined value (causing a gravity command to be issued)
// or the player has moved down the piece herself/himself. // or the player has moved down the piece herself/himself.
@ -63,7 +63,7 @@ typedef struct tetris_input_t
// if that value is reached). // if that value is reached).
int8_t nRepeatCount; int8_t nRepeatCount;
// Keeps track of the number loop cycles which have been run while in // Keeps track of the number of loop cycles which have been run while in
// pause mode. As soon as a well defined value is reached, the game // pause mode. As soon as a well defined value is reached, the game
// continues (in case someone paused the game and forgot to resume it). // continues (in case someone paused the game and forgot to resume it).
uint16_t nPauseCount; uint16_t nPauseCount;
@ -126,4 +126,11 @@ void tetris_input_setLevel(tetris_input_t *pIn,
uint8_t nLvl); uint8_t nLvl);
/* Function: tetris_input_resetDownKeyRepeat
* Description: resets the key repeat count for the down key
* Argument pIn: pointer to an input object
* Return value: void
*/
void tetris_input_resetDownKeyRepeat(tetris_input_t *pIn);
#endif /*INPUT_H_*/ #endif /*INPUT_H_*/

View File

@ -28,15 +28,15 @@
uint16_t tetris_logic_nHighscore EEMEM; uint16_t tetris_logic_nHighscore EEMEM;
#endif #endif
// MSB is leftmost pixel // MSB is leftmost pixel
static uint8_t icon[8] PROGMEM = static uint8_t icon[8] PROGMEM =
{0x0f, 0x0f, 0xc3, 0xdb, 0xdb, 0xc3, 0xf0, 0xf0}; // Tetris icon {0x0f, 0x0f, 0xc3, 0xdb, 0xdb, 0xc3, 0xf0, 0xf0}; // Tetris icon
void tetris(); void tetris();
game_descriptor_t tetris_game_descriptor __attribute__((section(".game_descriptors"))) ={ game_descriptor_t tetris_game_descriptor __attribute__((section(".game_descriptors"))) ={
&tetris, &tetris,
icon, icon,
}; };
@ -93,6 +93,7 @@ void tetris_logic_saveHighscore(uint16_t nHighscore)
#endif #endif
} }
/**************************** /****************************
* construction/destruction * * construction/destruction *
****************************/ ****************************/
@ -285,6 +286,9 @@ void tetris ()
// the piece has irrevocably hit the ground // the piece has irrevocably hit the ground
case TETRIS_PFS_DOCKED: case TETRIS_PFS_DOCKED:
// avoid accidentally issued "down" commands
tetris_input_resetDownKeyRepeat(pIn);
// remove complete lines (if any) // remove complete lines (if any)
tetris_playfield_removeCompleteLines(pPl); tetris_playfield_removeCompleteLines(pPl);
@ -292,6 +296,7 @@ void tetris ()
// and whether the level gets changed // and whether the level gets changed
tetris_logic_removedLines(pLogic, tetris_playfield_getRowMask(pPl)); tetris_logic_removedLines(pLogic, tetris_playfield_getRowMask(pPl));
tetris_input_setLevel(pIn, tetris_logic_getLevel(pLogic)); tetris_input_setLevel(pIn, tetris_logic_getLevel(pLogic));
break; break;
// avoid compiler warnings // avoid compiler warnings
@ -475,4 +480,3 @@ tetris_piece_t* tetris_logic_getPreviewPiece(tetris_logic_t *pLogic)
assert(pLogic != NULL); assert(pLogic != NULL);
return pLogic->pPreviewPiece; return pLogic->pPreviewPiece;
} }

View File

@ -49,7 +49,7 @@ void tetris_piece_destruct(tetris_piece_t *pPc)
****************************/ ****************************/
/* Function: tetris_piece_getBitmap /* Function: tetris_piece_getBitmap
* Description: returns bitfield representation of the piece * Description: returns bitfield representation of the piece
* Argument pPc: piece from which the bitfield shuld be retrieved * Argument pPc: piece from which the bitfield shuld be retrieved
* Return value: bitfield representation of the piece * Return value: bitfield representation of the piece
* - nth nibble is nth row of the piece (from upper left) * - nth nibble is nth row of the piece (from upper left)
@ -62,7 +62,7 @@ uint16_t tetris_piece_getBitmap(tetris_piece_t *pPc)
// Lookup table: // Lookup table:
// A value in an array represents a piece in a specific angle (rotating // A value in an array represents a piece in a specific angle (rotating
// clockwise from index 0). // clockwise from index 0).
const static uint16_t piece[][4] PROGMEM = static const uint16_t piece[][4] PROGMEM =
{{0x0F00, 0x2222, 0x0F00, 0x2222}, // LINE {{0x0F00, 0x2222, 0x0F00, 0x2222}, // LINE
{0x4E00, 0x4640, 0x0E40, 0x4C40}, // T {0x4E00, 0x4640, 0x0E40, 0x4C40}, // T
{0x0660, 0x0660, 0x0660, 0x0660}, // SQUARE {0x0660, 0x0660, 0x0660, 0x0660}, // SQUARE

View File

@ -14,6 +14,7 @@
#define WAIT(ms) wait(ms) #define WAIT(ms) wait(ms)
/*********** /***********
* defines * * defines *
***********/ ***********/
@ -409,7 +410,6 @@ void tetris_view_showResults(tetris_view_t *pV)
snprintf(pszResults, 48 * sizeof(char), snprintf(pszResults, 48 * sizeof(char),
"</#Lines %u New Highscore %u", nLines, nScore); "</#Lines %u New Highscore %u", nLines, nScore);
} }
#ifdef SCROLLTEXT_SUPPORT #ifdef SCROLLTEXT_SUPPORT
scrolltext(pszResults); scrolltext(pszResults);
#endif #endif