Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
59 KB
Referenced Files
None
Subscribers
None
diff --git a/HANDBOOK.md b/HANDBOOK.md
index 1fd831e..df52e46 100644
--- a/HANDBOOK.md
+++ b/HANDBOOK.md
@@ -1,100 +1,103 @@
![DeerPortal Title Screen](https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_773.png/@@images/image.png)
#Deer Portal
##Introduction
A computer multiplayer board game driven by the four classical elements. For 0-4 players. Game takes place in an ancient world where Almighty Deer God is protecting all the compassionate creatures.
*Disclaimer*: Both, manual and a game are under active development, in first place manual may not reflects all features available in the game yet
###History of the game
One of the authors of the game, during his buddhist journey trough Japan has visited a "deer temple", Tōdai-ji in Nara. After spending several nights there, he left a place with a mission - to deliver this game to spread the word about the Deer.
##Goal of the game
Transform yourself into a **Deer Lesser God** by reaching the **Hoof Portal** and collecting most diamonds.
![DeerPortal MultiPlayer Mode](https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_771.png/@@images/image.png)
##Game setup
A gameboard is split into four areas, each under control of one of the classical element.
![DeerPortal Game play](https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_772.png/@@images/image.png)
###Classical elements
* Water (blue)
* Earth (green)
* Fire (red)
* Air (yellow)
###Players
There are four players, each one being leaded / mentored by one of the classical element. They are able to:
* move around their board
* collect runes and diamonds
* meditate to get help of their patron
* reach the Deer Portal
Each player can be controlled by a human or a computer (it is possible to watch a duel of four computers, for example).
###Diamonds
To be allowed to pass the transformation you need to gift the Almighty Deer. The Almighty Deer likes shiny things, so collecting diamonds is a way to please him. A player who owns most diamonds on the Judgement Day - is a winner. The rest is being thrown into the flames of the infinitive, filled with collapsed realities folded in time void. Diamonds are being collected by moving the character onto the field containing a diamond, but also by grabbing a runes containing diamond action.
###Cards
On the right of the board game, there are four piles of 32 the cards dedicated to each of the classical element. To collect a card, player must put his character on a field containing a corresponding to the element rune. Rules are following:
* When the player collects his own element - card is being removed from the pile and next one unveiled.
* When the player collects the other element rune - a card is being executed in the field of the element which card has been taken.
####Types of the cards
* Stop - increases the **pause period** of the other element character.
* Collect diamond - steals diamond from the other element field
* Collect two diamonds - steals two diamonds from the other element field
* Collect rune - steals rune from the other element field
###Meditation
To meditate player has to go back to his start point, and since it depends on the mood of the patron, this is only possible by throwing exact numbers on the dice. It results in regenerating all the runes and diamonds on his board.
###Deer Portal
In the middle of all the boards, there is Deer Portal, with the **Hooftlar** (the Almighty Deer Good altar) placed in the center. First player who reach it and pay tribute to Almighty Deer, starts **Deer Mode** period which takes exactly four rounds (four turns for each player). After that everyone who didn't reach the portal - will be ceased.
##Game mechanic
Each player who is active (didn't reach Hoofltar yet, nor is being paused) has to perform two actions during his turn - throw a dice (by the click on hand symbol in the right bottom area of the screen), and then decide where to go - by clicking on the corresponding area on his board. After moving the character, depends on the destination field:
* Nothing happen - if the field was empty
* Collects the diamond - if there was one
* Meditates - if the field was a starter place for the character
* Collects the rune and executes the card - if run was on the field
-* Dedicates himself to the Almighty Deer God - finishes the game
+* Moves to the Deer God kingdom - by entering the portal.
+
+If the player entered portal as the first one - he does start Deer Mode and gets awarded with the few diamonds.
+
##End of the game
There can be only one winner, a player having highest number of the collected diamonds. If there is a draw, award goes for the player who reached portal first. Winner is being transformed into a Deer God. Rest of survivors are becoming his monks, the believers to spread the word. Ones who didn't survive, became a first heritage and a foundation of the new philosophy.
![DeerPortal Poster](https://bluszcz.net/projects/games/deerportal/poster01.png/@@images/image.png)
##Credits
* **bluszcz**: game design, code, audio
* **ukata**: game design, visual art
diff --git a/assets/img/diamond-big.png b/assets/img/diamond-big.png
new file mode 100644
index 0000000..74bf229
Binary files /dev/null and b/assets/img/diamond-big.png differ
diff --git a/game.cpp b/game.cpp
index 5ec3c70..7add049 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,1086 +1,1180 @@
#include "game.h"
#include "particle.h"
#include "calendar.h"
+#include <algorithm>
namespace efc {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 1;
int month = 0;
/*!
* \brief The ResultTable struct contains data for the end of the game screen.
*/
struct ResultTable
{
int playerNumber;
int playerResult;
bool reachedPortal;
bool reachedPortalFirst;
ResultTable(int number,int result, bool portal, bool portalFirst) :
playerNumber(number), playerResult(result), reachedPortal(portal), reachedPortalFirst(portalFirst) {}
bool operator < (const ResultTable& otherResult) const
{
if ((playerResult!=otherResult.playerResult) || ((reachedPortal==false) && (otherResult.reachedPortal==false)))
return (playerResult > otherResult.playerResult);
else if (reachedPortalFirst==true){
return true;
} else
{
return false;
}
;
}
};
/*!
* \brief Game::setTxtEndGameAmount orders the results text for the end of the game.
*/
void Game::setTxtEndGameAmount(){
std::string elementNames[4] = {"Water","Earth", "Fire", "Air"};
int width=1360;
// int height = 768;
// int startHeight = 100;
int separator = 40;
std::array<ResultTable, 4> results = {
{
ResultTable(0,players[0].cash, players[0].reachedPortal,players[0].reachedPortalFirst),
ResultTable(1,players[1].cash, players[1].reachedPortal,players[1].reachedPortalFirst),
ResultTable(2,players[2].cash, players[2].reachedPortal,players[2].reachedPortalFirst),
ResultTable(3,players[3].cash, players[3].reachedPortal,players[3].reachedPortalFirst)
}
};
std::vector < ResultTable > resultsVector;
txtSurvivors.clear();
txtLoosers.clear();
for (int i=0;i<4;i++)
{
resultsVector.push_back(results[i]);
};
std::sort(resultsVector.begin(), resultsVector.end());
txtWinner.setFont(gameFont);
txtWinner.setCharacterSize(40);
for (int i=0;i<4;i++)
{
int playerNumber = resultsVector[i].playerNumber;
std::string elementName = elementNames[playerNumber];
sf::Text tmpText;
tmpText.setFont(gameFont);
tmpText.setCharacterSize(25);
tmpText.setString(elementName+ " " + std::to_string(players[playerNumber].cash));
sf::FloatRect rectTxt = tmpText.getLocalBounds();
if (players[playerNumber].reachedPortal==true)
{
int counter = txtSurvivors.size();
tmpText.setPosition((1360/2)-(rectTxt.width/2),200+(counter*separator));
txtSurvivors.push_back(tmpText);
} else
{
int counter = txtLoosers.size();
tmpText.setPosition((width/2)-(rectTxt.width/2),540+(counter*separator));
txtLoosers.push_back(tmpText);
}
}
if (txtSurvivors.size()>0)
{
txtWinner.setString("Winner: " + txtSurvivors[0].getString());
txtSurvivors.erase(txtSurvivors.begin()+0);
}
txtWinner.setCharacterSize(40);
sf::FloatRect rectTxt = txtWinner.getLocalBounds();
txtWinner.setPosition((1360/2)-(rectTxt.width/2),120);
}
void Game::initBoard()
{
time_t t = time(0);
struct tm * now = localtime( & t );
int month = now->tm_mon + 1;
int day = now->tm_mday;
paganHolidayString = getHoliday(month, day);
// std::cout << "HOLIDAY"<< paganHolidayString << std::endl;
paganHolidayTxt.setString(paganHolidayString);
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
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);
cardsDeck.setFonts(&gameFont);
+ spriteBigDiamond.setTexture(textures.textureBigDiamond);
+ spriteBigDiamond.setPosition(474,342);
+ spriteBigDiamond.setColor(sf::Color (255, 255, 255,196));
restartGame();
launchNextPlayer();
// for (int i=0;i<4;i++)
// {
// endGameTxtAmount[i].setFont(gameFont);
// endGameTxtAmount[i].setCharacterSize(25);
// }
endGameTxt.setFont(gameFont);
endGameTxt.setString("End of the Game");
endGameTxt.setCharacterSize(30);
sf::FloatRect ss = endGameTxt.getLocalBounds();
endGameTxt.setPosition((1360/2)-(ss.width/2),60);
setTxtEndGameAmount();
bubble.setPosition(players[turn].characters[0].getPosition().x-30,
players[turn].characters[0].getPosition().y-45);
// endGameTxt.set
// endGameTxt.setScale(2,2);
txtSurvivorsLabel.setString("Survivors");
txtSurvivorsLabel.setFont(gameFont);
txtSurvivorsLabel.setCharacterSize(30);
sf::FloatRect rectSurvivors = txtSurvivorsLabel.getLocalBounds();
txtSurvivorsLabel.setPosition((1360/2)-(rectSurvivors.width/2),200);
txtLoosersLabel.setString("Digested by The Elements");
txtLoosersLabel.setFont(gameFont);
txtLoosersLabel.setCharacterSize(30);
sf::FloatRect rectLoosers = txtLoosersLabel.getLocalBounds();
txtLoosersLabel.setPosition((1360/2)-(rectLoosers.width/2),500);
}
/*!
* \brief Game::restartGame sets all the variables to the default value
*/
void Game::restartGame()
{
Player playerHud1(&textures, &gameFont,0);
Player playerHud2(&textures, &gameFont,1);
Player playerHud3(&textures, &gameFont,2);
Player playerHud4(&textures, &gameFont,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);
for (int i=0;i<4;i++)
{
players[i].restartPlayer();
players[i].reachedPortal = false;
boardDiamonds.reorder(i);
bubble.setPosition(players[i].characters[0].getPosition().x-30,
players[i].characters[0].getPosition().y-45);
players[i].done=false;
}
numberFinishedPlayers = 0;
turn = 0;
currentSeason = 1;
roundNumber = 1;
month = 0;
cardsDeck.reloadCards();
deerModeActive = false;
deerModeCounter = 16;
}
void Game::setCurrentNeighbours ()
{
currentNeighbours = players[turn].getNeighbours();
}
/*!
* \brief Game::loadAssets
*/
void Game::loadAssets()
{
if (!gameFont.loadFromFile("assets/fnt/metal-mania.regular.ttf"))
{
std::exit(1);
}
if (!menuFont.loadFromFile("assets/fnt/metal-macabre.regular.ttf"))
{
std::exit(1);
}
menuBackground.setTexture(textures.textureMenu);
spriteDeerGod.setTexture(textures.textureDeerGod);
if (!shaderBlur.loadFromFile("assets/shaders/blur.frag", sf::Shader::Fragment))
std::exit(1);
if (!shaderPixel.loadFromFile("assets/shaders/pixelate.frag", sf::Shader::Fragment))
std::exit(1);
if (!shaderDark.loadFromFile("assets/shaders/dark.frag", sf::Shader::Fragment))
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(gameFont);
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);
paganHolidayTxt.setFont(gameFont);
paganHolidayTxt.setCharacterSize(20);
paganHolidayTxt.setPosition(20,20);
for (int i=0;i<4;i++)
{
playersSprites[i].setTexture(textureBackgroundArt);
playersSprites[i].setTextureRect(sf::IntRect(playersSpritesCords[i][0],
playersSpritesCords[i][1], 280, 280));
playersSprites[i].setPosition(playersSpritesCords[i][0], playersSpritesCords[i][1]);
}
}
void Game::showMenu()
{
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_setup_players;
// currentState = state_lets_begin;
}
void Game::endGame()
{
currentState = state_end_game;
downTimeCounter = 0;
numberFinishedPlayers = 4;
setTxtEndGameAmount();
// musicBackground.stop();
}
void Game::throwDiceMove() {
// Throw a dice action
diceResultPlayer = roundDice.throwDiceSix();
players[turn].characters[0].diceResult=diceResultPlayer;
currentState = state_game;
bubble.state = BubbleState::MOVE;
nextRotateElem.reset();
prevRotateElem.reset();
}
/*!
* \brief Game::playerMakeMove move the player into the position on the map
* \param mousePos
*/
void Game::playerMakeMove(int mousePos) {
players[turn].setFigurePos(mousePos);
commandManager.processField(mousePos);
const int *possibleExit = std::find(std::begin(efc::endPlayers),
std::end(efc::endPlayers), mousePos);
if (possibleExit != efc::endPlayers+4) {
players[turn].done=true;
players[turn].reachedPortal=true;
commandManager.removeAllItems(turn);
if (numberFinishedPlayers == 0)
{
players[turn].reachedPortalFirst=true;
+ int turnover = (rand() % 2)+5;
+
+ players[turn].cash += turnover;
+ players[turn].updatePlayer();
startDeerMode();
}
numberFinishedPlayers += 1;
if (numberFinishedPlayers > 3)
{
endGame();
return;
}
}
nextPlayer();
return;
}
+int Game::mostDiamonds()
+{
+
+ std::array<int,4> results = {players[0].cash,players[1].cash,players[2].cash,players[3].cash};
+
+ auto minmax = std::minmax_element(std::begin(results), std::end(results));
+
+ std::cout << "max element " << *(minmax.second) << "\n";
+
+ int maxResult = *(minmax.second);
+
+ int result = 0;
+ int pos = -1;
+ for (int i=0; i<4;i++)
+ {
+ if (players[i].cash == maxResult)
+ {
+ result += 1;
+ pos = i;
+ }
+ };
+
+ if (result==1)
+ {
+ return pos;
+ }
+
+ return -1;
+
+}
+
/*!
* \brief Game::handleLeftClick
* \param pos
* \param posFull
* \param mousePos
*/
void Game::handleLeftClick(sf::Vector2f pos,sf::Vector2f posFull, int mousePos) {
if (currentState==state_game)
{
if (players[turn].human)
{
std::array<int,2> movements = players[turn].getMovements(diceResultPlayer);
if ((mousePos==movements[0]) || (mousePos==movements[1]))
{
playerMakeMove(mousePos);
}
}
}
if (currentState==state_setup_players)
{
for (int i=0;i<4;i++)
{
sf::IntRect spriteHumanRect(players[i].spriteAI.getGlobalBounds());
if (spriteHumanRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
players[i].swapHuman();
}
}
sf::IntRect startGameRect(580,640,180,80);
if (startGameRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
+ bigDiamondActive = true;
banner.setText("start game");
currentState=state_roll_dice;
launchNextPlayer();
return;
}
}
else if (currentState==state_roll_dice)
{
if (players[turn].human){
sf::IntRect diceRect(roundDice.spriteDice.getGlobalBounds());
if (diceRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
throwDiceMove();
}
}
}
if (currentState==state_menu)
{
downTimeCounter = 0;
hideMenu();
showGameBoard();
return;
}
if (currentState==state_gui_end_round)
{
std::string resultCommand = guiRoundDice.getElem(pos);
command(resultCommand);
}
if (currentState==state_lets_begin)
{
if (downTimeCounter>1)
{
currentState = state_roll_dice;
restartGame();
launchNextPlayer();
return;
}
}
if (currentState==state_end_game)
{
if (downTimeCounter>2)
{
currentState = state_menu;
restartGame();
return ;
// restartGame();
}
}
}
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),
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),
particleSystem( 430, 230),
commandManager(*this),
cardsDeck(&textures, &menuFont,&commandManager),
deerModeCounter(4),
deerModeActive(false),
- banner(&gameFont)
+ banner(&gameFont),
+ bigDiamondActive(false),
+ oscilator(-1),
+ oscilatorInc(true)
{
// TODO: perhaps get rid of the particles at all...
particleSystem.setDissolve( true );
particleSystem.setDissolutionRate( 10 );
particleSystem.setShape( Shape::CIRCLE );
particleSystem.fuel( 1000 );
playersSpritesCords[0][0] = 202;
playersSpritesCords[0][1] = 76;
playersSpritesCords[1][0] = 562;
playersSpritesCords[1][1] = 76;
playersSpritesCords[3][0] = 202;
playersSpritesCords[3][1] = 436;
playersSpritesCords[2][0] = 562;
playersSpritesCords[2][1] = 436;
textLoading.setString("loading...");
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
renderTexture.create(1360,768);
renderTexture.clear(sf::Color::White);
renderTexture.draw(textLoading);
renderTexture.display();
renderSprite.setTexture(renderTexture.getTexture());
numberFinishedPlayers = 0;
sf::Clock frameClock;
guiRoundDice.active = true;
showPlayerBoardElems = false;
window.setVerticalSyncEnabled(true);
std::srand (time(NULL));
window.clear(sf::Color(55,55,55));
renderTexture.draw(textLoading);
window.display();
loadAssets();
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
renderTexture.clear(sf::Color::Black);
renderTexture.draw(textLoading);
window.display();
initBoard();
renderTexture.clear(sf::Color::Black);
renderTexture.draw(textLoading);
renderTexture.display();
showMenu();
// run the main loop
while (window.isOpen())
{
sf::Time frameTime = frameClock.restart();
// handle events
sf::Event event;
float xpos = 320.0f;
float ypos = 240.0f;
float xgrv = 0.0f;
float ygrv = 0.0f;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close(); break;
case sf::Event::KeyPressed:
if(event.key.code == sf::Keyboard::Escape )
window.close();
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Space ) )
particleSystem.fuel( 200/* * window.getFrameTime() */);
if( sf::Keyboard::isKeyPressed( sf::Keyboard::A ) )
particleSystem.setPosition( --xpos, ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
particleSystem.setPosition( ++xpos, ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::W ) )
particleSystem.setPosition( xpos, --ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::S ) )
particleSystem.setPosition( xpos, ++ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
particleSystem.setGravity( --xgrv * 0.1f, ygrv * 0.1f);
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
particleSystem.setGravity( ++xgrv * 0.1f, ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
particleSystem.setGravity( xgrv * 0.1f, --ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
particleSystem.setGravity( xgrv * 0.1f, ++ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::G ) )
particleSystem.setGravity( 0.0f, 0.0f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::P ) )
particleSystem.setPosition( 320.0f, 240.0f );
break;
default:
break;
}
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();
// 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,
localPositionFull, mousePos);
}
}
update(frameTime);
render(frameTime.asSeconds());
}
}
void Game::update(sf::Time frameTime) {
banner.update(frameTime);
runningCounter += frameTime.asSeconds();
cpuTimeThinking -= frameTime.asSeconds();
+
+ if (oscilatorInc)
+ {
+ oscilator += frameTime.asSeconds();
+ } else {
+ oscilator -= frameTime.asSeconds();
+ }
+
+ if (oscilator<-1)
+ oscilatorInc = true;
+
+ if (oscilator>1)
+ oscilatorInc = false;
+
+
+ float modifier = sin(oscilator/2.5)*30.0f;
+ spriteBigDiamond.setPosition(474,342+modifier);
+
+
+
if (currentState==state_roll_dice)
{
if ((cpuTimeThinking<0) && (players[turn].human==false))
{
cpuTimeThinking = 1;
throwDiceMove();
}
}
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].getMovements(diceResultPlayer);
if ((cpuTimeThinking<0) && (players[turn].human==false))
{
std::vector<int> listRandomPos;
if (currentMovements[0]>-1) {
listRandomPos.push_back(currentMovements[0]);
}
if (currentMovements[1]>-1) {
listRandomPos.push_back(currentMovements[1]);
}
unsigned int sizeRndPos = listRandomPos.size();
if (sizeRndPos==0) {
} else if (sizeRndPos==1) {
playerMakeMove(listRandomPos[0]);
} else if (sizeRndPos==2) {
- int randPos = rand() % 2;
- playerMakeMove(listRandomPos[randPos]);
+
+ if (deerModeActive)
+ {
+ std::cout<<"goes deermode"<<std::endl;
+ playerMakeMove(listRandomPos[1]);
+ } else
+ {
+ if (players[turn].reachPortalMode == true)
+ {
+ std::cout<<"goes portal"<<std::endl;
+ playerMakeMove(listRandomPos[1]);
+ }
+ else
+ {
+ int randPos = rand() % 2;
+ std::cout<<"goes collect"<<std::endl;
+ playerMakeMove(listRandomPos[randPos]);
+ };
+ }
}
}
if (currentMovements[0]>-1)
{
prevRotateElem.spriteRotate.setPosition(players[turn].characters[0].leftChar.getPosition());
prevRotateElem.spriteRotate.move(10,20);
// Modificator to fit on the bigger view
prevRotateElem.spriteRotate.move(-202,-76);
prevRotateElem.update(frameTime);
prevRotateElem.setColor();
}
if (currentMovements[1]>-1)
{
nextRotateElem.spriteRotate.setPosition(players[turn].characters[0].rightChar.getPosition());
nextRotateElem.spriteRotate.move(10,20);
// Modificator to fit on the bigger view
nextRotateElem.spriteRotate.move(-202,-76);
nextRotateElem.update(frameTime);
nextRotateElem.setColor();
}
}
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>5)
{
currentState = state_roll_dice;
bubble.state = BubbleState::DICE;
}
}
if (currentState==state_end_game)
{
downTimeCounter += frameTime.asSeconds();
}
bubble.update(frameTime);
+
+
}
/*!
* \brief Game::nextRound is happening each every 4 months
*/
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();
launchNextPlayer();
}
/*!
* \brief Game::nextPlayer calculates which player should play
*/
void Game::nextPlayer(){
// End of game - we don't calculate more players
if (currentState==state_end_game)
{
return;
}
// End of game - we don't calculate more players
if (numberFinishedPlayers==4)
{
// std::cout << "Everybody Finished!!!" << std::endl;
endGame();
return ;
}
// Update old player
players[turn].updatePlayer();
if (turn>2)
{
nextRound();
return;
}
turn++;
// if (players[turn].done==true)
// {
// // std::cout << "Player " << turn << " is done" << std::endl;
// nextPlayer();
// return;
// }
launchNextPlayer();
}
void Game::launchNextPlayer(){
if (deerModeActive)
{
deerModeCounter -= 1;
}
if (deerModeCounter<0)
{
endGame();
return ;
}
// Just control
if (players[turn].done==true)
{
// std::cout << "Player " << turn << " is done" << std::endl;
nextPlayer();
return;
}
// Frozen player
if (players[turn].frozenLeft>0)
{
players[turn].frozenLeft -= 1;
nextPlayer();
return;
}
// Here we process new player
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);
if (deerModeActive==false)
{
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
} else
{
groupHud.setDeerModeActive();
int number = (deerModeCounter/4);
if (deerModeCounter<16)
number += 1;
if (number<0)
{
endGame();
return;
}
groupHud.setDeerModeCounter(number);
}
currentState = state_roll_dice;
bubble.state = BubbleState::DICE;
roundDice.setColor(turn);
bubble.setPosition(players[turn].characters[0].getPosition().x-30,
players[turn].characters[0].getPosition().y-45);
cpuTimeThinking = 1;
+ if (mostDiamonds()==turn)
+ {
+ players[turn].reachPortalMode = true;
+ } else {
+ players[turn].reachPortalMode = false;
+
+ }
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i]);
}
}
void Game::drawSquares() {
if (showPlayerBoardElems)
{
renderTexture.draw(selector);
}
}
void Game::drawBaseGame()
{
renderTexture.setView(viewTiles);
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i].elems);
}
drawSquares();
renderTexture.setView(viewGui);
renderTexture.setView(viewTiles);
renderTexture.setView(viewTiles); // Yeah Katia's inspiration
shaderBlur.setParameter("blur_radius", sin(runningCounter*0.01f) );
// renderTexture.draw(gameBackground);
renderTexture.setView(viewFull);
// renderTexture.draw(spriteBackgroundArt, &shaderDark);
// spriteBackgroundArt.setColor(sf::Color(255, 255, 255, 208));
shaderBlur.setParameter("blur_radius", 0.01);
// shaderBlur.setParameter("blur_radius", sin(runningCounter*0.01) );
// shaderBlur.setParameter("blur_radius", sin(runningCounter*0.01) );
shaderPixel.setParameter("pixel_threshold", sin(runningCounter* 0.005f));
renderTexture.draw(spriteBackgroundArt);
spriteBackgroundArt.setColor(sf::Color(255, 255, 255));
shaderBlur.setParameter("blur_radius", sin(runningCounter* 0.05f)/2);
renderTexture.draw(cardsDeck);
if (currentState==state_roll_dice)
{
spriteBackgroundArt.setColor(sf::Color(255, 255, 255));
shaderBlur.setParameter("blur_radius", sin(runningCounter* 0.5f)/4);
renderTexture.draw(roundDice.spriteDice);
}
else
renderTexture.draw(roundDice.spriteDice);
renderTexture.setView(viewTiles);
drawSquares();
}
void Game::drawCharacters(){
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].characters[0].getMovements(diceResultPlayer);
if (currentMovements[1]>-1)
{
if (nextRotateElem.active)
renderTexture.draw(nextRotateElem);
}
if (currentMovements[0]>-1)
{
if (prevRotateElem.active)
renderTexture.draw(prevRotateElem);
}
}
renderTexture.setView(viewFull);
shaderBlur.setParameter("blur_radius", 0.005f);
for (int i=0;i<4;i++)
{
for (auto&& j: players[i].characters)
{
if (currentState==state_game)
j.drawMovements = true;
else
j.drawMovements = false;
renderTexture.draw(j);
// renderTexture.draw(j, &shaderBlur);
}
}
}
/*!
* \brief Game::render main function responsible for drawing all elements
* \param deltaTime
*/
void Game::render(float deltaTime)
{
window.clear();
renderTexture.clear();
if ((currentState==state_game) or (currentState==state_roll_dice))
{
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
renderTexture.setView(viewTiles);
drawBaseGame();
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
renderTexture.setView(viewTiles);
drawCharacters();
renderTexture.draw(boardDiamonds);
renderTexture.draw(bubble);
renderTexture.setView(viewFull);
drawPlayersGui();
renderTexture.setView(viewFull);
} else if (currentState==state_setup_players) {
renderTexture.setView(viewFull);
renderTexture.draw(spriteDeerGod);
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i].spriteAI);
}
} else if (currentState==state_gui_elem) {
renderTexture.setView(viewFull);
shaderBlur.setParameter("blur_radius", 2);
renderTexture.draw(spriteBackgroundDark, &shaderBlur);
drawBaseGame();
drawCharacters();
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
} else if (currentState==state_menu) {
shaderBlur.setParameter("blur_radius", 15);
renderTexture.draw(menuBackground);
// renderTexture.draw(menuTxt, &shaderBlur);
// renderTexture.draw(menuTxt);
renderTexture.draw(paganHolidayTxt);
} else if (currentState==state_lets_begin) {
renderTexture.setView(viewFull);
shaderBlur.setParameter("blur_radius", 4);
renderTexture.draw(spriteBackgroundDark, &shaderBlur);
renderTexture.setView(viewTiles);
drawBaseGame();
drawCharacters();
renderTexture.draw(boardDiamonds, &shaderBlur);
renderTexture.setView(viewFull);
drawPlayersGui();
renderTexture.draw(spriteLestBegin,&shaderBlur);
} else if (currentState==state_gui_end_round){
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
drawBaseGame();
shaderBlur.setParameter("blur_radius", 0.05f);
renderTexture.draw(guiRoundDice, &shaderBlur);
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
}
else if (currentState==state_end_game){
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
renderTexture.draw(spriteLestBegin,&shaderBlur);
renderTexture.draw(endGameTxt);
// for (int i=0;i<4;i++){
// if (players[i].reachedPortal)
// renderTexture.draw(endGameTxtAmount[i]);
// }
renderTexture.draw(txtWinner);
renderTexture.draw(txtSurvivorsLabel);
for (unsigned int i=0; i<txtSurvivors.size();i++) {
renderTexture.draw(txtSurvivors[i]);
}
renderTexture.draw(txtLoosersLabel);
for (unsigned int i=0; i<txtLoosers.size();i++) {
renderTexture.draw(txtLoosers[i]);
}
}
+ if (bigDiamondActive)
+ renderTexture.draw(spriteBigDiamond);
if (banner.active)
renderTexture.draw(banner);
+
+
renderTexture.display();
renderSprite.setTexture(renderTexture.getTexture());
shaderBlur.setParameter("blur_radius", sin(deltaTime)*0.015f);
shaderBlur.setParameter("blur_radius", 0.0003f);
window.draw(renderSprite, &shaderBlur);
particleSystem.remove();
particleSystem.update();
particleSystem.render();
window.draw( particleSystem.getSprite() );
window.display();
}
void Game::command(std::string command){
if (command.compare("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();
}
/*!
* \brief Game::startDeerMode launches last episode of the game
*/
void Game::startDeerMode() {
deerModeActive = true;
deerModeCounter = 16;
banner.setText("deer mode");
+ bigDiamondActive = false;
}
}
diff --git a/game.h b/game.h
index d6b74d7..a06600d 100644
--- a/game.h
+++ b/game.h
@@ -1,206 +1,213 @@
#ifndef GAME_H
#define GAME_H
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <time.h> /* time */
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "command.h"
#include "tilemap.h"
#include "selector.h"
#include "playerhud.h"
#include "textureholder.h"
#include "hover.h"
#include "guiwindow.h"
#include "rounddice.h"
#include "guirounddice.h"
#include "grouphud.h"
#include "animatedsprite.h"
#include "character.h"
#include "rotateelem.h"
#include "boarddiamondseq.h"
#include "soundfx.h"
#include "cardsdeck.h"
#include "calendar.h"
#include "particle.h"
#include "bubble.h"
//class Command;
#include "banner.h"
namespace efc {
extern int initScreenX;
extern int initScreenY;
/*!
* \brief Game is a main class of the Deer Portal - contains most logic but also rendering.
*/
class Game
{
public:
sf::Vector2i screenSize;
sf::View viewFull;
sf::View viewGui;
sf::View viewTiles;
void setTxtEndGameAmount();
private:
Selector selector;
Character character;
std::string gameTitle;
std::string paganHolidayString;
RoundDice roundDice;
int roundNumber;
GuiRoundDice guiRoundDice;
public:
Game();
BoardDiamondSeq boardDiamonds;
sf::RenderWindow window;
sf::RenderTexture renderTexture;
sf::Sprite renderSprite;
Player players[4];
SoundFX sfx;
int turn;
private:
void initBoard();
void restartGame();
void loadAssets();
void drawPlayersGui();
void drawSquares();
void drawMenu();
float runningCounter;
+ float oscilator;
+ bool oscilatorInc;
sf::Sprite playersSprites[4] ;
int playersSpritesCords[4][2];
enum states {
state_init,
state_menu,
state_setup_players,
state_lets_begin,
state_roll_dice,
state_game,
state_gui_elem,
state_select_building,
state_gui_end_round,
state_end_game,
state_quit
};
states currentState;
sf::Sprite spriteDeerGod;
sf::Sprite spriteBackgroundDark;
sf::Sprite spriteLestBegin;
sf::Texture textureBackgroundArt;
sf::Sprite spriteBackgroundArt;
sf::Texture textureTiles;
sf::Texture textureFaces;
sf::Font gameFont;
sf::Font menuFont;
sf::Text menuTxt;
sf::Text endGameTxt;
sf::Text endGameTxtAmount[4];
sf::Text paganHolidayTxt;
sf::Shader shaderBlur;
sf::Shader shaderPixel;
sf::Shader shaderDark;
int mapSize;
int level[256];
int levelElems[256];
TextureHolder textures;
std::set<int> currentNeighbours;
void command(std::string command);
int selectedPos;
void update(sf::Time frameTime);
void render(float deltaTime);
ParticleSystem particleSystem;
void setCurrentNeighbours ();
void nextPlayer();
void launchNextPlayer();
void nextRound();
sf::Sprite menuBackground;
sf::Sprite seasons[4];
sf::Music musicGame;
sf::Music musicMenu;
sf::SoundBuffer sfxClickBuffer;
sf::Sound sfxClick;
sf::SoundBuffer sfxDoneBuffer;
sf::Sound sfxDone;
void showMenu();
void hideMenu();
void showGameBoard();
void hideGameBoard();
GroupHud groupHud;
/*!
* \brief showPlayerBoardElems defines if show mouse hover for the player
*/
bool showPlayerBoardElems;
void drawBaseGame();
int month;
Animation walkingAnimationDown;
Animation walkingAnimationUp;
Animation walkingAnimationLeft;
Animation walkingAnimationRight;
Animation* currentAnimation;
AnimatedSprite animatedSprite;
void drawCharacters();
void handleLeftClick(sf::Vector2f pos, sf::Vector2f posFull, int mousePos);
std::set<int> busyTiles;
int diceResultPlayer;
int numberFinishedPlayers;
RotateElem nextRotateElem;
RotateElem prevRotateElem;
void endGame();
float downTimeCounter;
Command commandManager;
sf::Text textLoading;
public:
CardsDeck cardsDeck;
void startDeerMode();
sf::Text txtWinner;
sf::Text txtSurvivorsLabel;
sf::Text txtLoosersLabel;
std::vector<sf::Text> txtSurvivors;
std::vector<sf::Text> txtLoosers;
void throwDiceMove();
void playerMakeMove(int mousePos);
float cpuTimeThinking;
Banner banner;
+ sf::Sprite spriteBigDiamond;
+ bool bigDiamondActive;
+
+ int mostDiamonds();
+
private:
Bubble bubble;
int deerModeCounter;
bool deerModeActive;
};
}
#endif // GAME_H
diff --git a/playerhud.cpp b/playerhud.cpp
index 3ae80e0..2ffea3e 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,265 +1,246 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
std::set<int> Player::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
std::set<int> Player::getBusy(){
std::set<int> busyTiles;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
busyTiles.insert(i.first);
}
return busyTiles;
}
std::set<int> Player::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))
{
neighbours.insert(j);
}
}
}
return neighbours;
}
void Player::updateTxt(){
txtCash.setString(std::to_string(cash));
}
void Player::updatePlayer(){
updateTxt();
}
Player::Player():
frozenLeft(0),
reachedPortal(false),
reachedPortalFirst(false),
- human(false)
+ human(false),
+ reachPortalMode(false)
{
pos = 0;
cash = 0;
energy = 0;
food = 0;
faith = 0;
active = false;
done = false;
tileSize = 0;
textures = nullptr;
number = 0;
-// setSpriteAI();
}
void Player::setActive(bool newState){
active = newState;
elems.active = newState;
for (auto&& i: characters)
{
i.active = newState;
}
}
Player::Player(TextureHolder *textures, sf::Font *gameFont, int playerNumber):
reachedPortal(false),
reachedPortalFirst(false),
- human(false)
-
+ human(false),
+ reachPortalMode(false)
{
number = playerNumber;
frozenLeft = 0;
done = false;
active = false;
this->textures = textures;
-// Character character(this->textures, pos);
characters.push_back(Character (this->textures, playerNumber));
-// 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 = playerNumber;
-
-// 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,(playerNumber*100)+10);
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[playerNumber][0],textPos[playerNumber][1] );
buttons.insert({"end_turn",rectangle});
setSpriteAI();
}
std::string Player::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 Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(txtCash, states);
}
void Player::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void Player::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> Player::getMovements(int diceResult)
{
return characters[0].getMovements(diceResult);
}
void Player::setFigurePos(int pos)
{
characters[0].setBoardPosition(pos);
}
void Player::restartPlayer(){
food = 0;
cash = 0;
energy = 0;
faith = 0;
}
void Player::setHuman(bool newHuman)
{
human = newHuman;
setSpriteAI();
}
void Player::swapHuman()
{
if (human)
{
setHuman(false);
return;
} else {
setHuman(true);
return;
}
}
void Player::setSpriteAI()
{
if (human)
spriteAI.setTexture(textures->textureButtonHuman);
else
spriteAI.setTexture(textures->textureButtonCpu);
std::array<std::array<int,2>,4> spriteHumanPos =
{
{
{{220,450}}, {{1050,450}},
{{140,600}}, {{1110, 600}}
}
};
sf::Vector2f spriteHumanPosNew(spriteHumanPos[number][0],spriteHumanPos[number][1]);
spriteAI.setPosition(spriteHumanPosNew);
}
diff --git a/playerhud.h b/playerhud.h
index 595d110..1019774 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,88 +1,89 @@
#ifndef PLAYERHUD_H
#define PLAYERHUD_H
#include <iostream>
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "boardelems.h"
#include "textureholder.h"
#include "elemsdescription.h"
#include "guiwindow.h"
#include "character.h"
#include "data.h"
class Player : public sf::Drawable, public sf::Transformable
{
public:
Player();
Player(TextureHolder *textures, sf::Font *gameFont, int pos);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
std::set<int> getNeighbours();
int pos;
int cash;
int energy;
int food;
int faith;
bool active;
BoardElems elems;
void setActive(bool newState);
std::vector<int> properties;
void updatePlayer();
std::string getElem(sf::Vector2f mousePosition);
std::map<std::string, sf::RectangleShape> buttons;
void updateTxt();
std::vector<Character> characters;
void update(sf::Time deltaTime);
void play();
std::set<int> getBusy();
std::array<int,2> getMovements(int diceResult);
void setFigurePos(int pos);
bool done;
int frozenLeft;
void restartPlayer();
bool reachedPortal;
bool reachedPortalFirst;
bool human;
sf::Sprite spriteAI;
void setSpriteAI();
void setHuman(bool newHuman);
int number;
void swapHuman();
+ bool reachPortalMode;
+
private:
// sf::Sprite spriteFace;
sf::Text txtCash;
sf::Text txtEnergy;
sf::Text txtFood;
sf::Text txtFaith;
sf::Text txtNextRound;
// int faceSize;
int tileSize;
TextureHolder *textures;
sf::RectangleShape rectangle;
sf::RectangleShape rectangle2;
sf::Sprite symbol;
std::set<int> getTerrainSet();
-
};
#endif // PLAYERHUD_H
diff --git a/textureholder.cpp b/textureholder.cpp
index 80a9cee..a6ef808 100644
--- a/textureholder.cpp
+++ b/textureholder.cpp
@@ -1,152 +1,154 @@
#include <iostream>
#include "textureholder.h"
namespace efc {
std::set<int> getTerrainSet() {
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
}
TextureHolder::TextureHolder()
{
// "stop", "card", "diamond", "diamond x 2"
std::string cardsImages[4][4] = {
{"card-water-stop.small.png", "card-water-remove-card.small.png","card-water-diam.small.png", "card-water-2-diam.small.png" },
{"card-earth-stop.small.png", "card-earth-remove-card.small.png","card-earth-diam.small.png", "card-earth-2-diam.small.png"},
{"card-fire-stop.small.png", "card-fire-remove-card.small.png","card-fire-diam.small.png", "card-fire-2-diam.small.png"},
{"card-air-stop.small.png", "card-air-remove-card.small.png", "card-air-diam.small.png", "card-air-2-diam.small.png" }
};
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
if(!cardsTextures[i][j].loadFromFile("assets/img/cards/"+cardsImages[i][j]))
{
// std::cout << "assets/img/cards/" << cardsImages[i][j];
std::exit(1);
} else {
// std::cout << "assets/img/cards/" << cardsImages[i][j] << " ok " << i << " " << j << " " << std::endl;
}
}
}
if (!textureCardBases[0].loadFromFile("assets/img/card-water-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[1].loadFromFile("assets/img/card-earth-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[2].loadFromFile("assets/img/card-fire-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[3].loadFromFile("assets/img/card-air-2-diam_m.png"))
std::exit(1);
// if (!textureGameBackground.loadFromFile("assets/img/game-ackground.png"))
// std::exit(1);
// if (!textureTiles.loadFromFile("assets/img/zw-tilesets/_MAP.png"))
// std::exit(1);
// if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
// std::exit(1);
// if (!textureGui.loadFromFile("assets/img/gui.png"))
// std::exit(1);
// if (!textureSymbols.loadFromFile("assets/img/symbols.png"))
// std::exit(1);
// if (!textureSeasons.loadFromFile("assets/img/seasons.png"))
// std::exit(1);
if (!textureCharacters.loadFromFile("assets/img/characters-new.png"))
std::exit(1);
if (!backgroundDark.loadFromFile("assets/img/background_dark.png"))
std::exit(1);
if (!textureBoardDiamond.loadFromFile("assets/img/board_diamonds.png"))
std::exit(1);
if (!textureMenu.loadFromFile("assets/img/dp_intro_menu.png"))
std::exit(1);
if (!textureLetsBegin.loadFromFile("assets/img/letsbegin.png"))
std::exit(1);
if (!textureButtonCpu.loadFromFile("assets/img/button-cpu.png"))
std::exit(1);
if (!textureButtonHuman.loadFromFile("assets/img/button-human.png"))
std::exit(1);
if (!textureDeerGod.loadFromFile("assets/img/deer-god.png"))
std::exit(1);
+ if (!textureBigDiamond.loadFromFile("assets/img/diamond-big.png"))
+ std::exit(1);
int defaultArray[5][8] = {
//Cash Food Energy Faith
{10, 2, 0, 0, 0, 0, 0, 0}, // base
{10, 1, 2, 0, 0, 5, 0, 0}, // windmill
{15, 0, 0, 2, 2, 0, 0, 0}, // granary
{20, 5, 4, 0, 4, 0, 0, 0}, // marketplace
{5, 0, 2, 0, 0, 0, 0, 2} // monasterium
};
int defaultFields[5] = {443, 651, 442, 585, 1100};
/*
* Array with description of the field
* global rule = even indexes are price, odd - monthly cost
* [0] - price in cash
* [1] - monthly cash cost
* [2] - price - in food
* [3] - monthly food cost
* [4] - price in energy
* [5] - monthly energy cost
* [6] - price in faith
* [7] - monthly cost in faith
*
*/
int counter = 0;
for (int i: defaultFields)
{
std::map<int, int> params;
for (int j=0;j<8;j++)
{
params.insert({j, defaultArray[counter][j]});
}
// params.insert({0, 10});
// params.insert({1, 2});
// params.insert({2, 10});
// params.insert({3, 0});
// params.insert({4, 10});
// params.insert({5, 0});
// params.insert({6, 0});
// params.insert({7, 0});
tilesDescription.insert({i, params});
counter++;
};
tilesTxt.insert({443, "Your base."});
tilesTxt.insert({651, "Windmill, produces energy.\nEnergy is a basic resource in a game,\nneeded by other buildings to running them."});
tilesTxt.insert({442, "Granary, food storehouse.\nFood gives your people ability to live.\nWithout the food your people will face\na death by starvation."});
tilesTxt.insert({585, "Marketplace, generates cash.\nProvides your tribe trading area.\nToday's offer - dog's bone."});
tilesTxt.insert({1100, "Monasterium, increase your faith.\nAs we all know, our world is being ruled\nby four ancient gods..."});
}
diff --git a/textureholder.h b/textureholder.h
index a0b3542..40af92c 100644
--- a/textureholder.h
+++ b/textureholder.h
@@ -1,57 +1,57 @@
#ifndef TEXTUREHOLDER_H
#define TEXTUREHOLDER_H
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "data.h"
#include <array>
namespace efc {
std::set<int> getTerrainSet();
}
/*!
* \brief The TextureHolder contains most textures.
*/
class TextureHolder
{
public:
TextureHolder();
// sf::Texture textureTiles;
// sf::Texture textureFaces;
// sf::Texture textureGui;
sf::Texture textureMenu;
// sf::Texture textureSymbols;
// sf::Texture textureSeasons;
sf::Texture backgroundDark;
sf::Texture textureCharacters;
// sf::Texture textureGameBackground;
sf::Texture textureBoardDiamond;
sf::Texture textureLetsBegin;
sf::Texture textureCardBase0;
sf::Texture textureCardBase1;
sf::Texture textureCardBase2;
sf::Texture textureCardBase3;
sf::Texture textureButtonCpu;
sf::Texture textureButtonHuman;
sf::Texture textureDeerGod;
std::array<sf::Texture, 4> textureCardBases;
std::map<int, std::map<int, int>> tilesDescription;
std::map<int, std::string> tilesTxt;
std::array<std::array<sf::Texture,4>,4> cardsTextures;
-
+ sf::Texture textureBigDiamond;
};
#endif // TEXTUREHOLDER_H

File Metadata

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

Event Timeline