#include #include #include "hub75.h" #define debounceDelay 180 _Bool gameOver = 0; //this flag bit is set to 1 when game is over int score = 0; //holds the score during gameplay int count=0; //used for screen refresh _Bool generate_new_shape = 0; //this flag bit is set to 1 when neww shape is be generated int shape_current_row_index; //holds row number of the current position int shape_current_col_index; //holds column number of the current position char current_shape_type; //l - line, L - L, S = Square, T - Tee, Z - Zee int current_shape_orientation;// 0 = original, 1 = 90 deg CW, 2 = 180 deg CW 3 = 270 deg CW //****************************************************main**************************************************// int main() { Initialize_GPIO(); shape_current_row_index = 0; shape_current_col_index = 15; current_shape_type = generateRandomShape(); current_shape_orientation = generateRandomOrientation(current_shape_type); defineBoundaries(10,20); while(1) { if(gameOver==0) {showDataOnHUB32x32();} else {showGameOver();} count++; if(gameOver == 0) { if(!(FIO0PIN & (1<<15))) //rotate { if(!rotate_collision_detection(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation)) { delay2(debounceDelay); makeCurrentShapeBitsZero(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); current_shape_orientation = rotateShape(current_shape_orientation,current_shape_type); } else {/**do nothing*/} } if(!(FIO0PIN & (1<<14))) //move left { if(!left_collision_detection(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation)) { delay2(debounceDelay); makeCurrentShapeBitsZero(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); shape_current_col_index--; } else { //do nothing } } if(!(FIO0PIN & (1<<16))) //move right { if(!right_collision_detection(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation)) { delay2(debounceDelay); makeCurrentShapeBitsZero(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); shape_current_col_index++; } else { //do nothing } } if(generate_new_shape ==1) //if it's a new shape then reset position and generate new shape { shape_current_row_index = 0; shape_current_col_index = 15; generate_new_shape = 0; } else //if it's not a new shape then continue { put_shape_to_main_matrix(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); //add one more parameter for shape type } if(count>25) //edit this to increase or decrease the move down speed { if(!down_collision_detection(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation)) { makeCurrentShapeBitsZero(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); shape_current_row_index = shape_current_row_index + 1; put_shape_to_main_matrix(shape_current_row_index,shape_current_col_index,current_shape_type,current_shape_orientation); } else { if(checkForGameOver(shape_current_row_index)==1) { gameOver=1; beepGameOver();beepGameOver();beepGameOver(); updateGOmatrixWithScore(score);//call game ovr update matrix here } if(checkRowForOnes()==1) //down collision detected now check for row containing all 1s { beepOnce(); score++;//update score } else {/*do nothing */} beepOnce(); generate_new_shape = 1; current_shape_type = generateRandomShape(); current_shape_orientation = generateRandomOrientation(current_shape_type); } count=0; } } } }