Beispiel #1
0
void Level::playerDied()
{
    Player::getInstance()->getPlayerState()->setSpeed(0.0f);
    Player::getInstance()->resetPosition();
    ((LazyCameraManipulator *)viewer.getCameraManipulator())->resetCamera();
    
    _headUpDisplay->resetTimer();
    _numDeaths++;
}
Beispiel #2
0
void startApplication()
{
	startMenu->hideAll();	
	
	osg::ref_ptr<osg::Node> groundRoot = genWorld(filename);
	root->addChild(groundRoot);

	osg::ref_ptr<FirstPersonController> controller = new FirstPersonController(&viewer);
    	viewer.setCameraManipulator(controller);

	// Add main HUD
    	mainHud = new hud(&viewer);
    	root->addChild(mainHud->_camera);

	// Set user position (aka camera)
	    osg::Vec3d eye( 0.0, -1.0, 0.0 );
	    osg::Vec3d center( 0.0, 0.0, 0.0 );
	    osg::Vec3d up( 0.0, 0.0, 90.0 );

	    viewer.getCameraManipulator()->setHomePosition(eye, center, up);
	    viewer.home();
}
Beispiel #3
0
void LevelUpdater::operator()(osg::Node *node, osg::NodeVisitor *nv)
{    
    double currentStepTime = viewer.getFrameStamp()->getSimulationTime();
    
    // compensate error arising from the osg::Viewer resetting its SimulationTime
    if(currentStepTime - _previousStepTime < 0.0f)
    {
        Player::getInstance()->resetPosition();
        ((LazyCameraManipulator *)viewer.getCameraManipulator())->resetCamera();        
        _previousStepTime = currentStepTime - 0.5;        
    }
    
    int numSimulationSubSteps = _level->getPhysicsWorld()->stepSimulation(currentStepTime - _previousStepTime, 
                                        (int)((currentStepTime - _previousStepTime) * 60.0f) + 1); 
                                        
    ((LazyCameraManipulator *)viewer.getCameraManipulator())->setNumSimulationSubSteps(numSimulationSubSteps);
       
    _previousStepTime = currentStepTime;
    
    // player dies when falling too low
    {
        btVector3 position = Player::getInstance()->getController()->getGhostObject()->getWorldTransform().getOrigin();
        int yBucketIndex = (int)(position.y() / 20.0f);
    
        if(yBucketIndex >= _level->getDeadlyAltitudes().size())
            yBucketIndex = _level->getDeadlyAltitudes().size() - 1;

        float minimum = min(_level->getDeadlyAltitudes()[yBucketIndex], 
                            (_level->getDeadlyAltitudes())[yBucketIndex + 1]);

        if(position.z() < (minimum - 5.0f))
            _level->playerDied();
    }
    
    // fade out when level is finished
    osg::Vec4 constantBlendColor = _blendColor->getConstantColor();
    float alpha = constantBlendColor.a();
    
    // player reached finish
    {
        osg::Vec3 position = Player::getInstance()->getPosition();
        std::vector<osg::Vec3> finishs = _level->getFinishs();

        for(size_t i = 0; i < finishs.size(); i++)
        {
            float maxDistance = 1.0f;
            osg::Vec3 diff = position - finishs[i];
            
            if(diff.x() < maxDistance && diff.x() > -maxDistance &&
                diff.y() < maxDistance * 3.0f && diff.y() > -maxDistance &&
                diff.z() < maxDistance && diff.z() > -maxDistance)
                {
                    if(alpha == 1.0f)
                    {
                        alpha -= 0.01f;
                        _level->getHeadUpDisplay()->stopTimer();
                        viewer.getEventHandlers().remove(_level->getKeyboardHandler());
                        ((LazyCameraManipulator *)viewer.getCameraManipulator())->fadeOut();
                        Player::getInstance()->getPlayerState()->setRequestAccelerate(false);
                        Player::getInstance()->getPlayerState()->setRequestDecelerate(true);
                    }                    
                }
        }
        
        if(alpha < 1.0f)
        {
            alpha -= 0.01f;

            if(alpha <= 0.0f)
            {
                alpha = 0.0f;                 
                _level->setReachedFinish(true);
            }

            constantBlendColor[3] = alpha;

            _blendColor->setConstantColor(constantBlendColor);
        }
    }
    
    traverse(node, nv);
}