Пример #1
0
void GameScreen::Update(const float time_step)
{
	player.Update(time_step);

	bool game_over = false;

	//Update asteroids checking them against player and lasers
	BSphere player_sphere = player.GetBSphere();
	std::list<Asteroid*>::iterator iter = asteroids.begin();
	while(iter != asteroids.end())
	{
		Asteroid* ast = iter._Ptr->_Myval;

		ast->Update(time_step);

		//Check asteroid is in the play region
		//if not reset it
		if(!play_region.Contains(ast->GetBSphere()))
		{
			//Move the asteroid elsewhere
			RepositionAsteroid(ast);
		}
		//check against the player
		if(player_sphere.Contains(ast->GetBSphere()))
		{
			//player.AddScore(ast->GetBSphere().GetRadius());
			game_over = true;
		}

		iter++;
	}

	//Do some laser-asteroid checking
	player.CheckLaserAsteroidCollisions(&asteroids);

	asteroid_spawn_countdown -= time_step;

	if(asteroid_spawn_countdown < 0 && asteroids.size() < MAX_ASTEROIDS)
	{
		asteroid_spawn_countdown = ASTEROID_SPAWN_INTERVAL;

		SpawnAsteroid();
	}

	if(game_over)
	{
		GameOverScreen *gameover_screen = new GameOverScreen();
		gameover_screen->Initialise(player.GetScore());
		RustyLib::Framework::ScreenManagement::ScreenManager::Instance().ChangeScreen(
					gameover_screen);
	}
}
Пример #2
0
void Player::CheckLaserAsteroidCollisions(std::list<Asteroid*>* asteroids)
{
    std::list<Asteroid*>::iterator a_iter = asteroids->begin();
    std::list<Asteroid*> a_tbd;
    std::list<Laser*> l_tbd;

    while(a_iter != asteroids->end())
    {
        Asteroid *ast = a_iter._Ptr->_Myval;
        std::list<Laser*>::iterator l_iter = lasers.begin();

        while(l_iter != lasers.end())
        {
            Laser *las = l_iter._Ptr->_Myval;

            if(ast->GetBSphere().Contains(las->GetPosition()))
            {
                //The laser is inside the asteroid bsphere
                a_tbd.push_back(ast);
                l_tbd.push_back(las);
                AddScore(ast->GetBSphere().GetRadius());
            }
            l_iter++;
        }
        a_iter++;
    }

    //Do the deletions
    std::list<Laser*>::iterator l_iter = l_tbd.begin();
    while(l_iter != l_tbd.end())
    {
        lasers.remove(l_iter._Ptr->_Myval);
        l_iter++;
    }
    a_iter = a_tbd.begin();
    while(a_iter != a_tbd.end())
    {
        asteroids->remove(a_iter._Ptr->_Myval);
        a_iter++;
    }
}