![](/media/cache/profiles/859bf1416b8b8761c5d588dee78dc65f.50x50_q85.jpg)
Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
HighScoreEntry.cpp@18:70190f956a24, 2013-06-17 (annotated)
- Committer:
- RichardE
- Date:
- Mon Jun 17 15:10:43 2013 +0000
- Revision:
- 18:70190f956a24
- Parent:
- 17:194789db2215
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichardE | 0:5fa232ee5fdf | 1 | /* |
RichardE | 0:5fa232ee5fdf | 2 | * SOURCE FILE : HighScoreEntry.cpp |
RichardE | 0:5fa232ee5fdf | 3 | * |
RichardE | 0:5fa232ee5fdf | 4 | * Definition of class HighScoreEntry. |
RichardE | 0:5fa232ee5fdf | 5 | * Routine to allow player to enter their name using joysticks. |
RichardE | 0:5fa232ee5fdf | 6 | * |
RichardE | 0:5fa232ee5fdf | 7 | */ |
RichardE | 0:5fa232ee5fdf | 8 | |
RichardE | 0:5fa232ee5fdf | 9 | #include "HighScoreEntry.h" |
RichardE | 0:5fa232ee5fdf | 10 | #include "Gameduino.h" // Gameduino stuff |
RichardE | 4:673eb9735d44 | 11 | #include "GDExtra.h" // more Gameduino stuff |
RichardE | 4:673eb9735d44 | 12 | #include "GDConst.h" // Gameduino constants |
RichardE | 4:673eb9735d44 | 13 | #include "FrameCounter.h" // counter updated every vertical flyback |
RichardE | 4:673eb9735d44 | 14 | #include "CharBlocks.h" // blocks of characters in program memory |
RichardE | 4:673eb9735d44 | 15 | #include "CharFrame.h" // for drawing frames made of characters |
RichardE | 4:673eb9735d44 | 16 | #include "CharCodes.h" // character codes |
RichardE | 16:d0b142ba4362 | 17 | #include "CharFrame.h" // for drawing frames of characters |
RichardE | 0:5fa232ee5fdf | 18 | |
RichardE | 15:d8ea0c7b7e64 | 19 | // Define this for debugging messages on serial port. |
RichardE | 16:d0b142ba4362 | 20 | #undef CHATTY |
RichardE | 15:d8ea0c7b7e64 | 21 | |
RichardE | 15:d8ea0c7b7e64 | 22 | #ifdef CHATTY |
RichardE | 15:d8ea0c7b7e64 | 23 | extern Serial pc; |
RichardE | 15:d8ea0c7b7e64 | 24 | #endif |
RichardE | 15:d8ea0c7b7e64 | 25 | |
RichardE | 15:d8ea0c7b7e64 | 26 | // Grid constants. |
RichardE | 15:d8ea0c7b7e64 | 27 | #define GRIDX 5 |
RichardE | 16:d0b142ba4362 | 28 | #define GRIDY 16 |
RichardE | 15:d8ea0c7b7e64 | 29 | #define GRIDCOLUMNS 20 |
RichardE | 17:194789db2215 | 30 | #define GRIDROWS 4 // 3 rows for characters, 1 row for special functions |
RichardE | 15:d8ea0c7b7e64 | 31 | #define GRIDCOLUMNSPACING 2 |
RichardE | 15:d8ea0c7b7e64 | 32 | #define GRIDROWSPACING 2 |
RichardE | 15:d8ea0c7b7e64 | 33 | |
RichardE | 17:194789db2215 | 34 | // Some text. |
RichardE | 17:194789db2215 | 35 | const char HighScoreEntry::textDelete[] = "DELETE"; |
RichardE | 17:194789db2215 | 36 | const char HighScoreEntry::textEnter[] = "ENTER"; |
RichardE | 17:194789db2215 | 37 | |
RichardE | 0:5fa232ee5fdf | 38 | /***************/ |
RichardE | 0:5fa232ee5fdf | 39 | /* CONSTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 40 | /***************/ |
RichardE | 0:5fa232ee5fdf | 41 | HighScoreEntry::HighScoreEntry() : |
RichardE | 16:d0b142ba4362 | 42 | charIndex( 0 ), |
RichardE | 16:d0b142ba4362 | 43 | cursorRow( 0 ), |
RichardE | 16:d0b142ba4362 | 44 | cursorColumn( 0 ), |
RichardE | 15:d8ea0c7b7e64 | 45 | grid( GRIDROWS ) |
RichardE | 0:5fa232ee5fdf | 46 | { |
RichardE | 15:d8ea0c7b7e64 | 47 | // Initialise grid around which cursor moves. |
RichardE | 15:d8ea0c7b7e64 | 48 | InitialiseGrid(); |
RichardE | 15:d8ea0c7b7e64 | 49 | #ifdef CHATTY |
RichardE | 15:d8ea0c7b7e64 | 50 | for( UInt8 rowNum = 0; rowNum < grid.GetRowCount(); ++rowNum ) { |
RichardE | 15:d8ea0c7b7e64 | 51 | FieldRow *row = grid.GetRow( rowNum ); |
RichardE | 15:d8ea0c7b7e64 | 52 | if( row != (FieldRow*)NULL ) { |
RichardE | 15:d8ea0c7b7e64 | 53 | FieldCell *cell = row->GetFirstCell(); |
RichardE | 15:d8ea0c7b7e64 | 54 | UInt8 columnNum = 0; |
RichardE | 15:d8ea0c7b7e64 | 55 | while( cell != (FieldCell*)NULL ) { |
RichardE | 15:d8ea0c7b7e64 | 56 | pc.printf( |
RichardE | 15:d8ea0c7b7e64 | 57 | "Row %d column %d -> %d,%d,%d,%d\r\n", |
RichardE | 15:d8ea0c7b7e64 | 58 | (int)rowNum, (int)columnNum, |
RichardE | 15:d8ea0c7b7e64 | 59 | (int)cell->Rect.X1, (int)cell->Rect.Y1, (int)cell->Rect.X2, (int)cell->Rect.Y2 |
RichardE | 15:d8ea0c7b7e64 | 60 | ); |
RichardE | 15:d8ea0c7b7e64 | 61 | cell = row->GetNextCell(); |
RichardE | 15:d8ea0c7b7e64 | 62 | columnNum++; |
RichardE | 15:d8ea0c7b7e64 | 63 | } |
RichardE | 15:d8ea0c7b7e64 | 64 | } |
RichardE | 15:d8ea0c7b7e64 | 65 | } |
RichardE | 15:d8ea0c7b7e64 | 66 | #endif |
RichardE | 0:5fa232ee5fdf | 67 | } |
RichardE | 0:5fa232ee5fdf | 68 | |
RichardE | 0:5fa232ee5fdf | 69 | /**************/ |
RichardE | 0:5fa232ee5fdf | 70 | /* DESTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 71 | /**************/ |
RichardE | 0:5fa232ee5fdf | 72 | HighScoreEntry::~HighScoreEntry() { |
RichardE | 0:5fa232ee5fdf | 73 | } |
RichardE | 0:5fa232ee5fdf | 74 | |
RichardE | 15:d8ea0c7b7e64 | 75 | /*******************/ |
RichardE | 15:d8ea0c7b7e64 | 76 | /* INITIALISE GRID */ |
RichardE | 15:d8ea0c7b7e64 | 77 | /*******************/ |
RichardE | 15:d8ea0c7b7e64 | 78 | void HighScoreEntry::InitialiseGrid( void ) { |
RichardE | 17:194789db2215 | 79 | // First initialise rows used for characters. |
RichardE | 16:d0b142ba4362 | 80 | UInt8 code = PlayerName::MinChar; |
RichardE | 16:d0b142ba4362 | 81 | UInt8 x = GRIDX, y = GRIDY; |
RichardE | 16:d0b142ba4362 | 82 | UInt8 columnNumber = 0, rowNumber = 0;; |
RichardE | 16:d0b142ba4362 | 83 | FieldRow *row = grid.GetRow( rowNumber++ ); |
RichardE | 16:d0b142ba4362 | 84 | while( code <= PlayerName::MaxChar ) { |
RichardE | 15:d8ea0c7b7e64 | 85 | if( row != (FieldRow*)NULL ) { |
RichardE | 16:d0b142ba4362 | 86 | FieldCell *cell = new FieldCell(); |
RichardE | 16:d0b142ba4362 | 87 | cell->Rect.X1 = x - 1; |
RichardE | 16:d0b142ba4362 | 88 | cell->Rect.Y1 = y - 1; |
RichardE | 16:d0b142ba4362 | 89 | cell->Rect.X2 = x + 1; |
RichardE | 16:d0b142ba4362 | 90 | cell->Rect.Y2 = y + 1; |
RichardE | 16:d0b142ba4362 | 91 | row->AddCell( cell ); |
RichardE | 16:d0b142ba4362 | 92 | } |
RichardE | 16:d0b142ba4362 | 93 | columnNumber++; |
RichardE | 16:d0b142ba4362 | 94 | if( columnNumber >= GRIDCOLUMNS ) { |
RichardE | 16:d0b142ba4362 | 95 | columnNumber = 0; |
RichardE | 15:d8ea0c7b7e64 | 96 | x = GRIDX; |
RichardE | 16:d0b142ba4362 | 97 | y += GRIDROWSPACING; |
RichardE | 16:d0b142ba4362 | 98 | row = grid.GetRow( rowNumber++ ); |
RichardE | 15:d8ea0c7b7e64 | 99 | } |
RichardE | 16:d0b142ba4362 | 100 | else { |
RichardE | 16:d0b142ba4362 | 101 | x += GRIDCOLUMNSPACING; |
RichardE | 16:d0b142ba4362 | 102 | } |
RichardE | 16:d0b142ba4362 | 103 | code++; |
RichardE | 15:d8ea0c7b7e64 | 104 | } |
RichardE | 17:194789db2215 | 105 | // Add another row for special functions. |
RichardE | 17:194789db2215 | 106 | columnNumber = 0; |
RichardE | 17:194789db2215 | 107 | x = GRIDX; |
RichardE | 17:194789db2215 | 108 | y += GRIDROWSPACING; |
RichardE | 17:194789db2215 | 109 | row = grid.GetRow( rowNumber++ ); |
RichardE | 17:194789db2215 | 110 | if( row != (FieldRow*)NULL ) { |
RichardE | 17:194789db2215 | 111 | AddTextCell( x, y, row, textDelete ); |
RichardE | 17:194789db2215 | 112 | AddTextCell( x, y, row, textEnter ); |
RichardE | 17:194789db2215 | 113 | } |
RichardE | 15:d8ea0c7b7e64 | 114 | } |
RichardE | 15:d8ea0c7b7e64 | 115 | |
RichardE | 17:194789db2215 | 116 | /***************************************/ |
RichardE | 17:194789db2215 | 117 | /* ADD A CELL CONTAINING TEXT TO A ROW */ |
RichardE | 17:194789db2215 | 118 | /***************************************/ |
RichardE | 17:194789db2215 | 119 | // Pass character coordinates in x and y. These will be updated. |
RichardE | 17:194789db2215 | 120 | // Pass row to which cells should be added in row. |
RichardE | 17:194789db2215 | 121 | // Pass text which is to be contained in cell in text. |
RichardE | 17:194789db2215 | 122 | void HighScoreEntry::AddTextCell( UInt8 &x, UInt8 &y, FieldRow *row, const char *text ) { |
RichardE | 17:194789db2215 | 123 | int len = strlen( text ); |
RichardE | 17:194789db2215 | 124 | FieldCell *cell = new FieldCell(); |
RichardE | 17:194789db2215 | 125 | cell->Rect.X1 = x - 1; |
RichardE | 17:194789db2215 | 126 | cell->Rect.Y1 = y - 1; |
RichardE | 17:194789db2215 | 127 | cell->Rect.X2 = x + len; |
RichardE | 17:194789db2215 | 128 | cell->Rect.Y2 = y + 1; |
RichardE | 17:194789db2215 | 129 | row->AddCell( cell ); |
RichardE | 17:194789db2215 | 130 | x += ( len + 1 ); |
RichardE | 17:194789db2215 | 131 | } |
RichardE | 17:194789db2215 | 132 | |
RichardE | 0:5fa232ee5fdf | 133 | /*********************/ |
RichardE | 0:5fa232ee5fdf | 134 | /* GET A PLAYER NAME */ |
RichardE | 0:5fa232ee5fdf | 135 | /*********************/ |
RichardE | 0:5fa232ee5fdf | 136 | // Pass pointer to place to store name in name. |
RichardE | 0:5fa232ee5fdf | 137 | // Pass pointer to controls to read in controls. |
RichardE | 4:673eb9735d44 | 138 | // Pass pointer to Gameduino to display on in gd. |
RichardE | 4:673eb9735d44 | 139 | void HighScoreEntry::GetName( PlayerName *name, PanelControls *controls, Gameduino *gd ) { |
RichardE | 0:5fa232ee5fdf | 140 | UInt16 inputs; |
RichardE | 0:5fa232ee5fdf | 141 | UInt8 countdown = 0; |
RichardE | 0:5fa232ee5fdf | 142 | // Initialise name to all 'A' characters. |
RichardE | 0:5fa232ee5fdf | 143 | for( UInt8 i = 0; i < PlayerName::Length; ++i ) { |
RichardE | 0:5fa232ee5fdf | 144 | name->Name[ i ] = 'A'; |
RichardE | 0:5fa232ee5fdf | 145 | } |
RichardE | 0:5fa232ee5fdf | 146 | // Draw screen. |
RichardE | 16:d0b142ba4362 | 147 | DrawScreen( gd, name ); |
RichardE | 0:5fa232ee5fdf | 148 | // Wait until player releases all controls. |
RichardE | 4:673eb9735d44 | 149 | WaitControls( gd, controls, false ); |
RichardE | 16:d0b142ba4362 | 150 | // Loop until player activates done cell. |
RichardE | 16:d0b142ba4362 | 151 | bool done = false; |
RichardE | 16:d0b142ba4362 | 152 | while( ! done ) { |
RichardE | 0:5fa232ee5fdf | 153 | // Read panel controls. |
RichardE | 0:5fa232ee5fdf | 154 | controls->Read(); |
RichardE | 0:5fa232ee5fdf | 155 | inputs = controls->GetInputs(); |
RichardE | 18:70190f956a24 | 156 | // Only react to joystick controls every so often to slow things down. |
RichardE | 0:5fa232ee5fdf | 157 | if( countdown == 0 ) { |
RichardE | 0:5fa232ee5fdf | 158 | countdown = 10; |
RichardE | 16:d0b142ba4362 | 159 | bool cursorMoved = false; |
RichardE | 16:d0b142ba4362 | 160 | // Point to current cell before changing. |
RichardE | 16:d0b142ba4362 | 161 | FieldCell *lastCell = grid.GetCellAt( cursorRow, cursorColumn ); |
RichardE | 0:5fa232ee5fdf | 162 | if( inputs & PanelControls::Up1 ) { |
RichardE | 16:d0b142ba4362 | 163 | // Joystick up moves cursor up. |
RichardE | 16:d0b142ba4362 | 164 | if( cursorRow > 0 ) { |
RichardE | 16:d0b142ba4362 | 165 | cursorRow--; |
RichardE | 16:d0b142ba4362 | 166 | ValidateCursorColumn(); |
RichardE | 16:d0b142ba4362 | 167 | cursorMoved = true; |
RichardE | 0:5fa232ee5fdf | 168 | } |
RichardE | 0:5fa232ee5fdf | 169 | } |
RichardE | 0:5fa232ee5fdf | 170 | else if( inputs & PanelControls::Down1 ) { |
RichardE | 16:d0b142ba4362 | 171 | // Joystick down moves cursor down. |
RichardE | 16:d0b142ba4362 | 172 | if( cursorRow < grid.GetRowCount() - 1 ) { |
RichardE | 16:d0b142ba4362 | 173 | cursorRow++; |
RichardE | 16:d0b142ba4362 | 174 | ValidateCursorColumn(); |
RichardE | 16:d0b142ba4362 | 175 | cursorMoved = true; |
RichardE | 0:5fa232ee5fdf | 176 | } |
RichardE | 0:5fa232ee5fdf | 177 | } |
RichardE | 16:d0b142ba4362 | 178 | if( inputs & PanelControls::Left1 ) { |
RichardE | 16:d0b142ba4362 | 179 | // Joystick left moves cursor left. |
RichardE | 16:d0b142ba4362 | 180 | if( cursorColumn > 0 ) { |
RichardE | 16:d0b142ba4362 | 181 | cursorColumn--; |
RichardE | 16:d0b142ba4362 | 182 | cursorMoved = true; |
RichardE | 0:5fa232ee5fdf | 183 | } |
RichardE | 0:5fa232ee5fdf | 184 | } |
RichardE | 0:5fa232ee5fdf | 185 | else if( inputs & PanelControls::Right1 ) { |
RichardE | 16:d0b142ba4362 | 186 | // Joystick right moves cursor right. |
RichardE | 16:d0b142ba4362 | 187 | FieldRow *row = grid.GetRow( cursorRow ); |
RichardE | 16:d0b142ba4362 | 188 | if( ( row != (FieldRow*)NULL ) && ( cursorColumn < row->GetColumnCount() - 1 ) ) { |
RichardE | 16:d0b142ba4362 | 189 | cursorColumn++; |
RichardE | 16:d0b142ba4362 | 190 | cursorMoved = true; |
RichardE | 16:d0b142ba4362 | 191 | } |
RichardE | 16:d0b142ba4362 | 192 | } |
RichardE | 16:d0b142ba4362 | 193 | // If necessary redraw the cursor. |
RichardE | 16:d0b142ba4362 | 194 | if( cursorMoved ) { |
RichardE | 16:d0b142ba4362 | 195 | WipeCursor( gd, lastCell ); |
RichardE | 16:d0b142ba4362 | 196 | DrawCursor( gd, grid.GetCellAt( cursorRow, cursorColumn ) ); |
RichardE | 0:5fa232ee5fdf | 197 | } |
RichardE | 0:5fa232ee5fdf | 198 | } |
RichardE | 0:5fa232ee5fdf | 199 | else { |
RichardE | 0:5fa232ee5fdf | 200 | countdown--; |
RichardE | 0:5fa232ee5fdf | 201 | } |
RichardE | 18:70190f956a24 | 202 | // Read button 1 on every loop to get instant response, |
RichardE | 18:70190f956a24 | 203 | if( inputs & PanelControls::Button1 ) { |
RichardE | 18:70190f956a24 | 204 | // Button 1 adds a character or possibly does something special. |
RichardE | 18:70190f956a24 | 205 | if( cursorRow < grid.GetRowCount() - 1 ) { |
RichardE | 18:70190f956a24 | 206 | char newChar = (char)( PlayerName::MinChar + cursorRow * GRIDCOLUMNS + cursorColumn ); |
RichardE | 18:70190f956a24 | 207 | name->Name[ charIndex ] = newChar; |
RichardE | 18:70190f956a24 | 208 | if( charIndex < PlayerName::Length - 1 ) { |
RichardE | 18:70190f956a24 | 209 | charIndex++; |
RichardE | 18:70190f956a24 | 210 | } |
RichardE | 18:70190f956a24 | 211 | } |
RichardE | 18:70190f956a24 | 212 | else { |
RichardE | 18:70190f956a24 | 213 | // Last row contains special functions. |
RichardE | 18:70190f956a24 | 214 | SpecialFunction( gd, cursorColumn, name, done ); |
RichardE | 18:70190f956a24 | 215 | } |
RichardE | 18:70190f956a24 | 216 | // Draw modified name. |
RichardE | 18:70190f956a24 | 217 | gd->waitvblank(); |
RichardE | 18:70190f956a24 | 218 | DrawName( gd, name ); |
RichardE | 18:70190f956a24 | 219 | // Wait until player releases all controls. |
RichardE | 18:70190f956a24 | 220 | WaitControls( gd, controls, false ); |
RichardE | 18:70190f956a24 | 221 | } |
RichardE | 16:d0b142ba4362 | 222 | // Wait for vertical flyback. Then do animation. |
RichardE | 4:673eb9735d44 | 223 | gd->waitvblank(); |
RichardE | 0:5fa232ee5fdf | 224 | FrameCounter++; |
RichardE | 4:673eb9735d44 | 225 | Animate( gd ); |
RichardE | 0:5fa232ee5fdf | 226 | } |
RichardE | 0:5fa232ee5fdf | 227 | // Wait until player releases all controls before returning. |
RichardE | 4:673eb9735d44 | 228 | WaitControls( gd, controls, false ); |
RichardE | 0:5fa232ee5fdf | 229 | } |
RichardE | 0:5fa232ee5fdf | 230 | |
RichardE | 17:194789db2215 | 231 | /************************************************************************/ |
RichardE | 17:194789db2215 | 232 | /* PERFORM A SPECIAL FUNCTION TRIGGERED FROM A CELL ON LAST ROW OF GRID */ |
RichardE | 17:194789db2215 | 233 | /************************************************************************/ |
RichardE | 17:194789db2215 | 234 | // Pass pointer to Gameduino to draw on in gd. |
RichardE | 17:194789db2215 | 235 | // Pass function number in funcNum (this is the cursor column number). |
RichardE | 17:194789db2215 | 236 | // Pass player name in name. |
RichardE | 17:194789db2215 | 237 | // Pass reference to done flag in done. |
RichardE | 17:194789db2215 | 238 | void HighScoreEntry::SpecialFunction( Gameduino *gd, UInt8 funcNum, PlayerName *name, bool &done ) { |
RichardE | 17:194789db2215 | 239 | switch( funcNum ) { |
RichardE | 17:194789db2215 | 240 | |
RichardE | 17:194789db2215 | 241 | case 0 : // DELETE function |
RichardE | 17:194789db2215 | 242 | if( charIndex > 0 ) { |
RichardE | 17:194789db2215 | 243 | name->Name[ charIndex-- ] = ' '; |
RichardE | 17:194789db2215 | 244 | } |
RichardE | 17:194789db2215 | 245 | break; |
RichardE | 17:194789db2215 | 246 | |
RichardE | 17:194789db2215 | 247 | case 1 : // ENTER function |
RichardE | 17:194789db2215 | 248 | done = true; |
RichardE | 17:194789db2215 | 249 | break; |
RichardE | 17:194789db2215 | 250 | |
RichardE | 17:194789db2215 | 251 | } |
RichardE | 17:194789db2215 | 252 | } |
RichardE | 17:194789db2215 | 253 | |
RichardE | 0:5fa232ee5fdf | 254 | /*********************/ |
RichardE | 0:5fa232ee5fdf | 255 | /* WAIT FOR CONTROLS */ |
RichardE | 0:5fa232ee5fdf | 256 | /*********************/ |
RichardE | 4:673eb9735d44 | 257 | // Pass pointer to Gameduino to display on in gd. |
RichardE | 0:5fa232ee5fdf | 258 | // Pass pointer to controls to read in controls. |
RichardE | 0:5fa232ee5fdf | 259 | // Pass true in waitActivate to wait for a control to be used. |
RichardE | 0:5fa232ee5fdf | 260 | // Pass false to wait for release. |
RichardE | 4:673eb9735d44 | 261 | void HighScoreEntry::WaitControls( Gameduino *gd, PanelControls *controls, bool waitActivate ) { |
RichardE | 4:673eb9735d44 | 262 | bool released = false; |
RichardE | 0:5fa232ee5fdf | 263 | UInt16 inputs; |
RichardE | 0:5fa232ee5fdf | 264 | while( ! released ) { |
RichardE | 0:5fa232ee5fdf | 265 | controls->Read(); |
RichardE | 0:5fa232ee5fdf | 266 | inputs = controls->GetInputs(); |
RichardE | 0:5fa232ee5fdf | 267 | released = ( waitActivate ? ( inputs != 0 ) : ( inputs == 0 ) ); |
RichardE | 0:5fa232ee5fdf | 268 | if( ! released ) { |
RichardE | 4:673eb9735d44 | 269 | gd->waitvblank(); |
RichardE | 0:5fa232ee5fdf | 270 | FrameCounter++; |
RichardE | 4:673eb9735d44 | 271 | Animate( gd ); |
RichardE | 0:5fa232ee5fdf | 272 | } |
RichardE | 0:5fa232ee5fdf | 273 | } |
RichardE | 0:5fa232ee5fdf | 274 | } |
RichardE | 0:5fa232ee5fdf | 275 | |
RichardE | 0:5fa232ee5fdf | 276 | /*******************/ |
RichardE | 0:5fa232ee5fdf | 277 | /* DRAW THE SCREEN */ |
RichardE | 0:5fa232ee5fdf | 278 | /*******************/ |
RichardE | 4:673eb9735d44 | 279 | // Pass pointer to Gameduino to draw on in gd. |
RichardE | 16:d0b142ba4362 | 280 | // Pass player name in name. |
RichardE | 16:d0b142ba4362 | 281 | void HighScoreEntry::DrawScreen( Gameduino *gd, PlayerName *name ) { |
RichardE | 4:673eb9735d44 | 282 | gd->waitvblank(); |
RichardE | 0:5fa232ee5fdf | 283 | // Clear the screen to zero characters. |
RichardE | 4:673eb9735d44 | 284 | gd->fill( Gameduino::RAM_PIC, 0, RAM_PIC_SIZE ); |
RichardE | 0:5fa232ee5fdf | 285 | // Turn off all the sprites. |
RichardE | 0:5fa232ee5fdf | 286 | for( UInt16 s = 0; s < SPRITE_COUNT; ++s ) { |
RichardE | 4:673eb9735d44 | 287 | gd->sprite( s, 0, 400, 0, 0 ); |
RichardE | 0:5fa232ee5fdf | 288 | } |
RichardE | 0:5fa232ee5fdf | 289 | // Draw border around screen. |
RichardE | 4:673eb9735d44 | 290 | CharFrame::Draw( gd, 0, 0, VISIBLE_CHAR_WIDTH, VISIBLE_CHAR_HEIGHT ); |
RichardE | 14:46a353b2a8e8 | 291 | // Draw instructions. |
RichardE | 14:46a353b2a8e8 | 292 | gd->putstr( 2, 2, " CONGRATULATIONS : YOU HAVE A HIGH SCORE!" ); |
RichardE | 14:46a353b2a8e8 | 293 | gd->putstr( 2, 4, "PLEASE ENTER YOUR NAME USING THE LEFT JOYSTICK" ); |
RichardE | 14:46a353b2a8e8 | 294 | gd->putstr( 2, 6, " TO MOVE THE CURSOR. PRESS THE LEFT BUTTON TO" ); |
RichardE | 17:194789db2215 | 295 | gd->putstr( 2, 8, " ENTER EACH LETTER. MOVE CURSOR TO \"ENTER\"" ); |
RichardE | 17:194789db2215 | 296 | gd->putstr( 2, 10, " AND PRESS LEFT BUTTON WHEN FINISHED." ); |
RichardE | 16:d0b142ba4362 | 297 | // Draw player's name. |
RichardE | 16:d0b142ba4362 | 298 | DrawName( gd, name ); |
RichardE | 14:46a353b2a8e8 | 299 | // Draw character grid. |
RichardE | 14:46a353b2a8e8 | 300 | DrawGrid( gd ); |
RichardE | 16:d0b142ba4362 | 301 | // Draw cursor. |
RichardE | 16:d0b142ba4362 | 302 | DrawCursor( gd, grid.GetCellAt( cursorRow, cursorColumn ) ); |
RichardE | 14:46a353b2a8e8 | 303 | } |
RichardE | 14:46a353b2a8e8 | 304 | |
RichardE | 14:46a353b2a8e8 | 305 | /***************************/ |
RichardE | 14:46a353b2a8e8 | 306 | /* DRAW THE CHARACTER GRID */ |
RichardE | 14:46a353b2a8e8 | 307 | /***************************/ |
RichardE | 14:46a353b2a8e8 | 308 | // Pass pointer to Gameduino to draw on in gd. |
RichardE | 14:46a353b2a8e8 | 309 | void HighScoreEntry::DrawGrid( Gameduino *gd ) { |
RichardE | 17:194789db2215 | 310 | // Draw rows containing characters. |
RichardE | 14:46a353b2a8e8 | 311 | UInt8 code = PlayerName::MinChar; |
RichardE | 14:46a353b2a8e8 | 312 | UInt8 x = GRIDX, y = GRIDY; |
RichardE | 14:46a353b2a8e8 | 313 | UInt8 columnNumber = 0; |
RichardE | 14:46a353b2a8e8 | 314 | char str [] = "X"; |
RichardE | 14:46a353b2a8e8 | 315 | while( code <= PlayerName::MaxChar ) { |
RichardE | 14:46a353b2a8e8 | 316 | str[ 0 ] = (char)code++; |
RichardE | 14:46a353b2a8e8 | 317 | gd->putstr( x, y, str ); |
RichardE | 14:46a353b2a8e8 | 318 | columnNumber++; |
RichardE | 14:46a353b2a8e8 | 319 | if( columnNumber >= GRIDCOLUMNS ) { |
RichardE | 14:46a353b2a8e8 | 320 | columnNumber = 0; |
RichardE | 14:46a353b2a8e8 | 321 | x = GRIDX; |
RichardE | 14:46a353b2a8e8 | 322 | y += GRIDROWSPACING; |
RichardE | 14:46a353b2a8e8 | 323 | } |
RichardE | 14:46a353b2a8e8 | 324 | else { |
RichardE | 14:46a353b2a8e8 | 325 | x += GRIDCOLUMNSPACING; |
RichardE | 14:46a353b2a8e8 | 326 | } |
RichardE | 14:46a353b2a8e8 | 327 | } |
RichardE | 17:194789db2215 | 328 | // Draw row containing special functions. |
RichardE | 17:194789db2215 | 329 | x = GRIDX; |
RichardE | 17:194789db2215 | 330 | y += GRIDROWSPACING; |
RichardE | 17:194789db2215 | 331 | gd->putstr( x, y, textDelete ); |
RichardE | 17:194789db2215 | 332 | x += ( strlen( textDelete ) + 1 ); |
RichardE | 17:194789db2215 | 333 | gd->putstr( x, y, textEnter ); |
RichardE | 0:5fa232ee5fdf | 334 | } |
RichardE | 0:5fa232ee5fdf | 335 | |
RichardE | 0:5fa232ee5fdf | 336 | /********************************/ |
RichardE | 0:5fa232ee5fdf | 337 | /* DRAW THE NAME AND THE CURSOR */ |
RichardE | 0:5fa232ee5fdf | 338 | /********************************/ |
RichardE | 4:673eb9735d44 | 339 | // Pass pointer to Gameduino to draw on in gd. |
RichardE | 0:5fa232ee5fdf | 340 | // Pass player name in name. |
RichardE | 4:673eb9735d44 | 341 | void HighScoreEntry::DrawName( Gameduino *gd, PlayerName *name ) { |
RichardE | 16:d0b142ba4362 | 342 | gd->putstr( 23, 13, name->Name ); |
RichardE | 16:d0b142ba4362 | 343 | UInt16 address = Gameduino::RAM_PIC + 14 * SCREEN_CHAR_WIDTH + 23; |
RichardE | 0:5fa232ee5fdf | 344 | for( UInt8 i = 0; i < PlayerName::Length; ++i ) { |
RichardE | 16:d0b142ba4362 | 345 | gd->wr( address, ( i == charIndex ) ? ArrowUp : ' ' ); |
RichardE | 0:5fa232ee5fdf | 346 | address++; |
RichardE | 0:5fa232ee5fdf | 347 | } |
RichardE | 0:5fa232ee5fdf | 348 | } |
RichardE | 0:5fa232ee5fdf | 349 | |
RichardE | 0:5fa232ee5fdf | 350 | /********************/ |
RichardE | 0:5fa232ee5fdf | 351 | /* UPDATE ANIMATION */ |
RichardE | 0:5fa232ee5fdf | 352 | /********************/ |
RichardE | 4:673eb9735d44 | 353 | // Pass pointer to Gameduino to display on in gd. |
RichardE | 4:673eb9735d44 | 354 | void HighScoreEntry::Animate( Gameduino *gd ) { |
RichardE | 0:5fa232ee5fdf | 355 | } |
RichardE | 16:d0b142ba4362 | 356 | |
RichardE | 16:d0b142ba4362 | 357 | /*******************/ |
RichardE | 16:d0b142ba4362 | 358 | /* WIPE THE CURSOR */ |
RichardE | 16:d0b142ba4362 | 359 | /*******************/ |
RichardE | 16:d0b142ba4362 | 360 | // Pass pointer to Gameduino to display on in gd. |
RichardE | 16:d0b142ba4362 | 361 | // Pass cell to draw in cell. |
RichardE | 16:d0b142ba4362 | 362 | void HighScoreEntry::WipeCursor( Gameduino *gd, FieldCell *cell ) { |
RichardE | 16:d0b142ba4362 | 363 | if( cell != (FieldCell*)NULL ) { |
RichardE | 16:d0b142ba4362 | 364 | CharFrame::Wipe( gd, cell->Rect.X1, cell->Rect.Y1, cell->Rect.GetWidth(), cell->Rect.GetHeight() ); |
RichardE | 16:d0b142ba4362 | 365 | } |
RichardE | 16:d0b142ba4362 | 366 | } |
RichardE | 16:d0b142ba4362 | 367 | |
RichardE | 16:d0b142ba4362 | 368 | /*******************/ |
RichardE | 16:d0b142ba4362 | 369 | /* DRAW THE CURSOR */ |
RichardE | 16:d0b142ba4362 | 370 | /*******************/ |
RichardE | 16:d0b142ba4362 | 371 | // Pass pointer to Gameduino to display on in gd. |
RichardE | 16:d0b142ba4362 | 372 | // Pass cell to draw in cell. |
RichardE | 16:d0b142ba4362 | 373 | void HighScoreEntry::DrawCursor( Gameduino *gd, FieldCell *cell ) { |
RichardE | 16:d0b142ba4362 | 374 | if( cell != (FieldCell*)NULL ) { |
RichardE | 16:d0b142ba4362 | 375 | CharFrame::Draw( gd, cell->Rect.X1, cell->Rect.Y1, cell->Rect.GetWidth(), cell->Rect.GetHeight() ); |
RichardE | 16:d0b142ba4362 | 376 | } |
RichardE | 16:d0b142ba4362 | 377 | } |
RichardE | 16:d0b142ba4362 | 378 | |
RichardE | 16:d0b142ba4362 | 379 | /**************************/ |
RichardE | 16:d0b142ba4362 | 380 | /* VALIDATE CURSOR COLUMN */ |
RichardE | 16:d0b142ba4362 | 381 | /**************************/ |
RichardE | 16:d0b142ba4362 | 382 | // If cursor column is beyond end of row then forces it back. |
RichardE | 16:d0b142ba4362 | 383 | void HighScoreEntry::ValidateCursorColumn( void ) { |
RichardE | 16:d0b142ba4362 | 384 | FieldRow *row = grid.GetRow( cursorRow ); |
RichardE | 16:d0b142ba4362 | 385 | if( row != (FieldRow*)NULL ) { |
RichardE | 16:d0b142ba4362 | 386 | UInt8 columnCount = row->GetColumnCount(); |
RichardE | 16:d0b142ba4362 | 387 | if( cursorColumn >= columnCount ) { |
RichardE | 16:d0b142ba4362 | 388 | cursorColumn = columnCount - 1; |
RichardE | 16:d0b142ba4362 | 389 | } |
RichardE | 16:d0b142ba4362 | 390 | } |
RichardE | 16:d0b142ba4362 | 391 | } |