Game entry for the Game Programming Contest sponsored by OutrageousCircuits.com (RETRO Game Console)
Fork of Official_RETRO by
Game.cpp@4:2d41b942a823, 2015-03-01 (annotated)
- Committer:
- Rogerup
- Date:
- Sun Mar 01 09:34:29 2015 +0000
- Revision:
- 4:2d41b942a823
- Parent:
- 3:7680307a02d7
Game Entry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
john_ghielec | 1:cd8a3926f263 | 1 | #include "Game.h" |
Rogerup | 4:2d41b942a823 | 2 | #include <cstdarg> |
Rogerup | 4:2d41b942a823 | 3 | |
Rogerup | 4:2d41b942a823 | 4 | #define SOUNDWIN 1 |
john_ghielec | 1:cd8a3926f263 | 5 | |
Rogerup | 4:2d41b942a823 | 6 | unsigned short piececolor[5] = { 0, LGRAY, WHITE, WHITE, DGRAY }; |
Rogerup | 4:2d41b942a823 | 7 | |
Rogerup | 4:2d41b942a823 | 8 | Game::Game() : left(P0_14, PullUp), right(P0_11, PullUp), down(P0_12, PullUp), up(P0_13, PullUp), square(P0_16, PullUp), circle(P0_1, PullUp), led1(P0_9), led2(P0_8), pwm(P0_18), ain(P0_15), i2c(P0_5, P0_4) |
Rogerup | 4:2d41b942a823 | 9 | { |
john_ghielec | 1:cd8a3926f263 | 10 | this->initialize(); |
john_ghielec | 1:cd8a3926f263 | 11 | } |
john_ghielec | 1:cd8a3926f263 | 12 | |
Rogerup | 4:2d41b942a823 | 13 | void Game::showNumber(int y, int val) |
Rogerup | 4:2d41b942a823 | 14 | { |
Rogerup | 4:2d41b942a823 | 15 | char buf[8]; |
Rogerup | 4:2d41b942a823 | 16 | int len = sprintf(buf, "%d", val); |
Rogerup | 4:2d41b942a823 | 17 | |
Rogerup | 4:2d41b942a823 | 18 | disp.fillRect( 128, y+9, 32, 8, BLACK ); |
Rogerup | 4:2d41b942a823 | 19 | |
Rogerup | 4:2d41b942a823 | 20 | if( val < 1000 ) |
Rogerup | 4:2d41b942a823 | 21 | disp.drawString(145-len*3, y+9, buf, CYAN, BLACK); |
Rogerup | 4:2d41b942a823 | 22 | else |
Rogerup | 4:2d41b942a823 | 23 | disp.drawString(145-3*3, y+9, "...", CYAN, BLACK); |
john_ghielec | 2:6ab46f2e851a | 24 | } |
john_ghielec | 2:6ab46f2e851a | 25 | |
Rogerup | 4:2d41b942a823 | 26 | void Game::initialize() |
Rogerup | 4:2d41b942a823 | 27 | { |
Rogerup | 4:2d41b942a823 | 28 | disp.clear(); |
Rogerup | 4:2d41b942a823 | 29 | led1 = 0; led2 = 0; |
Rogerup | 4:2d41b942a823 | 30 | pwm = 0; pwm.period_ms(1); |
Rogerup | 4:2d41b942a823 | 31 | |
Rogerup | 4:2d41b942a823 | 32 | tickCounter = 1000; |
Rogerup | 4:2d41b942a823 | 33 | tickWin = 0; |
Rogerup | 4:2d41b942a823 | 34 | bamTicksLeft = 0; |
Rogerup | 4:2d41b942a823 | 35 | |
Rogerup | 4:2d41b942a823 | 36 | level = 0; oldLevel = -1; |
Rogerup | 4:2d41b942a823 | 37 | for( int lev=0; lev<L_LAST; lev++ ) |
Rogerup | 4:2d41b942a823 | 38 | your[lev] = 10000; |
Rogerup | 4:2d41b942a823 | 39 | |
Rogerup | 4:2d41b942a823 | 40 | initTable(); |
john_ghielec | 2:6ab46f2e851a | 41 | } |
john_ghielec | 2:6ab46f2e851a | 42 | |
Rogerup | 4:2d41b942a823 | 43 | void Game::tick() |
Rogerup | 4:2d41b942a823 | 44 | { |
Rogerup | 4:2d41b942a823 | 45 | tickCounter++; |
Rogerup | 4:2d41b942a823 | 46 | |
Rogerup | 4:2d41b942a823 | 47 | playSound(); |
john_ghielec | 2:6ab46f2e851a | 48 | |
Rogerup | 4:2d41b942a823 | 49 | if( levelCompleted ) { |
Rogerup | 4:2d41b942a823 | 50 | if( (tickCounter % 40) == 0 ) { led1 = 1; led2 = 0; } |
Rogerup | 4:2d41b942a823 | 51 | if( (tickCounter % 40) == 20 ) { led1 = 0; led2 = 1; } |
Rogerup | 4:2d41b942a823 | 52 | } |
Rogerup | 4:2d41b942a823 | 53 | |
Rogerup | 4:2d41b942a823 | 54 | checkButtons(); |
Rogerup | 4:2d41b942a823 | 55 | if( level != L_INTRO) |
Rogerup | 4:2d41b942a823 | 56 | showTable(); |
Rogerup | 4:2d41b942a823 | 57 | |
Rogerup | 4:2d41b942a823 | 58 | playBam(); |
Rogerup | 4:2d41b942a823 | 59 | |
Rogerup | 4:2d41b942a823 | 60 | wait_ms(25); |
john_ghielec | 2:6ab46f2e851a | 61 | } |
john_ghielec | 2:6ab46f2e851a | 62 | |
Rogerup | 4:2d41b942a823 | 63 | void Game::checkButtons() |
Rogerup | 4:2d41b942a823 | 64 | { |
Rogerup | 4:2d41b942a823 | 65 | bool kSquare = false, kCircle = false, kUp = false, kDown = false, kLeft = false, kRight = false; |
john_ghielec | 2:6ab46f2e851a | 66 | |
Rogerup | 4:2d41b942a823 | 67 | // |
Rogerup | 4:2d41b942a823 | 68 | // Repeat key after 16*25ms = 400ms |
Rogerup | 4:2d41b942a823 | 69 | // |
Rogerup | 4:2d41b942a823 | 70 | char noKey = 0; |
Rogerup | 4:2d41b942a823 | 71 | if( !square.read() ) kSquare = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 72 | if( !circle.read() ) kCircle = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 73 | if( !up.read() ) kUp = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 74 | if( !down.read() ) kDown = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 75 | if( !left.read() ) kLeft = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 76 | if( !right.read() ) kRight = !lastKey; else noKey++; |
Rogerup | 4:2d41b942a823 | 77 | if( noKey < 6 ) { |
Rogerup | 4:2d41b942a823 | 78 | if( lastKey == 0 ) lastKey = 16; else lastKey--; |
Rogerup | 4:2d41b942a823 | 79 | } else |
Rogerup | 4:2d41b942a823 | 80 | lastKey = 0; |
john_ghielec | 2:6ab46f2e851a | 81 | |
Rogerup | 4:2d41b942a823 | 82 | // |
Rogerup | 4:2d41b942a823 | 83 | // Select level |
Rogerup | 4:2d41b942a823 | 84 | // |
Rogerup | 4:2d41b942a823 | 85 | if( kSquare ) if( ++level > L_LAST ) level = L_INTRO; |
Rogerup | 4:2d41b942a823 | 86 | if( kCircle ) if( --level < L_INTRO ) level = L_INTRO + 1; //L_LAST; |
Rogerup | 4:2d41b942a823 | 87 | if( kSquare || kCircle || (!up.read() && !left.read()) ) |
Rogerup | 4:2d41b942a823 | 88 | initTable(); |
Rogerup | 4:2d41b942a823 | 89 | |
Rogerup | 4:2d41b942a823 | 90 | // |
Rogerup | 4:2d41b942a823 | 91 | // Arrow keys to move |
Rogerup | 4:2d41b942a823 | 92 | // |
Rogerup | 4:2d41b942a823 | 93 | if( kUp ) moveTable( -1, 0, 1, TABH, 0, TABW ); |
Rogerup | 4:2d41b942a823 | 94 | if( kDown ) moveTable( 1, 0, TABH-2, -1, 0, TABW ); |
Rogerup | 4:2d41b942a823 | 95 | if( kLeft ) moveTable( 0, -1, 0, TABH, 1, TABW ); |
Rogerup | 4:2d41b942a823 | 96 | if( kRight ) moveTable( 0, 1, 0, TABH, TABW-2, -1 ); |
john_ghielec | 2:6ab46f2e851a | 97 | } |
john_ghielec | 2:6ab46f2e851a | 98 | |
Rogerup | 4:2d41b942a823 | 99 | void Game::fillTable(char i0, char j0, char h, char w, unsigned char v) |
Rogerup | 4:2d41b942a823 | 100 | { |
Rogerup | 4:2d41b942a823 | 101 | unsigned char nh = v & 0xF0; |
Rogerup | 4:2d41b942a823 | 102 | unsigned char nl = v & 0x0F; |
Rogerup | 4:2d41b942a823 | 103 | |
Rogerup | 4:2d41b942a823 | 104 | for( int i=i0; i<i0+h; i++ ) |
Rogerup | 4:2d41b942a823 | 105 | for( int j=j0; j<j0+w; j++ ) { |
Rogerup | 4:2d41b942a823 | 106 | if( v <= BONG ) { |
Rogerup | 4:2d41b942a823 | 107 | table[i][j] = v; |
Rogerup | 4:2d41b942a823 | 108 | } else { |
Rogerup | 4:2d41b942a823 | 109 | if( nh && table[i][j] <= BONG ) table[i][j] = FREE; |
Rogerup | 4:2d41b942a823 | 110 | if( nh ) table[i][j] = (table[i][j] & 0x0F) | nh; |
Rogerup | 4:2d41b942a823 | 111 | if( nl ) table[i][j] = (table[i][j] & 0xF0) | nl; |
Rogerup | 4:2d41b942a823 | 112 | } |
Rogerup | 4:2d41b942a823 | 113 | |
Rogerup | 4:2d41b942a823 | 114 | if( nl > MARK ) nl += 0x01; |
Rogerup | 4:2d41b942a823 | 115 | if( nh > BALL ) nh += 0x10; |
Rogerup | 4:2d41b942a823 | 116 | |
Rogerup | 4:2d41b942a823 | 117 | change[i] |= 1 << j; |
Rogerup | 4:2d41b942a823 | 118 | } |
john_ghielec | 2:6ab46f2e851a | 119 | } |
john_ghielec | 2:6ab46f2e851a | 120 | |
Rogerup | 4:2d41b942a823 | 121 | void Game::fillTableV( unsigned char v, ...) |
Rogerup | 4:2d41b942a823 | 122 | { |
Rogerup | 4:2d41b942a823 | 123 | unsigned short pos; |
Rogerup | 4:2d41b942a823 | 124 | |
Rogerup | 4:2d41b942a823 | 125 | va_list arguments; |
Rogerup | 4:2d41b942a823 | 126 | |
Rogerup | 4:2d41b942a823 | 127 | va_start ( arguments, v ); |
Rogerup | 4:2d41b942a823 | 128 | |
Rogerup | 4:2d41b942a823 | 129 | while( (pos = (unsigned short)va_arg ( arguments, int)) != 0 ) { |
Rogerup | 4:2d41b942a823 | 130 | unsigned char h = (pos & 0x00F0) >> 4; |
Rogerup | 4:2d41b942a823 | 131 | unsigned char w = (pos & 0x000F) >> 0; |
Rogerup | 4:2d41b942a823 | 132 | if( w == 0 ) w = 16; |
Rogerup | 4:2d41b942a823 | 133 | |
Rogerup | 4:2d41b942a823 | 134 | fillTable((pos&0xF000)>>12, (pos&0x0F00)>>8, h, w, v); |
Rogerup | 4:2d41b942a823 | 135 | if( (v&0x0F) > MARK ) v += h*w; |
Rogerup | 4:2d41b942a823 | 136 | if( v > BALL ) v += ((h*w) << 4); |
john_ghielec | 2:6ab46f2e851a | 137 | } |
Rogerup | 4:2d41b942a823 | 138 | |
Rogerup | 4:2d41b942a823 | 139 | va_end ( arguments ); |
john_ghielec | 2:6ab46f2e851a | 140 | } |
john_ghielec | 2:6ab46f2e851a | 141 | |
Rogerup | 4:2d41b942a823 | 142 | void Game::moveTable(int di, int dj, int i0, int i2, int j0, int j2 ) |
Rogerup | 4:2d41b942a823 | 143 | { |
Rogerup | 4:2d41b942a823 | 144 | if( level == L_INTRO || levelCompleted ) return; |
Rogerup | 4:2d41b942a823 | 145 | |
Rogerup | 4:2d41b942a823 | 146 | int ai = 1, aj = 1, mov = 0; |
Rogerup | 4:2d41b942a823 | 147 | |
Rogerup | 4:2d41b942a823 | 148 | if( i2 < i0 ) ai = -1; |
Rogerup | 4:2d41b942a823 | 149 | if( j2 < j0 ) aj = -1; |
john_ghielec | 2:6ab46f2e851a | 150 | |
Rogerup | 4:2d41b942a823 | 151 | // |
Rogerup | 4:2d41b942a823 | 152 | // Check BONG (RED) - If any ball hits BONG, no ball can move. |
Rogerup | 4:2d41b942a823 | 153 | // |
Rogerup | 4:2d41b942a823 | 154 | for( int i=i0; i!=i2; i+=ai ) |
Rogerup | 4:2d41b942a823 | 155 | for( int j=j0; j!=j2; j+=aj ) |
Rogerup | 4:2d41b942a823 | 156 | if( table[i][j] & 0xF0 ) |
Rogerup | 4:2d41b942a823 | 157 | if( (table[i+di][j+dj] & 0x0F) == BONG ) { |
Rogerup | 4:2d41b942a823 | 158 | showNumber( MOVY, ++moves ); |
Rogerup | 4:2d41b942a823 | 159 | bamX = (j+dj)*8; bamY = (i+di)*8; |
Rogerup | 4:2d41b942a823 | 160 | fillPieceV( BLACK, 0x0077, 0 ); |
Rogerup | 4:2d41b942a823 | 161 | fillPieceV( YELLOW, 0x1111, 0x5111, 0x1511, 0x5511, 0x3115, 0x1351, 0x2233, 0 ); |
Rogerup | 4:2d41b942a823 | 162 | disp.draw((unsigned short *)piece, bamX, bamY, 7, 7); |
Rogerup | 4:2d41b942a823 | 163 | bamTicksLeft = 5; |
Rogerup | 4:2d41b942a823 | 164 | return; |
Rogerup | 4:2d41b942a823 | 165 | } |
john_ghielec | 2:6ab46f2e851a | 166 | |
Rogerup | 4:2d41b942a823 | 167 | // |
Rogerup | 4:2d41b942a823 | 168 | // Move Balls |
Rogerup | 4:2d41b942a823 | 169 | // |
Rogerup | 4:2d41b942a823 | 170 | for( int i=i0; i!=i2; i+=ai ) |
Rogerup | 4:2d41b942a823 | 171 | { |
Rogerup | 4:2d41b942a823 | 172 | for( int j=j0; j!=j2; j+=aj ) |
Rogerup | 4:2d41b942a823 | 173 | { |
Rogerup | 4:2d41b942a823 | 174 | unsigned char ball = table[i][j] & 0xF0; |
Rogerup | 4:2d41b942a823 | 175 | |
Rogerup | 4:2d41b942a823 | 176 | if( !ball ) continue; |
Rogerup | 4:2d41b942a823 | 177 | if( table[i+di][j+dj] & 0xF0 ) continue; |
Rogerup | 4:2d41b942a823 | 178 | if( (table[i+di][j+dj] & 0x0F) == WALL ) continue; |
john_ghielec | 2:6ab46f2e851a | 179 | |
Rogerup | 4:2d41b942a823 | 180 | table[i+di][j+dj] |= ball; |
Rogerup | 4:2d41b942a823 | 181 | table[i][j] &= 0x0F; |
Rogerup | 4:2d41b942a823 | 182 | |
Rogerup | 4:2d41b942a823 | 183 | change[i+di] |= 1 << (j+dj); |
Rogerup | 4:2d41b942a823 | 184 | change[i] |= 1 << j; |
Rogerup | 4:2d41b942a823 | 185 | |
Rogerup | 4:2d41b942a823 | 186 | mov = 1; |
Rogerup | 4:2d41b942a823 | 187 | } |
Rogerup | 4:2d41b942a823 | 188 | } |
Rogerup | 4:2d41b942a823 | 189 | moves += mov; |
Rogerup | 4:2d41b942a823 | 190 | showNumber( MOVY, moves ); |
Rogerup | 4:2d41b942a823 | 191 | |
Rogerup | 4:2d41b942a823 | 192 | // |
Rogerup | 4:2d41b942a823 | 193 | // Check if Level is Completed |
Rogerup | 4:2d41b942a823 | 194 | // |
Rogerup | 4:2d41b942a823 | 195 | int balls = 0, marks = 0; |
Rogerup | 4:2d41b942a823 | 196 | for( int i=0; i<TABH; i++ ) { |
Rogerup | 4:2d41b942a823 | 197 | for( int j=0; j<TABW; j++ ) |
Rogerup | 4:2d41b942a823 | 198 | if( table[i][j] & 0xF0 ) { |
Rogerup | 4:2d41b942a823 | 199 | balls++; |
Rogerup | 4:2d41b942a823 | 200 | if( ((table[i][j] & 0x0F) - MARK + 1) == ((table[i][j] & 0xF0) >> 4) ) |
Rogerup | 4:2d41b942a823 | 201 | marks++; |
Rogerup | 4:2d41b942a823 | 202 | } |
Rogerup | 4:2d41b942a823 | 203 | } |
Rogerup | 4:2d41b942a823 | 204 | if( marks == balls ) { |
Rogerup | 4:2d41b942a823 | 205 | levelCompleted = true; |
Rogerup | 4:2d41b942a823 | 206 | if( moves < your[level] ) your[level] = moves; |
Rogerup | 4:2d41b942a823 | 207 | showNumber( YOUY, your[level] ); |
Rogerup | 4:2d41b942a823 | 208 | disp.drawString(8, 117, " LEVEL COMPLETED! ", RED, BLACK); |
Rogerup | 4:2d41b942a823 | 209 | led1 = 1; led2 = 1; |
Rogerup | 4:2d41b942a823 | 210 | #ifdef SOUNDWIN |
Rogerup | 4:2d41b942a823 | 211 | tickWin = tickCounter; |
Rogerup | 4:2d41b942a823 | 212 | #endif |
john_ghielec | 2:6ab46f2e851a | 213 | } |
john_ghielec | 2:6ab46f2e851a | 214 | } |
john_ghielec | 2:6ab46f2e851a | 215 | |
Rogerup | 4:2d41b942a823 | 216 | void Game::showTable() |
Rogerup | 4:2d41b942a823 | 217 | { |
Rogerup | 4:2d41b942a823 | 218 | for( int i=0; i<TABH; i++ ) |
Rogerup | 4:2d41b942a823 | 219 | for( int j=0; j<TABW; j++ ) |
Rogerup | 4:2d41b942a823 | 220 | showPiece(i,j); |
john_ghielec | 2:6ab46f2e851a | 221 | } |
john_ghielec | 2:6ab46f2e851a | 222 | |
Rogerup | 4:2d41b942a823 | 223 | void Game::showPiece(int i, int j) |
Rogerup | 4:2d41b942a823 | 224 | { |
Rogerup | 4:2d41b942a823 | 225 | if( !(change[i] & (1 << j)) ) return; |
Rogerup | 4:2d41b942a823 | 226 | |
Rogerup | 4:2d41b942a823 | 227 | change[i] &= ~(1 << j); |
Rogerup | 4:2d41b942a823 | 228 | |
Rogerup | 4:2d41b942a823 | 229 | unsigned char ball = table[i][j] >> 4; |
Rogerup | 4:2d41b942a823 | 230 | unsigned char base = table[i][j] & 0x0F; |
Rogerup | 4:2d41b942a823 | 231 | |
Rogerup | 4:2d41b942a823 | 232 | unsigned char basec = base; |
Rogerup | 4:2d41b942a823 | 233 | if( basec > MARK ) basec = MARK; |
Rogerup | 4:2d41b942a823 | 234 | |
Rogerup | 4:2d41b942a823 | 235 | fillPiece( 0, 0, 7, 7, piececolor[basec] ); |
john_ghielec | 1:cd8a3926f263 | 236 | |
Rogerup | 4:2d41b942a823 | 237 | if( base == WALL ) { |
Rogerup | 4:2d41b942a823 | 238 | fillPiece( 1, 1, 1, 1, 0 ); |
Rogerup | 4:2d41b942a823 | 239 | fillPiece( 1, 5, 1, 1, 0 ); |
Rogerup | 4:2d41b942a823 | 240 | fillPiece( 5, 1, 1, 1, 0 ); |
Rogerup | 4:2d41b942a823 | 241 | fillPiece( 5, 5, 1, 1, 0 ); |
Rogerup | 4:2d41b942a823 | 242 | } |
john_ghielec | 1:cd8a3926f263 | 243 | |
Rogerup | 4:2d41b942a823 | 244 | if( base == BONG ) { |
Rogerup | 4:2d41b942a823 | 245 | fillPiece( 1, 1, 5, 5, RED ); |
Rogerup | 4:2d41b942a823 | 246 | //fillPieceV( RED, 0x1111, 0x5111, 0x1511, 0x5511, 0x3115, 0x1351, 0x2233, 0 ); |
Rogerup | 4:2d41b942a823 | 247 | } |
Rogerup | 4:2d41b942a823 | 248 | |
Rogerup | 4:2d41b942a823 | 249 | if( base == MARK ) { |
Rogerup | 4:2d41b942a823 | 250 | fillPiece( 3, 3, 1, 1, WHITE ); |
Rogerup | 4:2d41b942a823 | 251 | } |
Rogerup | 4:2d41b942a823 | 252 | |
Rogerup | 4:2d41b942a823 | 253 | if( ball ) { |
Rogerup | 4:2d41b942a823 | 254 | fillPieceV( BLUE, 0x1051,0x0175, 0x1651, 0 ); |
Rogerup | 4:2d41b942a823 | 255 | //fillPieceV( WHITE 0x3311, 0 ); |
Rogerup | 4:2d41b942a823 | 256 | } |
john_ghielec | 2:6ab46f2e851a | 257 | |
Rogerup | 4:2d41b942a823 | 258 | disp.draw((unsigned short *)piece, j*8, i*8, 7, 7); |
Rogerup | 4:2d41b942a823 | 259 | |
Rogerup | 4:2d41b942a823 | 260 | if( base > MARK && !ball ) |
Rogerup | 4:2d41b942a823 | 261 | disp.drawNumber( j*8+2, i*8+1, base-MARK, WHITE, piececolor[MARK] ); |
john_ghielec | 2:6ab46f2e851a | 262 | |
Rogerup | 4:2d41b942a823 | 263 | if( ball > 1 ) |
Rogerup | 4:2d41b942a823 | 264 | disp.drawNumber( j*8+2, i*8+1, ball-1, WHITE, BLUE ); |
john_ghielec | 1:cd8a3926f263 | 265 | } |
john_ghielec | 1:cd8a3926f263 | 266 | |
Rogerup | 4:2d41b942a823 | 267 | void Game::fillPiece(int x0, int y0, int w, int h, unsigned short v) |
Rogerup | 4:2d41b942a823 | 268 | { |
Rogerup | 4:2d41b942a823 | 269 | for( int y=y0; y<y0+h; y++ ) |
Rogerup | 4:2d41b942a823 | 270 | for( int x=x0; x<x0+w; x++ ) |
Rogerup | 4:2d41b942a823 | 271 | piece[y][x] = v; |
john_ghielec | 1:cd8a3926f263 | 272 | } |
john_ghielec | 1:cd8a3926f263 | 273 | |
Rogerup | 4:2d41b942a823 | 274 | void Game::fillPieceV(unsigned short color, ...) |
Rogerup | 4:2d41b942a823 | 275 | { |
Rogerup | 4:2d41b942a823 | 276 | va_list arguments; |
Rogerup | 4:2d41b942a823 | 277 | va_start( arguments, color ); |
Rogerup | 4:2d41b942a823 | 278 | |
Rogerup | 4:2d41b942a823 | 279 | int pos; |
Rogerup | 4:2d41b942a823 | 280 | while( (pos = va_arg ( arguments, int)) != 0 ) |
Rogerup | 4:2d41b942a823 | 281 | fillPiece( (pos&0xF000)>>12, (pos&0x0F00)>>8, (pos & 0x00F0) >> 4, (pos & 0x000F) >> 0, color ); |
Rogerup | 4:2d41b942a823 | 282 | |
Rogerup | 4:2d41b942a823 | 283 | va_end( arguments ); |
john_ghielec | 1:cd8a3926f263 | 284 | } |
john_ghielec | 1:cd8a3926f263 | 285 | |
Rogerup | 4:2d41b942a823 | 286 | void Game::showImage( unsigned char x, unsigned char y, unsigned short back, unsigned short front, ... ) |
Rogerup | 4:2d41b942a823 | 287 | { |
Rogerup | 4:2d41b942a823 | 288 | fillPieceV( back, 0x0077, 0 ); |
Rogerup | 4:2d41b942a823 | 289 | |
Rogerup | 4:2d41b942a823 | 290 | va_list args; |
Rogerup | 4:2d41b942a823 | 291 | va_start( args, front ); |
Rogerup | 4:2d41b942a823 | 292 | |
Rogerup | 4:2d41b942a823 | 293 | int pos; |
Rogerup | 4:2d41b942a823 | 294 | while( (pos = va_arg ( args, int)) != 0 ) |
Rogerup | 4:2d41b942a823 | 295 | fillPiece( (pos&0xF000)>>12, (pos&0x0F00)>>8, (pos & 0x00F0) >> 4, (pos & 0x000F) >> 0, front ); |
Rogerup | 4:2d41b942a823 | 296 | |
Rogerup | 4:2d41b942a823 | 297 | va_end( args ); |
Rogerup | 4:2d41b942a823 | 298 | |
Rogerup | 4:2d41b942a823 | 299 | disp.draw( (unsigned short *)piece, x, y, 7, 7 ); |
john_ghielec | 1:cd8a3926f263 | 300 | } |
john_ghielec | 1:cd8a3926f263 | 301 | |
Rogerup | 4:2d41b942a823 | 302 | void Game::playBam() |
Rogerup | 4:2d41b942a823 | 303 | { |
Rogerup | 4:2d41b942a823 | 304 | if( bamTicksLeft == 0 ) |
Rogerup | 4:2d41b942a823 | 305 | return; |
john_ghielec | 1:cd8a3926f263 | 306 | |
Rogerup | 4:2d41b942a823 | 307 | if( --bamTicksLeft % 2 ) { |
Rogerup | 4:2d41b942a823 | 308 | led1 = 1; |
Rogerup | 4:2d41b942a823 | 309 | led2 = 1; |
Rogerup | 4:2d41b942a823 | 310 | } else { |
Rogerup | 4:2d41b942a823 | 311 | led1 = 0; |
Rogerup | 4:2d41b942a823 | 312 | led2 = 0; |
Rogerup | 4:2d41b942a823 | 313 | } |
Rogerup | 4:2d41b942a823 | 314 | |
Rogerup | 4:2d41b942a823 | 315 | //pwm.write(0.5); |
Rogerup | 4:2d41b942a823 | 316 | pwm.period_us(50); |
Rogerup | 4:2d41b942a823 | 317 | pwm.pulsewidth_us(50); |
Rogerup | 4:2d41b942a823 | 318 | |
Rogerup | 4:2d41b942a823 | 319 | if (bamTicksLeft == 0) { |
Rogerup | 4:2d41b942a823 | 320 | pwm.write(0.0); |
Rogerup | 4:2d41b942a823 | 321 | fillPieceV( WHITE, 0x0077, 0 ); |
Rogerup | 4:2d41b942a823 | 322 | fillPieceV( RED, 0x1111, 0x5111, 0x1511, 0x5511, 0x3115, 0x1351, 0x2233, 0 ); |
Rogerup | 4:2d41b942a823 | 323 | disp.draw((unsigned short *)piece, bamX, bamY, 7, 7); |
john_ghielec | 1:cd8a3926f263 | 324 | } |
john_ghielec | 1:cd8a3926f263 | 325 | } |
john_ghielec | 1:cd8a3926f263 | 326 | |
Rogerup | 4:2d41b942a823 | 327 | void Game::playSound() |
Rogerup | 4:2d41b942a823 | 328 | { |
Rogerup | 4:2d41b942a823 | 329 | if( tickCounter == tickWin + 1 ) { pwm = 0.02; pwm.period( 1.0 / 330.0 ); } |
Rogerup | 4:2d41b942a823 | 330 | if( tickCounter == tickWin + 9 ) { pwm = 0.02; pwm.period( 1.0 / 440.0 ); } |
Rogerup | 4:2d41b942a823 | 331 | if( tickCounter == tickWin + 25 ) { pwm = 0; pwm.period_ms(1); } |
john_ghielec | 1:cd8a3926f263 | 332 | } |