Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
46 KB
Referenced Files
None
Subscribers
None
diff --git a/boarddiamond.cpp b/boarddiamond.cpp
index 6e92135..849a4a5 100644
--- a/boarddiamond.cpp
+++ b/boarddiamond.cpp
@@ -1,38 +1,38 @@
#include "boarddiamond.h"
BoardDiamond::BoardDiamond()
{
}
BoardDiamond::BoardDiamond(TextureHolder *textures, int idNumber,
int playerNumber, int boardPosition)
{
this->textures = textures;
this->playerNumber = playerNumber;
this->boardPosition = boardPosition;
this->idNumber = idNumber;
spriteHolder.setTexture(this->textures->textureBoardDiamond);
sf::IntRect textureRect(idNumber*44, 0, 44,44);
spriteHolder.setTextureRect(textureRect);
spriteHolder.scale(0.5, 0.5);
setBoardPosition(boardPosition);
}
void BoardDiamond::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
if (boardPosition>-1)
{
states.transform *= getTransform();
sf::Vector2f where(getPosition());
target.draw(spriteHolder, states);
}
}
-void BoardDiamond::update(sf::Time deltaTime, std::set<int> &busyTiles)
-{
+//void BoardDiamond::update(sf::Time deltaTime, std::set<int> &busyTiles)
+//{
-}
+//}
diff --git a/boarddiamond.h b/boarddiamond.h
index a1db927..ecbc8e6 100644
--- a/boarddiamond.h
+++ b/boarddiamond.h
@@ -1,36 +1,36 @@
#ifndef BOARDDIAMOND_H
#define BOARDDIAMOND_H
#include <set>
#include "textureholder.h"
#include "elem.h"
#include <SFML/Graphics.hpp>
class BoardDiamond: public Elem
{
public:
BoardDiamond();
BoardDiamond(TextureHolder *textures, int idNumber,
int playerNumber, int boardPosition);
TextureHolder *textures;
/*!
* \brief number from the sprite sheet
*
* 0-3 are corresponding to the players numbers,
* everything above are the extra items:
* 4 - diamond
*/
int idNumber;
/*!
* \brief 0-3 elements area on the board
*/
int playerNumber;
sf::Sprite spriteHolder;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
- void update(sf::Time deltaTime, std::set<int>& busyTiles);
+// void update(sf::Time deltaTime, std::set<int>& busyTiles);
};
#endif // BOARDDIAMOND_H
diff --git a/character.cpp b/character.cpp
index 3c26f8a..73de763 100644
--- a/character.cpp
+++ b/character.cpp
@@ -1,321 +1,321 @@
#include "character.h"
/*!
* \brief Character::getMovements
* \return
*/
std::array<int,2> Character::getMovements(int howFar)
{
std::array<int,2> myArray;
if (howFar==7)
{
return std::array<int,2> {-1,-1};
}
if (active==true)
{
// std::cout << "howfar: " <<howFar <<std::endl;
int indexRight = boardPosition;
for (int i=boardPosition;i<=boardPosition+howFar-1;i++)
{
if (indexRight==-1)
break;
indexRight = efc::boards[indexRight][1];
// std::cout << " howfar" << howFar << " index R" << indexRight
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
if (indexRight==-1)
break;
}
moveRight = indexRight;
int indexLeft = boardPosition;
for (int i=boardPosition;i>=boardPosition-howFar+1;i--)
{ if (indexLeft==-1)
break;
indexLeft = efc::boards[indexLeft][0];
// std::cout << " howfar" << howFar << " index l " << indexLeft
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
if (indexLeft==-1)
break;
}
moveLeft = indexLeft;
myArray = {moveLeft,moveRight};
}
else
{
myArray = {-1,-1};
}
// std::cout << "howfar: " <<howFar << std::endl;
return myArray;
}
void Character::setDir(int direction)
{
if (direction==efc::DIR_LEFT)
currentAnimation = &walkingAnimationLeft;
}
void Character::setDir()
{
setDir(currentAnimationIndex);
}
void Character::setDirIndex(int direction)
{
currentAnimationIndex = direction;
}
void Character::play()
{
// animatedSprite.play(*currentAnimation);
animatedSprite.play(animations[currentAnimationIndex]);
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
// std::cout << a.x << " " << a.y << " "
// << position.x << " " << position.y << " pos > "
// << getBoardPosition() << std::endl;
}
Character::Character(TextureHolder *textures, int playerNumber):
animatedSprite(sf::seconds(0.2), true, false),
nextRedirect(0.f)
{
drawMovements = false;
this->textures = textures;
int offset = playerNumber*16;
active = false;
rectangleLeft.setFillColor(sf::Color(12, 12, 12,120));
rectangleLeft.setOutlineColor(sf::Color(24,24,40, 255));
rectangleRight.setFillColor(sf::Color(240, 240, 240,98));
rectangleRight.setOutlineColor(sf::Color(24,40,24, 90));
walkingAnimationDown.setSpriteSheet(textures->textureCharacters);
walkingAnimationDown.addFrame(sf::IntRect(offset, 0, 16, 24));
walkingAnimationDown.addFrame(sf::IntRect(offset, 24, 16, 24));
walkingAnimationRight.setSpriteSheet(textures->textureCharacters);
walkingAnimationRight.addFrame(sf::IntRect(offset, 48, 16, 24));
walkingAnimationRight.addFrame(sf::IntRect(offset, 72, 16, 24));
walkingAnimationLeft.setSpriteSheet(textures->textureCharacters);
walkingAnimationLeft.addFrame(sf::IntRect(offset, 96, 16, 24));
walkingAnimationLeft.addFrame(sf::IntRect(offset, 120, 16, 24));
walkingAnimationUp.setSpriteSheet(textures->textureCharacters);
walkingAnimationUp.addFrame(sf::IntRect(offset, 144, 16, 24));
walkingAnimationUp.addFrame(sf::IntRect(offset, 168, 16, 24));
currentAnimation = &walkingAnimationRight;
leftChar.setTexture(textures->textureCharacters);
leftChar.setTextureRect(sf::IntRect(offset, 96, 16, 24));
rightChar.setTexture(textures->textureCharacters);
rightChar.setTextureRect(sf::IntRect(offset, 48, 16, 24));
leftChar.scale(0.75,0.75);
rightChar.scale(0.75,0.75);
animations[efc::DIR_LEFT] = walkingAnimationLeft;
animations[efc::DIR_RIGHT] = walkingAnimationRight;
animations[efc::DIR_UP] = walkingAnimationUp;
animations[efc::DIR_DOWN] = walkingAnimationDown;
setDirIndex(efc::DIR_LEFT);
setDir();
- sf::Vector2f positions[4] = {
- sf::Vector2f(0, 0),
- sf::Vector2f(20, 40),
- sf::Vector2f(20, 240),
- sf::Vector2f(40, 240)
- };
+// sf::Vector2f positions[4] = {
+// sf::Vector2f(0, 0),
+// sf::Vector2f(20, 40),
+// sf::Vector2f(20, 240),
+// sf::Vector2f(40, 240)
+// };
std::array<int, 4> boardPositions{0,15,255-15,255};
// std::cout << "define " << playerNumber << std::endl;
setBoardPosition(boardPositions[playerNumber]);
}
void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(animatedSprite, states);
if ((active==true) && (drawMovements==true))
{
if (moveLeft>-1)
{
// std::cout << "draw " << rectangleLeft.getPosition().x << " " << rectangleLeft.getPosition().y << std::endl;
target.draw(leftChar);
}
if (moveRight>-1)
{
// std::cout << "draw R" << rectangleRight.getPosition().x << " " << rectangleRight.getPosition().y << std::endl;
target.draw(rightChar);
// target.draw(rectangleRight, 4, sf::Quads, states);
}
}
}
-void Character::update(sf::Time deltaTime, std::set<int> &busyTiles)
+void Character::update(sf::Time deltaTime)
{
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
- int charPos = efc::transCords(position);
+// 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];
+// int left = movements[0];
+// int right = movements[1];
if (active==true)
{
if (moveLeft>-1)
{
sf::Vector2i cordsLeft(efc::transPosition(moveLeft));
sf::Vector2i neededCords(efc::transPosition(moveLeft));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
leftChar.setPosition(newPos.x+efc::TILE_SIZE/4,newPos.y);
}
if (moveRight>-1)
{
sf::Vector2i cordsRight(efc::transPosition(moveRight));
sf::Vector2i neededCords(efc::transPosition(moveRight));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
rightChar.setPosition(newPos.x+efc::TILE_SIZE/4,newPos.y);
}
// std::cout << " dice " << diceResult<< moveLeft << " " << moveRight << std::endl;
}
}
sf::FloatRect Character::getLocalBounds() const
{
return sf::FloatRect(0.f, 0.f, 0, 0);
}
sf::FloatRect Character::getGlobalBounds() const
{
return getTransform().transformRect(getLocalBounds());
}
diff --git a/character.h b/character.h
index cda8a03..49a1787 100644
--- a/character.h
+++ b/character.h
@@ -1,59 +1,59 @@
#ifndef CHARACTER_H
#define CHARACTER_H
#include <random>
#include <iostream>
#include "data.h"
#include "textureholder.h"
#include "animatedsprite.h"
#include "tilemap.h"
#include "elem.h"
class Character: public Elem
{
public:
Character(TextureHolder *textures, int playerNumber);
TextureHolder *textures;
Animation walkingAnimationDown;
Animation walkingAnimationUp;
Animation walkingAnimationLeft;
Animation walkingAnimationRight;
Animation animations[4];
Animation* currentAnimation;
int currentAnimationIndex;
sf::Sprite leftChar;
sf::Sprite rightChar;
AnimatedSprite animatedSprite;
sf::FloatRect getLocalBounds() const;
sf::FloatRect getGlobalBounds() const;
void setDirUp();
void setDirDown();
void setDirLeft();
void setDirRight();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
- void update(sf::Time deltaTime, std::set<int>& busyTiles);
+ void update(sf::Time deltaTime);
void play();
void setDir();
void setDir(int direction);
void setDirIndex(int direction);
float nextRedirect;
std::array<int,2> getMovements(int howFar);
int diceResult;
sf::RectangleShape rectangleLeft;
sf::RectangleShape rectangleRight;
int moveLeft;
int moveRight;
bool active;
bool drawMovements;
};
#endif // CHARACTER_H
diff --git a/command.cpp b/command.cpp
index e0f3dba..7283cee 100644
--- a/command.cpp
+++ b/command.cpp
@@ -1,113 +1,118 @@
#include "game.h"
#include "command.h"
Command::Command(efc::Game &currentGame) :
game(currentGame)
{
}
void Command::removeCard(int playerNumber)
{
/*! This should works as following:
* - iterate over BoardDiamondSeq
* - find diamonds belonging to the playerNumber
* - create an array from the aboves
* - get a random element
* - remove from the board - set not active
*/
std::vector<int> diamonds;
for (auto&& i: game.boardDiamonds.diamonds)
{
int fieldNumber = i.playerNumber;
if ((fieldNumber==playerNumber) && (i.boardPosition>-1)
&& (i.idNumber<4))
{
diamonds.push_back(i.boardPosition);
}
}
int numberDiamonds = diamonds.size();
if (numberDiamonds>=0)
{
int elemToRemove = rand() % numberDiamonds;
game.boardDiamonds.collectField(diamonds[elemToRemove]);
}
}
void Command::removeDiamond(int playerNumber)
{
/*! This should works as following:
* - iterate over BoardDiamondSeq
* - find diamonds belonging to the playerNumber
* - create an array from the aboves
* - get a random element
* - remove from the board - set not active
*/
std::vector<int> diamonds;
for (auto&& i: game.boardDiamonds.diamonds)
{
int fieldNumber = i.playerNumber;
if ((fieldNumber==playerNumber) && (i.boardPosition>-1)
&& (i.idNumber==4))
{
diamonds.push_back(i.boardPosition);
}
}
int numberDiamonds = diamonds.size();
if (numberDiamonds>=0)
{
int elemToRemove = rand() % numberDiamonds;
game.boardDiamonds.collectField(diamonds[elemToRemove]);
}
}
void Command::freezePlayer(int playerNumber)
{
game.players[playerNumber].frozenLeft += 1;
}
void Command::processField(int pos)
{
if (game.boardDiamonds.ifFieldIsEmpty(pos)==false)
{
game.sfx.playCollect();
if (game.boardDiamonds.getNumberForField(pos)==4)
{
game.players[game.turn].cash += 1;
} else if (game.boardDiamonds.getNumberForField(pos)<4)
{
processCard(pos);
}
game.boardDiamonds.collectField(pos);
}
}
void Command::processCard(int pos)
{
int tokenNumber = game.boardDiamonds.getNumberForField(pos);
std::string cardType = game.cardsDeck.getTitle(tokenNumber);
if (tokenNumber!=game.turn)
{
if (cardType == "diamond")
{
removeDiamond(game.boardDiamonds.getNumberForField(pos));
} else if (cardType == "stop")
{
freezePlayer(tokenNumber);
} else if (cardType == "card")
{
removeCard(game.boardDiamonds.getNumberForField(pos));
}
}
game.cardsDeck.nextCard(tokenNumber);
game.sfx.playCard();
}
+
+int Command::processGui(sf::Vector2f posGui)
+{
+ return posGui.x + posGui.y; /*! TODO: add processing some actions */
+}
diff --git a/command.h b/command.h
index 8aa5337..57a63d0 100644
--- a/command.h
+++ b/command.h
@@ -1,29 +1,32 @@
#ifndef COMMAND_H
#define COMMAND_H
#include "vector"
namespace efc {
class Game;
}
class Command
{
public:
// Command();
Command(efc::Game &currentGame);
/*!
* \brief Removes a diamond from the player's field.
* \param player
*/
void removeDiamond(int playerNumber);
void removeCard(int playerNumber);
void freezePlayer(int playerNumber);
efc::Game &game;
void processField(int pos);
void processCard(int pos);
+
+ int processGui(sf::Vector2f posGui);
+
};
#endif // COMMAND_H
diff --git a/game.cpp b/game.cpp
index 36b1e12..81f1d6e 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,608 +1,613 @@
#include "game.h"
namespace efc {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 0;
int month = 0;
void Game::initBoard()
{
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
spriteBackground.setTexture(textureBackground);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
gameBackground.setTexture(textures.textureGameBackground);
spriteLestBegin.setTexture(textures.textureLetsBegin);
viewTiles.setViewport(sf::FloatRect(0.15f,0.1f, 1.0f, 1.0f));
viewGui.setViewport(sf::FloatRect(0.806f,0.066f, 1, 1));
groupHud.setFont(&gameFont);
groupHud.setSeason(currentSeason);
groupHud.setRoundName(roundNumber);
sf::IntRect seasonsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
sf::Sprite season1;
season1.setTexture(textures.textureSeasons);
season1.setTextureRect(seasonsRect[0]);
season1.setPosition(0,400);
season1.scale(sf::Vector2f(0.25f, 0.25f));
season1.move(37.5, 30.5);
season1.setColor(sf::Color(0,255,0,80));
seasons[0] = season1;
sf::Sprite season2;
season2.setTexture(textures.textureSeasons);
season2.setTextureRect(seasonsRect[1]);
season2.setPosition(0,400);
season2.scale(sf::Vector2f(0.25f, 0.25f));
season2.move(37.5, 30.5);
season2.setColor(sf::Color(200,200,50,80));
seasons[1] = season2;
sf::Sprite season3;
season3.setTexture(textures.textureSeasons);
season3.setTextureRect(seasonsRect[2]);
season3.setPosition(0,400);
season3.scale(sf::Vector2f(0.25f, 0.25f));
season3.move(37.5, 30.5);
season3.setColor(sf::Color(90,90,255,80));
seasons[2] = season3;
sf::Sprite season4;
season4.setTexture(textures.textureSeasons);
season4.setTextureRect(seasonsRect[3]);
season4.setPosition(0,400);
season4.scale(sf::Vector2f(0.25f, 0.25f));
season4.move(37.5, 30.5);
season4.setColor(sf::Color(255,0,0,80));
seasons[3] = season4;
// Initialization of the players
cardsDeck.setFonts(&menuFont);
PlayerHud playerHud1(&textures, &gameFont, 32,0);
PlayerHud playerHud2(&textures, &gameFont, 32,1);
PlayerHud playerHud3(&textures, &gameFont, 32,2);
PlayerHud playerHud4(&textures, &gameFont, 32,3);
players[0] = playerHud1;
players[1] = playerHud2;
players[3] = playerHud3;
players[2] = playerHud4;
players[0].setActive(true);
setCurrentNeighbours();
diceResultPlayer = 6;
players[turn].characters[0].diceResult = diceResultPlayer;
roundDice.setColor(turn);
}
void Game::setCurrentNeighbours ()
{
currentNeighbours = players[turn].getNeighbours();
}
void Game::loadAssets()
{
// if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
// std::exit(1);
// if (!textureTiles.loadFromFile("assets/img/zw-tilesets/_MAP.png"))
// std::exit(1);
if (!gameFont.loadFromFile("assets/fnt/metal-mania.regular.ttf"))
{
std::exit(1);
}
if (!menuFont.loadFromFile("assets/fnt/metal-macabre.regular.ttf"))
{
std::exit(1);
}
if (!textureBackgroundArt.loadFromFile("assets/img/background_land.png"))
std::exit(1);
if (!musicGame.openFromFile("assets/audio/game.ogg"))
std::exit(1);
if (!musicBackground.openFromFile("assets/audio/wind2.ogg"))
std::exit(1);
if (!musicMenu.openFromFile("assets/audio/menu.ogg"))
std::exit(1);
if (!sfxClickBuffer.loadFromFile("assets/audio/click.ogg"))
std::exit(1);
if (!sfxDoneBuffer.loadFromFile("assets/audio/done.ogg"))
std::exit(1);
if (!textureBackground.loadFromFile("assets/img/background.png"))
std::exit(1);
spriteBackgroundArt.setTexture(textureBackgroundArt);
menuTxt.setFont(menuFont);
menuTxt.setCharacterSize(60);
menuTxt.setString(gameTitle);
int width = menuTxt.getLocalBounds().width;
int height = menuTxt.getLocalBounds().height;
menuTxt.setPosition(1050-(width/2),750-(height/2)-150);
menuTxt.setColor(sf::Color(255, 255, 255, 85));
cardsDeck.setFonts(&gameFont);
}
void Game::showMenu()
{
musicBackground.play();
musicBackground.setLoop(true);
menuBackground.setTexture(textures.textureMenu);
musicBackground.setVolume(7);
musicMenu.play();
musicMenu.setLoop(true);
currentState = state_menu;
}
void Game::hideMenu()
{
musicMenu.stop();
}
void Game::showGameBoard()
{
// musicGame.setVolume(20);
musicGame.play();
musicGame.setLoop(true);
sfx.playLetsBegin();
std::cout << "lets begin" << std::endl;
currentState = state_lets_begin;
}
void Game::endGame()
{
currentState = state_end_game;
musicBackground.stop();
}
void Game::handleLeftClick(sf::Vector2f pos,
sf::Vector2f posGui, sf::Vector2f posFull, int mousePos) {
if (currentState==state_game)
{
+
+
std::array<int,2> movements = players[turn].getMovements(diceResultPlayer);
if ((mousePos==movements[0]) || (mousePos==movements[1]))
{
players[turn].setFigurePos(mousePos);
commandManager.processField(mousePos);
int *possibleExit = std::find(std::begin(efc::possibleExits),
std::end(efc::possibleExits), mousePos);
if (possibleExit != efc::possibleExits+4) {
- // 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);
+ commandManager.processGui(posGui);
}
else if (currentState==state_roll_dice)
{
sf::IntRect diceRect(roundDice.spriteDice.getGlobalBounds());
if (diceRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
diceResultPlayer = roundDice.throwDiceSix();
players[turn].characters[0].diceResult=diceResultPlayer;
currentState=state_game;
}
}
if (currentState==state_menu)
{
downTimeCounter = 0;
// std::cout << " AA " <<downTimeCounter << std::endl;
hideMenu();
showGameBoard();
}
if (currentState==state_gui_end_round)
{
std::string resultCommand = guiRoundDice.getElem(pos);
command(resultCommand);
}
}
void Game::hideGameBoard()
{
musicGame.play();
}
Game::Game():
screenSize(efc::initScreenX,efc::initScreenY),
viewFull(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
viewGui(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
viewTiles(sf::FloatRect(0, 0, 1360, 768)),
selector(efc::TILE_SIZE),
guiSelectBuilding(&textures),
character(&textures, 3),
- turn(0),
gameTitle("deerportal"),
roundDice(players),
roundNumber(1),
guiRoundDice(&textures),
boardDiamonds(&textures),
+
+ window(sf::VideoMode(efc::initScreenX, efc::initScreenY), "Deerportal - game about how human can be upgraded to the Deer"),
+ turn(0),
+
commandManager(*this),
- cardsDeck(&textures, &menuFont),
- window(sf::VideoMode(efc::initScreenX, efc::initScreenY), "Deerportal - game about how human can be upgraded to the Deer")
+ cardsDeck(&textures, &menuFont)
+
{
textLoading.setString("loading...");
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
window.clear(sf::Color::White);
window.draw(textLoading);
window.display();
numberFinishedPlayers = 0;
sf::Clock frameClock;
guiRoundDice.active = true;
showPlayerBoardElems = false;
window.setVerticalSyncEnabled(true);
std::srand (time(NULL));
window.clear(sf::Color(55,55,55));
window.draw(textLoading);
window.display();
loadAssets();
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setColor(sf::Color::White);
textLoading.setCharacterSize(10);
window.clear(sf::Color::Black);
window.draw(textLoading);
window.display();
initBoard();
window.clear(sf::Color::Black);
window.draw(textLoading);
window.display();
showMenu();
// run the main loop
while (window.isOpen())
{
sf::Time frameTime = frameClock.restart();
std::string resultCommand = "";
// handle events
sf::Event event;
while (window.pollEvent(event))
{
sf::Vector2i localPositionTmp = sf::Mouse::getPosition(window);
sf::Vector2f localPosition = window.mapPixelToCoords(localPositionTmp,viewTiles);
sf::Vector2f localPositionGui = window.mapPixelToCoords(localPositionTmp,viewGui);
sf::Vector2f localPositionFull = window.mapPixelToCoords(localPositionTmp,viewFull);
int mousePosX = (int)localPosition.x / efc::TILE_SIZE;
int mousePosY = (int)localPosition.y / efc::TILE_SIZE;
int mousePos = efc::transCords(sf::Vector2i(mousePosX, mousePosY));
if(event.type == sf::Event::Closed)
window.close();
if (currentState==state_gui_elem)
{
resultCommand = guiSelectBuilding.getElem(localPositionFull);
showPlayerBoardElems = false;
if (resultCommand.find("elem_")==0)
command(resultCommand);
else
command("hide_gui_elem_description");
}
// Showing mouse hover
if (currentState==state_game)
{
if ((localPosition.x>efc::TILE_SIZE*efc::BOARD_SIZE) || (localPosition.x<0) || (localPosition.y>efc::TILE_SIZE*efc::BOARD_SIZE) || (localPosition.y<0))
{
showPlayerBoardElems = false;
} else {
showPlayerBoardElems = true;
}
}
if ((localPosition.x>=0) && (localPosition.y>=0) && (localPosition.x<=efc::BOARD_SIZE*efc::TILE_SIZE) && (localPosition.y<=efc::BOARD_SIZE*efc::TILE_SIZE))
{
selector.setPosition((int) (localPosition.x / efc::TILE_SIZE)*efc::TILE_SIZE, ((int) localPosition.y / efc::TILE_SIZE)*efc::TILE_SIZE);
}
/*!
* Handling mouse click
*/
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
handleLeftClick(localPosition, localPositionGui,
localPositionFull, mousePos);
}
}
update(frameTime);
render();
}
}
void Game::update(sf::Time frameTime) {
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].getMovements(diceResultPlayer);
if (currentMovements[0]>-1)
{
prevRotateElem.spriteRotate.setPosition(players[turn].characters[0].leftChar.getPosition());
prevRotateElem.spriteRotate.move(4,16);
prevRotateElem.update(frameTime);
prevRotateElem.setColor(turn);
}
if (currentMovements[1]>-1)
{
nextRotateElem.spriteRotate.setPosition(players[turn].characters[0].rightChar.getPosition());
nextRotateElem.spriteRotate.move(4,16);
nextRotateElem.update(frameTime);
nextRotateElem.setColor(turn);
}
}
cardsDeck.update(frameTime);
for (int i=0;i<4;i++)
{
players[i].play();
- players[i].update(frameTime, busyTiles);
+ players[i].update(frameTime);
}
if (currentState==state_lets_begin)
{
downTimeCounter += frameTime.asSeconds();
spriteLestBegin.setColor(sf::Color(255,255,255,255-(downTimeCounter*35)));
if (downTimeCounter>6)
{
currentState = state_roll_dice;
}
}
}
void Game::nextRound() {
turn = 0;
std::string result = roundDice.drawRound();
roundNumber += 1;
month++;
if (month==13)
month=1;
if (month%4==0)
currentSeason++;
if (currentSeason>3)
currentSeason=0;
if (players[turn].done==true)
nextPlayer();
}
void Game::nextPlayer(){
if (numberFinishedPlayers==4)
{
std::cout << "Everybody Finished!!!" << std::endl;
endGame();
}
if (turn<4)
players[turn].updatePlayer();
else
nextRound();
turn++;
if ((players[turn].done==true) && (turn<4))
{
std::cout << "Player " << turn << " is done" << std::endl;
nextPlayer();
}
if ((turn==4) || (turn>4))
{
nextRound();
}
if (players[turn].frozenLeft>0)
{
players[turn].frozenLeft -= 1;
nextPlayer();
}
selector.changeColor(turn);
for (int i=0;i<4;i++)
{
if (i==turn)
{
players[i].setActive(true);
currentNeighbours = players[i].getNeighbours();
}
else
players[i].setActive(false);
}
sfxClick.play();
diceResultPlayer = 6;
roundDice.setDiceTexture(diceResultPlayer);
players[turn].characters[0].diceResult = diceResultPlayer;
groupHud.setRoundName(roundNumber);
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
currentState = state_roll_dice;
roundDice.setColor(turn);
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
window.draw(players[i]);
}
}
void Game::drawSquares() {
if (showPlayerBoardElems)
{
window.draw(selector);
}
}
void Game::drawBaseGame()
{
window.setView(viewTiles);
// window.draw(map);
for (int i=0;i<4;i++)
{
window.draw(players[i].elems);
}
drawSquares();
window.setView(viewGui);
window.setView(viewTiles);
}
void Game::drawCharacters(){
window.setView(viewTiles); // Yeah Katia's inspiration
window.draw(gameBackground);
window.setView(viewFull);
window.draw(spriteBackgroundArt);
window.draw(cardsDeck);
window.draw(roundDice.spriteDice);
window.setView(viewTiles);
drawSquares();
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].characters[0].getMovements(diceResultPlayer);
if (currentMovements[1]>-1)
window.draw(nextRotateElem);
if (currentMovements[0]>-1)
window.draw(prevRotateElem);
}
for (int i=0;i<4;i++)
{
for (auto&& j: players[i].characters)
{
if (currentState==state_game)
j.drawMovements = true;
else
j.drawMovements = false;
window.draw(j);
}
}
}
void Game::render()
{
window.clear();
if (currentState==state_game)
{
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_roll_dice) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_gui_elem) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
drawCharacters();
window.draw(guiSelectBuilding);
window.setView(viewFull);
window.draw(groupHud);
} else if (currentState==state_menu) {
window.draw(menuTxt);
} else if (currentState==state_lets_begin) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
drawBaseGame();
drawCharacters();
window.draw(boardDiamonds);
window.setView(viewFull);
drawPlayersGui();
window.draw(spriteLestBegin);
} else if (currentState==state_gui_end_round){
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
window.draw(guiRoundDice);
window.setView(viewFull);
window.draw(groupHud);
}
window.display();
}
void Game::command(std::string command){
if (command=="close_gui")
{
guiSelectBuilding.active = false;
currentState=state_game;
sfxClick.play();
}
if (command=="hide_gui_elem_description")
{
if (currentState==state_gui_elem) {
guiSelectBuilding.descriptionActive = false;
}
}
if (command.find("end_of_round")==0)
{
std::string subResult = command.substr(13);
guiRoundDice.active = true;
guiRoundDice.setTitle(subResult);
currentState = state_gui_end_round;
}
if (command=="end_turn")
nextPlayer();
}
sf::Vector2f Game::getMousePos(){
sf::Vector2i mousePosTmp(sf::Mouse::getPosition(window));
sf::Vector2f mousePosition(window.mapPixelToCoords(mousePosTmp,viewTiles));
return mousePosition;
}
}
diff --git a/game.h b/game.h
index c6e7820..ec305b4 100644
--- a/game.h
+++ b/game.h
@@ -1,186 +1,196 @@
#ifndef GAME_H
#define GAME_H
#include <stdlib.h>
#include <iostream>
#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 "guichoosebuilding.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"
//class Command;
namespace efc {
extern int initScreenX;
extern int initScreenY;
class Game
{
+public:
+ sf::Vector2i screenSize;
+ sf::View viewFull;
+ sf::View viewGui;
+ sf::View viewTiles;
+
private:
- sf::Vector2i screenSize;
+ Selector selector;
+
+ GuiChooseBuilding guiSelectBuilding;
+
+ Character character;
+ std::string gameTitle;
+ RoundDice roundDice;
+
+ int roundNumber;
+
+ GuiRoundDice guiRoundDice;
+
public:
Game();
- sf::RenderWindow window;
- sf::View viewFull;
- sf::View viewGui;
- sf::View viewTiles;
BoardDiamondSeq boardDiamonds;
+ sf::RenderWindow window;
PlayerHud players[4];
SoundFX sfx;
- int turn;
+public:
+ int turn;
+
+
private:
void initBoard();
void loadAssets();
void drawPlayersGui();
void drawSquares();
void drawMenu();
sf::Vector2f getMousePos();
enum states {
state_init,
state_menu,
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::Texture textureBackground;
sf::Sprite spriteBackground;
sf::Sprite gameBackground;
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;
TileMap map;
int mapSize;
int level[256];
int levelElems[256];
TextureHolder textures;
std::set<int> currentNeighbours;
void command(std::string command);
int selectedPos;
- Selector selector;
- GuiChooseBuilding guiSelectBuilding;
- Character character;
void update(sf::Time frameTime);
void render();
- std::string gameTitle;
- RoundDice roundDice;
- int roundNumber;
- GuiRoundDice guiRoundDice;
void setCurrentNeighbours ();
void nextPlayer();
void nextRound();
sf::Sprite menuBackground;
sf::Sprite seasons[4];
//int currentSeason = 0;
sf::Music musicGame;
sf::Music musicBackground;
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 posGui, 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;
};
}
#endif // GAME_H
diff --git a/playerhud.cpp b/playerhud.cpp
index c2e8494..e9f896f 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,219 +1,219 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
std::set<int> PlayerHud::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
std::set<int> PlayerHud::getBusy(){
std::set<int> busyTiles;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
busyTiles.insert(i.first);
}
return busyTiles;
}
std::set<int> PlayerHud::getNeighbours(){
std::set<int> neighbours;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
std::set<int> terrain = getTerrainSet();
std::set<int> neighboursVector(efc::getNeighbours(i.second.pos));
for (int j: neighboursVector)
{
if ((elems.items_map.count(j) == 0) && (terrain.count(j)==0))
{
// std::cout << j << " " << terrain.count(j) << std::endl;
neighbours.insert(j);
}
}
}
// // Fill in s1 and s2 with values
// std::set<int> result;
// std::set_difference(neighbours.begin(), neighbours.end(), terrain.begin(), terrain.end(),
// std::inserter(result, result.end()));
// for (int i: result)
// {
// std::cout << i << std::endl;
// }
return neighbours;
}
void PlayerHud::updateTxt(){
txtCash.setString(std::to_string(cash));
// txtFood.setString( "Food: " + std::to_string(food));
// txtEnergy.setString("Enrg: " + std::to_string(energy));
// txtFaith.setString( "Gods: " + std::to_string(faith));
}
void PlayerHud::updatePlayer(){
updateTxt();
}
PlayerHud::PlayerHud():
frozenLeft(0)
{
}
void PlayerHud::setActive(bool newState){
active = newState;
elems.active = newState;
for (auto&& i: characters)
{
i.active = newState;
}
}
PlayerHud::PlayerHud(TextureHolder *textures, sf::Font *gameFont, int faceSize, int pos)
{
static int startPlayers[4] = {0,15,240,255};
frozenLeft = 0;
done = false;
active = false;
this->textures = textures;
Character character(this->textures, pos);
characters.push_back(Character (this->textures, pos));
efc::BoardElem startElem(textures, 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;
txtCash.setFont(*gameFont);
txtCash.setCharacterSize(20);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(pos*100)+10);
int posX1 = 80;
int posX2 = 960;
int posY1 = 184;
int posY2 = 579;
std::array<std::array<int,2>,4> textPos =
{
{
{posX1,posY1}, {posX2,posY1},
{posX1,posY2}, {posX2, posY2}
}
};
txtCash.setPosition(textPos[pos][0],textPos[pos][1] );
buttons.insert({"end_turn",rectangle});
}
std::string PlayerHud::getElem(sf::Vector2f mousePosition) {
std::string result = "";
sf::Vector2f hoverPos = getPosition();
for (std::pair<std::string, sf::RectangleShape> i: buttons)
{
sf::FloatRect spriteBounds = i.second.getLocalBounds();
sf::FloatRect closeRect;
closeRect.left = i.second.getPosition().x;
closeRect.top = i.second.getPosition().y;
closeRect.width = spriteBounds.width;
closeRect.height = spriteBounds.height;
if (closeRect.contains(mousePosition.x - hoverPos.x,mousePosition.y - hoverPos.y))
{
return i.first;
}
}
return result;
}
void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(txtCash, states);
}
void PlayerHud::play()
{
for (auto&& i: characters)
{
i.play();
}
}
-void PlayerHud::update(sf::Time deltaTime, std::set<int>& busyTiles)
+void PlayerHud::update(sf::Time deltaTime)
{
updateTxt();
if (frozenLeft==0)
{
for (auto&& i: characters)
{
sf::Vector2f movement(0.f, 0.f);
if (i.currentAnimationIndex==efc::DIR_LEFT)
movement = sf::Vector2f (-10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_RIGHT)
movement = sf::Vector2f (10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_UP)
movement = sf::Vector2f (0.f, -10.f);
else if (i.currentAnimationIndex==efc::DIR_DOWN)
movement = sf::Vector2f (0.f, 10.f);
- i.update(deltaTime, busyTiles);
+ i.update(deltaTime);
}
} else{
characters[0].currentAnimationIndex=efc::DIR_DOWN;
}
}
std::array<int,2> PlayerHud::getMovements(int diceResult)
{
return characters[0].getMovements(diceResult);
}
void PlayerHud::setFigurePos(int pos)
{
characters[0].setBoardPosition(pos);
}
diff --git a/playerhud.h b/playerhud.h
index 7b1d896..1ab282a 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,75 +1,75 @@
#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"
namespace efc {
}
class PlayerHud : public sf::Drawable, public sf::Transformable
{
public:
PlayerHud();
PlayerHud(TextureHolder *textures, sf::Font *gameFont, int tileSize, 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, std::set<int> &busyTiles);
+ 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;
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

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:23 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71553
Default Alt Text
(46 KB)

Event Timeline