Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F102534
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
33 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7de41fe
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.o
+enfucraft
+enfucraft.pro.user
+Makefile
diff --git a/assets/audio/click.ogg b/assets/audio/click.ogg
new file mode 100644
index 0000000..5910d1f
Binary files /dev/null and b/assets/audio/click.ogg differ
diff --git a/assets/audio/wind.ogg b/assets/audio/wind.ogg
new file mode 100644
index 0000000..9535aad
Binary files /dev/null and b/assets/audio/wind.ogg differ
diff --git a/enfucraft.pro b/enfucraft.pro
index 236e17a..6c510f6 100644
--- a/enfucraft.pro
+++ b/enfucraft.pro
@@ -1,42 +1,42 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += c++11
SOURCES += main.cpp \
game.cpp \
tilemap.cpp \
selector.cpp \
playerhud.cpp \
boardelem.cpp \
boardelems.cpp \
textureholder.cpp \
hover.cpp \
guiwindow.cpp \
purchaseguielem.cpp \
guichoosebuilding.cpp
-LIBS += -lsfml-window -lsfml-system -lsfml-graphics
+LIBS += -lsfml-window -lsfml-system -lsfml-graphics -lsfml-audio
DESTDIR = ../build_release_enfucraft
assets.path = $${DESTDIR}/assets
assets.files = assets/*
INSTALLS += assets
HEADERS += \
game.h \
tilemap.h \
selector.h \
playerhud.h \
boardelem.h \
boardelems.h \
textureholder.h \
hover.h \
guiwindow.h \
purchaseguielem.h \
guichoosebuilding.h \
elemsdescription.h
RESOURCES += \
images.qrc
diff --git a/game.cpp b/game.cpp
index b43a04e..3bb318c 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,292 +1,370 @@
-#include <stdlib.h>
-#include <iostream>
#include "game.h"
-#include "guiwindow.h"
-#include <time.h> /* time */
namespace efc {
void Game::initBoard()
{
// Grass tile starts at 342 and has 11 tiles
// int level[256];
// int level[256];
// Structure of the board
/*
{
342, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
80, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3 }
*/
// Fill the array
for (int i=0;i<256;i++)
{
int grass = (rand() % 10) + 1;
level[i] = 342 + grass;
level[i] = level[i];
}
// level[0] = 441;
// level[240] = 0;
// level[255] = 0;
// level[15] = 0;
level[8] = 813;
level[24] = 803;
level[40] = 803;
level[56] = 803;
level[72] = 803;
level[88] = 801;
level[167] = 809;
level[183] = 803;
level[199] = 803;
level[215] = 803;
level[231] = 803;
level[247] = 812;
level[112] = 811;
for (int i=113;i<117;i++)
level[i] = 816;
level[117] = 815;
level[138] = 800;
for (int i=139;i<143;i++)
level[i] = 816;
level[143] = 814;
map.load(&textures, sf::Vector2u(efc::TILE_SIZE, efc::TILE_SIZE), level, efc::BOARD_SIZE, efc::BOARD_SIZE);
PlayerHud playerHud1(&textures, std::rand() % 80, &gameFont, 32,0);
PlayerHud playerHud2(&textures, std::rand() % 30, &gameFont, 32,1);
PlayerHud playerHud3(&textures, std::rand() % 60, &gameFont, 32,2);
PlayerHud playerHud4(&textures, std::rand() % 50, &gameFont, 32,3);
players[0] = playerHud1;
players[1] = playerHud2;
players[2] = playerHud3;
players[3] = playerHud4;
players[0].setActive(true);
setCurrentNeighbours();
}
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/8bitOperatorPlus-Regular.ttf"))
{
std::exit(1);
}
}
Game::Game():
- window(sf::VideoMode(512, 400), "EnFuCraft"),
+ window(sf::VideoMode(800, 600), "EnFuCraft"),
viewTiles(sf::FloatRect(00, 00, 400, 400)),
viewFull(sf::FloatRect(00, 00, 400, 400)),
viewGui(sf::FloatRect(00, 00, 112, 400)),
selector(efc::TILE_SIZE),
guiSelectBuilding(&textures),
turn(0)
{
+
+
+
+ if (!musicGame.openFromFile("assets/audio/wind.ogg"))
+ std::exit(1);
+ musicGame.play();
+ musicGame.setLoop(true);
+
+ if (!sfxClickBuffer.loadFromFile("assets/audio/click.ogg"))
+ std::exit(1);
+ sfxClick.setBuffer(sfxClickBuffer);
window.setVerticalSyncEnabled(true);
Hover hover;
GuiWindow guiWindow(&textures);
currentState = state_init;
std::srand (time(NULL));
loadAssets();
viewGui.setViewport(sf::FloatRect(0.8f,0, 1.0f, 1.0f));
viewTiles.setViewport(sf::FloatRect(0,0, 0.8f, 1.0f));
selector.changeColor(turn); //This is only for the test TODO: remove
initBoard();
currentState = state_game;
// run the main loop
while (window.isOpen())
{
+
+ 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);
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(localPosition);
+
+
+ if (resultCommand.find("elem_")==0)
+ command(resultCommand);
+ else
+ command("hide_gui_elem_description");
+
+
+
+ }
+
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
if (currentState==state_menu)
{
}
if (currentState==state_game)
{
if (currentNeighbours.find(mousePos) != currentNeighbours.end())
{
-// std::cout << "SUPER" << std::endl;
+ // std::cout << "SUPER" << std::endl;
if (!guiSelectBuilding.active)
{
float hover_x =localPosition.x;
float hover_y = localPosition.y;
if (localPosition.y > 290)
hover_y = hover_y - 100;
if (localPosition.x > 240)
hover_x = hover_x - 150;
if (hover_x>250)
hover_x = 249.0f;
if (hover_x<0)
hover_x = 1.0f;
if (hover_y>300)
hover_y = 299.0f;
if (hover_y<0)
hover_y = 1.0f;
selectedPos = mousePos;
guiSelectBuilding.setPosition(hover_x, hover_y);
guiSelectBuilding.active = true;
+ sfxClick.play();
currentState = state_gui_elem;
}
break;
}
- std::string result = players[turn].getElem(localPositionGui);
-// std::cout << result << " hello" << turn << std::endl;
- command(result);
+ resultCommand = players[turn].getElem(localPositionGui);
+ // std::cout << result << " hello" << turn << std::endl;
+ command(resultCommand);
-// nextPlayer();
+ // nextPlayer();
}
if (currentState==state_gui_elem)
{
- std::string result = guiSelectBuilding.getElem(localPosition);
- command(result);
+ resultCommand = guiSelectBuilding.getElem(localPosition);
+ if (resultCommand.find("elem_")==0)
+ {
+ std::string resultCommandWrapped = "build_" + resultCommand;
+ command(resultCommandWrapped);
+ } else if (resultCommand.find("close_gui")==0)
+ { command(resultCommand);}
}
}
}
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);
}
}
render();
}
}
void Game::nextPlayer(){
players[turn].updatePlayer();
turn++;
if (turn==4)
turn = 0;
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();
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
window.draw(players[i]);
}
}
void Game::drawSquares() {
window.draw(selector);
}
void Game::update()
{
}
void Game::render()
{
window.clear();
if (currentState==state_game)
{
window.setView(viewTiles);
window.draw(map);
for (int i=0;i<4;i++)
{
window.draw(players[i].elems);
}
drawSquares();
window.setView(viewGui);
drawPlayersGui();
} else if (currentState==state_gui_elem) {
window.setView(viewTiles);
window.draw(map);
for (int i=0;i<4;i++)
{
window.draw(players[i].elems);
}
-// window.draw(selector);
+ // window.draw(selector);
window.setView(viewGui);
drawPlayersGui();
}
window.setView(viewTiles);
window.draw(guiSelectBuilding);
window.display();
}
void Game::command(std::string command){
- if (command=="close")
+// std::cout << command << std::endl;
+ if (command=="close_gui")
+ {
+ guiSelectBuilding.active = false;
currentState=state_game;
+ sfxClick.play();
+
+
+
+
+ }
+
+ if (command=="hide_gui_elem_description")
+ {
+ if (currentState==state_gui_elem) {
+ guiSelectBuilding.descriptionActive = false;
+
+ }
+ }
+
+ if (command.find("elem_")==0)
+ {
+ if (currentState==state_gui_elem)
+ {
+
+ int buildingType = std::stoi(command.substr(5));
+
+
+ int cashUpd = textures.tilesDescription[buildingType][0];
+ int foodUpd = textures.tilesDescription[buildingType][2];
+ int enrgUpd = textures.tilesDescription[buildingType][4];
+ std::string descTxt = textures.tilesTxt[buildingType];
+ guiSelectBuilding.setDescriptionTxt("Cash:" + std::to_string(cashUpd) +"\n"+descTxt);
+ guiSelectBuilding.descriptionActive = true;
+
+ }
+ }
+
if (command=="end_turn")
nextPlayer();
if (command.find("build_")==0)
{
- int buildingType = std::stoi(command.substr(6));
- players[turn].addElem(selectedPos, buildingType);
- currentState = state_game;
- setCurrentNeighbours();
+ int buildingType = std::stoi(command.substr(11));
+ bool purchaseResult = players[turn].addElem(selectedPos, buildingType);
+ if (purchaseResult)
+ {
+ currentState = state_game;
+ setCurrentNeighbours();
+ guiSelectBuilding.active = false;
+ sfxClick.play();
+
+
+
+ }
}
}
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 861193a..e6052db 100644
--- a/game.h
+++ b/game.h
@@ -1,68 +1,77 @@
#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 "tilemap.h"
#include "selector.h"
#include "playerhud.h"
#include "textureholder.h"
#include "hover.h"
#include "guichoosebuilding.h"
+#include "guiwindow.h"
namespace efc {
class Game
{
public:
Game();
sf::RenderWindow window;
sf::View viewTiles;
private:
void initBoard();
void loadAssets();
void drawPlayersGui();
sf::Vector2f getMousePos();
enum states {
state_init,
state_menu,
state_game,
state_gui_elem,
state_select_building,
state_quit
};
states currentState;
sf::Texture textureTiles;
sf::Texture textureFaces;
sf::Font gameFont;
TileMap map;
PlayerHud players[4];
int mapSize;
int level[256];
int levelElems[256];
TextureHolder textures;
std::set<int> currentNeighbours;
void command(std::string command);
int selectedPos;
int turn;
void update();
void render();
sf::View viewGui;
Selector selector;
sf::View viewFull;
GuiChooseBuilding guiSelectBuilding;
void setCurrentNeighbours ();
void nextPlayer();
void drawSquares();
+ sf::Music musicGame;
+ sf::SoundBuffer sfxClickBuffer;
+ sf::Sound sfxClick;
+
};
}
#endif // GAME_H
diff --git a/guichoosebuilding.cpp b/guichoosebuilding.cpp
index 42e1c50..3aa04bc 100644
--- a/guichoosebuilding.cpp
+++ b/guichoosebuilding.cpp
@@ -1,60 +1,81 @@
#include "guichoosebuilding.h"
#include "tilemap.h"
GuiChooseBuilding::GuiChooseBuilding(TextureHolder *textures)
:GuiWindow(textures),
textureTiles(textures->textureTiles)
{
// this->textureTiles = &textures->textureGui;
- std::cout << "constructor" <<std::endl;
- addBuilding("build_8", 8);
- addBuilding("build_88", 88);
- addBuilding("build_328", 328);
+ // std::cout << "constructor" <<std::endl;
+ addBuilding("elem_651", 651);
+ addBuilding("elem_442", 442);
+ addBuilding("elem_585", 585);
+ addBuilding("elem_1100", 1100);
+
+
+ description = "Description";
+ guiElemTxt.setFont(guiElemFont);
+ guiElemTxt.setCharacterSize(10);
+ guiElemTxt.setColor(sf::Color(0,0,0));
+ updateDescription();
+ guiElemTxt.move(2,50);
+ descriptionActive = false;
+}
+
+void GuiChooseBuilding::updateDescription() {
+ guiElemTxt.setString(description);
+}
+
+void GuiChooseBuilding::setDescriptionTxt(std::string newDescription) {
+ description = newDescription;
+ updateDescription();
+
}
void GuiChooseBuilding::addBuilding(std::string name, int pos){
sf::Sprite newBuilding;
newBuilding.setTexture(textureTiles);
newBuilding.setTextureRect(efc::transPosIntoRect(pos));
- sf::Vector2f mod((buildings.size()*efc::TILE_SIZE),efc::TILE_SIZE);
+ sf::Vector2f mod((buildings.size()*efc::TILE_SIZE)+4*(buildings.size()+1)+4,efc::TILE_SIZE);
newBuilding.move(mod);
buildings.insert({name, newBuilding});
-// std::cout << "size " << buildings.size() <<std::endl;
+ // std::cout << "size " << buildings.size() <<std::endl;
}
void GuiChooseBuilding::draw(sf::RenderTarget& target, sf::RenderStates states) const{
if (active==true)
{
sf::RenderStates states2 = states;
states2.transform *= getTransform();
GuiWindow::draw(target, states);
for (std::pair<std::string, sf::Sprite> i: buildings)
{
target.draw(i.second, states2);
}
+ if (descriptionActive)
+ target.draw(guiElemTxt, states2);
}
}
std::string GuiChooseBuilding::getElem(sf::Vector2f mousePosition) {
std::string result = GuiWindow::getElem(mousePosition);
- if (result=="close")
+ if (result=="close_gui")
return result;
sf::Vector2f hoverPos = getPosition();
for (std::pair<std::string, sf::Sprite> i: buildings)
{
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))
{
- active = false;
return i.first;
}
}
return result;
}
diff --git a/guichoosebuilding.h b/guichoosebuilding.h
index 31a82aa..d702a59 100644
--- a/guichoosebuilding.h
+++ b/guichoosebuilding.h
@@ -1,18 +1,22 @@
#ifndef GUICHOOSEBUILDING_H
#define GUICHOOSEBUILDING_H
#include "guiwindow.h"
class GuiChooseBuilding : public GuiWindow
{
public:
GuiChooseBuilding(TextureHolder *textures);
std::map<std::string, sf::Sprite> buildings;
void addBuilding(std::string name, int pos);
const sf::Texture &textureTiles;
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
std::string getElem(sf::Vector2f mousePosition);
+ std::string description;
+ sf::Text guiElemTxt;
+ void updateDescription();
+ void setDescriptionTxt(std::string newDescription);
-
+ bool descriptionActive;
};
#endif // GUICHOOSEBUILDING_H
diff --git a/guiwindow.cpp b/guiwindow.cpp
index 2de0b34..3cfaea0 100644
--- a/guiwindow.cpp
+++ b/guiwindow.cpp
@@ -1,53 +1,70 @@
#include "guiwindow.h"
GuiWindow::GuiWindow(TextureHolder *textures)
{
spriteClose.setTexture(textures->textureGui);
spriteClose.setTextureRect(sf::IntRect(0,0,16,16));
spriteClose.move(sf::Vector2f(150-16,0));
+ if (!guiElemFont.loadFromFile("assets/fnt/8bitOperatorPlus-Regular.ttf"))
+ {
+ std::exit(1);
+ };
+
+
+ title = "Choose building:";
+ guiTitleTxt.setFont(guiElemFont);
+ guiTitleTxt.setCharacterSize(10);
+ guiTitleTxt.setColor(sf::Color(0,0,0));
+ guiTitleTxt.move(2,0);
+ guiTitleTxt.setString(title);
}
GuiWindow::GuiWindow(){
-
+ if (!guiElemFont.loadFromFile("assets/fnt/8bitOperatorPlus-Regular.ttf"))
+ {
+ std::exit(1);
+ };
}
void GuiWindow::setTextureHolder(TextureHolder *textures)
{
spriteClose.setTexture(textures->textureGui);
}
void GuiWindow::init(){
}
void GuiWindow::draw(sf::RenderTarget& target, sf::RenderStates states) const{
sf::RenderStates states2 = states;
states2.transform *= getTransform();
Hover::draw(target, states);
if (active)
- target.draw(spriteClose, states2);
+ {
+ target.draw(spriteClose, states2);
+ target.draw(guiTitleTxt, states2);
+ }
}
std::string GuiWindow::getElem(sf::Vector2f mousePosition)
{
sf::Vector2f hoverPos = getPosition();
sf::FloatRect spriteBounds = spriteClose.getLocalBounds();
sf::FloatRect closeRect;
closeRect.left = spriteClose.getPosition().x;
closeRect.top = spriteClose.getPosition().y;
closeRect.width = spriteBounds.width;
closeRect.height = spriteBounds.height;
if (closeRect.contains(mousePosition.x - hoverPos.x,mousePosition.y - hoverPos.y))
{
- active = false;
- return "close";
+ return "close_gui";
}
else
return "";
}
diff --git a/guiwindow.h b/guiwindow.h
index fe20681..f498dc2 100644
--- a/guiwindow.h
+++ b/guiwindow.h
@@ -1,26 +1,29 @@
#ifndef GUIWINDOW_H
#define GUIWINDOW_H
#include <iostream>
#include "hover.h"
#include "textureholder.h"
class GuiWindow: public Hover
{
public:
GuiWindow(TextureHolder *textures);
GuiWindow();
void setTextureHolder(TextureHolder *textures);
sf::Texture* textureGui;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void init();
virtual std::string getElem(sf::Vector2f mousePosition);
+ sf::Font guiElemFont;
+ std::string title;
+ sf::Text guiTitleTxt;
private:
sf::Sprite spriteClose;
};
#endif // GUIWINDOW_H
diff --git a/playerhud.cpp b/playerhud.cpp
index 9733225..5f04728 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,186 +1,213 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
-void PlayerHud::addElem(int pos, int type) {
- efc::BoardElem startElem(textures, pos,type);
- elems.items.push_back(startElem);
- elems.items_map.insert({pos, startElem});
+bool PlayerHud::addElem(int pos, int type) {
+ int price = textures->tilesDescription[type][0];
+
+
+ if (price<=cash)
+ {
+ efc::BoardElem startElem(textures, pos,type);
+ startElem.setColor(efc::playersColors[this->pos]);
+ elems.items.push_back(startElem);
+ elems.items_map.insert({pos, startElem});
+
+ cash -= price;
+ updateTxt();
+ return true;
+ }
+ return false;
}
std::set<int> PlayerHud::getNeighbours(){
std::set<int> neighbours;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
-// std::cout << "adding " << i.first << std::endl;
std::set<int> neighboursVector(efc::getNeighbours(i.second.pos));
for (int j: neighboursVector)
{
-// std::cout << "neigh " << j << " " << elems.items_map.count(j) << std::endl;
-
if (elems.items_map.count(j) == 0)
{
neighbours.insert(j);
}
}
}
return neighbours;
}
+void PlayerHud::updateTxt(){
+ txtCash.setString( "Cash: " + std::to_string(cash));
+ txtFood.setString( "Food: " + std::to_string(food));
+ txtEnergy.setString("Enrg: " + std::to_string(energy));
+ txtFaith.setString( "Gods: " + std::to_string(faith));
+
+}
+
+
void PlayerHud::updatePlayer(){
for (const efc::BoardElem &i: elems.items)
{
int cashUpd = textures->tilesDescription[i.type][1];
int foodUpd = textures->tilesDescription[i.type][3];
- int enrgUpd = textures->tilesDescription[i.type][3];
+ int enrgUpd = textures->tilesDescription[i.type][5];
+ int faithUpd = textures->tilesDescription[i.type][7];
+
cash += cashUpd;
energy += enrgUpd;
food += foodUpd;
- txtCash.setString("Cash: " + std::to_string(cash));
- std::cout << "CASH " << i.type << " " << i.pos << " " << cashUpd << " " << cash<< std::endl;
+ faith += faithUpd;
+ updateTxt();
}
}
-
PlayerHud::PlayerHud()
{
active = false;
food = 0;
- cash = 0;
+ cash = 10;
energy = 0;
+ faith = 0;
}
void PlayerHud::setActive(bool newState){
active = newState;
elems.active = newState;
}
PlayerHud::PlayerHud(TextureHolder *textures, int faceNumber, sf::Font *gameFont, int faceSize, int pos)
{
active = false;
this->textures = textures;
- efc::BoardElem startElem(textures, startPlayers[pos],441);
+ 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;
food = 0;
- cash = 0;
+ cash = 10;
energy = 0;
+ faith = 0;
int x = faceNumber % 10;
int y = (int) faceNumber /10;
txtCash.setFont(*gameFont);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
- txtNextRound.setFont(*gameFont);
-
+ txtFaith.setFont(*gameFont);
+ txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
txtNextRound.setScale(sf::Vector2f(0.25f, 1.f));
txtNextRound.setCharacterSize(10);
txtNextRound.setPosition(9,(pos*100)+10);
txtCash.setPosition(1,(pos*100)+40);
- txtCash.setString("Cash: " + std::to_string(cash));
+// txtCash.setString("Cash: " + std::to_string(cash));
txtCash.setCharacterSize(10);
txtCash.setScale(sf::Vector2f(0.25f, 1.f));
txtFood.setPosition(1,(pos*100)+55);
- txtFood.setString("Food: " + std::to_string(food));
+// txtFood.setString("Food: " + std::to_string(food));
txtFood.setCharacterSize(10);
txtFood.setScale(sf::Vector2f(0.25f, 1.f));
txtEnergy.setPosition(1,(pos*100)+70);
- txtEnergy.setString("Enrg: " + std::to_string(energy));
+// txtEnergy.setString("Enrg: " + std::to_string(energy));
txtEnergy.setCharacterSize(10);
txtEnergy.setScale(sf::Vector2f(0.25f, 1.f));
-
- std::cout << "playerHud" << faceNumber << " " << x << " " << y << std::endl;
+ txtFaith.setPosition(1,(pos*100)+85);
+// txtEnergy.setString("Enrg: " + std::to_string(energy));
+ txtFaith.setCharacterSize(10);
+ txtFaith.setScale(sf::Vector2f(0.25f, 1.f));
+ updateTxt();
spriteFace.setTextureRect(sf::IntRect(x*faceSize, y*faceSize, faceSize, faceSize));
spriteFace.setScale(sf::Vector2f(0.25f, 1.f));
spriteFace.setPosition(0,pos*100);
rectangle.setSize(sf::Vector2f(this->faceSize, this->faceSize));
rectangle2.setSize(sf::Vector2f(this->faceSize, (this->faceSize*2)+3));
if (pos==0)
{
rectangle.setFillColor(sf::Color(50, 50, 150,168));
rectangle2.setFillColor(sf::Color(100, 100, 150,168));
rectangle.setOutlineColor(sf::Color(0,0,128));
}
else if (pos==1)
{
rectangle.setFillColor(sf::Color(50, 150, 50,168));
rectangle2.setFillColor(sf::Color(100, 150,100,168));
rectangle.setOutlineColor(sf::Color(0,128,0));
}
else if (pos==2)
{
rectangle.setFillColor(sf::Color(150, 50, 50,168));
rectangle2.setFillColor(sf::Color(150, 100,100,168));
rectangle.setOutlineColor(sf::Color(128,0,0));
}
else if (pos==3)
{
rectangle.setFillColor(sf::Color(150, 150, 150,168));
rectangle2.setFillColor(sf::Color(200, 200,200,168));
rectangle.setOutlineColor(sf::Color(128,128,128));
}
rectangle.setOutlineThickness(1);
rectangle.setPosition(0, pos*100);
rectangle2.setPosition(0, (pos*100)+faceSize+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))
{
- active = false;
return i.first;
}
}
return result;
}
void PlayerHud::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// // apply the transform
states.transform *= getTransform();
// Color rectangles making the gui on the right side
// sf::RectangleShape rectangle(sf::Vector2f(faceSize, faceSize));
// sf::RectangleShape rectangle2(sf::Vector2f(faceSize, (faceSize*2)+3));
target.draw(rectangle, states);
target.draw(rectangle2, states);
target.draw(txtCash, states);
target.draw(txtFood, states);
target.draw(txtEnergy, states);
+ target.draw(txtFaith, states);
+
if (active)
target.draw(txtNextRound, states);
target.draw(spriteFace, states);
}
diff --git a/playerhud.h b/playerhud.h
index 3023562..228062b 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,57 +1,62 @@
#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"
static int startPlayers[4] = {0,15,240,255};
+namespace efc {
+static sf::Color playersColors[4] = {
+ sf::Color(50, 50,230,255),
+ sf::Color(50, 230,50,255),
+ sf::Color(230, 50,50,255),
+ sf::Color(150, 150,150,255)
+};
+
+}
+
+
class PlayerHud : public sf::Drawable, public sf::Transformable
{
public:
PlayerHud();
PlayerHud(TextureHolder *textures, int faceNumber, 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 addElem(int pos, int type);
-
-
+ bool addElem(int pos, int type);
void updatePlayer();
std::string getElem(sf::Vector2f mousePosition);
std::map<std::string, sf::RectangleShape> buttons;
-
-
+ void updateTxt();
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;
};
-
-
#endif // PLAYERHUD_H
diff --git a/textureholder.cpp b/textureholder.cpp
index 4490ac3..72e2d5c 100644
--- a/textureholder.cpp
+++ b/textureholder.cpp
@@ -1,39 +1,66 @@
#include "textureholder.h"
TextureHolder::TextureHolder()
{
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);
+ 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 defaultArray[6] = {10,2,10,0,2,2};
- int defaultFields[4] = {441, 8, 88, 328};
-
+ int counter = 0;
for (int i: defaultFields)
{
std::map<int, int> params;
- params.insert({0, 10});
- params.insert({1, 2});
- params.insert({2, 10});
- params.insert({3, 0});
- params.insert({4, 10});
- params.insert({5, 0});
-
+ 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."});
+ tilesTxt.insert({442, "Granary, increases food\nresources."});
+ tilesTxt.insert({585, "Marketplace, generates cash"});
+ tilesTxt.insert({1100, "Monasterium, brings you luck"});
- }
-// tilesDescription.insert({441, &defaultArray});
-// tilesDescription.insert({8, &defaultArray});
-// tilesDescription.insert({88, &defaultArray});
-// tilesDescription.insert({328, &defaultArray});
}
diff --git a/textureholder.h b/textureholder.h
index fa30199..ed9f6e8 100644
--- a/textureholder.h
+++ b/textureholder.h
@@ -1,18 +1,19 @@
#ifndef TEXTUREHOLDER_H
#define TEXTUREHOLDER_H
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
class TextureHolder
{
public:
TextureHolder();
sf::Texture textureTiles;
sf::Texture textureFaces;
sf::Texture textureGui;
std::map<int, std::map<int, int>> tilesDescription;
+ std::map<int, std::string> tilesTxt;
};
#endif // TEXTUREHOLDER_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Feb 4, 2:09 PM (6 h, 57 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55605
Default Alt Text
(33 KB)
Attached To
Mode
R82 deerportal
Attached
Detach File
Event Timeline
Log In to Comment