本文整理汇总了C++中sf::Time::AsSeconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Time::AsSeconds方法的具体用法?C++ Time::AsSeconds怎么用?C++ Time::AsSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Time
的用法示例。
在下文中一共展示了Time::AsSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Character::update(sf::Time frametime, Input input) {
if(!canMove)
return;
int x0 = position.x / Block::WIDTH;
int y0 = position.y / Block::HEIGHT;
float seconds = frametime.AsSeconds();
//Carve
if (input.LeftCarve && !lastInput.LeftCarve) {
Block* b = world->getBlock(x0 - 1, y0 + 1);
Block* c = world->getBlock(x0 - 1, y0);
if (b && b->getType() == Block::WALL && !c->isSolid() && !c->isLadder() && !c->isRope())
b->setActive(false);
}
if (input.RightCarve && !lastInput.RightCarve) {
Block* b = world->getBlock(x0 + 1, y0 + 1);
Block* c = world->getBlock(x0 + 1, y0);
if (b && b->getType() == Block::WALL && !c->isSolid() && !c->isLadder() && !c->isRope())
b->setActive(false);
}
lastInput = input;
sf::Vector2f direction = sf::Vector2f(0, 0);
Block* rope = world->getCollidingRope(getBbox());
Block* ladder = world->getCollidingLadder(getBbox());
bool isCentring = false;
if (ladder) {
isClimbing = true;
if (input.Up)
direction -= sf::Vector2f(0, speed.y);
else if (input.Down)
direction += sf::Vector2f(0, speed.y);
if (input.Up || input.Down) {
if (fabs(getCenter().x - ladder->getCenter().x) < speed.y * seconds)
alignToGridX();
else if (getCenter().x < ladder->getCenter().x)
direction.x += speed.x;
else if (getCenter().x > ladder->getCenter().x)
direction.x -= speed.x;
isCentring = true;
}
} else {
isClimbing = false;
}
//Align to rope
if (rope && (input.Left || input.Right || isFalling) && !(input.Down)) {
isHanging = true;
int deltaY = rope->getPosition().y - getPosition().y;
if (abs(deltaY) < 4)
setPosition(sf::Vector2f(position.x, rope->getPosition().y));
}
if (!rope || input.Down || rope->getPosition().y != getPosition().y)
isHanging = false;
if (isClimbing && isHanging)
isClimbing = false;
if (!isHanging && !isClimbing)
isFalling = true;
else
isFalling = false;
if (isFalling)
direction += sf::Vector2f(0, speed.y);
if (direction.y != 0) {
setPosition(sf::Vector2f(position.x, position.y + direction.y * seconds));
Entity *b = world->getCollidingSolid(getBbox());
while (b != NULL) {
if (direction.y < 0)
setPosition(sf::Vector2f(position.x, b->getBbox().Top + b->getBbox().Height));
else {
setPosition(sf::Vector2f(position.x, b->getBbox().Top - getBbox().Height));
isFalling = false;
}
b = world->getCollidingSolid(getBbox());
}
//Walk on ladder
b = world->getCollidingLadder(getBbox());
if (b && b->getPosition().y > getBbox().Top && isFalling && !input.Down) {
setPosition(sf::Vector2f(position.x, b->getBbox().Top - getBbox().Height));
isFalling = false;
}
}
//Left Right - Up Down (ladder)
//.........这里部分代码省略.........