diff --git a/src/character.cpp b/src/character.cpp index b074b02..6bebda4 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -5,16 +5,18 @@ namespace cloonel { ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- - Character::Character (const std::string& parPath, SDLMain* parMain) : + Character::Character (const std::string& parPath, SDLMain* parMain, ushort2 parSize) : Placeable(0.0f, 0.0f), + Drawable(parSize), m_texture(new Texture(parPath, parMain, false)) { } ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- - Character::Character (const std::string&& parPath, SDLMain* parMain) : + Character::Character (const std::string&& parPath, SDLMain* parMain, ushort2 parSize) : Placeable(0.0f, 0.0f), + Drawable(parSize), m_texture(new Texture(parPath, parMain, false)) { } @@ -27,6 +29,9 @@ namespace cloonel { ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- void Character::Prepare() { + const SDLMain* const sdlmain = m_texture->SDLObject(); + const int2 screensize(sdlmain->DefWidthHeight()); + m_texture->Reload(); } @@ -40,6 +45,6 @@ namespace cloonel { ///------------------------------------------------------------------------- void Character::Draw() const { const int2 pos(m_pos + 0.5f); - m_texture->Render(pos); + m_texture->Render(pos, m_wh); } } //namespace cloonel diff --git a/src/character.hpp b/src/character.hpp index 995abad..3582d44 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -13,8 +13,8 @@ namespace cloonel { class Character : public Placeable, public Drawable { public: - Character ( const std::string& parPath, SDLMain* parMain ); - Character ( const std::string&& parPath, SDLMain* parMain ); + Character ( const std::string& parPath, SDLMain* parMain, ushort2 parSize ); + Character ( const std::string&& parPath, SDLMain* parMai, ushort2 parSize ); virtual ~Character ( void ) noexcept; void Prepare ( void ); diff --git a/src/drawable.hpp b/src/drawable.hpp index 80a6cde..7174610 100644 --- a/src/drawable.hpp +++ b/src/drawable.hpp @@ -1,13 +1,21 @@ #ifndef idC5A880D06A03407DB4E9FC21593A47FB #define idC5A880D06A03407DB4E9FC21593A47FB +#include "vector.hpp" +#include + namespace cloonel { class Drawable { public: Drawable ( void ) = default; + Drawable ( uint16_t parWidth, uint16_t parHeight ) : m_wh(parWidth, parHeight) {} + explicit Drawable ( ushort2 parWH ) : m_wh(parWH) {} virtual ~Drawable ( void ) noexcept = default; virtual void Draw ( void ) const = 0; + + protected: + ushort2 m_wh; }; } //namespace cloonel diff --git a/src/gameplaysceneclassic.cpp b/src/gameplaysceneclassic.cpp index 6bb9140..932b0c9 100644 --- a/src/gameplaysceneclassic.cpp +++ b/src/gameplaysceneclassic.cpp @@ -25,7 +25,7 @@ namespace cloonel { ///-------------------------------------------------------------------------- void GameplaySceneClassic::Prepare() { std::unique_ptr moverSine(new MoverSine()); - std::unique_ptr player(new Character("resources/graphics/player.png", SDLObject())); + std::unique_ptr player(new Character("resources/graphics/player.png", SDLObject(), ushort2(80, 120))); player->Prepare(); player->SwapMover(moverSine.get()); diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index ed2c6b1..03d70a0 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -13,8 +13,7 @@ namespace cloonel { SDLMain::SDLMain (const char* parGameName, int parWidth, int parHeight) : m_gameName(parGameName), m_localData(new LocalData), - m_defWidth(parWidth), - m_defHeight(parHeight) + m_defWH(parWidth, parHeight) { } @@ -42,7 +41,7 @@ namespace cloonel { throw std::runtime_error(SDL_GetError()); parInitSDL.initialized = true; - SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_defWidth, m_defHeight, SDL_WINDOW_SHOWN); + SDL_Window* const win = SDL_CreateWindow(m_gameName.c_str(), 100, 100, m_defWH.x(), m_defWH.y(), SDL_WINDOW_SHOWN); if (!win) throw std::runtime_error(SDL_GetError()); parInitSDL.window = win; diff --git a/src/sdlmain.hpp b/src/sdlmain.hpp index 43760d9..a6a0d04 100644 --- a/src/sdlmain.hpp +++ b/src/sdlmain.hpp @@ -1,6 +1,7 @@ #ifndef id8E7A054DAC9040B887F2620EFD229EE8 #define id8E7A054DAC9040B887F2620EFD229EE8 +#include "vector.hpp" #include struct SDL_Renderer; @@ -13,6 +14,7 @@ namespace cloonel { void Init ( void ); SDL_Renderer* GetRenderer ( void ); + const int2& DefWidthHeight ( void ) const { return m_defWH; } private: struct LocalData; @@ -22,8 +24,7 @@ namespace cloonel { const std::string m_gameName; std::unique_ptr m_localData; - const int m_defWidth; - const int m_defHeight; + const int2 m_defWH; }; } //namespace cloonel diff --git a/src/texture.cpp b/src/texture.cpp index 54d7bae..f2c6473 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -223,9 +223,9 @@ namespace cloonel { ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- - void Texture::Render (int2 parPos) const { + void Texture::Render (int2 parPos, ushort2 parSize) const { assert(IsLoaded()); - const SDL_Rect dest = { parPos.x(), parPos.y(), m_size.x(), m_size.y() }; + const SDL_Rect dest = { parPos.x(), parPos.y(), parSize.x(), parSize.y() }; SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest); } } //namespace cloonel diff --git a/src/texture.hpp b/src/texture.hpp index e3a5fe7..6abd248 100644 --- a/src/texture.hpp +++ b/src/texture.hpp @@ -17,7 +17,9 @@ namespace cloonel { void Reload ( void ); void Destroy ( void ) noexcept; bool IsLoaded ( void ) const { return nullptr != m_texture; } - void Render ( int2 parPos ) const; + void Render ( int2 parPos ) const { Render(parPos, m_size); } + void Render ( int2 parPos, ushort2 parSize ) const; + const SDLMain* SDLObject ( void ) const { return m_sdlmain; } private: const std::string m_path;