예제 #1
0
파일: jump.c 프로젝트: Bediko/r0ket
void ram(void) {

	splash_scene();

	long frame_count = 0;
	init_game();

	while(1) {
		frame_count++;

		lcdFill(0);
		update_platforms(frame_count);
		move_player(frame_count);
		draw_platforms();
		draw_player();
		draw_hud();
		blink_led();
		lcdDisplay();

		if(!game.running) {
			if(!gameover_scene()){
                delayms_queue_plus(10,1);
				return;
            }
			init_game();
		}
        delayms_queue_plus(24,0);
	}
}
예제 #2
0
파일: gamerend.c 프로젝트: Mako88/DXX-Retro
void game_draw_hud_stuff()
{
#ifdef CROSSHAIR
	if ( Viewer->type == OBJ_PLAYER )
		laser_do_crosshair(Viewer);
#endif
	
#ifndef NDEBUG
	draw_window_label();
#endif

#ifdef NETWORK
	game_draw_multi_message();
#endif

	if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
		char message[128];
		int y;

		if (Newdemo_state == ND_STATE_PLAYBACK) {
			if (Newdemo_show_percentage) {
			  	sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
			} else {
				sprintf (message, " ");
			}
		} else {
			extern int Newdemo_num_written;
			sprintf (message, "%s (%dK)", TXT_DEMO_RECORDING, (Newdemo_num_written / 1024));
		}

		gr_set_curfont( GAME_FONT );
		gr_set_fontcolor( BM_XRGB(27,0,0), -1 );

		y = GHEIGHT-(LINE_SPACING*2);

		if (PlayerCfg.CockpitMode[1] == CM_FULL_COCKPIT)
			y = grd_curcanv->cv_bitmap.bm_h / 1.2 ;
		if (PlayerCfg.CockpitMode[1] != CM_REAR_VIEW)
			gr_string(0x8000, y, message );
	}

	render_countdown_gauge();

	if (GameCfg.FPSIndicator && PlayerCfg.CockpitMode[1] != CM_REAR_VIEW)
		show_framerate();

	if (Newdemo_state == ND_STATE_PLAYBACK)
		Game_mode = Newdemo_game_mode;

	draw_hud();

	if (Newdemo_state == ND_STATE_PLAYBACK)
		Game_mode = GM_NORMAL;

	if ( Player_is_dead )
		player_dead_message();
}
예제 #3
0
파일: draw.c 프로젝트: mbrown1413/asteroids
/**
 * draw_all
 * The master draw function that draws everything.
 */
