Пример #1
0
int main(){

	//setup window
	sf::RenderWindow window;
	window.create(sf::VideoMode(800,600),"Game");
	window.setFramerateLimit(30);
	window.setVerticalSyncEnabled(true);
	sf::Sprite mainSprite;
	Game game;
	mode = 0;
	sf::Texture text;
	if(!text.loadFromFile("images/titleScreen.png"))
		std::cout << "ERROROROROROR" << std::endl;
	

	mainSprite.setTexture(text);
	//Game loop

	//startGame();
	while(window.isOpen()){
		window.clear();
		sf::Event event;
		while(window.pollEvent(event)){
			if(event.type == sf::Event::Closed){
				game.output.close();
				window.close();
			}
			switch(mode){
			case 1:
				game.pollGame(event,&window);
				break;
			case 0:	
				pollMenu(&event, &window);
				break;
			}
		}
		switch(mode){
		case 1:
			game.runGame(&window);
			break;
		case 0:	
			runMenu(&window, &mainSprite);
			break;
		}
		
		window.display();
	}//End of Game loop
	return 0;
}
Пример #2
0
int mythplugin_config(void)
{
    //TODO do we need this here?
    loadMusic();

    gMusicData->paths = gCoreContext->GetSetting("TreeLevels");
    gMusicData->startdir = gCoreContext->GetSetting("MusicLocation");
    gMusicData->startdir = QDir::cleanPath(gMusicData->startdir);

    if (!gMusicData->startdir.endsWith("/"))
        gMusicData->startdir += "/";

    Metadata::SetStartdir(gMusicData->startdir);

    Decoder::SetLocationFormatUseTags();

    return runMenu("music_settings.xml");
}
Пример #3
0
void runGameState(GameVars* gameVars)
{
    //Game State manager
    switch (gameVars->gameState) {
        
        //Title screen
        case GSTitle:
        {
            runTitle(gameVars);
        }
            break;
        
        //Menu screen
        case GSMenu:
        {
            runMenu(gameVars);
        }
            break;
            
        case GSCredits:
        {
            runCredits(gameVars);
        }
            break;
            
        //Game engine
        case GSGameStart:
        case GSWaitForServe:
        case GSPlay:
        case GSScored:
        case GSGameOver:
        {
            runGameplay(gameVars);
        }
            break;
            
        default:
            break;
    }
}
Пример #4
0
int mythplugin_run(void)
{
    return runMenu("musicmenu.xml");
}
Пример #5
0
int mythplugin_config(void)
{
    Decoder::SetLocationFormatUseTags();

    return runMenu("music_settings.xml");
}
Пример #6
0
int main(int argc, char *argv[])
{
  int doScale=0; // 0=Undefined, 1=320x240, -1=OpenGL, >1=SwScale
  char* dumpPack=NULL;
  int state=1; //Game, Menu, Editor, Quit
  int sdlVideoModeFlags = SDL_SWSURFACE;

  #ifdef PSP
    //Note to PSP porter, please test if HW is actually faster, Wizznic does a lot of memory-manipulation in the screen-surface, each call might initiate a full copy back/forth from video memory. Remove comment when read. :)
    sdlVideoModeFlags = (SDL_HWSURFACE | SDL_DOUBLEBUF |SDL_HWACCEL);
    SetupCallbacks();//Callbacks actifs
    scePowerSetClockFrequency(333,333,166);
  #endif

//  #ifdef WIN32
//Redirect stdout to console on windows, so we can see what's going in.
//  FILE *stream;
//  stream = freopen("CON", "w", stdout);
//  #endif

  //Print welcome message
  printf( "Wizznic "VERSION_STRING". GPLv3 or newer Copyleft 2010-2013\n\n");

  //initialize path strings
  initUserPaths();

  //Tell where stuff's at.
  printf("Directories:\n    Settings: %s\n    DLC: %s\n    Highscores: %s\n    Editorlevels: %s\n    Datafiles: %s\n\n", \
                            getConfigDir(), getUsrPackDir(), getHighscoreDir(), getUserLevelDir(), (!strlen(DATADIR))?".":DATADIR);

  //Print the command line parameters
  printf("Command-line parameters:\n"STR_VID_OPTIONS);

  //Quit if user wants help
  if( argc > 1 && ( strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-help")==0 ))
  {
    printf("Please see readme.txt or http://wizznic.org/ for more help.\n");
    return(0);
  }

  //Read settings
  printf("Loading settings...\n");
  initSettings();

  #if defined(WITH_OPENGL)
  //We start by enabling glScaling if it was enabled in settings, it can then be overwritten by command line options.
  if( setting()->glEnable && doScale==0 )
    doScale=-1;
  #endif

  //Set scaling
  setting()->scaleFactor=1.0;

  atexit(SDL_Quit);

  //Init SDL
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER ) <0 )
  {
    printf("SDL_Init failed: %s\n",SDL_GetError());
    return(-1);
  }

  //Setup display
  #if defined (GP2X) || defined (PSP) || defined (WIZ)
  SDL_Surface* screen = SDL_SetVideoMode(SCREENW,SCREENH,16, sdlVideoModeFlags);
  #else
  SDL_Surface* screen=NULL;

  int i;
  for( i=0; i < argc; i++ )
  {
    if( strcmp( argv[i], "-sw" ) == 0 )
    {
      setting()->glEnable=0;
      doScale=0;
      saveSettings();
    } else
    if( strcmp( argv[i], "-gl" ) == 0 )
    {
      setting()->glEnable=1;
      doScale=-1;
      saveSettings();
    } else
    if( strcmp( argv[i], "-z" ) == 0 )
    {
      if( i+1 < argc )
      {
        doScale = atoi( argv[i+1] );
        setting()->glEnable=0;
        i++;
        saveSettings();
      } else {
        printf(" -z requires zoom level ( -z 2 for example ).\n");
        return(1);
      }
    } else
    if( strcmp( argv[i], "-f" ) == 0 )
    {
        setting()->fullScreen=1;
        saveSettings();
    } else
    if( strcmp( argv[i], "-w" ) == 0 )
      {
        setting()->fullScreen=0;
        saveSettings();
    } else if( strcmp( argv[i], "-glheight" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glHeight = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window height to %i.\n", setting()->glHeight);
        saveSettings();
      } else {
        printf(" -glheight requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glwidth" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glWidth = atoi( argv[i+1] );
        setting()->glEnable=1;
        doScale=-1;
        i++;
        printf("Setting OpenGL window width to %i.\n", setting()->glWidth);
        saveSettings();
      } else {
        printf(" -glwidth requires an argument (-1 or size in pixels).\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-glfilter" ) == 0 )
    {
      if( i+1 < argc )
      {
        setting()->glFilter=atoi(argv[i+1]);
        printf("OpenGL texture filtering set to %s.\n", (setting()->glFilter)?"Smooth":"Off");
        i++;
        saveSettings();
      } else {
        printf("-glfilter requires 0 or 1 as argument.\n");
        return(1);
      }
    } else if( strcmp( argv[i] , "-d" ) == 0 )
    {
      if( argc == 3 && i < argc+1 )
      {
        dumpPack = malloc( sizeof(char)*strlen(argv[i+1])+1 );
        strcpy( dumpPack, argv[i+1] );
        doScale=0;
        setting()->glEnable=0;
        i++;
      } else {
        printf("-d requires a packname, and must not be used with other parameters.\n");
        return(1);
      }
    } else if( strcmp( argv[i], "-rift") == 0 )
    {
      setting()->glWidth = 1280;
      setting()->glHeight = 800;
      setting()->glEnable=1;
      setting()->rift=1;
      doScale=-1;
    } else if( i > 0 )
    {
      printf("\nError: Invalid argument '%s', quitting.\n", argv[i]);
      return(1);
    }

  }

  if( setting()->fullScreen )
  {
    sdlVideoModeFlags |= SDL_FULLSCREEN;
  }

  if(doScale)
  {
    //Hardware accelerated scaling
    if( doScale == -1 )
    {
    #ifdef HAVE_ACCELERATION
      printf("Enabling platform specific accelerated scaling.\n");
      screen = platformInitAccel(sdlVideoModeFlags);
      if( !screen )
      {
        printf("Failed to set platform accelerated scaling, falling back to software window.\n");
        screen=swScreen(SDL_SWSURFACE);
        doScale=0;
      }
    #else
      printf("\nError:\n  Not compiled with hardware-scaling support, don't give me -z -1\n  Exiting...\n");
      return(-1);
    #endif
    } else if( doScale > 0 )
    {
    #ifdef WANT_SWSCALE
      //Set up software scaling
      printf("Enabling slow software-based scaling to %ix%i.\n",320*doScale, 240*doScale);
      screen = swScaleInit(sdlVideoModeFlags,doScale);
    #else
      printf("\nError:\n  I don't support software scaling, don't give me any -z options\n  Exiting...\n");
      return(-1);
    #endif
    }
  } else {
    screen=swScreen(sdlVideoModeFlags);
    doScale=0;
  }

  printf("Scaling factor: %f\n", setting()->scaleFactor);

  if( screen == NULL )
  {
    printf("ERROR: Couldn't init video.\n");
    return(-1);
  }


  //Set window title
  SDL_WM_SetCaption("Wizznic!", "Wizznic!");
  //Set window icon
  SDL_Surface* icon = IMG_Load( DATADIR"data/wmicon.png");
  SDL_WM_SetIcon(icon, NULL);
  SDL_FreeSurface(icon);

  #endif

  setting()->bpp = screen->format->BytesPerPixel;
  setAlphaCol( setting()->bpp );

  printf("Screen surface using %i bytes per pixel.\n",setting()->bpp);

  //Open Joysticks (for wiz)
  if (SDL_NumJoysticks() > 0) SDL_JoystickOpen(0);

  //Hide mouse cursor
  SDL_ShowCursor(SDL_DISABLE);

  //Load fonts
  txtInit();

  //Load sounds
  if(!initSound())
  {
    printf("Couldn't init sound.\n");
    return(-1);
  }

  //Menu Graphics
  if(!initMenu(screen))
  {
    printf("Couldn't load menu graphics.\n");
    return(-1);
  }

  //Init controls
  initControls();

  //Init stats
  statsInit();

  //Init packs
  packInit();

  //Scan userlevels dir
  makeUserLevelList(screen);

  //Init particles
  initParticles(screen);

  //Seed the pseudo random number generator (for particles 'n' stuff)
  srand( (int)time(NULL) );

  #if defined(PC)
  //Need to dump level-screenshots?
  if(dumpPack)
  {
    printf("Dumping level-images for pack: %s\n", dumpPack);
    dumplevelimages(screen, dumpPack, 0);
    return(0);
  }
  #endif

  //init starfield
  initStars(screen);

  //Init pointer
  initPointer(screen);

  printf("Applying settings..\n");
  //Apply settings (has to be done after packs are inited)
  applySettings();
  //Set Pack
  packSetByPath( setting()->packDir );

  #if defined( PLATFORM_SUPPORTS_STATSUPLOAD )
  if( (setting()->uploadStats) && !(setting()->firstRun) )
  {
    statsUpload(0,0,0,0,0,"check",1, &(setting()->session) );
    statsUpload(0,0,0,0,0,"q_solved",1, &(setting()->solvedWorldWide) );

    //DLC only works when stats-uploading is enabled so we can use the same nag-screen.
    dlcCheckOnline();
  }
  #endif

  printf("Setting Music...\n");
  //Start playing music (has to be done after readong settings)
  soundSetMusic();

  //Initialize credits
  initCredits(screen);

  initTransition();


#if SCREENW != 320 || SCREENH != 240
  SDL_Rect *borderSrcRect = malloc(sizeof(SDL_Rect));
  SDL_Surface* border = loadImg( BORDER_IMAGE );
  if( border )
  {
    printf("Border image loaded.\n");
    borderSrcRect->x=(border->w-SCREENW)/2;
    borderSrcRect->y=(border->h-SCREENH)/2;
    borderSrcRect->w=SCREENW;
    borderSrcRect->h=SCREENH;
    SDL_BlitSurface( border, borderSrcRect, screen, NULL );
    SDL_FreeSurface(border);
  } else {
    printf("Could not load border image: %s\n", BORDER_IMAGE);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
  }
  free(borderSrcRect);
  borderSrcRect=NULL;

#endif

  int lastTick;
  while(state!=STATEQUIT)
  {
    lastTick=SDL_GetTicks();

    frameStart();

    if(runControls()) state=STATEQUIT;
    switch(state)
    {
      case STATEPLAY:
        state = runGame(screen);
      break;

      case STATEMENU:
        state = runMenu(screen);
      break;

      case STATEEDIT:
        state=runEditor(screen);
      break;
    }

    drawPointer(screen);

    soundRun(screen,state);

    runTransition(screen);

    if(setting()->showFps)
      drawFPS(screen);

    switch( doScale )
    {
      #if defined(HAVE_ACCELERATION)
      case -1:
        platformDrawScaled(screen);
        break;
      #endif
      case 0:
        SDL_Flip(screen);
        break;
      #if defined(WANT_SWSCALE)
      default:
        swScale(screen,doScale);
        break;
      #else
      default:
        state=STATEQUIT;
      break;
      #endif
    }

    #if defined(CRUDE_TIMING)
    //Oh how I loathe this, is there no better way?
    while(SDL_GetTicks()-lastTick <= PLATFORM_CRUDE_TIMING_TICKS)
    {
      //Burn, burn baby burn!
    }
    #else
    int t=SDL_GetTicks()-lastTick;
    if(t < 20)
    {
      SDL_Delay( 20 -t);
    }
    #endif
  }

  #if defined(PLATFORM_NEEDS_EXIT)
  platformExit();
  #endif

  SDL_Quit();

  return(0);
}
Пример #7
0
int mythplugin_config(void)
{
    return runMenu("music_settings.xml");
}
task main()
{

	/*
	*	INITIALIZATION AND SETUP
	*	This first section gets the robot ready to start the match. It sets all the motor and servo
	*	starting positions, and prints some diagnostic information to the NXT and the debug stream.
	*/

	// Print a copyright notice to the debug stream
	string programName = "Autonomous";
	printWelcomeMessage(programName, programVersion);

	writeDebugStreamLine("Getting autonomous settings...");
	PlaySound(soundBeepBeep);
	runMenu();			// Get gameplay decisions from the operators

	initializeRobot();	// Set the robot to its starting positions

	// Notify the users that the program is ready and running
	writeDebugStreamLine("Waiting for start of match...");
	nxtDisplayTextLine(0, "2015 Powerstackers");
	nxtDisplayCenteredBigTextLine(1, "AUTO");
	nxtDisplayCenteredBigTextLine(3, "READY");
	PlaySound(soundFastUpwardTones);
	wait10Msec(200);

	/*
	*	DEBUG MODE
	*	If debug mode is activated, bypass the waitForStart function.
	*	Display a 3 second audio and visual countdown, and then execute.
	*/
	if(debugMode)
	{
		ClearSounds();
		for(int i = 3; i>0; --i)
		{
			nxtDisplayCenteredBigTextLine(3, "IN %d", i);
			PlaySound(soundException);
			wait10Msec(100);
		}
	}
	else
	{
		// Wait for the "starting gun" from the field control system
		waitForStart();
	}

	// Notify the users that the program is running
	nxtDisplayCenteredBigTextLine(3, "RUNNING");
	PlaySound(soundUpwardTones);
	//StartTask(watchMotors);

	/*
	*	GAMEPLAY
	*	From this point on, the program is split into different sections based on the options chosen in
	*	menu earlier. The two main options are the starting position and the game mode (offense or defense).
	*/

	if(startingPosition==STARTING_RAMP)
	{
		/*
		*	RAMP POSITION
		*	Starting from this position means that you can only access the rolling goals and the kickstand.
		*	In this position, offensive is mostly the only available game mode.
		*/

		// OFFENSIVE MODE
		if(offenseOrDefense==OFFENSIVE_MODE)
		{
			// Go straight down the ramp
			goTicks(inchesToTicks(-25), 30);
			turnDegrees(5, 50);
			goTicks(inchesToTicks(-40), 50);
			//this will make the robot drop the balls into the rolling goal
			grabTube();
			//this will make the robot turn to move twards the parking zone
			turnDegrees (-8,preferredTurnSpeed);
			goTicks(inchesToTicks(12), 75);
			turnDegrees(-20, preferredTurnSpeed);
			//this will make the robot move twards the parking zone
			goTicks (inchesToTicks(78), 75);
			//this will make the robot turn so it can be in place so it will move in the parking zone
			turnDegrees (-80,preferredTurnSpeed);
			goTicks(inchesToTicks(10), 50);
			dropBall(liftTargetMed);

		}	// END OFFENSE

		// DEFENSIVE MODE
		else if(offenseOrDefense==DEFENSIVE_MODE)
		{
			// Just go in a straight line down the ramp
			goTicks(inchesToTicks(80), 50);
		}	// END DEFENSE

	}	// END RAMP START
	else if(startingPosition==STARTING_FLOOR)
	{
		/*
		*	FLOOR POSITION
		*	In this position, you are available to block the other team, or to score in the high goal. You
		*	also have easy access to the kickstand. It is easiest to determine the orientation of the
		*	center tower from this position.
		*/

		// Detect and store the center goal position
		goTicks(inchesToTicks(-30), 100);
		char goalFacing = findGoalOrientation();

		// OFFENSIVE MODE
		if(offenseOrDefense==OFFENSIVE_MODE)
		{
			// Move slightly forwards to get into a better detecting position
			//goTicks(inchesToTicks(-20), 50);

			// Make a movement based on the position of the center goal
			switch (goalFacing)
			{
				// GOOD
				case CENTGOAL_POSITION_A :
				{
					// In this position, simply go in a straight line
					goTicks(inchesToTicks(-10),50);
					break;
				}
				// BAD
				case CENTGOAL_POSITION_B :
				{
					// Turn 45 degrees, tangent to the center structure
					turnDegrees (45,preferredTurnSpeed);

					// Move into position in front of the goal
					goTicks(inchesToTicks(-30),75);

					// Turn to face the goal
					turnDegrees (-90,preferredTurnSpeed); writeDebugStreamLine("Done");
					break;
				}
				// GOOD
				case CENTGOAL_POSITION_C :
				{
					// Turn 90 degrees, parallel to the center structure
					turnDegrees (-90,preferredTurnSpeed);

					// Move along the center structure until we're past the end
					goTicks(inchesToTicks(-38),50);

					// Turn 90 degrees, tangent to the center structure
					turnDegrees (90,preferredTurnSpeed);

					// Move into position in front of the center structure
					goTicks(inchesToTicks(-62),65);

					//  Turn to face the goal
					turnDegrees(90,preferredTurnSpeed);
					break;
				}

				default:
				{
					// In an ambiguous situtation, assume the goal is in A position
					goTicks(inchesToTicks(-20),75); writeDebugStreamLine("Done");
					break;
				}
			}

			// Print that the alignment is done
			writeDebugStreamLine("Aligned with center structure");


			// Position the robot to drop the ball in the center goal
			nMotorEncoder[mLift] = 0;
			moveMotorTo(mLift, liftTargetCent, 75);

			// Drop the ball in the center goal
			servo[rTrapDoor]=trapDoorOpenPosition;
			wait10Msec (500);
			servo[rTrapDoor]=trapDoorClosedPosition;

			// Drop down the lift
			moveMotorTo(mLift, liftTargetBase, 75);
			// Position the robot correctly to kick the kickstand
			turnDegrees (90, preferredTurnSpeed);
			goTicks(inchesToTicks(-15), 75);
			turnDegrees (90, preferredTurnSpeed);
			goTicks(inchesToTicks(35), 100);
			// Go to the robot's ending position


		}	// END OFFENSE

		// DEFENSIVE MODE
		else if(offenseOrDefense==DEFENSIVE_MODE)
		{
			/*
			*	Move from the starting position to block the opponent's rolling goals
			*/
			// Move 2 feet backwards at full power, to get out of the parking zone
			//goTicks(inchesToTicks(-24), 100);

			// Turn towards the opponent rolling goals
			turnDegrees(90, preferredTurnSpeed);

			// Drive forward and backward to disrupt the opponent 60cm goal
			goTicks(inchesToTicks(60), 100);
			goTicks(inchesToTicks(-12), 100);

			// turn slightly to get the 90cm goals
			turnDegrees(-45, preferredTurnSpeed);

			// Move forward and backwards to disrupt the 90cm goal
			goTicks(inchesToTicks(36), 75);
			goTicks(inchesToTicks(-36), 100);
return;
			// Turn slightly to face the 30cm goal
			turnDegrees(-45, preferredTurnSpeed);

			// Move foward and backward to disrupt the 30cm goal
			goTicks(inchesToTicks(36), 75);
			goTicks(inchesToTicks(-4), 100);

			// Move into position to align on the wall of the ramp
			turnDegrees(-90, preferredTurnSpeed);
			//goTicks(inchesToTicks(12), 100);
			//turnDegrees(90, preferredTurnSpeed);
return;
			// Align ourselves with this wall
			//wallAlign(ALIGN_FORWARD);

			/*
			*	BLOCK CETNER GOAL
			*	Move the robot in front of the opponent's center goal
			*/

			// Move into position for use to block the center goal
			goTicks(inchesToTicks(-6), 100);	// Move away from the wall
			turnDegrees(90, preferredTurnSpeed);				// Turn to face OUR ramp
			goTicks(inchesToTicks(-36), 100);		// Move foward, past the center goal
			//turnDegrees(90, preferredTurnSpeed);				// Turn parallel to the cetner structure

			// Move to block the center goal, in one of three positions
			switch(goalFacing)
			{
				// Farthest position
				case CENTGOAL_POSITION_A:
				{
					writeDebugStreamLine("-- BLOCKING GOAL POSITION A --");
					goTicks(inchesToTicks(-80), 100);	// Move alongside the goal
					turnDegrees(90, preferredTurnSpeed);				// Turn tangent to the center structure
					goTicks(inchesToTicks(20), 100);	// Move in front of the goal
					break;
				}
				// Middle position
				case CENTGOAL_POSITION_B:
				{
					writeDebugStreamLine("-- BLOCKING GOAL POSITION B --");
					goTicks(inchesToTicks(-40), 100);	// Move alongside the goal
					turnDegrees(45, preferredTurnSpeed);				// Turn tangent to the center structure
					goTicks(inchesToTicks(20), 100);	// Move in front of the goal
					break;
				}
				// Closest position
				case CENTGOAL_POSITION_C:
				{
					writeDebugStreamLine("-- BLOCKING GOAL POSITION C --");
					goTicks(inchesToTicks(-20), 100);	// Move in front of the goal
					break;
				}
				default:
				{
					break;
				}
			}

		}	// END DEFENSE

	}	// END FLOOR START

	// After the program has been carried out, play a cute "done" sound
	nxtDisplayCenteredBigTextLine(3, "DONE");
	PlaySound(soundBeepBeep);
	wait10Msec(200);
} // END