diff --git a/Resources/maps/debugmap.tmx b/Resources/maps/debugmap.tmx
new file mode 100644
index 0000000..ea7b84c
--- /dev/null
+++ b/Resources/maps/debugmap.tmx
@@ -0,0 +1,70 @@
+
+
diff --git a/Resources/maps/tilesets/shooterWorldOne.tsx b/Resources/maps/tilesets/shooterWorldOne.tsx
new file mode 100644
index 0000000..6b26e74
--- /dev/null
+++ b/Resources/maps/tilesets/shooterWorldOne.tsx
@@ -0,0 +1,366 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Resources/sprites/shooterWorldOneAtlas64.png b/Resources/maps/tilesets/shooterWorldOneAtlas64.png
similarity index 100%
rename from Resources/sprites/shooterWorldOneAtlas64.png
rename to Resources/maps/tilesets/shooterWorldOneAtlas64.png
diff --git a/Resources/maps/yupple.tiled-project b/Resources/maps/yupple.tiled-project
new file mode 100644
index 0000000..911167b
--- /dev/null
+++ b/Resources/maps/yupple.tiled-project
@@ -0,0 +1,14 @@
+{
+ "automappingRulesFile": "",
+ "commands": [
+ ],
+ "compatibilityVersion": 1100,
+ "extensionsPath": "extensions",
+ "folders": [
+ "../"
+ ],
+ "properties": [
+ ],
+ "propertyTypes": [
+ ]
+}
diff --git a/Resources/maps/yupple.tiled-session b/Resources/maps/yupple.tiled-session
new file mode 100644
index 0000000..c555e9b
--- /dev/null
+++ b/Resources/maps/yupple.tiled-session
@@ -0,0 +1,54 @@
+{
+ "activeFile": "",
+ "expandedProjectPaths": [
+ ],
+ "fileStates": {
+ "": {
+ "scaleInDock": 1
+ },
+ ":/automap-tiles.tsx": {
+ "scaleInDock": 1
+ },
+ "C:/Users/Ethan/Documents/yupplemayham/debugmap.tmx": {
+ "scale": 0.5472395833333333,
+ "selectedLayer": 0,
+ "viewCenter": {
+ "x": 959.3604263824117,
+ "y": 639.5736175882744
+ }
+ },
+ "C:/Users/Ethan/Documents/yupplemayham/shooterWorldOneAtlas.tsx": {
+ "scaleInDock": 0.5,
+ "scaleInEditor": 1
+ },
+ "debugmap.tmx": {
+ "scale": 0.45125,
+ "selectedLayer": 0,
+ "viewCenter": {
+ "x": 959.5567867036011,
+ "y": 955.1246537396123
+ }
+ },
+ "shooterWorldOneAtlas.tsx": {
+ "scaleInDock": 0.5,
+ "scaleInEditor": 1
+ },
+ "tilesets/shooterWorldOneAtlas.tsx": {
+ "scaleInDock": 0.5,
+ "scaleInEditor": 1
+ }
+ },
+ "last.externalTilesetPath": "C:/Users/Ethan/source/repos/YuppleMayham/Resources/maps/tilesets",
+ "last.imagePath": "C:/Users/Ethan/source/repos/YuppleMayham/Resources/maps/tilesets",
+ "openFiles": [
+ ],
+ "project": "yupple.tiled-project",
+ "property.type": "bool",
+ "recentFiles": [
+ "tilesets/shooterWorldOneAtlas.tsx",
+ "shooterWorldOneAtlas.tsx",
+ "C:/Users/Ethan/Documents/yupplemayham/shooterWorldOneAtlas.tsx",
+ "C:/Users/Ethan/Documents/yupplemayham/debugmap.tmx"
+ ],
+ "tileset.lastUsedFilter": "Tiled tileset files (*.tsx *.xml)"
+}
diff --git a/Resources/scenes/debugScene.xml b/Resources/scenes/debugScene.xml
index 11d39e8..ec2d95f 100644
--- a/Resources/scenes/debugScene.xml
+++ b/Resources/scenes/debugScene.xml
@@ -1,38 +1,7 @@
-
+
diff --git a/Resources/shaders/GL_tile.frag b/Resources/shaders/GL_tile.frag
index 2c9de80..f53e7bd 100644
--- a/Resources/shaders/GL_tile.frag
+++ b/Resources/shaders/GL_tile.frag
@@ -6,6 +6,13 @@ uniform sampler2D tileTexture;
void main()
{
- FragColor = texture(tileTexture, texCoord);
+ if (texCoord.x == 0.0 && texCoord.y == 0.0)
+ {
+ FragColor = vec4(0.0, 0.0, 0.0, 0.0);
+ }
+ else
+ {
+ FragColor = texture(tileTexture, texCoord);
+ }
//FragColor = vec4(mod(tileindex / float(tilesperrow), 1.0), mod(tileindex / float(tilesperrow), 1.0), 0.0, 1.0);
}
\ No newline at end of file
diff --git a/Resources/shaders/GL_tile.vert b/Resources/shaders/GL_tile.vert
index 1160865..7e1ddbd 100644
--- a/Resources/shaders/GL_tile.vert
+++ b/Resources/shaders/GL_tile.vert
@@ -1,7 +1,7 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
-layout (location = 2) in int tileIndex;
+layout (location = 2) in int aTileIndex;
layout (location = 3) in mat4 aModel;
uniform int tilesPerRow;
@@ -9,19 +9,29 @@ uniform mat4 proj;
uniform mat4 view;
out vec2 texCoord;
+out int tileIndex;
void main()
{
- float tileSize = 1.0 / float(tilesPerRow);
-
+ tileIndex = aTileIndex;
gl_Position = proj * view * aModel * vec4(aPos, 1.0);
+ if (tileIndex != 0)
+ {
+ int index = tileIndex - 1;
+ float tileSize = 1.0 / float(tilesPerRow);
- int row = tileIndex / tilesPerRow;
- int col = tileIndex % tilesPerRow;
+ int row = index / tilesPerRow;
+ int col = index % tilesPerRow;
- float offsetX = float(col) * tileSize;
- float offsetY = float(row) * tileSize;
+ float offsetX = float(col) * tileSize;
+ float offsetY = float(row) * tileSize;
- texCoord.x = (aTexCoord.x + col) * tileSize;
- texCoord.y = (aTexCoord.y + row) * tileSize;
+ texCoord.x = (aTexCoord.x + col) * tileSize;
+ texCoord.y = (aTexCoord.y + row) * tileSize;
+ }
+ else
+ {
+ texCoord.x = 0.0;
+ texCoord.y = 0.0;
+ }
}
\ No newline at end of file
diff --git a/YuppleMayham/CMakeLists.txt b/YuppleMayham/CMakeLists.txt
index 77a6d5e..cf36d30 100644
--- a/YuppleMayham/CMakeLists.txt
+++ b/YuppleMayham/CMakeLists.txt
@@ -35,7 +35,7 @@ add_executable (YuppleMayham
"src/gameplay/weapons/bulletmanager.cpp"
"src/gameplay/scene.cpp"
"src/graphics/texture.cpp"
- "src/graphics/tile.cpp"
+
"src/utility/resourcemanager.cpp"
"src/utility/xmlloader.cpp"
"src/gameplay/game.cpp"
@@ -52,9 +52,9 @@ add_executable (YuppleMayham
"include/utility/mousestate.h"
"include/gameplay/weapons/bulletmanager.h"
"include/gameplay/scene.h"
- "include/graphics/tile.h"
+
"include/graphics/texture.h"
- "include/graphics/tiletype.h"
+
"include/utility/resourcemanager.h"
"include/utility/xmlloader.h"
"include/gameplay/game.h"
diff --git a/YuppleMayham/include/gameplay/map.h b/YuppleMayham/include/gameplay/map.h
index 25e28f9..f9f498e 100644
--- a/YuppleMayham/include/gameplay/map.h
+++ b/YuppleMayham/include/gameplay/map.h
@@ -6,17 +6,16 @@
#include "graphics/instancedraw.h"
-//class TileTextureInstance;
class Shader;
class Camera;
+class ResourceManager;
struct MapData;
-//struct InstanceData;
-struct Tile;
+struct TileSetData;
class Map
{
public:
- Map(const std::shared_ptr& mapData, const std::shared_ptr& shader);
+ Map(std::shared_ptr mapData, const std::shared_ptr& shader, std::shared_ptr resourceManager);
const std::vector> getCollisionMap() const { return collisionMap; }
@@ -26,13 +25,14 @@ private:
void loadMap();
void createCollisionMap();
- const std::shared_ptr mapData;
+ std::shared_ptr mapData;
+ std::shared_ptr tileSetData;
- std::shared_ptr instanceHandle;
+ std::vector> instanceHandles;
std::shared_ptr shader;
- std::vector>> tileIds;
+ std::vector>> tileIds;
std::vector> collisionMap;
- std::vector tileData;
+ std::vector> tileData;
};
#endif
\ No newline at end of file
diff --git a/YuppleMayham/include/gameplay/weapons/weapon.h b/YuppleMayham/include/gameplay/weapons/weapon.h
index fb7fd64..9ac11e6 100644
--- a/YuppleMayham/include/gameplay/weapons/weapon.h
+++ b/YuppleMayham/include/gameplay/weapons/weapon.h
@@ -27,7 +27,7 @@ struct WeaponData;
class Weapon : public Entity, public std::enable_shared_from_this
{
public:
- Weapon(const WeaponData* data, const std::shared_ptr& weaponShader, const std::shared_ptr& bulletShader, ResourceManager* resourceManager);
+ Weapon(std::shared_ptr data, const std::shared_ptr& weaponShader, const std::shared_ptr& bulletShader, ResourceManager* resourceManager);
void setWielder(const std::shared_ptr& wielder) { this->wielder = wielder; }
void toggleInfiniteAmmo() { infiniteAmmo = !infiniteAmmo; }
diff --git a/YuppleMayham/include/graphics/instancedraw.h b/YuppleMayham/include/graphics/instancedraw.h
index 6c4ba99..8002572 100644
--- a/YuppleMayham/include/graphics/instancedraw.h
+++ b/YuppleMayham/include/graphics/instancedraw.h
@@ -10,7 +10,7 @@ class Texture;
struct InstanceData {
glm::mat4 modelMatrix;
- int tileIndex;
+ int tileIndex = 0;
};
class BaseInstanceDraw
@@ -26,6 +26,7 @@ protected:
Texture* texture = nullptr;
InstanceData instanceData[MAX_INSTANCES];
size_t numOfInstances = 0;
+ size_t numOfLayers = 0;
unsigned indices[6] = {
0, 1, 2,
3, 2, 0
diff --git a/YuppleMayham/include/graphics/tile.h b/YuppleMayham/include/graphics/tile.h
deleted file mode 100644
index 078506a..0000000
--- a/YuppleMayham/include/graphics/tile.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef _H_TILE_H
-#define _H_TILE_H
-
-#include
-#include
-#include
-#include
-
-enum class TileType;
-class Texture;
-
-// TODO: Decide how this struct will be used.
-// This holds only the texture data of the tile, this texture data will be held in
-// a further struct called Tile
-struct TileTexture {
- Texture* texture = nullptr;
- unsigned VAO, VBO, EBO;
-};
-
-// TODO: Finished replacing the Sprite version of tile set with this one
-// This class is NOT for game logic, only for the storage of the tile pointers that point to the TileTexture
-class TileSet
-{
-public:
- TileSet(const char* tileSetImage, float frameSize);
- void setupTiles(float frameSize);
- ~TileSet();
-
- const std::shared_ptr& getTileTexture(TileType tileType) const;
-
-private:
- Texture* texture;
-
- std::unordered_map> tiles;
-};
-
-#endif
\ No newline at end of file
diff --git a/YuppleMayham/include/graphics/tiletype.h b/YuppleMayham/include/graphics/tiletype.h
deleted file mode 100644
index 14620f6..0000000
--- a/YuppleMayham/include/graphics/tiletype.h
+++ /dev/null
@@ -1,78 +0,0 @@
-#ifndef _H_TILETYPE_H
-#define _H_TILETYPE_H
-
-struct Tile {
- enum class SpriteID {
- TILE_SOLID_GRASS_1,
- TILE_SOLID_GRASS_2,
- TILE_SOLID_GRASS_3,
- TILE_SOLID_GRASS_4,
- TILE_SOLID_GRASS_5,
- TILE_SOLID_GRASS_6,
- TILE_SOLID_GRASS_7,
- TILE_SOLID_GRASS_8,
- TILE_LSHAPE_GRASS_TL,
- TILE_LSHAPE_GRASS_TR,
- TILE_LSHAPE_GRASS_BR,
- TILE_LSHAPE_GRASS_BL,
- TILE_LINE_GRASS_T,
- TILE_LINE_GRASS_L,
- TILE_LINE_GRASS_R,
- TILE_LINE_GRASS_B,
- TILE_VSEG_GRASS_TL,
- TILE_VSEG_GRASS_TR,
- TILE_HSEG_GRASS_TL,
- TILE_HSEG_GRASS_TR,
- TILE_VSEG_GRASS_BL,
- TILE_VSEG_GRASS_BR,
- TILE_HSEG_GRASS_BL,
- TILE_HSEG_GRASS_BR,
- TILE_SOLID_DIRT_1,
- TILE_SOLID_DIRT_2,
- TILE_SOLID_DIRT_3,
- TILE_SOLID_DIRT_4,
- TILE_SOLID_DIRT_5,
- TILE_SOLID_DIRT_6,
- TILE_SOLID_DIRT_7,
- TILE_SOLID_DIRT_8,
- TILE_SOLID_WATER_1,
- TILE_SOLID_WATER_2,
- TILE_SOLID_WATER_3,
- TILE_SOLID_WATER_4,
- TILE_SOLID_WATER_5,
- TILE_SOLID_WATER_6,
- TILE_SOLID_WATER_7,
- TILE_SOLID_WATER_8,
- TILE_LSHAPE_WATER_TL,
- TILE_LSHAPE_WATER_TR,
- TILE_LSHAPE_WATER_BR,
- TILE_LSHAPE_WATER_BL,
- TILE_LINE_WATER_T,
- TILE_LINE_WATER_L,
- TILE_LINE_WATER_R,
- TILE_LINE_WATER_B,
- TILE_VSEG_WATER_TL,
- TILE_VSEG_WATER_TR,
- TILE_HSEG_WATER_TL,
- TILE_HSEG_WATER_TR,
- TILE_VSEG_WATER_BL,
- TILE_VSEG_WATER_BR,
- TILE_HSEG_WATER_BL,
- TILE_HSEG_WATER_BR,
- TILE_MISC_FLOWERS_1,
- TILE_MISC_FLOWERS_2,
- TILE_MISC_DUCK,
- TILE_MISC_PEBBLE_1,
- TILE_MISC_ROCK,
- TILE_MISC_SHRUB,
- TILE_MISC_PEBBLE_2,
- TILE_MISC_PEBBLE_3
- }spriteID;
- enum class TileData {
- TILE_WALKABLE = 1,
- TILE_WATER = 2,
- TILE_UNWALKABLE = 64
- }tileData;
-};
-
-#endif // _H_TILETYPE_H
\ No newline at end of file
diff --git a/YuppleMayham/include/utility/resourcemanager.h b/YuppleMayham/include/utility/resourcemanager.h
index 9d86652..ce20586 100644
--- a/YuppleMayham/include/utility/resourcemanager.h
+++ b/YuppleMayham/include/utility/resourcemanager.h
@@ -16,7 +16,7 @@ class Script;
class AnimationSet;
class AIScript;
class WeaponScript;
-class TileSet;
+class TileSetData;
class SpriteComponent;
class ResourceManager
@@ -26,20 +26,22 @@ public:
xmlLoader(std::make_shared())
{
xmlLoader->loadWeapons("weapons");
- xmlLoader->loadScenes("scenes");
xmlLoader->loadAnimations("animations");
+ xmlLoader->loadTileSets("maps/tilesets");
+ xmlLoader->loadMaps("maps");
+ xmlLoader->loadScenes("scenes");
};
std::shared_ptr loadSpriteAtlas (const std::string& path, float frameSize, bool isDirectional = false);
std::shared_ptr loadSpriteStatic (const std::string& path);
std::shared_ptr loadAIScript (const std::string& path);
std::shared_ptr loadWeaponScript (const std::string& path);
- std::shared_ptr loadTileSet (const std::string& path, float frameSize);
std::shared_ptr loadShader (const std::string& name, const std::string& vertexPath, const std::string& fragPath);
std::shared_ptr loadWeapon (const std::string& name, std::shared_ptr weaponShader, std::shared_ptr bulletShader);
std::shared_ptr loadScene (const std::string& id);
std::shared_ptr loadAnimationSet(const std::string& name, int entityid = 0);
+ std::shared_ptr loadTileSet (const std::string& name);
void clearResources();
@@ -48,7 +50,7 @@ private:
std::unordered_map> shaders;
std::unordered_map> weapons;
std::unordered_map> scripts;
- std::unordered_map> tileSets;
+ std::unordered_map>tileSets;
//std::unordered_map> entityData;
//std::unordered_map> scenes;
//std::unordered_map> maps;
diff --git a/YuppleMayham/include/utility/xmlloader.h b/YuppleMayham/include/utility/xmlloader.h
index 7a6fbbc..4a7ff62 100644
--- a/YuppleMayham/include/utility/xmlloader.h
+++ b/YuppleMayham/include/utility/xmlloader.h
@@ -5,6 +5,12 @@
#include
#include
#include
+#include
+
+#include
+#include
+#include
+#include
struct Tile;
@@ -19,17 +25,44 @@ struct EntityData {
struct MapData {
std::string name;
- std::string file;
+ std::string tileSet;
int width = 0, height = 0;
float tileSize = 32.f;
- std::vector>> groundTiles;
+ // 3D array, 0: layer, 1: y, 2: x
+ // Holding tile ids + 1, 0 is an empty tile
+ std::vector>> tiles;
+};
+
+struct TileSetData {
+ std::string name;
+ std::string type;
+ std::string file;
+ int width = 0, height = 0;
+ int columns = 0;
+ int tileCount = 0;
+ float tileSize = 64.f;
+ struct TileData {
+ int id = 0;
+ std::string type;
+ bool walkable = true;
+ struct ObjectData {
+ int id = 0;
+ std::string name;
+ glm::vec2 pos;
+ glm::vec2 size;
+ bool collidable = false;
+ bool pickup = false;
+ };
+ std::vector> objects;
+ };
+ std::vector> tiles;
};
struct SceneData {
std::string id;
std::string type;
- MapData map;
+ std::shared_ptr map;
std::vector entities;
};
@@ -74,6 +107,8 @@ public:
bool loadScenes(const char* sceneFolder);
bool loadWeapons(const char* weaponFolder);
bool loadAnimations(const char* animationFolder);
+ bool loadTileSets(const char* tileSetFolder);
+ bool loadMaps(const char* mapFolder);
const std::shared_ptr getSceneData(const std::string& id) const {
try {
@@ -84,6 +119,24 @@ public:
}
}
+ const std::shared_ptr getMapData(const std::string& name) const {
+ try {
+ return maps.at(name);
+ }
+ catch (std::exception&) {
+ return nullptr;
+ }
+ }
+
+ const std::shared_ptr getWeaponData(const std::string& name) const {
+ try {
+ return weapons.at(name);
+ }
+ catch (std::exception&) {
+ return nullptr;
+ }
+ }
+
const std::shared_ptr getAnimationData(const std::string& name) const {
try {
return animations.at(name);
@@ -93,6 +146,15 @@ public:
}
}
+ const std::shared_ptr getTileSetData(const std::string& name) const {
+ try {
+ return tileSets.at(name);
+ }
+ catch (std::exception&) {
+ return nullptr;
+ }
+ }
+
// return a full set of animations, may need further optimization.
// one idea is when loading animations we create a seperate map that holds each set by their reference, so we can just do a simple,
// hash table lookup.
@@ -106,18 +168,18 @@ public:
return animSet;
}
- const WeaponData* getWeaponDataByName(const char* name) const;
-
- void clearData() { scenes.clear(); weaponData.clear(); animations.clear(); }
+ void clearData() { scenes.clear(); weapons.clear(); animations.clear(); maps.clear(); tileSets.clear(); }
protected:
bool loadXmlScene(const char* xmlFile, SceneData* out);
- bool loadMap(const char* xmlFile, SceneData* out);
bool loadEntityData(const char* xmlFile, SceneData* out);
+ bool loadTile(tinyxml2::XMLElement* tileElement, TileSetData::TileData* out);
+ bool loadObject(tinyxml2::XMLElement* objectElement, TileSetData::TileData::ObjectData* out);
private:
std::unordered_map> scenes;
+ std::unordered_map> weapons;
std::unordered_map> animations;
-
- std::vector weaponData;
+ std::unordered_map> maps;
+ std::unordered_map> tileSets;
};
#endif // _H_XMLLOADER_H
\ No newline at end of file
diff --git a/YuppleMayham/src/gameplay/map.cpp b/YuppleMayham/src/gameplay/map.cpp
index 461b7dc..6dec0a3 100644
--- a/YuppleMayham/src/gameplay/map.cpp
+++ b/YuppleMayham/src/gameplay/map.cpp
@@ -1,52 +1,75 @@
#include "gameplay/map.h"
-#include "utility/xmlloader.h"
-#include "graphics/tiletype.h"
-#include "graphics/shader.h"
#include "gameplay/camera.h"
+#include "graphics/shader.h"
+#include "utility/xmlloader.h"
+#include "utility/resourcemanager.h"
#include
-Map::Map(const std::shared_ptr& mapData, const std::shared_ptr& shader) :
- shader(shader),
- mapData(mapData)
+Map::Map(std::shared_ptr mapData, const std::shared_ptr& shader, std::shared_ptr resourceManager) :
+ shader(shader),
+ mapData(mapData),
+ tileIds(mapData->tiles)
{
- instanceHandle = std::make_shared(this->mapData->file.c_str());
- tileIds = mapData->groundTiles;
- loadMap();
- createCollisionMap();
+ tileSetData = resourceManager->loadTileSet(mapData->tileSet);
+ if (tileSetData)
+ {
+ for (int layer = 0; layer < tileIds.size(); layer++)
+ instanceHandles.push_back(std::make_shared(tileSetData->file.c_str()));
+ loadMap();
+ createCollisionMap();
+ }
+
}
void Map::loadMap()
{
- for (int y = 0; y < tileIds.size(); y++)
+ tileData.resize(tileIds.size());
+ for (int layer = 0; layer < tileIds.size(); layer++)
{
- for (int x = 0; x < tileIds[y].size(); x++)
+ for (int y = 0; y < tileIds[layer].size(); y++)
{
- glm::mat4 modelMatrix =
- glm::translate(glm::mat4(1.f), glm::vec3(x * mapData->tileSize, y * mapData->tileSize, 0.0f)) *
- glm::scale(glm::mat4(1.f), glm::vec3(mapData->tileSize, mapData->tileSize, 1.0f));
- int tileIndex = static_cast(tileIds[y][x]->spriteID);
- tileData.push_back({ modelMatrix, tileIndex });
+ for (int x = 0; x < tileIds[layer][y].size(); x++)
+ {
+ glm::mat4 modelMatrix =
+ glm::translate(glm::mat4(1.f), glm::vec3(x * mapData->tileSize, y * mapData->tileSize, 0.0f)) *
+ glm::scale(glm::mat4(1.f), glm::vec3(mapData->tileSize, mapData->tileSize, 1.0f));
+ int tileIndex = static_cast(tileIds[layer][y][x]);
+ tileData[layer].push_back({modelMatrix, tileIndex});
+ }
}
}
shader->use();
// TODO: Figure someway to put these in with my xml data
- shader->setInt("tilesPerRow", 8);
+ shader->setInt("tilesPerRow", tileSetData->columns);
}
void Map::createCollisionMap()
{
- for (int y = 0; y < mapData->groundTiles.size(); y++)
+ // Match collisionMap to map size
+ collisionMap.resize(tileIds[0].size());
+ for (int y = 0; y < tileIds[0].size(); ++y)
{
- std::vector row;
- for (int x = 0; x < mapData->groundTiles[y].size(); x++)
+ collisionMap[y].resize(tileIds[0][y].size(), 0);
+ }
+
+ for (int layer = 0; layer < tileIds.size(); layer++)
+ {
+ for (int y = 0; y < tileIds[layer].size(); y++)
{
- if ((int)mapData->groundTiles[y][x]->tileData & (int)Tile::TileData::TILE_UNWALKABLE)
- row.push_back(1);
- else
- row.push_back(0);
+ for (int x = 0; x < tileIds[layer][y].size(); x++)
+ {
+ int id = tileIds[layer][y][x];
+ if (id == 0)
+ collisionMap[y][x] = 0;
+ else
+ {
+ auto& tile = tileSetData->tiles[id - 1];
+ if (!tile->walkable)
+ collisionMap[y][x] = 1;
+ }
+ }
}
- collisionMap.push_back(row);
}
}
@@ -55,6 +78,9 @@ void Map::render(const std::shared_ptr& camera)
shader->use();
shader->setMatrix4f("proj", glm::value_ptr(camera->getProjectionMatrix()));
shader->setMatrix4f("view", glm::value_ptr(camera->getViewMatrix()));
- instanceHandle->updateInstanceData(tileData);
- instanceHandle->draw();
+ for (int layer = 0; layer < instanceHandles.size(); layer++)
+ {
+ instanceHandles[layer]->updateInstanceData(tileData[layer]);
+ instanceHandles[layer]->draw();
+ }
}
\ No newline at end of file
diff --git a/YuppleMayham/src/gameplay/scene.cpp b/YuppleMayham/src/gameplay/scene.cpp
index 4eb674e..244bbed 100644
--- a/YuppleMayham/src/gameplay/scene.cpp
+++ b/YuppleMayham/src/gameplay/scene.cpp
@@ -6,7 +6,6 @@
#include "gameplay/physics.h"
#include "gameplay/ai.h"
-#include "graphics/tile.h"
#include "graphics/sprite.h"
#include "graphics/animation.h"
@@ -46,14 +45,14 @@ void Scene::loadDebugShooterScene()
if (!sceneData)
return;
EntityData playerData = sceneData->entities[0];
- MapData mapData = sceneData->map;
+ auto mapData = sceneData->map;
auto playerShader = resourceManager->loadShader("GL_player", "shaders/GL_player.vert", "shaders/GL_player.frag");
auto bubbleShader = resourceManager->loadShader("GL_bubble", "shaders/GL_bubble.vert", "shaders/GL_bubble.frag");
auto weaponShader = resourceManager->loadShader("GL_pistol", "shaders/GL_pistol.vert", "shaders/GL_pistol.frag");
// creating map from scene
auto tileShader = resourceManager->loadShader("GL_tile", "shaders/GL_tile.vert", "shaders/GL_tile.frag");
- map = std::make_shared