diff --git a/CMakeLists.txt b/CMakeLists.txt index e26d76b..4e04676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ add_executable(${PROJECT_NAME} src/tileiterator.cpp src/texture.cpp src/movingobject.cpp + src/character.cpp ) target_include_directories(${PROJECT_NAME} SYSTEM diff --git a/LPC_Sara_Preview.png b/LPC_Sara_Preview.png new file mode 100644 index 0000000..69417cb Binary files /dev/null and b/LPC_Sara_Preview.png differ diff --git a/src/character.cpp b/src/character.cpp new file mode 100644 index 0000000..bd79f2c --- /dev/null +++ b/src/character.cpp @@ -0,0 +1,46 @@ +#include "character.hpp" + +namespace curry { + Character::Character() : + m_position(0.0f) + { + } + + void Character::load (const char* parTexturePath, cloonel::SDLMain& parSDLMain) { + m_texture.load(parTexturePath, parSDLMain); + } + + void Character::unload() { + m_texture.unload(); + } + + void Character::set_position (const vec2f& parPos) { + m_position = parPos; + } + + const vec2f& Character::position() const { + return m_position; + } + + vec2us Character::width_height() const { + return m_texture.width_height(); + } + + Texture& Character::texture() { + return m_texture; + } + + Rect Character::destination_rect (const vec2f& parWorldPos) const { + return Rect( + m_position - parWorldPos, + m_position - parWorldPos + vector_cast(width_height()) + ); + } + + Rect Character::source_rect() const { + return Rect( + vec2f(0.0f), + vector_cast(width_height()) + ); + } +} //namespace curry diff --git a/src/character.hpp b/src/character.hpp new file mode 100644 index 0000000..3033a21 --- /dev/null +++ b/src/character.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "texture.hpp" +#include "vector.hpp" +#include "rect.hpp" + +namespace cloonel { + class SDLMain; +} //namespace cloonel + +namespace curry { + class Character { + public: + Character(); + + void load (const char* parTexturePath, cloonel::SDLMain& parSDLMain); + void unload(); + const vec2f& position() const; + void set_position (const vec2f& parPos); + vec2us width_height() const; + Texture& texture(); + Rect destination_rect (const vec2f& parWorldPos) const; + Rect source_rect() const; + + private: + Texture m_texture; + vec2f m_position; + }; +} //namespace curry diff --git a/src/ingamescene.cpp b/src/ingamescene.cpp index 8b88b12..b4377bb 100644 --- a/src/ingamescene.cpp +++ b/src/ingamescene.cpp @@ -8,6 +8,7 @@ #include "worldviewport.hpp" #include "texture.hpp" #include "rect.hpp" +#include "character.hpp" #include "csvloader.hpp" #include #include @@ -39,6 +40,7 @@ namespace curry { WorldViewport viewport; Texture worldtiles; MovingObject player; + Character character; }; IngameScene::IngameScene (cloonel::SDLMain* parSDLMain) : @@ -71,6 +73,7 @@ namespace curry { #endif m_local_data->viewport.allow_overscan(false); + m_local_data->character.load(RESOURCES_PATH "LPC_Sara_Preview.png", *this->sdl_main()); } void IngameScene::on_update (float parDeltaT) { @@ -92,6 +95,7 @@ namespace curry { if (cloonel::IsPressed(input_bag(), ActionDown)) offset.y() += speed; viewport.set_position(viewport.position() + offset); + m_local_data->character.set_position(m_local_data->character.position() + offset); const auto tilesize(static_cast(world.tile_size())); const auto tilecount(m_local_data->worldtiles.width_height() / world.tile_size()); @@ -108,9 +112,11 @@ namespace curry { this->draw_clipped(m_local_data->worldtiles, src_rect, dst_rect); } } + this->draw_clipped(m_local_data->character.texture(), m_local_data->character.source_rect(), m_local_data->character.destination_rect(viewport.position())); } void IngameScene::on_destroy() noexcept { m_local_data->worldtiles.unload(); + m_local_data->character.unload(); } } //namespace curry