ADD: Introduce Ownership to tiles
This commit is contained in:
parent
48bd9bf8d9
commit
dad3a4e0f3
@ -10,6 +10,7 @@ uniform sampler2D textureSampler;
|
||||
uniform vec3 lightColor;
|
||||
|
||||
uniform bool isHighlighted;
|
||||
uniform vec3 highLightColor;
|
||||
|
||||
void main(void) {
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
@ -20,7 +21,7 @@ void main(void) {
|
||||
vec3 diffuse = brightness * lightColor;
|
||||
|
||||
if(isHighlighted) {
|
||||
outColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
outColor = vec4(highLightColor, 1.0);
|
||||
} else {
|
||||
outColor = vec4(diffuse, 1.0f) * texture(textureSampler, pass_textureCoords);
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
class TileRenderComponent : public Component{
|
||||
public:
|
||||
bool isHighlighted;
|
||||
glm::vec3 color = glm::vec3(0,1,0);
|
||||
explicit TileRenderComponent(bool isHighlighted) : isHighlighted(isHighlighted) {};
|
||||
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
void MasterRenderer::render(const Light &light, const Camera &camera) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.3254901961, 0.6431372549, 0.9254901961f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
entityRenderer->prepare(camera, light);
|
||||
|
||||
@ -51,5 +51,5 @@ void TerrainRenderer::prepareInstance(const TerrainRenderingData &hexTile) {
|
||||
glm::mat4 transformationMatrix = MathUtils::createTransformationMatrix(hexTile.transform->position, 0,0,0,1);
|
||||
terrainShader.loadTransformationMatrix(transformationMatrix);
|
||||
|
||||
terrainShader.loadIsHighlighted(hexTile.terrainRenderComponent->isHighlighted);
|
||||
terrainShader.loadHighlight(hexTile.terrainRenderComponent->isHighlighted, hexTile.terrainRenderComponent->color);
|
||||
}
|
||||
|
||||
@ -26,8 +26,9 @@ void TerrainShader::loadLight(glm::vec3 position, glm::vec3 color) {
|
||||
loadVector(location_lightColor, color);
|
||||
}
|
||||
|
||||
void TerrainShader::loadIsHighlighted(bool isHighlighted) {
|
||||
void TerrainShader::loadHighlight(bool isHighlighted, glm::vec3 color) {
|
||||
loadBoolean(location_isHighlighted, isHighlighted);
|
||||
loadVector(location_highlightColor, color);
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +46,7 @@ void TerrainShader::getAllUniformLocations() {
|
||||
location_lightColor = getUniformLocation("lightColor");
|
||||
|
||||
location_isHighlighted = getUniformLocation("isHighlighted");
|
||||
location_highlightColor = getUniformLocation("highLightColor");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ public:
|
||||
void loadProjectionMatrix(glm::mat4 matrix);
|
||||
void loadViewMatrix(glm::mat4 matrix);
|
||||
void loadLight(glm::vec3 position, glm::vec3 color);
|
||||
void loadIsHighlighted(bool isHighlighted);
|
||||
void loadHighlight(bool isHighlighted, glm::vec3 color);
|
||||
private:
|
||||
inline static const std::string VERTEX_FILE = "assets/shaders/terrainVertexShader.glsl";
|
||||
inline static const std::string FRAGMENT_FILE = "assets/shaders/terrainFragmentShader.glsl";
|
||||
@ -26,6 +26,7 @@ private:
|
||||
int location_lightColor;
|
||||
|
||||
int location_isHighlighted;
|
||||
int location_highlightColor;
|
||||
|
||||
protected:
|
||||
void bindAttributes() const override;
|
||||
|
||||
@ -100,7 +100,7 @@ void GameLayer::onUpdate()
|
||||
|
||||
AnimationSystem::update(*entityManager, EngineTime::totalTime);
|
||||
camera->move(moveDir, 0.5f);
|
||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera);
|
||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode);
|
||||
buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState);
|
||||
CollectResourceSystem::update(*entityManager, *gameMode);
|
||||
RenderSystem::render(*entityManager, *renderer);
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include "MapGenerator.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
float MapGenerator::hexRadius = 10.0f;
|
||||
|
||||
void MapGenerator::init(Loader &loader, float hexRadius) {
|
||||
@ -41,9 +43,7 @@ void MapGenerator::generateHexMap(Map &map, int width, int height, EntityManager
|
||||
if (randomValue < 0.5f) {
|
||||
resourceType = RessourceType::WOOD;
|
||||
ForestTileGenerator forestTileGenerator;
|
||||
if (entityID != 0) { //Todo: Only temporary for tests!
|
||||
tileEntities = forestTileGenerator.generateHexTile(entityManager, random, worldPos);
|
||||
}
|
||||
tileEntities = forestTileGenerator.generateHexTile(entityManager, random, worldPos);
|
||||
hexModel = AssetManager::getModel("hexModelWood");
|
||||
modelName = "hexModelWood";
|
||||
} else if (randomValue < 0.75f) {
|
||||
@ -63,6 +63,8 @@ void MapGenerator::generateHexMap(Map &map, int width, int height, EntityManager
|
||||
entityManager.addComponent(entityID, tileHighlightComponent);
|
||||
entityManager.addComponent(entityID, tileGameplayComponent);
|
||||
entityManager.addComponent(entityID, std::make_shared<MapEntityComponent>());
|
||||
//Todo replace with area system
|
||||
entityManager.addComponent(entityID, std::make_shared<OwnerComponent>(random.randomInt(0,4)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,10 @@
|
||||
#include "ecs/components/TileGameplayComponent.h"
|
||||
#include "tileGenerator/ForestTileGenerator.h"
|
||||
|
||||
|
||||
struct MapArea {
|
||||
int id;
|
||||
std::vector<std::pair<int, int>> tiles;
|
||||
};
|
||||
|
||||
class MapGenerator {
|
||||
private:
|
||||
@ -27,6 +30,8 @@ public:
|
||||
static void init(Loader& loader, float hexRadius);
|
||||
static void generateHexMap(Map& map, int width, int height, EntityManager& entityManager);
|
||||
|
||||
std::vector<MapArea> generateAreas(const EntityManager &em);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
@ -32,10 +32,12 @@ void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gam
|
||||
auto transform = entityManager.getComponent<TransformComponent>(entityID);
|
||||
auto gameplay = entityManager.getComponent<TileGameplayComponent>(entityID);
|
||||
auto render = entityManager.getComponent<TileRenderComponent>(entityID);
|
||||
auto owner = entityManager.getComponent<OwnerComponent>(entityID);
|
||||
|
||||
if (!transform || !gameplay || !render) continue;
|
||||
if (!transform || !gameplay || !render || !owner) continue;
|
||||
if (!render->isHighlighted) continue;
|
||||
|
||||
if (owner->playerID != player) continue;
|
||||
BuildingDefinition def;
|
||||
if (gameMode.getActiveBuilding() == BuildingType::FOREST_HUT) {
|
||||
def = BuildingConfig::get(BuildingType::FOREST_HUT);
|
||||
|
||||
@ -4,17 +4,19 @@
|
||||
|
||||
#include "TileHighlightSystem.h"
|
||||
|
||||
#include "../../../GameMode.h"
|
||||
#include "../../../../engine/core/ECS/TileRenderComponent.h"
|
||||
#include "../../../../engine/core/ECS/TransformComponent.h"
|
||||
#include "../components/TileGameplayComponent.h"
|
||||
#include "../../../../engine/layer/entities/Camera.h"
|
||||
|
||||
|
||||
void TileHighlightSystem::update(EntityManager &entityManager, const MousePicker& picker, const Camera& camera) {
|
||||
void TileHighlightSystem::update(EntityManager &entityManager, const MousePicker& picker, const Camera& camera, GameMode& gameMode) {
|
||||
for (EntityID entityID : entityManager.getAllEntities()) {
|
||||
auto tileRenderComponent = entityManager.getComponent<TileRenderComponent>(entityID);
|
||||
auto transformComponent = entityManager.getComponent<TransformComponent>(entityID);
|
||||
auto tileGameplayComponent = entityManager.getComponent<TileGameplayComponent>(entityID);
|
||||
auto ownerComponent = entityManager.getComponent<OwnerComponent>(entityID);
|
||||
|
||||
if (!tileRenderComponent || !transformComponent || !tileGameplayComponent) {
|
||||
continue;
|
||||
@ -25,6 +27,15 @@ void TileHighlightSystem::update(EntityManager &entityManager, const MousePicker
|
||||
glm::vec3 intersectionPoint;
|
||||
if (intersectTile(rayOrigin, rayDirection, transformComponent->position, tileGameplayComponent->radius, intersectionPoint)) {
|
||||
tileRenderComponent->isHighlighted = true;
|
||||
if (ownerComponent) {
|
||||
if (ownerComponent->playerID == gameMode.getCurrentPlayer()) {
|
||||
tileRenderComponent->color = glm::vec4(0.0f, 1.0f, 0.0f, 1.f);
|
||||
} else {
|
||||
tileRenderComponent->color = glm::vec4(1.0f, 0.0f, 0.0f, 1.f);
|
||||
}
|
||||
} else {
|
||||
tileRenderComponent->color = glm::vec4(0.5f, 0.5f, 0.5f, 1.f);
|
||||
}
|
||||
} else {
|
||||
tileRenderComponent->isHighlighted = false;
|
||||
}
|
||||
|
||||
@ -4,13 +4,15 @@
|
||||
|
||||
#ifndef TILEHIGHLIGHTSYSTEM_H
|
||||
#define TILEHIGHLIGHTSYSTEM_H
|
||||
#include "../../../GameMode.h"
|
||||
#include "../../../../engine/core/ECS/EntityManager.h"
|
||||
#include "../../../../engine/platform/glfw/MousePicker.h"
|
||||
|
||||
class Camera;
|
||||
|
||||
class TileHighlightSystem {
|
||||
public:
|
||||
void update(EntityManager &entityManager, const MousePicker &picker, const Camera &camera);
|
||||
void update(EntityManager &entityManager, const MousePicker &picker, const Camera &camera, GameMode& gameMode);
|
||||
private:
|
||||
bool intersectTile(const glm::vec3 & rayOrigin, const glm::vec3 & rayDirection, glm::vec3 worldPos, float hexRadius, glm::vec3 &interectionPoint);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user