static bool check_pause_button(LandFloat mx, LandFloat my) { All * a = global_a; double rr = land_display_width() / 8 * 0.8; if (a->dpad == 2 || a->dpad == 3) { rr *= 1.5; } #line 14 double ry = rr; double rx = land_display_width() - rr; if (mx > rx && my < ry && (a->dpad < 4 || ! a->swipe)) { return 1; } #line 18 return 0; }
void init(void) { All * a = global_a; all_init(a); land_display_title("Yellow and Dangerous"); reload_fonts(); #line 148 a->up = 0; a->down = 0; a->left = 0; a->right = 0; a->jump = 0; #line 154 a->text = (LandColor) {0, 0, 0, 1}; #line 156 config_controls_read(); #line 158 game_setup(land_display_width(), land_display_height()); #line 160 render_setup(); #line 162 a->show_fps = 0; #line 164 for (int i = 0; i < 10; i += 1) { a->cheatpos [i] = 0; } }
void reload_fonts(void) { LandBuffer * b = land_buffer_new(); land_buffer_cat(b, main_data_path); //land_buffer_cat(b, "/data/Muli-Regular.ttf") land_buffer_cat(b, "/data/JosefinSans-Regular.ttf"); char * path = land_buffer_finish(b); #line 118 All * a = global_a; float w = land_display_width(); //float h = land_display_height() double s = w / 960; #line 123 if (a->font) { land_font_destroy(a->font); } #line 125 if (a->medium) { land_font_destroy(a->medium); } #line 127 if (a->big) { land_font_destroy(a->big); } a->font = land_font_load(path, 10 * s); land_font_scale(a->font, 1.0 / s); a->medium = land_font_load(path, 24 * s); land_font_scale(a->medium, 1.0 / s); a->big = land_font_load(path, 60 * s); land_font_scale(a->big, 1.0 / s); #line 137 land_font_set(a->medium); land_text_get_width("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); #line 140 land_free(path); }
void overview_render_next(Overview * self) { if (self->screenshot [game->level]) { #line 69 return ; } All * a = global_a; #line 73 game->sequence = 1; #line 75 intro_tint = land_color_rgba(1, 1, 1, 1); intro_back = land_color_rgba(0, 0, 0, 0); a->render_screenshot = 1; #line 79 int w = land_display_width(); int h = land_display_height(); self->screenshot [game->level] = land_image_new(w / 4, h / 4); land_set_image_display(self->screenshot [game->level]); #line 84 Viewport * backup = game->viewport; Viewport ovp; game->viewport = & ovp; viewport_update(game->viewport, w / 4, h / 4); a->overview = 0; render(game, w / 4, h / 4); a->overview = 1; game->viewport = backup; #line 93 land_unset_image_display(); #line 95 land_image_center(self->screenshot [game->level]); #line 97 game->sequence = 0; a->render_screenshot = 0; }
static bool check_title_button(LandFloat mx, LandFloat my) { All * a = global_a; if (! a->show_map) { return 0; } #line 24 double rr = land_display_width() / 8 * 0.8; if (a->dpad == 2 || a->dpad == 3) { rr *= 1.5; } #line 27 double ry = rr; double rx = land_display_width() - rr; if (mx > rx && my > ry && my < ry + rr && (a->dpad < 4 || ! a->swipe)) { return 1; } #line 31 return 0; }
void update(void) { All * a = global_a; #line 175 if (land_was_resized()) { #line 177 viewport_update(game->viewport, land_display_width(), land_display_height()); a->resize_in_ticks = 10; } if (a->resize_in_ticks > 0) { a->resize_in_ticks--; if (a->resize_in_ticks == 0) { reload_fonts(); } } #line 185 if (a->load_after_redraw) { if (a->load_after_redraw == 2) { #line 188 load_level(a->editor || game->record->is_replaying || game->record->is_recording); if (a->find_entrance) { a->find_entrance = 0; if (game->player) { player_find_entrance(& game->player->super); } } #line 193 if (game && game->player) { #line 195 record_load(game->record, game->level, game->player->super.x, game->player->super.y, game->player->super.z); } #line 196 a->load_after_redraw++; } #line 196 return ; } #line 199 config_check_controls(a); #line 201 if (a->title) { title_tick(); } #line 202 else { #line 204 game_tick(game); } }
void redraw(void) { #line 67 All * a = global_a; #line 69 if (a->load_after_redraw) { if (! a->overview) { render_loading_screen(); } #line 72 if (a->load_after_redraw == 1) { a->load_after_redraw = 2; } #line 74 else if (a->load_after_redraw == 2) { // wait for logic code to advance #line 74 ; } #line 77 if (a->load_after_redraw > 2) { a->load_after_redraw++; double t = land_get_time(); while (1) { if (! blocks_preload(game->blocks)) { a->load_after_redraw = 0; #line 84 if (a->overview) { overview_render_next(game->overview); } #line 86 break; } #line 87 if (land_get_time() > t + 0.01) { break; } } } #line 90 if (! a->overview) { #line 90 return ; } } float w = land_display_width(); float h = land_display_height(); //float fh = land_font_height(a->font) #line 97 if (a->title) { title_render(); } #line 98 else { #line 100 render(game, w, h); } if (a->show_fps) { double f1, f2; get_fps(& f1, & f2); land_text_pos(w, 0); land_font_set(a->font); land_color(a->text.r, a->text.g, a->text.b, a->text.a); land_print_right("FPS: %4d +- %-4d", (int) f1, (int) f2); land_print_right("%4d / sec", (int)(1.0 / a->direct_speed_measure)); } }
void input_tick(void) { All * a = global_a; #line 51 int count = 0; bool any = 0; for (int ti = 0; ti < 11; ti += 1) { double mx = land_touch_x(ti); double my = land_touch_y(ti); #line 57 bool holding = land_touch_down(ti); bool clicked = holding && land_touch_delta(ti); bool released = ! land_touch_down(ti) && land_touch_delta(ti); #line 61 if (! holding && ! released) { continue; } if (check_pause_button(mx, my)) { if (clicked) { input_toggle_pause(); } #line 66 return ; } #line 69 if (check_title_button(mx, my)) { a->show_map = 0; main_switch_to_title(0); #line 71 return ; } #line 74 if (check_menu(mx, my, released)) { break; } if (a->overview) { overview_click(game->overview, mx, my, clicked, released); break; } if (a->editor) { editor_click(mx, my, clicked, released); break; } if (! land_touch_down(ti)) { continue; } #line 87 any = 1; count++; #line 90 double rr = land_display_width() / 8 * 0.8; if (a->dpad == 2 || a->dpad == 3) { rr *= 1.5; } double dx = 0, dy = 0; #line 96 if (a->dpad > 3) { double p = 0.97; if (a->dpad == 4 || (a->dpad == 5 && count == 1)) { dx = mx - a->swipex; dy = my - a->swipey; a->swipex = a->swipex * p + mx * (1 - p); a->swipey = a->swipey * p + my * (1 - p); } if (! a->swipe) { a->swipe = 1; #line 107 if (a->dpad == 4) { if (land_get_time() < a->swipet + 0.25) { // double tap if (! a->swipej) { a->swipej = 1; } #line 111 else { // after heaving, just push // (so can lift+push, not lift+jump) #line 115 a->swipej = 0; } } #line 115 else { #line 117 a->swipex = mx; a->swipey = my; a->swipej = 0; dx = 0; dy = 0; } } #line 122 else if (a->dpad == 5) { a->swipex = mx; a->swipey = my; a->swipej = 0; dx = 0; dy = 0; } a->swipet = land_get_time(); } #line 129 else { #line 131 if (a->dpad == 5) { if (count == 1) { a->swipej = 0; } #line 134 if (count > 1) { a->swipej = 1; } } } #line 137 if (a->swipej) { a->jump = 1; } } #line 138 else { #line 140 double rx = rr; if (a->dpad == 1 || a->dpad == 3) { rx = land_display_width() - rr; } #line 143 double ry = land_display_height() - rr; if (a->dpad == 1 || a->dpad == 3) { rx = land_display_width() - rr; } #line 146 dx = mx - rx; dy = my - ry; } // move control // c // b d // a e // 9 f // 8 0 // 7 1 // 6 2 // 5 3 // 4 #line 160 bool move = 0; if (a->dpad == 4 || (a->dpad == 5 && count == 1)) { if (dx * dx + dy * dy > rr * rr / 256) { move = 1; } } #line 164 if (a->dpad < 4) { if ((fabs(dx) < rr && fabs(dy) < rr)) { if (dx * dx + dy * dy > rr * rr / 16) { move = 1; } } } #line 169 if (move) { double ang = atan2(dy, dx); // we use 16 subdivisions, the main directions get 12 // out of that and the diagonals 4 ang += pi / 16; if (ang < 0) { ang += pi * 2; } #line 176 int i = ang * 8 / pi; if (i <= 3 || i >= 0xd) { a->right = 1; } #line 179 if (i >= 1 && i <= 7) { a->down = 1; } #line 181 if (i >= 5 && i <= 0xb) { a->left = 1; } #line 183 if (i >= 9) { a->up = 1; } #line 185 a->swipet = land_get_time(); } // jump control if (a->dpad == 4 || a->dpad == 5) { #line 188 ; } #line 188 else { #line 191 double rx = land_display_width() - rr; double ry = land_display_height() - rr; if (a->dpad == 1 || a->dpad == 3) { rx = rr; } #line 195 dx = mx - rx; dy = my - ry; if (dx * dx + dy * dy < rr * rr) { a->jump = 1; } } } #line 200 if (! any) { if (a->dpad == 5) { a->swipej = 0; } #line 203 if (a->dpad == 4) { if (a->swipe) { a->swipet = land_get_time(); } } #line 206 a->swipe = 0; } }