From ac7489a1727e357cfc568f4930e9ee1ff7df2bc0 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 22 Aug 2021 00:22:55 +0200 Subject: [PATCH] add scrolling in menu --- assets-cg/levels.png | Bin 396 -> 401 bytes src/menu.c | 27 ++++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/assets-cg/levels.png b/assets-cg/levels.png index 34aaa65f055409c06953d61153050617f9411469..0144b47f3865463fd9fa289cfa0d75deab988eb3 100644 GIT binary patch delta 307 zcmV-30nGl41CaxeLk0{Ql$NDQkx3|j3rR#lRCwC$+Ch$jKoCGtFrKjw*_VVBi3>sK zD$^~#x19{7QZRlp(*yu_F(3V~*1ALolu~wQJbeBD002T!C|WoR2LJ%RI%DB1oQ1P+ z006#5@sDb)%cq5XW)Doe)FK0qF0s(?$iSxISpzQ(e>XHTu=)0yHFW%U-u;|^53%jT zT<1OZBmLeE0BAL>rq#5XR?}))4FJ$;T1~5IHLa%AwA!HjV-^5HQ78&Up(qrEqEJLA zV&MQ(s!COM}fl!xo-eub&Ti?;^?=>&sx9@Pk{jG7Hnk8`7&3pg=002ovPDHLk FV1nCmjZ**s delta 302 zcmbQp+`~M{^HUL{E)+HcuDFkcwMxZ#nWc83?cjWbOGs^|hOjxYGjT6s>*R zL#-W_pU968W7yHX?R(<;z3tpvwnaXE_=}l=fupNwQQPGL28IV0C3%-WG?~-J%id;x;y%$?6Pv2NbwX@{3RYBv9SlCYU$j?5X5Zd4(YgQ6oPJ)@l{Y_aZhiO{ z_g{Nu875p!F^%*Mn+&3OQFysQac7tu0z^buT^$3#6pO2gOv4ndrCuw8R)MK`w+){^ zyEBLRL4T{{=de?DcdSlaJW~0kp`GovRmbLP3*92g>j&M<`@FWhdP#pOH*4{Fwr9z0 n_wz44m&+dZt@tX-w`0F}B;y|Dskz^58Gyjk)z4*}Q$iB}Zft~R diff --git a/src/menu.c b/src/menu.c index b15024e..17d34cc 100644 --- a/src/menu.c +++ b/src/menu.c @@ -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();