Exemple #1
0
int main( int argc, char* argv[] )
{
  //Initialisieren
    ZWattribute=ZWgetattribute();
    load_options();
    ZWinitparameter();
    ZWattribute->strech=stretched;
    if (fullscreen)
    {
      ZWattribute->width=resolutionx;
      ZWattribute->height=resolutiony;
      ZWattribute->sdlflags|=SDL_FULLSCREEN;
    }
    else
    {
      ZWattribute->width=windowx;
      ZWattribute->height=windowy;
    }
    ZWattribute->quit_function=quit_function;
    ZWattribute->initflags|=SDL_INIT_AUDIO;
		
		load_mapping();
		
    ZWinitsdl();
    
    int audio_rate = 44100;
    Uint16 audio_format = AUDIO_S16SYS; 
    int audio_channels = 2;
    int audio_buffers = 2048;
    if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
    {
      printf("Unable to open audio!\n");
      exit(1);
   }
    
    if ((ZWattribute->sdlflags & SDL_FULLSCREEN)==0) //SDL_FULLSCREEN nicht mehr gesetzt? AAAAHHHH!
    {
      fullscreen=0;
      windowx=ZWattribute->width;
      windowy=ZWattribute->height;
      resolutionx=ZWattribute->resolution[0].x;
      resolutiony=ZWattribute->resolution[0].y;
    }
    ZWinitopengl();    
    setup_opengl();
    glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST);
    init_var();
        
  //Level laden
    if (argc<2)
    {
      printf("Not enough arguments\n");
      printf("testboard file.opxml [player]\n");
      ZWquitfont();
      ZWquitsdl();      
      return 1;
    }
    if (loadlevel(argv[1])==1)
    {
      printf("File %s not found\n",argv[1]);
      ZWquitfont();
      ZWquitsdl();   
      return 1;
    }  
    refreshsetlist();

  //Minispielliste laden
	  load_minigames();
		save_minigames();

  /*//zu Debugzwecken Set 0 bis 60 ausgeben:
  for (int a=0;a<61;a++)
  {
    if (setbynr[a]==NULL)
      printf("Set %i: NULL\n",a);
    else
      printf("Set %i: \"%s\"\n",a,setbynr[a]->type);  
  }*/

  //Debug
    if (argc>3 && argv[3][0]=='c')
      all_are_cpu=1;

  //Spielvorbereitungen
    if (argc>2)
      playernum=atoi(argv[2]);
    playernum=(playernum-1)%8+1;

		
		if (argc>3 && argv[3][1]=='2')
		{
			playernum=((playernum+1)/2)*2;
			if (playernum<4)
			  playernum=4;
			teamsize=2;
		}
		if (argc>3 && argv[3][1]=='3')
		{
			playernum=6;
			teamsize=3;
		}
		if (argc>3 && argv[3][1]=='4')
		{
			playernum=8;
			teamsize=4;
		}		

    pset startset=getsetbyname((char*)"start");
    if (startset==NULL) startset=firstset;
		prepare_game(startset,1);
		
    
  ZWreset_virtuell_joytick();
  //Controller festlegen:
  for (int a=0;a<playernum;a++)
  {
		if (all_are_cpu)
		  maindata.player[a].joystick_nr=-1;
		else		  
		  maindata.player[a].joystick_nr=a%ZWattribute->realjoystickcount;
  }
	calib_all_controllers();
  //Spiel starten
    Mix_FadeInMusic(backgroundmusic, -1,FADE_IN_TIME);
    ZWattribute->newticks=SDL_GetTicks();
    ZWschleifeex((void(*)(void*))draw_main,(int(*)(void*))calc_main_thread,(int(*)(void*))calc_main,
                 (void*)(&maindata),sizeof(tmaindata));    
    Mix_HaltMusic();
  //alles wieder freigeben
    reset_after_game();
    del_objects();
    del_sounds();
    Mix_CloseAudio();
    ZWquitfont();
    ZWquitsdl();
  return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{	
	char input = 0;
	char save_name[50];


	//Prepare engine
	Engine *engine = prepare_game(save_name);

	GoF_Screen *screen = screen_create(0, 0, 30, 30, 20);
	Graphics g;
	graphics_init(&g, 800, 900, "The Game of Life!");

	input = 0;
	while(input != 'k')
	{
		screen_draw(screen, &g, engine);
		input = graphics_event(&g);

		if(input == 1)
			engine_add_entity(engine, entity_create(g.last_x/screen->entity_length, g.last_y/screen->entity_length));
		else if(input == 3)
			engine_remove_entity(engine, g.last_x/screen->entity_length, g.last_y/screen->entity_length);
	}

	//Input
	input = 0;
	int sens = 5;

	//Main game loop
	while(input != 'q')
	{	
		//Draw on screen
		screen_draw(screen, &g, engine);

		//Update Engine
		engine_update(engine);
		
		//Process input
		while(graphics_check_event(&g))
		{
			input = graphics_event(&g);
			switch(input)
			{
				case 'p':
					engine->ups++;
					break;
				case 'm':
					if(engine->ups > 1)
						engine->ups--;
					break;
				case '.':
					sens++;
					break;
				case ',':
					if(sens > 1)
						sens--;
					break;
				case UP_ARROW:
					screen->y -= sens;
					break;
				case DOWN_ARROW:
					screen->y += sens;
					break;
				case LEFT_ARROW:
					screen->x -= sens;
					break;
				case RIGHT_ARROW:
					screen->x += sens;
					break;
			}
		}

		//Sleep
		usleep((1000/engine->ups) * 1000);
	}

	//Close graphics
	graphics_close(&g);

	//Save game
	printf("Saving game...\n");
	engine_save(engine, save_name);

	//Free mem
	engine_free(engine);
	screen_free(screen);

	return 0;
}