static int score_buttn(int b, int d) { if (d) { #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) #endif //GCWZERO { if (hole_move()) goto_state(&st_next); else //senquack - bugfix in original code: //original code had this, I think it is a bug, it should go back to the title like the mouse button does // but instead it 'freezes' on scores screen // goto_state(&st_score); goto_state(&st_title); } #ifndef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); #endif //GCWZERO } return 1; }
static int next_buttn(int b, int d) { if (d) { //senquack - on GCW Zero, you can press any A/X/Y/B to proceed (makes more sense) #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) #endif //GCWZERO { if (num > 0) { if (hole_goto(num, -1)) { num = 0; return goto_state(&st_next); } else { num = 0; return 1; } } return goto_state(&st_flyby); } //senquack - It really makes no sense to pause when asking to go the next hole, disabling that on GCW Zero: #ifndef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); #endif //GCWZERO } return 1; }
static int stop_buttn(int b, int d) { if (d) { //On GCW Zero, ABXY will all proceed, none of this silly pause-with-B thing: #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) #endif //GCWZERO { if (hole_next()) goto_state(&st_next); else goto_state(&st_score); } #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) #endif //GCWZERO return goto_pause(&st_over); } return 1; }
static int fall_buttn(int b, int d) { if (d) { //senquack - on GCW Zero, ABXY all proceed, no silly pause-with-B business: #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) #endif //GCWZERO { if (hole_next()) goto_state(&st_next); else goto_state(&st_score); } //senquack - On GCW Zero, Button B should do nothing, it's annoying and confusing otherwise #ifndef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); #endif //GCWZERO } return 1; }
static int roll_buttn(int b, int d) { if (d) { //senquack - On GCW Zero, Button B should do nothing, it's annoying and confusing otherwise #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) return goto_pause(&st_over); #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) return goto_pause(&st_over); #endif //GCWZERO } return 1; }
static int roll_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b)) return goto_pause(&st_over, 1); } return 1; }
static int shared_keybd(int c, int d) { if (d) { if (config_tst_d(CONFIG_KEY_PAUSE, c)) return goto_pause(&st_over, 0); } return 1; }
static int shared_keybd(int c, int d) { if (d) { if (c == KEY_EXIT) return goto_pause(&st_over); } return 1; }
static int stroke_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) return goto_state(&st_roll); if (config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) return goto_pause(&st_over); } return 1; }
static int next_keybd(int c, int d) { if (d) { if (c == SDLK_F12) return goto_state(&st_poser); if (config_tst_d(CONFIG_KEY_PAUSE, c)) return goto_pause(&st_over, 0); if ('0' <= c && c <= '9') num = num * 10 + c - '0'; } return 1; }
static int next_keybd(int c, int d) { if (d) { if (c == KEY_POSE) return goto_state(&st_poser); if (c == KEY_EXIT) return goto_pause(&st_over); if ('0' <= c && c <= '9') num = num * 10 + c - '0'; } return 1; }
static int flyby_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) { game_set_fly(0.f); return goto_state(&st_stroke); } if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b)) return goto_pause(&st_over, 1); } return 1; }
static int fall_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) { if (hole_next()) goto_state(&st_next); else goto_state(&st_score); } if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); } return 1; }
static int score_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) { if (hole_move()) goto_state(&st_next); else goto_state(&st_score); } if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b)) return goto_pause(&st_over, 1); } return 1; }
static int stroke_buttn(int b, int d) { if (d) { //senquack - made it so you could press A or B button to shoot: #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_state(&st_roll); #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) return goto_state(&st_roll); #endif //GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_START, b)) return goto_pause(&st_over); } return 1; }
static int next_buttn(int b, int d) { if (d) { if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) { if (num > 0 && hole_goto(num, -1)) { num = 0; return goto_state(&st_next); } return goto_state(&st_flyby); } if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); } return 1; }
static int goal_buttn(int b, int d) { if (d) { //senquack - on GCW Zero, A,B,X,Y will all proceed, instead of this silly pausing-with-B thing: #ifdef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b)) #else if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b)) #endif //GCWZERO { if (hole_next()) goto_state(&st_next); else goto_state(&st_score); } #ifndef GCWZERO if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b)) return goto_pause(&st_over); #endif //GCWZERO } return 1; }
static int loop(void) { SDL_Event e; int d = 1; int c; while (d && SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) return 0; switch (e.type) { case SDL_MOUSEMOTION: st_point(+e.motion.x, -e.motion.y + config_get_d(CONFIG_HEIGHT), +e.motion.xrel, -e.motion.yrel); break; case SDL_MOUSEBUTTONDOWN: d = st_click(e.button.button, 1); break; case SDL_MOUSEBUTTONUP: d = st_click(e.button.button, 0); break; case SDL_KEYDOWN: c = e.key.keysym.sym; #ifdef __APPLE__ if (c == SDLK_q && e.key.keysym.mod & KMOD_GUI) { d = 0; break; } #endif #ifdef _WIN32 if (c == SDLK_F4 && e.key.keysym.mod & KMOD_ALT) { d = 0; break; } #endif switch (c) { case KEY_SCREENSHOT: shot(); break; case KEY_FPS: config_tgl_d(CONFIG_FPS); break; case KEY_WIREFRAME: toggle_wire(); break; case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); break; case SDLK_ESCAPE: if (video_get_grab()) d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_START), 1); else d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_B), 1); break; default: if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), -1.0f); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), +1.0f); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), -1.0f); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), +1.0f); else d = st_keybd(e.key.keysym.sym, 1); } break; case SDL_KEYUP: c = e.key.keysym.sym; switch (c) { case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0); break; case SDLK_ESCAPE: if (video_get_grab()) d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_START), 0); else d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_B), 0); break; default: if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), 0.0f); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), 0.0f); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), 0.0f); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), 0.0f); else d = st_keybd(e.key.keysym.sym, 0); } break; case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: if (video_get_grab()) goto_pause(&st_over); break; case SDL_WINDOWEVENT_MOVED: if (config_get_d(CONFIG_DISPLAY) != video_display()) config_set_d(CONFIG_DISPLAY, video_display()); break; } break; case SDL_JOYAXISMOTION: st_stick(e.jaxis.axis, JOY_VALUE(e.jaxis.value)); break; case SDL_JOYBUTTONDOWN: d = st_buttn(e.jbutton.button, 1); break; case SDL_JOYBUTTONUP: d = st_buttn(e.jbutton.button, 0); break; } } return d; }
static int loop(void) { SDL_Event e; int d = 1; int c; /* Process SDL events. */ while (d && SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: return 0; case SDL_MOUSEMOTION: st_point(+e.motion.x, -e.motion.y + config_get_d(CONFIG_HEIGHT), +e.motion.xrel, config_get_d(CONFIG_MOUSE_INVERT) ? +e.motion.yrel : -e.motion.yrel); break; case SDL_MOUSEBUTTONDOWN: d = st_click(e.button.button, 1); break; case SDL_MOUSEBUTTONUP: d = st_click(e.button.button, 0); break; case SDL_KEYDOWN: c = e.key.keysym.sym; if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX); else switch (c) { case SDLK_F10: shot(); break; case SDLK_F9: config_tgl_d(CONFIG_FPS); break; case SDLK_F8: config_tgl_d(CONFIG_NICE); break; case SDLK_F7: if (config_cheat()) toggle_wire(); break; case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); break; case SDLK_ESCAPE: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1); break; default: if (SDL_EnableUNICODE(-1)) d = st_keybd(e.key.keysym.unicode, 1); else d = st_keybd(e.key.keysym.sym, 1); } break; case SDL_KEYUP: c = e.key.keysym.sym; if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); else switch (c) { case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0); break; case SDLK_ESCAPE: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0); break; default: d = st_keybd(e.key.keysym.sym, 0); } case SDL_ACTIVEEVENT: if (e.active.state == SDL_APPINPUTFOCUS) if (e.active.gain == 0 && video_get_grab()) goto_pause(); break; case SDL_JOYAXISMOTION: st_stick(e.jaxis.axis, e.jaxis.value); break; case SDL_JOYBUTTONDOWN: d = st_buttn(e.jbutton.button, 1); break; case SDL_JOYBUTTONUP: d = st_buttn(e.jbutton.button, 0); break; } } /* Process events via the tilt sensor API. */ if (tilt_stat()) { int b; int s; st_angle((int) tilt_get_x(), (int) tilt_get_z()); while (tilt_get_button(&b, &s)) { const int X = config_get_d(CONFIG_JOYSTICK_AXIS_X); const int Y = config_get_d(CONFIG_JOYSTICK_AXIS_Y); const int L = config_get_d(CONFIG_JOYSTICK_DPAD_L); const int R = config_get_d(CONFIG_JOYSTICK_DPAD_R); const int U = config_get_d(CONFIG_JOYSTICK_DPAD_U); const int D = config_get_d(CONFIG_JOYSTICK_DPAD_D); if (b == L || b == R || b == U || b == D) { static int pad[4] = { 0, 0, 0, 0 }; /* Track the state of the D-pad buttons. */ if (b == L) pad[0] = s; else if (b == R) pad[1] = s; else if (b == U) pad[2] = s; else if (b == D) pad[3] = s; /* Convert D-pad button events into joystick axis motion. */ if (pad[0] && !pad[1]) st_stick(X, -JOY_MAX); else if (pad[1] && !pad[0]) st_stick(X, +JOY_MAX); else st_stick(X, 1); if (pad[2] && !pad[3]) st_stick(Y, -JOY_MAX); else if (pad[3] && !pad[2]) st_stick(Y, +JOY_MAX); else st_stick(Y, 1); } else d = st_buttn(b, s); } } return d; }
static int loop(void) { SDL_Event e; int d = 1; int c; int ax, ay, dx, dy; while (d && SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) return 0; switch (e.type) { case SDL_MOUSEMOTION: /* Convert to OpenGL coordinates. */ ax = +e.motion.x; ay = -e.motion.y + video.window_h; dx = +e.motion.xrel; dy = -e.motion.yrel; /* Convert to pixels. */ ax = ROUND(ax * video.device_scale); ay = ROUND(ay * video.device_scale); dx = ROUND(dx * video.device_scale); dy = ROUND(dy * video.device_scale); st_point(ax, ay, dx, dy); break; case SDL_MOUSEBUTTONDOWN: d = st_click(e.button.button, 1); break; case SDL_MOUSEBUTTONUP: d = st_click(e.button.button, 0); break; case SDL_FINGERMOTION: case SDL_FINGERDOWN: case SDL_FINGERUP: /* Convert to OpenGL coordinates. */ if (video.device_orientation & VIDEO_ORIENTATION_ROTATE) { ax = e.tfinger.y * video.window_w; ay = e.tfinger.x * video.window_h; dx = e.tfinger.dy * video.window_w; dy = e.tfinger.dx * video.window_h; if (video.device_orientation & VIDEO_ORIENTATION_MIRROR) { ax = video.window_w - ax; ay = video.window_h - ay; dx *= -1; dy *= -1; } } else { ax = e.tfinger.x * video.window_w; ay = e.tfinger.y * video.window_h; dx = e.tfinger.dx * video.window_w; dy = e.tfinger.dy * video.window_h; if (video.device_orientation & VIDEO_ORIENTATION_MIRROR) { ax = video.window_w - ax; dx *= -1; } else { ay = video.window_h - ay; dy *= -1; } } /* Convert to pixels. */ ax = ROUND(ax * video.device_scale); ay = ROUND(ay * video.device_scale); dx = ROUND(dx * video.device_scale); dy = ROUND(dy * video.device_scale); st_point(ax, ay, dx, dy); if (e.type == SDL_FINGERDOWN) { d = st_click(SDL_BUTTON_LEFT, 1); } else if (e.type == SDL_FINGERUP) { d = st_click(SDL_BUTTON_LEFT, 0); st_point(0, 0, 0, 0); } break; case SDL_KEYDOWN: c = e.key.keysym.sym; #ifdef __APPLE__ if (c == SDLK_q && e.key.keysym.mod & KMOD_GUI) { d = 0; break; } #endif #ifdef _WIN32 if (c == SDLK_F4 && e.key.keysym.mod & KMOD_ALT) { d = 0; break; } #endif switch (c) { case KEY_SCREENSHOT: shot(); break; case KEY_FPS: config_tgl_d(CONFIG_FPS); break; case KEY_WIREFRAME: toggle_wire(); break; case SDLK_RETURN: case SDLK_KP_ENTER: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); break; case SDLK_ESCAPE: if (video_get_grab()) d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_START), 1); else d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_B), 1); break; default: if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), -1.0f); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), +1.0f); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), -1.0f); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), +1.0f); else d = st_keybd(e.key.keysym.sym, 1); } break; case SDL_KEYUP: c = e.key.keysym.sym; switch (c) { case SDLK_RETURN: case SDLK_KP_ENTER: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0); break; case SDLK_ESCAPE: if (video_get_grab()) d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_START), 0); else d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_B), 0); break; default: if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), 0.0f); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), 0.0f); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), 0.0f); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), 0.0f); else d = st_keybd(e.key.keysym.sym, 0); } break; case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: if (video_get_grab()) goto_pause(&st_over); break; case SDL_WINDOWEVENT_MOVED: if (config_get_d(CONFIG_DISPLAY) != video_display()) config_set_d(CONFIG_DISPLAY, video_display()); break; } break; case SDL_JOYAXISMOTION: st_stick(e.jaxis.axis, JOY_VALUE(e.jaxis.value)); break; case SDL_JOYBUTTONDOWN: d = st_buttn(e.jbutton.button, 1); break; case SDL_JOYBUTTONUP: d = st_buttn(e.jbutton.button, 0); break; } } return d; }