Ejemplo n.º 1
0
/* initialises all the positions and rotations of ship*/
void initAllShips(void)
{
	GLOBAL_Translate initialTranslateShip_1 = {ZERO, ZERO, SHIP_1_INTIAL_Z_POSITION}; /* declared in ship.h */
	GLOBAL_Translate initialTranslateShip_2 = {ZERO, ZERO, SHIP_2_INTIAL_Z_POSITION}; /* declared in ship.h */

	initShip(mesh_1, &directionKeys_ship_1, &initialTranslateShip_1, &translateShip_1, 
				&rotateShip_1, &scaleShip_1, &speed_ship_1, colour.red);
	initShip(mesh_2, &directionKeys_ship_1, &initialTranslateShip_2, &translateShip_2, 
				&rotateShip_2,&scaleShip_2, &speed_ship_2, colour.green);
}
Ejemplo n.º 2
0
int main() {
   int gameRunning = TRUE;
   clock_t start = clock();
   int fps = 2;
   double timestep = (double) 1 / fps;
   initShip();
   initCenario();
   /*a ideia eh usarmos algo com o timestep e sair quando o usuario
    * entrar com EOF ou com Q/<Insira uma letra de preferencia>*/
   while (gameRunning)
   { 
     clock_t now = clock();
     if (((double) (now - start)) >= timestep)
     {
       gameRunning = update();
       if (ship->vidas == 0) gameRunning = FALSE;
       imprimeCenario();
       start = now; 
     }

   }
     freeShip();
     freeCenario();
   printf("Fim de execucao!\n");
   return 0;
}
Ejemplo n.º 3
0
void initGame(int stg) {
  status = IN_GAME;

  initShip();
  initShots();
  initFoes();
  initFrags();
  initBonuses();
  initBackground();

  initBarrages(stagePrm[stg][0], stagePrm[stg][1], stagePrm[stg][2]);
  initGameState(stg);
  if ( stg < STAGE_NUM ) {
    setStageBackground(stg%5+1);
    playMusic(stg%5+1);
  } else {
    if ( !insane ) {
      setStageBackground(0);
      playMusic(0);
    } else {
      setStageBackground(6);
      playMusic(6);
    }
  }
}
Ejemplo n.º 4
0
// Game initialization function
// ==========================================================
void init(void) {

	// init random seed
	unsigned int seed = time(NULL);
	srand(seed);
	
	// Init asteroid object array
	asteroids = (object *)malloc(sizeof(object)*MAXASTEROIDS);
	int i;
	for(i=0;i<MAXASTEROIDS;i++) {

		// Create an asteroid at a random location on screen
		vector p = makeVec(10.0-(float)(rand()%25), 10.0-(float)(rand()%25));
		initAsteroid(asteroids+i, &p, 3.0);

		// If asteroid spawns too close to ship, make it somewhere else
		while(lengthVec(&(asteroids[i].pos)) < 5.0) {
			p = makeVec(10.0-(float)(rand()%25), 10.0-(float)(rand()%25));
			initAsteroid(asteroids+i, &p, 3.0);
		}

		// Activate 4 big asteroids at the beginning
		if (i%4!=0) asteroids[i].state &= !ASTEROID_ACTIVE;
		else asteroids[i].state |= ASTEROID_BIG;
	}

	// Init asteroid gibs (inactive)
	asteroidGibs = (object**)malloc(sizeof(object*)*MAXASTEROIDS);
	int ab;
	for (ab=0; ab<MAXASTEROIDS; ab++) {
		asteroidGibs[ab] = (object*)malloc(sizeof(object)*asteroids[ab].size);
		initGib(asteroidGibs[ab], asteroids+ab, 0);
	}
	
	// init ship
	ships = malloc(sizeof(object)*MAXSHIPS);
	for (i = 0; i < MAXSHIPS; i++) {
		initShip(ships+i);
	}
	myship = ships;
	myship->state = 0;
	
	// init ship stuff
	//initMissile();	

	// init ship gibs (inactive)
	shipGibs = (object*)malloc(sizeof(object)*ships[0].size*MAXSHIPS);	
	for (i=0; i < MAXSHIPS; i++) {
		initGib(shipGibs+i*ships[0].size, ships, 0);
	}
	
	// init stars
	stars = (object*)malloc(sizeof(object)*MAXSTARS);
	int si; for(si=0;si<MAXSTARS; si++) {
		vector v =  makeVec((float)(rand()%50)-25.0, (float)(rand()%50)-25.0);
		initStar(stars+si, &v);
	}

}	
Ejemplo n.º 5
0
void
Game2D::
start (){
    init ();

    initShip ();

    initEnemy ();
}
Ejemplo n.º 6
0
void initTitle() {
  int stg;
  status = TITLE;

  stg = initTitleAtr();
  initBoss();
  initShip();
  initLasers();
  initFrags();
  initShots();
  initBackground(0);
  initTitleStage(stg);
  left = -1;
}
Ejemplo n.º 7
0
void initTitle() {
  int stg;
  status = TITLE;

  stg = initTitleAtr();
  initShip();
  initShots();
  initFrags();
  initBonuses();
  initBackground();
  setStageBackground(1);

  initTitleStage(stg);
}
Ejemplo n.º 8
0
int main(int argc, char **argv){
  forceField = FALSE;
  initShip();
  initCenario();
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
  glutInitWindowSize(900, 900); 
  glutCreateWindow("Nave");
  init();
  
  glutDisplayFunc(draw);
  glutTimerFunc(100, timeStep, 1);
  glutIgnoreKeyRepeat(TRUE);
  glutKeyboardFunc(keydown);
  glutKeyboardUpFunc(keyup);
  glutMainLoop();
  return 0;   
}
Ejemplo n.º 9
0
void initGame(int stg) {
  int sn;
  status = IN_GAME;

  initBoss();
  initFoes();
  initShip();
  initLasers();
  initFrags();
  initShots();

  initGameState(stg);
  sn = stg%SAME_RANK_STAGE_NUM;
  initBackground(sn);
  if ( sn == SAME_RANK_STAGE_NUM-1 ) {
    playMusic(rand()%(SAME_RANK_STAGE_NUM-1));
  } else {
    playMusic(sn);
  }
}
Ejemplo n.º 10
0
//prototype
int main(void){

	bool done = false;
	bool redraw = true;
	const int FPS = 60;
	bool isGameOver = false;
	
	//object variables
	spaceShip ship;
	Bullet bullets[NUM_BULLETS];
	Comet comets[NUM_COMETS];

	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *eventQueue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_FONT *font18 = NULL;

	

	
	//check if allegro is initialised <allegro_native_dialog.h>
	if(!al_init()){ 
		return -1;
	}

	display = al_create_display(WIDTH,HEIGHT);
	

	//check if display was created
	if(!display){
		return -1;
	}

	al_init_primitives_addon();
	al_install_keyboard();
	al_init_font_addon();
	al_init_ttf_addon();

	eventQueue = al_create_event_queue();
	timer= al_create_timer(1.0/FPS);

	srand(time(NULL)); // gives the rand() some value
	initShip(ship);
	initBullet(bullets, NUM_BULLETS);
	initComet(comets, NUM_COMETS);

	font18 = al_load_font("arial.ttf",18,0);
	
	al_register_event_source(eventQueue, al_get_keyboard_event_source());
	al_register_event_source(eventQueue, al_get_timer_event_source(timer));
	al_register_event_source(eventQueue, al_get_display_event_source(display)); //event os display resize closing, moving

	al_start_timer(timer);

	while(!done){
	
		ALLEGRO_EVENT ev;
		al_wait_for_event(eventQueue, &ev);

		if (ev.type==ALLEGRO_EVENT_TIMER){
			redraw=true;
			if(keys[UP]){
				moveShipUp(ship);
			}
			if(keys[DOWN]){
				moveShipDown(ship);
			}
			if(keys[LEFT]){
				moveShipLeft(ship);
			}
			if(keys[RIGHT]){
				moveShipRight(ship);
			}

			if(!isGameOver){
				updateBullet(bullets,NUM_BULLETS);
				startComet(comets, NUM_COMETS);
				updateComet(comets, NUM_COMETS);
				collideBullet(bullets,NUM_BULLETS, comets, NUM_BULLETS, ship);
				collideComet(comets, NUM_COMETS, ship);
			
				if (ship.lives <= 0){
					isGameOver = true;
				}
			}

			
		}
		// when clicling on red X icon to close the game
		else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
			done=true;
		
		}
		else if (ev.type==ALLEGRO_EVENT_KEY_DOWN){
			switch(ev.keyboard.keycode){
				case ALLEGRO_KEY_ESCAPE:
					done=true;
					break;
				case ALLEGRO_KEY_UP:
					keys[UP]=true;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[DOWN]=true;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[LEFT]=true;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[RIGHT]=true;
					break;
				case ALLEGRO_KEY_SPACE:
					keys[SPACE]=true;
					fireBullet(bullets, NUM_BULLETS, ship);
					break;
			}
		}
		else if (ev.type==ALLEGRO_EVENT_KEY_UP){
			switch(ev.keyboard.keycode){
				//make sure when exiting the program exit with esc button
				case ALLEGRO_KEY_ESCAPE:
					done=true;
					break;
				case ALLEGRO_KEY_UP:
					keys[UP]=false;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[DOWN]=false;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[LEFT]=false;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[RIGHT]=false;
					break;
				case ALLEGRO_KEY_SPACE:
					keys[SPACE]=false;
					break;
			}
		}
		if (redraw && al_is_event_queue_empty(eventQueue)){ // I only draw the screen if there no more event
			redraw=false;

			if(!isGameOver){			
				drawShip(ship);
				drawBullet(bullets,NUM_BULLETS);
				drawComet(comets, NUM_COMETS);

				al_draw_textf(font18, al_map_rgb(255,0,255), 5, 5, 0, "Player has %i lives left. Player has destroyed %i objects", ship.lives, ship.score);
			}
			else{
				al_draw_textf(font18, al_map_rgb(0,255,255),WIDTH / 2, HEIGHT / 2, ALLEGRO_ALIGN_CENTRE, "Game Over, Pal. Final Score: %i", ship.score);
			}

			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0)); //that prevents the filled rectangle draw imga just like snake style	
	
		}
		
		//make sure when exiting the program exit with esc button
		
		// when clicling on red X icon to close the game
		}

	//al_rest(5.0);
	al_destroy_display(display);
