Пример #1
0
void CGame::IniciandoVideo()
{
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
	
	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Video Init: ", (const char *)SDL_GetError(), NULL);
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
		

	}
	
	window = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH_SCREEN, HEIGHT_SCREEN, SDL_WINDOW_OPENGL);
	
	if (!window) {
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Windows OpenGL Init: ", (const char *)SDL_GetError(), NULL);
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
		SDL_Quit();
		exit(2);
	}
	
	gContext = SDL_GL_CreateContext(window);

	if (!gContext) {
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL Context Init: ", (const char *)SDL_GetError(), NULL);
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
		SDL_Quit();
		exit(2);
	}
	openGlImplement.setSDLWindow(window);
}
bool Game::SpriteCollision(Sprite* pSpriteHitter, Sprite* pSpriteHittee){
  GameEngine *pGameEngine = GameEngine::GetEngine();

  // See if the chicken was hit
  if (pSpriteHittee == _pChickenSprite)
  {
    // Move the chicken back to the start
    _pChickenSprite->SetPosition(4, 175);

    // See if the game is over
    if (--_iNumLives > 0)
      SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION ,
			       "Henway",
			       "Ouch!",
			       pGameEngine->GetWindow());
    else
    {
      // Display game over message
      char szText[64];
      sprintf(szText, "Game Over! You scored %d points.", _iScore);
      SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION ,
			       "Henway",
			       szText,
			       pGameEngine->GetWindow());
      _bGameOver = true;
    }

    return false;
  }

  return true;
}
Пример #3
0
void _FAIL(int line = -1)
{
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "FAIL", "SOMETHING WENT WRONG!!!!", 0);
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "FAIL", SDL_GetError(), 0);

	char str[32];
	sprintf(str, "line: %d", line);
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "FAIL", str, 0);
	raise(SIGINT); //break into debugger
}
Пример #4
0
int SteamGlobal::init()
{
#if defined(CHOWDREN_FORCE_STEAM_OPEN) && defined(CHOWDREN_STEAM_APPID)
    if (SteamAPI_RestartAppIfNecessary(CHOWDREN_STEAM_APPID)) {
        return EXIT_FAILURE;
    }
#endif

    initialized = SteamAPI_Init();
    if (!initialized) {
        std::cout << "Could not initialize Steam API" << std::endl;
#ifdef CHOWDREN_FORCE_STEAM_OPEN
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Steam error",
                                 "Could not initialize Steam API. "
                                 "Please make sure you are logged in to Steam "
                                 "before opening the game.",
                                 NULL);
        return EXIT_FAILURE;
#endif
        return 0;
    }
	std::cout << "Initialized Steam API" << std::endl;

    bool debug_achievements = getenv("CHOWDREN_DEBUG_ACHIEVEMENTS") != NULL;
    if (debug_achievements) {
    	if (!SteamUserStats()->ResetAllStats(true))
    		std::cout << "Could not reset stats" << std::endl;
    }
	if (!SteamUserStats()->RequestCurrentStats())
		std::cout << "Could not request Steam stats" << std::endl;

#ifdef CHOWDREN_STEAM_APPID
    ISteamApps * ownapp = SteamApps();
    if (!ownapp->BIsSubscribedApp(CHOWDREN_STEAM_APPID)) {
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Steam error",
                                 "Please purchase the Steam version of the "
                                 "game if you want to play it on Steam.",
                                 NULL);
        return EXIT_FAILURE;
    }
