Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fog of war #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Barracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Barracks::Barracks(iPoint tile, int damage, j1Module* listener, Entity* creator)
isEntityFromPlayer = true;

isSpawningAUnit = false;

uint visibilityRadius = 5;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);


}

Barracks::~Barracks() {}
Expand Down
3 changes: 3 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Entity::Entity(iPoint tile, int damage, j1Module* listeners, Entity* creator) :
isOnTheMove = false;
isAlive = true;
spawningProgress = 0;

fow_entity = App->fow->CreateFOWEntity(currentTile, true);

}

Entity::~Entity() {
Expand Down
6 changes: 6 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "j1App.h"
#include "j1Audio.h"
#include "j1FogOfWar.h"

class j1Module;

Expand Down Expand Up @@ -156,6 +157,11 @@ class Entity
bool isBuildingSomething;
bool isAlive;

//FOW
FOW_Entity* fow_entity = nullptr;
bool visible = true;
uint visibilityRadius;

Entity* spawnedBy;
Entity* builtBy;

Expand Down
3 changes: 3 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ bool GameScene::Start()

App->player->cricketsRepeat.Start();

App->fow->SetVisibilityMap(App->map->data.width, App->map->data.height);


return ret;
}

Expand Down
6 changes: 6 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/House.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ House::House(iPoint tile, int damage, j1Module* listener, Entity* creator) : Ent
App->player->housingSpace.maxCount += 5;

isEntityFromPlayer = true;

uint visibilityRadius = 5;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);

}

House::~House() {}
2 changes: 2 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Motor2D.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<ClCompile Include="House.cpp" />
<ClCompile Include="j1ButtonUI.cpp" />
<ClCompile Include="j1Collision.cpp" />
<ClCompile Include="j1FogOfWar.cpp" />
<ClCompile Include="j1UIElements.cpp" />
<ClCompile Include="j1EntityManager.cpp" />
<ClCompile Include="j1FontsUI.cpp" />
Expand Down Expand Up @@ -152,6 +153,7 @@
<ClInclude Include="j1ButtonUI.h" />
<ClInclude Include="j1Collision.h" />
<ClInclude Include="j1EntityManager.h" />
<ClInclude Include="j1FogOfWar.h" />
<ClInclude Include="j1FontsUI.h" />
<ClInclude Include="j1UI_Manager.h" />
<ClInclude Include="j1SpritesUI.h" />
Expand Down
6 changes: 6 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Motor2D.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<ClCompile Include="TeamLogoScene.cpp">
<Filter>Motor ========\Scenes</Filter>
</ClCompile>
<ClCompile Include="j1FogOfWar.cpp">
<Filter>Motor ========\Modules</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="j1Window.h">
Expand Down Expand Up @@ -369,6 +372,9 @@
<ClInclude Include="TeamLogoScene.h">
<Filter>Motor ========\Scenes</Filter>
</ClInclude>
<ClInclude Include="j1FogOfWar.h">
<Filter>Motor ========\Modules</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Programacio 2 ===========">
Expand Down
6 changes: 6 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/PaintExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ PaintExtractor::PaintExtractor(iPoint tile, int damage, j1Module* listener, Enti
extractionRate *= 1.33f;

isEntityFromPlayer = true;

uint visibilityRadius = 6;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);

}

PaintExtractor::~PaintExtractor() {}
Expand Down
7 changes: 7 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Painter::Painter(iPoint tile, int damage, j1Module* listener, Entity* creator) :
extractionRate *= 1.33f;

isBuildingSomething = false;

visibilityRadius = 2;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);


}

Painter::~Painter() {}
Expand Down
6 changes: 6 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/TownHall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ TownHall::TownHall(iPoint tile, int damage, j1Module* listener, Entity* creator)
isEntityFromPlayer = true;

isSpawningAUnit = false;

visibilityRadius = 8;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);

}

TownHall::~TownHall() {}
Expand Down
7 changes: 7 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/Warrior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Warrior::Warrior(iPoint tile, int damage, j1Module* listener, Entity* creator) :
attackCooldown = attackSpeed;

isEntityFromPlayer = true;

uint visibilityRadius = 2;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);


}

Warrior::~Warrior() {}
Expand Down
6 changes: 5 additions & 1 deletion PaintWars/Project_II_Game/Motor2D/WoodProducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ WoodProducer::WoodProducer(iPoint tile, int damage, j1Module* listener, Entity*

constructionTime = 10.0f;


uint visibilityRadius = 6;

isEntityFromPlayer = true;

fow_entity->frontier = App->fow->CreateSightQuad(visibilityRadius, fow_entity->position);
fow_entity->LOS = App->fow->FulfillSight(fow_entity->frontier);

}

WoodProducer::~WoodProducer() {}
3 changes: 3 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/j1App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "j1SceneManager.h"
#include "j1QuestManager.h"
#include "j1Window.h"
#include "j1FogOfWar.h"

// Constructor
j1App::j1App(int argc, char* args[]) : argc(argc), args(args)
Expand All @@ -42,6 +43,7 @@ j1App::j1App(int argc, char* args[]) : argc(argc), args(args)
player = new j1Player();
transition_manager = new TransitionManager();
quest_manager = new j1QuestManager();
fow = new j1FogOfWar();


// Ordered for awake / Start / Update
Expand All @@ -61,6 +63,7 @@ j1App::j1App(int argc, char* args[]) : argc(argc), args(args)
AddModule(player);
AddModule(transition_manager);
AddModule(quest_manager);
AddModule(fow);

// render last to swap buffer
AddModule(render);
Expand Down
2 changes: 2 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/j1App.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class j1Player;
class TransitionManager;
class SceneManager;
class j1QuestManager;
class j1FogOfWar;

class j1App
{
Expand Down Expand Up @@ -107,6 +108,7 @@ class j1App
j1FontsUI* fonts = NULL;
TransitionManager* transition_manager = NULL;
j1QuestManager* quest_manager = NULL;
j1FogOfWar* fow = NULL;


private:
Expand Down
21 changes: 21 additions & 0 deletions PaintWars/Project_II_Game/Motor2D/j1EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,27 @@ bool j1EntityManager::Update(float dt) {





// Fog of war update (for active entities)

list<Entity*>::iterator entitiesFoW = activeEntities.begin();
while (entitiesFoW != activeEntities.end()) {

(*entitiesFoW)->fow_entity->is_visible = (*entitiesFoW)->visible;

if ((*entitiesFoW)->isEntityFromPlayer) {
(*entitiesFoW)->fow_entity->SetPos((*entitiesFoW)->currentTile);
}

entitiesFoW++;

}





//if (App->PAUSE_ACTIVE == true) {

// Draw all active entities
Expand Down
Loading