Use keydown instead of events

This commit is contained in:
Darks 2020-10-27 22:47:13 +01:00
parent bd16f89b30
commit 242439c05b
Signed by: Darks
GPG Key ID: 7515644268BE1433
2 changed files with 10 additions and 12 deletions

Binary file not shown.

View File

@ -17,14 +17,13 @@ void dialog(dialog_t *dialog)
int talking = 0;
// Init dialog characters pictures
img_t tmp = img_hflip_create(*(dialog->characters[1]));
img_t char_flipped = img_hflip_create(*(dialog->characters[1]));
img_t chars_img[2][2] = {
{ img_copy(*(dialog->characters[0])),
img_darken_create(*(dialog->characters[0])) },
{ img_copy(tmp),
img_darken_create(tmp)}
{ char_flipped,
img_darken_create(char_flipped)}
};
img_destroy(tmp);
// Init text properties
int current_replica = 0;
@ -34,22 +33,21 @@ void dialog(dialog_t *dialog)
// Entering main loop
prof_enter(prof_fps);
while(!(e.type == KEYEV_UP && e.key == KEY_EXIT)
&& dialog->text[current_replica])
while(dialog->text[current_replica])
{
// Get last keyboard event
e = pollevent();
clearevents();
// Manage events
if(e.type == KEYEV_UP && e.key == KEY_EXIT) break;
if(e.type == KEYEV_DOWN && e.key == KEY_SHIFT && wait_change == 1)
if(keydown(KEY_EXIT)) break;
if(keydown(KEY_SHIFT) && wait_change == 1)
{
// Reset current chars
current_chars = 0;
// Waiting for key up
wait_change = 2;
}
if(e.type == KEYEV_UP && e.key == KEY_SHIFT && wait_change == 2)
if(!keydown(KEY_SHIFT) && wait_change == 2)
{
// Change who's speaking
talking = !talking;
@ -82,10 +80,10 @@ void dialog(dialog_t *dialog)
// Display everything
img_render_vram(chars_img[0][talking],
DWIDTH * 0.15,
DHEIGHT * (0.15 + 0.04 * cos(time * 0.000005)));
DHEIGHT * (0.15 + 0.04 * fcos(time * 0.000005)));
img_render_vram(chars_img[1][!talking],
DWIDTH * 0.85 - chars_img[1][0].width,
DHEIGHT * (0.15 + 0.04 * sin(time * 0.000005)));
DHEIGHT * (0.15 + 0.04 * fsin(time * 0.000005)));
display_text(dialog->text[current_replica], (int)current_chars);