Extend map model with rotated tiles
This commit is contained in:
parent
9b91d6f3d0
commit
124116a8bf
4 changed files with 12 additions and 9 deletions
|
@ -87,8 +87,9 @@ void Map::finishEntityTransition(Entity *entity) {
|
||||||
std::unique_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) {
|
std::unique_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) {
|
||||||
std::unique_ptr<Map> map(new Map(16, 16, 2));
|
std::unique_ptr<Map> map(new Map(16, 16, 2));
|
||||||
|
|
||||||
map->tileset.push_back("dirt");
|
map->tileset.emplace_back("dirt", 0);
|
||||||
map->tileset.push_back("horizontal_bar");
|
map->tileset.emplace_back("horizontal_bar", 0);
|
||||||
|
map->tileset.emplace_back("horizontal_bar", 2);
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
for (int j = 0; j < 16; j++) {
|
for (int j = 0; j < 16; j++) {
|
||||||
|
@ -100,7 +101,9 @@ std::unique_ptr<Map> Map::load(__attribute__((unused)) const std::string &name)
|
||||||
map->setTileAt(0, Position<int>{i, j}, 0);
|
map->setTileAt(0, Position<int>{i, j}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (4 <= i && i < 12 && j == 8)
|
if (4 <= i && i < 12 && j == 7)
|
||||||
|
map->setTileAt(1, Position<int>{i, j}, 3);
|
||||||
|
else if (4 <= i && i < 12 && j == 8)
|
||||||
map->setTileAt(1, Position<int>{i, j}, 2);
|
map->setTileAt(1, Position<int>{i, j}, 2);
|
||||||
else
|
else
|
||||||
map->setTileAt(1, Position<int>{i, j}, 0);
|
map->setTileAt(1, Position<int>{i, j}, 0);
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Model {
|
||||||
|
|
||||||
class _Map {
|
class _Map {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> tileset;
|
std::vector<std::pair<std::string, int>> tileset;
|
||||||
|
|
||||||
size_t width, height;
|
size_t width, height;
|
||||||
std::vector<CollisionType> collision;
|
std::vector<CollisionType> collision;
|
||||||
|
@ -160,11 +160,11 @@ public:
|
||||||
entityStates = std::move(other.entityStates);
|
entityStates = std::move(other.entityStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> & getTileset() {
|
std::vector<std::pair<std::string, int>> & getTileset() {
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string> & getTileset() const {
|
const std::vector<std::pair<std::string, int>> & getTileset() const {
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace RPGEdit {
|
||||||
|
|
||||||
namespace View {
|
namespace View {
|
||||||
|
|
||||||
MapView::MapView(const std::shared_ptr<Window> &window0, const std::vector<std::string> &tileset)
|
MapView::MapView(const std::shared_ptr<Window> &window0, const std::vector<std::pair<std::string, int>> &tileset)
|
||||||
: window(window0) {
|
: window(window0) {
|
||||||
uint32_t rmask, gmask, bmask, amask;
|
uint32_t rmask, gmask, bmask, amask;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ MapView::MapView(const std::shared_ptr<Window> &window0, const std::vector<std::
|
||||||
.h = 0,
|
.h = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_Surface *sprite = spriteCache->get("tile", tileset[i], 0);
|
SDL_Surface *sprite = spriteCache->get("tile", tileset[i].first, tileset[i].second);
|
||||||
|
|
||||||
SDL_SetSurfaceBlendMode(sprite, SDL_BLENDMODE_NONE);
|
SDL_SetSurfaceBlendMode(sprite, SDL_BLENDMODE_NONE);
|
||||||
SDL_BlitSurface(sprite, nullptr, surface, &rect);
|
SDL_BlitSurface(sprite, nullptr, surface, &rect);
|
||||||
|
|
|
@ -50,7 +50,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapView(const std::shared_ptr<Window> &window0, const std::vector<std::string> &tileset);
|
MapView(const std::shared_ptr<Window> &window0, const std::vector<std::pair<std::string, int>> &tileset);
|
||||||
~MapView();
|
~MapView();
|
||||||
|
|
||||||
void updateEntities(const std::vector<std::unique_ptr<Model::Entity>> &entities);
|
void updateEntities(const std::vector<std::unique_ptr<Model::Entity>> &entities);
|
||||||
|
|
Reference in a new issue