Add code to register objects to the collider.
The character and the platforms can register now, but collision is not triggered for some reason.
This commit is contained in:
parent
42fb50e93e
commit
cdd37fead7
13 changed files with 133 additions and 10 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <algorithm>
|
||||
#include <SDL2/SDL_scancode.h>
|
||||
#include <ciso646>
|
||||
#include <functional>
|
||||
|
||||
namespace cloonel {
|
||||
namespace {
|
||||
|
@ -39,6 +40,12 @@ namespace cloonel {
|
|||
GameAction_Left,
|
||||
GameAction_Right
|
||||
};
|
||||
|
||||
enum {
|
||||
CollisionID_Platforms,
|
||||
CollisionID_Player,
|
||||
CollisionID_Enemies
|
||||
};
|
||||
} //unnamed namespace
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -62,6 +69,7 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
void GameplaySceneClassic::OnPrepare() {
|
||||
const float halfRefHeight = static_cast<float>(REFERENCE_HEIGHT) / 2.0f;
|
||||
Collider& collider = *this->GetCollider();
|
||||
|
||||
std::unique_ptr<MoverSine> moverSine(new MoverSine());
|
||||
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), float2(80.0f, 120.0f)));
|
||||
|
@ -80,6 +88,15 @@ namespace cloonel {
|
|||
moverWorld->RegisterPlaceable(platforms.get());
|
||||
wallpaper->Reload();
|
||||
|
||||
{
|
||||
auto regPlayerCollision(std::bind(&Collider::RegisterBar, &collider, CollisionID_Player, std::placeholders::_1));
|
||||
player->RegisterForCollision(regPlayerCollision);
|
||||
|
||||
auto regPlatfCollision(std::bind(&Collider::RegisterBar, &collider, CollisionID_Platforms, std::placeholders::_1));
|
||||
auto unregPlatfCollision(std::bind(&Collider::UnregisterBar, &collider, CollisionID_Platforms, std::placeholders::_1));
|
||||
platforms->RegisterForCollision(regPlatfCollision, unregPlatfCollision);
|
||||
}
|
||||
|
||||
std::swap(moverSine, m_moverSine);
|
||||
std::swap(player, m_player);
|
||||
std::swap(moverLeftRight, m_moverLeftRight);
|
||||
|
@ -96,6 +113,9 @@ namespace cloonel {
|
|||
|
||||
const float jumpPower = halfRefHeight * 1.29f;
|
||||
m_moverSine->SetPower(jumpPower);
|
||||
|
||||
collider.TieGroups(CollisionID_Platforms, CollisionID_Player);
|
||||
//collider.TieGroups(CollisionID_Enemies, CollisionID_Player);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -110,7 +130,6 @@ namespace cloonel {
|
|||
m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr));
|
||||
m_player = std::move(std::unique_ptr<Character>(nullptr));
|
||||
m_moverSine = std::move(std::unique_ptr<MoverSine>(nullptr));
|
||||
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue