void draw_column(t_raycaster *r, t_map *map, t_img *img, int x) { int line_height; int draw_start; int draw_end; int y; line_height = abs((int)(img->height / r->w_dis)); draw_start = -line_height / 2 + img->height / 2; draw_end = line_height / 2 + img->height / 2; if (draw_start < 0) draw_start = 0; if (draw_end >= img->height) draw_end = img->height - 1; y = draw_start; while (y < draw_end) { r->wall_y = -(((double)(y * 256 - img->height * 128 + line_height * 128)) / line_height) / 256 + 1; color_of_texture(tile_at_index(map, r->map.x, r->map.y), r->wall_x, r->wall_y); put_pixel(img, (t_pix){x, y}); y++; } draw_sky(img, r, (t_pix){x, draw_start}); draw_floor(img, map, r, (t_pix){x, draw_end}); }
void GameOver::loop(float timeStep) { int width, height; width = getparam_x_resolution(); height = getparam_y_resolution(); /* Check joystick */ if ( is_joystick_active() ) { update_joystick(); if ( is_joystick_continue_button_down() ) { if ( gameMgr->gametype != GameMgr::PRACTICING ) { set_game_mode( EVENT_RACE_SELECT ); }else{ set_game_mode( RACE_SELECT ); } winsys_post_redisplay(); return; } } fpsCounter.update(); update_audio(); clear_rendering_context(); fogPlane.setup(); update_player_pos( players[0], 0 ); update_view( players[0], 0 ); setup_view_frustum( players[0], NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(players[0].view.pos); draw_fog_plane(); set_course_clipping( true ); set_course_eye_point( players[0].view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { draw_particles( players[0] ); } ModelHndl->draw_tux(); draw_tux_shadow(); set_gl_options( GUI ); UIMgr.setupDisplay(); UIMgr.draw(); HUD1.draw(players[0]); reshape( width, height ); winsys_swap_buffers(); }
uint32_t buggychl_state::screen_update_buggychl(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { if (m_sky_on) draw_sky(bitmap, cliprect); else bitmap.fill(0x20, cliprect); // stage 3 disables sky, wants background pen to be blue draw_bg(bitmap, cliprect); draw_sprites(bitmap, cliprect); draw_fg(bitmap, cliprect); return 0; }
UINT32 buggychl_state::screen_update_buggychl(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { if (m_sky_on) draw_sky(bitmap, cliprect); else bitmap.fill(0, cliprect); if (m_bg_on) draw_bg(bitmap, cliprect); draw_sprites(bitmap, cliprect); draw_fg(bitmap, cliprect); return 0; }
void drawx(t_mlx *mlx) { int x; float val; float length; float wall; float deg; x = 0; length = 0; wall = 0; deg = mlx->deg - 30; val = (60 / (float)mlx->w); draw_sky(mlx); draw_floor(mlx); while (x <= mlx->w) { length = line(mlx, 0, deg); wall = mlx->h / length; drawy(mlx, wall, x); deg += val; x++; } }
static void draw_drive(lemuria_engine_t * e, void * user_data) { int index_1; int index_2; int i; float delta_phi; float angle; float speed; float speed_norm; drive_data * d = (drive_data*)(user_data); lemuria_range_update(&(d->curvature_range)); lemuria_range_update(&(d->speed_range)); /* Change stuff */ lemuria_range_get(&(d->speed_range), &(d->speed_start), &(d->speed_end), &speed); speed_norm = speed / SPEED_MAX; // fprintf(stderr, "Speed: %f speed_max: %f (Speed/speed_max)^2: %f\n", // speed, SPEED_MAX, speed_norm * speed_norm); // fprintf(stderr, "Speed: %f %f\n", speed, SPEED_MAX); if(e->quiet) { d->speed_start = speed; d->speed_end = SPEED_MIN; lemuria_range_init(e, &(d->speed_range), 1, 100, 200); } else if(e->beat_detected) { if(lemuria_range_done(&(d->speed_range)) && lemuria_decide(e, 0.2)) { d->speed_start = d->speed_end; d->speed_end = SPEED_MIN + (lemuria_random(e, 0.0, 0.5) + 0.5 * (float)e->loudness/32768.0)*(SPEED_MAX - SPEED_MIN); lemuria_range_init(e, &(d->speed_range), 1, 100, 200); } if(lemuria_range_done(&(d->curvature_range)) && lemuria_decide(e, 0.2)) { d->delta_phi_start = d->delta_phi_end; // if(d->delta_phi_end > 0.0) if(lemuria_decide(e, 0.3)) d->delta_phi_end = 0.0; else { // d->delta_phi_end = lemuria_random(DELTA_PHI_MIN, DELTA_PHI_MAX); d->delta_phi_end = DELTA_PHI_MIN + (lemuria_random(e, 0.0, 0.5) + 0.5 * (float)e->loudness / 32768.0)*(DELTA_PHI_MAX - DELTA_PHI_MIN); if(lemuria_decide(e, 0.5)) d->delta_phi_end *= -1.0; } // fprintf(stderr, "New phi: %f\n", d->delta_phi_end * 180.0 / M_PI); lemuria_range_init(e, &(d->curvature_range), 2, 50, 100); } } /* Create new rings if necessary */ d->z_start += speed; lemuria_range_get(&(d->curvature_range), &(d->delta_phi_start), &(d->delta_phi_end), &delta_phi); if(fabs(delta_phi) < DELTA_PHI_MIN) delta_phi = 0.0; while(d->z_start >= DELTA_Z) { d->segments[d->start_segment].delta_phi = delta_phi; d->texture_y += TEXTURE_DELTA_Y; d->segments[d->start_segment].texture_y_before = d->texture_y; if(d->texture_y > 1.0) d->texture_y -= 1.0; d->segments[d->start_segment].texture_y_after = d->texture_y; d->start_segment++; if(d->start_segment >= NUM_SEGMENTS) d->start_segment = 0; d->z_start -= DELTA_Z; } update_coords(d); /* Set up Opengl */ glClearColor(0.0, 0.0, 0.0, 0.0); // glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); lemuria_set_perspective(e, 1, 1000.0); /* Set up light and materials */ #ifndef DRAW_MESH glShadeModel(GL_SMOOTH); #endif glMatrixMode(GL_MODELVIEW); glPushMatrix(); index_1 = d->start_segment; index_2 = index_1 + 1; if(index_2 >= NUM_SEGMENTS) index_2 = 0; /* Do curvature transformation */ angle = atan2(20.0 * (speed_norm * speed_norm) * d->segments[d->start_segment].delta_phi, DELTA_PHI_MAX); /* / (SPEED_MAX * SPEED_MAX) */ d->angle = 0.8 * d->angle + 0.2 * angle; /* */ glTranslatef(0.0, SEGMENT_RADIUS - CAMERA_HEIGHT, 0.0); glRotatef(d->angle * 180.0 / M_PI, 0.0, 0.0, 1.0); glTranslatef(0.0, CAMERA_HEIGHT - SEGMENT_RADIUS, 0.0); #ifndef DRAW_MESH draw_sky(d, 0.0); glFogi(GL_FOG_MODE, GL_LINEAR ); glFogfv(GL_FOG_COLOR, fog_color); glFogf(GL_FOG_START, FOG_START); glFogf(GL_FOG_END, FOG_END); glEnable(GL_FOG); /* We set the light after we rotated stuff */ lemuria_set_material(&material, GL_FRONT); glEnable(GL_LIGHTING); lemuria_background_set(&(d->drive_background)); lemuria_set_light(&light_0, GL_LIGHT0); glEnable(GL_LIGHT0); glEnable(GL_TEXTURE_2D); #endif // lemuria_set_light(&light_1, GL_LIGHT1); // glEnable(GL_LIGHT1); // fprintf(stderr, "Segments: %d %d\n", d->start_segment, d->end_segment); for(i = 0; i < NUM_SEGMENTS-1; i++) { draw_segment(d, index_1, index_2); if(index_2 == d->end_segment) break; index_1++; if(index_1 >= NUM_SEGMENTS) index_1 = 0; index_2++; if(index_2 >= NUM_SEGMENTS) index_2 = 0; } glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_LIGHT1); glDisable(GL_FOG); }
void racing_loop( scalar_t time_step ) { int width, height; player_data_t *plyr = get_player_data( local_player() ); bool_t joy_paddling = False; bool_t joy_braking = False; bool_t joy_charging = False; bool_t airborne; vector_t dir; scalar_t speed; scalar_t terrain_weights[NumTerrains]; int new_terrain = 0; int slide_volume; dir = plyr->vel; speed = normalize_vector(&dir); airborne = plyr->airborne; width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); /* Update braking */ plyr->control.is_braking = (bool_t) ( braking || joy_braking ); if ( airborne ) { new_terrain = (1<<NumTerrains); /* * Tricks */ if ( trick_modifier) { if (left_turn) { plyr->control.barrel_roll_left = True; } if (right_turn) { plyr->control.barrel_roll_right = True; } if (paddling) { plyr->control.front_flip = True; } if (plyr->control.is_braking) { plyr->control.back_flip = True; } //Par défaut ca fait un front flip if(!plyr->control.front_flip && !plyr->control.back_flip && !plyr->control.barrel_roll_right && !plyr->control.barrel_roll_left ) { plyr->control.back_flip = True; } #ifdef __APPLE__ TRDebugLog("tricks : %d",plyr->tricks); #endif } } else { get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights); if (terrain_weights[Snow] > 0) { new_terrain |= (1<<Snow); } if (terrain_weights[Rock] > 0) { new_terrain |= (1<<Rock); } if (terrain_weights[Ice] > 0) { new_terrain |= (1<<Ice); } } /* * Jumping */ calc_jump_amt( time_step ); if ( ( charging || joy_charging ) && !plyr->control.jump_charging && !plyr->control.jumping ) { plyr->control.jump_charging = True; charge_start_time = g_game.time; } if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) { plyr->control.jump_charging = False; plyr->control.begin_jump = True; } /* * Turning */ scalar_t iPhone_turn_fact=accelerometerTurnFact(); iPhone_turn_fact=accelerometerTurnFact(); /*left_turn and right_turn are informations useful for tricks*/ if (iPhone_turn_fact>TURN_FACTOR_LIMIT) { left_turn=false; right_turn=true; } else if (iPhone_turn_fact<-TURN_FACTOR_LIMIT) { left_turn=true; right_turn=false; } else left_turn = right_turn = false; plyr->control.turn_fact = iPhone_turn_fact; plyr->control.turn_animation = iPhone_turn_fact; /* * Paddling */ if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) { plyr->control.is_paddling = True; plyr->control.paddle_time = g_game.time; } /* * Play flying sound (__APPLE__ : and add Flying time to plyr->control.fly_total_time) */ if (new_terrain & (1<<NumTerrains)) { set_sound_volume("flying_sound", min(128, speed*2)); if (!(last_terrain & (1<<NumTerrains))) { play_sound( "flying_sound", -1 ); plyr->control.is_flying=true; plyr->control.fly_start_time = g_game.time; } } else { if (last_terrain & (1<<NumTerrains)) { plyr->control.is_flying=false; plyr->control.fly_end_time = g_game.time; if (plyr->control.fly_end_time-plyr->control.fly_start_time>FLYING_TIME_LIMIT) { plyr->control.fly_total_time += plyr->control.fly_end_time-plyr->control.fly_start_time; } halt_sound( "flying_sound" ); } } /* * Play sliding sound */ slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) + (plyr->control.is_braking?128:0) + (plyr->control.jumping?128:0) + 20) * (speed/10), 128 ); if (new_terrain & (1<<Snow)) { set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]); if (!(last_terrain & (1<<Snow))) { play_sound( "snow_sound", -1 ); } } else { if (last_terrain & (1<<Snow)) { halt_sound( "snow_sound" ); } } if (new_terrain & (1<<Rock)) { //set_sound_volume("rock_sound", 128*pow((speed/2), 2) * terrain_weights[Rock]); int rockvol = slide_volume * 10 * terrain_weights[Rock]; if (rockvol > 400) rockvol = 400; set_sound_volume("rock_sound", rockvol); if (!(last_terrain & (1<<Rock))) { play_sound( "rock_sound", -1 ); } } else { if (last_terrain & (1<<Rock)) { halt_sound( "rock_sound" ); } } if (new_terrain & (1<<Ice)) { set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]); if (!(last_terrain & (1<<Ice))) { play_sound( "ice_sound", -1 ); } } else { if (last_terrain & (1<<Ice)) { halt_sound( "ice_sound" ); } } last_terrain = new_terrain; /* * gs */ bool roll = plyr->control.barrel_roll_left || plyr->control.barrel_roll_right; bool flip = plyr->control.front_flip || plyr->control.back_flip; if(roll && plyr->control.barrel_roll_factor == 0) { if(flip) { if(plyr->control.barrel_roll_left) add_new_bonus("Hyper heavy Jump", get_score_for_trick(HYPER_HEAVY_JUMP)); else add_new_bonus("Ray star hybrid Jump", get_score_for_trick(RAY_STAR_HYBRID_JUMP)); } else { if(plyr->control.barrel_roll_left) add_new_bonus("Roll Left", get_score_for_trick(ROLL_LEFT)); else add_new_bonus("Roll Right", get_score_for_trick(ROLL_RIGHT)); } } if(flip && plyr->control.flip_factor == 0) { if(roll) { if(plyr->control.back_flip) add_new_bonus("Saturn ice Fever", get_score_for_trick(SATURN_ICE_FEVER)); else add_new_bonus("Wild pinguin Show", get_score_for_trick(WILD_PINGUIN_SHOW)); } else { if(plyr->control.back_flip) add_new_bonus("Back Flip", get_score_for_trick(BACK_FLIP)); else add_new_bonus("Barlow's Wheel", get_score_for_trick(BARLOWS_WHEEL)); } } if (roll) { plyr->tricks+=1; plyr->control.barrel_roll_factor += ( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.05 * time_step / 0.05; if ( (plyr->control.barrel_roll_factor > 1) || (plyr->control.barrel_roll_factor < -1) ) { plyr->control.barrel_roll_factor = 0; plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False; } } if (flip) { plyr->tricks+=1; plyr->control.flip_factor += ( plyr->control.back_flip ? -1 : 1 ) * 0.05 * time_step / 0.05; if ( (plyr->control.flip_factor > 1) || (plyr->control.flip_factor < -1) ) { plyr->control.flip_factor = 0; plyr->control.front_flip = plyr->control.back_flip = False; } } update_player_pos( plyr, time_step ); /* * Track Marks */ add_track_mark( plyr ); update_view( plyr, time_step ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { update_particles( time_step ); draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); draw_hud( plyr ); draw_hud_training(plyr); reshape( width, height ); winsys_swap_buffers(); g_game.time += time_step; }
/** \brief The per-frame OpenGL display routine * * This function does the complete OpenGL drawing. First * the 3D scene is drawn, then some 2D overlays * (wind and battery indicator, GUI). */ void display() { CRRCMath::Vector3 plane_pos = FDM2Graphics(Global::aircraft->getPos()); // Prepare the current frame buffer and reset // the modelview matrix (for non-SSG drawing) GLbitfield clearmask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; if (vidbits.stencil) { clearmask |= GL_STENCIL_BUFFER_BIT; } glClear(clearmask); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); //~ glBlendFunc(GL_ONE, GL_ZERO); //~ glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); // Set up the viewing transformation (for SSG drawing) sgVec3 viewpos, planepos, up; sgSetVec3(viewpos, player_pos.r[0], player_pos.r[1], player_pos.r[2]); sgSetVec3(planepos, looking_pos.r[0], looking_pos.r[1], looking_pos.r[2]); sgSetVec3(up, 0.0, 1.0, 0.0); context->setCameraLookAt(viewpos, planepos, up); // 3D scene if( Global::scenery != NULL) { // 3D scene: sky sphere draw_sky(&viewpos, Global::Simulation->getTotalTime()); // 3D scene: airplane if (Global::aircraft->getModel() != NULL) { // For SSG rendering, this call does not draw anything, // but calculates the airplane's transformation matrix glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); Global::aircraft->getModel()->draw(Global::aircraft->getFDM()); } // 3D scene: scenery Global::scenery->draw(Global::Simulation->getTotalTime()); } // Lighting setup. Only needed as long as there are // non-SSG parts that modify the light sources. sgVec4 lightamb; sgSetVec4(lightamb , 0.2f, 0.2f, 0.2f, 1.0f); ssgGetLight(0)->setPosition(lightposn); ssgGetLight(0)->setColour(GL_AMBIENT, lightamb); // Draw the scenegraph (airplane model, shadow) ssgCullAndDraw(scene); context->forceBasicState(); // ssgCullAndDraw() ends up with an identity modelview matrix, // so we have to set up our own viewing transformation for // the thermals glLoadIdentity(); gluLookAt(player_pos.r[0], player_pos.r[1], player_pos.r[2], looking_pos.r[0], looking_pos.r[1], looking_pos.r[2], 0.0, 1.0, 0.0); if (Global::training_mode==TRUE) { draw_thermals(Global::aircraft->getPos()); } // 3D scene: game-mode-specific stuff (pylons etc.) Global::gameHandler->draw(); glPopMatrix(); // Overlay: game handler Global::gameHandler->display_infos(window_xsize, window_ysize); // Overlay: scope for audio interface if ( Global::testmode.test_mode && (Global::TXInterface->inputMethod() == T_TX_Interface::eIM_audio) ) { GlOverlay::setupRenderingState(window_xsize, window_ysize); oscillo(); GlOverlay::restoreRenderingState(); } // Overlay: wind direction indicator { double dx = (plane_pos.r[2] - player_pos.r[2]); double dy = (player_pos.r[0] - plane_pos.r[0]); double dir = atan2(dy, dx); GlOverlay::setupRenderingState(window_xsize, window_ysize); draw_wind(dir); GlOverlay::restoreRenderingState(); } // Overlay: battery capacity/fuel left { int r = window_ysize >> 5; int w = r >> 1; int h = window_ysize >> 3; int ht = (int)(Global::aircraft->getFDM()->getBatCapLeft() * h); #if 0 glDisable(GL_LIGHTING); glMatrixMode (GL_PROJECTION); glPushMatrix(); glLoadIdentity (); gluOrtho2D (0, window_xsize-1, 0, window_ysize); #endif GlOverlay::setupRenderingState(window_xsize, window_ysize); // Background glColor3f (0, 0, 0); glRectf(window_xsize-w, r+ht, window_xsize-1, r+h); glTranslatef(0,0,0.1); // Indicator glColor3f (0, 1, 0.); glRectf(window_xsize-w, r, window_xsize-1, r+ht); #if 0 glPopMatrix(); glEnable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); #endif GlOverlay::restoreRenderingState(); } // Overlay: console console->render(window_xsize, window_ysize); // Overlay: gui Global::gui->draw(); // check for any OpenGL errors evaluateOpenGLErrors(); // Force pipeline flushing and flip front and back buffer glFlush(); SDL_GL_SwapBuffers(); }
void Racing::loop(float timeStep) { int width, height; bool joy_left_turn = false; bool joy_right_turn = false; double joy_turn_fact = 0.0; bool joy_paddling = false; bool joy_braking = false; bool joy_tricks = false; bool joy_charging = false; bool airborne; pp::Vec3d dir; float speed; float terrain_weights[NUM_TERRAIN_TYPES]; int new_terrain = 0; int slide_volume; unsigned int i; if (Benchmark::getMode() == Benchmark::AUTO){ m_paddling = true; } dir = players[0].vel; speed = dir.normalize(); //set max_speed if (speed > players[0].max_speed) players[0].max_speed=int(speed); airborne = (bool) ( players[0].pos.y > ( find_y_coord(players[0].pos.x, players[0].pos.z) + JUMP_MAX_START_HEIGHT ) ); width = getparam_x_resolution(); height = getparam_y_resolution(); fpsCounter.update(); update_audio(); clear_rendering_context(); fogPlane.setup(); // Joystick if ( is_joystick_active() ) { float joy_x; float joy_y; update_joystick(); joy_x = get_joystick_x_axis(); joy_y = get_joystick_y_axis(); if ( joy_x > 0.1 ) { joy_right_turn = true; joy_turn_fact = joy_x; } else if ( joy_x < -0.1 ) { joy_left_turn = true; joy_turn_fact = joy_x; } if ( getparam_joystick_brake_button() >= 0 ) { joy_braking = is_joystick_button_down( getparam_joystick_brake_button() ); } if ( !joy_braking ) { joy_braking = (bool) ( joy_y > 0.5 ); } if ( getparam_joystick_paddle_button() >= 0 ) { joy_paddling = is_joystick_button_down( getparam_joystick_paddle_button() ); } if ( !joy_paddling ) { joy_paddling = (bool) ( joy_y < -0.5 ); } if ( getparam_joystick_jump_button() >= 0 ) { joy_charging = is_joystick_button_down( getparam_joystick_jump_button() ); } if ( getparam_joystick_trick_button() >= 0 ) { joy_tricks = is_joystick_button_down( getparam_joystick_trick_button() ); } } // Update braking players[0].control.is_braking = (bool) ( m_braking || joy_braking ); if ( airborne ) { new_terrain = (1<<4); // Tricks if ( m_trickModifier || joy_tricks ) { if ( m_leftTurn || joy_left_turn ) { players[0].control.barrel_roll_left = true; } if ( m_rightTurn || joy_right_turn ) { players[0].control.barrel_roll_right = true; } if ( m_paddling || joy_paddling ) { players[0].control.front_flip = true; } if ( players[0].control.is_braking ) { players[0].control.back_flip = true; } } for(i=0;i<num_terrains;i++){ if ( !terrain_texture[i].sound.empty() && terrain_texture[i].soundactive==true) { halt_sound( terrain_texture[i].sound.c_str() ); terrain_texture[i].soundactive=false; } } } else { get_surface_type(players[0].pos.x, players[0].pos.z, terrain_weights); //Play sliding sound slide_volume = int(MIN( (((pow(players[0].control.turn_fact, 2)*128)) + (players[0].control.is_braking?128:0) + (players[0].control.jumping?128:0) + 20) * (speed/10), 128 )); for(i=0;i<num_terrains;i++){ if ( !terrain_texture[i].sound.empty() ) { if (terrain_weights[i] > 0 ){ set_sound_volume(terrain_texture[i].sound.c_str(), int(slide_volume * terrain_weights[i])); if (terrain_texture[i].soundactive==false){ play_sound(terrain_texture[i].sound.c_str() , -1 ); terrain_texture[i].soundactive=true; } } else if (terrain_texture[i].soundactive==true){ halt_sound( terrain_texture[i].sound.c_str() ); terrain_texture[i].soundactive=false; } } } } // Jumping calcJumpAmt( timeStep ); if ( ( m_charging || joy_charging ) && !players[0].control.jump_charging && !players[0].control.jumping ) { players[0].control.jump_charging = true; m_chargeStartTime = gameMgr->time; } if ( ( !m_charging && !joy_charging ) && players[0].control.jump_charging ) { players[0].control.jump_charging = false; players[0].control.begin_jump = true; } // Turning if ( ( m_leftTurn || joy_left_turn ) ^ (m_rightTurn || joy_right_turn ) ) { bool turning_left = (bool) ( m_leftTurn || joy_left_turn ); if ( joy_left_turn || joy_right_turn ) { players[0].control.turn_fact = joy_turn_fact; } else { players[0].control.turn_fact = (turning_left?-1:1); } players[0].control.turn_animation += (turning_left?-1:1) * 0.15 * timeStep / 0.05; players[0].control.turn_animation = MIN(1.0, MAX(-1.0, players[0].control.turn_animation)); } else { players[0].control.turn_fact = 0; // Decay turn animation if ( timeStep < ROLL_DECAY_TIME_CONSTANT ) { players[0].control.turn_animation *= 1.0 - timeStep/ROLL_DECAY_TIME_CONSTANT; } else { players[0].control.turn_animation = 0.0; } } //Paddling if ( ( m_paddling || joy_paddling ) && players[0].control.is_paddling == false ) { players[0].control.is_paddling = true; players[0].control.paddle_time = gameMgr->time; } //Play flying sound if (new_terrain & (1<<4)) { set_sound_volume("flying_sound", int(MIN(128, speed*2))); if (!(m_lastTerrain & (1<<4))) { play_sound( "flying_sound", -1 ); } } else { if (m_lastTerrain & (1<<4)) { halt_sound( "flying_sound" ); } } m_lastTerrain = new_terrain; //Tricks if ( players[0].control.barrel_roll_left || players[0].control.barrel_roll_right ) { players[0].control.barrel_roll_factor += ( players[0].control.barrel_roll_left ? -1 : 1 ) * 0.15 * timeStep / 0.05; if ( (players[0].control.barrel_roll_factor > 1) || (players[0].control.barrel_roll_factor < -1) ) { players[0].control.barrel_roll_factor = 0; players[0].control.barrel_roll_left = players[0].control.barrel_roll_right = false; } } if ( players[0].control.front_flip || players[0].control.back_flip ) { players[0].control.flip_factor += ( players[0].control.back_flip ? -1 : 1 ) * 0.15 * timeStep / 0.05; if ( (players[0].control.flip_factor > 1) || (players[0].control.flip_factor < -1) ) { players[0].control.flip_factor = 0; players[0].control.front_flip = players[0].control.back_flip = false; } } update_player_pos( players[0], timeStep ); //Track Marks add_track_mark( players[0] ); update_view( players[0], timeStep ); setup_view_frustum( players[0], NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(players[0].view.pos); draw_fog_plane(); set_course_clipping( true ); set_course_eye_point( players[0].view.pos ); setup_course_lighting(); render_course(); //Draw snow update_snow( timeStep, false, players[0].view.pos ); draw_snow(players[0].view.pos); draw_trees(); if ( getparam_draw_particles() ) { update_particles( timeStep ); draw_particles( players[0] ); } ModelHndl->draw_tux(); draw_tux_shadow(); HUD1.draw(players[0]); reshape( width, height ); winsys_swap_buffers(); gameMgr->time += timeStep; if (airborne) gameMgr->airbornetime += timeStep; if(Benchmark::getMode() == Benchmark::PAUSED){ set_game_mode(PAUSED); } }
void view_draw_scene_render(int tick,obj_type *obj,weapon_type *weap) { // setup projection gl_3D_view(); gl_3D_rotate(&view.render->camera.pnt,&view.render->camera.ang); gl_setup_project(); // draw background and sky // unless obscured by fog if (!fog_solid_on()) { draw_background(); draw_sky(tick); } else { fog_solid_start(); } // setup per-scene shader variables gl_shader_draw_scene_initialize(); // compile meshes for drawing if (!view_compile_mesh_gl_lists(tick)) return; // setup some map polygon drawing flags render_map_setup(); // draw opaque scene items render_map_mesh_opaque(); render_map_liquid_opaque(tick); view_draw_model_opaque(tick); // additional mesh and model drawing // shadows, remote names, etc view_draw_mesh_shadows(); view_draw_models_final(); // draw transparent scene items render_map_mesh_transparent(); view_draw_model_transparent(tick); render_map_liquid_transparent(tick); // draw decals decal_render(); // effects effect_draw(tick); // draw rain rain_draw(tick); // draw fog fog_draw_textured(tick); if (fog_solid_on()) fog_solid_end(); // setup halos, crosshairs, zoom masks remote_draw_names_setup(); halo_draw_setup(); if ((obj!=NULL) && (weap!=NULL)) { crosshair_setup(tick,obj,weap); zoom_setup(tick,obj,weap); // draw the weapons in hand if (camera.mode==cv_fpp) draw_weapon_hand(tick,obj,weap); } // draw the remote names, halos, crosshairs, and zoom masks remote_draw_names_render(); halo_draw_render(); if ((obj!=NULL) && (weap!=NULL)) { crosshair_draw(obj,weap); zoom_draw(obj,weap); } }
void racing_loop( scalar_t time_step ) { int width, height; player_data_t *plyr = get_player_data( local_player() ); bool_t joy_left_turn = False; bool_t joy_right_turn = False; scalar_t joy_turn_fact = 0.0; bool_t joy_paddling = False; bool_t joy_braking = False; bool_t joy_tricks = False; bool_t joy_charging = False; bool_t airborne; vector_t dir; scalar_t speed; scalar_t terrain_weights[NumTerrains]; int new_terrain = 0; int slide_volume; dir = plyr->vel; speed = normalize_vector(&dir); airborne = (bool_t) ( plyr->pos.y > ( find_y_coord(plyr->pos.x, plyr->pos.z) + JUMP_MAX_START_HEIGHT ) ); width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); /* * Joystick */ if ( is_joystick_active() ) { scalar_t joy_x; scalar_t joy_y; update_joystick(); joy_x = get_joystick_x_axis(); joy_y = get_joystick_y_axis(); if ( joy_x > 0.1 ) { joy_right_turn = True; joy_turn_fact = joy_x; } else if ( joy_x < -0.1 ) { joy_left_turn = True; joy_turn_fact = joy_x; } if ( getparam_joystick_brake_button() >= 0 ) { joy_braking = is_joystick_button_down( getparam_joystick_brake_button() ); } if ( !joy_braking ) { joy_braking = (bool_t) ( joy_y > 0.5 ); } if ( getparam_joystick_paddle_button() >= 0 ) { joy_paddling = is_joystick_button_down( getparam_joystick_paddle_button() ); } if ( !joy_paddling ) { joy_paddling = (bool_t) ( joy_y < -0.5 ); } if ( getparam_joystick_jump_button() >= 0 ) { joy_charging = is_joystick_button_down( getparam_joystick_jump_button() ); } if ( getparam_joystick_trick_button() >= 0 ) { joy_tricks = is_joystick_button_down( getparam_joystick_trick_button() ); } } /* Update braking */ plyr->control.is_braking = (bool_t) ( braking || joy_braking ); if ( airborne ) { new_terrain = (1<<NumTerrains); /* * Tricks */ if ( trick_modifier || joy_tricks ) { if ( left_turn || joy_left_turn ) { plyr->control.barrel_roll_left = True; } if ( right_turn || joy_right_turn ) { plyr->control.barrel_roll_right = True; } if ( paddling || joy_paddling ) { plyr->control.front_flip = True; } if ( plyr->control.is_braking ) { plyr->control.back_flip = True; } } } else { get_surface_type(plyr->pos.x, plyr->pos.z, terrain_weights); if (terrain_weights[Snow] > 0) { new_terrain |= (1<<Snow); } if (terrain_weights[Rock] > 0) { new_terrain |= (1<<Rock); } if (terrain_weights[Ice] > 0) { new_terrain |= (1<<Ice); } } /* * Jumping */ calc_jump_amt( time_step ); if ( ( charging || joy_charging ) && !plyr->control.jump_charging && !plyr->control.jumping ) { plyr->control.jump_charging = True; charge_start_time = g_game.time; } if ( ( !charging && !joy_charging ) && plyr->control.jump_charging ) { plyr->control.jump_charging = False; plyr->control.begin_jump = True; } /* * Turning */ if ( ( left_turn || joy_left_turn ) ^ (right_turn || joy_right_turn ) ) { bool_t turning_left = (bool_t) ( left_turn || joy_left_turn ); if ( joy_left_turn || joy_right_turn ) { plyr->control.turn_fact = joy_turn_fact; } else { plyr->control.turn_fact = (turning_left?-1:1); } plyr->control.turn_animation += (turning_left?-1:1) * 0.15 * time_step / 0.05; plyr->control.turn_animation = min(1.0, max(-1.0, plyr->control.turn_animation)); } else { plyr->control.turn_fact = 0; /* Decay turn animation */ if ( time_step < ROLL_DECAY_TIME_CONSTANT ) { plyr->control.turn_animation *= 1.0 - time_step/ROLL_DECAY_TIME_CONSTANT; } else { plyr->control.turn_animation = 0.0; } } /* * Paddling */ if ( ( paddling || joy_paddling ) && plyr->control.is_paddling == False ) { plyr->control.is_paddling = True; plyr->control.paddle_time = g_game.time; } /* * Play flying sound */ if (new_terrain & (1<<NumTerrains)) { set_sound_volume("flying_sound", min(128, speed*2)); if (!(last_terrain & (1<<NumTerrains))) { play_sound( "flying_sound", -1 ); } } else { if (last_terrain & (1<<NumTerrains)) { halt_sound( "flying_sound" ); } } /* * Play sliding sound */ slide_volume = min( (((pow(plyr->control.turn_fact, 2)*128)) + (plyr->control.is_braking?128:0) + (plyr->control.jumping?128:0) + 20) * (speed/10), 128 ); if (new_terrain & (1<<Snow)) { set_sound_volume("snow_sound", slide_volume * terrain_weights[Snow]); if (!(last_terrain & (1<<Snow))) { play_sound( "snow_sound", -1 ); } } else { if (last_terrain & (1<<Snow)) { halt_sound( "snow_sound" ); } } if (new_terrain & (1<<Rock)) { set_sound_volume("rock_sound", 128*pow((speed/2), 2) * terrain_weights[Rock]); if (!(last_terrain & (1<<Rock))) { play_sound( "rock_sound", -1 ); } } else { if (last_terrain & (1<<Rock)) { halt_sound( "rock_sound" ); } } if (new_terrain & (1<<Ice)) { set_sound_volume("ice_sound", slide_volume * terrain_weights[Ice]); if (!(last_terrain & (1<<Ice))) { play_sound( "ice_sound", -1 ); } } else { if (last_terrain & (1<<Ice)) { halt_sound( "ice_sound" ); } } last_terrain = new_terrain; /* * Tricks */ if ( plyr->control.barrel_roll_left || plyr->control.barrel_roll_right ) { plyr->control.barrel_roll_factor += ( plyr->control.barrel_roll_left ? -1 : 1 ) * 0.15 * time_step / 0.05; if ( (plyr->control.barrel_roll_factor > 1) || (plyr->control.barrel_roll_factor < -1) ) { plyr->control.barrel_roll_factor = 0; plyr->control.barrel_roll_left = plyr->control.barrel_roll_right = False; } } if ( plyr->control.front_flip || plyr->control.back_flip ) { plyr->control.flip_factor += ( plyr->control.back_flip ? -1 : 1 ) * 0.15 * time_step / 0.05; if ( (plyr->control.flip_factor > 1) || (plyr->control.flip_factor < -1) ) { plyr->control.flip_factor = 0; plyr->control.front_flip = plyr->control.back_flip = False; } } update_player_pos( plyr, time_step ); /* * Track Marks */ add_track_mark( plyr ); update_view( plyr, time_step ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { update_particles( time_step ); draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); draw_hud( plyr ); reshape( width, height ); winsys_swap_buffers(); g_game.time += time_step; }
void game_over_loop( scalar_t time_step ) { player_data_t *plyr = get_player_data( local_player() ); int width, height; width = getparam_x_resolution(); height = getparam_y_resolution(); check_gl_error(); /* Check joystick */ if ( is_joystick_active() ) { update_joystick(); if ( is_joystick_continue_button_down() ) { set_game_mode( NEXT_MODE ); winsys_post_redisplay(); return; } } new_frame_for_fps_calc(); update_audio(); clear_rendering_context(); setup_fog(); update_player_pos( plyr, 0 ); update_view( plyr, 0 ); setup_view_frustum( plyr, NEAR_CLIP_DIST, getparam_forward_clip_distance() ); draw_sky(plyr->view.pos); draw_fog_plane(); set_course_clipping( True ); set_course_eye_point( plyr->view.pos ); setup_course_lighting(); render_course(); draw_trees(); if ( getparam_draw_particles() ) { draw_particles( plyr ); } draw_tux(); draw_tux_shadow(); set_gl_options( GUI ); ui_setup_display(); draw_game_over_text(); #ifndef __APPLE__ draw_hud( plyr ); #endif draw_hud_training(plyr); reshape( width, height ); winsys_swap_buffers(); }