Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
55 KB
Referenced Files
None
Subscribers
None
diff --git a/boardelem.cpp b/boardelem.cpp
index fb8fb29..1273f20 100644
--- a/boardelem.cpp
+++ b/boardelem.cpp
@@ -1,49 +1,49 @@
#include "boardelem.h"
namespace efc {
sf::RectangleShape createNeighbour(int pos) {
sf::RectangleShape rectangle(sf::Vector2f(efc::TILE_SIZE, efc::TILE_SIZE));
sf::Vector2i cords(efc::transPosition(pos));
rectangle.setFillColor(sf::Color(240, 240, 240,98));
rectangle.setOutlineColor(sf::Color(24,24,24, 90));
rectangle.setPosition(cords.x*efc::TILE_SIZE, cords.y*efc::TILE_SIZE);
// rectangle.setOutlineThickness(0.5);
return rectangle;
}
}
efc::BoardElem::BoardElem(TextureHolder *textures,int pos, int type)
{
- textureTiles = &textures->textureTiles;
+// textureTiles = &textures->textureTiles;
this->pos = pos;
this->type = type;
sf::Vector2i cords = efc::transPosition(pos);
int y_type = (int) type / efc::TILE_BOARD_SIZE;
int x_type = type % efc::TILE_BOARD_SIZE;
setPosition(cords.x*efc::TILE_SIZE,cords.y*efc::TILE_SIZE);
- setTexture(textures->textureTiles);
+// setTexture(textures->textureTiles);
setTextureRect(sf::IntRect(x_type*efc::TILE_SIZE, y_type*efc::TILE_SIZE, efc::TILE_SIZE, efc::TILE_SIZE));
// Sprite::SetBlendMode(sf::BlendMode::BlendAdd);
}
diff --git a/game.cpp b/game.cpp
index b6bc9c7..ad585a6 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,613 +1,612 @@
#include "game.h"
namespace efc {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 1;
int month = 0;
void Game::initBoard()
{
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
- spriteBackground.setTexture(textureBackground);
+// spriteBackground.setTexture(textureBackground);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
- gameBackground.setTexture(textures.textureGameBackground);
+// 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;
+// 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 (!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);
+// 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);
+// musicBackgroun/*d*/.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();
+// 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);
const int *possibleExit = std::find(std::begin(efc::endPlayers),
std::end(efc::endPlayers), mousePos);
if (possibleExit != efc::endPlayers+4) {
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),
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)
{
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");
- }
+// 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);
}
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.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=="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 ec305b4..fe9031b 100644
--- a/game.h
+++ b/game.h
@@ -1,196 +1,194 @@
#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:
Selector selector;
- GuiChooseBuilding guiSelectBuilding;
Character character;
std::string gameTitle;
RoundDice roundDice;
int roundNumber;
GuiRoundDice guiRoundDice;
public:
Game();
BoardDiamondSeq boardDiamonds;
sf::RenderWindow window;
PlayerHud players[4];
SoundFX sfx;
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::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;
void update(sf::Time frameTime);
void render();
void setCurrentNeighbours ();
void nextPlayer();
void nextRound();
sf::Sprite menuBackground;
sf::Sprite seasons[4];
//int currentSeason = 0;
sf::Music musicGame;
- sf::Music musicBackground;
+// 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/guichoosebuilding.cpp b/guichoosebuilding.cpp
deleted file mode 100644
index 036543a..0000000
--- a/guichoosebuilding.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-#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("elem_651", 651);
- addBuilding("elem_442", 442);
- addBuilding("elem_585", 585);
- addBuilding("elem_1100", 1100);
-
- description = "Description";
- guiElemTxt.setFont(guiElemFont);
- guiElemTxt.setCharacterSize(16);
- guiElemTxt.setColor(sf::Color(255,255,255,200));
- updateDescription();
- guiElemTxt.move(2,50);
- descriptionActive = false;
- rectangle.setSize(sf::Vector2f(400,200));
- bgdDark.setTextureRect((sf::IntRect)rectangle.getLocalBounds());
- spriteClose.setPosition(sf::Vector2f(rectangle.getLocalBounds().width-16,0));
-
-
-}
-
-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)+4*(buildings.size()+1)+4,efc::TILE_SIZE);
- newBuilding.move(mod);
- buildings.insert({name, newBuilding});
- // 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_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))
- {
- return i.first;
- }
- }
- return result;
-}
-
diff --git a/guichoosebuilding.h b/guichoosebuilding.h
deleted file mode 100644
index 199f3f4..0000000
--- a/guichoosebuilding.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#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);
- sf::Text guiElemTxt;
- void updateDescription();
- void setDescriptionTxt(std::string newDescription);
-
- bool descriptionActive;
-};
-
-#endif // GUICHOOSEBUILDING_H
diff --git a/guiwindow.cpp b/guiwindow.cpp
index 57e4454..f7db47c 100644
--- a/guiwindow.cpp
+++ b/guiwindow.cpp
@@ -1,80 +1,80 @@
#include "guiwindow.h"
void GuiWindow::setTitle(std::string newTitle) {
title = newTitle;
guiTitleTxt.setString(title);
}
GuiWindow::GuiWindow(TextureHolder *textures)
{
- spriteClose.setTexture(textures->textureGui);
- spriteClose.setTextureRect(sf::IntRect(0,0,16,16));
- spriteClose.move(sf::Vector2f(150-16,0));
+// spriteClose.setTexture(textures->textureGui);
+// spriteClose.setTextureRect(sf::IntRect(0,0,16,16));
+// spriteClose.move(sf::Vector2f(150-16,0));
if (!guiElemFont.loadFromFile("assets/fnt/metal-macabre.regular.ttf"))
{
std::exit(1);
};
bgdDark.setTexture(textures->backgroundDark);
// bgdDark.setColor(sf::Color(160, 160, 160, 200));
bgdDark.setTextureRect((sf::IntRect)rectangle.getLocalBounds());
title = "Choose building:";
guiTitleTxt.setFont(guiElemFont);
guiTitleTxt.setCharacterSize(58);
guiTitleTxt.setColor(sf::Color(255,255,255,200));
guiTitleTxt.move(2,0);
guiTitleTxt.setString(title);
setPosition(150, 100);
}
GuiWindow::GuiWindow(){
if (!guiElemFont.loadFromFile("assets/fnt/metal-macabre.regular.ttf"))
{
std::exit(1);
};
setPosition(150, 100);
}
-void GuiWindow::setTextureHolder(TextureHolder *textures)
-{
+//void GuiWindow::setTextureHolder(TextureHolder *textures)
+//{
- spriteClose.setTexture(textures->textureGui);
+//// 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);
target.draw(bgdDark, 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))
{
return "close_gui";
}
else
return "";
}
diff --git a/guiwindow.h b/guiwindow.h
index 2384974..197c773 100644
--- a/guiwindow.h
+++ b/guiwindow.h
@@ -1,34 +1,34 @@
#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);
+// void setTextureHolder(TextureHolder *textures);
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;
std::string description;
sf::Text guiTitleTxt;
sf::Texture* textureGui;
sf::Sprite bgdDark;
void setTitle(std::string newTitle);
sf::Sprite spriteClose;
private:
};
#endif // GUIWINDOW_H
diff --git a/pagan_board.pro b/pagan_board.pro
index f63af47..c1ba428 100644
--- a/pagan_board.pro
+++ b/pagan_board.pro
@@ -1,79 +1,77 @@
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 \
rounddice.cpp \
guirounddice.cpp \
grouphud.cpp \
animation.cpp \
animatedsprite.cpp \
character.cpp \
data.cpp \
rotateelem.cpp \
boarddiamond.cpp \
boarddiamondseq.cpp \
elem.cpp \
soundfx.cpp \
card.cpp \
pile.cpp \
cardslist.cpp \
command.cpp \
cardsdeck.cpp
LIBS += -lsfml-window -lsfml-system -lsfml-graphics -lsfml-audio
DESTDIR = ../build_release_pagan_board
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 \
rounddice.h \
guirounddice.h \
grouphud.h \
data.h \
animation.h \
animatedsprite.h \
character.h \
rotateelem.h \
boarddiamond.h \
boarddiamondseq.h \
elem.h \
soundfx.h \
card.h \
pile.h \
cardslist.h \
command.h \
cardsdeck.h
OTHER_FILES += \
CREDITS.md
QMAKE_CXXFLAGS += -std=gnu++0x -Wpedantic
diff --git a/playerhud.cpp b/playerhud.cpp
index fd5cd6a..aee75f0 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,218 +1,218 @@
#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)
{
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);
+// spriteFace.setTexture(textures->textureFaces);
this->pos = pos;
- symbol.setTexture(this->textures->textureSymbols);
+// 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)};
+// 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);
+// 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}
}
};
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);
}
diff --git a/soundfx.cpp b/soundfx.cpp
index 2f1983c..f5aedc9 100644
--- a/soundfx.cpp
+++ b/soundfx.cpp
@@ -1,35 +1,35 @@
#include "soundfx.h"
SoundFX::SoundFX()
{
- if (!soundCollectBuffer.loadFromFile("assets/audio/collect.wav"))
+ if (!soundCollectBuffer.loadFromFile("assets/audio/collect.ogg"))
exit(-1);
if (!soundCardBuffer.loadFromFile("assets/audio/card.ogg"))
exit(-1);
soundCollect.setBuffer(soundCollectBuffer);
soundCollect.setVolume(20);
soundCard.setBuffer(soundCardBuffer);
// soundCollect.setVolume(20);
if (!soundLetsBeginBuffer.loadFromFile("assets/audio/letsbegin.ogg"))
exit(-1);
soundLetsBegin.setBuffer(soundLetsBeginBuffer);
soundLetsBegin.setVolume(20);
}
void SoundFX::playCollect()
{
soundCollect.play();
}
void SoundFX::playCard()
{
soundCard.play();
}
void SoundFX::playLetsBegin()
{
std::cout << "playing.... begin lets" << std::endl;
soundLetsBegin.play();
}
diff --git a/textureholder.cpp b/textureholder.cpp
index b8bf101..a55f1dd 100644
--- a/textureholder.cpp
+++ b/textureholder.cpp
@@ -1,116 +1,116 @@
#include "textureholder.h"
namespace efc {
std::set<int> getTerrainSet() {
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
}
TextureHolder::TextureHolder()
{
if (!textureCardBases[0].loadFromFile("assets/img/card-water-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[1].loadFromFile("assets/img/card-earth-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[2].loadFromFile("assets/img/card-fire-2-diam_m.png"))
std::exit(1);
if (!textureCardBases[3].loadFromFile("assets/img/card-air-2-diam_m.png"))
std::exit(1);
- if (!textureGameBackground.loadFromFile("assets/img/game-background.png"))
- std::exit(1);
+// if (!textureGameBackground.loadFromFile("assets/img/game-ackground.png"))
+// std::exit(1);
- if (!textureTiles.loadFromFile("assets/img/zw-tilesets/_MAP.png"))
- std::exit(1);
- if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
- std::exit(1);
- if (!textureGui.loadFromFile("assets/img/gui.png"))
- std::exit(1);
+// if (!textureTiles.loadFromFile("assets/img/zw-tilesets/_MAP.png"))
+// std::exit(1);
+// if (!textureFaces.loadFromFile("assets/img/faces.jpg"))
+// std::exit(1);
+// if (!textureGui.loadFromFile("assets/img/gui.png"))
+// std::exit(1);
- if (!textureSymbols.loadFromFile("assets/img/symbols.png"))
- std::exit(1);
- if (!textureSeasons.loadFromFile("assets/img/seasons.png"))
- std::exit(1);
+// if (!textureSymbols.loadFromFile("assets/img/symbols.png"))
+// std::exit(1);
+// if (!textureSeasons.loadFromFile("assets/img/seasons.png"))
+// std::exit(1);
if (!textureCharacters.loadFromFile("assets/img/characters.png"))
std::exit(1);
if (!backgroundDark.loadFromFile("assets/img/background_dark.png"))
std::exit(1);
if (!textureBoardDiamond.loadFromFile("assets/img/board_diamonds.png"))
std::exit(1);
- if (!textureMenu.loadFromFile("assets/img/background_new.png"))
- std::exit(1);
+// if (!textureMenu.loadFromFile("assets/img/background_new.png"))
+// std::exit(1);
if (!textureLetsBegin.loadFromFile("assets/img/letsbegin.png"))
std::exit(1);
int defaultArray[5][8] = {
//Cash Food Energy Faith
{10, 2, 0, 0, 0, 0, 0, 0}, // base
{10, 1, 2, 0, 0, 5, 0, 0}, // windmill
{15, 0, 0, 2, 2, 0, 0, 0}, // granary
{20, 5, 4, 0, 4, 0, 0, 0}, // marketplace
{5, 0, 2, 0, 0, 0, 0, 2} // monasterium
};
int defaultFields[5] = {443, 651, 442, 585, 1100};
/*
* Array with description of the field
* global rule = even indexes are price, odd - monthly cost
* [0] - price in cash
* [1] - monthly cash cost
* [2] - price - in food
* [3] - monthly food cost
* [4] - price in energy
* [5] - monthly energy cost
* [6] - price in faith
* [7] - monthly cost in faith
*
*/
int counter = 0;
for (int i: defaultFields)
{
std::map<int, int> params;
for (int j=0;j<8;j++)
{
params.insert({j, defaultArray[counter][j]});
}
// params.insert({0, 10});
// params.insert({1, 2});
// params.insert({2, 10});
// params.insert({3, 0});
// params.insert({4, 10});
// params.insert({5, 0});
// params.insert({6, 0});
// params.insert({7, 0});
tilesDescription.insert({i, params});
counter++;
};
tilesTxt.insert({443, "Your base."});
tilesTxt.insert({651, "Windmill, produces energy.\nEnergy is a basic resource in a game,\nneeded by other buildings to running them."});
tilesTxt.insert({442, "Granary, food storehouse.\nFood gives your people ability to live.\nWithout the food your people will face\na death by starvation."});
tilesTxt.insert({585, "Marketplace, generates cash.\nProvides your tribe trading area.\nToday's offer - dog's bone."});
tilesTxt.insert({1100, "Monasterium, increase your faith.\nAs we all know, our world is being ruled\nby four ancient gods..."});
}
diff --git a/textureholder.h b/textureholder.h
index e605472..3e3afc5 100644
--- a/textureholder.h
+++ b/textureholder.h
@@ -1,45 +1,45 @@
#ifndef TEXTUREHOLDER_H
#define TEXTUREHOLDER_H
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "data.h"
namespace efc {
std::set<int> getTerrainSet();
}
class TextureHolder
{
public:
TextureHolder();
- sf::Texture textureTiles;
- sf::Texture textureFaces;
- sf::Texture textureGui;
- sf::Texture textureMenu;
- sf::Texture textureSymbols;
- sf::Texture textureSeasons;
+// sf::Texture textureTiles;
+// sf::Texture textureFaces;
+// sf::Texture textureGui;
+// sf::Texture textureMenu;
+// sf::Texture textureSymbols;
+// sf::Texture textureSeasons;
sf::Texture backgroundDark;
sf::Texture textureCharacters;
- sf::Texture textureGameBackground;
+// sf::Texture textureGameBackground;
sf::Texture textureBoardDiamond;
sf::Texture textureLetsBegin;
sf::Texture textureCardBase0;
sf::Texture textureCardBase1;
sf::Texture textureCardBase2;
sf::Texture textureCardBase3;
std::array<sf::Texture, 4> textureCardBases;
std::map<int, std::map<int, int>> tilesDescription;
std::map<int, std::string> tilesTxt;
};
#endif // TEXTUREHOLDER_H
diff --git a/tilemap.cpp b/tilemap.cpp
index 2e5c51c..330d63b 100644
--- a/tilemap.cpp
+++ b/tilemap.cpp
@@ -1,170 +1,170 @@
#include "tilemap.h"
namespace efc {
/*!
* Returns sf::Vector2i cords taking int board position as input.
*/
sf::Vector2i transPosition(int pos) {
int x = (int) pos % efc::BOARD_SIZE;
int y = (int) pos / efc::BOARD_SIZE;
sf::Vector2i cords(x,y);
return cords;
}
sf::Vector2i transTilePosition(int pos) {
int x = (int) pos % efc::TILE_BOARD_SIZE;
int y = (int) pos / efc::TILE_BOARD_SIZE;
sf::Vector2i cords(x,y);
return cords;
}
/*!
* Returns int cords taking screen sf::Vector2f position
* as the input.
*/
sf::Vector2i getCords(sf::Vector2f position){
int x = position.x/efc::TILE_BOARD_SIZE;
int y = position.y/efc::TILE_BOARD_SIZE;
return sf::Vector2i(x, y);
}
/*!
* Returns screen sf::Vector2f pos taking sf::Vector2i cords
* as the input.
*/
sf::Vector2f getScreenPos(sf::Vector2i cords){
float x = cords.x * efc::TILE_SIZE;
float y = cords.y * efc::TILE_SIZE;
return sf::Vector2f(x, y);
}
/*!
* Returns int board position (1-256, 16x16) taking
* sf::Vector2i cords as the input.
*/
int transCords(sf::Vector2i cords) {
// std::cout << cords.x << " " << cords.y << " " << std::endl;
int pos = (cords.y * efc::BOARD_SIZE)+cords.x;
return pos;
}
sf::IntRect transPosIntoRect(int pos)
{
sf::Vector2i cords = efc::transTilePosition(pos);
sf::IntRect posRect((int)cords.x*efc::TILE_SIZE, (int)cords.y*efc::TILE_SIZE, efc::TILE_SIZE, efc::TILE_SIZE);
// std::cout << "debug transPosIntoRect " << pos << " "<< cords.x << " " << cords.y << " " << posRect.left << " " << posRect.top << std::endl;
return posRect;
}
std::set<int> getNeighbours(int pos) {
sf::Vector2i cords = efc::transPosition(pos);
std::vector<int> neighbours;
std::set<int> neighboursSet;
std::set<int> terrain = efc::getTerrainSet();
int value = -1;
if (cords.x>0)
{
neighbours.push_back(pos-1);
// neighboursSet.insert(pos-1);
value = pos-1;
if ((value!=-1) && (terrain.count(value)==0))
neighboursSet.insert(value);
}
if (cords.x<efc::BOARD_SIZE-1)
{
neighbours.push_back(pos+1);
// neighboursSet.insert(pos+1);
value = pos+1;
if ((value!=-1) && (terrain.count(value)==0))
neighboursSet.insert(value);
}
if (cords.y>0)
{
neighbours.push_back(pos-efc::BOARD_SIZE);
// neighboursSet.insert(pos-efc::BOARD_SIZE);
value = pos-efc::BOARD_SIZE;
if ((value!=-1) && (terrain.count(value)==0))
neighboursSet.insert(value);
}
if (cords.y<efc::BOARD_SIZE)
{
neighbours.push_back(pos+efc::BOARD_SIZE);
// neighboursSet.insert(pos+efc::BOARD_SIZE);
value = pos+efc::BOARD_SIZE;
if ((value!=-1) && (terrain.count(value)==0))
neighboursSet.insert(value);
}
return neighboursSet;
}
}
TileMap::TileMap()
{
}
-bool TileMap::load(TextureHolder *textures, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
-{
- this->m_tileset = &textures->textureTiles;
- // resize the vertex array to fit the level size
- m_vertices.setPrimitiveType(sf::Quads);
- m_vertices.resize(width * height * 4);
-
- // populate the vertex array, with one quad per tile
- for (unsigned int i = 0; i < width; ++i)
- for (unsigned int j = 0; j < height; ++j)
- {
- // get the current tile number
- int tileNumber = tiles[i + j * width];
-
- // find its position in the tileset texture
- int tu = tileNumber % (m_tileset->getSize().x / tileSize.x);
- int tv = tileNumber / (m_tileset->getSize().x / tileSize.x);
-
- // get a pointer to the current tile's quad
- sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
-
- // define its 4 corners
- quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
- quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
- quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
- quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
-
- // define its 4 texture coordinates
- quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
- quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
- quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
- quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
- }
- return true;
-}
+//bool TileMap::load(TextureHolder *textures, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
+//{
+// this->m_tileset = &textures->textureTiles;
+// // resize the vertex array to fit the level size
+// m_vertices.setPrimitiveType(sf::Quads);
+// m_vertices.resize(width * height * 4);
+
+// // populate the vertex array, with one quad per tile
+// for (unsigned int i = 0; i < width; ++i)
+// for (unsigned int j = 0; j < height; ++j)
+// {
+// // get the current tile number
+// int tileNumber = tiles[i + j * width];
+
+// // find its position in the tileset texture
+// int tu = tileNumber % (m_tileset->getSize().x / tileSize.x);
+// int tv = tileNumber / (m_tileset->getSize().x / tileSize.x);
+
+// // get a pointer to the current tile's quad
+// sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
+
+// // define its 4 corners
+// quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
+// quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
+// quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
+// quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
+
+// // define its 4 texture coordinates
+// quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
+// quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
+// quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
+// quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
+// }
+// return true;
+//}
void TileMap::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the transform
states.transform *= getTransform();
// apply the tileset texture
states.texture = m_tileset;
// draw the vertex array
target.draw(m_vertices, states);
}
sf::VertexArray m_vertices;
sf::Texture m_tileset;
diff --git a/tilemap.h b/tilemap.h
index 828d9bd..042d1a2 100644
--- a/tilemap.h
+++ b/tilemap.h
@@ -1,44 +1,44 @@
#ifndef TILEMAP_H
#define TILEMAP_H
#include <iostream>
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "textureholder.h"
namespace efc {
enum {
TILE_SIZE = 40,
BOARD_SIZE = 16,
TILE_BOARD_SIZE = 80
};
sf::Vector2i transPosition(int pos);
int transCords(sf::Vector2i cords);
std::set<int> getNeighbours(int pos);
sf::IntRect transPosIntoRect(int pos);
sf::Vector2i transTilePosition(int pos);
sf::Vector2i getCords(sf::Vector2f position);
sf::Vector2f getScreenPos(sf::Vector2i cords);
}
class TileMap : public sf::Drawable, public sf::Transformable
{
public:
- bool load(TextureHolder *textures, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
+// bool load(TextureHolder *textures, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
TileMap();
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
sf::VertexArray m_vertices;
sf::Texture *m_tileset;
TextureHolder *textures;
};
#endif // TILEMAP_H

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 10:55 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71331
Default Alt Text
(55 KB)

Event Timeline