Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F131182
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
19 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/character.cpp b/character.cpp
index f9e270f..7c04b53 100644
--- a/character.cpp
+++ b/character.cpp
@@ -1,322 +1,325 @@
#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};
+ return std::array<int,2> {{-1,-1}};
}
+ std::array<int,2> myArray;
+
+
if (active==true)
{
// std::cout << "howfar: " <<howFar <<std::endl;
int indexRight = boardPosition;
for (int i=boardPosition;i<=boardPosition+howFar-1;i++)
{
moveRight = indexRight;
if (indexRight==-1)
break;
indexRight = efc::boards[indexRight][1];
// std::cout << " howfar" << howFar << " index R" << indexRight
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
if (indexRight==-2)
{
indexRight = moveRight;
break;
}
if (indexRight==-1)
break;
}
moveRight = indexRight;
int indexLeft = boardPosition;
for (int i=boardPosition;i>=boardPosition-howFar+1;i--)
{
moveLeft = indexLeft;
if (indexLeft==-1)
break;
indexLeft = efc::boards[indexLeft][0];
// std::cout << " howfar" << howFar << " index l " << indexLeft
// << " move L " << moveLeft << " move R " << moveRight << " dice " << diceResult
// << std::endl;
if (indexLeft==-2)
{
indexLeft = moveLeft;
break;
}
if (indexLeft==-1)
break;
}
moveLeft = indexLeft;
myArray = {moveLeft,moveRight};
}
else
{
myArray = {-1,-1};
}
// std::cout << "howfar: " <<howFar << std::endl;
return myArray;
}
void Character::setBoardPosition(int playerNumber)
{
Elem::setBoardPosition(playerNumber);
move(0,-20);
}
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);
leftChar.move(202,76);
rightChar.move(202,76);
animations[efc::DIR_LEFT] = walkingAnimationLeft;
animations[efc::DIR_RIGHT] = walkingAnimationRight;
animations[efc::DIR_UP] = walkingAnimationUp;
animations[efc::DIR_DOWN] = walkingAnimationDown;
setDirIndex(efc::DIR_LEFT);
setDir();
// sf::Vector2f positions[4] = {
// sf::Vector2f(0, 0),
// sf::Vector2f(20, 40),
// sf::Vector2f(20, 240),
// sf::Vector2f(40, 240)
// };
std::array<int, 4> boardPositions{0,15,255-15,255};
// std::cout << "define " << playerNumber << std::endl;
setBoardPosition(boardPositions[playerNumber]);
}
void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(animatedSprite, states);
if ((active==true) && (drawMovements==true))
{
if (moveLeft>-1)
{
target.draw(leftChar);
}
if (moveRight>-1)
{
target.draw(rightChar);
}
}
}
void Character::update(sf::Time deltaTime)
{
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
nextRedirect -= deltaTime.asSeconds();
if (nextRedirect<0)
{
int number = rand() % 2;
if ((currentAnimationIndex==efc::DIR_LEFT) || (currentAnimationIndex==efc::DIR_RIGHT))
{
if (number==0){
setDirIndex(efc::DIR_DOWN);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if ((currentAnimationIndex==efc::DIR_UP) || (currentAnimationIndex==efc::DIR_DOWN))
{
if (number==0){
setDirIndex(efc::DIR_LEFT);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
}
nextRedirect = rand() % 4;
}
if (currentAnimationIndex==efc::DIR_UP)
{
if (position.y<2)
{
setDirIndex(efc::DIR_DOWN);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_DOWN)
{
if (position.y>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_LEFT)
{
if (position.x<2)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_RIGHT)
{
if (position.x>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_LEFT);
setDir();
}
}
animatedSprite.update(deltaTime);
std::array<int,2> movements(getMovements(diceResult));
// int left = movements[0];
// int right = movements[1];
if (active==true)
{
if (moveLeft>-1)
{
// sf::Vector2i cordsLeft(efc::transPosition(moveLeft));
sf::Vector2i neededCords(efc::transPosition(moveLeft));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
leftChar.setPosition(newPos.x+efc::TILE_SIZE/4,newPos.y);
leftChar.move(202,76);
}
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);
rightChar.move(202,76);
}
// 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/playerhud.cpp b/playerhud.cpp
index 4b898c0..cf5b4d0 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,245 +1,245 @@
#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)
{
pos = 0;
cash = 0;
energy = 0;
food = 0;
faith = 0;
active = false;
done = false;
tileSize = 0;
textures = nullptr;
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::pos' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::cash' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::energy' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::food' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::faith' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::active' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::done' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::faceSize' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::tileSize' is not initialized in the constructor.
// unchanged playerhud.cpp 72 warning uninitMemberVar false Member variable 'PlayerHud::textures' is not initialized in the constructor.
}
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 pos)
{
frozenLeft = 0;
done = false;
active = false;
this->textures = textures;
// Character character(this->textures, pos);
characters.push_back(Character (this->textures, pos));
// efc::BoardElem startElem(textures, efc::startPlayers[pos],444);
// startElem.setColor(efc::playersColors[pos]);
// elems.items.push_back(startElem);
// elems.items_map.insert({efc::startPlayers[pos], startElem});
// this->faceSize = faceSize;
// spriteFace.setTexture(textures->textureFaces);
this->pos = pos;
// symbol.setTexture(this->textures->textureSymbols);
// sf::IntRect symbolsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
// symbol.setTextureRect(symbolsRect[pos]);
// symbol.setScale(sf::Vector2f(0.2f, 0.20f));
// symbol.setColor(sf::Color(25, 25, 25, 105));
// symbol.setPosition(60, (pos*100)+40);
food = 0;
cash = 0;
energy = 0;
faith = 0;
txtCash.setFont(*gameFont);
txtCash.setCharacterSize(20);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(pos*100)+10);
int posX1 = 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}
+ {{posX1,posY1}}, {posX2,posY1},
+ {{posX1,posY2}}, {posX2, posY2}
}
};
txtCash.setPosition(textPos[pos][0],textPos[pos][1] );
buttons.insert({"end_turn",rectangle});
}
std::string PlayerHud::getElem(sf::Vector2f mousePosition) {
std::string result = "";
sf::Vector2f hoverPos = getPosition();
for (std::pair<std::string, sf::RectangleShape> i: buttons)
{
sf::FloatRect spriteBounds = i.second.getLocalBounds();
sf::FloatRect closeRect;
closeRect.left = i.second.getPosition().x;
closeRect.top = i.second.getPosition().y;
closeRect.width = spriteBounds.width;
closeRect.height = spriteBounds.height;
if (closeRect.contains(mousePosition.x - hoverPos.x,mousePosition.y - hoverPos.y))
{
return i.first;
}
}
return result;
}
void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(txtCash, states);
}
void PlayerHud::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void PlayerHud::update(sf::Time deltaTime)
{
updateTxt();
if (frozenLeft==0)
{
for (auto&& i: characters)
{
sf::Vector2f movement(0.f, 0.f);
if (i.currentAnimationIndex==efc::DIR_LEFT)
movement = sf::Vector2f (-10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_RIGHT)
movement = sf::Vector2f (10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_UP)
movement = sf::Vector2f (0.f, -10.f);
else if (i.currentAnimationIndex==efc::DIR_DOWN)
movement = sf::Vector2f (0.f, 10.f);
i.update(deltaTime);
}
} else{
characters[0].currentAnimationIndex=efc::DIR_DOWN;
}
}
std::array<int,2> PlayerHud::getMovements(int diceResult)
{
return characters[0].getMovements(diceResult);
}
void PlayerHud::setFigurePos(int pos)
{
characters[0].setBoardPosition(pos);
}
void PlayerHud::restartPlayer(){
food = 0;
cash = 0;
energy = 0;
faith = 0;
}
diff --git a/rounddice.cpp b/rounddice.cpp
index 44da31b..32e026e 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 (!textureDice.loadFromFile("assets/img/diceWhite.png"))
std::exit(1);
spriteDice.setTexture(textureDice);
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();
+// eventExtraCash();
return "end_of_round_extra_cash";
}
return "end_of_round_"+std::to_string(diceResult);
}
int RoundDice::throwDice(){
sfxDice.play();
int result = rand()%100;
diceResult = result;
return result;
}
int RoundDice::throwDiceSix(){
sfxDice.play();
int result = rand()%6;
diceResultSix = result;
setDiceTexture();
return result+1;
}
-void RoundDice::eventExtraCash(){
+//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();
+//// }
+//}
diff --git a/rounddice.h b/rounddice.h
index 076c6d4..d7f2381 100644
--- a/rounddice.h
+++ b/rounddice.h
@@ -1,41 +1,41 @@
#ifndef ROUNDDICE_H
#define ROUNDDICE_H
#include <random>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include "playerhud.h"
class RoundDice
{
public:
explicit RoundDice(PlayerHud (&players)[4]);
PlayerHud *playersHud;
std::string drawRound();
int diceResult;
int diceResultSix;
int throwDiceSix();
sf::Texture textureDice;
sf::Sprite spriteDice;
void setDiceTexture();
void setDiceTexture(int diceResult);
void setColor(int playerNumber);
private:
int throwDice();
int diceSize;
- void eventExtraCash();
+// void eventExtraCash();
sf::SoundBuffer sfxDiceBuffer;
sf::Sound sfxDice;
};
#endif // ROUNDDICE_H
File Metadata
Details
Attached
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
70254
Default Alt Text
(19 KB)
Attached To
Mode
R82 deerportal
Attached
Detach File
Event Timeline