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
CharFrame.cpp@18:70190f956a24, 2013-06-17 (annotated)
- Committer:
- RichardE
- Date:
- Mon Jun 17 15:10:43 2013 +0000
- Revision:
- 18:70190f956a24
- Parent:
- 16:d0b142ba4362
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 | 2:bb0f631a6068 | 1 | /* |
RichardE | 2:bb0f631a6068 | 2 | * SOURCE FILE : CharFrame.cpp |
RichardE | 2:bb0f631a6068 | 3 | * |
RichardE | 2:bb0f631a6068 | 4 | * For drawing rectangular frames using characters. |
RichardE | 2:bb0f631a6068 | 5 | * |
RichardE | 2:bb0f631a6068 | 6 | */ |
RichardE | 2:bb0f631a6068 | 7 | |
RichardE | 2:bb0f631a6068 | 8 | #include "CharFrame.h" |
RichardE | 2:bb0f631a6068 | 9 | #include "GDConst.h" // a few Gameduino constants |
RichardE | 2:bb0f631a6068 | 10 | #include "CharCodes.h" // character set codes |
RichardE | 2:bb0f631a6068 | 11 | |
RichardE | 2:bb0f631a6068 | 12 | /****************/ |
RichardE | 2:bb0f631a6068 | 13 | /* DRAW A FRAME */ |
RichardE | 2:bb0f631a6068 | 14 | /****************/ |
RichardE | 2:bb0f631a6068 | 15 | // Pass Gameduino to draw on in gd. |
RichardE | 2:bb0f631a6068 | 16 | // Pass x coordinate of top left in x. |
RichardE | 2:bb0f631a6068 | 17 | // Pass y coordinate of top left in y. |
RichardE | 2:bb0f631a6068 | 18 | // Pass width in w. |
RichardE | 2:bb0f631a6068 | 19 | // Pass height in h. |
RichardE | 2:bb0f631a6068 | 20 | void CharFrame::Draw( Gameduino *gd, UInt8 x, UInt8 y, UInt8 w, UInt8 h ) { |
RichardE | 2:bb0f631a6068 | 21 | // Calculate address for top left. |
RichardE | 2:bb0f631a6068 | 22 | unsigned int rowStart = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x; |
RichardE | 2:bb0f631a6068 | 23 | unsigned int address = rowStart; |
RichardE | 2:bb0f631a6068 | 24 | UInt8 count; |
RichardE | 2:bb0f631a6068 | 25 | // Draw top left corner. |
RichardE | 2:bb0f631a6068 | 26 | gd->wr( address++, TopLeft ); |
RichardE | 2:bb0f631a6068 | 27 | // Draw top edge. |
RichardE | 2:bb0f631a6068 | 28 | if( w > 2 ) { |
RichardE | 2:bb0f631a6068 | 29 | for( count = w - 2; count > 0; --count ) { |
RichardE | 2:bb0f631a6068 | 30 | gd->wr( address++, Top ); |
RichardE | 2:bb0f631a6068 | 31 | } |
RichardE | 2:bb0f631a6068 | 32 | } |
RichardE | 2:bb0f631a6068 | 33 | // Draw top right corner. |
RichardE | 2:bb0f631a6068 | 34 | gd->wr( address, TopRight ); |
RichardE | 2:bb0f631a6068 | 35 | // Draw left and right edges. |
RichardE | 2:bb0f631a6068 | 36 | rowStart += SCREEN_CHAR_WIDTH; |
RichardE | 2:bb0f631a6068 | 37 | if( h > 2 ) { |
RichardE | 2:bb0f631a6068 | 38 | for( count = h - 2; count > 0; --count ) { |
RichardE | 2:bb0f631a6068 | 39 | gd->wr( rowStart, Left ); |
RichardE | 2:bb0f631a6068 | 40 | gd->wr( rowStart + w - 1, Right ); |
RichardE | 2:bb0f631a6068 | 41 | rowStart += SCREEN_CHAR_WIDTH; |
RichardE | 2:bb0f631a6068 | 42 | } |
RichardE | 2:bb0f631a6068 | 43 | } |
RichardE | 2:bb0f631a6068 | 44 | // Draw bottom edge. |
RichardE | 2:bb0f631a6068 | 45 | address = rowStart; |
RichardE | 2:bb0f631a6068 | 46 | // Draw bottom left corner. |
RichardE | 2:bb0f631a6068 | 47 | gd->wr( address++, BottomLeft ); |
RichardE | 2:bb0f631a6068 | 48 | // Draw bottom edge. |
RichardE | 2:bb0f631a6068 | 49 | if( w > 2 ) { |
RichardE | 2:bb0f631a6068 | 50 | for( count = w - 2; count > 0; --count ) { |
RichardE | 2:bb0f631a6068 | 51 | gd->wr( address++, Bottom ); |
RichardE | 2:bb0f631a6068 | 52 | } |
RichardE | 2:bb0f631a6068 | 53 | } |
RichardE | 2:bb0f631a6068 | 54 | // Draw bottom right corner. |
RichardE | 2:bb0f631a6068 | 55 | gd->wr( address, BottomRight ); |
RichardE | 2:bb0f631a6068 | 56 | } |
RichardE | 2:bb0f631a6068 | 57 | |
RichardE | 16:d0b142ba4362 | 58 | /****************/ |
RichardE | 16:d0b142ba4362 | 59 | /* WIPE A FRAME */ |
RichardE | 16:d0b142ba4362 | 60 | /****************/ |
RichardE | 16:d0b142ba4362 | 61 | // Pass Gameduino to draw on in gd. |
RichardE | 16:d0b142ba4362 | 62 | // Pass x coordinate of top left in x. |
RichardE | 16:d0b142ba4362 | 63 | // Pass y coordinate of top left in y. |
RichardE | 16:d0b142ba4362 | 64 | // Pass width in w. |
RichardE | 16:d0b142ba4362 | 65 | // Pass height in h. |
RichardE | 16:d0b142ba4362 | 66 | void CharFrame::Wipe( Gameduino *gd, UInt8 x, UInt8 y, UInt8 w, UInt8 h ) { |
RichardE | 16:d0b142ba4362 | 67 | // Calculate address for top left. |
RichardE | 16:d0b142ba4362 | 68 | unsigned int rowStart = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x; |
RichardE | 16:d0b142ba4362 | 69 | unsigned int address; |
RichardE | 16:d0b142ba4362 | 70 | UInt8 count; |
RichardE | 16:d0b142ba4362 | 71 | // Wipe top edge. |
RichardE | 16:d0b142ba4362 | 72 | address = rowStart; |
RichardE | 16:d0b142ba4362 | 73 | for( count = w; count > 0; --count ) { |
RichardE | 16:d0b142ba4362 | 74 | gd->wr( address++, TransparentChar ); |
RichardE | 16:d0b142ba4362 | 75 | } |
RichardE | 16:d0b142ba4362 | 76 | // Wipe left and right edges. |
RichardE | 16:d0b142ba4362 | 77 | address = rowStart + SCREEN_CHAR_WIDTH; |
RichardE | 16:d0b142ba4362 | 78 | if( h > 2 ) { |
RichardE | 16:d0b142ba4362 | 79 | for( count = h - 2; count > 0; --count ) { |
RichardE | 16:d0b142ba4362 | 80 | gd->wr( address, TransparentChar ); |
RichardE | 16:d0b142ba4362 | 81 | gd->wr( address + w - 1, TransparentChar ); |
RichardE | 16:d0b142ba4362 | 82 | } |
RichardE | 16:d0b142ba4362 | 83 | } |
RichardE | 16:d0b142ba4362 | 84 | // Wipe bottom edge. |
RichardE | 16:d0b142ba4362 | 85 | address = rowStart + SCREEN_CHAR_WIDTH * ( h - 1 ); |
RichardE | 16:d0b142ba4362 | 86 | for( count = w; count > 0; --count ) { |
RichardE | 16:d0b142ba4362 | 87 | gd->wr( address++, TransparentChar ); |
RichardE | 16:d0b142ba4362 | 88 | } |
RichardE | 16:d0b142ba4362 | 89 | } |