#endif
    steam_language = SteamApps()->GetCurrentGameLanguage();
    if (steam_language.empty())
        steam_language = "english";
    steam_language[0] = toupper(steam_language[0]);
    std::cout << "Detected Steam language: " << steam_language << std::endl;
    return 0;
}
Пример #5
0
int main(int argc, char* args[])
{
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        //This is a nice alternative to printf in SDL 2
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SDL", "SDL failed to initialize!", NULL);
        SDL_Quit();
        return 0;
    }

    //In SDL 2, SDL_SetVideoMode has been removed, we now create windows using SDL_CreateWindow to create windows
    Window = SDL_CreateWindow("I can talk!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);

    //SDL_GetWindowSurface gets the backbuffer of the window we created with SDL_CreateWindow
    Backbuffer = SDL_GetWindowSurface(Window);

    if(!LoadFiles())
    {
      SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SDL", SDL_GetError(), NULL);

        //SDL_DestroyWindow destroys a window we created with SDL_CreateWindow
        SDL_DestroyWindow(Window);
        FreeFiles();
        SDL_Quit();

        return 0;
    }

    while(ProgramIsRunning())
    {
        DrawImage(Background,Backbuffer, 0, 0);
        DrawRasterText(FontImage, Backbuffer, "All Systems Go!" , 100, 100, charSize);
        DrawRasterText(FontImage, Backbuffer, "Drawing Fonts is Fun!", 100, 116, charSize);

        SDL_Delay(20);

        //In SDL 2, SDL_UpdateWindowSurface replaces SDL_Flip
        SDL_UpdateWindowSurface(Window);
    }

    FreeFiles();

    //SDL_DestroyWindow destroys a window we created with SDL_CreateWindow
    SDL_DestroyWindow(Window);
    SDL_Quit();

    return 0;
}
Пример #6
0
void playsound (short sound, Mix_Chunk* gSound)
{
    //Load sfx
    switch (sound)
    {
        case 1 :
            gSound = Mix_LoadWAV ( SONYEP );
            break;

        case 2 :
            gSound = Mix_LoadWAV ( SONNOP );
            break;

        case 3 :
            gSound = Mix_LoadWAV ( SONCLICBOUTON );
            break;

        case 4 : //son defaite
            gSound = Mix_LoadWAV (SONLOOSE);
            break;
    }

    if ( gSound == NULL )
    {
        SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_ERROR, "Erreur du gestionnaire de son", Mix_GetError() , NULL);
        exit (EXIT_FAILURE);
    }

    Mix_PlayChannel ( -1, gSound, 0 );
    return;
}
Пример #7
0
void
fatalError(const char *string)
{
    printf("%s: %s\n", string, SDL_GetError());
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, string, SDL_GetError(), NULL);
    exit(1);
}
Пример #8
0
void vsFailedAssert( const vsString &conditionStr, const vsString &msg, const char *file, int line )
{
	if ( !bAsserted )
	{
		// failed assertion..  trace out some information and then crash.
		bAsserted = true;
		vsString trimmedFile(file);
		size_t pos = trimmedFile.rfind('/');
		if ( pos )
		{
			trimmedFile = trimmedFile.substr(pos+1);
		}

		vsLog("Failed assertion:  %s", msg.c_str());
		vsLog("Failed condition: (%s)", conditionStr.c_str());
		vsLog("at %s:%d", trimmedFile.c_str(), line);
		vsLog_End();

		{
#if defined(_DEBUG)
			DEBUG_BREAK;
#else
			vsString mbString = vsFormatString("Failed assertion:  %s\nFailed condition: (%s)\nat %s:%d", msg.c_str(), conditionStr.c_str(), trimmedFile.c_str(), line);
			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Failed assertion", mbString.c_str(), NULL);
#endif
			CRASH;
		}
	}
	else
	{
		vsLog("Error:  Asserted while handling assertion!");
	}
}
Пример #9
0
int main(int argc, char* argv[])
{
	/* Unused arguments */
	(void)argc;
	(void)argv;

	/* Initialize SDL */
	if (SDL_Init(SDL_INIT_VIDEO) != 0){
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
		                         "SDL_Init Failure",
		                         SDL_GetError(),
		                         NULL);
		return EXIT_FAILURE;
	}

	/* Initialize game state */
	init_game();
	/* Initialize graphics */
	if (init_graphics() != 0){
		return EXIT_FAILURE;
	}

	/* Start game logic thread */
	SDL_CreateThread(game_thread, "GameLogic", NULL);

	/* Main Loop */
	while (!quit){
		/* Handle events*/
		handle_event();
		/* Render graphics */
		update_graphics();
	}

	return EXIT_SUCCESS;
}
Пример #10
0
		void Message(MessageType type, const char* message, const char* title)
		{
			if (running_unittests) {
				throw WarningException(message);
			}

			int flags = 1;

			switch (type) 
			{
				case MESSAGEBOX_ERROR:
					flags = SDL_MESSAGEBOX_ERROR;
					if (title == NULL)
						title = "Error";
					break;
				case MESSAGEBOX_INFORMATION:
					flags = SDL_MESSAGEBOX_INFORMATION;
					if (title == NULL)
						title = "Information";
					break;
				case MESSAGEBOX_WARNING:
					flags = SDL_MESSAGEBOX_WARNING;
					if (title == NULL)
						title = "Warning";
					break;
				default:
					Int3();
					title = ""; // Remove warning about unitialized variable
					break;
			}

			SDL_ShowSimpleMessageBox(flags, title, message, os::getSDLMainWindow());
		}