void draw_all(Game* game) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    draw_hud(game);
    draw_objects(game);
    draw_zoom_square(game, game->screen_width);

    glFlush();
    glutSwapBuffers();

}
예제 #4
0
void Application::render() {
  update_gl_camera();
  switch (mode) {
    case EDIT_MODE:
      if (show_coordinates) draw_coordinates();
      scene->render_in_opengl();
      if (show_hud) draw_hud();
      break;
    case VISUALIZE_MODE:
      if (show_coordinates) draw_coordinates();
    case RENDER_MODE:
      pathtracer->update_screen();
      break;
  }
}
예제 #5
0
파일: playstate.cpp 프로젝트: walle/exoudus
void cPlaystate::run()
{
    if(paused == false)
    {
        pBackground->draw_scroll();
        if(gameover == false && quitting == false)
        {
            manage_enemies();
            manage_player();
            draw_hud();
        }
    }
    if(paused == true) { pause.draw( screen ); }
    if(gameover == true) { over.draw( screen ); }
    if(quitting == true) { quit.draw(screen); }
    explotion.drawOnce(screen);
    framerate.process();
    SDL_Flip(screen);
}
예제 #6
0
void draw_ingame_menu(MenuData *menu) {	
	glPushMatrix();
		glTranslatef(VIEWPORT_X, VIEWPORT_Y, 0);
	
	draw_ingame_menu_bg(1.0-menu_fade(menu));
	
	glPushMatrix();
	glTranslatef(VIEWPORT_W/2, VIEWPORT_H/4, 0);
		
	draw_menu_selector(0, menu->drawdata[0], menu->drawdata[1]/45.0, 0.25, menu->frames);
	
	menu->drawdata[0] += (menu->cursor*35 - menu->drawdata[0])/7.0;
	menu->drawdata[1] += (strlen(menu->entries[menu->cursor].name)*5 - menu->drawdata[1])/10.0;
	
	if(menu->context) {
		float s = 0.3 + 0.2 * sin(menu->frames/10.0);
		glColor4f(1-s/2, 1-s/2, 1-s, 1-menu_fade(menu));
		draw_text(AL_Center, 0, -2 * 35, menu->context, _fonts.standard);
	}
	
	int i;
	for(i = 0; i < menu->ecount; i++) {
		if(menu->entries[i].action) {
			float s = 0, t = 0.7;
			if(i == menu->cursor) {
				t = 1;
				s = 0.3 + 0.2*sin(menu->frames/7.0);
			}
			
			glColor4f(t-s,t-s,t-s/2, 1-menu_fade(menu));
		} else
			glColor4f(0.5, 0.5, 0.5, 0.5);
		
		draw_text(AL_Center, 0, i*35, menu->entries[i].name, _fonts.standard);
	}
		
	glColor4f(1,1,1,1);
	glPopMatrix();
	glPopMatrix();
	
	draw_hud();
}
예제 #7
0
void game_draw_hud_stuff()
{
#ifdef CROSSHAIR
	if ( Viewer->type == OBJ_PLAYER )
		laser_do_crosshair(Viewer);
#endif
	
#ifndef NDEBUG
	draw_window_label();
#endif
	
#ifdef NETWORK
	game_draw_multi_message();
#endif
	
	if ((Newdemo_state == ND_STATE_PLAYBACK) || (Newdemo_state == ND_STATE_RECORDING)) {
		char message[128];
		int y;
		
		if (Newdemo_state == ND_STATE_PLAYBACK) {
			if (Newdemo_show_percentage) {
			  	sprintf(message, "%s (%d%%%% %s)", TXT_DEMO_PLAYBACK, newdemo_get_percent_done(), TXT_DONE);
			} else {
				sprintf (message, " ");
			}
		} else {
			extern int Newdemo_num_written;
			sprintf (message, "%s (%dK)", TXT_DEMO_RECORDING, (Newdemo_num_written / 1024));
		}
		
		gr_set_curfont( GAME_FONT );
		gr_set_fontcolor( BM_XRGB(27,0,0), -1 );
		
		y = GHEIGHT-(LINE_SPACING*2);
		
		if (PlayerCfg.CockpitMode[1] == CM_FULL_COCKPIT)
			y = grd_curcanv->cv_bitmap.bm_h / 1.2 ;
		if (PlayerCfg.CockpitMode[1] != CM_REAR_VIEW)
			gr_printf(0x8000, y, message );
	}
	
	render_countdown_gauge();
	render_spec_status();	// jinx 02-01-13 spec
	
	// this should be made part of hud code some day
	if (( Player_num > -1 && Viewer->type==OBJ_PLAYER && Viewer->id==Player_num && PlayerCfg.CockpitMode[1] != CM_REAR_VIEW) || ((Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) && in_free))
	{
		int	x = FSPACX(1);
		int	y = grd_curcanv->cv_bitmap.bm_h;
		
		gr_set_curfont( GAME_FONT );
		gr_set_fontcolor( BM_XRGB(0, 31, 0), -1 );
		if ((Cruise_speed > 0) || ((Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) && in_free)) {
			if (PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN) {
				if (Game_mode & GM_MULTI)
					y -= LINE_SPACING * 10;
				else
					y -= LINE_SPACING * 6;
			} else if (PlayerCfg.CockpitMode[1] == CM_STATUS_BAR) {
				if (Game_mode & GM_MULTI)
					y -= LINE_SPACING * 6;
				else
					y -= LINE_SPACING * 1;
			} else {
				if (Game_mode & GM_MULTI)
					y -= LINE_SPACING * 7;
				else
					y -= LINE_SPACING * 2;
			}
			if (Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING)
				gr_printf( x, y, "Free Fly Speed %2d%%", 100 + f2i((Cruise_speed)));		// f2i(100 + (Cruise_speed / SPEC_SPEED_MOD)));
			else
				gr_printf( x, y, "%s %2d%%", TXT_CRUISE, f2i(Cruise_speed) );	
		}
	}
	
	if (GameCfg.FPSIndicator && PlayerCfg.CockpitMode[1] != CM_REAR_VIEW)
		show_framerate();

	if (Newdemo_state == ND_STATE_PLAYBACK)
		Game_mode = Newdemo_game_mode;

	draw_hud();

	if (Newdemo_state == ND_STATE_PLAYBACK)
		Game_mode = GM_NORMAL;
	
	if ( Player_is_dead )
		player_dead_message();
}
예제 #8
0
//Draw the world and all objects
void Game::drawScene(){
	static float hlt_rate = 0.01;		// opacity rate for highlights
	static float hlt =  0.4;			// opacity for highlights
	world.display(camera.get_pos());	// Draw the map

	// Draw fish in the water
	glColor3f(0,0.1,0.2);
	glPushMatrix();
		glTranslatef(0,-1,0);
		bird_system[0].display(dt, camera.get_pos());
	glPopMatrix();

	// Draw birds in the sky
	glColor3f(1,1,1);
	bird_system[1].display(dt, camera.get_pos());

	// Draw water
	glColor4ub(89,173,237,200);
	water_system.display(dt);
	draw_still_water();
	
	glDisable(GL_FOG);
	
	glEnable(GL_FOG);

	glDisable(GL_LIGHTING);

	// Draw the highlight around the selected unit
	glPointSize(4);
	if( current.is_traversable() ){
		vector3f p = current.get_wpos();
		glColor4f(0,0,1,hlt);
		draw_hilite(p);
	}

	// Draw the target around the target tile or unit
	if( target.is_traversable() ){
		vector3f p = target.get_wpos();
		glColor4f(1,0,0,hlt);
		draw_target(p);
	}

	// Draw the highlights for the possible movement area
	if( move_area.size() > 0 ){
		glColor4ub(255,0,93,255*hlt);
		for (int i = 0; i < move_area.size(); ++i){
			vector3f p = move_area[i].get_wpos();
			draw_hilite(p);
		}
	}

	// Draw the hilights for the movement path
	if( move_path.size() > 0 ){
		glColor4f(0,0,1,hlt);
		for (int i = 1; i < move_path.size(); ++i){
			vector3f p = move_path[i].get_wpos();
			draw_hilite(p);
		}
	}

	hlt += hlt_rate;
	if( hlt < 0.4 || hlt > 0.75)
		hlt_rate *= -1;

	draw_skybox();

	glEnable(GL_LIGHTING);
	
	// Draw all the units
	for (int i = 0; i < units.size(); ++i){
		if( units[i].get_team() == 0 )
			glColor3f(0.3,0.3,0.3);
		else
			glColor3f(0.7,0.7,0.7);
		units[i].display(dt,camera.get_pos());	
	}

	draw_hud();
}
예제 #9
0
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;
} 
예제 #10
0
파일: si.c 프로젝트: RastaCat/EssiInvaders
//Main program
int main() {
	
	/* Initialize SDL’s video system and check for errors */
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {

		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
	
	/* Make sure SDL_Quit gets called when the program exits! */
	atexit(SDL_Quit);
	
	/*set window title*/
	SDL_WM_SetCaption("Essi Invaders", "P");
	
	/* Attempt to set a 800x600 8 bit color video mode */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 8, SDL_DOUBLEBUF );
	
	if (screen == NULL) {
		
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	//load images
	load_image("titlescreen.bmp", &title_screen, magenta);
	load_image("cmap.bmp", &cmap, magenta);
	load_image("target1.bmp", &invaders_img[0], magenta);
	load_image("target2.bmp", &invaders_img[1], magenta);
	load_image("target3.bmp", &invaders_img[2], magenta);
	load_image("target4.bmp", &invaders_img[3], magenta);
	load_image("target5.bmp", &invaders_img[4], magenta);
	load_image("target6.bmp", &invaders_img[5], magenta);
	load_image("target7.bmp", &invaders_img[6], magenta);
	load_image("target8.bmp", &invaders_img[7], magenta);
	load_image("target9.bmp", &invaders_img[8], magenta);
	load_image("target10.bmp", &invaders_img[9], magenta);
	load_image("target11.bmp", &invaders_img[10], magenta);
	load_image("target12.bmp", &invaders_img[11], magenta);
	load_image("spaceship.bmp", &player_img, magenta);
	load_image("essi.bmp", &logo_img, magenta);
	load_image("saucer.bmp", &saucer_img, magenta);
	load_image("gameover.bmp", &game_over_img, magenta);
	load_image("damage.bmp", &damage_img, lime);
	load_image("damagetop.bmp", &damage_top_img, lime);

	Uint32 next_game_tick = SDL_GetTicks();
	int sleep = 0;
	Uint8 *keystate = 0;
	int quit = 0;
	SDL_Event event;

	init_score();
	init_bases();
	init_misil();
	init_invaders();
	init_player();
	init_saucer();
	init_bullets(bullets, P_BULLETS);
	init_bullets(enemy_bullets, E_BULLETS);
	state = menu;
	title_time = SDL_GetTicks();
		
	/* Animation */
	while (quit == 0) {
		
		/* Grab a snapshot of the keyboard. */
		keystate = SDL_GetKeyState(NULL);
		
		while (SDL_PollEvent(&event)) {

			switch(event.type) {
				
				case SDL_KEYDOWN:
					
					switch( event.key.keysym.sym ) {
					
						//exit out of game loop if escape is pressed
						case SDLK_ESCAPE:
							
							quit = 1;
						break;
						
						case SDLK_SPACE:	
						
							if (state == menu) {

								state = game;

							} else if (state == game){
								
								player_shoot();
								saucer_ai();
							
							} else if (state == game_over) {
							
								init_invaders();
								init_bases();
								init_score();
								init_player();
								state = game;
								match = -1;
							}
						break;
						
						default:
						break;
					}
				break;
				
				case SDL_KEYUP:
					switch( event.key.keysym.sym ) {
						
						case SDLK_UP:
							
							move_misil(up);
						break;
						
						case SDLK_DOWN:	
						
							move_misil(down);
						break;
						
						default:
						break;
					}
			}
		}
	
		draw_background();

		if (state == menu) {
			
			char s[] = "Press SPACEBAR to start";
			SDL_Rect src[60];
			
			int i;

			if (title_time + 2000 < SDL_GetTicks())  {
			
				src[0].x = (SCREEN_WIDTH/100)*30;		//Yellow Background of Space Invaders
				src[0].y = 40;
				src[0].w = 440;
				src[0].h = 230;
			
				SDL_FillRect(screen, &src[0], 248);
			
			} else {
			
				int y = 0;

				for (i = 0; i < 60; i++) {
				
					src[i].x = 0;
					src[i].y = y;
					src[i].w = SCREEN_WIDTH;
					src[i].h = 10;

					SDL_FillRect(screen, &src[i], 227);
				
					y += 10;							
				}
			
				for (i = 0; i < 60; i++) {

					SDL_FillRect(screen, &src[i], rand() % 255);

				}
			}
			
			draw_title_screen();	
			draw_string(s, (SCREEN_WIDTH / 2) - (strlen(s) * 10), 500);

		} else if (state == game) {

			//move player
			if (keystate[SDLK_LEFT]) {
				
				move_player(left);
			}

			if (keystate[SDLK_RIGHT]) {
				
				move_player(right);
			}
			
			draw_hud();
			draw_player();
			draw_bases();
			draw_invaders();
			draw_saucer();
			draw_serviceProjectMatch(match);
			draw_bullets(bullets, P_BULLETS);
			draw_bullets(enemy_bullets, E_BULLETS);
			enemy_hit_collision();
			player_hit_collision();
			enemy_base_collision();
			saucer_hit_collision();
			bullet_base_collision(enemy_bullets, E_BULLETS, 1);
			bullet_base_collision(bullets, P_BULLETS, 0);
			enemy_player_collision();
			move_invaders(invaders.speed);
			move_saucer();
			movenemy_bullets(bullets, P_BULLETS, -30);
			movenemy_bullets(enemy_bullets, E_BULLETS, 15);
			calculate_level();
			enemy_ai();
			game_over_ai();
			pause_game();
		
		} else if (state == game_over) {
			
			draw_hud();
			draw_player();
			draw_bases();
			draw_invaders();
			draw_saucer();
			draw_bullets(bullets, P_BULLETS);
			draw_bullets(enemy_bullets, E_BULLETS);
			draw_game_over();
		
		} else if (state == pause) {
			
			draw_hud();
			draw_player();
			draw_bases();
			draw_invaders();
			draw_saucer();
			draw_bullets(bullets, P_BULLETS);
			draw_bullets(enemy_bullets, E_BULLETS);
			pause_game();
		}

		/* Ask SDL to update the entire screen. */
		SDL_Flip(screen);

		next_game_tick += 1000 / 30;
		sleep = next_game_tick - SDL_GetTicks();
	
		if( sleep >= 0 ) {

            		SDL_Delay(sleep);
        	}
	}
	
	return 0;
}
예제 #11
0
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;
} 
예제 #12
0
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();
}