SpelunkyRemake / PowerUp.cpp
PowerUp.cpp
Raw
#include "pch.h"
#include "PowerUp.h"

PowerUp::PowerUp(const Point2f& center, PowerUp::Type type)
	: m_Shape{ Circlef{ center, 0 } }
	, m_Type{ type }
	, m_Texture{ "Resources/Images/PowerUp.png" }
	, m_Angle{}
	, m_RotSpeed{ 360 }
	, m_TextClip{ GetTextClip(type) }
{
	m_Shape.radius = m_Texture.GetWidth() / 2;
}

void PowerUp::Update(float elapsedSec)
{
	m_Angle += m_RotSpeed * elapsedSec;
}

bool PowerUp::IsOverlapping(const Rectf& rect) const
{
	if (utils::IsOverlapping(rect, m_Shape))
	{
		return true;
	}

	return false;
}

void PowerUp::Draw() const
{
	glPushMatrix();
	{
		glTranslatef(m_Shape.center.x, m_Shape.center.y, 0.f);
		glRotatef(m_Angle, 0.f, 0.f, 1.0f);
		m_Texture.Draw(Point2f{ -m_TextClip.width / 2, -m_TextClip.height / 2 }, m_TextClip);
	}
	glPopMatrix();
}

Rectf PowerUp::GetTextClip(PowerUp::Type type) const
{
	Rectf textClip;

	if (type == Type::green)
	{
		textClip = Rectf{ 0, m_Texture.GetHeight() / 2, m_Texture.GetWidth(), m_Texture.GetHeight() / 2 };
	}
	else if (type == Type::brown)
	{
		textClip = Rectf{ 0, 0, m_Texture.GetWidth(), m_Texture.GetHeight() / 2 };
	}

	return textClip;
}