From bd4dfe88c0cfc97fb55785e7e98f758cf8ab016b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Sat, 1 Feb 2025 18:43:10 +0100 Subject: [PATCH] Add Player collision to world --- assets/game/levels/BSZ/tilemap.png | Bin 0 -> 5608 bytes assets/game/objects/klinck.png | Bin 0 -> 1572 bytes assets/player.png.old | Bin 1524 -> 0 bytes assets/shaders/Sprite.frag | 4 +- source/engine/graphics/front/engine/Layer.hpp | 3 +- .../engine/graphics/front/object/Sprite.hpp | 2 + source/engine/physic/front/engine/Engine.cpp | 15 +- source/engine/physic/front/engine/Engine.hpp | 2 +- .../engine/physic/front/object/Tangible.cpp | 16 ++- .../engine/physic/front/object/Tangible.hpp | 6 +- source/game/Game.cpp | 87 ++++++++++-- source/game/back/object/Player.cpp | 45 +++--- source/game/back/object/Player.hpp | 23 +-- source/game/back/object/Terrain.cpp | 9 +- source/game/back/object/Terrain.hpp | 3 + source/game/back/object/tile/Tile.cpp | 4 +- source/game/back/object/tile/Tile.hpp | 2 +- source/game/back/object/tile/TileSolide.cpp | 4 +- source/game/back/object/tile/TileSolide.hpp | 2 +- source/game/front/Layer.hpp | 18 +++ source/game/front/Stats.hpp | 9 ++ source/game/front/object/Klinck.cpp | 132 ++++++++++++++++++ source/game/front/object/Klinck.hpp | 51 +++++++ source/game/front/profile/KlinckKeys.cpp | 35 +++++ .../{PlayerKeys.hpp => KlinckKeys.hpp} | 8 +- source/game/front/profile/PlayerKeys.cpp | 44 ------ source/kernel/back/engine/GraphicEngine.cpp | 2 + .../kernel/front/component/graphic/Sprite.cpp | 32 +++-- .../kernel/front/component/graphic/Sprite.hpp | 22 +-- .../front/component/graphic/TileMap.cpp | 4 +- source/kernel/front/component/physic/Tile.cpp | 6 +- source/kernel/front/component/physic/Tile.hpp | 2 +- .../front/component/physic/TileArray.cpp | 6 +- .../front/component/physic/TileArray.hpp | 4 +- 34 files changed, 448 insertions(+), 154 deletions(-) create mode 100644 assets/game/levels/BSZ/tilemap.png create mode 100644 assets/game/objects/klinck.png delete mode 100644 assets/player.png.old create mode 100644 source/game/front/Layer.hpp create mode 100644 source/game/front/Stats.hpp create mode 100644 source/game/front/object/Klinck.cpp create mode 100644 source/game/front/object/Klinck.hpp create mode 100644 source/game/front/profile/KlinckKeys.cpp rename source/game/front/profile/{PlayerKeys.hpp => KlinckKeys.hpp} (57%) delete mode 100644 source/game/front/profile/PlayerKeys.cpp diff --git a/assets/game/levels/BSZ/tilemap.png b/assets/game/levels/BSZ/tilemap.png new file mode 100644 index 0000000000000000000000000000000000000000..33c2c4713acf3de01bd3a0e8cfc4dee773cf847b GIT binary patch literal 5608 zcmeAS@N?(olHy`uVBq!ia0y~yU`SwKU|7Jx#=yYvxgfKLfq{XsILO_JVcj{ImkbOH zEa{HEjtmSN`?>!lvNA9*a29w(7BevL?FV5-3)Wy21_seuPZ!6KinzCP?boEZhaIbC z^X^erJG^k>gd05FDRT`|rcDS_a+t;8-^QHa?xJ=`+E6m?Et_|muw{(TqaMz5;VrXu zg*Ybj&g}dqcwlk;_pjIAzrOrD<m%hof8(~#oFB96d)VCI`hCHn-|xMvd(6JNb<dwC zb6<bAuiLdVYHi%!A4x|`%hs%TW9gP;>u*<S+xxKU@BLpX88&&ppT4T9t+crR`{T1G z4sv;Y-35UvQL1U)S2EVusDE}3u-`T#xmuj(><qCr4QDg8`XmI!?S8-d`s(xir+0rX z-~aDyuJot>fBob9-Q71^PwM>F&;7VSOgo`PV_!>&%D?ved+({as2BcYxBqee>h1jh z1;_1$t%a>luVyNpuJf*8J;RBXvmM$8j<%=E?=hA=$-e*CyYT(L{)M#PXI5i&X4-yg zpXm37ohjN5kJ1lK-l4YAhAp7UisQb}e;JD^hD8RFh0>F5=-L?Mc;>iI6ihttSrZ}C za8Xx%kwQbht=;M5gemtIseahm$=}U9;p~rzp%1hj1ULd&8KYJ|xMa~SDlqZIT7{65 z>U|kg?~1!eGDZrxg*E=pl)j{O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K^WeCtW{_F}#R=Yj=fvlp%x6m;PH zva#iPs?6$`x0Q05zh@a=l71Y!S(xGM1Rk~(=krW{aETwitT9u6W$P~&`RHwH4eznP zJbqDklfnz-=W=@w9PIGTIe&D&NgDfsiw7R_taXv$3`%`mT2-ygXr2Cz$zYTFFCS+H z)xfhZ;=0}s8cX<cFI#T^E8jN1X_0~5k75Nj2Y>hH|3tP}FxY+gUBPqq7vo~a9se$F zVyO9<K6^5Aq)bE3dAnr?{GP2pe$Jcsz=diDRS%ZkXQm}gTvfEN=%#zsKfl!Q-jDkv z>iAbo&{%w^;dh19QvvzH6B7O>7ahOgVV2#Pt95&oR@App>FK8e7#`ibEo7y9?%J9A zpQAQcn;0zqKKu8x1>YOEI@=^7g>D+}exABdWd)P*p`CC47hDLQaKyrVllvp{{)NY0 zY%@6i|B}43IJ?5^QrkYs1#9FBG#M>URWm3}*pPiwZgtGttt(!wJXR5}Q^$W|LV#iK zq@R=e4sJYFq0{$C?tt0UyWC29Be|8$7Qc;Ua<Am?Fy10m=(6S1vDat9Tyl!P)D_*= zspC(0;H7j=pw*>V-d~_qG%o#%<kLIf>MdSqX1qJ_zUxirn?3WJ!dCxh&W||Ks@|Ry R&A`CG;OXk;vd$@?2>_aS-BADl literal 0 HcmV?d00001 diff --git a/assets/game/objects/klinck.png b/assets/game/objects/klinck.png new file mode 100644 index 0000000000000000000000000000000000000000..f5ea178d3f0064be5995ff7e946b67c8d22ed468 GIT binary patch literal 1572 zcmeAS@N?(olHy`uVBq!ia0y~yU~phyU@+idV_;xd=v^bvz`(#*9OUlAu<o49O9lo8 zmUKs7M+SzC{oH>NSs54@I14-?iy0XB4uUY_j)~cC85mf1db&7<WH_IlWw@@yl&AH1 zx~PbU0+(4s#)7uCrZ(9Nn_0M~Ih^Oq(8yTO#<r1>i$#caw?xsOnm>LuZ=aky^ILF! z%B0ypZgk$?J9Fpf&#!`tznWeC8J^J-U9u$V@J);5Tk|Vc$Lz0tzWB8L{{Lo@#|+Zt zsy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X#4BNy=+g$&Gw~R5A)Pc%PFvs zz4!d1xJ&8JJlhxhqLT%um*20`HsO+IUf$K{8nyhl@4>IR|FZrvL{0c=84$u&V3@GE zK$XkW#rqa-MfAOG>emWR_+FAa#WZ6_<@fVB<_k;=i+eQxE1B=mwAXkP)l(!Wz3a)7 zi4y-S|AlVQx}f*-f9vJ!_4im6wjE|^mx!8me(upnBHI>UI&dy2dwC(hMEUF!p`GW0 z<~$Pk<nq=pknx~lo~M>>giOjp<yHPx&rZqMxvscc%j<O7FT_p!oDu`e#eWO#IOr)v zh$wx!ES~Z|iTS~V{n6T6S58RiYUG{4yRo*gp|Gd+%)y$N&dRH+?0@f(bK@(%m2MNa zTa&$h%Ny~i2yctPmT8Wr7dM=FGGF}APAB``bXgyh4QCwB*Ihaob*Ay;YS#t&jMh%e zyDb*>TmD!jwl?DUl61Sc?AK{N^O+7GtoDDBJz-vKtLGag-TCHrm$y6g+8w^<CoLfN z??1ELzwbX|jW%dJh?Vw;h_TJ#ERi@rpGmY#`(j1!wcOU9eJP0&&f11$E<9gMubq^5 z<{ZDpWd3cZ<0tbt3|?~G4$Qn#_99Aq_KJO+$I@S{_{F+@`;p`PjzVSCE5)pi$*lQe zw)|g5W5l^n*JKku-<!MDYTXpp2aGM>>-XHg@4Wo$_D!oe+Uu{fb~HwOUvMj$@6lad zmT1GDO4E)>&rY#lT+BZAM%StPK1seI+e0j#?(f*|y*}^o)BR_Q*L4ct@^Y4oJ)Ce! uPVC{^zC6bCuPue|uBPV2{D1mM{|@`iy7L?E=`%1eFnGH9xvX<aXaWH7SNih+ literal 0 HcmV?d00001 diff --git a/assets/player.png.old b/assets/player.png.old deleted file mode 100644 index 70456833ec2e399ebc897d12cc6abd8f1423db91..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1524 zcmeAS@N?(olHy`uVBq!ia0y~yU~phyU@+idV_;xd=v^bvz`(#*9OUlAu<o49O9lo8 zmUKs7M+SzC{oH>NSs54@I14-?iy0X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flat in int Id; void main() { vec2 coord = vec2( - (uFrames[Id].x / uSizes[Id].x) + (uFrames[Id].z / uSizes[Id].x) * Texture.x, - (uFrames[Id].y / uSizes[Id].y) + (uFrames[Id].w / uSizes[Id].y) * Texture.y + (uFrames[Id].x / uSizes[Id].x) + (uFrames[Id].z / uSizes[Id].x) * Texture.x, + (uFrames[Id].y / uSizes[Id].y) + (uFrames[Id].w / uSizes[Id].y) * Texture.y ); FragColor = texture(uSampler[uTextures[Id]], coord); } \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Layer.hpp b/source/engine/graphics/front/engine/Layer.hpp index 3efa4dd..3fde2cf 100644 --- a/source/engine/graphics/front/engine/Layer.hpp +++ b/source/engine/graphics/front/engine/Layer.hpp @@ -27,8 +27,7 @@ namespace megu { template <class T> size_t push(Priority priority, T & object, Module<T> * modul) { - - if(!this->_objects.contains(priority)) { + if(this->_objects.contains(priority)) { this->_objects.erase(priority); } this->_objects.insert({priority, Renderable{ object, modul }}); diff --git a/source/engine/graphics/front/object/Sprite.hpp b/source/engine/graphics/front/object/Sprite.hpp index 43b9a8b..a0b5b23 100644 --- a/source/engine/graphics/front/object/Sprite.hpp +++ b/source/engine/graphics/front/object/Sprite.hpp @@ -36,6 +36,8 @@ namespace megu { inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} + inline void setSize(float w, float h) {this->_transformation.setScaling(w, h);} + inline const Frame & frame() const {return this->_frame;} inline const Texture & texture() const {return this->_texture;} inline const Transformable & transformation() const {return this->_transformation;} diff --git a/source/engine/physic/front/engine/Engine.cpp b/source/engine/physic/front/engine/Engine.cpp index 480db59..2e39c9f 100644 --- a/source/engine/physic/front/engine/Engine.cpp +++ b/source/engine/physic/front/engine/Engine.cpp @@ -65,19 +65,22 @@ namespace megu { } } - bool PhysicEngine::makeCollision(const SquareBox & box, Priority priority) const { + std::optional<SquareBox> PhysicEngine::makeCollision(const SquareBox & box, Priority priority) const { for(const auto & source : this->_statics.at(priority)) { - if(source.get().isColliding(box)) { - return true; + auto obox = source.get().isColliding(box); + if(obox.has_value()) { + return obox; } } for(const auto & source : this->_dynamic.at(priority)) { - if(source.get().isColliding(box)) { - return true; + auto obox = source.get().isColliding(box); + if(obox.has_value()) { + return obox; } } - return false; + + return {}; } std::optional<std::reference_wrapper<const Tangible>> PhysicEngine::get(const Identifiable & id) const { diff --git a/source/engine/physic/front/engine/Engine.hpp b/source/engine/physic/front/engine/Engine.hpp index ae19a1b..7c8304d 100644 --- a/source/engine/physic/front/engine/Engine.hpp +++ b/source/engine/physic/front/engine/Engine.hpp @@ -28,7 +28,7 @@ namespace megu { void step(double); void step(double, Priority); - bool makeCollision(const SquareBox &, Priority) const; + std::optional<SquareBox> makeCollision(const SquareBox &, Priority) const; std::optional<std::reference_wrapper<const Tangible>> get(const Identifiable &) const; diff --git a/source/engine/physic/front/object/Tangible.cpp b/source/engine/physic/front/object/Tangible.cpp index 5915036..58708a0 100644 --- a/source/engine/physic/front/object/Tangible.cpp +++ b/source/engine/physic/front/object/Tangible.cpp @@ -1,20 +1,24 @@ #include "Tangible.hpp" +#include <optional> #include <iostream> namespace megu { Tangible::Tangible(const Position & position, const Dimension & dimension) : _box(position, dimension) {} - bool Tangible::isColliding(const Tangible & entity) const { - if(this != &entity) { - return this->_box.intersect(entity._box); + std::optional<SquareBox> Tangible::isColliding(const Tangible & entity) const { + if(this != &entity && this->_box.intersect(entity._box)) { + return this->_box; } - return false; + return {}; } - bool Tangible::isColliding(const SquareBox & box) const { - return this->_box.intersect(box); + std::optional<SquareBox> Tangible::isColliding(const SquareBox & box) const { + if(this->_box.intersect(box)) { + return this->_box; + } + return {}; } bool Tangible::operator==(const Tangible & entity) const { diff --git a/source/engine/physic/front/object/Tangible.hpp b/source/engine/physic/front/object/Tangible.hpp index 9cc4d73..9b98a61 100644 --- a/source/engine/physic/front/object/Tangible.hpp +++ b/source/engine/physic/front/object/Tangible.hpp @@ -5,6 +5,7 @@ #include <engine/physic/back/Position.hpp> #include <engine/physic/back/SquareBox.hpp> #include <functional> +#include <optional> namespace megu { class Tangible : virtual public Identifiable { @@ -24,11 +25,10 @@ namespace megu { inline void move(const Direction & direction) {this->_box.move(direction);} inline void move(float x, float y, float z = 0.f) {return this->move(Direction(x, y, z));} - virtual bool isColliding(const Tangible &) const; - virtual bool isColliding(const SquareBox &) const; + virtual std::optional<SquareBox> isColliding(const Tangible &) const; + virtual std::optional<SquareBox> isColliding(const SquareBox &) const; bool operator==(const Tangible &) const; - using UpdateLambda = std::function<void(double)>; diff --git a/source/game/Game.cpp b/source/game/Game.cpp index 8a14bbf..e002268 100644 --- a/source/game/Game.cpp +++ b/source/game/Game.cpp @@ -10,6 +10,10 @@ #include <game/back/object/tile/TileSolide.hpp> #include <game/object/Test.hpp> +#include <game/front/Layer.hpp> + +#include <game/front/object/Klinck.hpp> + #include <game/utility/FrameCouter.hpp> namespace megu::game { @@ -25,28 +29,87 @@ namespace megu::game { FrameCounter counter; kernel::Kernel kernel(window); - auto path = std::filesystem::path("assets/player.png"); - //megu::game::Object object(path); - Player player(0, 0, 32, 32, path); - Enemy enemy(64, 64, 16, 16, path); + Klinck klinck(kernel, 170, 170); + + Terrain terrain(0.f, 0.f, 32.f, 32.f, "assets/game/levels/BSZ/tilemap.png", 11, 11, 32.f, 16); + + std::vector<size_t> layer0 = { + 48, 49, 49, 23, 30, 31, 32, 34, 50, 50, 51, + 54, 55, 55, 29, 36, 37, 38, 40, 56, 56, 57, + 47, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, + 47, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, + 47, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, + 47, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, + 47, 1, 12, 13, 1, 1, 1, 12, 13, 1, 46, + 23, 1, 1, 1, 1, 1, 1, 1, 2, 1, 34, + 29, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + }; + + for(size_t i = 7; i < 60; ++i) { + terrain.setTileEvent(i, new TileSolide(32.f, physic::TERRAIN)); + } + terrain.setTileEvent(2, new TileSolide(32.f, physic::TERRAIN)); + + for(size_t i = 0; i < 11; ++i) { + terrain.graphic().addAnimation(i, 9, {18, 19, 20, 21}); + terrain.graphic().addAnimation(i, 10, {24, 25, 26, 27}); + } - Terrain terrain(0.f, 0.f, 32.f, 32.f, "assets/tilemap.png", 4, 4, 32.f, 16); + for(size_t i = 0; i < 11; ++i) { + for(size_t j = 0; j < 11; ++j) { + terrain.setValue(j, i, layer0.at(i*11 + j)); + } + } - terrain.setTileEvent(2, new TileSolide(32.f)); - terrain.setValue(1, 1, 1); - terrain.setValue(1, 0, 2); + terrain.getGraphicComponent()->setLayerPriority(graphic::TERRAIN); + terrain.getPhysicComponent()->setLayer(physic::TERRAIN); + + Terrain terrain_2(0.f, 0.f, 32.f, 32.f, "assets/game/levels/BSZ/tilemap.png", 11, 11, 32.f, 16); + + std::vector<size_t> layer1 = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 9, 0, 0, 0, 14, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 6, 7, 0, 0, 0, 6, 7, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + + terrain_2.setTileEvent(9, new TileSolide(32.f, physic::TERRAIN)); + terrain_2.setTileEvent(14, new TileSolide(32.f, physic::TERRAIN)); + terrain_2.setTileEvent(15, new TileSolide(32.f, physic::TERRAIN)); + + for(size_t i = 0; i < 11; ++i) { + for(size_t j = 0; j < 11; ++j) { + terrain_2.setValue(j, i, layer1.at(i*11 + j)); + } + } - Level level("STZ"); + terrain_2.getGraphicComponent()->setLayerPriority(graphic::TERRAIN_UP); + terrain_2.getPhysicComponent()->setLayer(physic::TERRAIN); + + + Level level("BSZ"); terrain.setup(kernel, level); terrain.apply(kernel); + + terrain_2.setup(kernel, level); + terrain_2.apply(kernel); //level.add(&enemy); - level.add(&player); - player.setup(kernel, level); - player.apply(kernel); + level.add(&klinck); + klinck.setup(kernel, level); + klinck.apply(kernel); //enemy.setup(kernel, level); //enemy.apply(kernel); diff --git a/source/game/back/object/Player.cpp b/source/game/back/object/Player.cpp index 4371a1d..f78ddf3 100644 --- a/source/game/back/object/Player.cpp +++ b/source/game/back/object/Player.cpp @@ -1,27 +1,25 @@ #include "Player.hpp" - -#include <game/front/profile/PlayerKeys.hpp> #include <game/back/object/Level.hpp> namespace megu::game { - Player::Player(float x, float y, float w, float h, std::filesystem::path & path) - : kernel::PropsPlayable(this->_sprite, this->_movable), GameProps(this), _sprite(path), _movable(x, y, w, h) { - this->_sprite.setPosition({x, y}); - this->_sprite.setLayerObject(2); - this->_movable.setLayer(2); - } + Player::Player(float x, float y, float w, float h, std::filesystem::path path) + : kernel::PropsPlayable(this->_sprite, this->_movable), GameProps(this), _sprite(path), _movable(x, y, w, h) {} void Player::move(float x, float y) { this->_sprite.move({x, y}); this->_movable.move(x, y); } - void Player::setup(kernel::Kernel & kernel, Level & level) { - this->setControl(kernel.window(), new PlayerKeyProfile(*this, kernel)); + void Player::setPosition(float x, float y) { + this->_sprite.setPosition({x, y}); + this->_movable.setPosition({x, y}); + } - this->_sprite.setFrame({0.f, 0.f, 16.f, 16.f}); - this->_sprite.setSize({32.f, 32.f}); + const Position & Player::getPosition() const { + return this->_movable.getPosition(); + } + void Player::setup(kernel::Kernel & kernel, Level & level) { this->_movable.setCollideLambda([this, &level](kernel::Kernel &, kernel::PhysicEngine &, Identifiable & id, kernel::Physical<kernel::PhysicEngine> & comp, double) { auto object = level.get(id); @@ -32,6 +30,12 @@ namespace megu::game { } } }); + + this->_movable.setUpdateLambda([this](double delta) { + this->onPhysic(delta); + }); + + this->onSetup(kernel, level); } void Player::on(const kernel::Prop & props, const Event & event) { @@ -43,25 +47,12 @@ namespace megu::game { this->onDamage(event); } } - - std::optional<Event> Player::on() const { - return {}; - } - + void Player::destroy(kernel::Kernel & kernel, Level & level) { - + this->onDestroy(kernel, level); } void Player::apply(kernel::Kernel & kernel) { kernel.add(this); } - - void Player::onDamage(const Event & b) { - std::cout << "Player Got Damage !" << std::endl; - std::cout << "I take " << b.get(0).value_or(0) << " damage !" << std::endl; - } - - void Player::onSolide(const kernel::Prop & props) { - - } } \ No newline at end of file diff --git a/source/game/back/object/Player.hpp b/source/game/back/object/Player.hpp index febcc85..9859acf 100644 --- a/source/game/back/object/Player.hpp +++ b/source/game/back/object/Player.hpp @@ -7,20 +7,27 @@ namespace megu::game { class Player : public kernel::PropsPlayable, public GameProps { public: - Player(float x, float y, float w, float h, std::filesystem::path &); + Player(float x, float y, float w, float h, std::filesystem::path); void move(float, float); + void setPosition(float, float); - void setup(kernel::Kernel &, Level &) override; - void destroy(kernel::Kernel &, Level &) override; + const Position & getPosition() const; - void apply(kernel::Kernel &) override; + void setup(kernel::Kernel &, Level &) override final; + void destroy(kernel::Kernel &, Level &) override final; - void on(const kernel::Prop &, const Event &) override; - std::optional<Event> on() const override; + void apply(kernel::Kernel &) override final; - void onDamage(const Event &); - void onSolide(const kernel::Prop &); + void on(const kernel::Prop &, const Event &) override final; + + std::optional<Event> on() const = 0; + + virtual void onDamage(const Event &) = 0; + virtual void onSolide(const kernel::Prop &) = 0; + virtual void onSetup(kernel::Kernel &, Level &) = 0; + virtual void onDestroy(kernel::Kernel &, Level &) = 0; + virtual void onPhysic(double) = 0; kernel::Movable & getPhysic() {return this->_movable;} kernel::Sprite & getGraphic() {return this->_sprite;} diff --git a/source/game/back/object/Terrain.cpp b/source/game/back/object/Terrain.cpp index dceb37e..eea0a86 100644 --- a/source/game/back/object/Terrain.cpp +++ b/source/game/back/object/Terrain.cpp @@ -2,6 +2,7 @@ #include <game/back/object/Level.hpp> + namespace megu::game { Terrain::Terrain(float x, float y, float w, float h, const std::filesystem::path & path, size_t r, size_t c , float size, size_t tileSize) : PropsTileMap(this->_graphic, this->_physic), GameProps(this), _graphic(path, r, c, size, tileSize), _physic(x, y, r * w, c * h) { @@ -12,7 +13,13 @@ namespace megu::game { void Terrain::setValue(size_t x, size_t y, size_t value) { this->_graphic.setValue(x, y, value); if(this->_event.contains(value)) { - this->_physic.push({static_cast<float>(x) * this->_graphic.getSize().x, (this->_graphic.getSize().y * (this->_graphic.height()- 1)) - static_cast<float>(y) * this->_graphic.getSize().y}, *this->_event[value]); + this->_physic.push( + { + static_cast<float>(x) * this->_graphic.getSize().x, + (this->_graphic.getSize().y * (this->_graphic.height()- 1)) - static_cast<float>(y) * this->_graphic.getSize().y + }, + *this->_event[value] + ); } } diff --git a/source/game/back/object/Terrain.hpp b/source/game/back/object/Terrain.hpp index 8fa99ec..44e9127 100644 --- a/source/game/back/object/Terrain.hpp +++ b/source/game/back/object/Terrain.hpp @@ -23,6 +23,9 @@ namespace megu::game { void on(const kernel::Prop &, const Event &) override; std::optional<Event> on() const override; + inline kernel::Tilemap & graphic() {return this->_graphic;} + inline kernel::TileArray & phyisc() {return this->_physic;} + private: kernel::Tilemap _graphic; kernel::TileArray _physic; diff --git a/source/game/back/object/tile/Tile.cpp b/source/game/back/object/tile/Tile.cpp index e255187..8cdabac 100644 --- a/source/game/back/object/tile/Tile.cpp +++ b/source/game/back/object/tile/Tile.cpp @@ -1,6 +1,6 @@ #include "Tile.hpp" namespace megu::game { - Tile::Tile(float d) - : kernel::Tile(0, 0, d) {} + Tile::Tile(float d, Priority p) + : kernel::Tile(0, 0, d, p) {} } \ No newline at end of file diff --git a/source/game/back/object/tile/Tile.hpp b/source/game/back/object/tile/Tile.hpp index ec35a38..09e3dbd 100644 --- a/source/game/back/object/tile/Tile.hpp +++ b/source/game/back/object/tile/Tile.hpp @@ -9,6 +9,6 @@ namespace megu::game { class Tile : public kernel::Tile, public GameEvent { public: Tile() = delete; - Tile(float d); + Tile(float d, Priority p); }; } \ No newline at end of file diff --git a/source/game/back/object/tile/TileSolide.cpp b/source/game/back/object/tile/TileSolide.cpp index 91d1ae7..b0bcd07 100644 --- a/source/game/back/object/tile/TileSolide.cpp +++ b/source/game/back/object/tile/TileSolide.cpp @@ -1,8 +1,8 @@ #include "TileSolide.hpp" namespace megu::game { - TileSolide::TileSolide(float d) - : Tile(d) {} + TileSolide::TileSolide(float d, Priority p) + : Tile(d, p) {} void TileSolide::on(const kernel::Prop &, const Event &) { //... diff --git a/source/game/back/object/tile/TileSolide.hpp b/source/game/back/object/tile/TileSolide.hpp index 84424f2..c8db88e 100644 --- a/source/game/back/object/tile/TileSolide.hpp +++ b/source/game/back/object/tile/TileSolide.hpp @@ -5,7 +5,7 @@ namespace megu::game { class TileSolide : public Tile { public: - TileSolide(float d); + TileSolide(float d, Priority p); void on(const kernel::Prop &, const Event &) override; std::optional<Event> on() const override; diff --git a/source/game/front/Layer.hpp b/source/game/front/Layer.hpp new file mode 100644 index 0000000..88ca9e9 --- /dev/null +++ b/source/game/front/Layer.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace megu::game { + namespace physic { + enum Layer { + TERRAIN = 0, + ENTITY = 1, + }; + } + + namespace graphic { + enum Layer { + TERRAIN = 0, + ENTITY = 1, + TERRAIN_UP = 2 + }; + } +} \ No newline at end of file diff --git a/source/game/front/Stats.hpp b/source/game/front/Stats.hpp new file mode 100644 index 0000000..ca02b26 --- /dev/null +++ b/source/game/front/Stats.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace megu::game { + enum Stats { + LIFE, + ATK, + DEF, + }; +} \ No newline at end of file diff --git a/source/game/front/object/Klinck.cpp b/source/game/front/object/Klinck.cpp new file mode 100644 index 0000000..b668e0b --- /dev/null +++ b/source/game/front/object/Klinck.cpp @@ -0,0 +1,132 @@ +#include "Klinck.hpp" + +#include <game/front/Stats.hpp> +#include <game/front/Layer.hpp> +#include <game/front/profile/KlinckKeys.hpp> + +namespace megu::game { + Klinck::Klinck(kernel::Kernel & k, float x, float y) + : Player(0.f, 0.f, 32.f, 32.f, "assets/game/objects/klinck.png"), _kernel(k), _life(100), _atk(10), _def(25), _vx(0.f), _vy(0.f) { + this->getGraphic().setLayerObject(graphic::Layer::ENTITY); + this->getPhysic().setLayer(physic::Layer::ENTITY); + this->move(x, y); + } + + void Klinck::onSetup(kernel::Kernel & kernel, Level &) { + auto & sprite = this->getGraphic(); + + sprite.push(Animation::IDL_BACK, 0, 32, 16, 16); + sprite.push(Animation::IDL_FRONT, 16, 32, 16, 16); + sprite.push(Animation::IDL_LEFT, 32, 32, 16, 16); + sprite.push(Animation::IDL_RIGHT, 48, 32, 16, 16); + + sprite.push(Animation::WALK_BACK, {{0, 16, 16, 16}, { 16, 16, 16, 16}}); + sprite.push(Animation::WALK_FRONT, {{32, 16, 16, 16}, { 48, 16, 16, 16}}); + sprite.push(Animation::WALK_LEFT, {{0, 0, 16, 16}, { 16, 0, 16, 16}}); + sprite.push(Animation::WALK_RIGHT, {{32, 0, 16, 16}, { 48, 0, 16, 16}}); + + sprite.setAnimation(Animation::IDL_BACK); + sprite.setSize({32.f, 32.f}); + + this->setControl(kernel.window(), new KlinckKeyProfile(*this, kernel)); + + this->_moving[UP] = false; + this->_moving[DOWN] = false; + this->_moving[LEFT] = false; + this->_moving[RIGHT] = false; + + } + + void Klinck::onDestroy(kernel::Kernel &, Level &) { + + } + + void Klinck::onDamage(const Event &) { + + } + + void Klinck::onSolide(const kernel::Prop &) { + + } + + void Klinck::onPhysic(double) { + if(abs(this->_vx) > 0.05f) { + this->_vx = this->_vx > 0 ? 0.05f : -0.05f; + } + + if(abs(this->_vy) > 0.05f) { + this->_vy = this->_vy > 0 ? 0.05f : -0.05f; + } + + float vx = 0.f, vy = 0.f; + if(this->_moving[UP]) { + vy += 0.01f; + } + + if(this->_moving[DOWN]) { + vy -= 0.01f; + } + + if(this->_moving[RIGHT]) { + vx += 0.01f; + } + + if(this->_moving[LEFT]) { + vx -= 0.01f; + } + + this->_vx += vx; + this->_vy += vy; + + if(abs(this->_vy) > 0) { + SquareBox box = this->getPhysic().getBox(); + box.move({0.f, this->_vy, 0.f}); + + std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().makeCollision(box, physic::TERRAIN); + if(obox.has_value()) { + float pos_y = this->_vy > 0 ? obox.value().position().y() - obox.value().height() : obox.value().position().y() + obox.value().height(); + this->setPosition(this->getPosition().x(), pos_y); + this->_vy = 0.f; + } + else { + this->move(0.0, this->_vy); + } + } + + if(abs(this->_vx) > 0) { + SquareBox box = this->getPhysic().getBox(); + box.move({this->_vx, 0.f, 0.f}); + + std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().makeCollision(box, physic::TERRAIN); + if(obox.has_value()) { + float pos_x = this->_vx > 0 ? obox.value().position().x() - obox.value().width() : obox.value().position().x() + obox.value().width(); + this->setPosition(pos_x, this->getPosition().y()); + this->_vx = 0.f; + } + else { + this->move(this->_vx, 0.0); + } + } + + if(abs(this->_vy) > 0.001f) { + this->_vy += this->_vy > 0.f ? -0.0002f : 0.0002f; + } + else { + this->_vy = 0.f; + } + + if(abs(this->_vx) > 0.001f) { + this->_vx += this->_vx > 0.f ? -0.0002f : 0.0002f; + } + else { + this->_vx = 0.f; + } + } + + std::optional<Event> Klinck::on() const { + Event event(Event::DAMAGE); + event.set(Stats::ATK, this->_atk); + + return event; + } +} \ No newline at end of file diff --git a/source/game/front/object/Klinck.hpp b/source/game/front/object/Klinck.hpp new file mode 100644 index 0000000..1780469 --- /dev/null +++ b/source/game/front/object/Klinck.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include <game/back/object/Player.hpp> + +namespace megu::game { + class Klinck : public Player { + public: + enum Animation { + IDL_FRONT = 1, + IDL_BACK = 2, + IDL_LEFT = 3, + IDL_RIGHT = 4, + + WALK_FRONT = 5, + WALK_BACK = 6, + WALK_LEFT = 7, + WALK_RIGHT = 8 + }; + + enum Direction { + UP, + DOWN, + LEFT, + RIGHT + }; + + Klinck(kernel::Kernel &, float, float); + + void onSetup(kernel::Kernel &, Level &) override; + void onDestroy(kernel::Kernel &, Level &) override; + void onDamage(const Event &) override; + void onSolide(const kernel::Prop &) override; + void onPhysic(double) override; + std::optional<Event> on() const override; + + inline void setVelocity(float x, float y) {this->_vx = x; this->_vy = y;} + inline void addVelocity(float x, float y) {this->_vx += x; this->_vy += y;} + inline float vx() const {return this->_vx;} + inline float vy() const {return this->_vy;} + + inline void setMovingDirection(Direction dir, bool state) {this->_moving[dir] = state;} + + private: + kernel::Kernel & _kernel; + unsigned int _life; + unsigned int _atk; + unsigned int _def; + float _vx, _vy; + std::map<Direction, bool> _moving; + }; +} \ No newline at end of file diff --git a/source/game/front/profile/KlinckKeys.cpp b/source/game/front/profile/KlinckKeys.cpp new file mode 100644 index 0000000..2da47f3 --- /dev/null +++ b/source/game/front/profile/KlinckKeys.cpp @@ -0,0 +1,35 @@ +#include "KlinckKeys.hpp" + +#include <game/front/Layer.hpp> +#include <optional> + +namespace megu::game { + KlinckKeyProfile::KlinckKeyProfile(Klinck & player, kernel::Kernel & kernel) + : _player(player), _kernel(kernel) {} + + void KlinckKeyProfile::on(Key key, int code, Action action, Mod mode) { + if(key == Keyboard::Key::ARROW_LEFT) { + this->_player.setMovingDirection(Klinck::Direction::LEFT, action != Action::RELEASE); + //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_LEFT : Klinck::Animation::WALK_LEFT); + this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_LEFT); + } + + if(key == Keyboard::Key::ARROW_RIGHT) { + this->_player.setMovingDirection(Klinck::Direction::RIGHT, action != Action::RELEASE); + //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_RIGHT : Klinck::Animation::WALK_RIGHT); + this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_RIGHT); + } + + if(key == Keyboard::Key::ARROW_UP) { + this->_player.setMovingDirection(Klinck::Direction::UP, action != Action::RELEASE); + //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_FRONT : Klinck::Animation::WALK_FRONT); + this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_FRONT); + } + + if(key == Keyboard::Key::ARROW_DOWN) { + this->_player.setMovingDirection(Klinck::Direction::DOWN, action != Action::RELEASE); + //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_BACK : Klinck::Animation::WALK_BACK); + this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_BACK); + } + } +} \ No newline at end of file diff --git a/source/game/front/profile/PlayerKeys.hpp b/source/game/front/profile/KlinckKeys.hpp similarity index 57% rename from source/game/front/profile/PlayerKeys.hpp rename to source/game/front/profile/KlinckKeys.hpp index 8acb995..7521b1b 100644 --- a/source/game/front/profile/PlayerKeys.hpp +++ b/source/game/front/profile/KlinckKeys.hpp @@ -1,19 +1,19 @@ #pragma once -#include <game/back/object/Player.hpp> +#include <game/front/object/Klinck.hpp> #include <engine/io/Keyboard.hpp> #include <engine/io/Mouse.hpp> namespace megu::game { - class PlayerKeyProfile : public Keyboard { + class KlinckKeyProfile : public Keyboard { public: - PlayerKeyProfile(Player &, kernel::Kernel &); + KlinckKeyProfile(Klinck &, kernel::Kernel &); virtual void on(Key, int, Action, Mod); private: - Player & _player; + Klinck & _player; kernel::Kernel & _kernel; }; } \ No newline at end of file diff --git a/source/game/front/profile/PlayerKeys.cpp b/source/game/front/profile/PlayerKeys.cpp deleted file mode 100644 index 1f33001..0000000 --- a/source/game/front/profile/PlayerKeys.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "PlayerKeys.hpp" - -namespace megu::game { - PlayerKeyProfile::PlayerKeyProfile(Player & player, kernel::Kernel & kernel) - : _player(player), _kernel(kernel) {} - - void PlayerKeyProfile::on(Key key, int code, Action action, Mod mode) { - if(key == Keyboard::Key::ARROW_UP) { - SquareBox box = this->_player.getPhysic().getBox(); - box.move({0.f, 1.f, 0.f}); - - if(!this->_kernel.getPhysicEngine().get().makeCollision(box, 0)) { - this->_player.move(0.f, 1.f); - } - } - - if(key == Keyboard::Key::ARROW_DOWN) { - SquareBox box = this->_player.getPhysic().getBox(); - box.move({0.f, -1.f, 0.f}); - - if(!this->_kernel.getPhysicEngine().get().makeCollision(box, 0)) { - this->_player.move(0.f, -1.f); - } - } - - if(key == Keyboard::Key::ARROW_LEFT) { - SquareBox box = this->_player.getPhysic().getBox(); - box.move({-1.f, 0.f, 0.f}); - - if(!this->_kernel.getPhysicEngine().get().makeCollision(box, 0)) { - this->_player.move(-1.f, 0.f); - } - } - - if(key == Keyboard::Key::ARROW_RIGHT) { - SquareBox box = this->_player.getPhysic().getBox(); - box.move({1.f, 0.f, 0.f}); - - if(!this->_kernel.getPhysicEngine().get().makeCollision(box, 0)) { - this->_player.move(1.f, 0.f); - } - } - } -} \ No newline at end of file diff --git a/source/kernel/back/engine/GraphicEngine.cpp b/source/kernel/back/engine/GraphicEngine.cpp index efb8418..1aa1931 100644 --- a/source/kernel/back/engine/GraphicEngine.cpp +++ b/source/kernel/back/engine/GraphicEngine.cpp @@ -8,6 +8,8 @@ namespace megu::kernel { void GraphicEngine::boot(Kernel &) { this->_engine.push(0, this->_renderer); + this->_engine.push(1, this->_renderer); + this->_engine.push(2, this->_renderer); } void GraphicEngine::stop(Kernel &) { diff --git a/source/kernel/front/component/graphic/Sprite.cpp b/source/kernel/front/component/graphic/Sprite.cpp index ba3cbb9..4545186 100644 --- a/source/kernel/front/component/graphic/Sprite.cpp +++ b/source/kernel/front/component/graphic/Sprite.cpp @@ -10,20 +10,20 @@ namespace megu::kernel { : Sprite(path, {0, 0, 0, 0}) {} Sprite::Sprite(const std::filesystem::path & path, const Frame & frame) - : megu::Sprite(path, frame), _animation(""), _index(0) { + : megu::Sprite(path, frame), _animation(0), _index(0) { if(!Sprite::_Linker.haveModule()) { Sprite::_Linker.setModule(new Sprite_Module{}); } } - const Frame_List & Sprite::getAnimations(const std::string & name) const { + const Frame_List & Sprite::getAnimations(size_t name) const { if(this->_frames.contains(name)) { return this->_frames.at(name); } throw std::runtime_error("Cannot get inexisting animation"); } - const Frame & Sprite::getFrame(const std::string & name, size_t index) const { + const Frame & Sprite::getFrame(size_t name, size_t index) const { auto & frames = this->getAnimations(name); if(frames.size() > index) { return frames.at(index); @@ -31,36 +31,44 @@ namespace megu::kernel { throw std::runtime_error("Cannot get inexisting frame"); } - void Sprite::setAnimation(const std::string & name) { + void Sprite::setAnimation(size_t name) { if(this->_frames.contains(name)) { this->_animation = name; this->_previous = 0.0; } - throw std::runtime_error("Cannot set inexisting animation"); + else { + throw std::runtime_error("Cannot set inexisting animation"); + } } - void Sprite::push(const std::string & name, const Frame_List & frames) { - this->_frames[name] = frames; + void Sprite::push(size_t name, const Frame_List & frames) { + for(auto & frame : frames) { + this->push(name, frame); + } } - void Sprite::push(const std::string & name, const Frame & frame) { + void Sprite::push(size_t name, const Frame & frame) { this->_frames[name].push_back(frame); } - void Sprite::remove(const std::string & name) { + void Sprite::push(size_t name, float x, float y, float w, float h) { + this->_frames[name].push_back({x, y, w, h}); + } + + void Sprite::remove(size_t name) { if(this->_frames.contains(name)) { this->_frames.erase(name); } } - void Sprite::remove(const std::string & name, size_t index) { + void Sprite::remove(size_t name, size_t index) { if(this->_frames.contains(name) && this->_frames[name].size() > index) { this->_frames[name].erase(this->_frames[name].begin() + index); } } void Sprite::update(double time) { - /*if(!this->_animation.empty()) { + if(this->_animation != 0) { if(this->_previous == 0.0) { this->setFrame(this->_frames[this->_animation][this->_index]); this->_previous = time; @@ -72,7 +80,7 @@ namespace megu::kernel { this->setFrame(this->_frames[this->_animation][this->_index]); } } - }*/ + } } void Sprite::apply(Kernel & kernel, GraphicEngine & engine) { diff --git a/source/kernel/front/component/graphic/Sprite.hpp b/source/kernel/front/component/graphic/Sprite.hpp index b3bcc56..f3e5e57 100644 --- a/source/kernel/front/component/graphic/Sprite.hpp +++ b/source/kernel/front/component/graphic/Sprite.hpp @@ -23,16 +23,18 @@ namespace megu::kernel { inline size_t getCurrentFrameIndex() const {return this->_index;} inline double getDuration() const {return this->_duration;} + inline void setDuration(double d) {this->_duration = d;} - const Frame_List & getAnimations(const std::string &) const; - const Frame & getFrame(const std::string &, size_t) const; + const Frame_List & getAnimations(size_t) const; + const Frame & getFrame(size_t, size_t) const; - void setAnimation(const std::string &); - void push(const std::string &, const Frame_List & = {}); - void push(const std::string &, const Frame &); + void setAnimation(size_t); + void push(size_t, const Frame_List & = {}); + void push(size_t, const Frame &); + void push(size_t, float, float, float, float); - void remove(const std::string &); - void remove(const std::string &, size_t); + void remove(size_t); + void remove(size_t, size_t); void update(double) override; void apply(Kernel &, GraphicEngine &) override; @@ -41,11 +43,11 @@ namespace megu::kernel { static const GraphicLinker<megu::Sprite> & linker() {return Sprite::_Linker;} private: - std::map<std::string, Frame_List> _frames; - std::string _animation; + std::map<size_t, Frame_List> _frames; + size_t _animation; size_t _index; double _duration; - double _previous; + double _previous; static GraphicLinker<megu::Sprite> _Linker; }; diff --git a/source/kernel/front/component/graphic/TileMap.cpp b/source/kernel/front/component/graphic/TileMap.cpp index e0df788..4e4acd3 100644 --- a/source/kernel/front/component/graphic/TileMap.cpp +++ b/source/kernel/front/component/graphic/TileMap.cpp @@ -5,9 +5,9 @@ namespace megu::kernel { Tilemap::Tilemap(const std::filesystem::path & path, size_t width, size_t height, float size, size_t lenght, double aUpdate) : TileArray(path, width , height, size, lenght), _tileSize(lenght), _duration(aUpdate) { - if(lenght % width != 0 && lenght % height != 0) { + /*if(lenght % width != 0 && lenght % height != 0) { throw std::runtime_error("Tilemap dimension not matching tiles size."); - } + }*/ size_t tileWidth = this->texture().width() / this->_tileSize; size_t tileHeight = this->texture().height() / this->_tileSize; diff --git a/source/kernel/front/component/physic/Tile.cpp b/source/kernel/front/component/physic/Tile.cpp index eafd5df..47e0e34 100644 --- a/source/kernel/front/component/physic/Tile.cpp +++ b/source/kernel/front/component/physic/Tile.cpp @@ -1,8 +1,10 @@ #include "Tile.hpp" namespace megu::kernel { - Tile::Tile(float x, float y, float d) - : Fixed(x, y, d, d) {} + Tile::Tile(float x, float y, float d, Priority p) + : Fixed(x, y, d, d) { + this->setLayer(p); + } bool Tile::operator==(const Tile & tile) const { return this->id() == tile.id(); diff --git a/source/kernel/front/component/physic/Tile.hpp b/source/kernel/front/component/physic/Tile.hpp index 112ac25..3b914c4 100644 --- a/source/kernel/front/component/physic/Tile.hpp +++ b/source/kernel/front/component/physic/Tile.hpp @@ -5,7 +5,7 @@ namespace megu::kernel { class Tile : public Fixed { public: - Tile(float x, float y, float d); + Tile(float x, float y, float d, Priority p); bool operator==(const Tile &) const; bool operator>=(const Tile &) const; diff --git a/source/kernel/front/component/physic/TileArray.cpp b/source/kernel/front/component/physic/TileArray.cpp index 1ce7961..7a2e455 100644 --- a/source/kernel/front/component/physic/TileArray.cpp +++ b/source/kernel/front/component/physic/TileArray.cpp @@ -45,14 +45,14 @@ namespace megu::kernel { } } - bool TileArray::isColliding(const SquareBox & box) const { + std::optional<SquareBox> TileArray::isColliding(const SquareBox & box) const { for(auto & [positon, tile] : this->_tiles) { SquareBox tbox = SquareBox(positon, tile.get().getBox().dimension()); if(box.intersect(tbox)) { - return true; + return tbox; } } - return false; + return {}; } void TileArray::update_physic(double time) const { diff --git a/source/kernel/front/component/physic/TileArray.hpp b/source/kernel/front/component/physic/TileArray.hpp index 418d8d0..3bd4631 100644 --- a/source/kernel/front/component/physic/TileArray.hpp +++ b/source/kernel/front/component/physic/TileArray.hpp @@ -27,10 +27,10 @@ namespace megu::kernel { void unapply(Kernel & k, PhysicEngine &) override; void on_collide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; - virtual bool isColliding(const SquareBox &) const override; + virtual std::optional<SquareBox> isColliding(const SquareBox &) const override; private: - std::map<Position, std::reference_wrapper<Tile>> _tiles; + std::map<Position, std::reference_wrapper<Tile>, reference_sorter<Position>> _tiles; TileCollideLambda _collide; UpdateLambda _update; }; -- GitLab