From 94237378186b3f183f686308c6bcaab2a08b3677 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Fri, 12 Jun 2009 06:24:04 +0000 Subject: [PATCH] adjusted controls and level speeds --- games/tetris/input.c | 29 +++++++++++++++++++++++++---- games/tetris/input.h | 13 ++++++++++--- games/tetris/logic.c | 14 +++++++++----- games/tetris/piece.c | 4 ++-- games/tetris/view.c | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/games/tetris/input.c b/games/tetris/input.c index 37aff2c..53cf997 100644 --- a/games/tetris/input.c +++ b/games/tetris/input.c @@ -30,8 +30,8 @@ #define TETRIS_INPUT_GLIDE_CYCLES 75 // here you can adjust the delays (in loop cycles) for key repeat -#define TETRIS_INPUT_REPEAT_INITIALDELAY 40 -#define TETRIS_INPUT_REPEAT_DELAY 10 +#define TETRIS_INPUT_REPEAT_INITIALDELAY 35 +#define TETRIS_INPUT_REPEAT_DELAY 5 // Here you can adjust the amount of loop cycles a command is ignored after // 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_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 * @@ -192,7 +196,7 @@ void tetris_input_destruct(tetris_input_t *pIn) * input related functions * ***************************/ -/* Function: retris_input_getCommand +/* Function: tetris_input_getCommand * Description: retrieves commands from joystick or loop interval * Argument pIn: pointer to an input object * 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(nLvl <= TETRIS_INPUT_LEVELS - 1); + + static const uint8_t nCycles[] = {TETRIS_INPUT_LVL_CYCLES}; + if (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; } } diff --git a/games/tetris/input.h b/games/tetris/input.h index faf7aca..72b02ad 100644 --- a/games/tetris/input.h +++ b/games/tetris/input.h @@ -9,7 +9,7 @@ ***********/ // 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. 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 // reaches a well defined value (causing a gravity command to be issued) // or the player has moved down the piece herself/himself. @@ -63,7 +63,7 @@ typedef struct tetris_input_t // if that value is reached). 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 // continues (in case someone paused the game and forgot to resume it). uint16_t nPauseCount; @@ -126,4 +126,11 @@ void tetris_input_setLevel(tetris_input_t *pIn, 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_*/ diff --git a/games/tetris/logic.c b/games/tetris/logic.c index 3709c43..02e2ed1 100644 --- a/games/tetris/logic.c +++ b/games/tetris/logic.c @@ -28,15 +28,15 @@ uint16_t tetris_logic_nHighscore EEMEM; #endif - // MSB is leftmost pixel + // MSB is leftmost pixel 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(); game_descriptor_t tetris_game_descriptor __attribute__((section(".game_descriptors"))) ={ - &tetris, - icon, + &tetris, + icon, }; @@ -93,6 +93,7 @@ void tetris_logic_saveHighscore(uint16_t nHighscore) #endif } + /**************************** * construction/destruction * ****************************/ @@ -285,6 +286,9 @@ void tetris () // the piece has irrevocably hit the ground case TETRIS_PFS_DOCKED: + // avoid accidentally issued "down" commands + tetris_input_resetDownKeyRepeat(pIn); + // remove complete lines (if any) tetris_playfield_removeCompleteLines(pPl); @@ -292,6 +296,7 @@ void tetris () // and whether the level gets changed tetris_logic_removedLines(pLogic, tetris_playfield_getRowMask(pPl)); tetris_input_setLevel(pIn, tetris_logic_getLevel(pLogic)); + break; // avoid compiler warnings @@ -475,4 +480,3 @@ tetris_piece_t* tetris_logic_getPreviewPiece(tetris_logic_t *pLogic) assert(pLogic != NULL); return pLogic->pPreviewPiece; } - diff --git a/games/tetris/piece.c b/games/tetris/piece.c index 815da6c..294fc54 100644 --- a/games/tetris/piece.c +++ b/games/tetris/piece.c @@ -49,7 +49,7 @@ void tetris_piece_destruct(tetris_piece_t *pPc) ****************************/ /* 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 * Return value: bitfield representation of the piece * - 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: // A value in an array represents a piece in a specific angle (rotating // clockwise from index 0). - const static uint16_t piece[][4] PROGMEM = + static const uint16_t piece[][4] PROGMEM = {{0x0F00, 0x2222, 0x0F00, 0x2222}, // LINE {0x4E00, 0x4640, 0x0E40, 0x4C40}, // T {0x0660, 0x0660, 0x0660, 0x0660}, // SQUARE diff --git a/games/tetris/view.c b/games/tetris/view.c index 35571a9..8d09147 100644 --- a/games/tetris/view.c +++ b/games/tetris/view.c @@ -14,6 +14,7 @@ #define WAIT(ms) wait(ms) + /*********** * defines * ***********/ @@ -409,7 +410,6 @@ void tetris_view_showResults(tetris_view_t *pV) snprintf(pszResults, 48 * sizeof(char), "