From e65c2341c266573f6ad6b318a6b33a6bf18e8d9d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 9 Nov 2016 01:46:10 +0100 Subject: [PATCH] Draw a test character to start experimenting. --- CMakeLists.txt | 1 + LPC_Sara_Preview.png | Bin 0 -> 1896 bytes src/character.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ src/character.hpp | 29 +++++++++++++++++++++++++++ src/ingamescene.cpp | 6 ++++++ 5 files changed, 82 insertions(+) create mode 100644 LPC_Sara_Preview.png create mode 100644 src/character.cpp create mode 100644 src/character.hpp 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 0000000000000000000000000000000000000000..69417cb812965a22e40665c4eb51cc0ab0e3887f GIT binary patch literal 1896 zcmV-u2bcJXP)f{H7!cg*r#{(CeX`l% z0rGx99Iz8oKu+R~sFHZ#x(94%N*Dkqzk`!Wcxum!>{+*#`gXX`oLtz!KI=aMlt|#} zwm5fp{~CZVzxgjOwzqSl`z`9*Vej(KXlN9&aKwW=5i@!|P=;&7y<%cqm%!D5p0W*t zDSmePF91~U&k)-96sK-{$%*c_%yx3EH|3CrSS^6esJPF^g2HxgL5TNI)4a{N* z%aNP2TsS@q*b<&1m^?qg)2|OOH8ZXJz{V8`1hhD0MwvKz+B)?qIO+oEs4RE%do;Mm zG1IrlhnYM-z|IebJux0!l)%K%(_(4MYu}#d*X{Q+^QR0~Ly(+?oStHQ{5i%3bwCG( z7rZYL2pL|Gup|Pk#3u?kZM}7c*qc{KymSB%5|GB*Ngxy_Ic+Ns#p$7kNM}N+6qf7(h0$CFyknQ= z>8LE{>nG>=Ph$-|A00IH577L$bxGJgqxo@2x2W3%N-T+hwtl_L?)r=2`m$-K))#@D z6xDDw6~5QnZZ36eHUXHfE+Gw0PCM)Ntq#*sS*|n|xI#eoQjUhktQiRH`+Peho#JpL zr>BUIiL!mG!|YofW+)mq+r`I3`I(n%-5B1YSTX^HGLT+y`h{tZ+_ZB0z?yO~o1F=` zb%mUsGL4)Z>gCMKwFGvA$>}KqJHkv3^-{IHiH+MHOkzJ2u1VltULaH7Rn@ipwzrGV z-)SQ9;VB}W2|6mv(OxYctN?_aD@Qr1#Y|NVsfaL z&);dH{&%%JGJDPOF2C(Op>TJo0{>t&HZ$oQAmMy5q0+}}pkmR7Uv-DMR# zaXn$)|NY==?94BjUTuq&LH?i_351MrUAMu<7Y+Z2;kXi6ai#w)F8_#O@bN{%i_MVo ze~8%Of2@aazs}0ecdb1^NYoYX3BvuwPmbM&@;^w}PjrJ3Ke5dj08+gGIz25Kel2dL z!{0(`_q(cxWx_LkMFJtCV%JIl!kc3Nq)(>E{WDRt{ZI8{p6K5b0wRHsu_9VVY;T;* zNE(3bRF3%xA@Pb`D;=cFPZ*vBKhFrbyR5=|E?<{1ja;nGi?Jz>0dn?NkRcfHJ7!*@ ze4VHh@RKD+WJ0U}s){Hntd2VR zpV)Ee;mic@2SJ8K!q6)h^EDUm*+&JG6EHP1UB)LE6}wiF8A%h~95ZKGt_VM7y6b5k iP^|o+&-F`q$nifwicXAyAy+#90000 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