Пример #11
0
	void SDLWindow::Alert (const char* message, const char* title) {
		
		#ifdef HX_WINDOWS
		
		int count = 0;
		int speed = 0;
		bool stopOnForeground = true;
		
		SDL_SysWMinfo info;
		SDL_VERSION (&info.version);
		SDL_GetWindowWMInfo (sdlWindow, &info);
		
		FLASHWINFO fi;
		fi.cbSize = sizeof (FLASHWINFO);
		fi.hwnd = info.info.win.window;
		fi.dwFlags = stopOnForeground ? FLASHW_ALL | FLASHW_TIMERNOFG : FLASHW_ALL | FLASHW_TIMER;
		fi.uCount = count;
		fi.dwTimeout = speed;
		FlashWindowEx (&fi);
		
		#endif
		
		if (message) {
			
			SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_INFORMATION, title, message, sdlWindow);
			
		}
		
	}
Пример #12
0
bool Window::showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow)
{
	SDL_MessageBoxFlags flags = convertMessageBoxType(type);
	SDL_Window *sdlwindow = attachtowindow ? window : nullptr;

	return SDL_ShowSimpleMessageBox(flags, title.c_str(), message.c_str(), sdlwindow) >= 0;
}
Пример #13
0
void EngineRoutines::ShowSimpleMsg(const char* msg)
{
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
        "notice",
        msg,
        NULL);
}
Пример #14
0
SDL_Texture *get_texture_from_image(SDL_Renderer *pRenderer, const char *filepath) {

  /** Generate an SDL_Texture object from an image filepath. **/

  SDL_Surface *image_surface = IMG_Load(filepath);

  if (image_surface == NULL) {
    /** Display an error message and quit the programme in case of error. **/
    char *message=calloc(256,sizeof(char)) ;
    sprintf(message,"Failed to load image %s!\n%s",filepath,SDL_GetError()) ;
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error image loading", message ,NULL) ;
    free(message) ;
    #ifdef DEBUG
      fprintf(stdout,"image_surface error (%s)\n",SDL_GetError());
    #endif
    exit(EXIT_FAILURE) ;
  
  }

  SDL_Texture *image_texture = SDL_CreateTextureFromSurface(pRenderer,image_surface) ;

  if (image_texture == NULL) {
    /** Exit the programme in case of error. **/
    exit(EXIT_FAILURE) ;
  
  }

  SDL_FreeSurface(image_surface) ; /** We clean up the surface. **/

  return image_texture ;
}
Пример #15
0
void show_add_player_input_message(SDL_Window *window)
{
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,
							 "Adicionar Jogador",
							 "Insira os dados do jogador no terminal.",
							 window);
}
void GameEngine::ErrorQuit(char* szErrorMsg)
{
  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
			   "Critical Error",
			   szErrorMsg,
			   GetWindow());
}
Пример #17
0
/*
 * Série de três funções que mostram janelas popup quando
 * inserimos um jogador (opção da tecla <a>)
 */
void show_add_player_message(SDL_Window *window)
{
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION,
							 "Adicionar Jogador",
							 "Clique num lugar vazio para inserir um novo jogador.",
							 window);
}
Пример #18
0
		void Runner::RunProtected() {
			SPADES_MARK_FUNCTION();
			std::string err;
			try{
				Run();
			}catch(const spades::Exception& ex){
				err = ex.GetShortMessage();
				SPLog("[!] Unhandled exception in SDLRunner:\n%s", ex.what());
			}catch(const std::exception& ex){
				err = ex.what();
				SPLog("[!] Unhandled exception in SDLRunner:\n%s", ex.what());
			}
			if(!err.empty()){
				
				std::string msg = err;
				msg = _Tr("Main", "A serious error caused OpenSpades to stop working:\n\n{0}\n\nSee SystemMessages.log for more details.", msg);
				
				
				SDL_InitSubSystem(SDL_INIT_VIDEO);
				if(SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, _Tr("Main", "OpenSpades Fatal Error").c_str(), msg.c_str(), nullptr)) {
					// showing dialog failed.
					// TODO: do appropriate action
				}
		
				
			}
		}
