add score; fix y-axis; add pause/sleep

master
Clyne 4 years ago
parent 0f5402ff37
commit 245866891a

109
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) if (x < 0 || y < 0 || x >= DISP_WIDTH || y >= DISP_HEIGHT)
return; return;
y = DISP_HEIGHT - 1 - y;
if (state) if (state)
dogs_buffer[y / 8 * DISP_WIDTH + x] |= (1 << (y % 8)); dogs_buffer[y / 8 * DISP_WIDTH + x] |= (1 << (y % 8));
else else
@ -236,94 +237,94 @@ static const unsigned char draw_number_bitmaps[10][10] = {
0b00011000, 0b00011000,
}, },
{ 8, 8, // '1' { 8, 8, // '1'
0b01111100,
0b00010000,
0b00010000,
0b00010000,
0b00010000,
0b00010000,
0b00010100,
0b00011000, 0b00011000,
0b00101000,
0b00001000,
0b00001000,
0b00001000,
0b00001000,
0b00001000,
0b00111110,
}, },
{ 8, 8, // '2' { 8, 8, // '2'
0b00011000, 0b01111110,
0b00100100,
0b01000010,
0b00000010,
0b00000100,
0b00001000, 0b00001000,
0b00010000, 0b00010000,
0b01111110, 0b00100000,
0b01000000,
0b01000010,
0b00100100,
0b00011000,
}, },
{ 8, 8, // '3' { 8, 8, // '3'
0b00111000, 0b00011100,
0b01000100, 0b00100010,
0b00000010, 0b01000000,
0b00100000,
0b00111100, 0b00111100,
0b00000100, 0b01000000,
0b00000010, 0b00100010,
0b01000100, 0b00011100,
0b00111000,
}, },
{ 8, 8, // '4' { 8, 8, // '4'
0b00000100, 0b00100000,
0b00001100, 0b00100000,
0b00010100, 0b00100000,
0b00111110,
0b00100100, 0b00100100,
0b01111100, 0b00101000,
0b00000100, 0b00110000,
0b00000100, 0b00100000,
0b00000100,
}, },
{ 8, 8, // '5' { 8, 8, // '5'
0b01111110, 0b00011100,
0b00100010,
0b01000000, 0b01000000,
0b01111000, 0b01000000,
0b00000100, 0b00100000,
0b00000010, 0b00011110,
0b00000010, 0b00000010,
0b01000100, 0b01111110,
0b00111000,
}, },
{ 8, 8, // '6' { 8, 8, // '6'
0b00011100,
0b00100000,
0b01000000,
0b01011100,
0b01100010,
0b01000010,
0b00100100,
0b00011000, 0b00011000,
}, 0b00100100,
{ 8, 8, // '7' 0b01000010,
0b01111110, 0b01000110,
0b00111010,
0b00000010, 0b00000010,
0b00000100, 0b00000100,
0b00111000,
},
{ 8, 8, // '7'
0b00001000,
0b00001000,
0b00001000,
0b00001000, 0b00001000,
0b00010000, 0b00010000,
0b00010000, 0b00100000,
0b00010000, 0b01000000,
0b00010000, 0b01111110,
}, },
{ 8, 8, // '8' { 8, 8, // '8'
0b00011000, 0b00011000,
0b00100100, 0b00100100,
0b01000010, 0b01000010,
0b00111100,
0b00100100, 0b00100100,
0b00111100,
0b01000010, 0b01000010,
0b00100100, 0b00100100,
0b00011000, 0b00011000,
}, },
{ 8, 8, // '9' { 8, 8, // '9'
0b00011000, 0b00011100,
0b00100100,
0b01000010,
0b00100010, 0b00100010,
0b00011110, 0b01000000,
0b00000010, 0b01111000,
0b01000100, 0b01000100,
0b00111000, 0b01000010,
0b00100100,
0b00011000,
}, },
}; };
@ -335,6 +336,8 @@ void draw_number(int x, int y, int number)
int count; int count;
for (count = 0; tmp; count++) for (count = 0; tmp; count++)
tmp /= 10; tmp /= 10;
if (count == 0)
count = 1;
x += count * 8; x += count * 8;
do { do {
x -= 8; x -= 8;

@ -20,6 +20,7 @@ extern unsigned char dogs_buffer[DISP_WIDTH * DISP_HEIGHT / 8];
void dogs_init(); void dogs_init();
void dogs_clear(); void dogs_clear();
void dogs_flush(); void dogs_flush();
void dogs_set_sleep(bool sleep);
void draw_pixel(int x, int y, bool state); void draw_pixel(int x, int y, bool state);
void draw_rect(int x, int y, int w, int h); void draw_rect(int x, int y, int w, int h);

@ -88,52 +88,72 @@ THD_FUNCTION(Thread2, arg)
0b11000000, 0b11000000,
}; };
int t1x = DISP_WIDTH / 2, t1o = 10; bool sleep = false;
int t2x = DISP_WIDTH, t2o = 50; int score = 0;
int t1x = DISP_WIDTH / 2, t1o = 15;
int t2x = DISP_WIDTH, t2o = 49;
int py = DISP_HEIGHT / 2 - 4; int py = DISP_HEIGHT / 2 - 4;
int vy = 0; int vy = 0;
int counter = 0; int counter = 0;
int mv = readVddmv(); int mv = readVddmv();
while (1) { while (1) {
// Player logic if (button_state & BUTTON_1) {
if (py > 0) { sleep ^= true;
py += vy; dogs_set_sleep(sleep);
if (vy > -4)
vy--;
} else if (py < 0) {
py = 0;
}
if (button_state & BUTTON_2) {
vy = 5;
if (py <= 0)
py = 1;
} }
// Rendering if (!sleep) {
dogs_clear(); // Player logic
if (py > 0) {
draw_rect(t1x, 0, 4, t1o - 10); py += vy;
draw_rect(t1x, t1o + 10, 4, DISP_HEIGHT - t1o + 10); if (vy > -3)
draw_rect(t2x, 0, 4, t2o - 10); vy--;
draw_rect(t2x, t2o + 10, 4, DISP_HEIGHT - t2o + 10); } else {
draw_bitmap(4, py, testbitmap); if (py < 0)
py = 0;
draw_number(0, 56, mv); if (score > 0)
dogs_flush(); score = 0;
}
// Game logic
if (++counter == 50) { if (button_state & BUTTON_2) {
counter = 0; vy = 5;
mv = !(PWR->CSR & PWR_CSR_PVDO) ? readVddmv() : 1; 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); chThdSleepS(TIME_MS2I(100) / 64);
} }

Loading…
Cancel
Save