Beispiel #1
0
bool Hero::receiveCommand(CommandID commandID, void* data)
{
    Controller::receiveCommand(commandID, data);
    
    switch (commandID)
    {
        case HERO_MOVE_LEFT:
            move(LEFT);
            break;
        case HERO_MOVE_RIGHT:
            move(RIGHT);
            break;
        case HERO_MOVE_STOP:
            stopMove();
            break;
        case HERO_MOVE_JUMP:
            jump();
            break;
        case HERO_ATTACK_0:
            playSkill(NORMAL_ATTACK);
            break;
        case HERO_ATTACK_1:
            playSkill(SKILL_1);
            break;
        case HERO_ATTACK_2:
            playSkill(SKILL_2);
            break;
        default:
            break;
    }
    
    return true;
}
Beispiel #2
0
/**
 * 移动动画步骤
 * 通过方向移动的动画步骤
 */
void SimpleMoveComponent::updateDirection( float delta)
{
    CCNode* owner=(CCNode*)m_pOwner;
    
    CCPoint pos=owner->getPosition();
	//根据速度计算移动距离
    float s=delta*10;
	pos.x+=s*m_speedX;
	pos.y+=s*m_speedY;
    
//    CCLOG("x:%f,y:%f",pos.x,pos.y);
	//判断是否结束	
	if (m_hasEndPosition && (m_directionFlagX * pos.x>m_directionFlagX*m_to.x  || fabs(pos.x-m_to.x)<0.00001) &&  (m_directionFlagY*pos.y> m_directionFlagY* m_to.y|| fabs(pos.y-m_to.y)<0.00001)) {
		pos.x=m_to.x;
		pos.y=m_to.y;
//		
//		if (m_moveState==MoveContinue) {
//
//            m_moveState=MoveStart;
//            m_direction=m_nextDirection;
//            m_speedX=m_speed*cosf(m_direction);
//            m_speedY=m_speed*sinf(m_direction);
//            if(beforeMove()){
//                
//            }
//
//		}else {
//			//stop move
//			m_moveState=MoveWillStop;//标记将要结束
			stopMove();
//		}
	}
	owner->setPosition(pos);
}
Beispiel #3
0
void WindowManager::setActiveLayout( TopWindow &rWindow,
                                     GenericLayout &rLayout )
{
    rWindow.setActiveLayout( &rLayout );
    // Rebuild the dependencies
    stopMove();
}
bool MovingEffect::moveStep() {
	if(isMoving() && !move_path.empty()){
		loc = move_path.back();
		move_path.pop_back();
		return true;
	}
	stopMove();
	return false;
}
Beispiel #5
0
void littleMovement()
{
    switch(direcao) {
   
    case 1:
    moveForward();
    delay(600);
    stopMove();
    delay(300);
    break;
 
    case 0:
    moveBackwards();
    delay(100);
    stopMove();
    delay(600);
    break;
  }
} 
Beispiel #6
0
void mediumMovement()
{
    switch(direcao) {
   
    case 1:
    moveForward();
    delay(1800);
    stopMove();
    delay(400);
    break;
 
    case 0:
    moveBackwards();
    delay(1800);
    stopMove();
    delay(400);
    break;
  }
} 
Beispiel #7
0
void crazyMovement()
{
  int i;
  for(i=0; i<1000; i++)
    stopMove();
    moveForward();
    delay(100);
    moveBackwards();
    delay(100);
}
void BoardActor::moveStep(){
	if(isMoving()){
		if(move_path.empty()){
			stopMove();
			return;
		}
		screen_location = move_path.back();
		location = Util::screenToCoord(screen_location);
		move_path.pop_back();
	}
}
//Collision Detection: Receive co-ordinates from the robot nodes and calculates the distances between them and this robot. If the distance is less than the distance limit, stop robot.
void coordinateCallback(project1::move mo)
{	
	
	double delta_x;
	double delta_y;
	double distance;
	delta_x = px - mo.x;
	delta_y = py - mo.y;
	distance = sqrt(delta_x*delta_x + delta_y*delta_y);
	if (distance< 0.8){
		stopMove();
	}
}
Beispiel #10
0
void WindowManager::unmaximize( TopWindow &rWindow )
{
    // Register the window to allow moving it
//     registerWindow( rWindow );

    // Resize the window
    // FIXME: Ugly const_cast
    GenericLayout &rLayout = (GenericLayout&)rWindow.getActiveLayout();
    startResize( rLayout, kResizeSE );
    resize( rLayout, m_maximizeRect.getWidth(), m_maximizeRect.getHeight() );
    stopResize();
    // Now move it
    startMove( rWindow );
    move( rWindow, m_maximizeRect.getLeft(), m_maximizeRect.getTop() );
    stopMove();
    rWindow.m_pVarMaximized->set( false );
}
Beispiel #11
0
void CEntity::onLoop( float dt )
{
    //We're not Moving
    if(moveLeft == false && moveRight == false && speed.y == 0) 
        stopMove();
    
    if(moveLeft) {
        accel.x += -ACC_WALK;
    }else if(moveRight) {
        accel.x += ACC_WALK;
    }

    if(flags & ENTITY_FLAG_GRAVITY) {
        accel.y += GRAVITY;
    }

    speed.x += accel.x * dt;
    speed.y += accel.y * dt;

    if(speed.x > maxSpeed.x)  speed.x =  maxSpeed.x;
    if(speed.x < -maxSpeed.x) speed.x = -maxSpeed.x;
    if(speed.y > maxSpeed.y)  speed.y =  maxSpeed.y;
    if(speed.y < -maxSpeed.y) speed.y = -maxSpeed.y;

    onAnimate();
    
		sf::Vector2f dv = speed*dt;

		//std::cout << "move:" << dv.x << "	" << dv.y << " || accel: " << accel.x << "	" << accel.y << std::endl;

		onMove(dv);

		//Update Sprite
		mEntitySprite.setPosition(pos);

		//Update Bound
		bound.top = pos.y + (size.y * mEntitySprite.getScale().y)/2 - bound.height/2;
		bound.left = pos.x + (size.x * mEntitySprite.getScale().x)/2 - bound.width/2;

		//Reset force
		accel.x=0;
		accel.y=0;
}
Beispiel #12
0
void CPlayer::OnUpdate( float time )
{
	if (live)
	{
		//vel=(goalPoint-getCenter()).normalize()*speed;
		if((goalPoint-getCenter()).getLenght()<size.x/2)
		{
			hasGoal=false;
		}
		if(hasGoal)
		{
			acc=(goalPoint-getCenter()).normalize()*speed;;
		}
		else
		{
			stopMove();
		}
		
		CMoveObject::OnUpdate(time);
	}
}
Beispiel #13
0
//------------------------------------------------------------------------------
void Entity::logic() {
    //We're not moving
    if(moveDown == false && moveLeft == false && moveRight == false && moveUp == false)
    {
        stopMove();
    }
    if(moveLeft)
    {
        accel = 0.5;
    }
    if(flags & ENTITY_FLAG_GRAVITY)
    {
        //Flat Surface
    }
    speed += accel * FPS::FPSControl.getSpeedFactor();

    if(speed > maxSpeed)
        speed = maxSpeed;

    animate();
    move();
}
void
coVR1DTransInteractor::preFrame()
{
   keepSize();
   if (!cover->isPointerLocked() && !cover->isNavigating() && !interactionOngoing && isSelected() && (cover->getButton()->getButtonStatus() /*==  ACTION_BUTTON*/) )
   {

      startMove();
      interactionOngoing = true;
   }
   if (interactionOngoing)
   {
      if (cover->getButton()->wasReleased() )
      {
         stopMove();
         interactionOngoing = false;
      }
      else
         move();
   }

}
Beispiel #15
0
void WindowManager::maximize( TopWindow &rWindow )
{
    // Save the current position/size of the window, to be able to restore it
    m_maximizeRect = SkinsRect( rWindow.getLeft(), rWindow.getTop(),
                               rWindow.getLeft() + rWindow.getWidth(),
                               rWindow.getTop() + rWindow.getHeight() );

    SkinsRect workArea = OSFactory::instance( getIntf() )->getWorkArea();
    // Move the window
    startMove( rWindow );
    move( rWindow, workArea.getLeft(), workArea.getTop() );
    stopMove();
    // Now resize it
    // FIXME: Ugly const_cast
    GenericLayout &rLayout = (GenericLayout&)rWindow.getActiveLayout();
    startResize( rLayout, kResizeSE );
    resize( rLayout, workArea.getWidth(), workArea.getHeight() );
    stopResize();
    rWindow.m_pVarMaximized->set( true );

    // Make the window unmovable by unregistering it
//     unregisterWindow( rWindow );
}
void loop() {

    if ((unsigned long) (millis() - previousEth) >= interval_ethernet) { //entra a cada 50ms
        previousEth = millis();
        if(count_eth == 0) { //espera completar um ciclo de todas as funções chamadas
            int packetSize = Udp.parsePacket();
            count_eth = 2;
            Serial.println("entrou eth");
            received = 0;
            if (packetSize) {
                set_debug(PC3);

#ifdef debug
                Serial.println("entrou eth RX ");
                Serial.print("Received packet of size ");
                Serial.println(packetSize);
                Serial.print("From ");
                IPAddress remote = Udp.remoteIP();
                for (int i =0; i < 4; i++)
                {
                    Serial.print(remote[i], DEC);
                    if (i < 3)
                    {
                        Serial.print(".");
                    }
                }
                Serial.print(", port ");
                Serial.println(Udp.remotePort());

                Serial.println("Contents:");
                Serial.println(packetBuffer);
#endif
                received = Udp.read();
                charBuffer.put(received);

#ifdef debug
                Serial.println("\rchar recebido:");
                Serial.write(received);
#endif

                /////////////////////////////
                clear_debug(PC3);
            }
        } else {
            count_eth--;
            Serial.println("entrou eth NADA");
            if (charBuffer.getSize() > 5) charBuffer.clear();
            if( charBuffer.getSize() > 0 )
                received = charBuffer.get();
            Serial.println("received:");
            Serial.println(received);

        }
    }
#ifdef debug
    Serial.println("client disconnected");
#endif
    /****************FIM ROTINA ETHERNET ***************************************************/


    if ((unsigned long) (millis() - previousADC) >= interval_adc) { //entra a cada 60ms
        previousADC = millis();
        set_debug(PC4);
        if (count_adc == 0) {
            count_adc = 1;
            /*testa obstaculo IR*/
            Serial.println("entrou adc OBSTACULO ");

            IR_obstaculo = 0;
            IR_obstaculo = verificaObstaculoIR();
#ifdef debug
            Serial.println("distancia_ir");
            Serial.println(IR_obstaculo);
            Serial.println("\r");
#endif
            if (IR_obstaculo > IR_OBSTACLE_THRESHOLD)
                obstacle_flag = 0;
            else if (IR_obstaculo > IR_OBSTACLE_THRESHOLD
                    && IR_obstaculo < IR_OBSTACLE_UPPER_THRESHOLD)
                obstacle_flag = 1;
            else if (IR_obstaculo <= IR_OBSTACLE_THRESHOLD)
                obstacle_flag = 2;
            clear_debug(PC4);
        } else {
            count_adc=0;
            Serial.println("entrou adc NADA ");

        }
    }

    /***************** FIM ROTINA ADC********************************/

    if ((unsigned long) (millis() - previousMotores) >= interval_motores) { //entra a cada 100ms
        previousMotores = millis();

        if (ciclosClock_motor == 2) { //duas bordas de subida depois de acionar o motor (200ms depois de acionar o motor)
            Serial.println("motor stop ");
            stopMove();
            ciclosClock_motor = 0;
        }
        if (count_motor == 0) {
            Serial.println("motor ANDA ");

            if (obstacle_flag == 0 || obstacle_flag == 1) {
                count_motor = 1;
                /*move motores*/
                switch (received) {
                case 'u':
                    goForward(obstacle_flag);
                    break;
                case 'd':
                    goBack(obstacle_flag);
                    break;
                case 'l':
                    goLeft(obstacle_flag);
                    break;
                case 'r':
                    goRight(obstacle_flag);
                    break;
                default:
                    received = 0;
                    stopMove();
                    break;
                }
            } else {
                if (received == 'd') {
                    goBack(WITH_CARE);
                } else {
                    stopMove();
                }
            }
        } else {
            ciclosClock_motor++;
            count_motor = 0;
            Serial.println("ciclosClock_motor++ ");
        }

    }
    // _delay_ms(500);
}
Beispiel #17
0
//-------------------------------------------------------------------------------------
PyObject* Entity::pyStopMove()
{
	return PyBool_FromLong(stopMove());
}
Beispiel #18
0
void WindowManager::stopResize()
{
    // Nothing different from stopMove(), luckily
    stopMove();
}
Beispiel #19
0
int main(void) {
    float distanceNear = kDistanceNearInitial;
    ControllMode currentMode = ControllModeSearching;
    int approachCount = 30000, backOffCount = 0;
    int iDontKnowCountPrimary = 30, iDontKnowCountSecondary = 500;
    bool USSensorWorking = false;
    distance = usSensor.getResult();
    if(distance > kApproachDistanceMin && distance < distanceNear) USSensorWorking = true;
    int programCount = 0;

    systemConfig();
    stopMove();
    delay(200);
    beginMoveForward();
    delay(75);
    beginTurnRight();
    delay(9);
    stopMove();
    delay(100);
    beginMoveForward();
    delay(100);
    beginTurnRight();
    delay(5);
    beginMoveForward();
    delay(150);
    beginMoveBackward();
    delay(8);
    beginTurnRight();
    delay(40);
    beginMoveForward();
    delay(60);
    beginMoveBackward();
    delay(30);
    beginTurnRight();
    delay(40);
    beginMoveForward();
    delay(60);
    beginMoveBackward();
    delay(30);
    while (true) {
        // Stop watchdog timer to prevent time out reset
        WDTCTL = WDTPW + WDTHOLD;
        /*programCount ++;
        if (programCount == 0xffff) {
            WDTCTL = WDTPW|0xff00;
        }
                */
        //delay(10);
        usSensor.beginSensing();
        distance = usSensor.getResult();
        USSensorWorking = false;
        if(distance > kApproachDistanceMin && distance < distanceNear) USSensorWorking = true;
        switch (currentMode) {

        case ControllModeSearching:
            if (USSensorWorking) {
                beginMoveForward();
                if (currentMode != ControllModeApproaching) {
                    approachCount = kApproachCountMax;
                }
                currentMode = ControllModeApproaching;
            }
            else {
                beginTurnLeft();
                iDontKnowCountPrimary --;
                if (iDontKnowCountPrimary == 0) {
                    iDontKnowCountPrimary = 10;
                    iDontKnowCountSecondary --;
                    if (iDontKnowCountSecondary == 0) {
                        iDontKnowCountSecondary = 500;
                        currentMode = ControllModeIDontKnowWhatTheHellShouldIDo;
                    }
                }
            }
            break;

        case ControllModeIDontKnowWhatTheHellShouldIDo:
            beginMoveForward();
            iDontKnowCountPrimary --;
            if (iDontKnowCountPrimary == 0) {
                iDontKnowCountPrimary = 20;
                iDontKnowCountSecondary --;
                if (iDontKnowCountSecondary == 0) {
                    iDontKnowCountSecondary = 500;
                    currentMode = ControllModeSearching;
                }
            }
            break;

        case ControllModeApproaching:
            if(USSensorWorking) {
                beginMoveForward();
                delay(1);
                if(distance < 0.2)
                {
                    delay(240);
                    approachCount = kApproachCountMax;
                    currentMode = ControllModeBackingOff;
                }
                else if(distance < 0.5)
                {
                    approachCount = 600;
                }
                else if(distance < 1.0)
                {
                    approachCount = 1200;
                }
            }
            else {
                approachCount--;
                beginMoveForward();
                delay(1);
                if (approachCount <= 0) {
                    approachCount = kApproachCountMax;
                    currentMode = ControllModeBackingOff;
                }
            }
            /*
            if (distance < kApproachDistanceMin) {
                approachCount = 0;
                currentMode = ControllModeBackingOff;
            }
            */
            break;

        case ControllModeBackingOff:
            if (backOffCount == 0) {
                stopMove();
                beginRotateBackward(MotorLeft);
                delay(60);
            }
            beginMoveBackward();
            delay(120);
            /*
            backOffCount++;
            if (backOffCount >= kBackOffCountMax) {
            	        backOffCount = 0;
                                */
            currentMode = ControllModeSearching;
            //}
            break;
        }
    }
}
Beispiel #20
0
void loop()                    
{
 
  int luzTrasEsq = analogRead(ldrTrasEsq);
  int luzTrasDir = analogRead(ldrTrasDir);
  int luzFrenteEsq = analogRead(ldrFrenteEsq);
  int luzFrenteDir = analogRead(ldrFrenteDir);

  //int temperatura = analogRead(temperaturaPin);
  int umidade = analogRead(umidadePin);
  
  // DEBUGS
  Serial.print("\nluzTrasEsq:");
  Serial.print(luzTrasEsq);
  Serial.print("\nluzTrasDir:");
  Serial.print(luzTrasDir);
  
  Serial.print("\nluzFrenteEsq:");
  Serial.print(luzFrenteEsq);
  Serial.print("\nluzFrenteDir:");
  Serial.print(luzFrenteDir);
  
  Serial.print("\n\n\n");
  Serial.print("\nUmidade:");
  Serial.print(umidade);
 
  colisaoFrenteHappened(); 
  colisaoTrasHappened();

  int luzFrente = (luzFrenteEsq+luzFrenteDir)/2;
  int luzTras = (luzTrasEsq+luzTrasDir)/2; 

  //Se umidade menor que limiar Umidade, executa movimento doidão
  if (umidade > limiarUmidade) {
     crazyMovement();
     // som de alegria \o/ águaaaaa eeeeeeeeeeeeeeeee :-D
     Serial.println("recebeu agua!");
     for (int i=0; i<5; i++) tone(soundPin, map(umidade, 600, 800, 1000, 2000), 100);
  }
 
  //Senão, verifiza luz
  else {
    Serial.print("\n\n #### Verificando luz!");
    // se a luz de um dos sensores estiver acima do limiar, planta fica parada
    if ((luzTras >= limiarLuz) || (luzFrente >= limiarLuz)) {
        Serial.print("\n\nfica parada!");
        stopMove();
        digitalWrite(backwards, 0);
        pinMode(backwards, INPUT);
        digitalWrite(forward, 0);
        pinMode(forward, INPUT);
     
    // senão, se movimenta em direção do sensor com mais luminosidade 
    }
    else {
      if (((luzTrasEsq > luzFrenteEsq*1.1) and (luzTrasEsq > luzFrenteDir*1.1)) or ((luzTrasDir > luzFrenteDir*1.1) and (luzTrasDir > luzFrenteEsq*1.1))) {
        Serial.print("\n\nandando pra trás!!");
          
        direcao = 0;
        mediumMovement();
                
        if (luzTrasEsq > luzTrasDir) { digitalWrite(left, 1); Serial.print("\n\nandando pra esquerda!!"); }
        else { Serial.print("\n\nandando pra direita!!"); digitalWrite(right, 1); }         
        colisaoTrasHappened();
        littleMovement();
        digitalWrite(left, 0);
        digitalWrite(right, 0);
      } else {
        Serial.print("\n\nandando pra frente!!");
        direcao = 1;
        littleMovement();
        
        if (luzFrenteEsq > luzFrenteDir) { digitalWrite(left, 1); Serial.print("\n\nandando pra esquerda!!"); }
        else { Serial.print("\n\nandando pra direita!!"); digitalWrite(right, 1); }           
        colisaoFrenteHappened();
        littleMovement(); 
      }
     
    }
  }
  
  // som do passo
  for (int i=0; i<5; i++) tone(soundPin, map(umidade, 600, 800, 1000, 2000), 10);
 
} 
Beispiel #21
0
void navigate(int direction, double distance)
{
	double dest = 0;

	distance = distance - 0.2;

	// Infrastructure
	ros::Rate loop_rate(loopRate);
	ros::NodeHandle n;
	geometry_msgs::Twist RobotNode_cmdvel;
	ros::Publisher RobotNode_stage_pub = n.advertise<geometry_msgs::Twist>("robot_11/cmd_vel",1000); 

	if (direction==0){ // Move East/right.
		// Rotating to face East with rotateToAngle().
		rotateToAngle(0);

		// Determine the destination co-ordinates.
		dest = px + distance;

		move();

		while(px<dest){
			//Break at position that is close enough
			if((dest-px)<posAllowance){
				break;
			}
			// Infrastructure
			RobotNode_cmdvel.linear.x = linear_x;
			RobotNode_cmdvel.angular.z = angular_z;
			RobotNode_stage_pub.publish(RobotNode_cmdvel);
			ros::spinOnce();
			loop_rate.sleep();			
		}

	}else if (direction==1){ // Move North/up.
		// Rotating to face North with rotateToAngle().
		rotateToAngle(M_PI/2);

		dest = py + distance;

		move();
		while(py<dest){
			//Break at position that is close enough
			if((dest-py)<posAllowance){
				break;
			}
			// Infrastructure
			RobotNode_cmdvel.linear.x = linear_x;
			RobotNode_cmdvel.angular.z = angular_z;
			RobotNode_stage_pub.publish(RobotNode_cmdvel);
			ros::spinOnce();
			loop_rate.sleep();
		}

	}else if (direction==2){ // Move West/left.
		// Rotating to face West with rotateToAngle().
		rotateToAngle(M_PI);
		
		dest = px - distance;

		move();
		while(px>dest){
			//Break at position that is close enough
			if((px-dest)<posAllowance){
				break;
			}

			// Infrastructure
			RobotNode_cmdvel.linear.x = linear_x;
			RobotNode_cmdvel.angular.z = angular_z;
			RobotNode_stage_pub.publish(RobotNode_cmdvel);
			ros::spinOnce();
			loop_rate.sleep();
		}

	}else{ // Move South/down.
		// Rotating to face South with rotateToAngle().
		rotateToAngle(-M_PI/2);
		
		dest = py - distance;

		move();
		while(py>dest){
			//Break at position that is close enough
			if((py-dest)<posAllowance){
				break;
			}

			// Infrastructure
			RobotNode_cmdvel.linear.x = linear_x;
			RobotNode_cmdvel.angular.z = angular_z;
			RobotNode_stage_pub.publish(RobotNode_cmdvel);
			ros::spinOnce();
			loop_rate.sleep();
		}
	}

	//Stop the robot's movement once at the destination
	stopMove();

	// Infrastructure
	RobotNode_cmdvel.linear.x = linear_x;
	RobotNode_cmdvel.angular.z = angular_z;
	RobotNode_stage_pub.publish(RobotNode_cmdvel);
	ros::spinOnce();
	loop_rate.sleep();

	//Spin again to ensure in correct position
	ros::spinOnce();
	loop_rate.sleep();
}
void MonsterAttRed::response(void)
{
	StyObj obj(identity,MONSTER_STYLE_TYPE);	
	vector<string> herId;	
	Point heroPt;
	Hero *perHero;		
	Nbox *box;
	
	if(map_now == NULL)
	{
		return;
	}
	
	box = map_now->getBox();
	
	if(box == NULL || !isAlive)
	{
		return;
	}	
	
	/*判断任务是否还在*/
	if(judgeTask())
	{
		cout<<"the task mon of the task is illeay:"<<endl;
		return;
	}
	
	if(!isPlayOver())
	{
	//	cout<<"it is playCd time:"<<endl;
		return;
	}
	
	memset(otherMsg,'\0',MONSTER_MSG_LENGTH + 1);	
	
	box->getStaInSrcVec(obj);	
	
	/*处理延时性技能*/
	hitedSkiFun();	
	
	/*判断地图是否有人,怪物是否已眩晕*/
	if(!dizz)     
	{
		stopMove();
		return;
	}

	/*回血功能*/
	recoverBloodSelf();
	
    /*这个是从仇恨列表里面得到的最高值,至于怎么得到的,则要看仇恨计算*/	
	if(flgRun)    
	{
		/*判断是否已定身*/
		if(!skiBody)
		{
			stopMove();
			return;
		}		
	}
	else
	{		
		
		/*终究还是专打红名了 add by chenzhen 201301300950*/
		redSchRge();
		
		if(!enmityValues.empty())
		{
			chageEny(((*(enmityValues.begin())).id)); 

			/*这个是从仇恨列表里面得到的最高值,至于怎么得到的,则要看仇恨计算*/
			perHero = getHero(perHerId); 
			if(perHero == NULL || !perHero->getLifeStation())
			{
				return;
			}
			
			heroPt = perHero->getLogPt();
			int fight_state = attackRangePoint(pt,perHero->getLocation(),attack_range);     
				
			if(fight_state != 1)
			{
				/*判断是否已定身*/
				if(!skiBody)
				{
					stopMove();					
					return;
				}
				
				 /*如果人物没动,则这次就不必要再寻一次路*/
                if(jdgSmePt(heroPt))
                {					
					findAttWay(heroPt);					
					isPersuitHero = true;
                }	
				
				isInPatrol = false;
			}
			
			else
			{
				stopMove();					
				exchageHat(herId);
				if(attackPoint && useSkill(herId))
				{					
					return;
				}
				attPerHero(otherMsg,sizeof(otherMsg),perHero);					
				box->sentBoxMsg(otherMsg);
			}			
		}
		else
		{	
			/*如果上次正在追人,而这次仇恨没人,则立即停下来*/
			if(isPersuitHero)
			{
				stopMove();
				
				isPersuitHero = false;
			}
			
			/*回血功能*/
	//		recoverBloodSelf();	
		
			if(Rec && !isInPatrol)
			{					
				/*判断是否已定身*/
				if(!skiBody)
				{
					stopMove();	
					return;
				}
				if(logic_pt == perLstPt)
				{
					Rec = false;
					return;	
				}
				
				/*避免多次寻路*/
				if(keyPath.empty())
				{
					findAttWay(perLstPt,false);			
				}			
				
			}
			else
			{					
				if(!isInPatrol)
				{
					/*模糊反应*/
					if(!judgeGoFor())
					{
						stopMove();	
						return;
					}	
				}
				
				/*判断是否已定身*/
				if(!skiBody)
				{
					stopMove();	
					return;
				}
				
				/*生成寻路终点*/
				getEnd();  
				
				if(logic_pt == endFinPt)
				{
					Rec = true;
					isInPatrol = false;
					return;
				}
				
				/*避免多次寻路*/
				if(keyPath.empty())
				{
					findSlfWay(endFinPt);		
				}			
			}
		}
	}
	if(perLstPt == logic_pt)
	{
		Rec = false;
	}
	else
	{
		Rec = true;
	}
}
Beispiel #23
0
void moveBackwards()
{
  stopMove();
  pinMode(backwards, OUTPUT); 
  digitalWrite(backwards, 1);          
} 
Beispiel #24
0
void moveForward()
{
  stopMove();
  pinMode(forward, OUTPUT);
  digitalWrite(forward, 1);          
  }
