Exemplo n.º 1
0
/** update SXLoco speed from encoder "delta"
 * larger delta => make larger speed steps
 */
void SXLoco::updateSpeed(int8_t delta) {
// Serial.print("delta=");
// Serial.println(delta);

   _tmpSpeed = _sxData & 0x1F;
   _tmpBackward = bitRead(_sxData,5);
   if (_tmpSpeed == 0) {     
        if (_tmpBackward) {
          if (delta > 0) {
            // then only change direction if delta > 0
            _tmpBackward = 0;
          } else {
             increaseSpeed(delta);
          }  
        } else { // forwards
          if (delta < 0) {
            // then only change direction if delta > 0
            _tmpBackward = 1;
          } else {
            increaseSpeed(delta);
          }  
        }
          
      } else {  // speed is not == 0
        if (_tmpBackward) {
          if (delta > 0) {
            if (_tmpSpeed > 3) { // do only if not close to ZERO
                decreaseSpeed(delta);
            } else {
                decreaseSpeed(1);
            }
          } else {
            increaseSpeed(delta);
          }
        } else {
          if (delta > 0) {
            increaseSpeed(delta);
          } else {
            if (_tmpSpeed > 3) { // do only if not close to ZERO
                decreaseSpeed(delta);
            } else {
                decreaseSpeed(1);
            }
          }
        }         
      }


   // did speed or direction change ?
   if ( (_tmpSpeed != (_sxData & 0x1F)) ||
        (_tmpBackward != bitRead(_sxData,5)) ) {
       _sxData = (_sxData & 0xE0) | _tmpSpeed;
       if (_tmpBackward) {
           bitSet(_sxData,5);
       } else {
           bitClear(_sxData,5);
       }
       _changed=1;   
   }
}
Exemplo n.º 2
0
void st03::init(){
    increaseStrength();
	while(getPoint()){
		if(getPoint())increaseHealth();
		if(getPoint())increaseSpeed();
	}
}
Exemplo n.º 3
0
void st03::play(){
	while(getPoint()){
		if(getPoint())increaseHealth();
		if(getPoint())increaseSpeed();
	}
	int d=(~0U>>1),x,y;
	for(int i=1;i<=N;++i)
		for(int j=1;j<=M;++j)
			if(askWhat(i,j)==EMPTY){
				int t1=abs(i-getX())+abs(j-getY());
				if(t1>getSp())continue;
				for(int k=1;k<=N;++k)
					for(int l=1;l<=M;++l)
						if(askWhat(k,l)!=EMPTY){
							int tmp=abs(i-k)+abs(j-l);
							if(tmp<d)d=tmp,x=i,y=j;
						}
			}
	move(x,y);
	for(int i=-1;i<2;++i)
		for(int j=-1;j<2;++j){
			if(i&&j)continue;
			if((!i)&&(!j))continue;
			if(askWhat(x+i,y+j)!=EMPTY){
				attack(x+i,y+j);
				return;
			}
		}
}
Exemplo n.º 4
0
void updateScore(int rows)
{
	int i;
	for (i = 1; i <= rows; i++)
	{
		points += CANVAS_WIDTH * i;
		increaseSpeed();
	}
}
Exemplo n.º 5
0
void ch_att::init()
{
	myID=getID();
	getInfo();
	for (int i=1;i<=4;i++)
	 increaseHealth();
	for (int i=1;i<=2;i++)
	 increaseStrength();
	for (int i=1;i<=4;i++)
	 increaseSpeed();
}
Exemplo n.º 6
0
void testAI::play()
{
    while(getPoint())
    {
        increaseSpeed();
        increaseStrength();
        increaseHealth();
    }
    int i,j,x,y,flag=0,t1,t2;
    x=getX();
    y=getY();
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            if(abs(i-x)+abs(j-y)<=getSp())
            {
                if(askWhat(i-1,j)>0 || askWhat(i+1,j)>0 || askWhat(i,j-1)>0 || askWhat(i,j+1)>0)
                {
                    move(i,j);
                    flag=1;
                    break;
                }
                t1=i;t2=j;
            }
        }
        if(flag)break;
    }
    if(!flag)move(t1,t2);
    if(askWhat(i-1,j)>0)
    {
        attack(i-1,j);
        return;
    }
    if(askWhat(i+1,j)>0)
    {
        attack(i+1,j);
        return;
    }
    if(askWhat(i,j-1)>0)
    {
        attack(i,j-1);
        return;
    }
    if(askWhat(i,j+1)>0)
    {
        attack(i,j+1);
        return;
    }

}
Exemplo n.º 7
0
void HangState::handleInput(Scene& scene,SDL_Event& e)
{
	if (GameInputs::keyDown(e, ControlType::UP))
	{
		yDirection_ = -1;
		increaseSpeed();
	}	
	else if (GameInputs::keyDown(e, ControlType::DOWN))
	{
		yDirection_ = 1;
		increaseSpeed();
	}
	else if (GameInputs::keyDown(e, ControlType::LEFT))
	{
		LOG("HARVEY") << "LEFT KEY PRESSED";
		stateManager_->MovementState().setKeyDirection(true);
		stateManager_->MovementState().setDirection(1);
		stateManager_->MovementState().setAngle(angle_);
		stateManager_->MovementState().setRadius(radius_);
		stateManager_->changeMovementState(scene, "SwingState");
	}
	else if (GameInputs::keyDown(e, ControlType::RIGHT))
	{
		LOG("HARVEY") << "RIGHT KEY PRESSED";
		stateManager_->MovementState().setKeyDirection(false);
		stateManager_->MovementState().setDirection(-1);
		stateManager_->MovementState().setAngle(angle_);
		stateManager_->MovementState().setRadius(radius_);
		stateManager_->changeMovementState(scene, "SwingState");
	}
	else
	{
		yDirection_ = 0;
		ySpeed_ = STARTING_SPEED;
	}
}
Exemplo n.º 8
0
void ch_att::assignPoints()
{
	long est=0;
	
	// Health
	while (point>0 && hp<att*7/3)
	 {
		point--;
		increaseHealth();
	 }
	// Speed
	est=targetSpeed();
	while (point>0 && sp<SpeedCap && sp<=est)
	 {
		point--;
		increaseSpeed();
	 }
	// Strength
	while (point>0)
	 {
		point--;
		increaseStrength();
	 }
}
Exemplo n.º 9
0
void Ball::handlePaddleCollision(Paddle* aPaddle)
{
	//Calculate the ball's distance from the paddle
	float distanceX = fabsf(getX() - aPaddle->getX() - (aPaddle->getWidth() / 2.0f));
	float distanceY = fabsf(getY() - aPaddle->getY() - (aPaddle->getHeight() / 2.0f));
  
	//If the distance on the x-axis is greater than half-the-width of the paddle + the ball's radius, then 
	//there is no way they can be colliding and return out of this method, no more collision handling is needed.
	if(distanceX > ((aPaddle->getWidth() / 2.0f) + getRadius()))
	{
		return; 
	}
  
	//If the distance on the y-axis is greater than half-the-height of the paddle + the ball's radius, then 
	//there is no way they can be colliding and return out of this method, no more collision handling is needed.
	if(distanceY > ((aPaddle->getHeight() / 2.0f) + getRadius())) 
	{
	    return; 
	}
  
	//If we got here (passed the previous 2 if checks), then there is a good chance that a collision has occured.

	//If the distance on the x-axis is less than half-the-width of the paddle, then we have a collision on top of 
	//the paddle, set the ball's Y value and y-direction accordingly.
	if(distanceX <= (aPaddle->getWidth() / 2.0f))
	{
	    //Bottom
	    if(getY() > aPaddle->getY() + (aPaddle->getHeight() / 2.0f))
	    {
	    	setY(aPaddle->getY() + aPaddle->getHeight() + getRadius());
	    }
	    //Top
	    else 
	    {
	    	setY(aPaddle->getY() - getRadius());
	    }
  
		//Change the ball's direction and increase the ball's speed
		setDirectionY(getDirectionY() * -1.0f);
		increaseSpeed();
		return;
	} 
  
	//If the distance on the y-axis is less than half-the-height of the paddle, then we have a collision on either 
	//side of the paddle, set the x-direction accordingly.
	if(distanceY <= (aPaddle->getHeight() / 2.0f))
	{
		//Right
		if(getX() > aPaddle->getX() + (aPaddle->getWidth() / 2.0f))
		{
			setX(aPaddle->getX() + aPaddle->getWidth() + getRadius());
		}
		//Left
		else 
		{
			setX(aPaddle->getX() - getRadius());
		}
  
		//Change the ball's direction and increase the ball's speed
		setDirectionX(getDirectionX() * -1.0f);
		increaseSpeed();
		return;
	}
}
Exemplo n.º 10
0
void testAI::init()
{
    increaseHealth();
    increaseStrength();
    while(getPoint())increaseSpeed();
}