Skip to content
Snippets Groups Projects
Commit 2a0fa130 authored by BATON Theau's avatar BATON Theau
Browse files

Changing Props -> BasicProps

parent 7f1850cf
No related branches found
No related tags found
No related merge requests found
Showing
with 134 additions and 50 deletions
assets/tilemap.png

4.44 KiB | W: | H:

assets/tilemap.png

4.87 KiB | W: | H:

assets/tilemap.png
assets/tilemap.png
assets/tilemap.png
assets/tilemap.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
namespace megu { namespace megu {
TileArray::TileArray(const std::filesystem::path & path, size_t width, size_t height, float size) TileArray::TileArray(const std::filesystem::path & path, size_t width, size_t height, float size, size_t lenght)
: _width(width), _height(height), _size(size) { : _width(width), _height(height), _size(size) {
megu::TextureBuffer buffer(path); megu::TextureBuffer buffer(path);
this->_texture.store(buffer); this->_texture.store(buffer);
...@@ -14,7 +14,7 @@ namespace megu { ...@@ -14,7 +14,7 @@ namespace megu {
for(size_t x = 0; x < width; ++x) { for(size_t x = 0; x < width; ++x) {
std::vector<glm::vec4> rows; std::vector<glm::vec4> rows;
for(size_t y = 0; y < height; ++y) { for(size_t y = 0; y < height; ++y) {
rows.push_back({0.f, 0.f, twidth, theight}); rows.push_back({0.f, this->_texture.height() - lenght, lenght, lenght});
} }
this->_uvs.push_back(rows); this->_uvs.push_back(rows);
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace megu { namespace megu {
class TileArray : public Quads { class TileArray : public Quads {
public: public:
TileArray(const std::filesystem::path &, size_t, size_t, float); TileArray(const std::filesystem::path &, size_t, size_t, float, size_t);
inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);}
inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);}
......
...@@ -20,17 +20,10 @@ namespace megu::game { ...@@ -20,17 +20,10 @@ namespace megu::game {
FrameCounter counter; FrameCounter counter;
kernel::Kernel kernel(window); kernel::Kernel kernel(window);
/* object */
auto path = std::filesystem::path("assets/textures/Neera.png"); auto path = std::filesystem::path("assets/textures/Neera.png");
megu::game::Object object(path); megu::game::Object object(path);
kernel.add(&object); kernel.add(&object);
/*megu::game::Object object2(path);
object2.tmp_setPos(20, 0);
kernel.add(&object2);*/
/* ------ */
while(window.isOpen()) { while(window.isOpen()) {
counter.count(Window::Time()); counter.count(Window::Time());
window.pollEvents(); window.pollEvents();
......
#pragma once
namespace megu::game {
class GameObject {
public:
virtual void setup() = 0;
virtual void destroy() = 0;
};
}
\ No newline at end of file
#pragma once
#include <game/back/GameObject.hpp>
namespace megu::game {
class Message;
class Collider : public GameObject {
public:
Collider<>
virtual void setup();
virtual void on(Message &);
virtual Message make()
};
}
\ No newline at end of file
#pragma once
#include <kernel/front/props/PropsTileMap.hpp>
namespace megu::game {
class Terrain : public kernel::PropsTileMap {
public:
Terrain(float, float);
private:
kernel::Tilemap _graphicMap;
kernel::FixedArray _solidMap;
};
}
\ No newline at end of file
...@@ -2,16 +2,45 @@ ...@@ -2,16 +2,45 @@
namespace megu::game { namespace megu::game {
Object::Object(std::filesystem::path & path) Object::Object(std::filesystem::path & path)
: _physic(0, 0, 64, 64), _graphic(path), _map("assets/tilemap.png", 2, 2, 16.f, 16) { : _physic(0, 0, 64, 64), _graphic(path), _map("assets/tilemap.png", 8, 8, 8.f, 16, 0.125) {
this->_graphic.setFrame({0.f, 0.f, 51.f, 98.f}); this->_graphic.setFrame({0.f, 0.f, 51.f, 98.f});
this->_graphic.setSize({51.f, 98.f}); this->_graphic.setSize({51.f, 98.f});
this->_map.setValue(0, 0, 1); size_t tab[8][8] = {
this->_map.setValue(1, 0, 2); {44, 45, 44, 47, 2, 1, 1, 1},
this->_map.setValue(0, 1, 1); {45, 45, 44, 47, 1, 1, 1, 1},
this->_map.setValue(1, 1, 1); {45, 44, 44, 47, 1, 1, 1, 1},
{22, 22, 22, 23, 1, 1, 2, 1},
{28, 28, 28, 29, 1, 1, 1, 1},
{ 1, 2, 1, 1, 1, 1, 1, 1},
{ 1, 2, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 2, 1, 1, 1, 1}
};
this->_map.addAnimation(0, 1, {18, 19, 20, 21}); for(size_t i = 0; i < 8; ++i) {
this->_map.addAnimation(1, 1, {18, 19, 20, 21}); for(size_t j = 0; j < 8; ++j) {
this->_map.setValue(j, i, tab[i][j]);
}
}
this->_map.addAnimation(0, 6, {18, 18, 20, 21});
this->_map.addAnimation(1, 6, {18, 18, 20, 21});
this->_map.addAnimation(2, 6, {18, 18, 20, 21});
this->_map.addAnimation(3, 6, {18, 18, 20, 21});
this->_map.addAnimation(4, 6, {18, 18, 20, 21});
this->_map.addAnimation(5, 6, {18, 18, 20, 21});
this->_map.addAnimation(6, 6, {18, 18, 20, 21});
this->_map.addAnimation(7, 6, {18, 18, 20, 21});
this->_map.addAnimation(0, 7, {24, 25, 26, 27});
this->_map.addAnimation(1, 7, {24, 25, 26, 27});
this->_map.addAnimation(2, 7, {24, 25, 26, 27});
this->_map.addAnimation(3, 7, {24, 25, 26, 27});
this->_map.addAnimation(4, 7, {24, 25, 26, 27});
this->_map.addAnimation(5, 7, {24, 25, 26, 27});
this->_map.addAnimation(6, 7, {24, 25, 26, 27});
this->_map.addAnimation(7, 7, {24, 25, 26, 27});
this->_map.setSize({360 / 8, 360 / 8});
} }
} }
\ No newline at end of file
#pragma once #pragma once
#include <kernel/back/props/Props.hpp> #include <kernel/front/props/Props.hpp>
#include <kernel/front/component/physic/Fixed.hpp> #include <kernel/front/component/physic/Fixed.hpp>
#include <kernel/front/component/graphic/Sprite.hpp> #include <kernel/front/component/graphic/Sprite.hpp>
#include <kernel/front/component/graphic/TileMap.hpp> #include <kernel/front/component/graphic/TileMap.hpp>
namespace megu::game { namespace megu::game {
class Object : public kernel::Props { class Object : public kernel::Prop {
public: public:
Object(std::filesystem::path &); Object(std::filesystem::path &);
inline kernel::Physical<kernel::PhysicEngine> * getPhysicComponent() override {return &this->_physic;} inline kernel::Prop::Physical_Component * getPhysicComponent() override {return &this->_physic;}
inline kernel::Graphical<kernel::GraphicEngine> * getGraphicComponent() override {return &this->_map;} inline kernel::Prop::Graphical_Component * getGraphicComponent() override {return &this->_map;}
private: private:
kernel::Fixed _physic; kernel::Fixed _physic;
......
#pragma once #pragma once
#include "Component.hpp" #include "Component.hpp"
#include <engine/utility/Priority.hpp>
namespace megu::kernel { namespace megu::kernel {
template <class Ge> template <class Ge>
......
#pragma once #pragma once
#include <functional>
#include "Component.hpp" #include "Component.hpp"
#include <functional>
#include <utility/Identifiable.hpp> #include <utility/Identifiable.hpp>
namespace megu::kernel { namespace megu::kernel {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <engine/graphics/front/module/TileArray_Module.hpp> #include <engine/graphics/front/module/TileArray_Module.hpp>
#include <engine/graphics/front/object/TileArray.hpp> #include <engine/graphics/front/object/TileArray.hpp>
#include <kernel/back/props/Graphical.hpp> #include <kernel/back/component/Graphical.hpp>
namespace megu::kernel { namespace megu::kernel {
class GraphicEngine : public Engine<megu::GraphicEngine, Graphical<GraphicEngine>, Renderable> { class GraphicEngine : public Engine<megu::GraphicEngine, Graphical<GraphicEngine>, Renderable> {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "Engine.hpp" #include "Engine.hpp"
#include <engine/physic/front/engine/Engine.hpp> #include <engine/physic/front/engine/Engine.hpp>
#include <kernel/back/props/Physical.hpp> #include <kernel/back/component/Physical.hpp>
namespace megu::kernel { namespace megu::kernel {
class PhysicEngine : public Engine<megu::PhysicEngine, Physical<PhysicEngine>, Tangible> { class PhysicEngine : public Engine<megu::PhysicEngine, Physical<PhysicEngine>, Tangible> {
......
...@@ -24,7 +24,7 @@ namespace megu::kernel { ...@@ -24,7 +24,7 @@ namespace megu::kernel {
this->_pResolver.resolve(*this, this->_pEngine, time); this->_pResolver.resolve(*this, this->_pEngine, time);
} }
void Kernel::add(Props * props) { void Kernel::add(Prop * props) {
this->_props[props->id()] = props; this->_props[props->id()] = props;
auto * pComponent = props->getPhysicComponent(); auto * pComponent = props->getPhysicComponent();
if(pComponent != nullptr) { if(pComponent != nullptr) {
......
...@@ -4,23 +4,24 @@ ...@@ -4,23 +4,24 @@
#include <engine/io/Window.hpp> #include <engine/io/Window.hpp>
#include <kernel/back/engine/PhysicEngine.hpp> #include <kernel/front/props/Props.hpp>
#include <kernel/back/engine/GraphicEngine.hpp>
#include <kernel/back/props/Props.hpp>
#include "resolver/PhysicResolver.hpp"
#include "resolver/GraphicResolver.hpp" #include "resolver/GraphicResolver.hpp"
#include "resolver/PhysicResolver.hpp"
namespace megu::kernel { namespace megu::kernel {
class PhysicResolver;
class GraphicResolver;
class Kernel { class Kernel {
public: public:
Kernel(Window &); Kernel(Window &);
~Kernel(); ~Kernel();
void step(); void step();
void add(Props *); void add(Prop *);
inline Identifiable_Map<Props> & props() {return this->_props;} inline Identifiable_Map<Prop> & props() {return this->_props;}
inline PhysicEngine & getPhysicEngine() {return this->_pEngine;} inline PhysicEngine & getPhysicEngine() {return this->_pEngine;}
inline GraphicEngine & getGraphicEngine() {return this->_gEngine;} inline GraphicEngine & getGraphicEngine() {return this->_gEngine;}
...@@ -31,7 +32,7 @@ namespace megu::kernel { ...@@ -31,7 +32,7 @@ namespace megu::kernel {
PhysicEngine _pEngine; PhysicEngine _pEngine;
GraphicEngine _gEngine; GraphicEngine _gEngine;
Identifiable_Map<Props> _props; Identifiable_Map<Prop> _props;
PhysicResolver _pResolver; PhysicResolver _pResolver;
GraphicResolver _gResolver; GraphicResolver _gResolver;
}; };
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <chrono> #include <chrono>
#include <kernel/back/engine/GraphicEngine.hpp> #include <kernel/back/engine/GraphicEngine.hpp>
#include <kernel/back/props/Graphical.hpp> #include <kernel/back/component/Graphical.hpp>
#include <kernel/back/linker/GraphicLinker.hpp> #include <kernel/back/linker/GraphicLinker.hpp>
#include <engine/utility/ref_set.hpp> #include <engine/utility/ref_set.hpp>
......
...@@ -4,14 +4,17 @@ namespace megu::kernel { ...@@ -4,14 +4,17 @@ namespace megu::kernel {
UniqueGraphicLinker<TileArray> Tilemap::_Linker = UniqueGraphicLinker<TileArray>(); UniqueGraphicLinker<TileArray> Tilemap::_Linker = UniqueGraphicLinker<TileArray>();
Tilemap::Tilemap(const std::filesystem::path & path, size_t width, size_t height, float size, size_t lenght, double aUpdate) 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), _tileSize(lenght), _duration(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."); throw std::runtime_error("Tilemap dimension not matching tiles size.");
} }
for(size_t x = 0; x < this->texture().width() - this->_tileSize*2; x += this->_tileSize) { size_t tileWidth = this->texture().width() / this->_tileSize;
for(size_t y = 0; y < this->texture().height() - this->_tileSize*2; y += this->_tileSize) { size_t tileHeight = this->texture().height() / this->_tileSize;
this->_tilesPosition.push_back({y, x});
for(size_t y = 0; y < tileHeight; ++y) {
for(size_t x = 0; x < tileWidth; ++x) {
this->_tilesPosition.push_back({x * this->_tileSize, y * this->_tileSize});
} }
} }
...@@ -28,10 +31,19 @@ namespace megu::kernel { ...@@ -28,10 +31,19 @@ namespace megu::kernel {
Tilemap::_Linker.setModule(new TileArray_Module{}); Tilemap::_Linker.setModule(new TileArray_Module{});
} }
this->setSize({width * size, height * size}); //this->setSize({width * size, height * size});
} }
void Tilemap::setValue(size_t x, size_t y, size_t value) { void Tilemap::setValue(size_t x, size_t y, size_t value) {
if(this->width() <= x || this->height() <= y) {
throw std::runtime_error("Set Tilemap coords out of range.");
}
if(value >= this->_tilesPosition.size()) {
std::cerr << value << " for " << this->_tilesPosition.size() << std::endl;
throw std::runtime_error("Set Tilemap value out of range.");
}
TilePosition position = this->_tilesPosition[value]; TilePosition position = this->_tilesPosition[value];
glm::vec4 uv = {position.x, glm::vec4 uv = {position.x,
this->texture().height() - position.y - this->_tileSize, this->texture().height() - position.y - this->_tileSize,
...@@ -42,7 +54,12 @@ namespace megu::kernel { ...@@ -42,7 +54,12 @@ namespace megu::kernel {
this->_tilesValue[x][y] = value; this->_tilesValue[x][y] = value;
} }
size_t Tilemap::getValue(size_t x, size_t y) { size_t Tilemap::getValue(size_t x, size_t y) const {
TilePosition position = {x, y};
if(this->_animations.contains(position)) {
return this->_animations.at(position).first.at(this->_animations.at(position).second);
}
if(this->_tilesValue.size() > x && this->_tilesValue[x].size() > y) { if(this->_tilesValue.size() > x && this->_tilesValue[x].size() > y) {
return this->_tilesValue[x][y]; return this->_tilesValue[x][y];
} }
...@@ -50,15 +67,16 @@ namespace megu::kernel { ...@@ -50,15 +67,16 @@ namespace megu::kernel {
} }
void Tilemap::addAnimation(size_t x, size_t y, const std::vector<size_t> & ids) { void Tilemap::addAnimation(size_t x, size_t y, const std::vector<size_t> & ids) {
if(x < this->width() && y < this->height()) {
this->_animations[{x, y}] = std::pair<std::vector<size_t>, size_t>(ids, 0); this->_animations[{x, y}] = std::pair<std::vector<size_t>, size_t>(ids, 0);
} }
}
void Tilemap::removeAnimation(size_t x, size_t y) { void Tilemap::removeAnimation(size_t x, size_t y) {
this->_animations.erase({x, y}); this->_animations.erase({x, y});
} }
void Tilemap::update(double time) { void Tilemap::update(double time) {
//... Peut-être des tiles animées si j'ai le temps 🙌 (spoiler non).
if(this->_previous == 0.0) { if(this->_previous == 0.0) {
this->_previous = time; this->_previous = time;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include <kernel/back/engine/GraphicEngine.hpp> #include <kernel/back/engine/GraphicEngine.hpp>
#include <kernel/back/props/Graphical.hpp> #include <kernel/back/component/Graphical.hpp>
#include <kernel/back/linker/UniqueLinker.hpp> #include <kernel/back/linker/UniqueLinker.hpp>
#include <engine/graphics/front/object/TileArray.hpp> #include <engine/graphics/front/object/TileArray.hpp>
...@@ -17,29 +17,31 @@ namespace megu::kernel { ...@@ -17,29 +17,31 @@ namespace megu::kernel {
size_t x = 0; size_t x = 0;
size_t y = 0; size_t y = 0;
friend bool operator<(const TilePosition & p1, const TilePosition & p2) { bool operator<(const TilePosition & p) const {
if(p1.x == p2.x) { if(this->x == p.x) {
return p1.y < p2.y; return this->y < p.y;
} }
return p1.x < p1.y; return this->y < p.y;
} }
}; };
Tilemap(const std::filesystem::path &, size_t, size_t, float, size_t, double = 0.1); Tilemap(const std::filesystem::path &, size_t, size_t, float, size_t, double = 0.1);
void setValue(size_t, size_t, size_t); void setValue(size_t, size_t, size_t);
size_t getValue(size_t, size_t); size_t getValue(size_t, size_t) const;
void addAnimation(size_t, size_t, const std::vector<size_t> &); void addAnimation(size_t, size_t, const std::vector<size_t> &);
void removeAnimation(size_t, size_t); void removeAnimation(size_t, size_t);
const std::map<TilePosition, std::pair<std::vector<size_t>, size_t>, reference_sorter<TilePosition>> & animation() const {return this->_animations;}
void update(double) override; void update(double) override;
void apply(Kernel &, GraphicEngine &) override; void apply(Kernel &, GraphicEngine &) override;
private: private:
std::vector<TilePosition> _tilesPosition; std::vector<TilePosition> _tilesPosition;
std::vector<std::vector<size_t>> _tilesValue; std::vector<std::vector<size_t>> _tilesValue;
std::map<TilePosition, std::pair<std::vector<size_t>, size_t>> _animations; std::map<TilePosition, std::pair<std::vector<size_t>, size_t>, reference_sorter<TilePosition>> _animations;
TileArray_Module _module; TileArray_Module _module;
size_t _tileSize; size_t _tileSize;
double _duration; double _duration;
......
#pragma once #pragma once
#include <kernel/back/props/Physical.hpp> #include <kernel/back/component/Physical.hpp>
#include <kernel/back/engine/PhysicEngine.hpp> #include <kernel/back/engine/PhysicEngine.hpp>
#include <engine/physic/front/object/TangibleStatic.hpp> #include <engine/physic/front/object/TangibleStatic.hpp>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment