New TiledWallpaper class for the background.

This commit is contained in:
King_DuckZ 2014-03-06 11:42:56 +01:00
parent 83d139d4b5
commit 8d2ddaa9ff
5 changed files with 107 additions and 0 deletions

View file

@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
src/moverrelative.cpp src/moverrelative.cpp
src/inputbag.cpp src/inputbag.cpp
src/moverleftright.cpp src/moverleftright.cpp
src/tiledwallpaper.cpp
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}

View file

@ -24,6 +24,7 @@
#include "inputbag.hpp" #include "inputbag.hpp"
#include "key.hpp" #include "key.hpp"
#include "moverleftright.hpp" #include "moverleftright.hpp"
#include "tiledwallpaper.hpp"
#include <algorithm> #include <algorithm>
#include <SDL2/SDL_scancode.h> #include <SDL2/SDL_scancode.h>
#include <ciso646> #include <ciso646>
@ -63,17 +64,21 @@ namespace cloonel {
std::unique_ptr<MoverSine> moverSine(new MoverSine()); std::unique_ptr<MoverSine> moverSine(new MoverSine());
std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), ushort2(80, 120))); std::unique_ptr<Character> player(new Character("resources/graphics/player.png", SDLObject(), ushort2(80, 120)));
std::unique_ptr<MoverLeftRight> moverLeftRight(new MoverLeftRight(1.5f, 5.0f, 40.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()));
player->Prepare(); player->Prepare();
moverSine->RegisterPlaceable(player.get()); moverSine->RegisterPlaceable(player.get());
moverLeftRight->RegisterPlaceable(player.get()); moverLeftRight->RegisterPlaceable(player.get());
wallpaper->Reload();
std::swap(moverSine, m_moverSine); std::swap(moverSine, m_moverSine);
std::swap(player, m_player); std::swap(player, m_player);
std::swap(moverLeftRight, m_moverLeftRight); std::swap(moverLeftRight, m_moverLeftRight);
std::swap(wallpaper, m_wallpaper);
AddMover(m_moverSine.get()); AddMover(m_moverSine.get());
AddMover(m_moverLeftRight.get()); AddMover(m_moverLeftRight.get());
AddDrawable(m_wallpaper.get());
AddDrawable(m_player.get()); AddDrawable(m_player.get());
m_moverSine->SetPower(static_cast<float>(SDLObject()->DefWidthHeight().y() / 2)); m_moverSine->SetPower(static_cast<float>(SDLObject()->DefWidthHeight().y() / 2));
@ -85,6 +90,7 @@ namespace cloonel {
m_moverSine = std::move(std::unique_ptr<MoverSine>(nullptr)); m_moverSine = std::move(std::unique_ptr<MoverSine>(nullptr));
m_player = std::move(std::unique_ptr<Character>(nullptr)); m_player = std::move(std::unique_ptr<Character>(nullptr));
m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr)); m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr));
m_wallpaper = std::move(std::unique_ptr<TiledWallpaper>(nullptr));
} }
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------

View file

@ -28,6 +28,7 @@ namespace cloonel {
class Character; class Character;
class MoverSine; class MoverSine;
class MoverLeftRight; class MoverLeftRight;
class TiledWallpaper;
class GameplaySceneClassic : public GameplayScene { class GameplaySceneClassic : public GameplayScene {
public: public:
@ -46,6 +47,7 @@ namespace cloonel {
std::unique_ptr<Character> m_player; std::unique_ptr<Character> m_player;
std::unique_ptr<MoverSine> m_moverSine; std::unique_ptr<MoverSine> m_moverSine;
std::unique_ptr<MoverLeftRight> m_moverLeftRight; std::unique_ptr<MoverLeftRight> m_moverLeftRight;
std::unique_ptr<TiledWallpaper> m_wallpaper;
}; };
} //namespace cloonel } //namespace cloonel

54
src/tiledwallpaper.cpp Normal file
View file

@ -0,0 +1,54 @@
/*
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/>.
*/
#include "tiledwallpaper.hpp"
#include "texture.hpp"
namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
TiledWallpaper::TiledWallpaper (const std::string&& parPath, SDLMain* parMain) :
Drawable(0, 0),
m_tile(new Texture(parPath, parMain, false))
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
TiledWallpaper::~TiledWallpaper() noexcept {
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void TiledWallpaper::Reload() {
m_tile->Reload();
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void TiledWallpaper::Destroy() noexcept {
m_tile->Destroy();
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void TiledWallpaper::Draw() const {
m_tile->Render(int2(0));
}
} //namespace cloonel

44
src/tiledwallpaper.hpp Normal file
View file

@ -0,0 +1,44 @@
/*
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/>.
*/
#ifndef idDDB250A761E9458899C0687B7C8C5B7D
#define idDDB250A761E9458899C0687B7C8C5B7D
#include <memory>
#include "drawable.hpp"
namespace cloonel {
class Texture;
class SDLMain;
class TiledWallpaper : public Drawable {
public:
TiledWallpaper ( const std::string&& parPath, SDLMain* parMain );
virtual ~TiledWallpaper ( void ) noexcept;
void Reload ( void );
void Destroy ( void ) noexcept;
virtual void Draw ( void ) const;
private:
const std::unique_ptr<Texture> m_tile;
};
} //namespace cloonel
#endif