Skip to content

Commit

Permalink
Revert "Revert "Merge branch 'Develop'""
Browse files Browse the repository at this point in the history
This reverts commit ef262cb.
  • Loading branch information
Jordi-Pardo committed Apr 23, 2020
1 parent ef262cb commit fee55c2
Show file tree
Hide file tree
Showing 38 changed files with 519 additions and 151 deletions.
6 changes: 6 additions & 0 deletions Mythology_Parade_Engine/Core/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ std::unordered_map<AnimationType, std::unordered_map<Direction, Animation_char>>
}
animations[type][dir] = LoadAnimation(group, row, sprite_num, name, &charData[s_type]);

if (type == AnimationType::DIE || type == AnimationType::HIT)
{
animations[type][dir].loop = false;
}

group = group.next_sibling("tile");
}
}
Expand Down Expand Up @@ -138,6 +143,7 @@ Animation_char Animation::LoadAnimation(pugi::xml_node& obj_group, int row, int
rect_x += cData->tile_width;
i++;
}

anim.loop = true;

return anim;
Expand Down
32 changes: 18 additions & 14 deletions Mythology_Parade_Engine/Core/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ struct Animation_char

int GetSprite()
{
if (sprites[current_sprite].current_frame != sprites[current_sprite].frames)
if (!finished)
{
sprites[current_sprite].current_frame = sprites[current_sprite].current_frame + 1;
}
else {
sprites[current_sprite].current_frame = 0;
current_sprite++;
}
if (loop) {
if (current_sprite == num_sprites) {
current_sprite = 0;
if (sprites[current_sprite].current_frame != sprites[current_sprite].frames)
{
sprites[current_sprite].current_frame = sprites[current_sprite].current_frame + 1;
}
else {
sprites[current_sprite].current_frame = 0;
current_sprite++;
}
if (loop) {
if (current_sprite == num_sprites) {
current_sprite = 0;
}
}
else if (current_sprite == num_sprites - 1)
{
current_sprite = num_sprites - 1;
finished = true;
}
}
else if (current_sprite == num_sprites) {
current_sprite = num_sprites;
finished = true;
}
return current_sprite;
}
Expand Down
21 changes: 16 additions & 5 deletions Mythology_Parade_Engine/Core/Building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Building::Building(BuildingType type, iPoint pos, BuildingInfo info)
{

position = pos;
position = { (float)pos.x, (float)pos.y};
buildingStatus = CONSTRUCTING;
buildingAction = NOTHING;
time_producing = 0;
Expand Down Expand Up @@ -85,7 +85,7 @@ Building::Building(BuildingType type, iPoint pos, BuildingInfo info)
//buildingType = info.buildingType;
tileLenght = info.tileLenght;

collisionRect = { position.x, position.y + ((App->map->data.tile_height / 2) * tileLenght), blitRect.x, -blitRect.y};
collisionRect = { (int)position.x, (int)position.y + ((App->map->data.tile_height / 2) * tileLenght), blitRect.x, -blitRect.y};

timer_construction.Start();
}
Expand All @@ -106,12 +106,21 @@ void Building::CreateUnit()
case FORTRESS:
break;
case MONASTERY:
App->entityManager->CreateUnitEntity(UnitType::MONK, { position.x - 30,position.y },civilization);
App->entityManager->CreateUnitEntity(UnitType::MONK, { (int)position.x - 30, (int)position.y },civilization);
if (Mix_Playing(4) == 0)
{
App->entityManager->FxUnits(6, App->entityManager->CreateMonk_sound, position.x, position.y);
}
break;
case TEMPLE:
break;
case ENCAMPMENT:
App->entityManager->CreateUnitEntity(UnitType::ASSASSIN, { position.x - 20,position.y },civilization);
App->entityManager->CreateUnitEntity(UnitType::ASSASSIN, { (int)position.x - 20, (int)position.y },civilization);
if(Mix_Playing(4) == 0)
{
App->entityManager->FxUnits(7, App->entityManager->CreateAssasin_sound, position.x, position.y);
}

break;
}
}
Expand All @@ -134,6 +143,7 @@ bool Building::Update(float dt)
buildingStatus = FINISHED;
percentage_constructing = 1;
first_time_constructing = false;

}
else
{
Expand Down Expand Up @@ -243,7 +253,7 @@ bool Building::Draw(float dt)
void Building::Draw_Construction_Bar(int blitWidth, int bar_used)
{
SDL_Rect construction_spriteRect = App->entityManager->construction_bar_back;
iPoint pos = { position.x + (int)(0.15 * blitWidth),position.y + (int)(((32 / 2) * tileLenght) - 1.25 * blitRect.y) };
iPoint pos = { (int)position.x + (int)(0.15 * blitWidth), (int)position.y + (int)(((32 / 2) * tileLenght) - 1.25 * blitRect.y) };
App->render->Blit(texture, pos.x, pos.y, &construction_spriteRect);
if (bar_used == 0)
construction_spriteRect = App->entityManager->construction_bar_front;
Expand All @@ -265,6 +275,7 @@ void Building::StartProducing(int time, std::string thing_producing) {
time_producing = time;
element_producing = thing_producing;
timer_construction.Start();

}

void Building::FinishProduction(std::string thing_produced)
Expand Down
9 changes: 5 additions & 4 deletions Mythology_Parade_Engine/Core/CombatUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CombatUnit::CombatUnit(UnitType type, iPoint pos) : Unit(type, pos), range(0), d
{
//TODO 10: Change textures
unitType = type;
position = pos;
position = {(float)pos.x, (float)pos.y};
switch (unitType)
{
case UnitType::ASSASSIN:
Expand All @@ -14,15 +14,15 @@ CombatUnit::CombatUnit(UnitType type, iPoint pos) : Unit(type, pos), range(0), d
researched = true;
//Change texture
LevelSystem::Init(3500, 6500, 9500);
CombatUnit::Init(100, 15, 1, 4);
CombatUnit::Init(100, 15, 1, 80);
break;
case UnitType::PIKEMAN:
time_production = 90;
time_research = 70;
researched = false;
//Change Texture
LevelSystem::Init(3000, 6000, 9500);
CombatUnit::Init(110, 25, 1, 2);
CombatUnit::Init(110, 25, 1, 40);
break;
case UnitType::EXPLORER:
break;
Expand Down Expand Up @@ -101,7 +101,8 @@ void CombatUnit::Init(int maxHealth, int damage, int range, int speed)

bool CombatUnit::Update(float dt)
{
//Unit::Update(dt);
Unit::Update(dt);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Mythology_Parade_Engine/Core/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Entity :public j1Module
EntityType type;

SDL_Texture* texture; //Change it to Character_TMX
iPoint position;
fPoint position;

//Rect in the spritesheet
SDL_Rect spriteRect;
Expand Down
93 changes: 76 additions & 17 deletions Mythology_Parade_Engine/Core/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ bool EntityManager::Awake(pugi::xml_node& a)
}
active = false;

//LoadingFX
Building_destruction = App->audio->LoadFx("audio/fx/Building_destruction.wav");
Building_placed = App->audio->LoadFx("audio/fx/BuildingPlaced.wav");
Decrease_Faith = App->audio->LoadFx("audio/fx/Descrease_FAITH.wav");
Getting_resources = App->audio->LoadFx("audio/fx/Getting_Resources.wav");
hit_1 = App->audio->LoadFx("audio/fx/hit_1.wav");
increase_prayers = App->audio->LoadFx("audio/fx/Increase_prayers.wav");
increase_sacrifice = App->audio->LoadFx("audio/fx/Increase_sacrifice.wav");
Walking_troops = App->audio->LoadFx("audio/fx/Walking_troop.wav");
CreateMonk_sound = App->audio->LoadFx("audio/fx/Appear_monk.wav");
CreateAssasin_sound = App->audio->LoadFx("audio/fx/Appear_assasin.wav");
Research_sound = App->audio->LoadFx("audio/fx/Research_Sound.wav");

return true;
}

Expand All @@ -74,7 +87,7 @@ bool EntityManager::Start()

void EntityManager::LoadBuildingsBlitRect()
{
for (int i = 0; i < buildingsData.size(); i++)
for (unsigned int i = 0; i < buildingsData.size(); i++)
{
BuildingInfo* info = &buildingsData[i];
int blitWidth = info->tileLenght * App->map->data.tile_width;
Expand Down Expand Up @@ -192,17 +205,6 @@ bool EntityManager::Update(float dt)
break;
}

for (int y = mouse.y; y > mouse.y - crPreview.height; y--)
{
for (int x = mouse.x; x < mouse.x + crPreview.width; x++)
{

if (IN_RANGE(x, 0, App->map->data.width - 1) == 1 && IN_RANGE(y, 0, App->map->data.height - 1) == 1)
{
App->pathfinding->ChangeMapValue({x, y}, 0);
}
}
}
//Onces you build disable building mode
App->entityManager->getPlayer()->DecreaseFaith(faithToDescrease);
crPreview.active = false;
Expand Down Expand Up @@ -231,18 +233,18 @@ bool EntityManager::CleanUp()
}
entities[(EntityType)i].clear();
}
for (int i = 0; i < entitySpriteSheets.size(); i++)
for (unsigned int i = 0; i < entitySpriteSheets.size(); i++)
{
if(entitySpriteSheets[(SpriteSheetType)i])
App->tex->UnLoad(entitySpriteSheets[(SpriteSheetType)i]);
}
entities.clear();

for (int i = 0; i < animations.size(); i++)
for (unsigned int i = 0; i < animations.size(); i++)
{
for (int k = 0; k < animations[(UnitType)i].size(); k++)
for (unsigned int k = 0; k < animations[(UnitType)i].size(); k++)
{
for (int j = 0; j < animations[(UnitType)i][(AnimationType)k].size(); j++)
for (unsigned int j = 0; j < animations[(UnitType)i][(AnimationType)k].size(); j++)
{
animations[(UnitType)i][(AnimationType)k][(Direction)j].Clean();
}
Expand Down Expand Up @@ -439,6 +441,24 @@ Entity* EntityManager::CreateBuildingEntity(iPoint pos, BuildingType type, Build
ret = new Building(BuildingType::ENCAMPMENT, pos, info);
break;
}


iPoint iso = pos;
iso += App->map->GetTilesHalfSize();
iso = App->map->WorldToMap(iso.x, iso.y);

for (int y = iso.y; y > iso.y - info.tileLenght; y--)
{
for (int x = iso.x; x < iso.x + info.tileLenght; x++)
{

if (IN_RANGE(x, 0, App->map->data.width - 1) == 1 && IN_RANGE(y, 0, App->map->data.height - 1) == 1)
{
App->pathfinding->ChangeMapValue({ x, y }, 0);
}
}
}

ret->civilization = civilization;
ret->type = EntityType::BUILDING;
ret->texture = entitySpriteSheets[SpriteSheetType::BUILDINGS];
Expand Down Expand Up @@ -545,14 +565,53 @@ void EntityManager::LoadBuildingsData(pugi::xml_node& node)
buildingsData.push_back(info);
}
}


}

iPoint EntityManager::CalculateBuildingSize(int bw, int w, int h)
{
return {bw , (bw * h) / w};
}

Player* EntityManager::getPlayer()
Player* EntityManager::getPlayer() const
{
return (Player*)App->entityManager->entities[EntityType::PLAYER].begin()._Ptr->_Myval;
}

bool EntityManager::IsPointInsideQuad(SDL_Rect rect, int x, int y)
{

if (x >= rect.x && x <= rect.x + rect.w && y >= rect.y + rect.h && y <= rect.y)
return true;

return false;
}

void EntityManager::FxUnits(int channel, int fx, int posx, int posy)
{
Mix_Playing(channel);
Mix_HaltChannel(channel);

int distance = ((posx - App->render->camera.x * App->render->camera.x) + (posy - App->render->camera.y * App->render->camera.y));
distance = distance;
int volume = (distance * 2000) / App->render->camera.w;
if (volume < 0) {
volume = 0;
}
if (volume > 200) {
volume = 200;
}

float angle = 90;
if (App->render->camera.y == 0) {
angle = atan(-App->render->camera.x);
}
else {
angle = atan((-App->render->camera.x) / (App->render->camera.y));
}
angle = angle * 57 + 360;

Mix_SetPosition(channel, angle, volume);
App->audio->PlayFx(channel, fx, 0);
}
20 changes: 19 additions & 1 deletion Mythology_Parade_Engine/Core/EntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include"j1Input.h"
#include"j1Map.h"
#include"j1Pathfinding.h"
#include"j1Audio.h"

#include<vector>
#include <algorithm>
Expand Down Expand Up @@ -117,7 +118,9 @@ class EntityManager : public j1Module

void LoadBuildingsBlitRect();

Player* getPlayer();
Player* getPlayer() const;

static bool IsPointInsideQuad(SDL_Rect rect, int x, int y);

public:

Expand All @@ -128,6 +131,8 @@ class EntityManager : public j1Module
//The way to store the spritesheets
std::unordered_map<SpriteSheetType, SDL_Texture*> entitySpriteSheets;
std::vector<BuildingInfo> buildingsData;
void FxUnits(int channel, int fx, int posx, int posy);
int volume;

private:
int buildingTestIndex = 0;
Expand All @@ -144,5 +149,18 @@ class EntityManager : public j1Module

std::unordered_map<UnitType, std::unordered_map<AnimationType, std::unordered_map<Direction, Animation_char>>> animations;

int Building_destruction;
int Building_placed;
int Decrease_Faith;
int Getting_resources;
int hit_1;
int Increase_faith;
int increase_prayers;
int increase_sacrifice;
int Walking_troops;
int CreateMonk_sound;
int CreateAssasin_sound;
int Research_sound;

};
#endif // !_ENTITYMANAGER_H
3 changes: 2 additions & 1 deletion Mythology_Parade_Engine/Core/HealthSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void HealthSystem::Init()
health = maxHealth;
}

void HealthSystem::RecieveDamage(int value)
bool HealthSystem::RecieveDamage(int value)
{
if (!App->scene->godMode)
{
Expand All @@ -18,6 +18,7 @@ void HealthSystem::RecieveDamage(int value)
if (health <= 0)
isDeath = true;
}
return isDeath;
}
int HealthSystem::GetHealth()
{
Expand Down
2 changes: 1 addition & 1 deletion Mythology_Parade_Engine/Core/HealthSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct HealthSystem
void Init();

//Function to substract health from enemy attack
void RecieveDamage(int value);
bool RecieveDamage(int value);

//Getters
int GetHealth();
Expand Down
Loading

0 comments on commit fee55c2

Please sign in to comment.