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

39 lines
1.1 KiB
C++
Raw Normal View History

2024-05-27 16:44:01 -03:00
#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)
2024-05-31 12:01:46 -03:00
{
2024-05-27 16:44:01 -03:00
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)
{
2024-05-31 12:01:46 -03:00
collectedSound->Play();
isCollected = true;
2024-05-27 16:44:01 -03:00
}
void Gem::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch)
2024-05-31 12:01:46 -03:00
{
2024-05-27 16:44:01 -03:00
spriteBatch.Draw(texture, Position(), nullptr, Color, 0.0f, origin, 1.0f, xna::SpriteEffects::None, 0.0f);
}
}