本文整理汇总了C++中sf::Time类的典型用法代码示例。如果您正苦于以下问题:C++ Time类的具体用法?C++ Time怎么用?C++ Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Time类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: update
void Monster::update(const sf::Time & elapsed)
{
c_LastAggroTime += elapsed;
if(elapsed.asSeconds() < c_LostAggroTime && c_LastAggroTime.asSeconds() > c_LostAggroTime)
c_LastAggroTime = sf::seconds(c_LostAggroTime);
c_LastAtkTime += elapsed;
if(elapsed.asSeconds() < c_DelayAtkTime && c_LastAtkTime.asSeconds() > c_DelayAtkTime)
c_LastAtkTime = sf::seconds(c_DelayAtkTime);
Living::update(elapsed);
}
开发者ID:LightningAmal,项目名称:MEUPORG,代码行数:12,代码来源:monster.cpp
示例2: uniform
NDistribution<sf::Time> uniform(sf::Time min, sf::Time max)
{
assert(min <= max);
const float floatMin = min.asSeconds();
const float floatMax = max.asSeconds();
return [=] () -> sf::Time
{
return sf::seconds(NMath::random(floatMin, floatMax));
};
}
开发者ID:Cmdu76,项目名称:Delmia,代码行数:12,代码来源:Distributions.hpp
示例3: update
void cBkGrid::update(sf::Time dt)
{
mAccumulator += dt;
if ( mAccumulator >= mTimer )
{
mAccumulator = sf::Time::Zero;
adjustColor();
}
// Horizontal lines' velocity
sf::Vector2f dVhori { 0.0, mVelocity.y };
dVhori *= dt.asSeconds();
for (auto i = 0; i < gGridSize.y * 2; ++i)
{
mPoints[i].position += dVhori;
if (mPoints[i].position.y < 0)
{
mPoints[i].position.y += mSize;
}
if (mPoints[i].position.y > mSize)
{
mPoints[i].position.y -= mSize;
}
}
// Vertical lines' velocity
sf::Vector2f dVvert { mVelocity.x, 0.0 };
dVvert *= dt.asSeconds();
for (auto i = mFirstVline; i < gGridPointCount; ++i)
{
mPoints[i].position += dVvert;
if (mPoints[i].position.x < 0)
{
mPoints[i].position.x += mSize;
}
if (mPoints[i].position.x > mSize)
{
mPoints[i].position.x -= mSize;
}
}
// Now rotate
mRot += mSpin * dt.asSeconds();
if ( mRot < -360 ) mRot += 360;
if ( mRot > 360 ) mRot -= 360;
setRotation(mRot);
// Adjust position
setPosition(mHalfSize / 2.0, mHalfSize / 2.0);
}
开发者ID:andras-szabo,项目名称:project-shmup,代码行数:52,代码来源:bkGrid.cpp
示例4: updateCurrent
void Entity::updateCurrent(sf::Time dt)
{
if (hasFriction)
{
mVelocity.x *= FRICTION;
mVelocity.y *= FRICTION;
}
if (hasGravity)
{
mVelocity.y += GRAVITY * dt.asSeconds();
}
move(mVelocity * dt.asSeconds());
}
开发者ID:KarelCasier,项目名称:Mech-Assault,代码行数:13,代码来源:Entity.cpp
示例5: update
void Player::update(const sf::Time& dt) {
handleInput(dt);
if (getPosition().x < 0) {
move(m_speed * dt.asSeconds(), 0.0f);
} else if (getPosition().x + getGlobalBounds().width > m_windowSize.x) {
move(-m_speed * dt.asSeconds(), 0.0f);
}
m_spaceKey = sf::Keyboard::isKeyPressed(sf::Keyboard::Space);
Entity::update(dt);
}
开发者ID:aclonegeek,项目名称:Spaceliens,代码行数:13,代码来源:Player.cpp
示例6: update
void SpeedupPullCamera::update(const sf::Time& frameTime)
{
if (g_inputController->isKeyActive(Key::Up))
{
m_cameraTop -= CAMERA_SPEED_PER_S * frameTime.asSeconds();
m_cameraCenter.y = m_cameraTop + (m_cameraWindowHeight / 2.f);
}
if (g_inputController->isKeyActive(Key::Down))
{
m_cameraTop += CAMERA_SPEED_PER_S * frameTime.asSeconds();
m_cameraCenter.y = m_cameraTop + (m_cameraWindowHeight / 2.f);
}
}
开发者ID:G-GFFD,项目名称:Cendric2,代码行数:13,代码来源:SpeedupPullCamera.cpp
示例7: target
SoundManager::FadedMusic::FadedMusic(
VFileMusic& music, float target, sf::Time fadeDuration):
target(target),
music(&music),
increment(0)
{
if (fadeDuration.asMicroseconds()) {
music.setVolume(100 - target);
increment = (target - music.getVolume()) / fadeDuration.asSeconds();
} else {
music.setVolume(target);
}
}
开发者ID:Oberon00,项目名称:jd,代码行数:13,代码来源:SoundManager.cpp
示例8: update
void ParticleSystem::update(const sf::Time &dt) {
if (emitRate > 0.0f) {
emitWithRate(dt.asSeconds());
}
for (int i = 0; i < m_particles->countAlive; ++i) {
m_particles->acc[i] = { 0.0f, 0.0f };
}
for (auto & updater : m_updaters) {
updater->update(m_particles, dt.asSeconds());
}
}
开发者ID:tizian,项目名称:particles,代码行数:13,代码来源:ParticleSystem.cpp
示例9: update
/*
* Update
*/
void Bee::update(sf::Time dt)
{
action(dt);
move(dt);
if(moveState_ == MoveState::REST){
energy_ -= getConfig()["energy"]["consumption rates"]
["idle"].toDouble()*dt.asSeconds();
}else if(moveState_ == MoveState::TARGET ||
moveState_ == MoveState::RAND){
energy_ -= getConfig()["energy"]["consumption rates"]
["moving"].toDouble()*dt.asSeconds();
}
if(energy_ <= 0){ throw energy_; }
}
开发者ID:PhelixF,项目名称:Bee_Simulator,代码行数:17,代码来源:Bee.cpp
示例10: update
void NotificationManager::update(sf::Time dt)
{
if(notifications.size() == 0)
return;
sf::Text tmpText;
tmpText.setCharacterSize(50);
tmpText.setFont(NotificationFont);
auto factor = (static_cast<float>(RenderWindow.getView().getSize().y) / RenderWindow.getSize().y);
if(notifications[0].time > 0)
notifications[0].time -= dt.asSeconds(); //Count down notification time
else if(notifications[0].alpha - dt.asSeconds() * 150.f > 0)
notifications[0].alpha -= dt.asSeconds() * 150.f; //Hide notification
else
notifications.erase(this->notifications.begin()); //Delete notification
for(auto i = 0u; i < notifications.size() && i < 5; i++)
{
/* Apply alpha to text and notification */
tmpText.setFillColor
({
notificationTextColor.r,
notificationTextColor.g,
notificationTextColor.b,
static_cast<sf::Uint8>(sfm::mapValue(notifications[i].alpha, 0.f, static_cast<float>(notificationBacgroundColor.a), 0.f, static_cast<float>(notificationTextColor.a)))
});
notifications[i].background.setFillColor
({
notificationBacgroundColor.r,
notificationBacgroundColor.g,
notificationBacgroundColor.b,
static_cast<sf::Uint8>(notifications[i].alpha)
});
/* Set notification's background position */
notifications[i].background.setScale(factor, factor);
notifications[i].background.setPosition(RenderWindow.mapPixelToCoords({static_cast<int>(RenderWindow.getSize().x - 410), static_cast<int>(10 + i * 50)}));
/* Set text parameters */
tmpText.setScale(factor, factor);
tmpText.setString(notifications[i].text);
tmpText.setPosition(RenderWindow.mapPixelToCoords({static_cast<int>(RenderWindow.getSize().x - 410 + 10), static_cast<int>(10 + i * 50 - 15)}));
/* Draw notification */
RenderWindow.draw(notifications[i].background);
RenderWindow.draw(tmpText);
}
}
开发者ID:KoczurekK,项目名称:BattleOfHrubieszow,代码行数:50,代码来源:notificationmanager.cpp
示例11: update
void EnemyActor::update(const sf::Time& delta_t)
{
Actor::update(delta_t);
if(delta_t.asSeconds() == 0.0)
return;
if (getState() == EnemyActor::Patrol || getState() == EnemyActor::Follow)
patrolTimer -= delta_t.asSeconds();
if (getState() == EnemyActor::Patrol && patrolTimer <= 0.0) {
setNeedSeek(true);
patrolTimer = patrolTimerMin;
}
}
开发者ID:fenaren,项目名称:cs420-game,代码行数:14,代码来源:EnemyActor.cpp
示例12: update
void MonsterEntity::update(sf::Time delta) {
timer += delta.asSeconds();
if (timer > .5) {
swapAppearance();
timer = 0;
}
if (type == monster_flyer) {
move(velocity * delta.asSeconds());
} else if (type == monster_crawler) {
velocity.y += (gravity.y * delta.asSeconds());
velocity.x -= (gravity.y * delta.asSeconds());
move(velocity * delta.asSeconds());
}
}
开发者ID:peterschueler,项目名称:NotAPlumber,代码行数:14,代码来源:MonsterEntity.cpp
示例13: update
void Car::update(const sf::Time & _time) {
// keep location as last valid
if (!this->mDriftedOffTrack) {
this->mCurrentPassedDistance += length(this->mCurrentLocation - this->mLastLocation);
this->mLastLocation = this->mCurrentLocation;
// std::cout << "Passed Distance: " << this->mCurrentPassedDistance << std::endl;
}
// compute cars offset to the track segment and adjust it
sf::Vector2f proj = project(this->mCurrentLocation, this->mTrack[this->mSegmentStart], this->mTrack[this->mSegmentEnd]);
sf::Vector2f positionAdjust = proj - this->mCurrentLocation;
// apply drag friction
if (this->mVelocity > 0.0f) {
// this->mForce -= abs(Car::FRICTION_FORCE * (this->mVelocity) * (this->mDriftedOffTrack ? Car::DRAG_FRICTION_OFF_TRACK : Car::DRAG_FRICTION_ON_TRACK));
this->mForce -= abs(Car::FRICTION_FORCE * (this->mVelocity));
this->mForce -= abs(this->mIsAccelerating ? 0.0f : Car::BREAK_FRICTION * this->mVelocity);
this->mForce -= abs(!this->mDriftedOffTrack ? 0.0f : Car::DRAG_FRICTION_OFF_TRACK * this->mVelocity);
this->mIsAccelerating = false;
}
// compute acceleration A = F / M
float acceleration = this->mForce / Car::DEFAULT_MASS;
// compute velocity
this->mVelocity += acceleration * _time.asSeconds();
this->mVelocity = fmax(fmin(this->mVelocity, Car::MAX_VELOCITY), 0.0f);
//std::cout << "Velocity: " << this->mVelocity << std::endl;
// compute new position
this->mCurrentLocation += this->mCurrentDirection * (this->mVelocity * _time.asSeconds());
this->mCurrentLocation += positionAdjust;
this->keepOnTrack();
this->updateGhosts();
// compute rotation
float angle = heading(this->mCurrentDirection);
this->mCarDrawable.setRotation(RAD_TO_DEG(angle));
this->mCarDrawable.setPosition(this->mCurrentLocation);
// debug stuff
this->mLocationPoint.setPosition(this->mCurrentLocation);
this->mDirectionShape.setPosition(this->mCurrentLocation);
}
开发者ID:JannesMeyer,项目名称:rac0r,代码行数:49,代码来源:Car.cpp
示例14: Update
void GameStateGame::Update(const sf::Time& time)
{
SharedContext* context = m_stateMgr->GetContext();
EntityBase * player = context->entityManager->Find("Player");
if (!player)
{
std::cout << "Respawning player..." << std::endl;
context->entityManager->Add(EntityType::Player, "Player");
player = context->entityManager->Find("Player");
player->SetPosition(m_gameMap->GetPlayerStart());
std::cout << "Player respawned..." << std::endl;
}
else
{
m_view.setCenter(player->GetPosition());
context->window->GetRenderWindow()->setView(m_view);
}
sf::FloatRect viewSpace = context->window->GetViewSpace();
if (viewSpace.left <= 0)
{
m_view.setCenter(viewSpace.width / 2.0f, m_view.getCenter().y);
context->window->GetRenderWindow()->setView(m_view);
}
else if (viewSpace.left + viewSpace.width > (m_gameMap->GetMapSize().x) * TILE_SIZE)
{
m_view.setCenter(((m_gameMap->GetMapSize().x) * TILE_SIZE) - (viewSpace.width / 2.0f),
m_view.getCenter().y);
context->window->GetRenderWindow()->setView(m_view);
}
if (viewSpace.top <= 0)
{
m_view.setCenter(m_view.getCenter().x, viewSpace.height / 2.0f);
context->window->GetRenderWindow()->setView(m_view);
}
else if (viewSpace.top + viewSpace.height >
(m_gameMap->GetMapSize().y) * TILE_SIZE)
{
m_view.setCenter(m_view.getCenter().x,
((m_gameMap->GetMapSize().y) *
TILE_SIZE) - (viewSpace.height / 2.0f));
context->window->GetRenderWindow()->setView(m_view);
}
m_gameMap->Update(time.asSeconds());
m_stateMgr->GetContext()->entityManager->Update(time.asSeconds());
}
开发者ID:notrallon,项目名称:Gutland-Liberatus,代码行数:49,代码来源:GameStateGame.cpp
示例15: update
void Link::update(sf::Time dt)
{
if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerLeft->toBinding().Key))
move(-64*dt.asSeconds(), 0);
if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerRight->toBinding().Key))
move(+64*dt.asSeconds(), 0);
if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerUp->toBinding().Key))
move(0, -64*dt.asSeconds());
if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerDown->toBinding().Key))
move(0, +64*dt.asSeconds());
Player::update(dt);
m_currentSprite->setPosition(m_pos);
m_currentSprite->update(dt);
}
开发者ID:Antidote,项目名称:ALTTPRemake,代码行数:15,代码来源:Link.cpp
示例16: Update
void Spit_projectile::Update(sf::Time DeltaTime){
grav += gravity * DeltaTime.asSeconds();
m_Sprite.move(direction.x * speed * DeltaTime.asSeconds(), direction.y * speed * DeltaTime.asSeconds() + grav*DeltaTime.asSeconds() - distGY*DeltaTime.asSeconds());
if(this->checkCollisionPointInRadie(m_Sprite.getPosition(), player)){
player->takeDamage();
deleteMe = true;
}
spitAnim.update();
}
开发者ID:MasterKenth,项目名称:Mugito,代码行数:15,代码来源:Spit_projectile.cpp
示例17: update
void Paddle::update(sf::Time& dt){
atEdge();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && !(_atRight)){
_atLeft = false;
float delta = dt.asSeconds() * _xVel;
_paddle.move(delta, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && !(_atLeft)){
_atRight = false;
float delta = dt.asSeconds() * _xVel;
_paddle.move(-delta, 0);
}
}
开发者ID:minhasg,项目名称:Brick,代码行数:15,代码来源:Paddle.cpp
示例18: updatePosition
void GameObject::updatePosition(sf::Time elapsedTime)
{
sf::Vector2f acceleration(resultantForce.x / mass, resultantForce.y / mass);
//calculate velocity
sf::Vector2f newVelocity = velocity + acceleration*elapsedTime.asSeconds();
float newVelocityLen = ezo::vecLength(newVelocity.x, newVelocity.y);
if(newVelocityLen > maxVelocity)
velocity = {newVelocity.x/newVelocityLen*maxVelocity, newVelocity.y/newVelocityLen*maxVelocity};
else
velocity = newVelocity;
oldPosition = representation.getPosition();
representation.setPosition(representation.getPosition() + velocity*elapsedTime.asSeconds());
}
开发者ID:Sinity,项目名称:WSoC13,代码行数:15,代码来源:game_object.cpp
示例19: update
void World::update(sf::Time dt)
{
// Scroll the world, reset player velocity
mWorldView.move(0.f, mScrollSpeed * dt.asSeconds() * mScrollSpeedCompensation);
FOREACH(Aircraft* a, mPlayerAircrafts)
a->setVelocity(0.f, 0.f);
// Setup commands to destroy entities, and guide missiles
destroyEntitiesOutsideView();
guideMissiles();
// Forward commands to scene graph, adapt velocity (scrolling, diagonal correction)
while (!mCommandQueue.isEmpty())
mSceneGraph.onCommand(mCommandQueue.pop(), dt);
adaptPlayerVelocity();
// Collision detection and response (may destroy entities)
handleCollisions();
// Remove aircrafts that were destroyed (World::removeWrecks() only destroys the entities, not the pointers in mPlayerAircraft)
auto firstToRemove = std::remove_if(mPlayerAircrafts.begin(), mPlayerAircrafts.end(), std::mem_fn(&Aircraft::isMarkedForRemoval));
mPlayerAircrafts.erase(firstToRemove, mPlayerAircrafts.end());
// Remove all destroyed entities, create new ones
mSceneGraph.removeWrecks();
spawnEnemies();
// Regular update step, adapt position (correct if outside view)
mSceneGraph.update(dt, mCommandQueue);
adaptPlayerPosition();
updateSounds();
}
开发者ID:AlexanderButyaev,项目名称:SFML-Game-Development-Book,代码行数:35,代码来源:World.cpp
示例20: update
void WaveController::update(sf::Time const& elapsedTime) {
mTimeSinceWave += elapsedTime.asSeconds();
if (!mWaveQueue.empty() && isTimeToSpawnWave()) {
spawnWave();
}
}
开发者ID:AlexMeuer,项目名称:FinalYearProject,代码行数:7,代码来源:WaveController.cpp
注:本文中的sf::Time类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论