Page MenuHomePhabricator (Chris)

No OneTemporary

Size
15 KB
Referenced Files
None
Subscribers
None
diff --git a/character.cpp b/character.cpp
index 93382a5..9596e32 100644
--- a/character.cpp
+++ b/character.cpp
@@ -1,349 +1,351 @@
#include "character.h"
/*!
* \brief Character::getMovements
* \return
*/
std::array<int,2> Character::getMovements(int howFar)
{
+ std::array<int,2> myArray;
- std::cout << "howfar: " <<howFar <<std::endl;
+ if (active==true)
+ {
+// std::cout << "howfar: " <<howFar <<std::endl;
- if (boardPosition+howFar>255)
- moveRight = -1;
- else
- {
- int index = boardPosition;
- for (int i=boardPosition;i<=boardPosition+howFar-1;i++)
- {
- std::cout << "FUCK ME " << index << std::endl;
- if (index==-1)
- break;
- index = efc::boards[index][1];
-// std::cout << " index R" << index
-// << " move R " << moveRight
-// << std::endl;
- if (index==-1)
- break;
- }
- moveRight = index;
- }
+ 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;
- if (boardPosition-howFar<0)
- moveLeft = -1;
+
+
+ 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
{
- int index = boardPosition;
- for (int i=boardPosition;i>=boardPosition-howFar+1;i--)
- { if (index==-1)
- break;
- index = efc::boards[index][0];
-// std::cout << " index l " << index
-// << " move L " << moveLeft
-// << std::endl;
- if (index==-1)
- break;
- }
- moveLeft = index;
+ myArray = {-1,-1};
}
-
-
- std::array<int,2> myArray = {moveLeft,moveRight};
- int x = efc::boards[2][2];
+// 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)
{
this->textures = textures;
int offset = playerNumber*16;
active = false;
rectangleLeft.setFillColor(sf::Color(12, 12, 12,120));
rectangleLeft.setOutlineColor(sf::Color(24,24,40, 255));
rectangleRight.setFillColor(sf::Color(240, 240, 240,98));
rectangleRight.setOutlineColor(sf::Color(24,40,24, 90));
walkingAnimationDown.setSpriteSheet(textures->textureCharacters);
walkingAnimationDown.addFrame(sf::IntRect(offset, 0, 16, 24));
walkingAnimationDown.addFrame(sf::IntRect(offset, 23, 16, 24));
walkingAnimationRight.setSpriteSheet(textures->textureCharacters);
walkingAnimationRight.addFrame(sf::IntRect(offset, 48, 16, 24));
walkingAnimationRight.addFrame(sf::IntRect(offset, 72, 16, 24));
walkingAnimationLeft.setSpriteSheet(textures->textureCharacters);
walkingAnimationLeft.addFrame(sf::IntRect(offset, 96, 16, 24));
walkingAnimationLeft.addFrame(sf::IntRect(offset, 120, 16, 24));
walkingAnimationUp.setSpriteSheet(textures->textureCharacters);
walkingAnimationUp.addFrame(sf::IntRect(offset, 144, 16, 24));
walkingAnimationUp.addFrame(sf::IntRect(offset, 168, 16, 24));
currentAnimation = &walkingAnimationRight;
leftChar.setTexture(textures->textureCharacters);
leftChar.setTextureRect(sf::IntRect(offset, 96, 16, 24));
rightChar.setTexture(textures->textureCharacters);
rightChar.setTextureRect(sf::IntRect(offset, 48, 16, 24));
animations[efc::DIR_LEFT] = walkingAnimationLeft;
animations[efc::DIR_RIGHT] = walkingAnimationRight;
animations[efc::DIR_UP] = walkingAnimationUp;
animations[efc::DIR_DOWN] = walkingAnimationDown;
setDirIndex(efc::DIR_LEFT);
setDir();
sf::Vector2f positions[4] = {
sf::Vector2f(0, 0),
sf::Vector2f(20, 40),
sf::Vector2f(20, 240),
sf::Vector2f(40, 240)
};
std::array<int, 4> boardPositions{0,15,255-15,255};
// std::cout << "define " << playerNumber << std::endl;
setBoardPosition(boardPositions[playerNumber]);
}
void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(animatedSprite, states);
if (active==true)
{
if (moveLeft>-1)
{
// std::cout << "draw " << rectangleLeft.getPosition().x << " " << rectangleLeft.getPosition().y << std::endl;
target.draw(leftChar);
}
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)
{
sf::Vector2f a(getPosition());
sf::Vector2i position(efc::getCords(a));
int charPos = efc::transCords(position);
// std::cout << a.x << " " << a.y << " " << position.x << " " << position.y << " " << charPos << std::endl;
nextRedirect -= deltaTime.asSeconds();
if (nextRedirect<0)
{
int number = rand() % 2;
if ((currentAnimationIndex==efc::DIR_LEFT) || (currentAnimationIndex==efc::DIR_RIGHT))
{
if (number==0){
setDirIndex(efc::DIR_DOWN);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if ((currentAnimationIndex==efc::DIR_UP) || (currentAnimationIndex==efc::DIR_DOWN))
{
if (number==0){
setDirIndex(efc::DIR_LEFT);
setDir();
} else if (number==1)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
}
nextRedirect = rand() % 4;
}
if (currentAnimationIndex==efc::DIR_UP)
{
if (position.y<2)
{
setDirIndex(efc::DIR_DOWN);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_DOWN)
{
if (position.y>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_UP);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_LEFT)
{
if (position.x<2)
{
setDirIndex(efc::DIR_RIGHT);
setDir();
}
} else if (currentAnimationIndex==efc::DIR_RIGHT)
{
if (position.x>efc::BOARD_SIZE-1)
{
setDirIndex(efc::DIR_LEFT);
setDir();
}
}
animatedSprite.update(deltaTime);
std::array<int,2> movements(getMovements(diceResult));
int left = movements[0];
int right = movements[1];
if (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);
}
if (moveRight>-1)
{
sf::Vector2i cordsRight(efc::transPosition(moveRight));
sf::Vector2i neededCords(efc::transPosition(moveRight));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
rightChar.setPosition(newPos);
}
- std::cout << " dice " << diceResult<< moveLeft << " " << moveRight << std::endl;
+// std::cout << " dice " << diceResult<< moveLeft << " " << moveRight << std::endl;
}
}
sf::FloatRect Character::getLocalBounds() const
{
return sf::FloatRect(0.f, 0.f, 0, 0);
}
sf::FloatRect Character::getGlobalBounds() const
{
return getTransform().transformRect(getLocalBounds());
}
/*!
* \brief Character::getBoardPosition
* \return
*/
int Character::getBoardPosition()
{
sf::Vector2f currentPos(getPosition());
sf::Vector2i currentCords(efc::getCords(currentPos));
int currentBoardPosition = efc::transCords(currentCords);
return currentBoardPosition;
}
/*!
* \brief Character::setBoardPosition
* \param boardPosition
*/
void Character::setBoardPosition(int boardPosition)
{
sf::Vector2i neededCords(efc::transPosition(boardPosition));
sf::Vector2f newPos(efc::getScreenPos(neededCords));
setPosition(newPos.x, newPos.y);
this->boardPosition = boardPosition;
std::array<int,2> movements(getMovements(diceResult));
std::cout << "board pos >> " << boardPosition << " cords >>" << neededCords.x << " " << neededCords.y
<< "newpos >> " << newPos.x << " " << newPos.y << " "
<< "movements >> " << movements[0] << " " << movements[1]
<< std::endl;
}
diff --git a/data.cpp b/data.cpp
index 5a79406..2db3259 100644
--- a/data.cpp
+++ b/data.cpp
@@ -1,87 +1,87 @@
#include <data.h>
namespace efc {
std::string seasonsNames[4] = {"spring", "summer", "fall", "winter"};
// This array defines fields occupied by the river
int terrainArray[24] = {
8, 24, 40, 56, 72, 88,
113, 114, 115, 116, 117, 118,
138, 139, 140, 141, 142, 143,
167, 183, 199, 215, 231, 247
};
/*
* 0
* 16
* 32
* 48
* 64
* 80
* 96
* 112
* 128
* 144
* 160
* 176
* 192
*/
std::array<std::array<int,2>,256> boards = {
{
{0,1}, {0,2}, {1,3}, {2,4}, {3,5}, {4,21}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {11,26}, {12,10}, {13,11}, {14,12}, {15,13}, {-1,14},
{-1,-1}, {18,33}, {19,17}, {20,18}, {21,19}, {5,20}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {10, 27,}, {26,28}, {27,29}, {28,30}, {29,46}, {-1,-1},
{33,48}, {17,32}, {-1,-1}, {51,36}, {35,37}, {36,38}, {37,54}, {-1,-1}, {-1,-1}, {-1,-1}, {43,58}, {44,42}, {60,43}, {-1,-1}, {30,47}, {46,63},
- {32,49}, {48,50}, {49,51}, {50,35}, {-1,-1}, {54,69}, {36,53}, {-1,-1}, {-1,-1}, {58,73}, {42,57}, {-1,-1}, {61,44}, {62,60}, {63,61}, {47,62},
+ {32,49}, {48,50}, {49,51}, {50,35}, {-1,-1}, {54,69}, {38,53}, {-1,-1}, {-1,-1}, {58,73}, {42,57}, {-1,-1}, {61,44}, {62,60}, {63,61}, {47,62},
{65,80}, {66,64}, {67,65}, {68,66}, {69,67}, {53,68}, {-1,-1}, {-1,-1}, {-1,-1}, {57,74}, {73,75}, {74,76}, {75,77}, {76,78}, {77,79}, {78,95},
{64,81}, {80,97}, {-1,-1}, {99,84}, {83,85}, {84,101}, {-1,-1}, {-1,-1}, {-1,-1}, {90,105}, {91,89}, {92,90}, {108,91}, {-1,-1}, {95,110}, {79,94},
{-1,-1}, {81,98}, {97,99}, {98,83}, {-1,-1}, {85,102}, {101,118}, {-1,-1}, {105,120}, {89,104}, {-1,-1}, {-1,-1}, {109,92}, {110,108}, {94,109}, {-1,-1},
{-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {102, 119},{118,-1}, {104,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
{-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1} , {151,-1}, {137,-1}, {153,136}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
{-1,-1}, {161,146}, {145,147}, {146,163}, {-1,-1}, {-1,-1}, {166,151}, {150,135} ,{-1,-1}, {154,137}, {170,153}, {-1,-1}, {157,172}, {158,156}, {174,157}, {-1,-1},
- {176,161},{160,145}, {-1,-1}, {147,164}, {163,165}, {165,166}, {165,150}, {-1,-1}, {-1,-1}, {-1,-1}, {171,154}, {172,170}, {156,171}, {-1,-1}, {175,158}, {191,174},
+ {176,161},{160,145}, {-1,-1}, {147,164}, {163,165}, {164,166}, {165,150}, {-1,-1}, {-1,-1}, {-1,-1}, {171,154}, {172,170}, {156,171}, {-1,-1}, {175,158}, {191,174},
{177,160},{178,176}, {179,177}, {180,178}, {181,179}, {182,180}, {198,181}, {-1,-1}, {-1,-1}, {-1,-1}, {202,187}, {186,188}, {187,189}, {188,190}, {189,191}, {190,175},
{208,193},{192,194}, {193,195}, {194,211}, {-1,-1}, {213,198}, {197,182}, {-1,-1}, {-1,-1}, {217,202}, {201,186}, {-1,-1}, {205,220}, {206,204}, {207,205}, {223,206},
- {209,192},{225,208}, {-1,-1}, {195,212}, {211,213}, {212,195}, {-1,-1}, {-1,-1}, {-1,-1}, {218,201}, {219,217}, {220,218}, {204,219}, {-1,-1}, {238,223}, {222,207},
+ {209,192},{225,208}, {-1,-1}, {195,212}, {211,213}, {212,197}, {-1,-1}, {-1,-1}, {-1,-1}, {218,201}, {219,217}, {220,218}, {204,219}, {-1,-1}, {238,223}, {222,207},
{-1,-1}, {226,209}, {227,225}, {228,226}, {229,227}, {245,228}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {250,235}, {234,236}, {235,237}, {236,238}, {237,222}, {-1,-1},
{-1,241}, {240,242},{241,243}, {242,244}, {243,245}, {244,229}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {251,234}, {252,250}, {253,251}, {254,252}, {255,253}, {-1,254},
},
};
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//{167,809}, {183, 803}, {199, 803}, {215, 803}, {231, 803} ,{247, 8},
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//{8,813}, {24, 803}, {40, 803}, {56, 803}, {72, 803} ,{88, 801},
//level[8] = 813;
//level[24] = 803;
//level[40] = 803;
//level[56] = 803;
//level[72] = 803;
//level[88] = 801;
//level[167] = 809;
//level[183] = 803;
//level[199] = 803;
//level[215] = 803;
//level[231] = 803;
//level[247] = 812;
//level[112] = 811;
//for (int i=113;i<117;i++)
// level[i] = 816;
//level[117] = 815;
//level[138] = 800;
//for (int i=139;i<143;i++)
// level[i] = 816;
//level[143] = 814;
// Colors for the board elements
sf::Color playersColors[4] = {
sf::Color(0, 150,255,255),
sf::Color(50, 230,50,255),
sf::Color(230, 50,50,255),
sf::Color(150, 150,150,255)
};
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Feb 2, 8:59 PM (2 d, 17 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55551
Default Alt Text
(15 KB)

Event Timeline