예제 #1
0
파일: GameWorld.cpp 프로젝트: Soxs/PMRGame
void GameWorld::update(float delta) {

    scoreTextLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(100, 100))));
    
    scoreLabel->setString(std::to_string(scoreManager->getScore()));
    pointlocation = this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(110, 130)));
    scoreLabel->setPosition(pointlocation);
    
    heartsprite->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(30, 60))));
    
    healthLabel->setString(std::to_string(player->currentHealth));
	healthLabel->setPosition(this->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(ccp(114, 60))));
    
    //Update the player.
    player->update(delta);
    
    //Update all the npcs.
    for (Entity* e : *npcManager->getNpcs()) {
        if (IsType<Crowd>(e)) {
            Crowd* c = static_cast<Crowd*>(e);
            c->update(delta);
        } else if (IsType<Helicopter>(e)) {
            Helicopter* h = static_cast<Helicopter*>(e);
            h->update(delta);
        } else
            e->update(delta);
    }
    
    //Update all the broken buildings.
    for (BrokenStructure* b : *structureManager->getStructures()) {
        b->update(delta);
    }
    
}
예제 #2
0
void SimulationWriter::writeOut(Crowd& c)
{
  XMLElement* ticknode = _doc.FirstChildElement("simulation")
    ->FirstChildElement("ticks")->ToElement();

  XMLElement* currenttick = _doc.NewElement("tick");
  currenttick->SetAttribute("num", c.age());
  ticknode->InsertEndChild(currenttick);

  for (size_t i = 0; i < c.size(); i++)
  {
    addVertex(currenttick, c.at(i));
  }
}
예제 #3
0
void CrowdApp::draw()
{
	gl::clear( Color::black() );
	gl::setMatricesWindow( getWindowSize());
	gl::enableAlphaBlending();

	glPushMatrix();
	glTranslatef( getWindowSize().x / 2, getWindowSize().y / 2.  /*+ 100*/,0 );
	mCrowd.draw();
	glPopMatrix();

	gl::disableAlphaBlending();
}
예제 #4
0
void CrowdApp::update()
{
	mCrowd.update();
}
예제 #5
0
void CrowdApp::mouseDown( MouseEvent event )
{
	if( event.isLeftDown())  mCrowd.energize( Rand::randFloat( 1.0f, 3.0f ));
	if( event.isRightDown()) mCrowd.wave    ( Rand::randFloat( 1.0f, 3.0f ));
}
예제 #6
0
void CrowdApp::setup()
{
	mCrowd.setup( 800, 600 );
}
예제 #7
0
void Spectator::onUpdateActivity(float dt)
{
    // spectator can become inactive when he is relaxing
    if( _active && _wish == wishRelax && _scene->getCamera() )
    {
        Matrix4f cameraPose = _scene->getCamera()->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        float distance = ( cameraPos - _clump->getFrame()->getPos() ).length();
        if( distance > activeRadius && _action->getActionTime() > _action->getBlendTime() )
        {
            _active = false;
        }
    }
    if( !_active && _scene->getCamera() )
    {
        Matrix4f cameraPose = _scene->getCamera()->getPose();
        Vector3f cameraPos( cameraPose[3][0], cameraPose[3][1], cameraPose[3][2] );
        float distance = ( cameraPos - _clump->getFrame()->getPos() ).length();
        if( distance < activeRadius ) _active = true;
    }

    if( !_active ) return;

    // fulfill wish
    switch( _wish )
    {
    case wishRelax: {
        // setup corresponding action
        if( !actionIs(Idle) || 
            _clump->getAnimationController()->getTrackAnimation(0) != &idleSequence )
        {
            delete _action;
            _action = new Character::Idle( _clump, &idleSequence, 0.2f, 1.0f );
        }
        // decrease relax time
        _relaxTime -= dt;
        if( _relaxTime < 0 ) _endOfWish = true;
        } break;
    case wishGoto: {
        // obtain distance vector to desired position
        Vector3f distance = _gotoPos - _clump->getFrame()->getPos();
        if( distance.length() > _gotoError )
        {
            // if i am did not moves yet
            if( !actionIs(Move) )
            {
                // obtain angle to desired pos
                Vector3f direction = distance;
                direction[1] = 0.0f;
                direction.normalize();
                float angle = calcAngle( direction, _clump->getFrame()->getAt(), Vector3f( 0,1,0 ) );
                // if angle too large, i will turns
                if( fabs( angle ) > 5.0f )
                {
                    if( !actionIs(Turn) )
                    {
                        delete _action;
                        _action = new Turn( _clump, direction );
                    }
                }
                // else i will move
                else if( !actionIs(Move) )
                {
                    delete _action;
                    _action = new Move( _clump, _enclosure, _gotoPos, false );
                }
            }
            // if wish is undesirable, reject it
            else if( _action->isEndOfAction() )
            {
                _endOfWish = true;
            }
        }
        else
        {
            _endOfWish = true;
        }
        } break;
    case wishWatch: {
        // simulate delay due to character orientation
        _watchDelay -= dt;
        if( _watchDelay > 0 ) break;
        // obtain distance vector to desired position
        Vector3f distance = _watchPos - _clump->getFrame()->getPos();
        // obtain angle to desired pos
        Vector3f direction = distance;
        direction[1] = 0.0f;
        direction.normalize();
        float angle = calcAngle( direction, _clump->getFrame()->getAt(), Vector3f( 0,1,0 ) );
        // if angle too large, i will turns
        if( fabs( angle ) > 5.0f )
        {
            if( !actionIs(Turn) )
            {
                delete _action;
                _action = new Turn( _clump, direction );
            }
        }
        else
        {
            if( !actionIs(Idle) ||
                _clump->getAnimationController()->getTrackAnimation( 0 ) != &watchSequence )
            {
                delete _action;
                _action = new Character::Idle( _clump, &watchSequence, 0.2f, 1.0f );
            }
        }
        // decrease watch time
        _watchTime -= dt;
        if( _watchTime <= 0 ) _endOfWish = true;
        } break;
    }

    // end of wish?
    if( _endOfWish )
    {
        // complete previous wish
        if( _wish == wishGoto )
        {
            Crowd* crowd = dynamic_cast<Crowd*>( _parent ); assert( crowd );
            crowd->endWalk();
        }

        // choose new wish
        if( _wish != wishRelax )
        {
            _wish = wishRelax;
            _relaxTime = getCore()->getRandToolkit()->getUniform( wishRelaxTimeMin ,wishRelaxTimeMax );
        }
        else
        {
            // request for a walk
            Crowd* crowd = dynamic_cast<Crowd*>( _parent ); assert( crowd );
            if( crowd->beginWalk() )
            {
                _wish = wishGoto;
                _gotoPos = _enclosure->place();
                _gotoError = 100.0f;
            }
            else
            {
                _wish = wishRelax;
                _relaxTime = getCore()->getRandToolkit()->getUniform( wishRelaxTimeMin ,wishRelaxTimeMax );
            }
        }
        _endOfWish = false;
    }

    // inherited behaviour
    Character::onUpdateActivity( dt );
}