/*---------------------------------------------------------------------------*/
+static SDL_Joystick *joystick = NULL;
+
+void set_joystick(SDL_Joystick *j)
+{
+ joystick = j;
+}
+
+/*---------------------------------------------------------------------------*/
+
static char *number(int i)
{
static char str[MAXSTR];
/*---------------------------------------------------------------------------*/
+static int shared_stick_basic(int id, int a, int v)
+{
+ int jd = 0;
+
+ if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
+ jd = gui_stick(id, v, 0);
+ else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
+ jd = gui_stick(id, 0, v);
+
+ if (jd)
+ gui_pulse(jd, 1.2f);
+
+ return jd;
+}
+
+static void shared_stick(int id, int a, int v)
+{
+ shared_stick_basic(id, a, v);
+}
+
+/*---------------------------------------------------------------------------*/
+
#define TITLE_PLAY 1
#define TITLE_CONF 2
#define TITLE_EXIT 3
gui_delete(id);
}
-static void title_paint(int id, float st)
+static void title_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
}
game_set_fly(fcosf(time_state() / 10.f));
gui_timer(id, dt);
- audio_timer(dt);
}
static void title_point(int id, int x, int y, int dx, int dy)
return (d && b < 0) ? title_action(gui_token(gui_click())) : 1;
}
-static int title_keybd(int c, int d)
+static int title_buttn(int b, int d)
{
- return (d && c == SDLK_ESCAPE) ? 0 : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return title_action(gui_token(gui_click()));
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return title_action(TITLE_EXIT);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
static int desc_id;
static int shot_id;
+#define COURSE_BACK -1
+
static int course_action(int i)
{
if (course_exists(i))
course_goto(i);
goto_state(&st_party);
}
- if (i < 0)
+ if (i == COURSE_BACK)
goto_state(&st_title);
return 1;
int w = config_get_d(CONFIG_WIDTH);
int h = config_get_d(CONFIG_HEIGHT);
- int id, jd, kd, ld, i = 0, j, n = course_count();
+ int id, jd, kd, ld, md, i = 0, j, n = course_count();
int m = (int)(sqrt(n/2.0)*2);
if ((id = gui_vstack(0)))
if ((jd = gui_hstack(id)))
{
shot_id = gui_image(jd, course_shot(0), w / 3, h / 3);
+
gui_filler(jd);
+
if ((kd = gui_varray(jd)))
{
for(i = 0; i < n; i += m)
for (j = (m - 1); j >= 0; j--)
{
if (i + j < n)
- gui_active(gui_image(ld, course_shot(i + j),
- w / 3 / m, h / 3 / m),
- i + j, 0);
+ {
+ md = gui_image(ld, course_shot(i + j),
+ w / 3 / m, h / 3 / m);
+ gui_active(md, i + j, 0);
+
+ if (i + j == 0)
+ gui_focus(md);
+ }
else
gui_space(ld);
}
if ((jd = gui_hstack(id)))
{
gui_filler(jd);
- gui_state(jd, _("Back"), GUI_SML, -1, 0);
+ gui_state(jd, _("Back"), GUI_SML, COURSE_BACK, 0);
}
gui_layout(id, 0, 0);
gui_delete(id);
}
-static void course_paint(int id, float st)
+static void course_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
}
static void course_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static void course_point(int id, int x, int y, int dx, int dy)
if ((jd = gui_point(id, x, y)))
{
int i = gui_token(jd);
+
+ if (course_exists(i))
+ {
+ gui_set_image(shot_id, course_shot(i));
+ gui_set_multi(desc_id, _(course_desc(i)));
+ }
+ gui_pulse(jd, 1.2f);
+ }
+}
+
+static void course_stick(int id, int a, int v)
+{
+ int jd;
+
+ if ((jd = shared_stick_basic(id, a, v)))
+ {
+ int i = gui_token(jd);
+
if (course_exists(i))
{
gui_set_image(shot_id, course_shot(i));
return (d && b < 0) ? course_action(gui_token(gui_click())) : 1;
}
-static int course_keybd(int c, int d)
+static int course_buttn(int b, int d)
{
- return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return course_action(gui_token(gui_click()));
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return course_action(COURSE_BACK);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
gui_set_color(p2, gui_grn, gui_wht);
gui_set_color(p3, gui_blu, gui_wht);
gui_set_color(p4, gui_yel, gui_wht);
+
+ gui_focus(p1);
}
gui_space(id);
gui_delete(id);
}
-static void party_paint(int id, float st)
+static void party_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
}
static void party_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static void party_point(int id, int x, int y, int dx, int dy)
return (d && b < 0) ? party_action(gui_token(gui_click())) : 1;
}
-static int party_keybd(int c, int d)
+static int party_buttn(int b, int d)
{
- return (d && c == SDLK_ESCAPE) ? goto_state(&st_course) : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return party_action(gui_token(gui_click()));
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return party_action(PARTY_B);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
static int paused = 0;
static struct state *st_continue;
+static struct state *st_quit;
#define PAUSE_CONTINUE 1
#define PAUSE_QUIT 2
-int goto_pause(void)
+int goto_pause(struct state *s, int e)
{
+ if (curr_state() == &st_pause)
+ return 1;
+
+ if (e && !config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
+ return goto_state(s);
+
st_continue = curr_state();
+ st_quit = s;
paused = 1;
+
return goto_state(&st_pause);
}
return goto_state(st_continue ? st_continue : &st_title);
case PAUSE_QUIT:
- return goto_state(&st_over);
+ return goto_state(st_quit);
}
return 1;
}
audio_music_fade_in(0.5f);
}
-static void pause_paint(int id, float st)
+static void pause_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
hud_paint();
}
static void pause_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static void pause_point(int id, int x, int y, int dx, int dy)
static int pause_keybd(int c, int d)
{
- if (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c)))
+ if (d && config_tst_d(CONFIG_KEY_PAUSE, c))
return pause_action(PAUSE_CONTINUE);
return 1;
}
+static int pause_buttn(int b, int d)
+{
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return pause_action(gui_token(gui_click()));
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return pause_action(PAUSE_CONTINUE);
+ }
+ 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 num = 0;
gui_delete(id);
}
-static void next_paint(int id, float st)
+static void next_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
hud_paint();
gui_paint(id);
}
static void next_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static void next_point(int id, int x, int y, int dx, int dy)
{
if (c == SDLK_F12)
return goto_state(&st_poser);
- if (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))
- return goto_pause();
- if (c == SDLK_RETURN)
- {
- hole_goto(num, -1);
- num = 0;
- return goto_state(&st_next);
- }
+ 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_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_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
+}
+
/*---------------------------------------------------------------------------*/
static int poser_enter(void)
return 0;
}
-static void poser_paint(int id, float st)
+static void poser_paint(int id, float t)
{
- game_draw(1);
+ game_draw(1, t);
}
-static int poser_keybd(int c, int d)
+static int poser_buttn(int b, int d)
{
- return (d && c == SDLK_ESCAPE) ? goto_state(&st_next) : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return goto_state(&st_next);
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return goto_state(&st_next);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
hud_free();
}
-static void flyby_paint(int id, float st)
+static void flyby_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
hud_paint();
}
game_set_fly(1.f - t);
gui_timer(id, dt);
- audio_timer(dt);
}
static int flyby_click(int b, int d)
return 1;
}
-static int flyby_keybd(int c, int d)
+static int flyby_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ 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 stroke_rotate = 0;
+static int stroke_mag = 0;
+
static int stroke_enter(void)
{
hud_init();
config_set_d(CONFIG_CAMERA, 0);
}
-static void stroke_paint(int id, float st)
+static void stroke_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
hud_paint();
}
{
float g[3] = { 0.f, 0.f, 0.f };
+ float k;
+
+ if (SDL_GetModState() & KMOD_SHIFT ||
+ (joystick && SDL_JoystickGetButton(joystick,
+ config_get_d(CONFIG_JOYSTICK_BUTTON_B))))
+ k = 0.25;
+ else
+ k = 1.0;
+
+ game_set_rot(stroke_rotate * k);
+ game_set_mag(stroke_mag * k);
+
game_update_view(dt);
game_step(g, dt);
- audio_timer(dt);
}
static void stroke_point(int id, int x, int y, int dx, int dy)
game_set_mag(dy);
}
+static void stroke_stick(int id, int a, int v)
+{
+ if (v == 1) /* See 'loop' in main.c */
+ v = 0;
+
+ if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
+ stroke_rotate = (6 * v) / JOY_MAX;
+ else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
+ stroke_mag = -((6 * v) / JOY_MAX);
+}
+
static int stroke_click(int b, int d)
{
return (d && b < 0) ? goto_state(&st_roll) : 1;
}
-static int stroke_keybd(int c, int d)
+static int stroke_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return goto_state(&st_roll);
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
hud_free();
}
-static void roll_paint(int id, float st)
+static void roll_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
hud_paint();
}
case GAME_GOAL: goto_state(&st_goal); break;
case GAME_FALL: goto_state(&st_fall); break;
}
- audio_timer(dt);
}
-static int roll_keybd(int c, int d)
+static int roll_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
hud_free();
}
-static void goal_paint(int id, float st)
+static void goal_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
hud_paint();
}
else
goto_state(&st_score);
}
- audio_timer(dt);
}
static int goal_click(int b, int d)
return 1;
}
-static int goal_keybd(int c, int d)
+static int goal_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ 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_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
hud_free();
}
-static void stop_paint(int id, float st)
+static void stop_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
hud_paint();
}
game_update_view(dt);
game_step(g, dt);
- audio_timer(dt);
if (time_state() > 1)
{
return 1;
}
-static int stop_keybd(int c, int d)
+static int stop_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ 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_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
else
{
hole_fall();
- game_draw(0); /*TODO: is this call ok? */
+/* game_draw(0);*/ /*TODO: is this call ok? */ /* No, it's not. */
}
hud_init();
hud_free();
}
-static void fall_paint(int id, float st)
+static void fall_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
hud_paint();
}
else
goto_state(&st_score);
}
- audio_timer(dt);
}
static int fall_click(int b, int d)
return 1;
}
-static int fall_keybd(int c, int d)
+static int fall_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ 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_EXIT, b))
+ return goto_pause(&st_over, 1);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
gui_delete(id);
}
-static void score_paint(int id, float st)
+static void score_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
}
static void score_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static int score_click(int b, int d)
return 1;
}
-static int score_keybd(int c, int d)
+static int score_buttn(int b, int d)
{
- return (d && (c == SDLK_ESCAPE || config_tst_d(CONFIG_KEY_PAUSE, c))) ? goto_pause() : 1;
+ 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;
}
/*---------------------------------------------------------------------------*/
gui_delete(id);
}
-static void over_paint(int id, float st)
+static void over_paint(int id, float t)
{
- game_draw(0);
+ game_draw(0, t);
gui_paint(id);
}
static void over_timer(int id, float dt)
{
gui_timer(id, dt);
- audio_timer(dt);
}
static int over_click(int b, int d)
return (d && b < 0) ? goto_state(&st_title) : 1;
}
-static int over_keybd(int c, int d)
+static int over_buttn(int b, int d)
{
- return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
+ if (d)
+ {
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
+ return goto_state(&st_title);
+ if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
+ return goto_state(&st_title);
+ }
+ return 1;
}
/*---------------------------------------------------------------------------*/
title_paint,
title_timer,
title_point,
+ shared_stick,
NULL,
title_click,
- title_keybd,
NULL,
+ title_buttn,
1, 0
};
course_paint,
course_timer,
course_point,
+ course_stick,
NULL,
course_click,
- course_keybd,
NULL,
+ course_buttn,
1, 0
};
party_paint,
party_timer,
party_point,
+ shared_stick,
NULL,
party_click,
- party_keybd,
NULL,
+ party_buttn,
1, 0
};
next_paint,
next_timer,
next_point,
+ shared_stick,
NULL,
next_click,
next_keybd,
- NULL,
+ next_buttn,
1, 0
};
NULL,
NULL,
NULL,
- poser_keybd,
NULL,
+ NULL,
+ poser_buttn,
1, 0
};
flyby_timer,
NULL,
NULL,
- flyby_click,
- flyby_keybd,
NULL,
+ flyby_click,
+ shared_keybd,
+ flyby_buttn,
1, 0
};
stroke_paint,
stroke_timer,
stroke_point,
+ stroke_stick,
NULL,
stroke_click,
- stroke_keybd,
- NULL,
+ shared_keybd,
+ stroke_buttn,
0, 0
};
NULL,
NULL,
NULL,
- roll_keybd,
NULL,
+ shared_keybd,
+ roll_buttn,
0, 0
};
goal_timer,
NULL,
NULL,
- goal_click,
- goal_keybd,
NULL,
+ goal_click,
+ shared_keybd,
+ goal_buttn,
0, 0
};
stop_timer,
NULL,
NULL,
- stop_click,
- stop_keybd,
NULL,
+ stop_click,
+ shared_keybd,
+ stop_buttn,
0, 0
};
fall_timer,
NULL,
NULL,
- fall_click,
- fall_keybd,
NULL,
+ fall_click,
+ shared_keybd,
+ fall_buttn,
0, 0
};
score_timer,
NULL,
NULL,
- score_click,
- score_keybd,
NULL,
+ score_click,
+ shared_keybd,
+ score_buttn,
0, 0
};
over_timer,
NULL,
NULL,
+ NULL,
over_click,
- over_keybd,
NULL,
+ over_buttn,
1, 0
};
pause_paint,
pause_timer,
pause_point,
+ shared_stick,
NULL,
pause_click,
pause_keybd,
- NULL,
+ pause_buttn,
1, 0
};