コード例 #1
0
ファイル: player.cpp プロジェクト: DomNomNom/SuperFoxManCrate
// === 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.
}
コード例 #2
0
ファイル: enemy.cpp プロジェクト: DomNomNom/SuperFoxManCrate
// 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
  }
}
コード例 #3
0
ファイル: player.cpp プロジェクト: DomNomNom/SuperFoxManCrate
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.
}