/* * LCD_Test.c * * Created: 2022-05-05 10:43:03 * Author : cid12bel */ #define F_CPU 16000000u #include #include #include #include #include "LCD_display.h" #include "game_logic.h" #include "charset_header.h" #include #include /* the ball used in the game */ ball a_ball; /* iterator parameters */ uint8_t i = 0; uint8_t j = 0; uint8_t k = 0; /* the representation of the maze */ tile maze[16][8]; /* a byte to be filled with pixel data for drawing one 8 pixel column on a display page */ uint8_t temp_draw = 0; uint8_t detect_collision(uint8_t move_x, uint8_t move_y) { uint8_t hit = 0; /* save the old position so we can erase the old image if the ball moves */ a_ball.prevx = a_ball.posx; a_ball.prevy = a_ball.posy; while (move_x > 0 || move_y > 0) { /* there needs to be checks for borders betweent tiles both * horizontally and vertically and there needs to be checks * for the border between CS1 and CS2. */ if (a_ball.v_y > 0 && move_y > 0) { /* right side of ball is front */ if (a_ball.posy > 125) { a_ball.v_y = 0; hit = 1; move_y = 0; } else { ++a_ball.posy; curr_tile_y = (a_ball.posy + 1) / 8; curr_y = (a_ball.posy + 1) % 8; curr_page = a_ball.posx / 8; curr_x = a_ball.posx % 8; if (maze[curr_tile_y][curr_page].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y] & BALL_POSITIONS[curr_x]; if (curr_x == 7 && hit < 1 && maze[curr_tile_y][curr_page + 1].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page + 1].char_id][curr_y] & 0b00000001; if (hit > 0) { a_ball.v_y = 0; --a_ball.posy; move_y = 0; } else --move_y; } } else if (a_ball.v_y < 0 && move_y > 0) { /* left side of ball is front */ if (a_ball.posy == 0) { a_ball.v_y = 0; hit = 1; move_y = 0; } else { --a_ball.posy; curr_tile_y = (a_ball.posy) / 8; curr_y = (a_ball.posy) % 8; curr_page = a_ball.posx / 8; curr_x = a_ball.posx % 8; if(maze[curr_tile_y][curr_page].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y] & BALL_POSITIONS[curr_x]; if (curr_x == 7 && hit < 1 && maze[curr_tile_y][curr_page + 1].has_wall > 0 ) { hit = tile_set[maze[curr_tile_y][curr_page + 1].char_id][curr_y] & BALL_POSITIONS[0b00000001]; } if (hit > 0) { a_ball.v_y = 0; ++a_ball.posy; move_y = 0; } else --move_y; } } if (a_ball.v_x > 0 && move_x > 0) { /* bottom side is front */ if(a_ball.posx == 62) { a_ball.v_x = 0; hit = 1; move_x = 0; } else { ++a_ball.posx; curr_tile_y = (a_ball.posy) / 8; curr_y = (a_ball.posy) % 8; curr_page = (a_ball.posx + 1) / 8; curr_x = (a_ball.posx + 1) % 8; if (curr_x == 0) { if (maze[curr_tile_y][curr_page].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y] & 0b00000001; if(curr_y == 7 && hit < 1 && maze[curr_tile_y + 1][curr_page].has_wall > 0) { hit = tile_set[maze[curr_tile_y + 1][curr_page].char_id][0] & 0b00000001; } else if (maze[curr_tile_y][curr_page].has_wall > 0 && hit < 1) { hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y + 1] & 0b00000001; } } else { if (maze[curr_tile_y][curr_page].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y] & BALL_POSITIONS[curr_x - 1]; if(curr_y == 7 && hit < 1 && maze[curr_tile_y + 1][curr_page].has_wall > 0) { hit = tile_set[maze[curr_tile_y + 1][curr_page].char_id][0] & BALL_POSITIONS[curr_x - 1]; } else if (maze[curr_tile_y][curr_page].has_wall > 0 && hit < 1) { hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y + 1] & BALL_POSITIONS[curr_x - 1]; } } if (hit > 0) { a_ball.v_x = 0; --a_ball.posx; move_x = 0; } else --move_x; } } else if (a_ball.v_x < 0 && move_x > 0) { /* top is front */ if (a_ball.posx == 0) { a_ball.v_x = 0; hit = 1; move_x = 0; } else { --a_ball.posx; curr_tile_y = (a_ball.posy) / 8; curr_y = (a_ball.posy) % 8; curr_page = a_ball.posx / 8; curr_x = a_ball.posx % 8; if (maze[curr_tile_y][curr_page].has_wall > 0) hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y] & BALL_POSITIONS[curr_x]; if (curr_y == 7 && hit < 1 && maze[curr_tile_y + 1][curr_page].has_wall > 0) { hit = tile_set[maze[curr_tile_y + 1][curr_page].char_id][0] & BALL_POSITIONS[curr_x]; } else if (maze[curr_tile_y][curr_page].has_wall > 0 && hit < 1) { hit = tile_set[maze[curr_tile_y][curr_page].char_id][curr_y + 1] & BALL_POSITIONS[curr_x]; } if (hit > 0) { a_ball.v_x = 0; ++a_ball.posx; move_x = 0; } else --move_x; } } } return hit; } void draw_ball() { /** TRY TO MOVE THE BALL INCLUDING COLLISION DETECTION **/ detect_collision(abs(a_ball.v_x), abs(a_ball.v_y)); /*********************************************************** * First, erase the ball's previous position on the screen * ***********************************************************/ curr_page = a_ball.prevx / NBR_PAGES; /* To know what page we are on */ curr_x = a_ball.prevx % 8; /* Each page is 8 px high. */ curr_y = a_ball.prevy % 64; curr_tile_y = a_ball.prevy / 8; /* integer division by 8 gives the tile's horizontal position */ /* set which part of the screen to draw on */ if (curr_tile_y < 8) { set_CS2(); /* left side */ } else { set_CS1(); /* right side */ } LCD_command(disp_ypos(curr_y)); LCD_command(disp_page(curr_page)); /*** B A L L L E F T H A L F ***/ /* slightly complicated.. the position in the maze contains a reference to the 8x8 image that corresponds to what should be drawn on the current tile. curr_x gives which of the 8 columns that should be drawn. maze[curr_tile_y][curr_tile_x].char_id gives the int value for the character index row */ LCD_data(tile_set[maze[curr_tile_y][curr_page].char_id][curr_y % 8]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ LCD_command(disp_ypos(curr_y)); /* reset y */ LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y][curr_page + 1].char_id][curr_y % 8]); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } /*** B A L L R I G H T H A L F ***/ if ((a_ball.prevy % 8) == 7 && curr_tile_y < 15) { if (a_ball.prevy == 63) { set_CS1(); LCD_command(disp_ypos(0)); } else { LCD_command(disp_ypos(curr_y + 1)); } LCD_data(tile_set[maze[curr_tile_y + 1][curr_page].char_id][0]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ if (a_ball.posy == 63) { LCD_command(disp_ypos(0)); } else { LCD_command(disp_ypos(curr_y + 1)); } LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y + 1][curr_page + 1].char_id][0]); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } /* make sure we draw on the left half again when moving the other way */ if (a_ball.prevy == 63/* && a_ball.v_y < 0 */) { set_CS2(); } } else { LCD_data(tile_set[maze[curr_tile_y][curr_page].char_id][(curr_y+1) % 8]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ LCD_command(disp_ypos(curr_y + 1)); /* reset y */ LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y][curr_page + 1].char_id][(curr_y + 1) % 8]); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } } curr_page = a_ball.posx / 8; curr_x = a_ball.posx % 8; curr_y = a_ball.posy % 64; curr_tile_y = a_ball.posy / 8; /* integer division by 8 gives the tile's horizontal position */ if (a_ball.posy < 64) { set_CS2(); /* left side */ } else { set_CS1(); /* right side */ } /***************************************************************** * Time to draw the ball * *****************************************************************/ /*** B A L L L E F T H A L F ***/ LCD_command(disp_ypos(curr_y)); LCD_command(disp_page(curr_page)); /*** B A L L L E F T H A L F ***/ /* slightly complicated.. the position in the maze contains a reference to the 8x8 image that corresponds to what should be drawn on the current tile. curr_x gives which of the 8 columns that should be drawn. maze[curr_tile_y][curr_tile_x].char_id gives the int value for the character index row */ LCD_data(tile_set[maze[curr_tile_y][curr_page].char_id][curr_y % 8] + BALL_POSITIONS[curr_x]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ LCD_command(disp_ypos(curr_y)); /* reset y */ LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y][curr_page + 1].char_id][curr_y % 8] + 1); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } /*** B A L L R I G H T H A L F ***/ if ((a_ball.posy % 8) == 7 && curr_tile_y < 15) { if (a_ball.posy == 63) { set_CS1(); LCD_command(disp_ypos(0)); } else { LCD_command(disp_ypos(curr_y + 1)); } LCD_data(tile_set[maze[curr_tile_y + 1][curr_page].char_id][0] + BALL_POSITIONS[curr_x]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ if (a_ball.posy == 63) { LCD_command(disp_ypos(0)); } else { LCD_command(disp_ypos(curr_y + 1)); } LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y + 1][curr_page + 1].char_id][0] + 1); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } /* make sure we draw on the left half again when moving the other way */ if (a_ball.posy == 63 && a_ball.v_y < 0) { set_CS2(); } } else { LCD_data(tile_set[maze[curr_tile_y][curr_page].char_id][(curr_y+1) % 8] + BALL_POSITIONS[curr_x]); if (curr_x == 7 && curr_page < NBR_PAGES - 1 ) /* only on pages 1--6 */ { /* In case we are at the bottom border between pages, except the bottom page. */ LCD_command(disp_ypos(curr_y + 1)); /* reset y */ LCD_command(disp_page(curr_page + 1)); /* move 1 page down */ LCD_data(tile_set[maze[curr_tile_y][curr_page + 1].char_id][(curr_y + 1) % 8] + 1); LCD_command(disp_page(curr_page)); /* we need to reset page position again */ } } } void setup_labyrinth() { uint8_t left = 1; int col = 0; int row = 0; int k = 0; int l = 0; LCD_command(disp_page(row)); /* replace with proper page calculation !! */ LCD_command(disp_ypos(0)); set_CS2(); /* this also needs to be calculated */ for (k = 0; k < CHARSET_SIZE; ++k) { LCD_command(disp_ypos(col*8)); for (l = 0; l < 8; ++l) { LCD_data(charset[k][l]); } ++col; if (col == 8 && left > 0) { set_CS1(); left = 0; col = 0; LCD_command(disp_page(row)); } else if (col == 8 && left < 1) { set_CS2(); left = 1; col = 0; ++row; LCD_command(disp_page(row)); } } } void msg_game_over() { set_CS2(); LCD_command(disp_page(3)); LCD_command(disp_ypos(24)); /* Left half; write GAME */ /* G */ for (i = 0; i < 8; ++i) { LCD_data(charset[6][i]); } /* A */ for (i = 0; i < 8; ++i) { LCD_data(charset[0][i]); } /* M */ for (i = 0; i < 8; ++i) { LCD_data(charset[12][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } for (i = 0; i < 8; ++i) { LCD_data(0); } /* Right half; write OVER */ set_CS1(); LCD_command(disp_page(3)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ for (i = 0; i < 8; ++i) { LCD_data(0); } for (i = 0; i < 8; ++i) { LCD_data(charset[14][i]); } for (i = 0; i < 8; ++i) { LCD_data(charset[21][i]); } for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } for (i = 0; i < 8; ++i) { LCD_data(charset[17][i]); } } void make_maze() { maze[0][0].char_id = 0; maze[0][1].char_id = 0; maze[0][2].char_id = 0; maze[0][3].char_id = 0; maze[0][4].char_id = 0; maze[0][5].char_id = 0; maze[0][6].char_id = 1; maze[0][6].has_wall = 1; maze[0][7].char_id = 0; maze[1][0].char_id = 0; maze[1][1].char_id = 7; maze[1][1].has_wall = 1; maze[1][2].char_id = 0; maze[1][3].char_id = 11; maze[1][3].has_wall = 1; maze[1][4].char_id = 0; maze[1][5].char_id = 0; maze[1][6].char_id = 1; maze[1][6].has_wall = 1; maze[1][7].char_id = 0; maze[2][0].char_id = 0; maze[2][1].char_id = 1; maze[2][1].has_wall = 1; maze[2][2].char_id = 0; maze[2][3].char_id = 1; maze[2][3].has_wall = 1; maze[2][4].char_id = 0; maze[2][5].char_id = 2; maze[2][5].has_wall = 1; maze[2][6].char_id = 9; maze[2][6].has_wall = 1; maze[2][7].char_id = 0; maze[3][0].char_id = 0; maze[3][1].char_id = 1; maze[3][1].has_wall = 1; maze[3][2].char_id = 0; maze[3][3].char_id = 1; maze[3][3].has_wall = 1; maze[3][4].char_id = 0; maze[3][5].char_id = 2; maze[3][5].has_wall = 1; maze[3][6].char_id = 9; maze[3][6].has_wall = 1; maze[3][7].char_id = 0; maze[4][0].char_id = 0; maze[4][1].char_id = 1; maze[4][1].has_wall = 1; maze[4][2].char_id = 0; maze[4][3].char_id = 1; maze[4][3].has_wall = 1; maze[4][4].char_id = 0; maze[4][5].char_id = 0; maze[4][6].char_id = 0; maze[4][7].char_id = 0; maze[5][0].char_id = 0; maze[5][0].is_start =1; maze[5][1].char_id = 1; maze[5][1].has_wall = 1; maze[5][2].char_id = 0; maze[5][3].char_id = 6; maze[5][3].has_wall = 1; maze[5][4].char_id = 11; maze[5][4].has_wall = 1; maze[5][5].char_id = 2; maze[5][5].has_wall = 1; maze[5][6].char_id = 2; maze[5][6].has_wall = 1; maze[5][7].char_id = 0; maze[6][0].char_id = 2; maze[6][0].has_wall = 1; maze[6][1].char_id = 10; maze[6][1].has_wall = 1; maze[6][2].char_id = 5; maze[6][2].has_wall = 1; maze[6][3].char_id = 0; maze[6][4].char_id = 1; maze[6][4].has_wall = 1; maze[6][5].char_id = 0; maze[6][6].char_id = 0; maze[6][7].char_id = 0; maze[7][0].char_id = 0; maze[7][1].char_id = 0; maze[7][2].char_id = 6; maze[7][2].has_wall = 1; maze[7][3].char_id = 2; maze[7][3].has_wall = 1; maze[7][4].char_id = 4; maze[7][4].has_wall = 1; maze[7][5].char_id = 0; maze[7][6].char_id = 0; maze[7][7].char_id = 7; maze[7][7].has_wall = 1; maze[8][0].char_id = 0; maze[8][1].char_id = 7; maze[8][1].has_wall = 1; maze[8][2].char_id = 0; maze[8][3].char_id = 7; maze[8][3].has_wall = 1; maze[8][4].char_id = 0; maze[8][5].char_id = 7; maze[8][5].has_wall = 1; maze[8][6].char_id = 2; maze[8][6].has_wall = 1; maze[8][7].char_id = 4; maze[8][7].has_wall = 1; maze[9][0].char_id = 0; maze[9][1].char_id = 8; maze[9][1].has_wall = 1; maze[9][2].char_id = 2; maze[9][2].has_wall = 1; maze[9][3].char_id = 10; maze[9][3].has_wall = 1; maze[9][4].char_id = 11; maze[9][4].has_wall = 1; maze[9][5].char_id = 4; maze[9][5].has_wall = 1; maze[9][6].char_id = 0; maze[9][7].char_id = 13; maze[9][7].finish_line = 1; maze[10][0].char_id = 5; maze[10][0].has_wall = 1; maze[10][1].char_id = 0; maze[10][2].char_id = 0; maze[10][3].char_id = 0; maze[10][4].char_id = 6; maze[10][4].has_wall = 1; maze[10][5].char_id = 5; maze[10][5].has_wall = 1; maze[10][6].char_id = 0; maze[10][7].char_id = 5; maze[10][7].has_wall = 1; maze[11][0].char_id = 6; maze[11][0].has_wall = 1; maze[11][1].char_id = 3; maze[11][1].has_wall = 1; maze[11][2].char_id = 3; maze[11][2].has_wall = 1; maze[11][3].char_id = 5; maze[11][3].has_wall = 1; maze[11][4].char_id = 0; maze[11][5].char_id = 1; maze[11][5].has_wall = 1; maze[11][6].char_id = 0; maze[11][7].char_id = 1; maze[11][7].has_wall = 1; maze[12][0].char_id = 0; maze[12][1].char_id = 1; maze[12][1].has_wall = 1; maze[12][2].char_id = 6; maze[12][2].has_wall = 1; maze[12][3].char_id = 1; maze[12][3].has_wall = 1; maze[12][4].char_id = 0; maze[12][5].char_id = 1; maze[12][5].has_wall = 1; maze[12][6].char_id = 0; maze[12][7].char_id = 1; maze[12][7].has_wall = 1; maze[13][0].char_id = 0; maze[13][1].char_id = 0; maze[13][2].char_id = 0; maze[13][3].char_id = 0; maze[13][4].char_id = 0; maze[13][5].char_id = 1; maze[13][5].has_wall = 1; maze[13][6].char_id = 0; maze[13][7].char_id = 6; maze[13][7].has_wall = 1; maze[14][0].char_id = 0; maze[14][1].char_id = 2; maze[14][1].has_wall = 1; maze[14][2].char_id = 2; maze[14][2].has_wall = 1; maze[14][3].char_id = 3; maze[14][3].has_wall = 1; maze[14][4].char_id = 2; maze[14][4].has_wall = 1; maze[14][5].char_id = 3; maze[14][5].has_wall = 1; maze[14][6].char_id = 0; maze[14][7].char_id = 0; maze[15][0].char_id = 0; maze[15][1].char_id = 0; maze[15][2].char_id = 0; maze[15][3].char_id = 0; maze[15][4].char_id = 0; maze[15][5].char_id = 0; maze[15][6].char_id = 0; maze[15][7].char_id = 0; } void draw_maze() { for (i = 0; i < 8; ++i) { for(j = 0; j < 8; ++j) { /* display right half */ set_CS1(); LCD_command(disp_page(i)); LCD_command(disp_ypos(j*8)); for (k = 0; k < 8; ++k) LCD_data(tile_set[maze[j + 8][i].char_id][k]); /* display left half */ set_CS2(); LCD_command(disp_page(i)); LCD_command(disp_ypos(j*8)); for (k = 0; k < 8; ++k) LCD_data(tile_set[maze[j][i].char_id][k]); } } } void msg_well_done(uint8_t a_line) { set_CS2(); LCD_command(disp_page(a_line)); LCD_command(disp_ypos(16)); /* Left half; write WELL */ /* G */ for (i = 0; i < 8; ++i) { LCD_data(charset[22][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* L */ for (i = 0; i < 8; ++i) { LCD_data(charset[11][i]); } /* L */ for (i = 0; i < 8; ++i) { LCD_data(charset[11][i]); } /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* Right half; write DONE ! */ set_CS1(); LCD_command(disp_page(a_line)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* D */ for (i = 0; i < 8; ++i) { LCD_data(charset[3][i]); } /* O */ for (i = 0; i < 8; ++i) { LCD_data(charset[14][i]); } /* N */ for (i = 0; i < 8; ++i) { LCD_data(charset[13][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* ! */ for (i = 0; i < 8; ++i) { LCD_data(charset[44][i]); } } void msg_get_ready() { set_CS2(); LCD_command(disp_page(3)); LCD_command(disp_ypos(24)); /* Left half; write GET */ /* G */ for (i = 0; i < 8; ++i) { LCD_data(charset[6][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* T */ for (i = 0; i < 8; ++i) { LCD_data(charset[19][i]); } /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* Right half; write READY ! */ set_CS1(); LCD_command(disp_page(3)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* R */ for (i = 0; i < 8; ++i) { LCD_data(charset[17][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* A */ for (i = 0; i < 8; ++i) { LCD_data(charset[0][i]); } /* D */ for (i = 0; i < 8; ++i) { LCD_data(charset[3][i]); } /* Y */ for (i = 0; i < 8; ++i) { LCD_data(charset[24][i]); } /* ! */ for (i = 0; i < 8; ++i) { LCD_data(charset[44][i]); } } void msg_your_time(uint8_t line_nbr) { set_CS2(); LCD_command(disp_page(line_nbr)); LCD_command(disp_ypos(24)); /* Left half; write YOUR */ /* Y */ for (i = 0; i < 8; ++i) { LCD_data(charset[24][i]); } /* O */ for (i = 0; i < 8; ++i) { LCD_data(charset[14][i]); } /* U */ for (i = 0; i < 8; ++i) { LCD_data(charset[20][i]); } /* R */ for (i = 0; i < 8; ++i) { LCD_data(charset[17][i]); } /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* Right half; write TIME: */ set_CS1(); LCD_command(disp_page(line_nbr)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* T */ for (i = 0; i < 8; ++i) { LCD_data(charset[19][i]); } /* I */ for (i = 0; i < 8; ++i) { LCD_data(charset[8][i]); } /* M */ for (i = 0; i < 8; ++i) { LCD_data(charset[12][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } } void msg_kycklingmiddag(uint8_t line_nbr) { set_CS2(); LCD_command(disp_page(line_nbr)); LCD_command(disp_ypos(0)); /* Left half; write KYCKLING */ /* K */ for (i = 0; i < 8; ++i) { LCD_data(charset[10][i]); } /* Y */ for (i = 0; i < 8; ++i) { LCD_data(charset[24][i]); } /* C */ for (i = 0; i < 8; ++i) { LCD_data(charset[2][i]); } /* K */ for (i = 0; i < 8; ++i) { LCD_data(charset[10][i]); } /* L */ for (i = 0; i < 8; ++i) { LCD_data(charset[11][i]); } /* I */ for (i = 0; i < 8; ++i) { LCD_data(charset[8][i]); } /* N */ for (i = 0; i < 8; ++i) { LCD_data(charset[13][i]); } /* G */ for (i = 0; i < 8; ++i) { LCD_data(charset[6][i]); } /* Right half; write MIDDAG!! */ set_CS1(); LCD_command(disp_page(line_nbr)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* M */ for (i = 0; i < 8; ++i) { LCD_data(charset[12][i]); } /* I */ for (i = 0; i < 8; ++i) { LCD_data(charset[8][i]); } /* D */ for (i = 0; i < 8; ++i) { LCD_data(charset[3][i]); } /* D */ for (i = 0; i < 8; ++i) { LCD_data(charset[3][i]); } /* A */ for (i = 0; i < 8; ++i) { LCD_data(charset[0][i]); } /* G */ for (i = 0; i < 8; ++i) { LCD_data(charset[6][i]); } /* ! */ for (i = 0; i < 8; ++i) { LCD_data(charset[44][i]); } /* ! */ for (i = 0; i < 8; ++i) { LCD_data(charset[44][i]); } } void msg_best_time(uint8_t line_nbr) { set_CS2(); LCD_command(disp_page(line_nbr)); LCD_command(disp_ypos(24)); /* Left half; write YOUR */ /* B */ for (i = 0; i < 8; ++i) { LCD_data(charset[1][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* S */ for (i = 0; i < 8; ++i) { LCD_data(charset[18][i]); } /* T */ for (i = 0; i < 8; ++i) { LCD_data(charset[19][i]); } /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* Right half; write TIME: */ set_CS1(); LCD_command(disp_page(line_nbr)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* ' ' */ for (i = 0; i < 8; ++i) { LCD_data(0); } /* T */ for (i = 0; i < 8; ++i) { LCD_data(charset[19][i]); } /* I */ for (i = 0; i < 8; ++i) { LCD_data(charset[8][i]); } /* M */ for (i = 0; i < 8; ++i) { LCD_data(charset[12][i]); } /* E */ for (i = 0; i < 8; ++i) { LCD_data(charset[4][i]); } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } } void msg_empty_record(uint8_t line_nbr) { /* Left half */ set_CS2(); LCD_command(disp_page(line_nbr)); LCD_command(disp_ypos(32)); /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } /* Right half */ set_CS1(); LCD_command(disp_page(line_nbr)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* Leave 1 tile for space */ /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } /* - */ for (i = 0; i < 8; ++i) { LCD_data(charset[45][i]); } } void msg_a_time(uint8_t line_nbr, double a_time) { uint8_t tempv = 0; /* Left half */ set_CS2(); LCD_command(disp_page(line_nbr)); LCD_command(disp_ypos(32)); /* minutes */ tempv = get_minutes(a_time); /* get the time in whole minutes*/ for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv / 10][i]); /* 10 minutes */ } for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv % 10][i]); /* 1 minute */ } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } /* seconds */ tempv = get_seconds(a_time); for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv / 10][i]); /* 10s of seconds*/ } /* Right half */ set_CS1(); LCD_command(disp_page(line_nbr)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); /* seconds continued */ for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv % 10][i]); } /* : */ for (i = 0; i < 8; ++i) { LCD_data(charset[42][i]); } /* tenths */ tempv = get_tenths(a_time); for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv][i]); } /* maybe implement a get_hundredth ... */ tempv = get_hundredths(a_time); for (i = 0; i < 8; ++i) { LCD_data(charset[29 + tempv][i]); } } void do_countdown() { for (j = 5; j > 0; --j) { /* left half */ set_CS2(); LCD_command(disp_page(5)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(56)); for (i = 0; i < 8; ++i) { LCD_data(charset[29][i]); } /* Right half */ set_CS1(); LCD_command(disp_page(5)); /* Note that both halves needs to be set to the correct page */ LCD_command(disp_ypos(0)); for (i = 0; i < 8; ++i) { LCD_data(charset[29 + j][i]); } _delay_ms(100); } } int main(void) { init_display(); ADC_Init(); clear_display(); make_maze(); draw_maze(); timer_setup(); uint8_t current_mode = GAME_START; BEST_TIME = UINT32_MAX; int bool_v = 0; //msg_game_over(); /* Replace with your application code */ while (1) { switch(current_mode) { case GAME_START: current_mode = GAME_RUN; GAME_TIME = 0; msg_get_ready(); do_countdown(); draw_maze(); /* in a proper c program the start position of the ball should be calculated, but alas... */ a_ball.posx = 4; a_ball.posy = 30; a_ball.v_x = 0; a_ball.v_y = 12; TCNT1 = 0; break; case GAME_RUN: a_ball.v_y += (getXValues()*3); /* maybe we should make the game less sensitive */ a_ball.v_x -= (getYValues()*3); draw_ball(); GAME_TIME += TCNT1; // read timer 1 counter TCNT1 = 0; // reset it for next read if (maze[a_ball.posy/8][a_ball.posx/8].finish_line) current_mode = GAME_END; _delay_ms(5); break; case GAME_END: if (GAME_TIME < BEST_TIME) { BEST_TIME = GAME_TIME; msg_kycklingmiddag(1); } else { msg_well_done(1); } msg_your_time(3); msg_a_time(4, get_time_s(GAME_TIME)); msg_best_time(5); msg_a_time(6, get_time_s(BEST_TIME)); _delay_ms(1000); draw_maze(); current_mode = GAME_START; break; } } }