Example #1
0
// === private functions: ===
void Player::canGoX(float dt, const Physics &phys) {
  pos.x += vel.x * dt;
  for (float changeX = phys.testX(*this); changeX!=0; changeX = phys.testX(*this)) {  // as long as there are collisions, keep checking
    pos.x += changeX;
    vel.x = 0;
    if (  // if there was a collision with the ground
      ( (changeX < 0 && phys.gravAngle==1*90) || (changeX>0 && phys.gravAngle==3*90) ) 
      && abs(changeX)<=abs(phys.testY(*this))
    ) inAir = false;
  }
  if (phys.testBoundsX(*this) != 0) dead = true; // player fell into a pit.
}
Example #2
0
// helper functions for update()
void Enemy::canGoX(float dt, const Physics &phys) {
  pos.x += vel.x * dt;
  float changeX = phys.testX(*this);
  while (changeX!=0) {  // as long as there are collisions with the level, keep checking
    pos.x += changeX;
    if (phys.gravAngle%180 == 0) hitWall = true;
    else vel.setY(0, phys.gravAngle);
    changeX = phys.testX(*this);
  }
  changeX = phys.testBoundsX(*this);
  if (changeX != 0) {
    anger(phys);
    dead = true;  // indicate death to reset
  }
}