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
GDExtra.cpp@18:70190f956a24, 2013-06-17 (annotated)
- Committer:
- RichardE
- Date:
- Mon Jun 17 15:10:43 2013 +0000
- Revision:
- 18:70190f956a24
- Parent:
- 1:dfd5eaaf96a3
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 | 1:dfd5eaaf96a3 | 1 | /* |
RichardE | 1:dfd5eaaf96a3 | 2 | * SOURCE FILE : GDExtra.cpp |
RichardE | 1:dfd5eaaf96a3 | 3 | * |
RichardE | 1:dfd5eaaf96a3 | 4 | * Additional routines for the Gameduino. |
RichardE | 1:dfd5eaaf96a3 | 5 | * |
RichardE | 1:dfd5eaaf96a3 | 6 | */ |
RichardE | 1:dfd5eaaf96a3 | 7 | |
RichardE | 1:dfd5eaaf96a3 | 8 | #include "GDExtra.h" |
RichardE | 1:dfd5eaaf96a3 | 9 | #include "GDConst.h" |
RichardE | 1:dfd5eaaf96a3 | 10 | |
RichardE | 1:dfd5eaaf96a3 | 11 | /*********************************************/ |
RichardE | 1:dfd5eaaf96a3 | 12 | /* DISPLAY A STRING STORED IN PROGRAM MEMORY */ |
RichardE | 1:dfd5eaaf96a3 | 13 | /*********************************************/ |
RichardE | 1:dfd5eaaf96a3 | 14 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 15 | // Pass coordinates in x and y. |
RichardE | 1:dfd5eaaf96a3 | 16 | // Pass address of string in s. |
RichardE | 1:dfd5eaaf96a3 | 17 | void GDExtra::WriteProgString( Gameduino *gd, UInt8 x, UInt8 y, const char *s ) { |
RichardE | 1:dfd5eaaf96a3 | 18 | UInt16 address = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x; |
RichardE | 1:dfd5eaaf96a3 | 19 | while( *s != 0 ) { |
RichardE | 1:dfd5eaaf96a3 | 20 | gd->wr( address++, *s++ ); |
RichardE | 1:dfd5eaaf96a3 | 21 | } |
RichardE | 1:dfd5eaaf96a3 | 22 | } |
RichardE | 1:dfd5eaaf96a3 | 23 | |
RichardE | 1:dfd5eaaf96a3 | 24 | /*******************************/ |
RichardE | 1:dfd5eaaf96a3 | 25 | /* DISPLAY AN UNSIGNED INTEGER */ |
RichardE | 1:dfd5eaaf96a3 | 26 | /*******************************/ |
RichardE | 1:dfd5eaaf96a3 | 27 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 28 | // Pass coordinates in x and y. |
RichardE | 1:dfd5eaaf96a3 | 29 | // Pass number to write in num. |
RichardE | 1:dfd5eaaf96a3 | 30 | // Pass numeric base in base. |
RichardE | 1:dfd5eaaf96a3 | 31 | // Pass number of digits to write in digits. |
RichardE | 1:dfd5eaaf96a3 | 32 | void GDExtra::WriteUInt16( Gameduino *gd, UInt8 x, UInt8 y, UInt16 num, UInt8 base, UInt8 digits ) { |
RichardE | 1:dfd5eaaf96a3 | 33 | UInt16 address = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x + digits - 1; |
RichardE | 1:dfd5eaaf96a3 | 34 | UInt8 dig; |
RichardE | 1:dfd5eaaf96a3 | 35 | while( digits > 0 ) { |
RichardE | 1:dfd5eaaf96a3 | 36 | dig = num % base; |
RichardE | 1:dfd5eaaf96a3 | 37 | if( dig < 10 ) { |
RichardE | 1:dfd5eaaf96a3 | 38 | gd->wr( address--, '0' + dig ); |
RichardE | 1:dfd5eaaf96a3 | 39 | } |
RichardE | 1:dfd5eaaf96a3 | 40 | else { |
RichardE | 1:dfd5eaaf96a3 | 41 | gd->wr( address--, 'A' + dig ); |
RichardE | 1:dfd5eaaf96a3 | 42 | } |
RichardE | 1:dfd5eaaf96a3 | 43 | num /= base; |
RichardE | 1:dfd5eaaf96a3 | 44 | digits--; |
RichardE | 1:dfd5eaaf96a3 | 45 | } |
RichardE | 1:dfd5eaaf96a3 | 46 | } |
RichardE | 1:dfd5eaaf96a3 | 47 | |
RichardE | 1:dfd5eaaf96a3 | 48 | /************************/ |
RichardE | 1:dfd5eaaf96a3 | 49 | /* DISPLAY A BCD NUMBER */ |
RichardE | 1:dfd5eaaf96a3 | 50 | /************************/ |
RichardE | 1:dfd5eaaf96a3 | 51 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 52 | // Pass coordinates in x and y. |
RichardE | 1:dfd5eaaf96a3 | 53 | // Pass number to write in num. |
RichardE | 1:dfd5eaaf96a3 | 54 | // Pass number of digits to write in digits. |
RichardE | 1:dfd5eaaf96a3 | 55 | void GDExtra::WriteBCDNumber( Gameduino *gd, UInt8 x, UInt8 y, UInt32 num, UInt8 digits ) { |
RichardE | 1:dfd5eaaf96a3 | 56 | UInt16 address = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x + digits - 1; |
RichardE | 1:dfd5eaaf96a3 | 57 | while( digits > 0 ) { |
RichardE | 1:dfd5eaaf96a3 | 58 | gd->wr( address--, '0' + ( num & 0xF ) ); |
RichardE | 1:dfd5eaaf96a3 | 59 | num >>= 4; |
RichardE | 1:dfd5eaaf96a3 | 60 | digits--; |
RichardE | 1:dfd5eaaf96a3 | 61 | } |
RichardE | 1:dfd5eaaf96a3 | 62 | } |
RichardE | 1:dfd5eaaf96a3 | 63 | |
RichardE | 1:dfd5eaaf96a3 | 64 | /******************************************************/ |
RichardE | 1:dfd5eaaf96a3 | 65 | /* DISPLAY A CHARACTER BLOCK STORED IN PROGRAM MEMORY */ |
RichardE | 1:dfd5eaaf96a3 | 66 | /******************************************************/ |
RichardE | 1:dfd5eaaf96a3 | 67 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 68 | // Pass coordinates in x and y. |
RichardE | 1:dfd5eaaf96a3 | 69 | // Pass address of character block in bPtr. |
RichardE | 1:dfd5eaaf96a3 | 70 | // Address points to the width of the block, followed by the height of |
RichardE | 1:dfd5eaaf96a3 | 71 | // the block and then the character codes that make up the block. |
RichardE | 1:dfd5eaaf96a3 | 72 | void GDExtra::WriteProgCharBlock( Gameduino *gd, UInt8 x, UInt8 y, const UInt8 *bPtr ) { |
RichardE | 1:dfd5eaaf96a3 | 73 | // Calculate address for top left of block. |
RichardE | 1:dfd5eaaf96a3 | 74 | UInt16 address = Gameduino::RAM_PIC + y * SCREEN_CHAR_WIDTH + x; |
RichardE | 1:dfd5eaaf96a3 | 75 | // Fetch width and height from program memory. |
RichardE | 1:dfd5eaaf96a3 | 76 | UInt8 width = *bPtr++; |
RichardE | 1:dfd5eaaf96a3 | 77 | UInt8 height = *bPtr++; |
RichardE | 1:dfd5eaaf96a3 | 78 | // Write rows of data to screen. |
RichardE | 1:dfd5eaaf96a3 | 79 | for( int row = 0; row < height; ++row ) { |
RichardE | 1:dfd5eaaf96a3 | 80 | gd->copy( address, (prog_uchar*)bPtr, width ); |
RichardE | 1:dfd5eaaf96a3 | 81 | address += SCREEN_CHAR_WIDTH; |
RichardE | 1:dfd5eaaf96a3 | 82 | bPtr += width; |
RichardE | 1:dfd5eaaf96a3 | 83 | } |
RichardE | 1:dfd5eaaf96a3 | 84 | } |
RichardE | 1:dfd5eaaf96a3 | 85 | |
RichardE | 1:dfd5eaaf96a3 | 86 | /****************/ |
RichardE | 1:dfd5eaaf96a3 | 87 | /* CLEAR SCREEN */ |
RichardE | 1:dfd5eaaf96a3 | 88 | /****************/ |
RichardE | 1:dfd5eaaf96a3 | 89 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 90 | // Writes all character RAM with given character code. |
RichardE | 1:dfd5eaaf96a3 | 91 | void GDExtra::ClearScreen( Gameduino *gd, UInt8 code ) { |
RichardE | 1:dfd5eaaf96a3 | 92 | gd->fill( Gameduino::RAM_PIC, code, RAM_PIC_SIZE ); |
RichardE | 1:dfd5eaaf96a3 | 93 | } |
RichardE | 1:dfd5eaaf96a3 | 94 | |
RichardE | 1:dfd5eaaf96a3 | 95 | /************************/ |
RichardE | 1:dfd5eaaf96a3 | 96 | /* HIDE A SINGLE SPRITE */ |
RichardE | 1:dfd5eaaf96a3 | 97 | /************************/ |
RichardE | 1:dfd5eaaf96a3 | 98 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 99 | // Pass sprite number in spriteNumber parameter. |
RichardE | 1:dfd5eaaf96a3 | 100 | void GDExtra::HideSprite( Gameduino *gd, UInt8 spriteNumber ) { |
RichardE | 1:dfd5eaaf96a3 | 101 | gd->sprite( spriteNumber, 0, 400, 0, 0 ); |
RichardE | 1:dfd5eaaf96a3 | 102 | } |
RichardE | 1:dfd5eaaf96a3 | 103 | |
RichardE | 1:dfd5eaaf96a3 | 104 | /********************/ |
RichardE | 1:dfd5eaaf96a3 | 105 | /* HIDE ALL SPRITES */ |
RichardE | 1:dfd5eaaf96a3 | 106 | /********************/ |
RichardE | 1:dfd5eaaf96a3 | 107 | // Pass pointer to a Gameduino in gd. |
RichardE | 1:dfd5eaaf96a3 | 108 | void GDExtra::HideAllSprites( Gameduino *gd ) { |
RichardE | 1:dfd5eaaf96a3 | 109 | // This code comes from the Cookbook section of the Gameduino |
RichardE | 1:dfd5eaaf96a3 | 110 | // website. Look for the entry entitled "Hiding sprites". |
RichardE | 1:dfd5eaaf96a3 | 111 | gd->__wstartspr(0); // start writing sprites at slot 0 |
RichardE | 1:dfd5eaaf96a3 | 112 | // Now hide all the remaining sprites. |
RichardE | 1:dfd5eaaf96a3 | 113 | // Actually this does not hide sprite number 255. |
RichardE | 1:dfd5eaaf96a3 | 114 | // If you used SPRITE_COUNT instead of SPRITE_COUNT - 1 then |
RichardE | 1:dfd5eaaf96a3 | 115 | // you end up with an endless loop because gd->spr is a byte |
RichardE | 1:dfd5eaaf96a3 | 116 | // and is always less than SPRITE_COUNT since SPRITE_COUNT is 256. |
RichardE | 1:dfd5eaaf96a3 | 117 | while( gd->spr < SPRITE_COUNT - 1 ) { |
RichardE | 1:dfd5eaaf96a3 | 118 | gd->xhide(); |
RichardE | 1:dfd5eaaf96a3 | 119 | } |
RichardE | 1:dfd5eaaf96a3 | 120 | gd->__end(); |
RichardE | 1:dfd5eaaf96a3 | 121 | } |