void Cannon::Animate() { Enemy::Animate(); bool bLeft = Player::GetPlayer().GetPos().x < m_pos.x; SetAnimationFrame(bLeft ? 1 : 0); }
void Player::Update(const jutil::GameTime& timespan) { if (m_Health <= 0) { HandleDeath(timespan); return; } if (m_TimerInvincibility.ElapsedMilliseconds() < INVINCIBILITY_TIME) { HandleInvincibility(timespan); } else { SetAlpha(1.f); m_PlayerState = UNKNOWN; } HandleLevelCollisionResolution(timespan); // Jumping controls if (m_PlayerState != TAKING_DAMAGE) { HandleControls(timespan); } HandleBullets(timespan); SetAnimationFrame(); }
void Flier2::Animate() { Enemy::Animate(); if ((Player::GetPlayer().GetPos().x >= m_pos.x)) { if (m_nAnimationFrame == 2) { SetAnimationFrame(0); } } else { if (m_nAnimationFrame == 0) { SetAnimationFrame(2); } } }
void Font::Render(int x, int y, Engine::EColor eColor, const std::string& text) { SetColor(eColor); Vector2 pos(static_cast<float>(x), static_cast<float>(y)); for (std::string::const_iterator it = text.begin(), itEnd = text.end(); it != itEnd; ++it) { SetAnimationFrame(*it); SetPos(pos); Sprite::Render(); pos.x += m_nWidth; } }
void BigZ::Animate() { Enemy::Animate(); SetAnimationFrame((Player::GetPlayer().GetPos().x >= m_pos.x) ? 0 : 1); }
// Animation that plays on death - twelve circles with oscillating radiuses that move away from the player void Player::HandleDeath(const jutil::GameTime& timespan) { // If we've just entered, put all the sprites in place if (m_TimerDeath.ElapsedMilliseconds() == 0) { for (int i = 0; i < m_DeathSprites.size(); ++i) m_DeathSprites[i].SetPosition(GetPosition()); } else // Otherwise, we're under way - animate { // Oscillate the radius if (m_DeathSpriteFlickerCounter > 4) m_DeathSpriteFlicker = false; else if (m_DeathSpriteFlickerCounter < 1) m_DeathSpriteFlicker = true; if (m_DeathSpriteFlicker) m_DeathSpriteFlickerCounter++; else m_DeathSpriteFlickerCounter--; for (int i = 0; i < m_DeathSprites.size(); ++i) m_DeathSprites[i].SetCurrentFrame(m_DeathSpriteFlickerCounter); // Move all the circles outwards in the right directions float d = timespan.GetDeltaTime(); for (int i = 0; i < 2; i++, d = -d) m_DeathSprites[i].Move(jmath::vec2(d, d)); for (int i = 2; i < 4; i++, d = -d) m_DeathSprites[i].Move(jmath::vec2(-d, d)); for (int i = 4; i < 6; ++i, d = -d) m_DeathSprites[i].MoveX(d*1.6f); for (int i = 6; i < 8; ++i, d = -d) m_DeathSprites[i].MoveY(d*1.6f); for (int i = 8; i < 10; ++i, d = -d) m_DeathSprites[i].MoveX(d*0.4f); for (int i = 10; i < 12; ++i, d = -d) m_DeathSprites[i].MoveY(d*0.4f); } m_TimerDeath += timespan; m_TimerInvincibility.SetTime(JTime::Milliseconds(INVINCIBILITY_TIME)); // If we're done dying, reset everything if (m_TimerDeath.ElapsedMilliseconds() > 5850) // 5300 { m_TimerDeath.SetTime(0); m_Health = 28; } // If we're done dying, get ready to spawn back in else if (m_TimerDeath.ElapsedMilliseconds() > 5400) { float n = jmath::Normalise(5400.f, 5800.f, (float)m_TimerDeath.ElapsedMilliseconds()); if (n > 0.9f) { if (GetCurrentFrame() == 1) SetCurrentFrame(2); else SetCurrentFrame(3); } else SetRectangle(jmath::vec4(120, 8, 24, 32)); SetAnimationFrame(); if (n > 1.f) n = 1.f; jmath::vec2 r = m_RespawnPos; r.y = jmath::Lerp(m_RespawnPos.y - 240, m_RespawnPos.y - 5, n); SetPosition(r); } // If we've played the animation, set player to spawn pos else if (m_Health != INT_MIN && m_TimerDeath.ElapsedMilliseconds() > 2300) { jmath::vec2 r = m_RespawnPos; m_Health = INT_MIN; r.y -= 240; SetPosition(r); SetAnimationFrame(); } }