Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F102461
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
31 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/assets/img/background_land.png b/assets/img/background_land.png
index 92a35e4..e231480 100644
Binary files a/assets/img/background_land.png and b/assets/img/background_land.png differ
diff --git a/game.cpp b/game.cpp
index 19ddff7..4487098 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,733 +1,740 @@
#include "game.h"
namespace efc {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 0;
int month = 0;
void Game::initBoard()
{
// Grass tile starts at 342 and has 11 tiles
// int level[256];
// int level[256];
// Structure of the board
/*
{
342, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
80, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3 }
*/
// Fill the array
for (int i=0;i<256;i++)
{
int grass = (rand() % 10) + 1;
level[i] = 342 + grass;
level[i] = level[i];
}
// level[0] = 441;
// level[240] = 0;
// level[255] = 0;
// level[15] = 0;
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;
map.load(&textures, sf::Vector2u(efc::TILE_SIZE, efc::TILE_SIZE), level, efc::BOARD_SIZE, efc::BOARD_SIZE);
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
spriteBackground.setTexture(textureBackground);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
gameBackground.setTexture(textures.textureGameBackground);
// viewTiles.setViewport(sf::FloatRect(0.04f,0.060f, 1.0f, 1.0f));
viewTiles.setViewport(sf::FloatRect(0.15f,0.1f, 1.0f, 1.0f));
viewGui.setViewport(sf::FloatRect(0.806f,0.066f, 1, 1));
selector.changeColor(turn); //This is only for the test TODO: remove
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;
PlayerHud playerHud1(&textures, std::rand() % 80, &gameFont, 32,0);
PlayerHud playerHud2(&textures, std::rand() % 30, &gameFont, 32,1);
PlayerHud playerHud3(&textures, std::rand() % 60, &gameFont, 32,2);
PlayerHud playerHud4(&textures, std::rand() % 50, &gameFont, 32,3);
players[0] = playerHud1;
players[1] = playerHud2;
players[3] = playerHud3;
players[2] = playerHud4;
players[0].setActive(true);
setCurrentNeighbours();
// roundDice.throwDiceSix();
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);
spriteBackgroundArt.setTexture(textureBackgroundArt);
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);
menuTxt.setFont(menuFont);
menuTxt.setCharacterSize(60);
menuTxt.setString(gameTitle);
int width = menuTxt.getLocalBounds().width;
int height = menuTxt.getLocalBounds().height;
menuTxt.setPosition(400-(width/2),300-(height/2)-150);
menuTxt.setColor(sf::Color(55, 255, 35, 85));
}
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(50);
musicGame.play();
musicGame.setLoop(true);
currentState = state_roll_dice;
}
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);
if (boardDiamonds.ifFieldIsEmpty(mousePos)==false)
{
sfx.playCollect();
if (boardDiamonds.getNumberForField(mousePos)==4)
{
players[turn].cash += 1;
};
std::cout << "cash " << players[turn].cash << " " << " for " << turn << " " << boardDiamonds.getNumberForField(mousePos) << " result" << std::endl;
// After this no more visible
boardDiamonds.collectField(mousePos);
}
int *possibleExit = std::find(std::begin(efc::possibleExits),
std::end(efc::possibleExits), mousePos);
if (possibleExit != efc::possibleExits+4) {
// std::cerr << "Found hahahah" << mousePos << std::endl;
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);
}
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;
}
}
else if (currentState==state_gui_elem)
{
std::string resultCommand = guiSelectBuilding.getElem(posFull);
if (resultCommand.find("elem_")==0)
{
std::string resultCommandWrapped = "build_" + resultCommand;
command(resultCommandWrapped);
} else if (resultCommand.find("close_gui")==0)
{ command(resultCommand);}
}
if (currentState==state_menu)
{
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),
window(sf::VideoMode(efc::initScreenX, efc::initScreenY), "Pagan Board"),
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),
turn(0),
gameTitle("pagan board"),
roundDice(players),
roundNumber(1),
guiRoundDice(&textures),
boardDiamonds(&textures)
{
int gWidth = guiSelectBuilding.rectangle.getLocalBounds().width;
int gHeight = guiSelectBuilding.rectangle.getLocalBounds().height;
int borderLeft = 31;
int borderRight = 28;
int borderTop = 39;
int borderBottom = 39;
int guiWidth = 128;
int guiStartPosTmp[4][2] = {
{borderLeft+3,borderTop+2},
{screenSize.x - guiWidth - borderRight - gWidth-4,borderTop+2},
{borderLeft+3,screenSize.y-gHeight-borderBottom-4} ,
{screenSize.x - guiWidth - borderRight - gWidth-4,
screenSize.y-gHeight-borderBottom-4}};
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
guiStartPos[i][j] = guiStartPosTmp[i][j];
}
numberFinishedPlayers = 0;
sf::Clock frameClock;
guiRoundDice.active = true;
showPlayerBoardElems = false;
window.setVerticalSyncEnabled(true);
Hover hover;
GuiWindow guiWindow(&textures);
std::srand (time(NULL));
loadAssets();
initBoard();
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");
}
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;
players[turn].elems.displayNeighbours = false;
} else {
showPlayerBoardElems = true;
players[turn].elems.displayNeighbours = true;
}
}
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
handleLeftClick(localPosition, localPositionGui,
localPositionFull, mousePos);
}
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);
}
}
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);
}
}
for (int i=0;i<4;i++)
{
players[i].play();
}
for (int i=0;i<4;i++)
{
players[i].update(frameTime, busyTiles);
}
}
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();
// command(result);
}
void Game::nextPlayer(){
// boardDiamonds.reorder();
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();
}
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();
// roundDice.throwDiceSix();
// diceResultPlayer = roundDice.throwDiceSix();
diceResultPlayer = 6;
roundDice.setDiceTexture(diceResultPlayer);
// std::cout << "DEBUG " << turn << " "<< diceResultPlayer << std::endl;
players[turn].characters[0].diceResult = diceResultPlayer;
// std::cout << roundNumber << " " << roundNumber % 16 << std::endl;
groupHud.setRoundName(roundNumber);
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
// setBusyTiles();
currentState = state_roll_dice;
roundDice.setColor(turn);
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
window.draw(players[i]);
}
- window.draw(seasons[currentSeason]);
+// window.draw(seasons[currentSeason]);
}
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);
- drawPlayersGui();
window.setView(viewTiles);
}
void Game::drawCharacters(){
// window.setView(viewFull);
window.setView(viewTiles); // Yeah Katia's inspiration
window.draw(gameBackground);
window.setView(viewFull);
window.draw(spriteBackgroundArt);
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();
+
} else if (currentState==state_roll_dice) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
+ window.setView(viewFull);
+
+ drawPlayersGui();
} else if (currentState==state_gui_elem) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
drawCharacters();
window.draw(guiSelectBuilding);
} else if (currentState==state_menu) {
window.draw(menuBackground);
window.draw(menuTxt);
window.draw(groupHud);
window.setView(viewFull);
} 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){
// std::cout << command << std::endl;
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.find("elem_")==0)
// {
// if (currentState==state_gui_elem)
// {
// int buildingType = std::stoi(command.substr(5));
// std::string descTxt = textures.tilesTxt[buildingType];
// char priceTxtChar [100];
// std::string priceTxt = priceTxtChar;
// char costTxtChar [100];
// std::string costTxt = costTxtChar;
// guiSelectBuilding.setDescriptionTxt(priceTxt + costTxt + "\n"+descTxt);
// guiSelectBuilding.descriptionActive = true;
// }
// }
if (command=="end_turn")
nextPlayer();
// if (command.find("build_")==0)
// {
// int buildingType = std::stoi(command.substr(11));
// bool purchaseResult = players[turn].addElem(selectedPos, buildingType);
// if (purchaseResult)
// {
// currentState = state_game;
// setCurrentNeighbours();
// guiSelectBuilding.active = false;
// sfxDone.play();
// }
// }
}
sf::Vector2f Game::getMousePos(){
sf::Vector2i mousePosTmp(sf::Mouse::getPosition(window));
sf::Vector2f mousePosition(window.mapPixelToCoords(mousePosTmp,viewTiles));
return mousePosition;
}
void Game::setBusyTiles() {
busyTiles.clear();
for (int i: efc::terrainArray)
{
busyTiles.insert(i);
}
for (int i=0;i<4;i++)
{
for (int j:players[i].getBusy())
{
busyTiles.insert(j);
}
}
}
}
diff --git a/grouphud.cpp b/grouphud.cpp
index 8cac37c..6d0c2ac 100644
--- a/grouphud.cpp
+++ b/grouphud.cpp
@@ -1,57 +1,57 @@
#include "grouphud.h"
#include "data.h"
namespace efc {
GroupHud::GroupHud(sf::Font *gameFont)
{
seasonName.setFont(*gameFont);
}
GroupHud::GroupHud(){
}
void GroupHud::setFont(sf::Font *gameFont) {
- move(20,2);
+ move(440,12);
seasonName.setFont(*gameFont);
roundName.setFont(*gameFont);
monthName.setFont(*gameFont);
- seasonName.setColor(sf::Color(0,0,0,255));
+ seasonName.setColor(sf::Color(255,255,255,200));
seasonName.setCharacterSize(30);
roundName.setCharacterSize(30);
monthName.setCharacterSize(30);
- roundName.setColor(sf::Color(0,0,0,255));
- roundName.move(1200, 0);
+ roundName.setColor(sf::Color(255,255,255,200));
+ roundName.move(30, 700);
// monthName.move(400, 0);
setMonthName(1);
}
void GroupHud::setSeason(int seasonNumber){
seasonName.setString("Season: " + efc::seasonsNames[seasonNumber]);
};
void GroupHud::setRoundName(int roundNumber){
roundName.setString("Round: " + std::to_string(roundNumber));
};
void GroupHud::setMonthName(int monthNumber){
monthName.setString("Month: " + std::to_string(monthNumber));
};
void GroupHud::draw(sf::RenderTarget& target, sf::RenderStates states) const{
states.transform *= getTransform();
target.draw(seasonName, states);
target.draw(roundName, states);
// target.draw(monthName, states);
}
}
diff --git a/playerhud.cpp b/playerhud.cpp
index dd9fa92..34ff51e 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,242 +1,230 @@
#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));
-
-// 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));
+ 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(){
- 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();
- }
+
+ 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};
done = false;
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 = 0;
energy = 0;
faith = 0;
int x = faceNumber % 10;
int y = (int) faceNumber /10;
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 = 70;
+ int posX2 = 920;
+ int posY1 = 175;
+ int posY2 = 575;
+ 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();
- if (active)
- target.draw(txtNextRound, states);
-
+ target.draw(txtCash, states);
}
void PlayerHud::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void PlayerHud::update(sf::Time deltaTime, std::set<int>& busyTiles)
{
+ updateTxt();
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);
}
diff --git a/rounddice.cpp b/rounddice.cpp
index b5dcf84..692d622 100644
--- a/rounddice.cpp
+++ b/rounddice.cpp
@@ -1,76 +1,76 @@
#include "rounddice.h"
RoundDice::RoundDice(PlayerHud (&players)[4])
{
playersHud = players;
diceResult = 1;
diceResultSix = 6;
diceSize = 150;
if (!sfxDiceBuffer.loadFromFile("assets/audio/dice.ogg"))
std::exit(1);
if (!textureDices.loadFromFile("assets/img/dicesWhite.png"))
std::exit(1);
spriteDice.setTexture(textureDices);
sfxDice.setBuffer(sfxDiceBuffer);
sfxDice.setVolume(12);
spriteDice.setPosition(1140,550);
setDiceTexture();
}
void RoundDice::setDiceTexture(){
sf::IntRect diceRect(diceSize*diceResultSix, 0, diceSize, diceSize);
spriteDice.setTextureRect(diceRect);
}
void RoundDice::setColor(int playerNumber){
sf::Color color(efc::playersColors[playerNumber]);
spriteDice.setColor(color);
}
void RoundDice::setDiceTexture(int diceResult){
this->diceResultSix = diceResult;
setDiceTexture();
}
std::string RoundDice::drawRound(){
throwDice();
if (diceResult<33)
{
return "end_of_round_extra_grow";
} else if (diceResult<66)
{
return "end_of_round_extra_energy";
} else
{
eventExtraCash();
return "end_of_round_extra_cash";
}
return "end_of_round_"+std::to_string(diceResult);
}
int RoundDice::throwDice(){
sfxDice.play();
int result = random()%100;
diceResult = result;
return result;
}
int RoundDice::throwDiceSix(){
sfxDice.play();
int result = random()%6;
diceResultSix = result;
setDiceTexture();
return result+1;
}
void RoundDice::eventExtraCash(){
- for (int i=0;i<4;i++)
- {
- playersHud[i].cash += 20;
- playersHud[i].updateTxt();
- }
+// for (int i=0;i<4;i++)
+// {
+// playersHud[i].cash += 20;
+// playersHud[i].updateTxt();
+// }
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Feb 2, 8:54 PM (2 d, 4 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55535
Default Alt Text
(31 KB)
Attached To
Mode
R82 deerportal
Attached
Detach File
Event Timeline
Log In to Comment