diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-11 21:04:54 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-11 21:04:54 +0100 |
commit | 43503cfa510a7f7e650efccaac266d7cc6657a5d (patch) | |
tree | f0fc2a9b480f413f8f0bab25bd97170b17a794b8 /src | |
parent | cd2296358a03ab9ca4d6c017262735eaa63b5fdb (diff) | |
download | gold-mine-run-1.2.tar.gz gold-mine-run-1.2.zip |
Better koystick support1.2
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 9 | ||||
-rw-r--r-- | src/joy.c | 20 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/menu.c | 12 |
4 files changed, 32 insertions, 11 deletions
@@ -382,8 +382,15 @@ update_menu: goto update_menu; } - if (keys[KEY_ENTER]) + if (keys[KEY_ENTER] || (ctl & CTL_FIRE1)) + { + while (keys[KEY_ENTER] || (ctl & CTL_FIRE1)) + { + ctl = control_read(); + wait_vsync(); + } break; + } } wait_vsync(); @@ -66,6 +66,10 @@ uint8_t joy_detect() printf("Joystick detected!\n"); + uint16_t cx, cy; + printf("Please center the joystick and press BUTTON 1 (ESC to abort)\n"); + if (!calibrate(&cy, &cx)) + return 0; printf("Please move UP + LEFT and press BUTTON 1 (ESC to abort)\n"); if (!calibrate(&j_up, &j_left)) return 0; @@ -78,10 +82,10 @@ uint8_t joy_detect() j_up, j_down, j_left, j_right); #endif - j_up += j_up >> 4; - j_down -= j_down >> 4; - j_left += j_left >> 4; - j_right -= j_right >> 4; + j_up = cy - ((cy - j_up) / 2); + j_down = cy + ((j_down - cy) / 2); + j_left = cx - ((cx - j_left) / 2); + j_right = cx + ((j_right - cx) / 2); #ifdef DEBUG printf(" Adjusted: up=%04d, down=%04d, left=%04d, right=%04d\n", @@ -108,15 +112,15 @@ uint8_t joy_read() r |= CTL_FIRE2; v = read_axis(AXISY); - if (v <= j_up) + if (v < j_up) r |= CTL_UP; - if (v >= j_down) + if (v > j_down) r |= CTL_DOWN; v = read_axis(AXISX); - if (v <= j_left) + if (v < j_left) r |= CTL_LEFT; - if (v >= j_right) + if (v > j_right) r |= CTL_RIGHT; return r; @@ -14,7 +14,7 @@ #include "game.h" #define GAME_NAME "Gold Mine Run!" -#define GAME_VERSION "1.1 (2023-08-10)" +#define GAME_VERSION "1.2 (2023-08-11)" #define GAME_URL "https://www.usebox.net/jjm/gold-mine-run/" /* disable paging because our int handlers are written in C */ @@ -2,6 +2,7 @@ #include <stdio.h> #include "keyb.h" +#include "control.h" #include "vga.h" #include "sound.h" #include "text.h" @@ -77,15 +78,24 @@ uint8_t run_menu() uint16_t count = 0; uint8_t cast = 0; uint8_t wait; + uint8_t ctl; blit_target(TARGET_SCREEN); while (1) { + ctl = control_read(); + if (keys[KEY_ESC]) return 0; - if (keys[KEY_SPACE]) + if (keys[KEY_SPACE] || (ctl & CTL_FIRE1)) { + while (keys[KEY_SPACE] || (ctl & CTL_FIRE1)) + { + ctl = control_read(); + wait_vsync(); + } + sound_play_efx(EFX_ONEUP); for (uint8_t i = 0; i < 32; i++) |