#include "gem.hpp" #include "level.hpp" namespace PlatformerStarterKit { Gem::Gem(xna::sptr const& level, xna::Vector2 const& position) : level(level), basePosition(position){ LoadContent(); } void Gem::LoadContent() { texture = level->Content()->Load("Sprites/Gem"); origin = xna::Vector2(texture->Width() / 2.0f, texture->Height() / 2.0f); collectedSound = level->Content()->Load("Sounds/GemCollected"); } void Gem::Update(xna::GameTime const& gameTime) { constexpr float BounceHeight = 0.18f; constexpr float BounceRate = 3.0f; constexpr float BounceSync = -0.75f; const auto t = gameTime.TotalGameTime.TotalSeconds() * BounceRate + Position().X * BounceSync; bounce = static_cast(std::sin(t)) * BounceHeight * texture->Height(); } void Gem::OnCollected(xna::sptr& collectedBy) { collectedSound->Play(); isCollected = true; } void Gem::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch) { spriteBatch.Draw(texture, Position(), std::nullopt, Color, 0.0f, origin, 1.0f, xna::SpriteEffects::None, 0.0f); } }