summaryrefslogtreecommitdiffstats
path: root/src/view/MapView.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/MapView.hpp')
-rw-r--r--src/view/MapView.hpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/view/MapView.hpp b/src/view/MapView.hpp
index 9150753..e3fccc6 100644
--- a/src/view/MapView.hpp
+++ b/src/view/MapView.hpp
@@ -30,6 +30,7 @@
#include "../model/Map.hpp"
#include <cmath>
+#include <map>
namespace RPGEdit {
@@ -41,11 +42,13 @@ private:
std::shared_ptr<Window> window;
std::shared_ptr<const Model::Map> map;
SDL_Texture *tileTexture;
+ std::map<std::string, SDL_Texture *> entityTextures;
public:
MapView(const std::shared_ptr<Window> &window0,
const std::shared_ptr<const Model::Map> &map0,
- const std::vector<SDL_Surface *> tiles)
+ const std::vector<SDL_Surface *> &tiles,
+ const std::map<std::string, SDL_Surface *> &entities)
: window(window0), map(map0) {
uint32_t rmask, gmask, bmask, amask;
@@ -77,10 +80,17 @@ public:
tileTexture = SDL_CreateTextureFromSurface(window->getRenderer(), surface);
SDL_FreeSurface(surface);
+
+ for (const std::pair<std::string, SDL_Surface *> &entity : entities) {
+ entityTextures[entity.first] = SDL_CreateTextureFromSurface(window->getRenderer(), entity.second);
+ }
}
~MapView() {
SDL_DestroyTexture(tileTexture);
+
+ for (const std::pair<std::string, SDL_Texture *> &entity : entityTextures)
+ SDL_DestroyTexture(entity.second);
}
void render(float centerX, float centerY) {
@@ -123,6 +133,27 @@ public:
}
}
+ for (const std::shared_ptr<Model::Entity> &entity : map->getEntities()) {
+ std::pair<float, float> pos = entity->getPosition();
+ Direction dir = entity->getDirection();
+
+ SDL_Rect src = {
+ .x = 16*dir,
+ .y = 0,
+ .w = 16,
+ .h = 16,
+ };
+
+ SDL_Rect dst = {
+ .x = baseX + int(pos.first*tilePixels),
+ .y = baseY + int(pos.second*tilePixels),
+ .w = tilePixels,
+ .h = tilePixels,
+ };
+
+ SDL_RenderCopy(window->getRenderer(), entityTextures[entity->getName()], &src, &dst);
+ }
+
SDL_RenderPresent(window->getRenderer());
}
};