Пример #19
0
static void checkGameDirs()
{
	static const char errorMessage[] = "Can't find \"gamedata\" and/or \"fedata\" directories in current working directory!"
#ifndef WIN32
		"\nBe sure that all files and directories have small letters!"
#endif
	;
	BOOL showErrorMessage = true;
#ifdef WIN32
	DWORD dwAttrib1 = GetFileAttributes("gamedata");
	DWORD dwAttrib2 = GetFileAttributes("fedata");
	if
	(
		dwAttrib1 != INVALID_FILE_ATTRIBUTES &&
		dwAttrib2 != INVALID_FILE_ATTRIBUTES &&
		(dwAttrib1 & FILE_ATTRIBUTE_DIRECTORY) &&
		(dwAttrib2 & FILE_ATTRIBUTE_DIRECTORY)
	) showErrorMessage = false;
#else
	struct stat st;
	if (!stat("gamedata", &st) && S_ISDIR(st.st_mode) && !stat("fedata", &st) && S_ISDIR(st.st_mode))
		showErrorMessage = false;
#endif
	if (showErrorMessage)
	{
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, errorMessage, NULL);
		exit(-1);
	}
}
Пример #20
0
void wzFatalDialog(const char *msg)
{
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
	                         "We have a problem!",
	                         msg,
	                         NULL);
}
Пример #21
0
bool FileSys::OpenDIR()
{
    DIR * dir;
    struct dirent * entry;
    string currentDIR = GetDIR();

    dir = opendir( currentDIR.c_str() );

    if ( !dir )
    {
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Запрещенно", GetDIR().c_str(), NULL );
        Upward();
        return false;
    }

    EmptyFoldersAndFiles();
    while ( ( entry = readdir(dir) ) != NULL )
    {
        if( entry->d_name[0] != '.' )
        {
            if( entry->d_type == DT_DIR )
                foldersInDIR.push_back( entry->d_name );
            if( entry->d_type == DT_REG )
                filesInDIR.push_back( entry->d_name );
        }
    };

    allFilesInDIR = filesInDIR.size();
    allFoldersInDIR = foldersInDIR.size();
    closedir(dir);
    return true;
}
Пример #22
0
static void msgBox(QString title, QString text)
{
    std::string ttl = title.toStdString();
    std::string msg = text.toStdString();
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                             ttl.c_str(), msg.c_str(),
                             PGE_Window::window);
}
Пример #23
0
Enemy::Enemy(double x, double y, const std::string &name):
    PE::Ai(x, y, name)
    {
    speed = 50.0;
    stateMachine.addState(Idle(stateMachine, *this));
    stateMachine.changeState(IDLE_ID);
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Debug", "initStateMachine done", NULL);
    }
Пример #24
0
void Xash_Error( const char *errorstring )
{
#ifdef XASH_SDL
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Xash Error", errorstring, NULL);
#endif
	fprintf(stderr, "Xash Error: %s\n", errorstring);
	exit( 1 );
}
Пример #25
0
static void ss_MsgFunc( void* unused, SGS_CTX, int type, const char* message )
{
	if( type >= SGS_ERROR )
	{
		sgs_PushErrorInfo( C, SGS_ERRORINFO_FULL, type, message );
		SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, "Script error", sgs_GetStringPtr( C, -1 ), NULL );
		exit( -1 );
	}
}
Пример #26
0
        void WindowSDL2::simple_message( const char* message, const char* title ) {

            if(closed) {
                return;
            }

            SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window );

        } //WindowSDL2::simple_message
Пример #27
0
void fatal(const char * fmt, ...) {
	va_list v;
	char buf[1024];

	va_start(v, fmt);
	vsnprintf(buf, 1024, fmt, v);
	va_end(v);
	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, app_title, buf, NULL);
	exit(1);
}
Пример #28
0
int show_error(std::string str, bool is_fatal) {
	std::cerr << str << "\n";
	int r = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", str.c_str(), NULL);

	if (is_fatal) {
		throw 1;
	}

	return r;
}
Пример #29
0
void Windows::exit (const std::string& reason, int errorCode)
{
	if (errorCode != 0) {
		logError(reason);
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", reason.c_str(), nullptr);
	} else {
		logOutput(reason);
	}
	ExitProcess(errorCode);
}
Пример #30
0
void Windows::exit (const std::string& reason, int errorCode)
{
	if (errorCode != 0) {
		Log::error(LOG_COMMON, "%s", reason.c_str());
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", reason.c_str(), nullptr);
	} else {
		Log::info(LOG_COMMON, "%s", reason.c_str());
	}
	ExitProcess(errorCode);
}