diff --git a/dogs.c b/dogs.c index 9b341f3..12482f5 100644 --- a/dogs.c +++ b/dogs.c @@ -191,6 +191,7 @@ void draw_pixel(int x, int y, bool state) { if (x < 0 || y < 0 || x >= DISP_WIDTH || y >= DISP_HEIGHT) return; + y = DISP_HEIGHT - 1 - y; if (state) dogs_buffer[y / 8 * DISP_WIDTH + x] |= (1 << (y % 8)); else @@ -236,94 +237,94 @@ static const unsigned char draw_number_bitmaps[10][10] = { 0b00011000, }, { 8, 8, // '1' + 0b01111100, + 0b00010000, + 0b00010000, + 0b00010000, + 0b00010000, + 0b00010000, + 0b00010100, 0b00011000, - 0b00101000, - 0b00001000, - 0b00001000, - 0b00001000, - 0b00001000, - 0b00001000, - 0b00111110, }, { 8, 8, // '2' - 0b00011000, - 0b00100100, - 0b01000010, - 0b00000010, - 0b00000100, + 0b01111110, 0b00001000, 0b00010000, - 0b01111110, + 0b00100000, + 0b01000000, + 0b01000010, + 0b00100100, + 0b00011000, }, { 8, 8, // '3' - 0b00111000, - 0b01000100, - 0b00000010, + 0b00011100, + 0b00100010, + 0b01000000, + 0b00100000, 0b00111100, - 0b00000100, - 0b00000010, - 0b01000100, - 0b00111000, + 0b01000000, + 0b00100010, + 0b00011100, }, { 8, 8, // '4' - 0b00000100, - 0b00001100, - 0b00010100, + 0b00100000, + 0b00100000, + 0b00100000, + 0b00111110, 0b00100100, - 0b01111100, - 0b00000100, - 0b00000100, - 0b00000100, + 0b00101000, + 0b00110000, + 0b00100000, }, { 8, 8, // '5' - 0b01111110, + 0b00011100, + 0b00100010, 0b01000000, - 0b01111000, - 0b00000100, - 0b00000010, + 0b01000000, + 0b00100000, + 0b00011110, 0b00000010, - 0b01000100, - 0b00111000, + 0b01111110, }, { 8, 8, // '6' - 0b00011100, - 0b00100000, - 0b01000000, - 0b01011100, - 0b01100010, - 0b01000010, - 0b00100100, 0b00011000, - }, - { 8, 8, // '7' - 0b01111110, + 0b00100100, + 0b01000010, + 0b01000110, + 0b00111010, 0b00000010, 0b00000100, + 0b00111000, + }, + { 8, 8, // '7' + 0b00001000, + 0b00001000, + 0b00001000, 0b00001000, 0b00010000, - 0b00010000, - 0b00010000, - 0b00010000, + 0b00100000, + 0b01000000, + 0b01111110, }, { 8, 8, // '8' 0b00011000, 0b00100100, 0b01000010, - 0b00111100, 0b00100100, + 0b00111100, 0b01000010, 0b00100100, 0b00011000, }, { 8, 8, // '9' - 0b00011000, - 0b00100100, - 0b01000010, + 0b00011100, 0b00100010, - 0b00011110, - 0b00000010, + 0b01000000, + 0b01111000, 0b01000100, - 0b00111000, + 0b01000010, + 0b00100100, + 0b00011000, }, }; @@ -335,6 +336,8 @@ void draw_number(int x, int y, int number) int count; for (count = 0; tmp; count++) tmp /= 10; + if (count == 0) + count = 1; x += count * 8; do { x -= 8; diff --git a/dogs.h b/dogs.h index c165979..194c3e1 100644 --- a/dogs.h +++ b/dogs.h @@ -20,6 +20,7 @@ extern unsigned char dogs_buffer[DISP_WIDTH * DISP_HEIGHT / 8]; void dogs_init(); void dogs_clear(); void dogs_flush(); +void dogs_set_sleep(bool sleep); void draw_pixel(int x, int y, bool state); void draw_rect(int x, int y, int w, int h); diff --git a/main.c b/main.c index 61bda23..bc8fec5 100644 --- a/main.c +++ b/main.c @@ -88,52 +88,72 @@ THD_FUNCTION(Thread2, arg) 0b11000000, }; - int t1x = DISP_WIDTH / 2, t1o = 10; - int t2x = DISP_WIDTH, t2o = 50; + bool sleep = false; + int score = 0; + + int t1x = DISP_WIDTH / 2, t1o = 15; + int t2x = DISP_WIDTH, t2o = 49; int py = DISP_HEIGHT / 2 - 4; int vy = 0; int counter = 0; int mv = readVddmv(); while (1) { - // Player logic - if (py > 0) { - py += vy; - if (vy > -4) - vy--; - } else if (py < 0) { - py = 0; - } - - if (button_state & BUTTON_2) { - vy = 5; - if (py <= 0) - py = 1; + if (button_state & BUTTON_1) { + sleep ^= true; + dogs_set_sleep(sleep); } - // Rendering - dogs_clear(); - - draw_rect(t1x, 0, 4, t1o - 10); - draw_rect(t1x, t1o + 10, 4, DISP_HEIGHT - t1o + 10); - draw_rect(t2x, 0, 4, t2o - 10); - draw_rect(t2x, t2o + 10, 4, DISP_HEIGHT - t2o + 10); - draw_bitmap(4, py, testbitmap); - - draw_number(0, 56, mv); - dogs_flush(); - - // Game logic - if (++counter == 50) { - counter = 0; - mv = !(PWR->CSR & PWR_CSR_PVDO) ? readVddmv() : 1; + if (!sleep) { + // Player logic + if (py > 0) { + py += vy; + if (vy > -3) + vy--; + } else { + if (py < 0) + py = 0; + if (score > 0) + score = 0; + } + + if (button_state & BUTTON_2) { + vy = 5; + if (py <= 0) + py = 1; + } + + // Rendering + dogs_clear(); + + draw_rect(t1x, 0, 4, t1o - 10); + draw_rect(t1x, t1o + 10, 4, DISP_HEIGHT - t1o + 10); + draw_rect(t2x, 0, 4, t2o - 10); + draw_rect(t2x, t2o + 10, 4, DISP_HEIGHT - t2o + 10); + draw_bitmap(4, py, testbitmap); + + draw_number(DISP_WIDTH - 33, DISP_HEIGHT - 8, mv); + draw_number(DISP_WIDTH - 33, DISP_HEIGHT - 16, score); + dogs_flush(); + + // Game logic + if (++counter == 50) { + counter = 0; + mv = !(PWR->CSR & PWR_CSR_PVDO) ? readVddmv() : 1; + } + + if (t1x == 4) + score = (py + 2 > t1o - 10 && py + 6 < t1o + 10) ? score + 1 : 0; + if (t2x == 4) + score = (py + 2 > t2o - 10 && py + 6 < t2o + 10) ? score + 1 : 0; + + t1x -= 2; + if (t1x <= -5) + t1x = DISP_WIDTH; + t2x -= 2; + if (t2x <= -5) + t2x = DISP_WIDTH; } - t1x -= 2; - if (t1x <= -5) - t1x = DISP_WIDTH; - t2x -= 2; - if (t2x <= -5) - t2x = DISP_WIDTH; chThdSleepS(TIME_MS2I(100) / 64); }