Bouncing works but going too high causes an assertion.

This commit also reduces the jump size and the character's size.
This commit is contained in:
King_DuckZ 2014-08-03 15:13:54 +02:00
parent df8f5ca6b2
commit 164030202c
9 changed files with 82 additions and 7 deletions

View file

@ -21,9 +21,15 @@
#include "sdlmain.hpp"
#include "texture.hpp"
#include "collider.hpp"
#include "line.hpp"
#include <cassert>
namespace cloonel {
namespace {
void DoNothing (const Line<float, 2>&, const float2&) {
}
} //unnamed namespace
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
Character::Character (const std::string& parPath, SDLMain* parMain, float2 parSize) :
@ -31,9 +37,11 @@ namespace cloonel {
Drawable(parSize),
m_bottomBar(float2(0.0f), parSize.x()),
m_screenRatio(parMain),
m_bounceCallback(&DoNothing),
m_texture(new Texture(parPath, parMain, false))
{
assert(parMain);
m_bottomBar.SetCallback(std::bind(&Character::OnBounce, this, std::placeholders::_1, std::placeholders::_2));
}
///-------------------------------------------------------------------------
@ -43,9 +51,11 @@ namespace cloonel {
Drawable(parSize),
m_bottomBar(float2(0.0f), parSize.x()),
m_screenRatio(parMain),
m_bounceCallback(&DoNothing),
m_texture(new Texture(parPath, parMain, false))
{
assert(parMain);
m_bottomBar.SetCallback(std::bind(&Character::OnBounce, this, std::placeholders::_1, std::placeholders::_2));
}
///-------------------------------------------------------------------------
@ -85,4 +95,21 @@ namespace cloonel {
void Character::OnRegister (Mover& parMover, Mover::PlaceableTicketType parParentTicket) {
parMover.RegisterPlaceable(&m_bottomBar, parParentTicket);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
void Character::SetOnBounceCallback (BounceCallbackType parCallb) {
m_bounceCallback = parCallb;
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
void Character::OnBounce (const Line<float, 2>& parCollision, const float2& parDirection) {
if (parDirection.y() < 0.0f) {
const float2 newPos(GetPos().x(), parCollision.Start().y());
this->SetAbsolutePosition(newPos);
m_bottomBar.SetAbsolutePosition(newPos);
m_bounceCallback(parCollision, parDirection);
}
}
} //namespace cloonel