Revision 5ad07f5f main.c

View differences:

main.c
76 76
	} player_t;
77 77

  
78 78
int main(void);
79
inline void customColor(uint8_t colorPins);
79 80
inline void redDot(void);
80 81
inline void greenDot(void);
81 82
inline void yellowDot(void);
......
91 92
void moveSpriteToLines(sprite_t* sprite);
92 93
uint8_t checkPlayerSpriteForCollision(player_t* player, uint16_t block[4], int8_t lookahead); // lookahead -1 -> look down
93 94
void moveSpriteHorizontal(volatile sprite_t *sprite, int8_t dir); // -1 if left, 1 if right
94
void handleGamepadInput(player_t* player, uint8_t input);
95 95
inline void printLine(int16_t line, uint8_t round, sprite_t* sprite);
96 96
static inline void drawGameArea(player_t player[NUMBER_OF_PLAYERS]);
97 97
void gameOver(player_t* player);
......
99 99
void drawScore(uint16_t* score, uint8_t round);
100 100
void drawNumber(uint8_t startpos, uint16_t number[5]);
101 101
static inline void drawEverything(void);
102
inline void printLineBasic(int16_t line, uint8_t round);
102
inline void printLineBasic(int16_t line, uint8_t round, uint8_t color);
103 103
void printSignedNumber16(int16_t number);
104 104

  
105 105
//volatile uint16_t lines[90] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
......
143 143

  
144 144
	int16_t countdown = 1000;
145 145
	while(1){
146
		for(uint8_t i = 0; i < 255; i++){
146
		//for(uint8_t i = 0; i < 255; i++){
147 147
			drawEverything();
148
		}
149
		printSignedNumber16(countdown);
150
		countdown--;
148
		//}
149
		//printSignedNumber16(countdown);
150
		//countdown--;
151 151
	}
152 152
}
153 153

  
......
219 219
	}
220 220
}
221 221
static inline void drawEverything(){
222
	for(uint8_t round = 0; round < 16; round++){
223
		for(int16_t line = 0; line < 90; line++){
224
			printLineBasic(line, round);
222
	for(uint8_t intensity = 0; intensity < 16; intensity++){
223
		for(uint8_t round = 0; round < intensity; round++){
224
			PORT(ADDRESS_PORT) = round;
225
			for(int16_t line = 0; line < 90; line++){
226
				printLineBasic(line, round, (1<<DATA_GREEN_PIN));
227
			}
228
			OE();
229
			_delay_us(40);
230
			ODE();
231
			_delay_us(1); // avoid ghosting
232
		}
233
		for(uint8_t round = intensity; round < 16; round++){
234
			PORT(ADDRESS_PORT) = round;
235
			for(int16_t line = 0; line < 90; line++){
236
				printLineBasic(line, round, (1<<DATA_RED_PIN));
237
			}
238
			OE();
239
			_delay_us(40);
240
			ODE();
241
			_delay_us(1); // avoid ghosting
225 242
		}
226
		OE();
227
		_delay_us(80);
228
		ODE();
229
		_delay_us(1); // avoid ghosting
230
		PORT(ADDRESS_PORT) = round+1;
231 243
	}
232 244
}
233 245
static inline void drawGameArea(player_t player[NUMBER_OF_PLAYERS]){
......
253 265
		PORT(ADDRESS_PORT) = round+1;
254 266
	}
255 267
}
256
inline void printLineBasic(int16_t line, uint8_t round){
268
inline void printLineBasic(int16_t line, uint8_t round, uint8_t color){
257 269
	if((1<<round) & lines[line]){
258
		yellowDot();
270
		customColor(color);
259 271
	}
260 272
	else{
261 273
		noDot();
......
280 292
	}
281 293
}
282 294

  
283
void handleGamepadInput(player_t* player, uint8_t input){
284
	switch(input){
285
		// move > rotate > down
286
		case (LEFT | DOWN | RIGHT | ROTATE):
287
			keypressCounter+=2;
288
		case (DOWN | ROTATE):
289
			rotateLeft((sprite_t*)&((*player).sprite));
290
			rawToBlock((uint16_t*)(*player).sprite.block, (*player).sprite.raw, (*player).sprite.offset);
291
			moveSpriteDown((sprite_t*)&((*player).sprite));
292
			keypressCounter+=2;
293
			break;
294
		case (LEFT | DOWN | RIGHT):
295
			keypressCounter+=2;
296
		case (DOWN):
297
			moveSpriteDown((sprite_t*)&((*player).sprite));
298
			keypressCounter+=1;
299
			break;
300
		case (RIGHT):
301
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), -1);
302
			keypressCounter+=1;
303
			break;
304
		case (LEFT | RIGHT | ROTATE):
305
			keypressCounter+=1;
306
		case (RIGHT | ROTATE):
307
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), -1);
308
			keypressCounter+=1;
