add scrolling in menu

This commit is contained in:
Lephenixnoir 2021-08-22 00:22:55 +02:00
parent 1e23517e4b
commit ac7489a172
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 20 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 401 B

View File

@ -19,6 +19,9 @@ int main_menu(int *episode, int *level)
int s_episode = 0;
int s_level = 0;
int scroll = 0;
int target_scroll = 0;
int scroll_by_episode[20] = { 0 };
*episode = 0;
*level = 0;
@ -29,6 +32,13 @@ int main_menu(int *episode, int *level)
time += 1.0 / 30;
/* Smooth scroll update */
if(target_scroll != scroll) {
int diff = (target_scroll - scroll) * 3 / 16;
if(diff == 0) diff = (target_scroll > scroll) ? 1 : -1;
scroll += diff;
}
/* Keyboard input */
key_event_t e;
@ -44,8 +54,8 @@ int main_menu(int *episode, int *level)
break;
}
if(e.type == KEYEV_DOWN && e.key == KEY_DOWN &&
(s_episode < episode_count
|| s_level < episodes[s_episode].level_count)) {
(s_episode < episode_count - 1
|| s_level < episodes[s_episode].level_count - 1)) {
s_level++;
if(s_level >= episodes[s_episode].level_count) {
s_episode++;
@ -64,20 +74,23 @@ int main_menu(int *episode, int *level)
if(input_finished)
break;
target_scroll = scroll_by_episode[0]-scroll_by_episode[s_episode];
/* Rendering */
dclear(C_BLACK);
dimage(330 + scroll, DHEIGHT/2 - img_title.height / 2,
dimage(330+scroll, DHEIGHT/2 - img_title.height / 2,
&img_title);
render_player(265 + scroll, DHEIGHT/2, time * 0.8);
render_player(268+scroll, DHEIGHT/2, time * 0.8);
int x = 180, y=40;
int x=188+scroll, y=40;
for(int i = 0; i < episode_count; i++) {
episode_t const *e = &episodes[i];
scroll_by_episode[i] = x;
duet_text_opt(x, y, C_WHITE, C_NONE, DTEXT_LEFT, DTEXT_TOP,
e->name, -1);
x -= 13;
x -= 11;
for(int j = 0; j < e->level_count; j++) {
int rx = x - 38 * (j/4);
@ -90,7 +103,7 @@ int main_menu(int *episode, int *level)
dsubimage(rx-30, ry, &img_levels, 0, 31*j, 31, 31, DIMAGE_NONE);
}
x -= 35 * ((e->level_count + 3) / 4);
x -= 18;
x -= 20;
}
dupdate();