Add a line to the character to mark the collision bar.

This commit is contained in:
King_DuckZ 2014-08-22 11:03:32 +02:00
parent 5026ce2c53
commit 634503bf00
5 changed files with 28 additions and 2 deletions

View file

@ -39,6 +39,9 @@ namespace cloonel {
m_screenRatio(parMain),
m_bounceCallback(&DoNothing),
m_texture(new Texture(parPath, parMain, false))
#if defined(WITH_DEBUG_VISUALS)
, m_bottomBarDrawable(parMain, Colour(250, 5, 1), static_cast<ushort2>(m_bottomBar.From()), static_cast<ushort2>(m_bottomBar.To()))
#endif
{
assert(parMain);
m_bottomBar.SetCallback(std::bind(&Character::OnBounce, this, std::placeholders::_1, std::placeholders::_2));
@ -53,6 +56,9 @@ namespace cloonel {
m_screenRatio(parMain),
m_bounceCallback(&DoNothing),
m_texture(new Texture(parPath, parMain, false))
#if defined(WITH_DEBUG_VISUALS)
, m_bottomBarDrawable(parMain, Colour(250, 5, 1), static_cast<ushort2>(m_bottomBar.From()), static_cast<ushort2>(m_bottomBar.To()))
#endif
{
assert(parMain);
m_bottomBar.SetCallback(std::bind(&Character::OnBounce, this, std::placeholders::_1, std::placeholders::_2));
@ -88,6 +94,9 @@ namespace cloonel {
///-------------------------------------------------------------------------
void Character::Draw() const {
m_texture->Render(GetPos(), WidthHeight(), m_screenRatio.Ratio(), true);
#if defined(WITH_DEBUG_VISUALS)
m_bottomBarDrawable.Render(GetPos(), m_screenRatio.Ratio());
#endif
}
///-------------------------------------------------------------------------

View file

@ -27,6 +27,9 @@
#include "sizenotifiable.hpp"
#include "horzcollisionbar.hpp"
#include "collidertypedef.hpp"
#if defined(WITH_DEBUG_VISUALS)
# include "drawableline.hpp"
#endif
#include <string>
#include <memory>
#include <cstdint>
@ -64,6 +67,9 @@ namespace cloonel {
SizeNotifiable<regbehaviours::AutoRegister> m_screenRatio;
BounceCallbackType m_bounceCallback;
const std::unique_ptr<Texture> m_texture;
#if defined(WITH_DEBUG_VISUALS)
DrawableLine m_bottomBarDrawable;
#endif
};
} //unnamed namespace

View file

@ -30,6 +30,7 @@ namespace cloonel {
Colour ( void ) = default;
Colour ( ChannelType parR, ChannelType parG, ChannelType parB, ChannelType parA );
Colour ( ChannelType parR, ChannelType parG, ChannelType parB ) : Colour(parR, parG, parB, 0xFF) {}
explicit Colour ( ChannelType parFill );
Colour ( const Colour& parOther ) = default;

View file

@ -67,7 +67,16 @@ namespace cloonel {
ClipLine(screen, scaledLine);
}
//SDL_RenderDrawLine(m_sdlmain->GetRenderer(), x1, y1, x2, y2
const uint16_t h = m_sdlmain->WidthHeight().y();
if (scaledLine[0] != scaledLine[1]) {
SDL_RenderDrawLine(
m_sdlmain->GetRenderer(),
scaledLine[0].x(),
h - scaledLine[0].y(),
scaledLine[1].x(),
h - scaledLine[1].y()
);
}
//Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.
//http://www.ginkgobitter.org/sdl/?SDL_RenderDrawLine
}

View file

@ -97,7 +97,8 @@ namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
float2 HorzCollisionBar::To() const {
return this->GetPos() + len(m_segment);
assert(m_segment.End().x() - m_segment.Start().x() != 0.0f);
return this->GetPos() + float2(std::abs(m_segment.End().x() - m_segment.Start().x()), 0.0f);
}
///--------------------------------------------------------------------------