本文整理汇总了C++中Physics::testX方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::testX方法的具体用法?C++ Physics::testX怎么用?C++ Physics::testX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::testX方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canGoX
// === 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: canGoX
// 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: canGoY
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.
}