void MonsterActive::response(void)
{		
	
	StyObj obj(identity,MONSTER_STYLE_TYPE);
	vector<string> herId;		
	Point heroPt;
	Hero *perHero;		
	Nbox *box;
	
	if(map_now == NULL)
	{
		return;
	}
	
	box = map_now->getBox();	
	if(box == NULL || !isAlive)
	{
		return;
	}
	
	/*判断任务是否还在*/
	if(judgeTask())
	{
		cout<<"the task mon of the task is illeay:"<<endl;
		return;
	}
	
	if(!isPlayOver())
	{
		// cout<<"it is playCd time:"<<endl;
		return;
	}	
	
	memset(otherMsg,'\0',MONSTER_MSG_LENGTH + 1);
	
	box->getStaInSrcVec(obj);
	
	/*处理延时性技能*/
	hitedSkiFun();
	
	/*地图没人,判断是否已眩晕*/
	if(!dizz)     
	{
		stopMove();
		return;
	}	
	
	/*回血功能*/
	recoverBloodSelf();
	
	/*boss逃跑*/
	if(flgRun)    
	{
		/*判断是否已定身*/
		if(!skiBody)
		{
			stopMove();
			return;
		}		
	}
	else
	{			
		/*仇恨范围搜寻*/
		schRge();
		
		/*如果仇恨列表不为空*/
		if(!enmityValues.empty())   
		{						
			/*这个是从仇恨列表里面得到的最高值,至于怎么得到的,则要看仇恨计算*/
			perHero = getHero(perHerId);
			
			if(perHero == NULL || !perHero->getLifeStation())
			{
				return;	
			}
			
			heroPt = perHero->getLogPt();
			
			/*攻击距离判断*/
			int fight_state = attackRangePoint(pt,perHero->getLocation(),attack_range);	
			
			
			if(fight_state != 1)
			{				
				/*判断是否已定身*/
				if(!skiBody)
				{
					stopMove();					
					return;
				}
         
                /*如果人物没动,则这次就不必要再寻一次路*/
                if(jdgSmePt(heroPt))
                {					
                    findAttWay(heroPt);						
					isPersuitHero = true;
                }
			}
			
			else
			{			
				stopMove();	
				exchageHat(herId);
				if(attackPoint && useSkill(herId))
				{					
					return;
				}
				attPerHero(otherMsg,sizeof(otherMsg),perHero);					
				box->sentBoxMsg(otherMsg);
			}			
		}
		else
		{
			/*如果上次正在追人,而这次仇恨没人,则立即停下来*/
			if(isPersuitHero)
			{
				stopMove();
				
				isPersuitHero = false;
			}
		
			/*归位*/
            if(Rec)
            { 			
				/*判断是否已定身*/
				if(!skiBody)
				{
					stopMove();	
					return;
				}
				
				if(perLstPt == logic_pt)
				{
					Rec = false;
					return;
				}
				
				/*避免多次寻路*/
				if(keyPath.empty())
				{
					findSlfWay(perLstPt);		
				}			
            }		
			
		}
		
	}
	
	if(perLstPt == logic_pt)
	{
		Rec = false;
	}
	else
	{
		Rec = true;
	}		
	
}