void Game::ResetGame( ) { SetPlanetValues( ); ClearAllPumpBullets( ); ClearKeyStates( ); // Reset the player RandomlyPlacePlayer( ); m_Player.SetDirection( LDE::Vector2f( 0.0f, 0.0f ) ); m_ActiveLazer = false; m_GameTimer.Start( ); }
// Private functions bool Game::Load( ) { // Seed "Random" srand( time( NULL ) * 45621 ) ; // Set the window size m_WindowSize = LDE::Vector2i( 1024, 720 ); // Initialize SDL IMPORTANT if( SDL_Init( SDL_INIT_VIDEO ) != 0 ) { std::cout << "[Game::Load( )] Unable to initialize SDL: " << SDL_GetError( ) << std::endl; return false; } // use OGL double buffer SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); SDL_WM_SetCaption( "LD26", NULL ); // Load the opengl SDL surface if( (m_pSurface = SDL_SetVideoMode( m_WindowSize.x, m_WindowSize.y, 16, SDL_OPENGL /*| SDL_FULLSCREEN */ ) ) == NULL ) { std::cout << "[Game::Load( )] Unable to set SDL surface: " << SDL_GetError( ) << std::endl; return false; } //Initialize SDL_ttf /* if( TTF_Init() == -1 ) { std::cout << "[Game::Load( )] Unable to init TTF: " << SDL_GetError( ) << std::endl; return false; }*/ // Load the font /*if( !m_Font.Load( "Data/Fonts/pixelart.ttf", 28 ) ) { std::cout << "[Game::Load( )] Unable to load the font: " << SDL_GetError( ) << std::endl; return false; }*/ //SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 ); // Set up opengl glEnable( GL_TEXTURE_2D ); glEnable( GL_LINE_SMOOTH ); //glClearColor( 39.0f / 255.0f, 43.0f / 255.0f, 47.0f / 255.0f, 0.0f ); glClearColor( 5.0f / 255.0f, 5.0f / 255.0f, 5.0f / 255.0f, 0.0f ); glViewport( 0, 0, m_WindowSize.x, m_WindowSize.y ); glClear( GL_COLOR_BUFFER_BIT /*|GL_DEPTH_BUFFER_BIT */ ); // Enable alpha blending glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); glAlphaFunc( GL_GREATER, 0 ); glEnable( GL_ALPHA_TEST ); // Set up opengl matrices glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( 0.0f, m_WindowSize.x, 0.0f, m_WindowSize.y, -1.0f, 1.0f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); // Load the game start values LoadStartValues( ); // Load the high scores ReadHighScore( ); // Load all the textures if( !m_PlanetTexture.Load( "Data/Textures/Planet.BMP" ) ) { std::cout << "[Game::Load( )] Unable to load the texture: " << SDL_GetError( ) << std::endl; return false; } if( !m_SpacecraftTexture.Load( "Data/Textures/Spacecraft.BMP" ) ) { std::cout << "[Game::Load( )] Unable to load the texture: " << SDL_GetError( ) << std::endl; return false; } if( !m_OverlayTexture.Load( "Data/Textures/Overlay.BMP" ) ) { std::cout << "[Game::Load( )] Unable to load the texture: " << SDL_GetError( ) << std::endl; return false; } // Load the overlay quad m_OverlayQuad.SetPosition( LDE::Vector2f( 0.0f, 0.0f ) ); m_OverlayQuad.SetVertLowCoo( LDE::Vector2f( 0.0f, 0.0f ) ); m_OverlayQuad.SetVertHighCoo( m_WindowSize ); m_OverlayQuad.SetTexLowCoo( LDE::Vector2f( 0.0f, 0.0f ) ); m_OverlayQuad.SetTexHighCoo( LDE::Vector2f( 1.0f, 1.0f ) ); // Load the player m_Player = Player( &m_SpacecraftTexture ); if( !m_Player.Load( ) ) { std::cout << "[Game::Load( )] Unable to load the player" << std::endl; return false; } RandomlyPlacePlayer( ); m_Player.SetDirection( m_StartPlayerDirection ); m_Player.SetColor( m_StartPlayerColor ); m_Player.SetMaxSpeed( 300.0f ); m_Player.SetRotationSpeed( 200.0f ); // Load the planets for( unsigned int i = 0; i < PLANET_COUNT; i++ ) { m_Planets[ i ].SetTexture( &m_PlanetTexture ); m_Planets[ i ].Load( ); } // Set all the other planet values SetPlanetValues( ); // Clear all pumps ClearAllPumpBullets( ); // Clear all key inputs ClearKeyStates( ); m_GameTimer.Start( ); return true; }
cInput::cInput() { ClearKeyStates(); }
InputManager::InputManager() { ClearKeyStates(); m_maxClickTime = 0.5f; }