コード例 #1
0
ファイル: game.cpp プロジェクト: mcdooda/flat-engine
void Game::loop()
{
	bool running = true;
	while (running)
	{
		FLAT_PROFILE("Frame");
		
		time->beginFrame();

		input->pollEvents();
		
		{
			FLAT_PROFILE("Game state update");
			getStateMachine().update();
		}

		{
			FLAT_PROFILE("Lua end frame");
			message->update();
			lua->endFrame();
		}

		{
			FLAT_PROFILE("Video end frame");
			video->endFrame();
		}

		time->endFrame();

		running = !input->window->isClosed() && !m_stop;
	}
}
コード例 #2
0
ファイル: IntroState.cpp プロジェクト: ace13/LD29
void IntroState::update(double dt)
{
	mTime += dt / 6;

	mCard.update(dt);

	if (getInputs()["MenuExit"].pressed())
		mTime = 1;

	if (mTime > 1)
	{
		auto stateKeeper = getStateMachine().curState();
		getStateMachine().popState();
		getStateMachine().pushState(new MenuState());
	}
}
コード例 #3
0
void MainMenuState::render(){
	sf::RenderWindow* graphics = getStateMachine()->getGraphics();
	graphics->draw(background);
	graphics->draw(menu_background);
	graphics->draw(new_game_button);
	graphics->draw(quit_game_button);
	graphics->draw(game_logo);
	graphics->draw(cursor_sprite);
}
コード例 #4
0
void MainMenuState::handleKeyPresses(){

		
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){

		StateMachine* s_mach = getStateMachine();
		s_mach->change(LOCAL_MAP_STATE);
		//s_machine->change(LOCAL_MAP_STATE);
	}
}
コード例 #5
0
ファイル: EnemyObjNormal.cpp プロジェクト: kuronokurujp/stg
/*
    @brief  通常敵
*/
bool        EnemyObjNormal::init()
{
    if ( EnemyObjBase::init() == false ) {
        return false;
    }

    //  しょっぱなから移動する。
    getStateMachine().setState( eSTATE_MOVE );
    
    schedule( schedule_selector( EnemyObjNormal::_update ) );
    
    return true;
}
コード例 #6
0
ファイル: EnemyObjNormal.cpp プロジェクト: kuronokurujp/stg
//  ヒット時のコールバック
void    EnemyObjNormal::onHit( HitTargetInterface* in_pHitTargetInterface )
{
    StateMachine&   state   = getStateMachine();

    const char* pHitTargetName  = in_pHitTargetInterface->getHitTargetName();
    if ( strcmp( pHitTargetName, MyBulletInterface::spTargetName_ ) ) {
        //  自機の攻撃をくらったのでHPが減る
        state.setState( eSTATE_DAMAGE );
    }
    else if ( strcmp( pHitTargetName, MyShipInterface::spHitTargetName_ ) ) {
        //  自機と接触したので消滅
        state.setState( eSTATE_DIE );
    }
}
コード例 #7
0
ファイル: EnemyObjNormal.cpp プロジェクト: kuronokurujp/stg
void    EnemyObjNormal::_update( float dt )
{
    StateMachine&   state   = getStateMachine();
    
    const eSTATE  nowState    = (eSTATE)state.getState();
    if ( nowState == eSTATE_MOVE ) {
        //  プレイヤーに近寄る
        std::list< MyShipFacade* >&  shipList    = MyShipFacade::list();
        if ( shipList.empty() == false ) {
            CCPoint endPos  = CCPointZero;
            
            std::list< MyShipFacade* >::iterator    it  = shipList.begin();
            for ( ; it != shipList.end(); ++it ) {
                MyShipFacade*   pShipFacade = (*it);
                endPos  = pShipFacade->getShipInterface()->getObjNode()->getPosition();
                break;
            }
            
            CCPoint startPos    = getPosition();
            CCPoint dirVec  = ( endPos - startPos ).normalize();
            
            CCPoint nextPos = startPos + dirVec;
            setPosition( nextPos );
        }
    }
    else if ( nowState == eSTATE_DAMAGE ) {
        int subState    = state.getChildState( 0 );
        if ( subState == 0  ) {
            const int   nowHp   = getNowHp();
            int newHp   = nowHp - 1;
            if ( newHp <= 0 ) {
                state.setState( eSTATE_DIE );
            }

            setNowHp( newHp );
        }
    }
    else if ( nowState == eSTATE_DIE ) {
        //  自分を消滅してメモリから削除する時に使う。
        removeFromParentAndCleanup( true );
    }
}
コード例 #8
0
ファイル: FieldPlayer.cpp プロジェクト: LiuJack/FootballAI
void FieldPlayer::onUpdate(double time_diff)
{
	this->mIsUpdatingAfterChange = (time_diff == 0);

	mStateMachine->onUpdate();

	// Update here
	mSteeringBehaviors->calculateDrivingForce();

	// Apply a small rotation 
	Ogre::Quaternion rotation = getRotation();
	Ogre::Vector3 current_velocity = getVelocity();
	Ogre::Vector3 current_heading = rotation * Ogre::Vector3(0, 0, 1);

	float velocity_magnitude = current_velocity.length();
	Ogre::Vector3 driving_force = mSteeringBehaviors->getSteeringForce();


	btTransform trans = mPhysicsBody->getRigidBody()->getWorldTransform();
	btMotionState* motion = mPhysicsBody->getRigidBody()->getMotionState();

	if (driving_force.length() > EPS)
	{
		Ogre::Radian angle = current_heading.getRotationTo(driving_force).getYaw();

		if (angle > Ogre::Radian(mTurnRate))
			angle = Ogre::Radian(mTurnRate);

		if (angle < Ogre::Radian(-mTurnRate))
			angle = Ogre::Radian(-mTurnRate);

		float accumulate_force = current_heading.dotProduct(driving_force);

		// If at the same line
		if (fabs(angle.valueRadians()) < 1e-3 && accumulate_force < 0)
			angle = mTurnRate;

        rotation = rotation * Ogre::Quaternion(angle, Ogre::Vector3(0, 1, 0));

		trans.setRotation(BtOgre::Convert::toBullet(rotation));

		velocity_magnitude += accumulate_force;
		
		if (velocity_magnitude < 0)
			velocity_magnitude = 0;
	} 
	else 
	{
		velocity_magnitude *= 0.8;
	}

	// Is at target
	if (mIsTurnningAroundAtTarget != Ogre::Radian(0))
	{
		rotation = rotation * Ogre::Quaternion(mIsTurnningAroundAtTarget, Ogre::Vector3(0, 1, 0));
		trans.setRotation(BtOgre::Convert::toBullet(rotation));
	}

	if (velocity_magnitude > mMaxSpeed)
		velocity_magnitude = mMaxSpeed;

	// About animation
	if (velocity_magnitude < 1e-6)
		mMesh->stopAnimation();
	else
		mMesh->playAnimation();

	// Set velocity 
	mVelocity = rotation * Ogre::Vector3(0, 0, velocity_magnitude);

	trans.setOrigin(trans.getOrigin() + BtOgre::Convert::toBullet(mVelocity) * 0.02);
	motion->setWorldTransform(trans);

	mIsTurnningAroundAtTarget = Ogre::Radian(0);

	setDebugText(getStateMachine()->getNameOfCurrentState());
	//setDebugText(dt::Utils::toString(getSteering()->getTarget()));
	//DEBUG_MODE_BEGIN
	//setDebugText(dt::Utils::toString(getSteering()->getSteeringForce()));
	//DEBUG_MODE_END

	dt::Node::onUpdate(time_diff);
}
コード例 #9
0
ファイル: Screen.cpp プロジェクト: antidotcb/stellabella
 CGame* CScreen::getContainer() {
     return dynamic_cast<CGame*>(getStateMachine());
 }