use lut
This commit is contained in:
parent
509da0b18a
commit
87220d57be
1 changed files with 29 additions and 42 deletions
|
@ -10,8 +10,8 @@ struct character {
|
|||
char ch;
|
||||
int x, y, v;
|
||||
} chars[MAXCH];
|
||||
int screen_width, screen_height, char_width, char_height;
|
||||
|
||||
int screen_width, screen_height, char_width, char_height;
|
||||
int hit, miss, wrong;
|
||||
|
||||
int randint(int l, int r) {
|
||||
|
@ -40,7 +40,6 @@ void progress(int frame) {
|
|||
if (c->ch) {
|
||||
c->y += c->v;
|
||||
if (c->y < 0) {
|
||||
hit++;
|
||||
c->ch = '\0';
|
||||
}
|
||||
if (c->y + char_height >= screen_height) {
|
||||
|
@ -55,12 +54,16 @@ void check_hit(char ch) {
|
|||
int m = -1;
|
||||
for (int i = 0; i < LENGTH(chars); i++) {
|
||||
struct character *c = &chars[i];
|
||||
if (ch == c->ch && c->v > 0 && (m == -1 || c->y > chars[m].y)) {
|
||||
if (ch == c->ch && c->v > 0 && (m < 0 || c->y > chars[m].y)) {
|
||||
m = i;
|
||||
}
|
||||
}
|
||||
if (m == -1) wrong++;
|
||||
else chars[m].v = -(screen_height - char_height + 1) / (FPS);
|
||||
if (m == -1) {
|
||||
wrong++;
|
||||
} else {
|
||||
hit++;
|
||||
chars[m].v = -(screen_height - char_height + 1) / (FPS);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t px[32 * 16], blank[32 * 16];
|
||||
|
@ -81,14 +84,27 @@ void render() {
|
|||
}
|
||||
}
|
||||
io_write(AM_GPU_FBDRAW, 0, 0, NULL, 0, 0, true);
|
||||
for (int i = 0; i < 80; i++) putch('\b');
|
||||
printf("Hit: %d; Miss: %d; Wrong: %d", hit, miss, wrong);
|
||||
}
|
||||
|
||||
char lut[256] = {
|
||||
[AM_KEY_A] = 'A', [AM_KEY_B] = 'B', [AM_KEY_C] = 'C', [AM_KEY_D] = 'D',
|
||||
[AM_KEY_E] = 'E', [AM_KEY_F] = 'F', [AM_KEY_G] = 'G', [AM_KEY_H] = 'H',
|
||||
[AM_KEY_I] = 'I', [AM_KEY_J] = 'J', [AM_KEY_K] = 'K', [AM_KEY_L] = 'L',
|
||||
[AM_KEY_M] = 'M', [AM_KEY_N] = 'N', [AM_KEY_O] = 'O', [AM_KEY_P] = 'P',
|
||||
[AM_KEY_Q] = 'Q', [AM_KEY_R] = 'R', [AM_KEY_S] = 'S', [AM_KEY_T] = 'T',
|
||||
[AM_KEY_U] = 'U', [AM_KEY_V] = 'V', [AM_KEY_W] = 'W', [AM_KEY_X] = 'X',
|
||||
[AM_KEY_Y] = 'Y', [AM_KEY_Z] = 'Z',
|
||||
};
|
||||
|
||||
int main() {
|
||||
char_width = 8;
|
||||
char_height = 16;
|
||||
|
||||
for (int i = 0; i < char_width * char_height; i ++) px[i] = 0x345678;
|
||||
for (int i = 0; i < char_width * char_height; i ++) blank[i] = 0;
|
||||
|
||||
ioe_init();
|
||||
|
||||
screen_width = io_read(AM_GPU_CONFIG).width;
|
||||
|
@ -101,45 +117,16 @@ int main() {
|
|||
while (current < frames) {
|
||||
progress(current);
|
||||
current++;
|
||||
|
||||
while (1) {
|
||||
AM_INPUT_KEYBRD_T ev = io_read(AM_INPUT_KEYBRD);
|
||||
if (ev.keycode == AM_KEY_NONE) break;
|
||||
if (!ev.keydown) continue;
|
||||
switch (ev.keycode) {
|
||||
case AM_KEY_A: check_hit('A'); break;
|
||||
case AM_KEY_B: check_hit('B'); break;
|
||||
case AM_KEY_C: check_hit('C'); break;
|
||||
case AM_KEY_D: check_hit('D'); break;
|
||||
case AM_KEY_E: check_hit('E'); break;
|
||||
case AM_KEY_F: check_hit('F'); break;
|
||||
case AM_KEY_G: check_hit('G'); break;
|
||||
case AM_KEY_H: check_hit('H'); break;
|
||||
case AM_KEY_I: check_hit('I'); break;
|
||||
case AM_KEY_J: check_hit('J'); break;
|
||||
case AM_KEY_K: check_hit('K'); break;
|
||||
case AM_KEY_L: check_hit('L'); break;
|
||||
case AM_KEY_M: check_hit('M'); break;
|
||||
case AM_KEY_N: check_hit('N'); break;
|
||||
case AM_KEY_O: check_hit('O'); break;
|
||||
case AM_KEY_P: check_hit('P'); break;
|
||||
case AM_KEY_Q: check_hit('Q'); break;
|
||||
case AM_KEY_R: check_hit('R'); break;
|
||||
case AM_KEY_S: check_hit('S'); break;
|
||||
case AM_KEY_T: check_hit('T'); break;
|
||||
case AM_KEY_U: check_hit('U'); break;
|
||||
case AM_KEY_V: check_hit('V'); break;
|
||||
case AM_KEY_W: check_hit('W'); break;
|
||||
case AM_KEY_X: check_hit('X'); break;
|
||||
case AM_KEY_Y: check_hit('Y'); break;
|
||||
case AM_KEY_Z: check_hit('Z'); break;
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < 80; i++) putch('\b');
|
||||
printf("Hit: %d; Miss: %d; Wrong: %d", hit, miss, wrong);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
AM_INPUT_KEYBRD_T ev = io_read(AM_INPUT_KEYBRD);
|
||||
if (ev.keycode == AM_KEY_NONE) break;
|
||||
if (ev.keydown && lut[ev.keycode]) {
|
||||
check_hit(lut[ev.keycode]);
|
||||
}
|
||||
};
|
||||
|
||||
if (current > rendered) {
|
||||
render();
|
||||
rendered = current;
|
||||
|
|
Loading…
Reference in a new issue