Beispiel #1
0
void Enemy::canGoY(float dt, const Physics &phys) {
  pos.y += vel.y * dt;
  for (float changeY = phys.testY(*this); changeY!=0; changeY = phys.testY(*this)) {
    pos.y += phys.testY(*this); 
    if (phys.gravAngle%180 == 0) vel.setY(0, phys.gravAngle);
    else hitWall = true;
  }
  if (phys.testBoundsY(*this) != 0) {  // when fallen into the pit
    anger(phys);
    dead = true;  // indicate death to reset
  }
}
Beispiel #2
0
void Player::canGoY(float dt, const Physics &phys) {
  pos.y += vel.y * dt;
  for (float changeY = phys.testY(*this); changeY!=0; changeY = phys.testY(*this)) {
    pos.y += changeY; 
    vel.y = 0;
    if (  // if there was a collision with the ground
      ( (changeY < 0 && phys.gravAngle==0*90) || (changeY>0 && phys.gravAngle==2*90) ) 
      && abs(changeY)<=abs(phys.testX(*this))
    ) inAir = false;
  }
  if (phys.testBoundsY(*this) != 0) dead = true;  // player fell into a pit.
}