Esempio n. 1
0
void EChesses::lin() {
    Entiles::lin();
    if(b_CanMove) {
        b2Vec2 vel = m_body->GetLinearVelocity();

        b2Vec2 desiredVel = b2Vec2(0,0);

        switch(state) {
        case 0:
        {
            switch ( direc )
            {
            case MS_LEFT:
                desiredVel = b2Vec2(-4,2);
                break;
            case MS_STOP:
                desiredVel =  b2Vec2(0,0);
                break;
            case MS_RIGHT:
                desiredVel =  b2Vec2(4,-2);
                break;
            case MS_UP:
                desiredVel = b2Vec2(4,2);
                break;
            case MS_DOWN:
                desiredVel = b2Vec2(-4,-2);
                break;
            }

            break;
        }
        case 1:
        {
            CCPoint cur = GameManager::sharedLogicCenter()->ml->tm->m_checkPoint(ccp(m_body->GetPosition().x,m_body->GetPosition().y));
            DecideDirect(cur,desiredVel);
            break;
        }
        }

        if(direc != MS_STOP) stand = direc;

        float velChangeX = desiredVel.x - vel.x;
        float velChangeY = desiredVel.y - vel.y;
        float impulseX = m_body->GetMass() * velChangeX; //disregard time factor
        float impulseY = m_body->GetMass() * velChangeY;
        m_body->ApplyLinearImpulse( b2Vec2(impulseX,impulseY), m_body->GetWorldCenter() );


        b_Dirty = true;
    }

}
Esempio n. 2
0
void EChesses::lin(){
	Entiles::lin();
	if(b_CanMove){
		b2Vec2 vel = m_body->GetLinearVelocity();
		
		b2Vec2 desiredVel = b2Vec2(0,0);
		float tfRate = mfBaseRate * mfAdditRate;

		switch(state){
		case 0:
			{
				switch ( direc )
				{
#if (WM_TYPE == MAP_TYPE_ISO)
				case MS_LEFT:  desiredVel = b2Vec2(-4,2); break;
				case MS_STOP:  desiredVel =  b2Vec2(0,0); break;
				case MS_RIGHT: desiredVel =  b2Vec2(4,-2); break;
				case MS_UP: desiredVel = b2Vec2(4,2); break;
				case MS_DOWN: desiredVel = b2Vec2(-4,-2); break;
#else
				case MS_LEFT:  desiredVel = b2Vec2(-4,0); break;
				case MS_STOP:  desiredVel =  b2Vec2(0,0); break;
				case MS_RIGHT: desiredVel =  b2Vec2(4,0); break;
				case MS_UP: desiredVel = b2Vec2(0,4); break;
				case MS_DOWN: desiredVel = b2Vec2(0,-4); break;
#endif
				}
				//////////////////////////////////////////////////////////////////////////
				if(direc != MS_STOP){
					stand = direc;
					m_animator->PlayAnim(CCString::createWithFormat("paodong_%s",sDirect[direc])->getCString());
				}else{
					m_animator->PlayAnim(CCString::createWithFormat("stand_%s",sDirect[stand])->getCString());
					m_bMoving = false;
					//FixPosition();
					FixTar();
				}
				break;
			}
		case 1:
			{
				CCPoint cur = GameManager::sharedLogicCenter()->ml->tm->m_checkPoint(ccp(m_body->GetPosition().x,m_body->GetPosition().y));
				DecideDirect(cur,desiredVel);
				//////////////////////////////////////////////////////////////////////////
				if(direc != MS_STOP){
					stand = direc;
					m_animator->PlayAnim(CCString::createWithFormat("paodong_%s",sDirect[direc])->getCString());
				}else{
					m_animator->PlayAnim(CCString::createWithFormat("stand_%s",sDirect[stand])->getCString());
					m_bMoving = false;
					FixTar();
					//FixPosition();
				}
				break;
			}
		case 3:
			{
				m_animator->setDirect(stand);
				break;
			}
		case 4:
			{
				//CCLog(">[EChess] lin() | Upadate| %s", name.c_str());
				CCPoint cur = GameManager::sharedLogicCenter()->ml->tm->m_checkPoint(ccp(m_body->GetPosition().x,m_body->GetPosition().y));
				DecideDirect(cur,desiredVel);
				//////////////////////////////////////////////////////////////////////////
				if(direc != MS_STOP){
					stand = direc;
				}else{
					CCLog(">[EChess] lin() | Move ends normaly. | %s", name.c_str());
					m_bMoving = false;
					state = 3;
					mfAdditRate = 1;
					FixPosition();
				}
				break;
			}
		}



		float velChangeX = desiredVel.x * tfRate - vel.x;
		float velChangeY = desiredVel.y * tfRate - vel.y;
		float impulseX = m_body->GetMass() * velChangeX; //disregard time factor
		float impulseY = m_body->GetMass() * velChangeY;
		m_body->ApplyLinearImpulse( b2Vec2(impulseX,impulseY), m_body->GetWorldCenter() );
		


		b_Dirty = true;
	}

}