2014-02-21 20:28:34 +00:00
|
|
|
#include "gameplaysceneclassic.hpp"
|
2014-02-21 20:51:56 +00:00
|
|
|
#include "character.hpp"
|
|
|
|
#include "moversine.hpp"
|
2014-02-22 12:13:49 +00:00
|
|
|
#include "sdlmain.hpp"
|
2014-02-24 20:16:00 +00:00
|
|
|
#include "inputbag.hpp"
|
|
|
|
#include "key.hpp"
|
2014-02-24 23:36:33 +00:00
|
|
|
#include "moverleftright.hpp"
|
2014-02-21 20:51:56 +00:00
|
|
|
#include <algorithm>
|
2014-02-24 20:16:00 +00:00
|
|
|
#include <SDL2/SDL_scancode.h>
|
2014-02-24 23:36:33 +00:00
|
|
|
#include <ciso646>
|
2014-02-21 20:28:34 +00:00
|
|
|
|
|
|
|
namespace cloonel {
|
2014-02-24 20:16:00 +00:00
|
|
|
namespace {
|
|
|
|
enum GameActionType {
|
|
|
|
GameAction_Left,
|
|
|
|
GameAction_Right
|
|
|
|
};
|
|
|
|
} //unnamed namespace
|
|
|
|
|
2014-02-21 20:51:56 +00:00
|
|
|
struct GameplaySceneClassic::LocalData {
|
|
|
|
};
|
|
|
|
|
2014-02-21 20:28:34 +00:00
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
GameplaySceneClassic::GameplaySceneClassic (SDLMain* parSdlMain) :
|
2014-02-21 20:51:56 +00:00
|
|
|
GameplayScene(parSdlMain),
|
|
|
|
m_local(new LocalData)
|
2014-02-21 20:28:34 +00:00
|
|
|
{
|
2014-02-24 20:16:00 +00:00
|
|
|
//TODO: replace the hardcoded bindings with something more customizable.
|
|
|
|
InputBag& input = *InputBagObject();
|
|
|
|
input.AddAction(GameAction_Left, Key(InputDevice_Keyboard, SDL_SCANCODE_LEFT), "Move left");
|
2014-02-24 23:36:33 +00:00
|
|
|
input.AddAction(GameAction_Right, Key(InputDevice_Keyboard, SDL_SCANCODE_RIGHT), "Move right");
|
2014-02-21 20:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
GameplaySceneClassic::~GameplaySceneClassic() noexcept {
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
void GameplaySceneClassic::Prepare() {
|
2014-02-21 20:51:56 +00:00
|
|
|
std::unique_ptr<MoverSine> moverSine(new MoverSine());
|
2014-02-22 11:25:16 +00:00
|
|
|
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), ushort2(80, 120)));
|
2014-02-24 23:36:33 +00:00
|
|
|
std::unique_ptr<MoverLeftRight> moverLeftRight(new MoverLeftRight());
|
2014-02-21 20:51:56 +00:00
|
|
|
|
|
|
|
player->Prepare();
|
2014-02-24 20:09:33 +00:00
|
|
|
moverSine->RegisterPlaceable(player.get());
|
2014-02-24 23:36:33 +00:00
|
|
|
moverLeftRight->RegisterPlaceable(player.get());
|
2014-02-21 20:51:56 +00:00
|
|
|
|
|
|
|
std::swap(moverSine, m_moverSine);
|
|
|
|
std::swap(player, m_player);
|
2014-02-24 23:36:33 +00:00
|
|
|
std::swap(moverLeftRight, m_moverLeftRight);
|
2014-02-21 20:51:56 +00:00
|
|
|
|
|
|
|
AddMover(m_moverSine.get());
|
2014-02-24 23:36:33 +00:00
|
|
|
AddMover(m_moverLeftRight.get());
|
2014-02-21 20:51:56 +00:00
|
|
|
AddDrawable(m_player.get());
|
2014-02-22 12:13:49 +00:00
|
|
|
|
|
|
|
m_moverSine->SetPower(static_cast<float>(SDLObject()->DefWidthHeight().y() / 2));
|
2014-02-21 20:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
void GameplaySceneClassic::Destroy() noexcept {
|
2014-02-21 20:51:56 +00:00
|
|
|
m_moverSine = std::move(std::unique_ptr<MoverSine>(nullptr));
|
|
|
|
m_player = std::move(std::unique_ptr<Character>(nullptr));
|
2014-02-24 23:36:33 +00:00
|
|
|
m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
void GameplaySceneClassic::OnPreUpdate() {
|
|
|
|
InputBag& input = *InputBagObject();
|
|
|
|
if (IsPressed(input, GameAction_Left)) {
|
|
|
|
m_moverLeftRight->SetMovement(MoverLeftRight::MovementDirection_Left);
|
|
|
|
}
|
|
|
|
else if (IsPressed(input, GameAction_Right)) {
|
|
|
|
m_moverLeftRight->SetMovement(MoverLeftRight::MovementDirection_Right);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_moverLeftRight->SetMovement(MoverLeftRight::MovementDirection_Still);
|
|
|
|
}
|
2014-02-21 20:28:34 +00:00
|
|
|
}
|
|
|
|
} //namespace cloonel
|