summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-22 21:54:01 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-22 21:54:01 +0200
commitfe0c3b733abf6eac5f4b5bc18f24f8a5cda1bfc4 (patch)
tree6f96e327b37fad557bd7cba7b45911c401f98ad2 /src/view
parent6e67a0f13263b748718c692b4c6481a70b127fda (diff)
downloadrpgedit-fe0c3b733abf6eac5f4b5bc18f24f8a5cda1bfc4.tar
rpgedit-fe0c3b733abf6eac5f4b5bc18f24f8a5cda1bfc4.zip
Render entities
Diffstat (limited to 'src/view')
-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());
}
};