Page MenuHomePhabricator (Chris)

No OneTemporary

Size
24 KB
Referenced Files
None
Subscribers
None
diff --git a/character.cpp b/character.cpp
index bbcb131..93382a5 100644
--- a/character.cpp
+++ b/character.cpp
@@ -1,343 +1,349 @@
#include "character.h"
/*!
* \brief Character::getMovements
* \return
*/
std::array<int,2> Character::getMovements(int howFar)
{
+ std::cout << "howfar: " <<howFar <<std::endl;
if (boardPosition+howFar>255)
moveRight = -1;
else
{
int index = boardPosition;
for (int i=boardPosition;i<=boardPosition+howFar-1;i++)
{
+ std::cout << "FUCK ME " << index << std::endl;
+ if (index==-1)
+ break;
index = efc::boards[index][1];
// std::cout << " index R" << index
// << " move R " << moveRight
// << std::endl;
if (index==-1)
break;
}
moveRight = index;
}
if (boardPosition-howFar<0)
moveLeft = -1;
else
{
int index = boardPosition;
for (int i=boardPosition;i>=boardPosition-howFar+1;i--)
- {
+ { if (index==-1)
+ break;
index = efc::boards[index][0];
// std::cout << " index l " << index
// << " move L " << moveLeft
// << std::endl;
if (index==-1)
break;
}
moveLeft = index;
}
std::array<int,2> myArray = {moveLeft,moveRight};
int x = efc::boards[2][2];
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),
- diceResult(2)
+ nextRedirect(0.f)
{
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, 23, 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));
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)
{
if (moveLeft>-1)
{
// std::cout << "draw " << rectangleLeft.getPosition().x << " " << rectangleLeft.getPosition().y << std::endl;
- target.draw(leftChar, states);
+ target.draw(leftChar);
}
if (moveRight>-1)
{
// std::cout << "draw R" << rectangleRight.getPosition().x << " " << rectangleRight.getPosition().y << std::endl;
- target.draw(rightChar, states);
+ target.draw(rightChar);
// target.draw(rectangleRight, 4, sf::Quads, states);
}
}
- target.draw(animatedSprite, states);
+
}
void Character::update(sf::Time deltaTime, std::set<int> &busyTiles)
{
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 (left>-1)
+ if (active==true)
{
- sf::Vector2i cords(efc::transPosition(left));
+ if (moveLeft>-1)
+ {
+ sf::Vector2i cordsLeft(efc::transPosition(moveLeft));
+ sf::Vector2i neededCords(efc::transPosition(moveLeft));
+ sf::Vector2f newPos(efc::getScreenPos(neededCords));
+ leftChar.setPosition(newPos);
+ }
- rectangleLeft.setPosition(cords.x*efc::TILE_SIZE, cords.y*efc::TILE_SIZE);
- rectangleLeft.setPosition(200,200);
- leftChar.setPosition(cords.x*efc::TILE_SIZE, cords.y*efc::TILE_SIZE);
-// target.draw(rectangleLeft, states);
- }
+ if (moveRight>-1)
+ {
+ sf::Vector2i cordsRight(efc::transPosition(moveRight));
+ sf::Vector2i neededCords(efc::transPosition(moveRight));
+ sf::Vector2f newPos(efc::getScreenPos(neededCords));
+ rightChar.setPosition(newPos);
+ }
- if (right>-1)
- {
- sf::Vector2i cords(efc::transPosition(right));
- sf::RectangleShape rectangleRight(sf::Vector2f(efc::TILE_SIZE, efc::TILE_SIZE));
- rectangleRight.setPosition(cords.x*efc::TILE_SIZE, cords.y*efc::TILE_SIZE);
- rightChar.setPosition(cords.x*efc::TILE_SIZE, cords.y*efc::TILE_SIZE);
-// target.draw(rectangleRight, states);
+ 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());
}
/*!
* \brief Character::getBoardPosition
* \return
*/
int Character::getBoardPosition()
{
sf::Vector2f currentPos(getPosition());
sf::Vector2i currentCords(efc::getCords(currentPos));
int currentBoardPosition = efc::transCords(currentCords);
return currentBoardPosition;
}
/*!
* \brief Character::setBoardPosition
* \param boardPosition
*/
void Character::setBoardPosition(int boardPosition)
{
sf::Vector2i neededCords(efc::transPosition(boardPosition));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
setPosition(newPos.x, newPos.y);
this->boardPosition = boardPosition;
std::array<int,2> movements(getMovements(diceResult));
std::cout << "board pos >> " << boardPosition << " cords >>" << neededCords.x << " " << neededCords.y
<< "newpos >> " << newPos.x << " " << newPos.y << " "
<< "movements >> " << movements[0] << " " << movements[1]
<< std::endl;
}
diff --git a/data.cpp b/data.cpp
index 3ad39c9..e02e470 100644
--- a/data.cpp
+++ b/data.cpp
@@ -1,73 +1,87 @@
#include <data.h>
namespace efc {
std::string seasonsNames[4] = {"spring", "summer", "fall", "winter"};
// 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
+ */
std::array<std::array<int,2>,256> boards = {
{
- {0,1},{0,2},{1,3},{2,4},{3,5},{4,6},{5,12},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{12,14},{13,15},{14,-1},
- {0,17},{0,18},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
- {0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},{0,2},
+ {0,1}, {0,2}, {1,3}, {2,4}, {3,5}, {4,21}, {-1,-1}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{12,14},{13,15},{14,-1},
+ {-1,-1}, {18,33}, {19,17}, {20,18}, {21,19}, {5,20}, {-1,-1}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {33,48}, {17,32}, {-1,-1}, {51,36}, {35,37}, {36,38}, {37,54}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {32,49}, {48,50}, {49,51}, {50,35}, {-1,-1}, {54,69}, {36,53}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {65,80}, {66,64}, {67,65}, {68,66}, {69,67}, {53,68}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {64,81}, {80,97}, {-1,-1}, {99,84}, {83,85}, {84,101}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {-1,-1}, {81,98}, {97,99}, {98,83}, {-1,-1}, {85,102}, {101,118},{-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,-1}, {102, 119},{118,-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}, {-1,-1} , {151,-1},{-1,-1},{-1,-1},{-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},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {176,161},{160,145}, {-1,-1}, {147,164}, {163,165}, {165,166}, {165,150},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {177,160},{178,176}, {179,177}, {180,178}, {181,179}, {182,180}, {198,181},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {208,193},{192,194}, {193,195}, {194,211}, {-1,-1}, {213,198}, {197,182},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {209,192},{225,208}, {-1,-1}, {195,212}, {211,213}, {212,195}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {-1,-1}, {226,209}, {227,225}, {228,226}, {229,227},{245,228}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
+ {-1,241}, {240,-242},{241,243}, {242,244}, {243,245},{244,229}, {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
},
};
//{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)
};
}
diff --git a/playerhud.cpp b/playerhud.cpp
index 8b43589..4581249 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,321 +1,321 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
bool PlayerHud::addElem(int pos, int type) {
int price = textures->tilesDescription[type][0];
if (price<=cash)
{
efc::BoardElem startElem(textures, pos,type);
startElem.setColor(efc::playersColors[this->pos]);
elems.items.push_back(startElem);
elems.items_map.insert({pos, startElem});
cash -= price;
updateTxt();
- characters.push_back(Character (this->textures, this->pos));
+// characters.push_back(Character (this->textures, this->pos));
return true;
}
return false;
}
std::set<int> PlayerHud::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrainArray)
{
// std::cout << i << std::endl;
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( "Cash: " + 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(){
for (const efc::BoardElem &i: elems.items)
{
int cashUpd = textures->tilesDescription[i.type][1];
int foodUpd = textures->tilesDescription[i.type][3];
int enrgUpd = textures->tilesDescription[i.type][5];
int faithUpd = textures->tilesDescription[i.type][7];
cash += cashUpd;
energy += enrgUpd;
food += foodUpd;
faith += faithUpd;
updateTxt();
}
}
PlayerHud::PlayerHud()
{
}
void PlayerHud::setActive(bool newState){
active = newState;
elems.active = newState;
for (auto&& i: characters)
{
i.active = newState;
}
}
PlayerHud::PlayerHud(TextureHolder *textures, int faceNumber, sf::Font *gameFont, int faceSize, int pos)
{
static int startPlayers[4] = {0,15,240,255};
active = false;
this->textures = textures;
Character character(this->textures, pos);
characters.push_back(Character (this->textures, pos));
efc::BoardElem startElem(textures, startPlayers[pos],444);
startElem.setColor(efc::playersColors[pos]);
elems.items.push_back(startElem);
elems.items_map.insert({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 = 20;
energy = 0;
faith = 0;
int x = faceNumber % 10;
int y = (int) faceNumber /10;
txtCash.setFont(*gameFont);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
// txtNextRound.setScale(sf::Vector2f(0.25f, 1.f));
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(pos*100)+10);
txtCash.setPosition(1,(pos*100)+40);
// txtCash.setString("Cash: " + std::to_string(cash));
txtCash.setCharacterSize(10);
// txtCash.setScale(sf::Vector2f(0.25f, 1.f));
txtFood.setPosition(1,(pos*100)+55);
// txtFood.setString("Food: " + std::to_string(food));
txtFood.setCharacterSize(10);
// txtFood.setScale(sf::Vector2f(0.25f, 1.f));
txtEnergy.setPosition(1,(pos*100)+70);
// txtEnergy.setString("Enrg: " + std::to_string(energy));
txtEnergy.setCharacterSize(10);
// txtEnergy.setScale(sf::Vector2f(0.25f, 1.f));
txtFaith.setPosition(1,(pos*100)+85);
// txtEnergy.setString("Enrg: " + std::to_string(energy));
txtFaith.setCharacterSize(10);
// txtFaith.setScale(sf::Vector2f(0.25f, 1.f));
updateTxt();
spriteFace.setTextureRect(sf::IntRect(x*faceSize, y*faceSize, faceSize, faceSize));
// spriteFace.setScale(sf::Vector2f(0.25f, 1.f));
spriteFace.setPosition(0,pos*100);
rectangle.setSize(sf::Vector2f((this->faceSize)*7, this->faceSize));
rectangle2.setSize(sf::Vector2f((this->faceSize)*7, (this->faceSize*2)+3));
if (pos==0)
{
rectangle.setFillColor(sf::Color(50, 50, 200,68));
rectangle2.setFillColor(sf::Color(100, 100, 150,38));
rectangle.setOutlineColor(sf::Color(0,0,128,68));
}
else if (pos==1)
{
rectangle.setFillColor(sf::Color(50, 150, 50,68));
rectangle2.setFillColor(sf::Color(100, 150,100,38));
rectangle.setOutlineColor(sf::Color(0,128,0,68));
}
else if (pos==2)
{
rectangle.setFillColor(sf::Color(150, 50, 50,68));
rectangle2.setFillColor(sf::Color(150, 100,100,38));
rectangle.setOutlineColor(sf::Color(128,0,0,68));
}
else if (pos==3)
{
rectangle.setFillColor(sf::Color(150, 150, 150,68));
rectangle2.setFillColor(sf::Color(200, 200,200,38));
rectangle.setOutlineColor(sf::Color(128,128,128,68));
}
rectangle.setOutlineThickness(1);
rectangle.setPosition(0, pos*100);
rectangle2.setPosition(0, (pos*100)+faceSize+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;
// std::cout << closeRect.left << " " << closeRect.top << " " << closeRect.width << " " << closeRect.height
// << hoverPos.x << " " << hoverPos.y << " OK"
// << std::endl;
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
{
// // apply the transform
states.transform *= getTransform();
// Color rectangles making the gui on the right side
// sf::RectangleShape rectangle(sf::Vector2f(faceSize, faceSize));
// sf::RectangleShape rectangle2(sf::Vector2f(faceSize, (faceSize*2)+3));
target.draw(rectangle, states);
target.draw(rectangle2, states);
target.draw(txtCash, states);
target.draw(txtFood, states);
target.draw(txtEnergy, states);
target.draw(txtFaith, states);
if (active)
target.draw(txtNextRound, states);
target.draw(symbol, states);
target.draw(spriteFace, states);
}
void PlayerHud::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void PlayerHud::update(sf::Time deltaTime, std::set<int>& busyTiles)
{
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.move(movement * deltaTime.asSeconds());
i.update(deltaTime, busyTiles);
}
}
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
Mon, Feb 2, 9:00 PM (2 d, 6 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55554
Default Alt Text
(24 KB)

Event Timeline