309
		case (ROTATE):
310
			rotateLeft((sprite_t*)&((*player).sprite));
311
			rawToBlock((uint16_t*)(*player).sprite.block, (*player).sprite.raw, (*player).sprite.offset);
312
			keypressCounter+=1;
313
			break;
314
		case (DOWN | RIGHT):
315
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), -1);
316
			moveSpriteDown((sprite_t*)&((*player).sprite));
317
			keypressCounter+=2;
318
			break;
319
		case (DOWN | RIGHT | ROTATE):
320
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), -1);
321
			rotateLeft((sprite_t*)&((*player).sprite));
322
			rawToBlock((uint16_t*)(*player).sprite.block, (*player).sprite.raw, (*player).sprite.offset);
323
			moveSpriteDown((sprite_t*)&((*player).sprite));
324
			keypressCounter+=3;
325
			break;
326
		case (LEFT):
327
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), 1);
328
			keypressCounter+=1;
329
			break;
330
		case (LEFT | ROTATE):
331
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), 1);
332
			rotateLeft((sprite_t*)&((*player).sprite));
333
			rawToBlock((uint16_t*)(*player).sprite.block, (*player).sprite.raw, (*player).sprite.offset);
334
			keypressCounter+=2;
335
			break;
336
		case (LEFT | DOWN):
337
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), 1);
338
			moveSpriteDown((sprite_t*)&((*player).sprite));
339
			keypressCounter+=2;
340
			break;
341
		case (LEFT | DOWN | ROTATE):
342
			moveSpriteHorizontal((sprite_t*)&((*player).sprite), 1);
343
			rotateLeft((sprite_t*)&((*player).sprite));
344
			rawToBlock((uint16_t*)(*player).sprite.block, (*player).sprite.raw, (*player).sprite.offset);
345
			moveSpriteDown((sprite_t*)&((*player).sprite));
346
			keypressCounter+=3;
347
			break;
348
		// "nops"
349
		case (LEFT | RIGHT): // left+right = no move
350
			keypressCounter+=2;
351
		case (0b0000): // nothing pressed
352
			break;
353
	}
354
}
355

  
356 295
void rawToBlock(uint16_t block[4], uint16_t raw, int8_t offset){
357 296
	block[0] = raw & 0xf;
358 297
	block[1] = (raw>>4) & 0xf;
......
473 412
	lines[89] = tmp;
474 413
}
475 414

  
415
inline void customColor(uint8_t colorPins){
416
	PORT(WALLBOARD_PORT) |= colorPins | (1<<CLOCK_PIN);
417
	PORT(WALLBOARD_PORT) &= ~(colorPins | (1<<CLOCK_PIN));
418
}
419

  
476 420
inline void greenDot(){
477 421
	PORT(WALLBOARD_PORT) |= (1<<DATA_GREEN_PIN) | (1<<CLOCK_PIN);
478 422
	PORT(WALLBOARD_PORT) &= ~((1<<DATA_GREEN_PIN) | (1<<CLOCK_PIN));

Also available in: Unified diff