예제 #1
0
파일: game.c 프로젝트: noox/Raketka
//inicializacni funkce pri zacatku hry
void init_game() {
	//pocatecni pozice, rychlost a hp raketky
	posx=0;
	posy=-300;
	speedx=speedy=0;
	hp=1;

	//hrac muze hned strilet
	reload=0;
	
	//promenne pro zachovani hlavnich statistik hry
	level=0;
	plevel=0;
	score=0;

	//na zacatku hrac zije
	playerdead=0; 
	
	//cas od smrti hrace nakonci
	deathtimer=0;
	
	//trvani bonusu
	shieldtimer=0;
	canontimer=0;
	
	init_stars();
	init_bullets();
	init_enemies();
	init_particles();
	init_bonuses();
}
예제 #2
0
파일: main.c 프로젝트: dradtke/battlechess
/* the main game function */
static int play_game()
{ 
   ALLEGRO_TIMER *inc_counter;
   int gameover = 0;
   int cyclenum = 0;

   /* init */
   score = 0;

   init_view();
   init_player();
   init_badguys();
   init_bullets();
   init_explode();
   init_message();

   #define TIMER_SPEED  ALLEGRO_BPS_TO_SECS(30*(cyclenum+2))

   inc_counter = al_create_timer(TIMER_SPEED);
   al_start_timer(inc_counter);

   while (!gameover) {

      /* move everyone */
      while ((al_get_timer_count(inc_counter) > 0) && (!gameover)) {
	 update_view();
	 update_bullets();
	 update_explode();
	 update_message();

	 if (update_badguys()) {
	    if (advance_view()) {
	       cyclenum++;
	       al_set_timer_count(inc_counter, 0);
	       lay_attack_wave(TRUE);
	       advance_player(TRUE);
	    }
	    else {
	       lay_attack_wave(FALSE);
	       advance_player(FALSE);
	    }
	 }

	 gameover = update_player();

	 al_set_timer_count(inc_counter, al_get_timer_count(inc_counter)-1);
      }

      /* take a screenshot? */
      if (key[ALLEGRO_KEY_PRINTSCREEN]) {
	 static int ss_count = 0;

	 char fname[80];

	 sprintf(fname, "speed%03d.tga", ++ss_count);

	 al_save_bitmap(fname, al_get_backbuffer(screen));

	 while (key[ALLEGRO_KEY_PRINTSCREEN])
	    poll_input_wait();

	 al_set_timer_count(inc_counter, 0);
      }

      /* toggle fullscreen window */
      if (key[ALLEGRO_KEY_F]) {
         int flags = al_get_display_flags(screen);
         al_set_display_flag(screen, ALLEGRO_FULLSCREEN_WINDOW,
            !(flags & ALLEGRO_FULLSCREEN_WINDOW));

         while (key[ALLEGRO_KEY_F])
            poll_input_wait();
      }

      /* draw everyone */
      draw_view();
   }

   /* cleanup */
   al_destroy_timer(inc_counter);

   shutdown_view();
   shutdown_player();
   shutdown_badguys();
   shutdown_bullets();
   shutdown_explode();
   shutdown_message();

   if (gameover < 0) {
      sfx_ping(1);
      return FALSE;
   }

   return TRUE;
}
예제 #3
0
파일: game.c 프로젝트: evktalo/overgod
void begin_game(void)
{
 int i;

 counter = 0;

 init_structs_etc();

 for (i = 0; i < NO_ACTORS; i ++)
 {
  actor[i].in_play = 0;
 }

 player[0].score = 0;
 player[1].score = 0;

 if (game.type == GAME_SINGLE || game.type == GAME_TIME_ATTACK)
 {
  game.users = 1;

  actor[0].in_play = 0;
  player[game.single_player].actor_controlled = 0;
//  player[0].ships_left = 3;
  game.ships_left = 3;
  actor[0].controller = game.single_player;
  init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP);
 }

 if (game.type == GAME_COOP || game.type == GAME_DUEL || game.type == GAME_TIME_ATTACK_COOP)
 {
    game.users = 2;

    actor[0].in_play = 0;
    player[0].actor_controlled = 0;
//    player[0].ships_left = 3;
    actor[0].controller = 0;
    init_actor(0, player[0].ship); //ACTORTYPE_SHIP);
 
    actor[1].in_play = 0;
    player[1].actor_controlled = 1;
//    player[1].ships_left = 3;
    actor[1].controller = 1;
    init_actor(1, player[1].ship); //ACTORTYPE_SHIP);
    game.ships_left = 6;
 }
 
   
 init_bullets();
 init_clouds();
// init_stars();
 init_enemies();
 prepare_display();

 game.drag = 0.013;//955;//9999;
/*
 arena.max_x = 894000;
 arena.max_y = 895000;
*/

 arena.level = 0;
 game.symbols_given = 0;

 init_level();

 long_slacktime = 0;
 arena.waver_on_level = 0;

}
예제 #4
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;
}
예제 #5
0
파일: game.c 프로젝트: evktalo/lacewing
void begin_game(void)
{
 int i;

 counter = 0;

 init_structs_etc();

 for (i = 0; i < NO_ACTORS; i ++)
 {
  actor[i].in_play = 0;
 }

 player[0].score = 0;
 player[1].score = 0;

 if (game.type == GAME_SINGLE)
 {
  game.users = 1;

  actor[0].in_play = 0;
  player[game.single_player].actor_controlled = 0;
//  player[0].ships_left = 3;
  game.ships_left = 3;
  actor[0].controller = game.single_player;
  init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP);
 }
  else
   {
    game.users = 2;

    actor[0].in_play = 0;
    player[0].actor_controlled = 0;
//    player[0].ships_left = 3;
    actor[0].controller = 0;
    init_actor(0, player[0].ship); //ACTORTYPE_SHIP);
 
    actor[1].in_play = 0;
    player[1].actor_controlled = 1;
//    player[1].ships_left = 3;
    actor[1].controller = 1;
    init_actor(1, player[1].ship); //ACTORTYPE_SHIP);
    game.ships_left = 6;
   }
   
 init_bullets();
 init_clouds();
 init_enemies();
 prepare_display();

 game.drag = 0.013;//955;//9999;
/*
 arena.max_x = 894000;
 arena.max_y = 895000;
*/

 arena.level = 0;

 init_level();


}