diff --git a/src/game_graphics.c b/src/game_graphics.c index adac3b9..df71127 100644 --- a/src/game_graphics.c +++ b/src/game_graphics.c @@ -93,6 +93,22 @@ static const uint8_t box_new_hi_score[BOX_WIDTH] = { 0, 0,102, 0, 23, 5, 0, 7, 15, 20, 0, 1, 0, 14, 5, 23, 0, 8, 9, 7, 8, 45, 19, 3, 15, 18, 5, 33, 0,102, 0, 0 }; +#define INSTR_BOX_WIDTH 14 +#define INSTR_BOX_HEIGHT 8 +#define INSTR_BOX_SIZE (INSTR_BOX_HEIGHT * INSTR_BOX_WIDTH) +#define INSTR_BOX_X 27 +#define INSTR_BOX_Y 114 +static const uint8_t instruction_box[INSTR_BOX_SIZE] = { + 103, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,104, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, + 105, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,106 +}; + // The grid is 5x5 squares, // It is offset on the left side by 7 pixels and on the top by 14 @@ -101,7 +117,7 @@ static const uint8_t box_new_hi_score[BOX_WIDTH] = { void draw_field_borders_on_buffer(uint8_t brd, uint8_t* buf); void draw_picture(uint8_t w, uint8_t h, uint8_t x, uint8_t y, const uint8_t *data, uint8_t *dest); void direct_draw_number(uint16_t n, uint8_t len, uint8_t x, uint8_t y, uint8_t *disp_buf); - +void draw_graph_char_box(uint8_t x_offset, uint8_t y_offset, uint8_t width, uint8_t height, uint8_t const *data, uint8_t* buf); void ddraw_field_borders_on_buffer(uint8_t brd) { draw_field_borders_on_buffer(brd, front_buf); @@ -127,7 +143,22 @@ void draw_game_background(uint16_t hi_score) { // Draw the high-score. This won't change at every turn, so makes sense to just draw once direct_draw_number(hi_score, HIGH_TEXT_WIDTH, HIGH_TEXT_X, HIGH_TEXT_Y, front_buf); - +/* + // Draw instruction box + for(uint16_t tile = 0; tile < INSTR_BOX_SIZE; tile++) { + if(!instruction_box[tile]) continue; + + uint8_t x = tile % INSTR_BOX_WIDTH; + uint8_t y = tile / INSTR_BOX_WIDTH; + uint8_t invert = instruction_box[tile] & 0x80; + uint8_t ch_num = instruction_box[tile] & 0x7F; + + for(uint8_t row = 0; row < CHAR_HEIGHT; row++) { + uint16_t offset = line_offset_map[INSTR_BOX_Y + (y * CHAR_HEIGHT) + row] + INSTR_BOX_X + x; + front_buf[offset] = invert ? ((~CHARSET[(ch_num * CHAR_HEIGHT) + row]) & 0x7F) : CHARSET[(ch_num * CHAR_HEIGHT) + row]; + } + } +*/ // Copy the data from display page 1 to 2 memcpy((void*)DISPLAY_PAGE_2, (void*)DISPLAY_PAGE_1, DISPLAY_PAGE_SIZE); @@ -233,41 +264,33 @@ void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score) { else if (done > 0) content = box_content_win; else content = box_content_lose; - // And now, the content!!! - for(uint16_t tile = 0; tile < BOX_CONTENT_SIZE; tile++) { - if(!content[tile]) continue; - - uint8_t x = tile % (SCREEN_WIDTH_B - (ENDGAME_BOX_X_OFFSET * 2) - 4); - uint8_t y = tile / (SCREEN_WIDTH_B - (ENDGAME_BOX_X_OFFSET * 2) - 4); - uint8_t invert = content[tile] & 0x80; - uint8_t ch_num = content[tile] & 0x7F; - - for(uint8_t row = 0; row < CHAR_HEIGHT; row++) { - uint16_t offset = line_offset_map[ENDGAME_BOX_Y_OFFSET + (2 * CHAR_HEIGHT) + (y * CHAR_HEIGHT) + row] + ENDGAME_BOX_X_OFFSET + 2 + x; - front_buf[offset] = invert ? ((~CHARSET[(ch_num * CHAR_HEIGHT) + row]) & 0x7F) : CHARSET[(ch_num * CHAR_HEIGHT) + row]; - } - } + draw_graph_char_box(ENDGAME_BOX_X_OFFSET + 2, (ENDGAME_BOX_Y_OFFSET + (2 * CHAR_HEIGHT)), BOX_WIDTH, BOX_HEIGHT, content, front_buf); if(done != 0) { // Print the score direct_draw_number(score, ENDGAME_BOX_SCORE_LEN, ENDGAME_BOX_X_OFFSET + 23, ENDGAME_BOX_Y_OFFSET + (11 * CHAR_HEIGHT), front_buf); if(score > hi_score) { - for(uint8_t tile = 0; tile < BOX_WIDTH; tile++) { - if(!box_new_hi_score[tile]) continue; - - uint8_t invert = box_new_hi_score[tile] & 0x80; - uint8_t ch_num = box_new_hi_score[tile] & 0x7F; - - for(uint8_t row = 0; row < CHAR_HEIGHT; row++) { - uint16_t offset = line_offset_map[ENDGAME_BOX_Y_OFFSET + (2 * CHAR_HEIGHT) + (13 * CHAR_HEIGHT) + row] + ENDGAME_BOX_X_OFFSET + 2 + tile; - front_buf[offset] = invert ? ((~CHARSET[(ch_num * CHAR_HEIGHT) + row]) & 0x7F) : CHARSET[(ch_num * CHAR_HEIGHT) + row]; - } - } + draw_graph_char_box(ENDGAME_BOX_X_OFFSET + 2, (ENDGAME_BOX_Y_OFFSET + (2 * CHAR_HEIGHT) + (13 * CHAR_HEIGHT)), BOX_WIDTH, 1, box_new_hi_score, front_buf); + } + } +} + +void draw_graph_char_box(uint8_t x_offset, uint8_t y_offset, uint8_t width, uint8_t height, uint8_t const *data, uint8_t* buf) { + // Draw box + for(uint16_t tile = 0; tile < width * height; tile++) { + if(!data[tile]) continue; + + uint8_t x = tile % width; + uint8_t y = tile / width; + uint8_t invert = data[tile] & 0x80; + uint8_t ch_num = data[tile] & 0x7F; + + for(uint8_t row = 0; row < CHAR_HEIGHT; row++) { + uint16_t offset = line_offset_map[y_offset + (y * CHAR_HEIGHT) + row] + x_offset + x; + buf[offset] = invert ? ((~CHARSET[(ch_num * CHAR_HEIGHT) + row]) & 0x7F) : CHARSET[(ch_num * CHAR_HEIGHT) + row]; } } - - // TODO: Add additional info to the box, if necessary } // Note that the horizontal values here are in group of 7 pixels