From 634503bf00e49b442ddb64bba452564dd81a2dba Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 22 Aug 2014 11:03:32 +0200 Subject: [PATCH] Add a line to the character to mark the collision bar. --- src/character.cpp | 9 +++++++++ src/character.hpp | 6 ++++++ src/colour.hpp | 1 + src/drawableline.cpp | 11 ++++++++++- src/horzcollisionbar.cpp | 3 ++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index f59b7e3..1d4757d 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -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(m_bottomBar.From()), static_cast(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(m_bottomBar.From()), static_cast(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 } ///------------------------------------------------------------------------- diff --git a/src/character.hpp b/src/character.hpp index 97f44a8..e2c5143 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -27,6 +27,9 @@ #include "sizenotifiable.hpp" #include "horzcollisionbar.hpp" #include "collidertypedef.hpp" +#if defined(WITH_DEBUG_VISUALS) +# include "drawableline.hpp" +#endif #include #include #include @@ -64,6 +67,9 @@ namespace cloonel { SizeNotifiable m_screenRatio; BounceCallbackType m_bounceCallback; const std::unique_ptr m_texture; +#if defined(WITH_DEBUG_VISUALS) + DrawableLine m_bottomBarDrawable; +#endif }; } //unnamed namespace diff --git a/src/colour.hpp b/src/colour.hpp index 1e06308..c3e41bf 100644 --- a/src/colour.hpp +++ b/src/colour.hpp @@ -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; diff --git a/src/drawableline.cpp b/src/drawableline.cpp index 8d3a5b5..6411193 100644 --- a/src/drawableline.cpp +++ b/src/drawableline.cpp @@ -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 } diff --git a/src/horzcollisionbar.cpp b/src/horzcollisionbar.cpp index 76704c4..6125455 100644 --- a/src/horzcollisionbar.cpp +++ b/src/horzcollisionbar.cpp @@ -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); } ///--------------------------------------------------------------------------