本文整理汇总了C++中sf::Time::asSeconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Time::asSeconds方法的具体用法?C++ Time::asSeconds怎么用?C++ Time::asSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Time
的用法示例。
在下文中一共展示了Time::asSeconds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void GameStateCinematic::update(sf::Time dt) {
this->activateNext += dt.asSeconds();
if (this->activateNext >= 0.25 && next) {
this->d->pop_front();
this->c++;
this->next = false;
this->activateNext = 0;
}
if (this->control.empty()) {
this->game->changeState(this->nextState);
} else if (this->c == this->control.front()) {
this->background.pop_front();
this->control.pop_front();
this->c = 0;
}
}
示例2: main
int main()
{
sf::Clock clock;
initTexts();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color(244, 67, 54));
if(game_over)
{
window.draw(endText);
ostringstream s;
s << "Your score was : " << snake.length();
scoreText.setString(s.str());
window.draw(scoreText);
}
else
{
input(dir);
sf::Time elapsed = clock.getElapsedTime();
if(elapsed >= delta)
{
if(snake.head()->position() == f.position())
{
snake.add();
f.generatePos();
delta = sf::seconds(delta_i.asSeconds() - (float)snake.length()/100);
}
snake.move(dir);
clock.restart();
}
o.draw();
f.draw();
snake.draw();
}
window.display();
}
return 0;
}
示例3: targetMove
/*
* move
*/
void Bee::targetMove(sf::Time dt)
{
if(avoidanceClock_.asSeconds() <= 0){
Vec2d currSpeed = directionTo(target_).normalised() * speed_.length();
Collider dummy(position_, rayon_);
dummy.move(currSpeed*dt.asSeconds());
if(getAppEnv().getWorld().isFlyable(dummy.getPosition()))
{
position_ = dummy.getPosition();
}else{
avoidanceClock_ = sf::seconds(getConfig()["moving behaviour"]["target"]
["avoidance delay"].toDouble());
}
}else{
avoidanceClock_ -= dt;
RandomMove(dt);
}
}
示例4: Update
void ParticleSystem::Update(sf::Time dt)
{
for(unsigned int id : _EntitiesToUpdate) {
Entity* e = this->GetEntity(id);
ParticleComponent* pc = e->GetComponent<ParticleComponent>("particle");
for(std::size_t i = 0; i < pc->_particleInfo.size(); ++i) {
ParticleInfo& p = pc->_particleInfo[i];
p.life -= dt;
if(p.life <= sf::Time::Zero)
pc->resetParticle(i);
pc->_particles._vertices[i].position += p.velocity * dt.asSeconds();
float ratio = p.life.asSeconds() / pc->_lifeTime.asSeconds();
pc->_particles._vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
}
}
}
示例5: update
void Player::update(sf::Time deltaTime)
{
float seconds = deltaTime.asSeconds();
if(_rotation != 0)
{
float angle = _rotation*180*seconds;
_ship.rotate(angle);
}
if(_is_moving)
{
float angle = _ship.getRotation() / 180 * M_PI - M_PI / 2;
_velocity += sf::Vector2f(std::cos(angle),std::sin(angle)) * 60.f * seconds;
}
_ship.move(seconds * _velocity);
}
示例6: doStuff
//What's in doStuff right now is only for testing purpose. Lot of stuff to do here.
void Elodie::doStuff(const EventHandler& event, const std::vector< std::vector<TileSprite*> >& tiles,
EntityMap& entities, sf::Time animate)
{
//Compute the gravity
computeGravity(animate);
//Check the collisions, set the new distances and do the move
Collide collideTiles = collideWithTiles(tiles, animate.asSeconds());
setDistance(collideTiles);
move(animate.asSeconds()*(speed.x), animate.asSeconds()*speed.y);
spriteCast->update(animate);
//Change the sprite in accord with the speed
changeAnimation(collideTiles);
handleEvent(event, entities, collideTiles);
if (0 == speed.x && !collideTiles.right["surface"])
{
speed.x = moveSpeed;
}
float dist = cameraPos.x - spriteCast->getPosition().x;
if (dist > 0 && !collideTiles.right["surface"] && !buffed)
{
buffed = true;
speed.x = moveSpeed + dist;
}
buffed = !collideTiles.right["surface"];
if (buffed && dist <= 0)
{
buffed = false;
speed.x = moveSpeed;
}
//Other stuff to do
attackTimer += animate.asSeconds();
pvTimer += animate.asSeconds();
if (pvTimer > interRecoveryTime)
{
pvTimer = 0;
immersionLevel = immersionLevel == 100 ? 100 : immersionLevel + 1;
}
if (damageCD)
{
--damageCD;
}
cameraPos.x += (moveSpeed)*animate.asSeconds();
cameraPos.y = spriteCast->getPosition().y;
}
示例7: mover
void mover(da::Game &game, const sf::Time &delta) {
int vert = sf::Keyboard::isKeyPressed(sf::Keyboard::S) -
sf::Keyboard::isKeyPressed(sf::Keyboard::W);
int horz = sf::Keyboard::isKeyPressed(sf::Keyboard::D) -
sf::Keyboard::isKeyPressed(sf::Keyboard::A);
if (vert || horz) {
float theta = atan2(vert, horz);
xform->move(horz * delta.asSeconds() * 100.f,
vert * delta.asSeconds() * 100.f);
dirAnim->setDirection(theta);
dirAnim->getAnimation().play();
} else {
dirAnim->getAnimation().stop();
}
}
示例8: updateMovementPattern
void Aircraft::updateMovementPattern(sf::Time dt)
{
const std::vector<Direction>& directions = Table[mType].directions;
if (!directions.empty())
{
float distanceToTravel = directions[mDirectionIndex].distance;
if (mTravelledDistance > distanceToTravel)
{
mDirectionIndex = (mDirectionIndex + 1) % directions.size();
mTravelledDistance = 0.f;
}
float Radians = toRadian(directions[mDirectionIndex].angle + 90.f);
float vx = getSpeed() * std::cos(Radians);
float vy = getSpeed() * std::sin(Radians);
setVelocity(vx, vy);
mTravelledDistance += getSpeed() * dt.asSeconds();
}
}
示例9: updateMovementPattern
void Aircraft::updateMovementPattern(sf::Time delta)
{
const std::vector<Direction>& directions = Table[mType].directions;
if (!directions.empty()) {
float distanceToTravel = directions[mDirectionIndex].distance;
if (mTravelledDistance > distanceToTravel) {
mDirectionIndex = (mDirectionIndex + 1) % directions.size();
mTravelledDistance = 0.f;
}
float radians = Utility::toRadian(directions[mDirectionIndex].angle + 90.f);
float xVel = getMaxSpeed() * std::cos(radians);
float yVel = getMaxSpeed() * std::sin(radians);
setVelocity(xVel, yVel);
mTravelledDistance += getMaxSpeed() * delta.asSeconds();
}
}
示例10: updateCurrent
void ParticleNode::updateCurrent(sf::Time dt, CommandQueue& commands)
{
if (mParticles.empty()) return;
while (!mParticles.empty() && mParticles.front().lifetime <= sf::Time::Zero)
mParticles.pop_front();
for (auto& particle : mParticles)
{
particle.lifetime -= dt;
particle.position += dt.asSeconds() * particle.velocity;
particle.rotation += dt.asSeconds() * particle.rotationSpeed;
for (const auto& affector : mAffectors)
affector(particle, dt);
}
mNeedsVertexUpdate = true;
}
示例11: updateCurrent
//Update the spaceship
void Spaceship::updateCurrent(sf::Time dt)
{
Entity::updateCurrent(dt);
//If we don't have a target, stay where we are
if(target == sf::Vector2f(0, 0))
target = getWorldPosition();
sf::Vector2f velocity = getVelocity();
velocity += normalize((target-getWorldPosition()))*deltaV*dt.asSeconds();
if(sqrt(velocity.x*velocity.x+velocity.y*velocity.y) > maxV)
velocity = normalize(velocity)*maxV;
setVelocity(velocity);
if(velocity.x != 0||velocity.y != 0)
{
float rotation = atan2(velocity.y, velocity.x)*180/3.1415+90;
while(rotation > 360)
rotation -= 360;
setRotation(rotation);
}
}
示例12: shoot
void Player::shoot(const sf::Time& elapsedTime)
{
if (mCooldown > 0)
{
mCooldown -= elapsedTime.asSeconds();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && mCooldown <= 0)
{
mProjectileManager.addProjectile(sf::Vector2f(player.getPosition().x + player.getLocalBounds().width / 2, player.getPosition().y - player.getLocalBounds().height), sf::IntRect(134, 308, 55, 98));
std::cout << player.getPosition().y << std::endl;
mCooldown = mDelay;
}
if (!mProjectileManager.getSpriteVector().empty() && (mProjectileManager.getSpriteVector().back().getPosition().y > window.getSize().y - mProjectileManager.getSpriteVector().back().getLocalBounds().height))
{
mProjectileManager.getSpriteVector().pop_back();
}
}
示例13: gravity
void shape_system::gravity(sf::Time tElapsed)
{
for (int i = 0; i < numberOfShapes; i++)
{
float dt = tElapsed.asSeconds();
float u = shapesVelocities[i].j;
float v = dt*acceleration + u;
float s = u*dt + 0.5*acceleration*dt*dt;
shapesVelocities[i].j = v;
//cout << "v = " << v;
sf::Vector2f pos = shapes[i]->getPosition();
pos.y = pos.y + s;
shapes[i]->setPosition(pos);
}
}
示例14: update
void update(sf::Time elapsed) {
for (std::size_t i=0; i<m_particles.size(); ++i) {
// update the particle lifetime
m_particles[i].lifetime -= elapsed;
// if the particle is dead, respawn it
if (m_particles[i].lifetime <= sf::Time::Zero) resetParticle(i);
// update the position of the corresponding vertex
m_vertices[i].position += m_particles[i].velocity * elapsed.asSeconds();
// update the alpha (transparency) of the particle according to its lifetime
float ratio = m_particles[i].lifetime.asSeconds() / m_lifetime.asSeconds();
m_vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
}
}
示例15: getReadableMusicOffset
std::string MusicPlayer::getReadableMusicOffset(const sf::Time & offset) {
int time_s = static_cast<int>(offset.asSeconds());
int hours = time_s / 3600;
time_s -= 3600 * hours;
int minutes = time_s / 60;
time_s -= 60 * minutes;
int seconds = time_s;
char * c_str = new char[64];
if (hours > 0)
sprintf(c_str, "%d:%02d:%02d", hours, minutes, seconds);
else
sprintf(c_str, "%d:%02d", minutes, seconds);
return std::string(c_str);
}