//hadouken

return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
  SDL_Surface *screen;
  if (argc > 1) {
    screen = gu_init_SDL("URS Ship Viewer", atoi(argv[1]));
  } else {
    screen = gu_init_SDL("URS Ship Viewer", 0);
  }
  gu_init_GL();
  gu_init_display(display);

  skuInitKeyBinder(&kb);
  skuBindKeyHandler(&kb, SDLK_BACKSPACE, reinitCam);
  skuBindKeyHandler(&kb, SDLK_UP, rotateUp);
  skuBindKeyHandler(&kb, SDLK_DOWN, rotateDown);
  skuBindKeyHandler(&kb, SDLK_LEFT, rotateLeft);
  skuBindKeyHandler(&kb, SDLK_RIGHT, rotateRight);
  skuBindKeyHandler(&kb, SDLK_z, zoom);
  skuBindKeyHandler(&kb, SDLK_s, dezoom);
  skuBindKeyHandler(&kb, SDLK_q, left);
  skuBindKeyHandler(&kb, SDLK_d, right);

  camInit(&camera);

  gu_initLights();

  GLfloat whiteLight[4] = {1, 1, 1, 1};
  GLfloat blackLight[4] = {0, 0, 0, 1};
  glLightfv(GL_LIGHT0, GL_AMBIENT, blackLight);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);

  glMatrixMode(GL_PROJECTION);
  gluPerspective(50, (float) screen->w / screen->h, 1, 10000);
  glMatrixMode(GL_MODELVIEW);
  reinitCam();

  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  initShip(&ship, 0, 0, 0);
  initSun(&sun, 0, 30, 30, 3, 0, 0, 0, 0);
  GLuint texDesc;
  gu_initTextures(&texDesc, 1, 1, "space.png");
  initSpace(&space, 0, 0, 0, 10, 0, 0, texDesc, 10);

  continuer = 1;
  SDL_Event event;

  Uint32 startTime;
  Uint32 ellapsedTime = 0;
  int frameNb = 0;

  //Boucle principale
  while (continuer) {
    
    //Les FPS
    startTime = SDL_GetTicks();
    if (ellapsedTime >= 1000) {
      printf("\r~%d fps", frameNb);
      fflush(stdout);
      ellapsedTime = 0;
      frameNb = 0;
    }

    //Les events
    while (SDL_PollEvent(&event)) {
      eventCatcher(&event);
    }
    skuHandle(&kb);
    gu_display();
    frameNb++;

    ellapsedTime += SDL_GetTicks() - startTime;
  }
  //C'est finit, libération des ressources
  printf("\n");
  gu_SDLQuit(1);
  exit(EXIT_SUCCESS);
}
//prototype
int main(void){

	bool done = false;
	bool redraw = true;
	const int FPS = 60;

	//object variables
	spaceShip ship;
	Bullet bullets[5];

	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *eventQueue = NULL;
	ALLEGRO_TIMER *timer = NULL;

	
	//check if allegro is initialised <allegro_native_dialog.h>
	if(!al_init()){ 
		return -1;
	}

	display = al_create_display(WIDTH,HEIGHT);
	

	//check if display was created
	if(!display){
		return -1;
	}

	al_init_primitives_addon();
	al_install_keyboard();
	//to capture keyboard events
	eventQueue = al_create_event_queue();
	timer = al_create_timer(1.0 / FPS);


	initShip(ship);
	initBullet(bullets,NUM_BULLETS);

	//register the keyboard to eventQueue
	al_register_event_source(eventQueue,al_get_keyboard_event_source());
	al_register_event_source(eventQueue,al_get_timer_event_source(timer));
	al_register_event_source(eventQueue,al_get_display_event_source(display));

	al_start_timer(timer);

	while(!done){
		ALLEGRO_EVENT ev;
		al_wait_for_event(eventQueue,&ev);
		if(ev.type == ALLEGRO_EVENT_TIMER){
			redraw=true;

			if(keys[UP]){
				moveShipUp(ship);
			}
			if(keys[DOWN]){
				moveShipDown(ship);
			}
			if(keys[LEFT]){
				moveShipLeft(ship);
			}
			if(keys[RIGHT]){
				moveShipRight(ship);
			}

			updateBullet(bullets,NUM_BULLETS);
		
		}
		else if(ev.type  == ALLEGRO_EVENT_DISPLAY_CLOSE){
			done=true;
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_DOWN){
			switch(ev.keyboard.keycode){
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = true;
				fireBullet(bullets, NUM_BULLETS, ship);
				break;

			}
		}

		else if(ev.type == ALLEGRO_EVENT_KEY_UP){
			switch(ev.keyboard.keycode){
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE] = false;
				break;
			}
		}

		if(redraw && al_is_event_queue_empty(eventQueue)){
			redraw = false;
			drawShip(ship);
			//without updating the bullets they will be only create a static spot in the screen, limited to n number of bullets
			drawBullet(bullets,NUM_BULLETS);
			// when clicling on red X icon to close the game
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0)); //that prevents the filled rectangle draw imga just like snake style	
		}
		//make sure when exiting the program exit with esc button
		
		}

	//al_rest(5.0);
	al_destroy_display(display);
//hadouken

return 0;
}