tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit ef8efbb66c24fc07fbb3e71acfb8f209b6de1f9c
parent 758737b73ce2b9892aa0671ef2fc8ddbeb80d6b5
Author: Connor Thomson <connor@gnufault.org>
Date:   Sun, 18 Oct 2026 20:25:02 -0700

Add N64 joypad support and make the selected menu item pulse yellow

Diffstat:
Minclude/ta_button.h | 1+
Mplatforms/n64/n64.c | 38++++++++++++++++++++++++++++++++++++++
Msrc/ta_button.c | 21++++++++++++++-------
3 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/include/ta_button.h b/include/ta_button.h @@ -16,6 +16,7 @@ typedef struct { ta_size selected; ta_size animation_from; ta_uint32 animation_frame; + ta_uint32 pulse_frame; ta_bool animation_active; ta_bool up_was_down; ta_bool down_was_down; diff --git a/platforms/n64/n64.c b/platforms/n64/n64.c @@ -1,5 +1,6 @@ #include "ta_api.h" #include <display.h> +#include <joypad.h> #include <surface.h> #include <stdlib.h> #include <stdint.h> @@ -8,8 +9,43 @@ #define SCREEN_HEIGHT 240 #define WINDOW_BPP 32 +static void update_controller_input(void) { + joypad_buttons_t buttons = joypad_get_buttons(JOYPAD_PORT_1); + + if (buttons.d_up) { + ta_keyboard_key_down(KEY_UP); + } else { + ta_keyboard_key_up(KEY_UP); + } + + if (buttons.d_down) { + ta_keyboard_key_down(KEY_DOWN); + } else { + ta_keyboard_key_up(KEY_DOWN); + } + + if (buttons.d_left) { + ta_keyboard_key_down(KEY_LEFT); + } else { + ta_keyboard_key_up(KEY_LEFT); + } + + if (buttons.d_right) { + ta_keyboard_key_down(KEY_RIGHT); + } else { + ta_keyboard_key_up(KEY_RIGHT); + } + + if (buttons.a || buttons.start) { + ta_keyboard_key_down(KEY_ENTER); + } else { + ta_keyboard_key_up(KEY_ENTER); + } +} + int main(void) { display_init(RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE); + joypad_init(); ta_fb.width = SCREEN_WIDTH; ta_fb.height = SCREEN_HEIGHT; @@ -19,6 +55,8 @@ int main(void) { while (1) { surface_t *display = display_get(); + joypad_poll(); + update_controller_input(); ta_main_update(); const ta_uint32 *source = (const ta_uint32 *)ta_fb.buffers[0]; diff --git a/src/ta_button.c b/src/ta_button.c @@ -7,6 +7,8 @@ #define TA_BUTTON_SPACING 48 #define TA_BUTTON_COLOR_IDLE 118 #define TA_BUTTON_COLOR_SELECTED 255 +#define TA_BUTTON_COLOR_PULSE_BLUE_MIN 96 +#define TA_BUTTON_PULSE_HALF_FRAMES 24 void ta_button_lists_init(ta_button_lists *list) { if (list == 0) { @@ -18,6 +20,7 @@ void ta_button_lists_init(ta_button_lists *list) { list->selected = 0; list->animation_from = 0; list->animation_frame = 0; + list->pulse_frame = 0; list->animation_active = ta_false; list->up_was_down = ta_false; list->down_was_down = ta_false; @@ -52,12 +55,12 @@ ta_bool ta_button_lists_add(ta_button_lists *list, const char *label, ta_button_ } ta_bool ta_button_lists_update(ta_button_lists *list) { - ta_bool moved = ta_false; - if (list == 0 || list->size == 0) { return ta_false; } + list->pulse_frame = (list->pulse_frame + 1) % (TA_BUTTON_PULSE_HALF_FRAMES * 2); + ta_bool up_down = ta_keyboard_is_down(KEY_UP); ta_bool down_down = ta_keyboard_is_down(KEY_DOWN); ta_bool enter_down = ta_keyboard_is_down(KEY_ENTER); @@ -95,7 +98,6 @@ ta_bool ta_button_lists_update(ta_button_lists *list) { if (list->selected != list->animation_from) { list->animation_frame = 0; list->animation_active = ta_true; - moved = ta_true; } } @@ -103,7 +105,7 @@ ta_bool ta_button_lists_update(ta_button_lists *list) { list->buttons[list->selected].callback(); } - return moved; + return ta_true; } void ta_button_lists_draw(const ta_button_lists *list) { @@ -152,10 +154,15 @@ void ta_button_lists_draw(const ta_button_lists *list) { selection += progress; } - ta_uint8 color = (ta_uint8)(TA_BUTTON_COLOR_IDLE + (TA_BUTTON_COLOR_SELECTED - TA_BUTTON_COLOR_IDLE) * selection + 0.5); - ta_uint32 x = (ta_uint32)(ta_fb.width - text_width) / 2; + ta_uint32 pulse_position = list->pulse_frame; + ta_uint32 pulse_distance = pulse_position <= TA_BUTTON_PULSE_HALF_FRAMES ? pulse_position : TA_BUTTON_PULSE_HALF_FRAMES * 2 - pulse_position; + ta_uint8 pulse_blue = (ta_uint8)(TA_BUTTON_COLOR_SELECTED - ((TA_BUTTON_COLOR_SELECTED - TA_BUTTON_COLOR_PULSE_BLUE_MIN) * pulse_distance / TA_BUTTON_PULSE_HALF_FRAMES)); + ta_uint8 red = (ta_uint8)(TA_BUTTON_COLOR_IDLE + (TA_BUTTON_COLOR_SELECTED - TA_BUTTON_COLOR_IDLE) * selection + 0.5); + ta_uint8 green = red; + ta_uint8 blue = (ta_uint8)(TA_BUTTON_COLOR_IDLE + (pulse_blue - TA_BUTTON_COLOR_IDLE) * selection + 0.5); + ta_uint32 x = (ta_uint32)(ta_fb.width - text_width) / 2; - ta_text_draw_outline(list->buttons[i].label, x, (ta_uint32)y, text_width, text_height, color, color, color, 1, 0, 0, 0); + ta_text_draw_outline(list->buttons[i].label, x, (ta_uint32)y, text_width, text_height, red, green, blue, 1, 0, 0, 0); } }