Generate one platform and draw it. WiP.
This commit is contained in:
parent
4aef3a7c84
commit
fc50c6af55
5 changed files with 64 additions and 12 deletions
|
@ -25,6 +25,8 @@
|
|||
#include "key.hpp"
|
||||
#include "moverleftright.hpp"
|
||||
#include "tiledwallpaper.hpp"
|
||||
#include "texture.hpp"
|
||||
#include "platformsystem.hpp"
|
||||
#include <algorithm>
|
||||
#include <SDL2/SDL_scancode.h>
|
||||
#include <ciso646>
|
||||
|
@ -61,16 +63,19 @@ namespace cloonel {
|
|||
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), float2(80.0f, 120.0f)));
|
||||
std::unique_ptr<MoverLeftRight> moverLeftRight(new MoverLeftRight(1.5f, 5.0f, 40.0f));
|
||||
std::unique_ptr<TiledWallpaper> wallpaper(new TiledWallpaper("resources/graphics/background_tile.png", SDLObject()));
|
||||
std::unique_ptr<PlatformSystem> platforms(new PlatformSystem("resources/graphics/platform.png", SDLObject(), this));
|
||||
|
||||
player->Prepare();
|
||||
moverSine->RegisterPlaceable(player.get());
|
||||
moverLeftRight->RegisterPlaceable(player.get());
|
||||
wallpaper->Reload();
|
||||
platforms->Prepare();
|
||||
|
||||
std::swap(moverSine, m_moverSine);
|
||||
std::swap(player, m_player);
|
||||
std::swap(moverLeftRight, m_moverLeftRight);
|
||||
std::swap(wallpaper, m_wallpaper);
|
||||
std::swap(platforms, m_platforms);
|
||||
|
||||
AddMover(m_moverSine.get());
|
||||
AddMover(m_moverLeftRight.get());
|
||||
|
@ -87,6 +92,7 @@ namespace cloonel {
|
|||
m_player = std::move(std::unique_ptr<Character>(nullptr));
|
||||
m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr));
|
||||
m_wallpaper = std::move(std::unique_ptr<TiledWallpaper>(nullptr));
|
||||
m_platforms = std::move(std::unique_ptr<PlatformSystem>(nullptr));
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -102,5 +108,7 @@ namespace cloonel {
|
|||
else {
|
||||
m_moverLeftRight->SetMovement(MoverLeftRight::MovementDirection_Still);
|
||||
}
|
||||
|
||||
m_platforms->SpawnPlatforms();
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace cloonel {
|
|||
class MoverSine;
|
||||
class MoverLeftRight;
|
||||
class TiledWallpaper;
|
||||
class Texture;
|
||||
class PlatformSystem;
|
||||
|
||||
class GameplaySceneClassic : public GameplayScene {
|
||||
public:
|
||||
|
@ -45,6 +47,7 @@ namespace cloonel {
|
|||
std::unique_ptr<MoverSine> m_moverSine;
|
||||
std::unique_ptr<MoverLeftRight> m_moverLeftRight;
|
||||
std::unique_ptr<TiledWallpaper> m_wallpaper;
|
||||
std::unique_ptr<PlatformSystem> m_platforms;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace cloonel {
|
|||
Platform& operator= ( Platform&& parOther ) = delete;
|
||||
|
||||
virtual void Draw ( void ) const;
|
||||
const float2& TopLeft ( void ) const { return m_position; }
|
||||
float2 BottomRight ( void ) const { return m_position + m_size; }
|
||||
|
||||
private:
|
||||
SizeNotifiable<regbehaviuors::AutoRegister> m_screenRatio;
|
||||
|
|
|
@ -19,19 +19,24 @@
|
|||
|
||||
#include "platformsystem.hpp"
|
||||
#include "platform.hpp"
|
||||
#include "CloonelJumpConfig.h"
|
||||
#include "texture.hpp"
|
||||
#include "gameplayscene.hpp"
|
||||
#include <ciso646>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
PlatformSystem::PlatformSystem() :
|
||||
m_platforms()
|
||||
PlatformSystem::PlatformSystem (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene) :
|
||||
m_sizeRatio(parSDLMain),
|
||||
m_platforms(),
|
||||
m_texture(new Texture(parTexturePath, parSDLMain, false)),
|
||||
m_sdlmain(parSDLMain),
|
||||
m_scene(parScene)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
PlatformSystem::PlatformSystem (PlatformSystem&& parOther) {
|
||||
m_platforms.swap(parOther.m_platforms);
|
||||
assert(m_sdlmain);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
|
@ -42,10 +47,32 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::SpawnPlatforms() {
|
||||
const int2 refWH(REFERENCE_WIDTH, REFERENCE_HEIGHT);
|
||||
const int2 platfWH(110, 30);
|
||||
if (m_platforms.empty()) {
|
||||
const float2 newPos(static_cast<float>(std::rand() % (refWH.x() - platfWH.x())), static_cast<float>(std::rand() % (refWH.y() - platfWH.y())));
|
||||
m_platforms.push(Platform(m_sdlmain, newPos, m_texture.get(), static_cast<float2>(platfWH)));
|
||||
m_scene->AddDrawable(&m_platforms.back());
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::GarbageCollect() {
|
||||
while (not m_platforms.empty() and m_platforms.front().TopLeft().y() <= 0.0f) {
|
||||
m_platforms.pop();
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::Prepare() {
|
||||
m_texture->Reload();
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::Destroy() noexcept {
|
||||
m_texture->Destroy();
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -19,24 +19,36 @@
|
|||
|
||||
#ifndef id17908979556C47F8A978688BBE4A9D22
|
||||
|
||||
#include <vector>
|
||||
#include "sizenotifiable.hpp"
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
|
||||
namespace cloonel {
|
||||
class Platform;
|
||||
class SDLMain;
|
||||
class Texture;
|
||||
class GameplayScene;
|
||||
|
||||
class PlatformSystem {
|
||||
public:
|
||||
PlatformSystem ( void );
|
||||
PlatformSystem ( void ) = delete;
|
||||
PlatformSystem ( const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene );
|
||||
PlatformSystem ( const PlatformSystem& ) = delete;
|
||||
PlatformSystem ( PlatformSystem&& parOther );
|
||||
PlatformSystem ( PlatformSystem&& parOther ) = delete;
|
||||
~PlatformSystem ( void ) noexcept;
|
||||
PlatformSystem& operator= ( const PlatformSystem& ) = delete;
|
||||
|
||||
void Prepare ( void );
|
||||
void Destroy ( void ) noexcept;
|
||||
void SpawnPlatforms ( void );
|
||||
void GarbageCollect ( void );
|
||||
|
||||
private:
|
||||
std::vector<Platform> m_platforms;
|
||||
SizeNotifiable<regbehaviuors::AutoRegister> m_sizeRatio;
|
||||
std::queue<Platform> m_platforms;
|
||||
const std::unique_ptr<Texture> m_texture;
|
||||
SDLMain* const m_sdlmain;
|
||||
GameplayScene* const m_scene;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
Loading…
Reference in a new issue