}
}
+static void enable_tap_control(endless_runner_state_t *state) {
+ if (!state->tap_control_on) {
+ movement_enable_tap_detection_if_available();
+ state->tap_control_on = true;
+ }
+}
+
+static void disable_tap_control(endless_runner_state_t *state) {
+ if (state->tap_control_on) {
+ movement_disable_tap_detection_if_available();
+ state->tap_control_on = false;
+ }
+}
+
static void display_title(endless_runner_state_t *state) {
uint16_t hi_score = state -> hi_score;
uint8_t difficulty = state -> difficulty;
watch_display_text(WATCH_POSITION_BOTTOM, buf);
}
display_difficulty(difficulty);
+ if (state -> soundOn) watch_set_indicator(WATCH_INDICATOR_BELL);
}
static void display_time(watch_date_time_t date_time, bool clock_mode_24h) {
endless_runner_state_t *state = (endless_runner_state_t *)context;
switch (event.event_type) {
case EVENT_ACTIVATE:
+ disable_tap_control(state);
check_and_reset_hi_score(state);
- if (state -> soundOn) watch_set_indicator(WATCH_INDICATOR_BELL);
display_title(state);
break;
case EVENT_TICK:
break;
case EVENT_LIGHT_BUTTON_UP:
case EVENT_ALARM_BUTTON_UP:
- if (game_state.curr_screen == SCREEN_TITLE)
+ if (game_state.curr_screen == SCREEN_TITLE) {
+ enable_tap_control(state);
begin_playing(state);
- else if (game_state.curr_screen == SCREEN_LOSE)
+ }
+ else if (game_state.curr_screen == SCREEN_LOSE) {
display_title(state);
+ }
break;
case EVENT_LIGHT_LONG_PRESS:
if (game_state.curr_screen == SCREEN_TITLE)
}
break;
case EVENT_ALARM_LONG_PRESS:
- if (game_state.curr_screen != SCREEN_PLAYING)
+ if (game_state.curr_screen == SCREEN_TITLE)
toggle_sound(state);
break;
case EVENT_TIMEOUT:
+ disable_tap_control(state);
if (game_state.curr_screen != SCREEN_TITLE)
display_title(state);
break;
}
void endless_runner_face_resign(void *context) {
- (void) context;
- movement_disable_tap_detection_if_available();
+ endless_runner_state_t *state = (endless_runner_state_t *)context;
+ disable_tap_control(state);
}
This is a basic endless-runner, like the [Chrome Dino game](https://en.wikipedia.org/wiki/Dinosaur_Game).
On the title screen, you can select a difficulty by long-pressing LIGHT or toggle sound by long-pressing ALARM.
LED or ALARM are used to jump.
+ If the accelerometer is installed, you can tap the screen to jump and move through the menus after using the
+ buttons to go into the first game.
High-score is displayed on the top-right on the title screen. During a game, the current score is displayed.
*/
uint8_t month_last_hi_score : 4;
uint8_t year_last_hi_score : 6;
uint8_t soundOn : 1;
- /* 24 bits, likely aligned to 32 bits = 4 bytes */
+ uint8_t tap_control_on : 1;
+ uint8_t unused : 7;
} endless_runner_state_t;
void endless_runner_face_setup(uint8_t watch_face_index, void ** context_ptr);