From 1cd4b55add17fcde4cb501e123aea52d9e8b4ba6 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Sun, 1 Dec 2024 14:17:31 -0800 Subject: [PATCH] melee: reset cursor blinky on move --- src/game/scenes/melee.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/game/scenes/melee.c b/src/game/scenes/melee.c index e3c46f8c2..4d5ab08d7 100644 --- a/src/game/scenes/melee.c +++ b/src/game/scenes/melee.c @@ -85,6 +85,7 @@ typedef struct { surface select_hilight; unsigned int ticks; + unsigned int tickbase[2]; str vs_text; str wins_text_a; @@ -135,12 +136,20 @@ void melee_free(scene *scene) { scene_set_userdata(scene, local); } -static void set_cursor_colors(int offset, bool a_done, bool b_done) { +static int ticks_to_blinky(int ticks) { + float rate = ((float)ticks) / 25.0f; + int offset = roundf((cosf(rate) + 1.0f) * 64.0f); + return offset; +} + +static void set_cursor_colors(int a_ticks, int b_ticks, bool a_done, bool b_done) { int base = 120; + int a_offset = ticks_to_blinky(a_ticks); + int b_offset = ticks_to_blinky(b_ticks); - vga_color red_cursor_color = {base + (a_done ? 64 : offset), 0, 0}; - vga_color blue_cursor_color = {0, 0, base + (b_done ? 64 : offset)}; - vga_color violet_cursor_color = {base + offset, 0, base + offset}; + vga_color red_cursor_color = {base + (a_done ? 64 : a_offset), 0, 0}; + vga_color blue_cursor_color = {0, 0, base + (b_done ? 64 : b_offset)}; + vga_color violet_cursor_color = {base + a_offset, 0, base + a_offset}; vga_state_set_base_palette_index(RED_CURSOR_INDEX, &red_cursor_color); vga_state_set_base_palette_index(BLUE_CURSOR_INDEX, &blue_cursor_color); @@ -185,10 +194,9 @@ void melee_tick(scene *scene, int paused) { } // Tick cursor colors + set_cursor_colors(local->ticks - local->tickbase[0], local->ticks - local->tickbase[1], CURSOR_A_DONE(local), + CURSOR_B_DONE(local)); local->ticks++; - double rate = ((double)local->ticks) / 25.0; - int num = round((sin(rate) + 1.0) * 64); - set_cursor_colors(num, CURSOR_A_DONE(local), CURSOR_B_DONE(local)); } void refresh_pilot_stats(melee_local *local) { @@ -225,6 +233,15 @@ void update_har(scene *scene, int player) { } } +static void reset_cursor_blinky(melee_local *local, int player) { + if(CURSORS_MATCH(local) || player == 0) { + local->tickbase[0] = local->ticks; + } + if(CURSORS_MATCH(local) || player == 1) { + local->tickbase[1] = local->ticks; + } +} + void handle_action(scene *scene, int player, int action) { game_player *player1 = game_state_get_player(scene->gs, 0); game_player *player2 = game_state_get_player(scene->gs, 1); @@ -246,22 +263,26 @@ void handle_action(scene *scene, int player, int action) { if(*column < 0) { *column = 4; } + reset_cursor_blinky(local, player); break; case ACT_RIGHT: (*column)++; if(*column > 4) { *column = 0; } + reset_cursor_blinky(local, player); break; case ACT_UP: if(*row == 1) { *row = 0; } + reset_cursor_blinky(local, player); break; case ACT_DOWN: if(*row == 0) { *row = 1; } + reset_cursor_blinky(local, player); // nova selection cheat if(*row == 1 && *column == 0) { local->katana_down_count[player]++; @@ -793,7 +814,7 @@ int melee_create(scene *scene) { component_layout(local->bar_endurance[1], 320 - 66 - local->bg_player_stats.w, 48, 20 * 4, 8); refresh_pilot_stats(local); - set_cursor_colors(0, false, false); + set_cursor_colors(0, 0, false, false); // initialize nova selection cheat memset(local->har_selected, 0, sizeof(local->har_selected));