2014-02-25 10:04:16 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Michele "King_DuckZ" Santullo
|
|
|
|
|
|
|
|
This file is part of CloonelJump.
|
|
|
|
|
|
|
|
CloonelJump is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
CloonelJump is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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-07-05 18:33:16 +00:00
|
|
|
#include "moverworld.hpp"
|
2014-03-06 10:42:56 +00:00
|
|
|
#include "tiledwallpaper.hpp"
|
2014-03-28 09:52:59 +00:00
|
|
|
#include "texture.hpp"
|
|
|
|
#include "platformsystem.hpp"
|
2014-07-05 18:33:16 +00:00
|
|
|
#include "CloonelJumpConfig.h"
|
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:28:34 +00:00
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
GameplaySceneClassic::GameplaySceneClassic (SDLMain* parSdlMain) :
|
2014-03-06 09:56:02 +00:00
|
|
|
GameplayScene(parSdlMain)
|
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-07-05 18:33:16 +00:00
|
|
|
const float halfRefHeight = static_cast<float>(REFERENCE_HEIGHT) / 2.0f;
|
|
|
|
|
2014-02-21 20:51:56 +00:00
|
|
|
std::unique_ptr<MoverSine> moverSine(new MoverSine());
|
2014-03-12 10:04:22 +00:00
|
|
|
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), float2(80.0f, 120.0f)));
|
2014-03-05 21:09:32 +00:00
|
|
|
std::unique_ptr<MoverLeftRight> moverLeftRight(new MoverLeftRight(1.5f, 5.0f, 40.0f));
|
2014-07-05 18:33:16 +00:00
|
|
|
std::unique_ptr<MoverWorld> moverWorld(new MoverWorld(halfRefHeight));
|
2014-03-06 10:42:56 +00:00
|
|
|
std::unique_ptr<TiledWallpaper> wallpaper(new TiledWallpaper("resources/graphics/background_tile.png", SDLObject()));
|
2014-07-10 18:00:54 +00:00
|
|
|
std::unique_ptr<PlatformSystem> platforms(new PlatformSystem("resources/graphics/platform.png", SDLObject(), this, halfRefHeight * 0.9f));
|
2014-02-21 20:51:56 +00:00
|
|
|
|
|
|
|
player->Prepare();
|
2014-07-10 18:00:54 +00:00
|
|
|
platforms->Prepare();
|
2014-02-24 20:09:33 +00:00
|
|
|
moverSine->RegisterPlaceable(player.get());
|
2014-07-05 18:33:16 +00:00
|
|
|
moverSine->RegisterPlaceable(moverWorld.get()); //Keep an invisible mover
|
2014-02-24 23:36:33 +00:00
|
|
|
moverLeftRight->RegisterPlaceable(player.get());
|
2014-07-05 18:33:16 +00:00
|
|
|
moverWorld->RegisterPlaceable(player.get()); //It compensates the position when the chara goes over the mid
|
|
|
|
moverWorld->RegisterPlaceable(moverWorld.get()); //The mover has to be in sync with the character
|
2014-07-10 18:00:54 +00:00
|
|
|
moverWorld->RegisterPlaceable(platforms.get());
|
2014-03-06 10:42:56 +00:00
|
|
|
wallpaper->Reload();
|
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-07-05 18:33:16 +00:00
|
|
|
std::swap(moverWorld, m_moverWorld);
|
2014-03-06 10:42:56 +00:00
|
|
|
std::swap(wallpaper, m_wallpaper);
|
2014-03-28 09:52:59 +00:00
|
|
|
std::swap(platforms, m_platforms);
|
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-03-06 10:42:56 +00:00
|
|
|
AddDrawable(m_wallpaper.get());
|
2014-07-05 18:33:16 +00:00
|
|
|
AddMover(m_moverWorld.get());
|
|
|
|
m_platforms->AddDrawables();
|
2014-02-21 20:51:56 +00:00
|
|
|
AddDrawable(m_player.get());
|
2014-02-22 12:13:49 +00:00
|
|
|
|
2014-07-05 18:33:16 +00:00
|
|
|
const float jumpPower = halfRefHeight * 1.29f;
|
|
|
|
m_moverSine->SetPower(jumpPower);
|
2014-02-21 20:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
void GameplaySceneClassic::Destroy() noexcept {
|
2014-07-05 18:33:16 +00:00
|
|
|
//Destroy in reverse creation order
|
2014-03-28 09:52:59 +00:00
|
|
|
m_platforms = std::move(std::unique_ptr<PlatformSystem>(nullptr));
|
2014-07-05 18:33:16 +00:00
|
|
|
m_wallpaper = std::move(std::unique_ptr<TiledWallpaper>(nullptr));
|
|
|
|
m_moverWorld = std::move(std::unique_ptr<MoverWorld>(nullptr));
|
|
|
|
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));
|
2014-02-24 23:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
///--------------------------------------------------------------------------
|
|
|
|
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-03-28 09:52:59 +00:00
|
|
|
|
|
|
|
m_platforms->SpawnPlatforms();
|
2014-02-21 20:28:34 +00:00
|
|
|
}
|
|
|
|
} //namespace cloonel
|