Ejemplo n.º 1
0
void ALeft::execute(const sf::Int32 elapsed) {
  // TODO: Verif' they are existing components
  // #1 get all components
  CSpeed * speed;
  speed = (CSpeed *) parent->getComponent("Speed");
  CAcceleration * acceleration;
  acceleration = (CAcceleration *) parent->getComponent("Acceleration");
  CPosition * position;
  position = (CPosition *) parent->getComponent("Position");

  if (speed->getHSpeed() > 1.2) {
    // #2a go back to 0
    speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0));
    position->setX((position->getX())+(speed->getHSpeed()));
  } else {
    // #2b increase speed
    speed->setHSpeed((speed->getHSpeed())-(acceleration->getHAcceleration()));
    position->setX((position->getX())+(speed->getHSpeed()));
  }  
  // #3 change sprites TODO
  // example : if elapsed > modulotime/2 then ...
}
Ejemplo n.º 2
0
void ARight::execute(const sf::Int64 elapsed) {
  // TODO: Verif' they are existing components
  // #1 get all components
  sf::Int64 tempElapsedSum = getElapsedSum() + elapsed;
  CAcceleration * acceleration;
  acceleration = (CAcceleration *) parent->getComponent("Acceleration");
  CSpeed * speed = (CSpeed *) parent->getComponent("Speed");
  CPosition * position = (CPosition *) parent->getComponent("Position");
  CSprite * sprite = (CSprite *) parent->getComponent("Sprite");

  if (speed->getHSpeed() < -1.2) {
    // #2a go back to 0                                                       
    speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0));
    position->setX((position->getX())+(speed->getHSpeed()));
    sprite->updatePosition();
  } else { 
    // #2b add values
    speed->setHSpeed((speed->getHSpeed())+
		     ((float)elapsed/acceleration->getHAcceleration()*
		      speed->getHSpeedMax()));
    position->setX((position->getX())+ceil((speed->getHSpeed()))); // round sup
    sprite->updatePosition();
  }

  // #3 change sprites
  sf::Int64 temp = 0;
  int k = 0; //index to read in tab
  while (temp < tempElapsedSum) {
    ++k;
    temp = temp + (getModuloTime()/getSubSprites().size());
  }
  if ((k-1)>=getSubSprites().size())
    {k=getSubSprites().size();}
  sprite->updateSubSprite(getSubSprites().at(k-1));
  sprite->setDirection("right");
  setElapsedSum(tempElapsedSum%getModuloTime());
}
Ejemplo n.º 3
0
void ALeft::execute(const sf::Int32 elapsed) {
    // TODO: Verif' they are existing components
    // #1 get all components
    CAcceleration * acceleration;
    acceleration = (CAcceleration *) parent->getComponent("Acceleration");
    CSpeed * speed;
    speed = (CSpeed *) parent->getComponent("Speed");
    CPosition * position;
    position = (CPosition *) parent->getComponent("Position");

    // #2 add values
    speed->setHSpeed((speed->getHSpeed())-(acceleration->getHAcceleration()));
    position->setX((position->getX())+(speed->getHSpeed()));

    // #3 change sprites TODO
    // example : if elapsed > modulotime/2 then ...
}
Ejemplo n.º 4
0
void AStand::execute(const sf::Int32 elapsed) {
  // TODO: Verif' they are existing components
  // #1 get all components
  CSpeed * speed;
  speed = (CSpeed *) parent->getComponent("Speed");
  if ((float) std::abs(speed->getHSpeed()) > 1.2) {
    CAcceleration * acceleration;
    acceleration = (CAcceleration *) parent->getComponent("Acceleration");
    CPosition * position;
    position = (CPosition *) parent->getComponent("Position");
  
    // #2 add value
    speed->setHSpeed((speed->getHSpeed())-((float)(speed->getHSpeed())/8.0));
    position->setX((position->getX())+(speed->getHSpeed()));
  } else {
    speed->setHSpeed(0.0);
  }

  // #3 change sprites TODO
  // example : if elapsed > modulotime/2 then ...
}