1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
2024-06-06 14:18:16 -03:00

39 lines
1.1 KiB
C++

#include "gem.hpp"
#include "level.hpp"
namespace PlatformerStarterKit {
Gem::Gem(xna::sptr<PlatformerStarterKit::Level> const& level, xna::Vector2 const& position) :
level(level), basePosition(position){
LoadContent();
}
void Gem::LoadContent()
{
texture = level->Content()->Load<xna::PTexture2D>("Sprites/Gem");
origin = xna::Vector2(texture->Width() / 2.0f, texture->Height() / 2.0f);
collectedSound = level->Content()->Load<xna::PSoundEffect>("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<float>(std::sin(t)) * BounceHeight * texture->Height();
}
void Gem::OnCollected(xna::sptr<Player>& 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);
}
}