Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
48 KB
Referenced Files
None
Subscribers
None
diff --git a/assets/audio/menu.ogg b/assets/audio/menu.ogg
index 3fb1b3a..1988ff7 100644
Binary files a/assets/audio/menu.ogg and b/assets/audio/menu.ogg differ
diff --git a/assets/img/background_land.png b/assets/img/background_land.png
index 24ac73d..da0aaeb 100644
Binary files a/assets/img/background_land.png and b/assets/img/background_land.png differ
diff --git a/boarddiamondseq.cpp b/boarddiamondseq.cpp
index 6807939..62881a1 100644
--- a/boarddiamondseq.cpp
+++ b/boarddiamondseq.cpp
@@ -1,136 +1,136 @@
#include "boarddiamondseq.h"
BoardDiamondSeq::BoardDiamondSeq(TextureHolder *textures)
{
this->textures = textures;
for (int i=0; i<efc::diamondsNumber; i++)
{
diamonds[i] = BoardDiamond(this->textures,
efc::DIAMONDS_SETUP[i][0],
efc::DIAMONDS_SETUP[i][1],
efc::DIAMONDS_SETUP[i][2]);
}
reorder();
}
void BoardDiamondSeq::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
for (int i=0; i<efc::diamondsNumber; i++)
{
target.draw(diamonds[i],states);
}
}
std::array<int,efc::diamondsNumber> BoardDiamondSeq::getBoardPositions()
{
std::array<int, efc::diamondsNumber> results;
for (int i=0; i<efc::diamondsNumber; i++)
{
results[i] = diamonds[i].getBoardPosition();
}
return results;
}
bool BoardDiamondSeq::ifFieldIsEmpty(int pos, int element)
{
- for (int i=element*14;i<(efc::diamondsNumber/4)+(element*14);i++)
+ for (int i=element*efc::diamondsNumber/4;i<(efc::diamondsNumber/4)+(element*efc::diamondsNumber/4);i++)
{
if (diamonds[i].boardPosition==pos)
return false;
}
return true;
}
bool BoardDiamondSeq::ifFieldIsEmpty(int pos)
{
for (int element=0;element<4;element++)
{
- for (int i=element*14;i<(efc::diamondsNumber/4)+(element*14);i++)
+ for (int i=element*efc::diamondsNumber/4;i<(efc::diamondsNumber/4)+(element*efc::diamondsNumber/4);i++)
{
if (diamonds[i].boardPosition==pos)
return false;
}
}
return true;
}
int BoardDiamondSeq::getRandomPos(int playerNumber)
{
std::set<int> setSteps(efc::occupiedFields[playerNumber].cbegin(), efc::occupiedFields[playerNumber].cend());
- for (int i=playerNumber*14;i<(efc::diamondsNumber/4)+(playerNumber*14);i++)
+ for (int i=playerNumber*efc::diamondsNumber/4;i<(efc::diamondsNumber/4)+(playerNumber*efc::diamondsNumber/4);i++)
{
if (diamonds[i].boardPosition!=-1)
{
setSteps.erase(diamonds[i].boardPosition);
}
}
int step = rand()%setSteps.size();
std::vector<int> freePositions;
freePositions.resize(setSteps.size());
freePositions.assign(setSteps.begin(),setSteps.end());
return freePositions[step];
}
void BoardDiamondSeq::reorder()
{
srand((unsigned)time(0));
for (int element=0;element<4;element++)
{
int start = element;
- for (int i=start*14;i<(efc::diamondsNumber/4)+(start*14);i++)
+ for (int i=start*efc::diamondsNumber/4;i<(efc::diamondsNumber/4)+(start*efc::diamondsNumber/4);i++)
{
int step = getRandomPos(element);
diamonds[i].setBoardPosition(step);
}
}
}
void BoardDiamondSeq::reorder(int element)
{
srand((unsigned)time(0));
int start = element;
if (element==2)
start = 3;
else if (element==3)
start = 2;
int newElement = start;
- for (int i=start*14;i<(efc::diamondsNumber/4)+(start*14);i++)
+ for (int i=start*efc::diamondsNumber/4;i<(efc::diamondsNumber/4)+(start*efc::diamondsNumber/4);i++)
{
int step = getRandomPos(newElement);
diamonds[i].setBoardPosition(step);
}
}
void BoardDiamondSeq::collectField(int pos)
{
for (int i=0; i<efc::diamondsNumber; i++)
{
if (diamonds[i].boardPosition==pos)
{
diamonds[i].setBoardPosition(-1);
break;
}
}
}
int BoardDiamondSeq::getNumberForField(int pos)
{
for (int i=0; i<efc::diamondsNumber; i++)
{
if (diamonds[i].boardPosition==pos)
{
return diamonds[i].idNumber;
}
}
return -1;
}
diff --git a/cardsdeck.cpp b/cardsdeck.cpp
index 170a942..b06cd5b 100644
--- a/cardsdeck.cpp
+++ b/cardsdeck.cpp
@@ -1,100 +1,100 @@
#include "cardsdeck.h"
CardsDeck::CardsDeck(TextureHolder *textures, sf::Font *gameFont)
{
std::array<std::array<int,2>,4> cardsPos = {
{
{1087,95}, {1225, 95}, {1225, 277}, {1087, 277}
}
};
this->textures = textures;
for (int i=0;i<=3;i++)
{
spriteCardBases[i].setTexture(this->textures->textureCardBases[i]);
spriteCardBases[i].setPosition(cardsPos[i][0],cardsPos[i][1]);
textPileTitle[i].setFont(*gameFont);
textPileTitle[i].setCharacterSize(10);
textPileTitle[i].setPosition(cardsPos[i][0]+10,cardsPos[i][1]+100);
for (int j=0;j<efc::PILE_SIZE;j++)
{
cardsList[i].cardsPile[j].cardType = efc::cardsTypes[j];
}
setTitles();
}
}
void CardsDeck::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
for (int i=0;i<=3;i++)
{
if (cardsList[i].invisibleLeft==0.0f)
{
target.draw(spriteCardBases[i], states);
target.draw(textPileTitle[i], states);
}
}
}
void CardsDeck::setTitles()
{
for (int i=0;i<=3;i++)
{
textPileTitle[i].setString(getTitle(i));
}
}
void CardsDeck::setFonts(sf::Font *gameFont)
{
for (int i=0;i<=3;i++)
{
textPileTitle[i].setFont(*gameFont);
}
}
void CardsDeck::nextCard(int pileNumber)
{
- cardsList[pileNumber].invisibleLeft = 1.0f;
+ cardsList[pileNumber].invisibleLeft = 0.75f;
int currentCard = getCurrentCard(pileNumber);
currentCard += 1;
if (currentCard>efc::PILE_SIZE-1)
currentCard = 0;
cardsList[pileNumber].currentCard = currentCard;
setTitles();
}
int CardsDeck::getCurrentCard(int pileNumber)
{
int currentCard = cardsList[pileNumber].currentCard;
return currentCard;
}
std::string CardsDeck::getTitle(int pileNumber)
{
std::string currentText = cardsList[pileNumber].cardsPile[getCurrentCard(pileNumber)].cardType;
return currentText;
}
void CardsDeck::update(sf::Time deltaTime)
{
for (int i=0;i<=3;i++)
{
if (cardsList[i].invisibleLeft>0.0f)
{
cardsList[i].invisibleLeft -= deltaTime.asSeconds();
}
if (cardsList[i].invisibleLeft<0.0f)
{
cardsList[i].invisibleLeft = 0.0f;
}
}
}
diff --git a/character.cpp b/character.cpp
index 73de763..c3e3d9f 100644
--- a/character.cpp
+++ b/character.cpp
@@ -1,321 +1,306 @@
#include "character.h"
/*!
* \brief Character::getMovements
* \return
*/
std::array<int,2> Character::getMovements(int howFar)
{
std::array<int,2> myArray;
if (howFar==7)
{
return std::array<int,2> {-1,-1};
}
if (active==true)
{
// std::cout << "howfar: " <<howFar <<std::endl;
-
-
-
int indexRight = boardPosition;
for (int i=boardPosition;i<=boardPosition+howFar-1;i++)
{
+ moveRight = indexRight;
if (indexRight==-1)
break;
indexRight = efc::boards[indexRight][1];
// std::cout << " howfar" << howFar << " index R" << indexRight
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
+ if (indexRight==-2)
+ {
+ indexRight = moveRight;
+ break;
+ }
+
if (indexRight==-1)
break;
}
moveRight = indexRight;
-
-
int indexLeft = boardPosition;
for (int i=boardPosition;i>=boardPosition-howFar+1;i--)
- { if (indexLeft==-1)
+ {
+ moveLeft = indexLeft;
+
+ if (indexLeft==-1)
break;
indexLeft = efc::boards[indexLeft][0];
// std::cout << " howfar" << howFar << " index l " << indexLeft
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
+ if (indexLeft==-2)
+ {
+ indexLeft = moveLeft;
+ break;
+ }
if (indexLeft==-1)
break;
}
moveLeft = indexLeft;
myArray = {moveLeft,moveRight};
}
else
{
myArray = {-1,-1};
}
// std::cout << "howfar: " <<howFar << std::endl;
return myArray;
}
void Character::setDir(int direction)
{
if (direction==efc::DIR_LEFT)
currentAnimation = &walkingAnimationLeft;
}
void Character::setDir()
{
setDir(currentAnimationIndex);
}
void Character::setDirIndex(int direction)
{
currentAnimationIndex = direction;
}
void Character::play()
{
// animatedSprite.play(*currentAnimation);
animatedSprite.play(animations[currentAnimationIndex]);
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
// std::cout << a.x << " " << a.y << " "
// << position.x << " " << position.y << " pos > "
// << getBoardPosition() << std::endl;
}
Character::Character(TextureHolder *textures, int playerNumber):
animatedSprite(sf::seconds(0.2), true, false),
nextRedirect(0.f)
{
drawMovements = false;
this->textures = textures;
int offset = playerNumber*16;
active = false;
rectangleLeft.setFillColor(sf::Color(12, 12, 12,120));
rectangleLeft.setOutlineColor(sf::Color(24,24,40, 255));
rectangleRight.setFillColor(sf::Color(240, 240, 240,98));
rectangleRight.setOutlineColor(sf::Color(24,40,24, 90));
walkingAnimationDown.setSpriteSheet(textures->textureCharacters);
walkingAnimationDown.addFrame(sf::IntRect(offset, 0, 16, 24));
walkingAnimationDown.addFrame(sf::IntRect(offset, 24, 16, 24));
walkingAnimationRight.setSpriteSheet(textures->textureCharacters);
walkingAnimationRight.addFrame(sf::IntRect(offset, 48, 16, 24));
walkingAnimationRight.addFrame(sf::IntRect(offset, 72, 16, 24));
walkingAnimationLeft.setSpriteSheet(textures->textureCharacters);
walkingAnimationLeft.addFrame(sf::IntRect(offset, 96, 16, 24));
walkingAnimationLeft.addFrame(sf::IntRect(offset, 120, 16, 24));
walkingAnimationUp.setSpriteSheet(textures->textureCharacters);
walkingAnimationUp.addFrame(sf::IntRect(offset, 144, 16, 24));
walkingAnimationUp.addFrame(sf::IntRect(offset, 168, 16, 24));
currentAnimation = &walkingAnimationRight;
leftChar.setTexture(textures->textureCharacters);
leftChar.setTextureRect(sf::IntRect(offset, 96, 16, 24));
rightChar.setTexture(textures->textureCharacters);
rightChar.setTextureRect(sf::IntRect(offset, 48, 16, 24));
leftChar.scale(0.75,0.75);
rightChar.scale(0.75,0.75);
animations[efc::DIR_LEFT] = walkingAnimationLeft;
animations[efc::DIR_RIGHT] = walkingAnimationRight;
animations[efc::DIR_UP] = walkingAnimationUp;
animations[efc::DIR_DOWN] = walkingAnimationDown;
setDirIndex(efc::DIR_LEFT);
setDir();
// sf::Vector2f positions[4] = {
// sf::Vector2f(0, 0),
// sf::Vector2f(20, 40),
// sf::Vector2f(20, 240),
// sf::Vector2f(40, 240)
// };
std::array<int, 4> boardPositions{0,15,255-15,255};
// std::cout << "define " << playerNumber << std::endl;
setBoardPosition(boardPositions[playerNumber]);
}
void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(animatedSprite, states);
if ((active==true) && (drawMovements==true))
{
if (moveLeft>-1)
{
-// std::cout << "draw " << rectangleLeft.getPosition().x << " " << rectangleLeft.getPosition().y << std::endl;
-
target.draw(leftChar);
-
}
if (moveRight>-1)
{
-// std::cout << "draw R" << rectangleRight.getPosition().x << " " << rectangleRight.getPosition().y << std::endl;
-
-
target.draw(rightChar);
-
- // target.draw(rectangleRight, 4, sf::Quads, states);
-
}
}
-
-
-
-
}
void Character::update(sf::Time deltaTime)
{
-
-
-
-
-
-
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
-
-// int charPos = efc::transCords(position);
-
-// std::cout << a.x << " " << a.y << " " << position.x << " " << position.y << " " << charPos << std::endl;
-
nextRedirect -= deltaTime.asSeconds();
-
if (nextRedirect<0)
{
int number = rand() % 2;
if ((currentAnimationIndex==efc::DIR_LEFT) || (currentAnimationIndex==efc::DIR_RIGHT))
{
if (number==0){
setDirIndex(efc::DIR_DOWN);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if ((currentAnimationIndex==efc::DIR_UP) || (currentAnimationIndex==efc::DIR_DOWN))
{
if (number==0){
setDirIndex(efc::DIR_LEFT);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
}
nextRedirect = rand() % 4;
}
if (currentAnimationIndex==efc::DIR_UP)
{
if (position.y<2)
{
setDirIndex(efc::DIR_DOWN);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_DOWN)
{
if (position.y>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_LEFT)
{
if (position.x<2)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_RIGHT)
{
if (position.x>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_LEFT);
setDir();
}
}
animatedSprite.update(deltaTime);
std::array<int,2> movements(getMovements(diceResult));
// int left = movements[0];
// int right = movements[1];
if (active==true)
{
if (moveLeft>-1)
{
- sf::Vector2i cordsLeft(efc::transPosition(moveLeft));
+// sf::Vector2i cordsLeft(efc::transPosition(moveLeft));
sf::Vector2i neededCords(efc::transPosition(moveLeft));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
leftChar.setPosition(newPos.x+efc::TILE_SIZE/4,newPos.y);
}
if (moveRight>-1)
{
- sf::Vector2i cordsRight(efc::transPosition(moveRight));
+// sf::Vector2i cordsRight(efc::transPosition(moveRight));
sf::Vector2i neededCords(efc::transPosition(moveRight));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
rightChar.setPosition(newPos.x+efc::TILE_SIZE/4,newPos.y);
}
// std::cout << " dice " << diceResult<< moveLeft << " " << moveRight << std::endl;
}
}
sf::FloatRect Character::getLocalBounds() const
{
return sf::FloatRect(0.f, 0.f, 0, 0);
}
sf::FloatRect Character::getGlobalBounds() const
{
return getTransform().transformRect(getLocalBounds());
}
diff --git a/data.cpp b/data.cpp
index 66c1c47..bf0979c 100644
--- a/data.cpp
+++ b/data.cpp
@@ -1,141 +1,162 @@
#include <data.h>
namespace efc {
std::string seasonsNames[4] = {"winter", "spring", "summer", "fall"};
// This array defines fields occupied by the river
int terrainArray[24] = {
8, 24, 40, 56, 72, 88,
113, 114, 115, 116, 117, 118,
138, 139, 140, 141, 142, 143,
167, 183, 199, 215, 231, 247
};
/*
* 0
* 16
* 32
* 48
* 64
* 80
* 96
* 112
* 128
* 144
* 160
* 176
* 192
*/
-int possibleExits[4] = {119,120,135,136};
std::array<std::array<int,2>,256> boards = {
{
{-1,1}, {0,2}, {1,3}, {2,4}, {3,5}, {4,21}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {11,26}, {12,10}, {13,11}, {14,12}, {15,13}, {-1,14},
{-1,-1}, {18,33}, {19,17}, {20,18}, {21,19}, {5,20}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {10, 27,}, {26,28}, {27,29}, {28,30}, {29,46}, {-1,-1},
{33,48}, {17,32}, {-1,-1}, {51,36}, {35,37}, {36,38}, {37,54}, {-1,-1}, {-1,-1}, {-1,-1}, {43,58}, {44,42}, {60,43}, {-1,-1}, {30,47}, {46,63},
{32,49}, {48,50}, {49,51}, {50,35}, {-1,-1}, {54,69}, {38,53}, {-1,-1}, {-1,-1}, {58,73}, {42,57}, {-1,-1}, {61,44}, {62,60}, {63,61}, {47,62},
{65,80}, {66,64}, {67,65}, {68,66}, {69,67}, {53,68}, {-1,-1}, {-1,-1}, {-1,-1}, {57,74}, {73,75}, {74,76}, {75,77}, {76,78}, {77,79}, {78,95},
{64,81}, {80,97}, {-1,-1}, {99,84}, {83,85}, {84,101}, {-1,-1}, {-1,-1}, {-1,-1}, {90,105}, {91,89}, {92,90}, {108,91}, {-1,-1}, {95,110}, {79,94},
{-1,-1}, {81,98}, {97,99}, {98,83}, {-1,-1}, {85,102}, {101,118}, {-1,-1}, {105,120}, {89,104}, {-1,-1}, {-1,-1}, {109,92}, {110,108}, {94,109}, {-1,-1},
- {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {102, 119},{118,-1}, {104,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
- {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1} , {151,-1}, {137,-1}, {153,136}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
+ {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {102, 119},{118,-2}, {104,-2}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
+ {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1} , {151,-2}, {137,-2}, {153,136}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
{-1,-1}, {161,146}, {145,147}, {146,163}, {-1,-1}, {-1,-1}, {166,151}, {150,135} ,{-1,-1}, {154,137}, {170,153}, {-1,-1}, {157,172}, {158,156}, {174,157}, {-1,-1},
{176,161},{160,145}, {-1,-1}, {147,164}, {163,165}, {164,166}, {165,150}, {-1,-1}, {-1,-1}, {-1,-1}, {171,154}, {172,170}, {156,171}, {-1,-1}, {175,158}, {191,174},
{177,160},{178,176}, {179,177}, {180,178}, {181,179}, {182,180}, {198,181}, {-1,-1}, {-1,-1}, {-1,-1}, {202,187}, {186,188}, {187,189}, {188,190}, {189,191}, {190,175},
{208,193},{192,194}, {193,195}, {194,211}, {-1,-1}, {213,198}, {197,182}, {-1,-1}, {-1,-1}, {217,202}, {201,186}, {-1,-1}, {205,220}, {206,204}, {207,205}, {223,206},
{209,192},{225,208}, {-1,-1}, {195,212}, {211,213}, {212,197}, {-1,-1}, {-1,-1}, {-1,-1}, {218,201}, {219,217}, {220,218}, {204,219}, {-1,-1}, {238,223}, {222,207},
{-1,-1}, {226,209}, {227,225}, {228,226}, {229,227}, {245,228}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {250,235}, {234,236}, {235,237}, {236,238}, {237,222}, {-1,-1},
{-1,241}, {240,242},{241,243}, {242,244}, {243,245}, {244,229}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {251,234}, {252,250}, {253,251}, {254,252}, {255,253}, {-1,254},
},
};
std::array<std::array<int,numberSteps>,4> occupiedFields =
{
{
{1,2,3,4,5,17,18,19,20,21,32,33,35,36,37,38,48,49,50,51,53,54,64,65,66,67,68,69,80,81,83,84,85,97,98,99,101,102,118},
{10,11,12,13,14,26,27,28,29,30,42,43,44,46,47,57,58,60,61,62,63,73,74,75,76,77,78,79,89,90,91,92,94,95,104,105,108,109,110},
{145,146,147,150,151,160,161,163,164,165,166,176,177,178,179,180,181,182,192,193,194,195,197,198,208,209,211,212,213,225,226,227,228,229,241,242,243,244,245},
{137,153,154,156,157,158,170,171,172,174,175,186,187,188,189,190,191,201,202,204,205,206,207,217,218,219,220,222,223,234,235,236,237,238,250,251,252,253,254}
}
};
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//{167,809}, {183, 803}, {199, 803}, {215, 803}, {231, 803} ,{247, 8},
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//level[8] = 813;
//level[24] = 803;
//level[40] = 803;
//level[56] = 803;
//level[72] = 803;
//level[88] = 801;
//level[167] = 809;
//level[183] = 803;
//level[199] = 803;
//level[215] = 803;
//level[231] = 803;
//level[247] = 812;
//level[112] = 811;
//for (int i=113;i<117;i++)
// level[i] = 816;
//level[117] = 815;
//level[138] = 800;
//for (int i=139;i<143;i++)
// level[i] = 816;
//level[143] = 814;
// Colors for the board elements
//sf::Color playersColors[4] = {
// sf::Color(0, 150,255,255),
// sf::Color(50, 230,50,255),
// sf::Color(230, 50,50,255),
// sf::Color(150, 150,150,255)
//};
sf::Color playersColors[4] = {
sf::Color(122, 185,246,255),
sf::Color(144, 226,106,255),
sf::Color(255, 163,142,255),
sf::Color(250, 255,117,255),
};
std::array<std::array<int,3>,efc::diamondsNumber> DIAMONDS_SETUP =
{
{
{0,0,-1},{0,0,-1},
{1,0,-1},{1,0,-1},
{2,0,-1},{2,0,-1},
{3,0,-1},{3,0,-1},
{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},
+ {0,0,-1},{0,0,-1},
+ {1,0,-1},{1,0,-1},
+ {2,0,-1},{2,0,-1},
+ {3,0,-1},{3,0,-1},
+ {4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},
{0,1,-1},{0,1,-1},
{1,1,-1},{1,1,-1},
{2,1,-1},{2,1,-1},
{3,1,-1},{3,1,-1},
{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},
+ {0,1,-1},{0,1,-1},
+ {1,1,-1},{1,1,-1},
+ {2,1,-1},{2,1,-1},
+ {3,1,-1},{3,1,-1},
+ {4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},
+
{0,3,-1},{0,3,-1},
{1,3,-1},{1,3,-1},
{2,3,-1},{2,3,-1},
{3,3,-1},{3,3,-1},
{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},
+ {0,3,-1},{0,3,-1},
+ {1,3,-1},{1,3,-1},
+ {2,3,-1},{2,3,-1},
+ {3,3,-1},{3,3,-1},
+ {4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},
+
{0,2,-1},{0,2,-1},
{1,2,-1},{1,2,-1},
{2,2,-1},{2,2,-1},
{3,2,-1},{3,2,-1},
{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},
+ {0,2,-1},{0,2,-1},
+ {1,2,-1},{1,2,-1},
+ {2,2,-1},{2,2,-1},
+ {3,2,-1},{3,2,-1},
+ {4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},
}
} ;
}
diff --git a/data.h b/data.h
index 4f87106..9e68566 100644
--- a/data.h
+++ b/data.h
@@ -1,46 +1,47 @@
#ifndef DATA_H
#define DATA_H
#include <map>
#include <string>
#include <string>
#include <SFML/Graphics.hpp>
namespace efc {
extern std::string seasonsNames[4];
enum directions {
DIR_LEFT,
DIR_RIGHT,
DIR_UP,
DIR_DOWN
};
enum cardType {
FREEZE,
COLLECT_DIAMOND
};
extern int terrainArray[24];
extern sf::Color playersColors[4];
extern std::array<std::array<int,2>,256> boards;
extern int possibleExits[4]; // number of portal's exit where player stops to play
- const static int diamondsNumber = 56; // number of all cards / diamonds on the board
+ const static int diamondsNumber = 112; // number of all cards / diamonds on the board
extern std::array<std::array<int,3>,efc::diamondsNumber> DIAMONDS_SETUP;
extern std::array<std::array<int,39>,4> occupiedFields;
const static int numberSteps = 39;
const static int startPlayers[4] = {0,15,255,240};
+ const static int endPlayers[4] = {119,120,135,136};
const static std::map<std::string, std::string> cardTypes = {
{"stop", "Freezes a player for the one turn time"},
{"diamond", "Collect a diamond from the player area"},
{"card", "Collect a card from the player area"},
};
}
#endif // DATA_H
diff --git a/game.cpp b/game.cpp
index a161835..b6bc9c7 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,613 +1,613 @@
#include "game.h"
namespace efc {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 1;
int month = 0;
void Game::initBoard()
{
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
spriteBackground.setTexture(textureBackground);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
gameBackground.setTexture(textures.textureGameBackground);
spriteLestBegin.setTexture(textures.textureLetsBegin);
viewTiles.setViewport(sf::FloatRect(0.15f,0.1f, 1.0f, 1.0f));
viewGui.setViewport(sf::FloatRect(0.806f,0.066f, 1, 1));
groupHud.setFont(&gameFont);
groupHud.setSeason(currentSeason);
groupHud.setRoundName(roundNumber);
sf::IntRect seasonsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
sf::Sprite season1;
season1.setTexture(textures.textureSeasons);
season1.setTextureRect(seasonsRect[0]);
season1.setPosition(0,400);
season1.scale(sf::Vector2f(0.25f, 0.25f));
season1.move(37.5, 30.5);
season1.setColor(sf::Color(0,255,0,80));
seasons[0] = season1;
sf::Sprite season2;
season2.setTexture(textures.textureSeasons);
season2.setTextureRect(seasonsRect[1]);
season2.setPosition(0,400);
season2.scale(sf::Vector2f(0.25f, 0.25f));
season2.move(37.5, 30.5);
season2.setColor(sf::Color(200,200,50,80));
seasons[1] = season2;
sf::Sprite season3;
season3.setTexture(textures.textureSeasons);
season3.setTextureRect(seasonsRect[2]);
season3.setPosition(0,400);
season3.scale(sf::Vector2f(0.25f, 0.25f));
season3.move(37.5, 30.5);
season3.setColor(sf::Color(90,90,255,80));
seasons[2] = season3;
sf::Sprite season4;
season4.setTexture(textures.textureSeasons);
season4.setTextureRect(seasonsRect[3]);
season4.setPosition(0,400);
season4.scale(sf::Vector2f(0.25f, 0.25f));
season4.move(37.5, 30.5);
season4.setColor(sf::Color(255,0,0,80));
seasons[3] = season4;
// Initialization of the players
cardsDeck.setFonts(&menuFont);
PlayerHud playerHud1(&textures, &gameFont, 32,0);
PlayerHud playerHud2(&textures, &gameFont, 32,1);
PlayerHud playerHud3(&textures, &gameFont, 32,2);
PlayerHud playerHud4(&textures, &gameFont, 32,3);
players[0] = playerHud1;
players[1] = playerHud2;
players[3] = playerHud3;
players[2] = playerHud4;
players[0].setActive(true);
setCurrentNeighbours();
diceResultPlayer = 6;
players[turn].characters[0].diceResult = diceResultPlayer;
roundDice.setColor(turn);
}
void Game::setCurrentNeighbours ()
{
currentNeighbours = players[turn].getNeighbours();
}
void Game::loadAssets()
{
// if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
// std::exit(1);
// if (!textureTiles.loadFromFile("assets/img/zw-tilesets/_MAP.png"))
// std::exit(1);
if (!gameFont.loadFromFile("assets/fnt/metal-mania.regular.ttf"))
{
std::exit(1);
}
if (!menuFont.loadFromFile("assets/fnt/metal-macabre.regular.ttf"))
{
std::exit(1);
}
if (!textureBackgroundArt.loadFromFile("assets/img/background_land.png"))
std::exit(1);
if (!musicGame.openFromFile("assets/audio/game.ogg"))
std::exit(1);
if (!musicBackground.openFromFile("assets/audio/wind2.ogg"))
std::exit(1);
if (!musicMenu.openFromFile("assets/audio/menu.ogg"))
std::exit(1);
if (!sfxClickBuffer.loadFromFile("assets/audio/click.ogg"))
std::exit(1);
if (!sfxDoneBuffer.loadFromFile("assets/audio/done.ogg"))
std::exit(1);
if (!textureBackground.loadFromFile("assets/img/background.png"))
std::exit(1);
spriteBackgroundArt.setTexture(textureBackgroundArt);
menuTxt.setFont(menuFont);
menuTxt.setCharacterSize(60);
menuTxt.setString(gameTitle);
int width = menuTxt.getLocalBounds().width;
int height = menuTxt.getLocalBounds().height;
menuTxt.setPosition(1050-(width/2),750-(height/2)-150);
menuTxt.setColor(sf::Color(255, 255, 255, 85));
cardsDeck.setFonts(&gameFont);
}
void Game::showMenu()
{
musicBackground.play();
musicBackground.setLoop(true);
menuBackground.setTexture(textures.textureMenu);
musicBackground.setVolume(7);
musicMenu.play();
musicMenu.setLoop(true);
currentState = state_menu;
}
void Game::hideMenu()
{
musicMenu.stop();
}
void Game::showGameBoard()
{
// musicGame.setVolume(20);
musicGame.play();
musicGame.setLoop(true);
sfx.playLetsBegin();
std::cout << "lets begin" << std::endl;
currentState = state_lets_begin;
}
void Game::endGame()
{
currentState = state_end_game;
musicBackground.stop();
}
void Game::handleLeftClick(sf::Vector2f pos,
sf::Vector2f posGui, sf::Vector2f posFull, int mousePos) {
if (currentState==state_game)
{
std::array<int,2> movements = players[turn].getMovements(diceResultPlayer);
if ((mousePos==movements[0]) || (mousePos==movements[1]))
{
players[turn].setFigurePos(mousePos);
commandManager.processField(mousePos);
- int *possibleExit = std::find(std::begin(efc::possibleExits),
- std::end(efc::possibleExits), mousePos);
- if (possibleExit != efc::possibleExits+4) {
+ const int *possibleExit = std::find(std::begin(efc::endPlayers),
+ std::end(efc::endPlayers), mousePos);
+ if (possibleExit != efc::endPlayers+4) {
players[turn].done=true;
numberFinishedPlayers += 1;
if (numberFinishedPlayers > 3)
endGame();
} else {
// std::cerr << "Not found" << std::endl;
}
nextPlayer();
}
// std::string resultCommand = players[turn].getElem(posGui);
// command(resultCommand);
commandManager.processGui(posGui);
}
else if (currentState==state_roll_dice)
{
sf::IntRect diceRect(roundDice.spriteDice.getGlobalBounds());
if (diceRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
diceResultPlayer = roundDice.throwDiceSix();
players[turn].characters[0].diceResult=diceResultPlayer;
currentState=state_game;
}
}
if (currentState==state_menu)
{
downTimeCounter = 0;
// std::cout << " AA " <<downTimeCounter << std::endl;
hideMenu();
showGameBoard();
}
if (currentState==state_gui_end_round)
{
std::string resultCommand = guiRoundDice.getElem(pos);
command(resultCommand);
}
}
void Game::hideGameBoard()
{
musicGame.play();
}
Game::Game():
screenSize(efc::initScreenX,efc::initScreenY),
viewFull(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
viewGui(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
viewTiles(sf::FloatRect(0, 0, 1360, 768)),
selector(efc::TILE_SIZE),
guiSelectBuilding(&textures),
character(&textures, 3),
gameTitle("deerportal"),
roundDice(players),
roundNumber(1),
guiRoundDice(&textures),
boardDiamonds(&textures),
window(sf::VideoMode(efc::initScreenX, efc::initScreenY), "Deerportal - game about how human can be upgraded to the Deer"),
turn(0),
commandManager(*this),
cardsDeck(&textures, &menuFont)
{
textLoading.setString("loading...");
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
window.clear(sf::Color::White);
window.draw(textLoading);
window.display();
numberFinishedPlayers = 0;
sf::Clock frameClock;
guiRoundDice.active = true;
showPlayerBoardElems = false;
window.setVerticalSyncEnabled(true);
std::srand (time(NULL));
window.clear(sf::Color(55,55,55));
window.draw(textLoading);
window.display();
loadAssets();
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
window.clear(sf::Color::Black);
window.draw(textLoading);
window.display();
initBoard();
window.clear(sf::Color::Black);
window.draw(textLoading);
window.display();
showMenu();
// run the main loop
while (window.isOpen())
{
sf::Time frameTime = frameClock.restart();
std::string resultCommand = "";
// handle events
sf::Event event;
while (window.pollEvent(event))
{
sf::Vector2i localPositionTmp = sf::Mouse::getPosition(window);
sf::Vector2f localPosition = window.mapPixelToCoords(localPositionTmp,viewTiles);
sf::Vector2f localPositionGui = window.mapPixelToCoords(localPositionTmp,viewGui);
sf::Vector2f localPositionFull = window.mapPixelToCoords(localPositionTmp,viewFull);
int mousePosX = (int)localPosition.x / efc::TILE_SIZE;
int mousePosY = (int)localPosition.y / efc::TILE_SIZE;
int mousePos = efc::transCords(sf::Vector2i(mousePosX, mousePosY));
if(event.type == sf::Event::Closed)
window.close();
if (currentState==state_gui_elem)
{
resultCommand = guiSelectBuilding.getElem(localPositionFull);
showPlayerBoardElems = false;
if (resultCommand.find("elem_")==0)
command(resultCommand);
else
command("hide_gui_elem_description");
}
// Showing mouse hover
if (currentState==state_game)
{
if ((localPosition.x>efc::TILE_SIZE*efc::BOARD_SIZE) || (localPosition.x<0) || (localPosition.y>efc::TILE_SIZE*efc::BOARD_SIZE) || (localPosition.y<0))
{
showPlayerBoardElems = false;
} else {
showPlayerBoardElems = true;
}
}
if ((localPosition.x>=0) && (localPosition.y>=0) && (localPosition.x<=efc::BOARD_SIZE*efc::TILE_SIZE) && (localPosition.y<=efc::BOARD_SIZE*efc::TILE_SIZE))
{
selector.setPosition((int) (localPosition.x / efc::TILE_SIZE)*efc::TILE_SIZE, ((int) localPosition.y / efc::TILE_SIZE)*efc::TILE_SIZE);
}
/*!
* Handling mouse click
*/
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
handleLeftClick(localPosition, localPositionGui,
localPositionFull, mousePos);
}
}
update(frameTime);
render();
}
}
void Game::update(sf::Time frameTime) {
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].getMovements(diceResultPlayer);
if (currentMovements[0]>-1)
{
prevRotateElem.spriteRotate.setPosition(players[turn].characters[0].leftChar.getPosition());
prevRotateElem.spriteRotate.move(4,16);
prevRotateElem.update(frameTime);
prevRotateElem.setColor(turn);
}
if (currentMovements[1]>-1)
{
nextRotateElem.spriteRotate.setPosition(players[turn].characters[0].rightChar.getPosition());
nextRotateElem.spriteRotate.move(4,16);
nextRotateElem.update(frameTime);
nextRotateElem.setColor(turn);
}
}
cardsDeck.update(frameTime);
for (int i=0;i<4;i++)
{
players[i].play();
players[i].update(frameTime);
}
if (currentState==state_lets_begin)
{
downTimeCounter += frameTime.asSeconds();
spriteLestBegin.setColor(sf::Color(255,255,255,255-(downTimeCounter*35)));
if (downTimeCounter>6)
{
currentState = state_roll_dice;
}
}
}
void Game::nextRound() {
turn = 0;
std::string result = roundDice.drawRound();
roundNumber += 1;
month++;
if (month==13)
month=1;
if (month%4==0)
currentSeason++;
if (currentSeason>3)
currentSeason=0;
if (players[turn].done==true)
nextPlayer();
}
void Game::nextPlayer(){
if (numberFinishedPlayers==4)
{
std::cout << "Everybody Finished!!!" << std::endl;
endGame();
}
if (turn<4)
players[turn].updatePlayer();
else
nextRound();
turn++;
if ((players[turn].done==true) && (turn<4))
{
std::cout << "Player " << turn << " is done" << std::endl;
nextPlayer();
}
if ((turn==4) || (turn>4))
{
nextRound();
}
if (players[turn].frozenLeft>0)
{
players[turn].frozenLeft -= 1;
nextPlayer();
}
selector.changeColor(turn);
for (int i=0;i<4;i++)
{
if (i==turn)
{
players[i].setActive(true);
currentNeighbours = players[i].getNeighbours();
}
else
players[i].setActive(false);
}
sfxClick.play();
diceResultPlayer = 6;
roundDice.setDiceTexture(diceResultPlayer);
players[turn].characters[0].diceResult = diceResultPlayer;
groupHud.setRoundName(roundNumber);
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
currentState = state_roll_dice;
roundDice.setColor(turn);
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
window.draw(players[i]);
}
}
void Game::drawSquares() {
if (showPlayerBoardElems)
{
window.draw(selector);
}
}
void Game::drawBaseGame()
{
window.setView(viewTiles);
// window.draw(map);
for (int i=0;i<4;i++)
{
window.draw(players[i].elems);
}
drawSquares();
window.setView(viewGui);
window.setView(viewTiles);
}
void Game::drawCharacters(){
window.setView(viewTiles); // Yeah Katia's inspiration
window.draw(gameBackground);
window.setView(viewFull);
window.draw(spriteBackgroundArt);
window.draw(cardsDeck);
window.draw(roundDice.spriteDice);
window.setView(viewTiles);
drawSquares();
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].characters[0].getMovements(diceResultPlayer);
if (currentMovements[1]>-1)
window.draw(nextRotateElem);
if (currentMovements[0]>-1)
window.draw(prevRotateElem);
}
for (int i=0;i<4;i++)
{
for (auto&& j: players[i].characters)
{
if (currentState==state_game)
j.drawMovements = true;
else
j.drawMovements = false;
window.draw(j);
}
}
}
void Game::render()
{
window.clear();
if (currentState==state_game)
{
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_roll_dice) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_gui_elem) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
drawCharacters();
window.draw(guiSelectBuilding);
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_menu) {
window.draw(menuTxt);
} else if (currentState==state_lets_begin) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.draw(spriteLestBegin);
} else if (currentState==state_gui_end_round){
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
window.draw(guiRoundDice);
window.setView(viewFull);
window.draw(groupHud);
}
window.display();
}
void Game::command(std::string command){
if (command=="close_gui")
{
guiSelectBuilding.active = false;
currentState=state_game;
sfxClick.play();
}
if (command=="hide_gui_elem_description")
{
if (currentState==state_gui_elem) {
guiSelectBuilding.descriptionActive = false;
}
}
if (command.find("end_of_round")==0)
{
std::string subResult = command.substr(13);
guiRoundDice.active = true;
guiRoundDice.setTitle(subResult);
currentState = state_gui_end_round;
}
if (command=="end_turn")
nextPlayer();
}
sf::Vector2f Game::getMousePos(){
sf::Vector2i mousePosTmp(sf::Mouse::getPosition(window));
sf::Vector2f mousePosition(window.mapPixelToCoords(mousePosTmp,viewTiles));
return mousePosition;
}
}
diff --git a/playerhud.cpp b/playerhud.cpp
index 70ae0a5..fd5cd6a 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,218 +1,218 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
std::set<int> PlayerHud::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
std::set<int> PlayerHud::getBusy(){
std::set<int> busyTiles;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
busyTiles.insert(i.first);
}
return busyTiles;
}
std::set<int> PlayerHud::getNeighbours(){
std::set<int> neighbours;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
std::set<int> terrain = getTerrainSet();
std::set<int> neighboursVector(efc::getNeighbours(i.second.pos));
for (int j: neighboursVector)
{
if ((elems.items_map.count(j) == 0) && (terrain.count(j)==0))
{
// std::cout << j << " " << terrain.count(j) << std::endl;
neighbours.insert(j);
}
}
}
// // Fill in s1 and s2 with values
// std::set<int> result;
// std::set_difference(neighbours.begin(), neighbours.end(), terrain.begin(), terrain.end(),
// std::inserter(result, result.end()));
// for (int i: result)
// {
// std::cout << i << std::endl;
// }
return neighbours;
}
void PlayerHud::updateTxt(){
txtCash.setString(std::to_string(cash));
// txtFood.setString( "Food: " + std::to_string(food));
// txtEnergy.setString("Enrg: " + std::to_string(energy));
// txtFaith.setString( "Gods: " + std::to_string(faith));
}
void PlayerHud::updatePlayer(){
updateTxt();
}
PlayerHud::PlayerHud():
frozenLeft(0)
{
}
void PlayerHud::setActive(bool newState){
active = newState;
elems.active = newState;
for (auto&& i: characters)
{
i.active = newState;
}
}
PlayerHud::PlayerHud(TextureHolder *textures, sf::Font *gameFont, int faceSize, int pos)
{
frozenLeft = 0;
done = false;
active = false;
this->textures = textures;
// Character character(this->textures, pos);
characters.push_back(Character (this->textures, pos));
// efc::BoardElem startElem(textures, efc::startPlayers[pos],444);
// startElem.setColor(efc::playersColors[pos]);
// elems.items.push_back(startElem);
// elems.items_map.insert({efc::startPlayers[pos], startElem});
this->faceSize = faceSize;
spriteFace.setTexture(textures->textureFaces);
this->pos = pos;
symbol.setTexture(this->textures->textureSymbols);
sf::IntRect symbolsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
symbol.setTextureRect(symbolsRect[pos]);
symbol.setScale(sf::Vector2f(0.2f, 0.20f));
symbol.setColor(sf::Color(25, 25, 25, 105));
symbol.setPosition(60, (pos*100)+40);
food = 0;
cash = 0;
energy = 0;
faith = 0;
txtCash.setFont(*gameFont);
txtCash.setCharacterSize(20);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(pos*100)+10);
- int posX1 = 80;
- int posX2 = 960;
- int posY1 = 184;
- int posY2 = 579;
+ int posX1 = 82;
+ int posX2 = 962;
+ int posY1 = 22;
+ int posY2 = 720;
std::array<std::array<int,2>,4> textPos =
{
{
{posX1,posY1}, {posX2,posY1},
{posX1,posY2}, {posX2, posY2}
}
};
txtCash.setPosition(textPos[pos][0],textPos[pos][1] );
buttons.insert({"end_turn",rectangle});
}
std::string PlayerHud::getElem(sf::Vector2f mousePosition) {
std::string result = "";
sf::Vector2f hoverPos = getPosition();
for (std::pair<std::string, sf::RectangleShape> i: buttons)
{
sf::FloatRect spriteBounds = i.second.getLocalBounds();
sf::FloatRect closeRect;
closeRect.left = i.second.getPosition().x;
closeRect.top = i.second.getPosition().y;
closeRect.width = spriteBounds.width;
closeRect.height = spriteBounds.height;
if (closeRect.contains(mousePosition.x - hoverPos.x,mousePosition.y - hoverPos.y))
{
return i.first;
}
}
return result;
}
void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(txtCash, states);
}
void PlayerHud::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void PlayerHud::update(sf::Time deltaTime)
{
updateTxt();
if (frozenLeft==0)
{
for (auto&& i: characters)
{
sf::Vector2f movement(0.f, 0.f);
if (i.currentAnimationIndex==efc::DIR_LEFT)
movement = sf::Vector2f (-10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_RIGHT)
movement = sf::Vector2f (10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_UP)
movement = sf::Vector2f (0.f, -10.f);
else if (i.currentAnimationIndex==efc::DIR_DOWN)
movement = sf::Vector2f (0.f, 10.f);
i.update(deltaTime);
}
} else{
characters[0].currentAnimationIndex=efc::DIR_DOWN;
}
}
std::array<int,2> PlayerHud::getMovements(int diceResult)
{
return characters[0].getMovements(diceResult);
}
void PlayerHud::setFigurePos(int pos)
{
characters[0].setBoardPosition(pos);
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:25 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71437
Default Alt Text
(48 KB)

Event Timeline