Example #1
0
void Game::Update(float deltaTime)
{
	// Calculate FPS
	m_fTimePassed += deltaTime;
	m_nFramesPassed++;
	if(m_fTimePassed > 0.25f && m_nFramesPassed > 5)
	{
		m_fFPS = ((float)m_nFramesPassed / m_fTimePassed);
		m_fTimePassed = 0.0f;
		m_nFramesPassed = 0;
	}

	// Get the mouse X and Y position
	int mouseX;
	int mouseY;
	Input::Instance()->GetMouseXY(&mouseX, &mouseY);
	m_v2MousePos.x = (float)mouseX;
	m_v2MousePos.y = (float)mouseY;

	// Update all the enemies
	UpdateEnemies(deltaTime);
}
Example #2
0
void GameManager::PlayGame() 
{
	while (!doExit) //Main Game Loop
	{	
		RunGameOverCheck();

		UpdateGameTimers();

		UpdatePlayerInput();

		UpdateEnemySpawner();

		UpdateEnemies();

		UpdatePlayer();

		UpdateBullets();

		RunCollisionCheck();

		Render(); //Render everyting
	}
	QuitGame();
}
Example #3
0
//MAIN GAME LOOP
void Game::GameLoop()
{
    //check time of last frame
    float frameTime = frameClock.getElapsedTime().asSeconds();
    frameClock.restart();



    //event loop
    sf::Event currentEvent;
    while(mainWindow.pollEvent(currentEvent))
    {
        //gotta handle resize things here
        if(currentEvent.type == sf::Event::Resized)
        {
            //std::cerr << "resized" << std::endl;
            float aspectRatio = float(currentEvent.size.width)/float(currentEvent.size.height);
            float newHeight = (1024.f*currentEvent.size.height)/currentEvent.size.width;
            float newWidth = (768.f*currentEvent.size.width)/currentEvent.size.height;
            if(aspectRatio > (4.f/3.f))
            {
                float displace = (newWidth - 1024.f)/(-2.f);
                View = sf::View(sf::FloatRect(displace, 0, newWidth, 768));
            }
            else if(aspectRatio < (4.f/3.f))
            {
                float displace = (newHeight - 768.f)/(-2.f);
                View = sf::View(sf::FloatRect(0, displace, 1024, newHeight));
            }
            mainWindow.setView(View);
        }
        //broken fullscreen stuff, do not touch
        else if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::F))
        {
            //mainWindow.close();
            //std::vector<sf::VideoMode> FullscreenModes = sf::VideoMode::getFullscreenModes();
            //mainWindow.create(FullscreenModes[0],"SHMUP Super Alpha", sf::Style::Fullscreen);
        }

        switch(gameState)
        {
        case GameOver:
        {
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return))
            {
                scoreboard.clear();
                gameState = Uninitialized;
            }
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            break;
        }
        case Playing:
        {
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P))
            {
                sounds[2].play();
                gameState = Paused;
            }
            break;
        }
        case Paused:
        {
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::P))
            {
                sounds[2].play();
                gameState = Playing;
            }
            break;
        }
	case Intro:
	{
	    if(currentEvent.type == (sf::Event::KeyPressed) && currentEvent.key.code == (sf::Keyboard::Return))
            {
		storyScreen++;
		sounds[1].play();
		unsigned pos = 0;
		for(int i = 0; i < 10; i++)
		{
			pos = story.find_first_of('\n',pos+1);
		}
		buffer.assign(story,0,pos);
		story.erase(0,pos);

            }
            if(currentEvent.type == sf::Event::Closed || (currentEvent.type == (sf::Event::KeyPressed) && (currentEvent.key.code == sf::Keyboard::Escape)))
            {
                gameState = Exiting;
            }
            break;

	}

	}
        }

    //non event-triggered state stuff (every frame updates)
    switch(gameState)
    {
    case Uninitialized:
    {
        mainWindow.clear();

        background0.Load("images/acespacebg0.png");
        background1.Load("images/acespacebg1.png");
        background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768));
        background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768),576,768));
        bgMove0 = 0;
        bgMove1 = 0;

        player1.Load("images/Player.png");
        player1.SetPosition(576/2,700);
        player1.revive();

        scoreboard.updatePower(0);
        scoreboard.updateLives(0);
        scoreboard.updateScore(-1);
	scoreboard.updateTargetHP(0,0);

        scoreboard.updateFont(&datagoth);
        scoreboard.clear();
    }
    case ShowingSplash:
    {
        if(!ShowSplashScreen())
            gameState = Exiting;
        else
        {
           gameState = Intro;
		unsigned pos = 0;
		for(int i = 0; i < 10; i++)
		{
			pos = story.find_first_of('\n',pos+1);
		}
		buffer.assign(story,0,pos);
		story.erase(0,pos);
	}
        break;
    }
    case Intro:
    {

	    if(storyScreen == 5) 
	    {
                music[0].stop();
		music[1].play();    
		gameState = Playing;

		scoreboard.updateLives(1);
		scoreboard.updatePower(5);
		scoreboard.updateScore(000000);
		scoreboard.updateTargetHP(0,0);

		//intial wave to seed the enemy list
		Enemy* newEnemy2 = new Enemy(2, 0, -100);
		newEnemy2->setDestination(200, 300);
		enemyList.push_front(*newEnemy2);

		Enemy* newEnemy3 = new Enemy(2, 576, -100);
		newEnemy3->setDestination(350, 300);
		enemyList.push_front(*newEnemy3);

		Enemy* newEnemy4 = new Enemy(2, 60, -100);
		newEnemy4->setDestination(200, 300);
		enemyList.push_front(*newEnemy4);

		Enemy* newEnemy5 = new Enemy(2, 536, -100);
		newEnemy5->setDestination(350, 300);
		enemyList.push_front(*newEnemy5);

		frameClock.restart();
	    }
    }
    case Playing:
    {
        //check movement
        CheckMovement(5, frameTime);
        if(player1.destroyCheck())
        {
            enemyList.clear();
            mainWindow.clear();
            player1.clearProjectiles();
            music[1].stop();
            sounds[4].play();
            scoreboard.updateLives(-1);
            gameState = GameOver;
            break;
        }

        UpdateProj();
        UpdateEnemies();

        //update paralaxed backgrounds
        if(bgMove0 > (2500-768))
            bgMove0 = 0;
        bgMove0 += 1;
        background0.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove0,576,768));
        break;
    }
    }

    if(bgMove1 > (2500-768))
        bgMove1 = 0;
    bgMove1 += 3;
    background1.sprite.setTextureRect(sf::Rect<int>(0,(2500-768)-bgMove1,576,768));

    //clean up sprites to be deleted
    CleanUp();

    //draw game
    mainWindow.clear(sf::Color(0,0,0));
    mainWindow.draw(wholeArea);
    background0.Draw(mainWindow);

    char fps[60];
    sprintf(fps,"%.2f\nESC to Quit\nP to Pause\nSPACE to Fire\nWASD to Move",(float(1)/frameTime));
    sf::String fpsString(fps);
    sf::Text text(fpsString, datagoth);
    text.setCharacterSize(20);
    text.setColor(sf::Color::White);
    text.setPosition(596, 650);

    sf::String sidebar(buffer+"\n\nPress Enter");
    sf::Text textBox(sidebar,datagoth);

    if(gameState == GameOver)
    {
        sf::String gameOver("GAME OVER");
        sf::Text endingMessage(gameOver, datagoth);
        endingMessage.setCharacterSize(50);
        //endingMessage.setStyle(sf::Text::Bold);
        endingMessage.setColor(sf::Color::Red);
        endingMessage.setPosition(288-(endingMessage.getGlobalBounds().width/2), 300);

        sf::String authors("Developed by:\nJohn New\nDevon Gardner\nJon Forcht\nDanny Krulick\n\n\n\n\n\n\nPress Enter to Restart");
        sf::Text credits(authors, datagoth);
        credits.setCharacterSize(20);
        credits.setColor(sf::Color::White);
        credits.setPosition(288-(credits.getGlobalBounds().width/2), 500);
        mainWindow.draw(credits);
        mainWindow.draw(endingMessage);
    }

    DrawProj();
    DrawEnemies();

    if(player1.destroyCheck() == false)
        player1.Draw(mainWindow);

    background1.Draw(mainWindow);

    mainWindow.draw(spawnArea);
    mainWindow.draw(rightBound);
    mainWindow.draw(leftBound);
    mainWindow.draw(bottomBound);
    mainWindow.draw(text);
    if(gameState == Intro && storyScreen < 5)
    {
    	textBox.setCharacterSize(20);
    	textBox.setColor(sf::Color::White);
    	textBox.setPosition(596, 250);
	mainWindow.draw(textBox);
    }
    scoreboard.drawScoreboard(mainWindow, player1.sprite);

    //finally, render the frame
    mainWindow.display();
}
Example #4
0
INT CGpApp::FrameMove()
{
	INT hr =0;

	// Input Update
	hr = m_pInput->Update();

	if (LC_FAILED(hr))
		return LC_EFAIL;


	LCXVECTOR3	vcMtsPos = m_pInput->MtsPosition();
	//LC_STATE	nMtsState= m_pInput->MtsState();
	const BYTE*	pKey = m_pInput->KeyMap();
	const BYTE*	pMts = m_pInput->MtsMap();

	// Home Key
	if(pKey[LCIK_ESCAPE])
		return LC_EFAIL;


	if(8>m_nSkip)
	{
		++m_nSkip;
		return 0;
	}


	SystemControl();

	if (PLAYER_STATUS_DEAD != m_PlayerStatus)
		UpdatePlayer();

	UpdatePlayerMissiles();
	UpdateEnemies();
	UpdateEnemyMissiles();

	CollisionPlayerMissilesAndEnemies();
	CollisionPlayerAndEnemies();
	CollisionEnemyMissilesAndPlayer();
	ScrollBackground();

	ShieldPulse();


	if(0>=m_Player.nAlive)
		return LC_EFAIL;


	
	if(m_bShowSt)
	{
		char sbuf[128]={0};
		DOUBLE fFPS		   = m_TimeFPS;
		DOUBLE fElasedTime = m_TimeElps;

		sprintf(sbuf, "갈릭: m: %.f %.f %d, %.f(%.1f)F"
				, vcMtsPos.x, vcMtsPos.y, pMts[0], fFPS, fElasedTime);

		m_pFont->String(sbuf);
	}

	return LC_OK;
}
Example #5
0
void Enemies::Update(float elapsedTime, float totalTime, std::list<Bullet*>* playerbullets, Bullet* bomb)
{
	UpdateEnemies(elapsedTime, totalTime, playerbullets, bomb);

	UpdatePowerups(elapsedTime, totalTime);
}