Browse Source

Merge pull request #3 from stefanctdo/kart

Kart: Add blink effect on boost, switched boost-key to 'fire'
feature/2017
Christian Kroll 9 years ago
parent
commit
21dd61011b
  1. 41
      src/games/kart/kart.c
  2. 1
      src/games/kart/kart.h

41
src/games/kart/kart.c

@ -44,7 +44,7 @@ game_descriptor_t kart_game_descriptor __attribute__((section(".game_descriptors
#define WAIT 15 #define WAIT 15
#define DRIVE_DIV 10 #define DRIVE_DIV 9
#define DIRECTION_DIV 20 #define DIRECTION_DIV 20
#define DECREASE_WIDTH_DIV 300 #define DECREASE_WIDTH_DIV 300
#define ACCELERATE_DIV 800 #define ACCELERATE_DIV 800
@ -64,6 +64,9 @@ game_descriptor_t kart_game_descriptor __attribute__((section(".game_descriptors
#define BORDER_DARK 2 #define BORDER_DARK 2
#define OBSTACLE_COLOR 3 #define OBSTACLE_COLOR 3
#define NUM_FLASHES 3
#define BLINK_TIME 300
// borders = (middle, width, obstacle_pos) // borders = (middle, width, obstacle_pos)
uint8_t borders[NUM_ROWS][3]; uint8_t borders[NUM_ROWS][3];
uint32_t extra_score = 0; uint32_t extra_score = 0;
@ -72,6 +75,7 @@ void kart_game(){
// Initialisation // Initialisation
uint32_t decrease_width_div = DECREASE_WIDTH_DIV; uint32_t decrease_width_div = DECREASE_WIDTH_DIV;
uint16_t accelerate_div = ACCELERATE_DIV;
uint8_t key_ignore[2]; uint8_t key_ignore[2];
uint8_t drive_div = DRIVE_DIV; uint8_t drive_div = DRIVE_DIV;
uint8_t carpos = NUM_COLS / 2; uint8_t carpos = NUM_COLS / 2;
@ -109,12 +113,13 @@ void kart_game(){
// DECREASE WIDTH // DECREASE WIDTH
if(cycle % decrease_width_div == 0){ if(cycle % decrease_width_div == 0){
width--; width--;
decrease_width_div = decrease_width_div*2; decrease_width_div *= 2;
} }
// INCREASE SPEED // INCREASE SPEED
if(cycle % ACCELERATE_DIV == 0 ){ if(cycle % accelerate_div == 0 ){
drive_div--; drive_div--;
accelerate_div *= 2;
} }
// MOVE // MOVE
@ -142,7 +147,8 @@ void kart_game(){
key_ignore[1] = KEY_IGNORE_INITIAL; key_ignore[1] = KEY_IGNORE_INITIAL;
key_ignore[0] = 0; key_ignore[0] = 0;
}else if(JOYISUP && boost_till == 0){ }else if(JOYISFIRE && boost_till == 0){
blink();
boost_till = cycle + BOOST_CYCLES; boost_till = cycle + BOOST_CYCLES;
boost_multiplier = BOOST_MULTIPLIER; boost_multiplier = BOOST_MULTIPLIER;
}else if(!(JOYISRIGHT || JOYISLEFT)){ }else if(!(JOYISRIGHT || JOYISLEFT)){
@ -265,6 +271,33 @@ void save_street(uint8_t middle, uint8_t width, uint8_t obstacle_pos){
} }
/**
* Flash the screen NUM_FLASHES times.
*/
void blink(){
// Two copies of the pixmap.
unsigned char pixmap_copy_1[NUMPLANE][NUM_ROWS][LINEBYTES];
unsigned char pixmap_copy_2[NUMPLANE][NUM_ROWS][LINEBYTES];
unsigned char plane, row, byte, flashes;
// create empty pixmap
for(plane = 0; plane < NUMPLANE; plane++){
for(row = 0; row < NUM_ROWS; row++){
for(byte = 0; byte < LINEBYTES; byte++){
pixmap_copy_2[plane][row][byte] = 0;
}
}
}
// Do a triangle shift.
for(flashes = NUM_FLASHES*2; flashes > 0; flashes--){
memcpy(pixmap_copy_1, pixmap, sizeof(pixmap));
memcpy(pixmap, pixmap_copy_2, sizeof(pixmap));
memcpy(pixmap_copy_2, pixmap_copy_1, sizeof(pixmap));
wait(BLINK_TIME);
}
}
/** /**
* check if collision occours * check if collision occours
*/ */

1
src/games/kart/kart.h

@ -13,5 +13,6 @@ void kart_game(void);
void drive(void); void drive(void);
void save_street(uint8_t middle, uint8_t width, uint8_t obstacle_pos); void save_street(uint8_t middle, uint8_t width, uint8_t obstacle_pos);
uint8_t check_collision(uint8_t carpos); uint8_t check_collision(uint8_t carpos);
void blink();
#endif /* KART_H_ */ #endif /* KART_H_ */

Loading…
Cancel
Save