int main () { double prev_time = 0.0; double accum_sim_time = 0.0; if (!start_gl (800, 800)) { fprintf (stderr, "ERROR: could not start opengl\n"); return 1; } init_cam (); init_terrain (); init_dash (); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glClearColor (0.0, 0.5, 0.5, 1.0); prev_time = glfwGetTime (); while (!glfwWindowShouldClose (gl_window)) { // work out how much time has passed double curr_time = glfwGetTime (); double elapsed = curr_time - prev_time; prev_time = curr_time; accum_sim_time += elapsed; // work out simulation time steps while (accum_sim_time > TIME_STEP_SIZE) { accum_sim_time -= TIME_STEP_SIZE; update_player (TIME_STEP_SIZE); } glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, gl_width, gl_height); draw_terrain (); // i dont want the dashboard to ever intersect with background so // i do a clear of the depth buffer glClear (GL_DEPTH_BUFFER_BIT); draw_dash (); // can expect everything has updated camera matrices by now cam_P_dirty = false; cam_V_dirty = false; glfwPollEvents (); glfwSwapBuffers (gl_window); } return 0; }
void game() { /* MAIN LOOP, DO NOT BREAK */ while (1) { /* GETKEY */ keyupdate(); // handle [menu] if (PRGM_GetKey()==48) { GetKey(&key); } // direction keys if (keydownlast(KEY_PRGM_LEFT) && cursor_pos[0]>33) { cursor_pos[0] -= cursor_speed; } else if (keydownlast(KEY_PRGM_RIGHT) && cursor_pos[0]<LCD_WIDTH_PX-33) { cursor_pos[0] += cursor_speed; } if (keydownlast(KEY_PRGM_UP) && cursor_pos[1]>0) { cursor_pos[1] -= cursor_speed; } else if (keydownlast(KEY_PRGM_DOWN) && cursor_pos[1]<(LCD_HEIGHT_PX-dash_height-cart_height-man_height-10)) { cursor_pos[1] += cursor_speed; } // control keys // shift if (keydownlast(KEY_PRGM_SHIFT) && man_is_hanging) { // drop man man_is_hanging = false; man_pos[0] = copter_pos[0]; man_pos[1] = copter_pos[1]+9; } /* OPERATIONS */ // move copter if (cursor_pos[0] > copter_pos[0]) { copter_pos[0]+=copter_speed; } else if (cursor_pos[0] < copter_pos[0]) { copter_pos[0]-=copter_speed; } if (cursor_pos[1] > copter_pos[1]) { copter_pos[1]+=copter_speed; } else if (cursor_pos[1] < copter_pos[1]) { copter_pos[1]-=copter_speed; } // if man is falling, drop him if (!man_is_hanging) { man_pos[1] += man_speed; } // if man is below cart level, check if he is in the cart if (!man_is_hanging && man_pos[1]>(LCD_HEIGHT_PX-dash_height-cart_height-5)) { if (!man_is_dead && man_pos[0]>cart_pos && man_pos[0]<cart_pos+35) { next_try(); } else { die_animation(man_pos[0], man_pos[1]); } } // move cart cart_counter = (cart_counter+1) % LCD_WIDTH_PX; cart_pos = cart_counter-70; // update frame cart_frame = (cart_frame+1) % 2; /* GRAPHICS */ // clear screen Bdisp_AllClr_VRAM(); // display functions draw_copter(copter_pos[0], copter_pos[1], man_is_hanging); draw_cart(cart_pos, LCD_HEIGHT_PX-dash_height-cart_height, cart_frame); // if man is falling, draw him if (!man_is_hanging /* && !man_is_dead */) { draw_man(man_pos[0], man_pos[1]); } // draw dash draw_dash(); // draw cursor on top of everything draw_cursor(cursor_pos[0], cursor_pos[1]); // copy VRAM to screen Bdisp_PutDisp_DD(); } }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { static double solid_line[] = { 4, 0 }; static double invisible_line[] = { 0, 4 }; static double dotted_line[] = { 0, 6 }; static double zero_1_of_3[] = { 0, 2, 3 }; static double zero_2_of_3[] = { 1, 0, 3 }; static double zero_3_of_3[] = { 1, 2, 0 }; static double zero_1_of_4[] = { 0, 2, 3, 4 }; static double zero_2_of_4[] = { 1, 0, 3, 4 }; static double zero_3_of_4[] = { 1, 2, 0, 4 }; static double zero_4_of_4[] = { 1, 2, 3, 0 }; static double zero_1_2_of_4[] = { 0, 0, 3, 4 }; static double zero_1_3_of_4[] = { 0, 2, 0, 4 }; /* Clearly it would be nice to draw this one as well, but it seems to trigger a bug in ghostscript. */ #if BUG_FIXED_IN_GHOSTSCRIPT static double zero_1_4_of_4[] = { 0, 2, 3, 0 }; #endif static double zero_2_3_of_4[] = { 1, 0, 0, 4 }; static double zero_2_4_of_4[] = { 1, 0, 3, 0 }; static double zero_3_4_of_4[] = { 1, 2, 0, 0 }; static double zero_1_2_3_of_4[] = { 0, 0, 0, 4 }; static double zero_1_2_4_of_4[] = { 0, 0, 3, 0 }; static double zero_1_3_4_of_4[] = { 0, 2, 0, 0 }; static double zero_2_3_4_of_4[] = { 1, 0, 0, 0 }; cairo_set_source_rgb (cr, 1, 0, 0); cairo_set_line_width (cr, 2); draw_dash (cr, solid_line, 2); draw_dash (cr, invisible_line, 2); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); draw_dash (cr, dotted_line, 2); cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); draw_dash (cr, zero_1_of_3, 3); draw_dash (cr, zero_2_of_3, 3); draw_dash (cr, zero_3_of_3, 3); draw_dash (cr, zero_1_of_4, 4); draw_dash (cr, zero_2_of_4, 4); draw_dash (cr, zero_3_of_4, 4); draw_dash (cr, zero_4_of_4, 4); draw_dash (cr, zero_1_2_of_4, 4); draw_dash (cr, zero_1_3_of_4, 4); #if BUG_FIXED_IN_GHOSTSCRIPT draw_dash (cr, zero_1_4_of_4, 4); #endif draw_dash (cr, zero_2_3_of_4, 4); draw_dash (cr, zero_2_4_of_4, 4); draw_dash (cr, zero_3_4_of_4, 4); draw_dash (cr, zero_1_2_3_of_4, 4); draw_dash (cr, zero_1_2_4_of_4, 4); draw_dash (cr, zero_1_3_4_of_4, 4); draw_dash (cr, zero_2_3_4_of_4, 4); return CAIRO_TEST_SUCCESS; }