Page MenuHomePhabricator (Chris)

No OneTemporary

Size
62 KB
Referenced Files
None
Subscribers
None
diff --git a/CREDITS.md b/CREDITS.md
index cc126d8..b16da86 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -1,42 +1,46 @@
Artwork
=======
*Fantasy book* http://opengameart.org/content/fantasy-book
by yd, Public Domain CC0[^cc0].
*Zw tileset* http://opengameart.org/content/zwischenwelt-tileset
by hagish, Public Domain CC0[^cc0].
*Public domain portraits* http://opengameart.org/content/public-domain-portraits
by qubodup, Public Domain CC0[^cc0].
*Cans in the wind in a garden in Ukraine* http://www.freesound.org/people/felix.blume/sounds/139008/
by felix.blume, This work is licensed under the Creative Commons 0 License[^cc0].
*Menu click effect*, http://www.freesound.org/people/broumbroum/sounds/50561/
by broumbroum, This work is licensed under the Creative Commons 0 License[^cc0].
[^cc0]:Definition of Creative Commons 0 License can be found here: http://creativecommons.org/publicdomain/zero/1.0/
*8 Bit The Hero * http://opengameart.org/content/8-bit-the-hero
bye ShwiggityShwag, This work is licensed under the Creative Commons 0 License[^cc0].
*Andy's Report* http://opengameart.org/content/andys-report-8bit-and-piano-ver
by megupets, This work is licensed under the Creative Commons 0 License[^cc0].
*Ancient symbols* https://openclipart.org/user-detail/cinemacookie
*Dices* https://www.freesound.org/people/qubodup/sounds/189321/
by qubodup
*Collect Done * https://www.freesound.org/people/suntemple/sounds/241809/
by suntemple
+
+*db16 RPG Character Sprites* http://opengameart.org/content/db16-rpg-character-sprites
+
+by usr_share
diff --git a/animatedsprite.cpp b/animatedsprite.cpp
new file mode 100644
index 0000000..5f2fd09
--- /dev/null
+++ b/animatedsprite.cpp
@@ -0,0 +1,188 @@
+////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2014 Maximilian Wagenbach (aka. Foaly) (foaly.f@web.de)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "animatedsprite.h"
+
+AnimatedSprite::AnimatedSprite(sf::Time frameTime, bool paused, bool looped) :
+ m_animation(NULL), m_frameTime(frameTime), m_currentFrame(0), m_isPaused(paused), m_isLooped(looped), m_texture(NULL)
+{
+
+}
+
+void AnimatedSprite::setAnimation(const Animation& animation)
+{
+ m_animation = &animation;
+ m_texture = m_animation->getSpriteSheet();
+ m_currentFrame = 0;
+ setFrame(m_currentFrame);
+}
+
+void AnimatedSprite::setFrameTime(sf::Time time)
+{
+ m_frameTime = time;
+}
+
+void AnimatedSprite::play()
+{
+ m_isPaused = false;
+}
+
+void AnimatedSprite::play(const Animation& animation)
+{
+ if (getAnimation() != &animation)
+ setAnimation(animation);
+ play();
+}
+
+void AnimatedSprite::pause()
+{
+ m_isPaused = true;
+}
+
+void AnimatedSprite::stop()
+{
+ m_isPaused = true;
+ m_currentFrame = 0;
+ setFrame(m_currentFrame);
+}
+
+void AnimatedSprite::setLooped(bool looped)
+{
+ m_isLooped = looped;
+}
+
+void AnimatedSprite::setColor(const sf::Color& color)
+{
+ // Update the vertices' color
+ m_vertices[0].color = color;
+ m_vertices[1].color = color;
+ m_vertices[2].color = color;
+ m_vertices[3].color = color;
+}
+
+const Animation* AnimatedSprite::getAnimation() const
+{
+ return m_animation;
+}
+
+sf::FloatRect AnimatedSprite::getLocalBounds() const
+{
+ sf::IntRect rect = m_animation->getFrame(m_currentFrame);
+
+ float width = static_cast<float>(std::abs(rect.width));
+ float height = static_cast<float>(std::abs(rect.height));
+
+ return sf::FloatRect(0.f, 0.f, width, height);
+}
+
+sf::FloatRect AnimatedSprite::getGlobalBounds() const
+{
+ return getTransform().transformRect(getLocalBounds());
+}
+
+bool AnimatedSprite::isLooped() const
+{
+ return m_isLooped;
+}
+
+bool AnimatedSprite::isPlaying() const
+{
+ return !m_isPaused;
+}
+
+sf::Time AnimatedSprite::getFrameTime() const
+{
+ return m_frameTime;
+}
+
+void AnimatedSprite::setFrame(std::size_t newFrame, bool resetTime)
+{
+ if (m_animation)
+ {
+ //calculate new vertex positions and texture coordiantes
+ sf::IntRect rect = m_animation->getFrame(newFrame);
+
+ m_vertices[0].position = sf::Vector2f(0.f, 0.f);
+ m_vertices[1].position = sf::Vector2f(0.f, static_cast<float>(rect.height));
+ m_vertices[2].position = sf::Vector2f(static_cast<float>(rect.width), static_cast<float>(rect.height));
+ m_vertices[3].position = sf::Vector2f(static_cast<float>(rect.width), 0.f);
+
+ float left = static_cast<float>(rect.left) + 0.0001f;
+ float right = left + static_cast<float>(rect.width);
+ float top = static_cast<float>(rect.top);
+ float bottom = top + static_cast<float>(rect.height);
+
+ m_vertices[0].texCoords = sf::Vector2f(left, top);
+ m_vertices[1].texCoords = sf::Vector2f(left, bottom);
+ m_vertices[2].texCoords = sf::Vector2f(right, bottom);
+ m_vertices[3].texCoords = sf::Vector2f(right, top);
+ }
+
+ if (resetTime)
+ m_currentTime = sf::Time::Zero;
+}
+
+void AnimatedSprite::update(sf::Time deltaTime)
+{
+ // if not paused and we have a valid animation
+ if (!m_isPaused && m_animation)
+ {
+ // add delta time
+ m_currentTime += deltaTime;
+
+ // if current time is bigger then the frame time advance one frame
+ if (m_currentTime >= m_frameTime)
+ {
+ // reset time, but keep the remainder
+ m_currentTime = sf::microseconds(m_currentTime.asMicroseconds() % m_frameTime.asMicroseconds());
+
+ // get next Frame index
+ if (m_currentFrame == 0)
+ m_currentFrame++;
+ else
+ {
+ // animation has ended
+ m_currentFrame = 0; // reset to start
+
+ if (!m_isLooped)
+ {
+ m_isPaused = true;
+ }
+
+ }
+
+ // set the current frame, not reseting the time
+ setFrame(m_currentFrame, false);
+ }
+ }
+}
+
+void AnimatedSprite::draw(sf::RenderTarget& target, sf::RenderStates states) const
+{
+ if (m_animation && m_texture)
+ {
+ states.transform *= getTransform();
+ states.texture = m_texture;
+ target.draw(m_vertices, 4, sf::Quads, states);
+ }
+}
diff --git a/animatedsprite.h b/animatedsprite.h
new file mode 100644
index 0000000..c0f886b
--- /dev/null
+++ b/animatedsprite.h
@@ -0,0 +1,72 @@
+////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2014 Maximilian Wagenbach (aka. Foaly) (foaly.f@web.de)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#ifndef ANIMATEDSPRITE_INCLUDE
+#define ANIMATEDSPRITE_INCLUDE
+
+#include <SFML/Graphics/RenderTarget.hpp>
+#include <SFML/System/Time.hpp>
+#include <SFML/Graphics/Drawable.hpp>
+#include <SFML/Graphics/Transformable.hpp>
+#include <SFML/System/Vector2.hpp>
+
+#include "animation.h"
+
+class AnimatedSprite : public sf::Drawable, public sf::Transformable
+{
+public:
+ explicit AnimatedSprite(sf::Time frameTime = sf::seconds(0.2f), bool paused = false, bool looped = true);
+
+ void update(sf::Time deltaTime);
+ void setAnimation(const Animation& animation);
+ void setFrameTime(sf::Time time);
+ void play();
+ void play(const Animation& animation);
+ void pause();
+ void stop();
+ void setLooped(bool looped);
+ void setColor(const sf::Color& color);
+ const Animation* getAnimation() const;
+ sf::FloatRect getLocalBounds() const;
+ sf::FloatRect getGlobalBounds() const;
+ bool isLooped() const;
+ bool isPlaying() const;
+ sf::Time getFrameTime() const;
+ void setFrame(std::size_t newFrame, bool resetTime = true);
+ const Animation* m_animation;
+
+
+private:
+ sf::Time m_frameTime;
+ sf::Time m_currentTime;
+ std::size_t m_currentFrame;
+ bool m_isPaused;
+ bool m_isLooped;
+ const sf::Texture* m_texture;
+ sf::Vertex m_vertices[4];
+
+ virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+
+};
+
+#endif // ANIMATEDSPRITE_INCLUDE
diff --git a/animation.cpp b/animation.cpp
new file mode 100644
index 0000000..28f33cb
--- /dev/null
+++ b/animation.cpp
@@ -0,0 +1,54 @@
+////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2014 Maximilian Wagenbach (aka. Foaly) (foaly.f@web.de)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "animation.h"
+
+Animation::Animation() : m_texture(NULL)
+{
+
+}
+
+void Animation::addFrame(sf::IntRect rect)
+{
+ m_frames.push_back(rect);
+}
+
+void Animation::setSpriteSheet(const sf::Texture& texture)
+{
+ m_texture = &texture;
+}
+
+const sf::Texture* Animation::getSpriteSheet() const
+{
+ return m_texture;
+}
+
+std::size_t Animation::getSize() const
+{
+ return m_frames.size();
+}
+
+const sf::IntRect& Animation::getFrame(std::size_t n) const
+{
+ return m_frames[n];
+}
diff --git a/animation.h b/animation.h
new file mode 100644
index 0000000..f9ec7f2
--- /dev/null
+++ b/animation.h
@@ -0,0 +1,47 @@
+////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2014 Maximilian Wagenbach (aka. Foaly) (foaly.f@web.de)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#ifndef ANIMATION_INCLUDE
+#define ANIMATION_INCLUDE
+
+#include <vector>
+#include <SFML/Graphics/Rect.hpp>
+#include <SFML/Graphics/Texture.hpp>
+
+class Animation
+{
+public:
+ Animation();
+
+ void addFrame(sf::IntRect rect);
+ void setSpriteSheet(const sf::Texture& texture);
+ const sf::Texture* getSpriteSheet() const;
+ std::size_t getSize() const;
+ const sf::IntRect& getFrame(std::size_t n) const;
+
+private:
+ std::vector<sf::IntRect> m_frames;
+ const sf::Texture* m_texture;
+};
+
+#endif // ANIMATION_INCLUDE
diff --git a/assets/img/characters.png b/assets/img/characters.png
new file mode 100644
index 0000000..2d592d5
Binary files /dev/null and b/assets/img/characters.png differ
diff --git a/character.cpp b/character.cpp
new file mode 100644
index 0000000..0052afc
--- /dev/null
+++ b/character.cpp
@@ -0,0 +1,167 @@
+#include "character.h"
+
+
+
+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 << "" << 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;
+
+ 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 = &walkingAnimationLeft;
+
+
+ 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(40, 40),sf::Vector2f(540, 40),sf::Vector2f(40, 440),sf::Vector2f(540, 440)};
+ setPosition(positions[playerNumber]);
+
+
+}
+
+void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
+{
+
+ states.transform *= getTransform();
+ target.draw(animatedSprite, states);
+
+}
+
+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::TILE_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::TILE_BOARD_SIZE-1)
+ {
+ setDirIndex(efc::DIR_LEFT);
+ setDir();
+ }
+ }
+
+
+ animatedSprite.update(deltaTime);
+}
+
+sf::FloatRect Character::getLocalBounds() const
+{
+
+ return sf::FloatRect(0.f, 0.f, 0, 0);
+}
+
+sf::FloatRect Character::getGlobalBounds() const
+{
+ return getTransform().transformRect(getLocalBounds());
+}
diff --git a/character.h b/character.h
new file mode 100644
index 0000000..1a539fa
--- /dev/null
+++ b/character.h
@@ -0,0 +1,41 @@
+#ifndef CHARACTER_H
+#define CHARACTER_H
+#include <random>
+#include <iostream>
+#include "data.h"
+#include "textureholder.h"
+#include "animatedsprite.h"
+#include "tilemap.h"
+
+
+class Character: public sf::Drawable, public sf::Transformable
+{
+public:
+ Character(TextureHolder *textures, int playerNumber);
+ TextureHolder *textures;
+ Animation walkingAnimationDown;
+ Animation walkingAnimationUp;
+ Animation walkingAnimationLeft;
+ Animation walkingAnimationRight;
+ Animation animations[4];
+ Animation* currentAnimation;
+ int currentAnimationIndex;
+
+ AnimatedSprite animatedSprite;
+ sf::FloatRect getLocalBounds() const;
+ sf::FloatRect getGlobalBounds() const;
+ void setDirUp();
+ void setDirDown();
+ void setDirLeft();
+ void setDirRight();
+ virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+ void update(sf::Time deltaTime);
+ void play();
+ void setDir();
+ void setDir(int direction);
+ void setDirIndex(int direction);
+ float nextRedirect;
+
+};
+
+#endif // CHARACTER_H
diff --git a/data.h b/data.h
index 0bc55cc..691f3ec 100644
--- a/data.h
+++ b/data.h
@@ -1,6 +1,12 @@
#ifndef DATA_H
#define DATA_H
namespace efc {
static std::string seasonsNames[4] = {"spring", "summer", "fall", "winter"};
+ enum directions {
+ DIR_LEFT,
+ DIR_RIGHT,
+ DIR_UP,
+ DIR_DOWN
+ };
}
#endif // DATA_H
diff --git a/game.cpp b/game.cpp
index 25e4598..f320e77 100644
--- a/game.cpp
+++ b/game.cpp
@@ -1,616 +1,643 @@
#include "game.h"
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);
groupHud.setFont(&gameFont);
groupHud.setSeason(currentSeason);
groupHud.setRoundName(roundNumber);
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/VCR_OSD_MONO_1.001.ttf"))
{
std::exit(1);
}
if (!menuFont.loadFromFile("assets/fnt/VCR_OSD_MONO_1.001.ttf"))
{
std::exit(1);
}
menuTxt.setFont(menuFont);
- menuTxt.setCharacterSize(120);
+ menuTxt.setCharacterSize(60);
menuTxt.setString(gameTitle);
-
- menuTxt.setColor(sf::Color(55, 255, 35, 85));
-
int width = menuTxt.getLocalBounds().width;
int height = menuTxt.getLocalBounds().height;
-
menuTxt.setPosition(400-(width/2),300-(height/2)-150);
- // menuTxt.setScale(0.5, 0.5);
+ menuTxt.setColor(sf::Color(55, 255, 35, 85));
}
void Game::showMenu()
{
menuBackground.setTexture(textures.textureMenu);
musicMenu.play();
musicMenu.setLoop(true);
currentState = state_menu;
}
void Game::hideMenu()
{
musicMenu.stop();
}
void Game::showGameBoard()
{
musicGame.setVolume(20);
musicGame.play();
musicGame.setLoop(true);
currentState = state_game;
}
void Game::hideGameBoard()
{
musicGame.play();
}
Game::Game():
- window(sf::VideoMode(800, 600), "Pagan Board"),
+ screenSize(efc::initScreenX,efc::initScreenY),
+ window(sf::VideoMode(efc::initScreenX, efc::initScreenY), "Pagan Board"),
viewTiles(sf::FloatRect(0, 0, 524, 458)),
- viewGui(sf::FloatRect(00, 00, 800, 600)),
- viewFull(sf::FloatRect(00, 00, 800, 600)),
+ viewGui(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
+ viewFull(sf::FloatRect(00, 00, screenSize.x, screenSize.y)),
selector(efc::TILE_SIZE),
guiSelectBuilding(&textures),
+ character(&textures, 3),
turn(0),
- gameTitle(" PAgAN\nBOaRD "),
+ gameTitle("pagan\nboard"),
roundDice(players),
roundNumber(1),
guiRoundDice(&textures)
{
if (!textureBackground.loadFromFile("assets/img/background.png"))
std::exit(1);
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)};
int gWidth = guiSelectBuilding.rectangle.getLocalBounds().width;
int gHeight = guiSelectBuilding.rectangle.getLocalBounds().height;
int borderLeft = 31;
int borderRight = 28;
int borderTop = 39;
int borderBottom = 39;
int guiWidth = 128;
int guiStartPos[4][2] = {
{borderLeft+3,borderTop+2},
- {800 - guiWidth - borderRight - gWidth-4,borderTop+2},
- {borderLeft+3,600-gHeight-borderBottom-4} ,
- {800 - guiWidth - borderRight - gWidth-4, 600-gHeight-borderBottom-4}};
+ {screenSize.x - guiWidth - borderRight - gWidth-4,borderTop+2},
+ {borderLeft+3,screenSize.y-gHeight-borderBottom-4} ,
+ {screenSize.x - guiWidth - borderRight - gWidth-4, screenSize.y-gHeight-borderBottom-4}};
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::Clock frameClock;
+
+ float speed = 80.f;
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(568,000);
// spriteBackgroundDark.setColor(sf::Color(55,55,55,155));
spriteBackground.setTexture(textureBackground);
guiRoundDice.active = true;
showPlayerBoardElems = false;
if (!musicGame.openFromFile("assets/audio/game.ogg"))
std::exit(1);
if (!musicBackground.openFromFile("assets/audio/wind.ogg"))
std::exit(1);
if (!musicMenu.openFromFile("assets/audio/menu.ogg"))
std::exit(1);
musicBackground.play();
musicBackground.setLoop(true);
if (!sfxClickBuffer.loadFromFile("assets/audio/click.ogg"))
std::exit(1);
sfxClick.setBuffer(sfxClickBuffer);
if (!sfxDoneBuffer.loadFromFile("assets/audio/done.ogg"))
std::exit(1);
sfxDone.setBuffer(sfxDoneBuffer);
window.setVerticalSyncEnabled(true);
Hover hover;
GuiWindow guiWindow(&textures);
std::srand (time(NULL));
loadAssets();
viewTiles.setViewport(sf::FloatRect(0.04f,0.060f, 1.0f, 1.0f));
viewGui.setViewport(sf::FloatRect(0.806f,0.066f, 1, 1));
selector.changeColor(turn); //This is only for the test TODO: remove
initBoard();
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_game)
{
if ((localPosition.x>400) || (localPosition.x<0) || (localPosition.y>400) || (localPosition.y<0))
{
showPlayerBoardElems = false;
players[turn].elems.displayNeighbours = false;
} else {
showPlayerBoardElems = true;
players[turn].elems.displayNeighbours = true;
}
}
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
if (currentState==state_game)
{
resultCommand = players[turn].getElem(localPositionGui);
command(resultCommand);
if (currentNeighbours.find(mousePos) != currentNeighbours.end())
{
if ((!guiSelectBuilding.active) && (showPlayerBoardElems))
{
float hover_x =localPositionFull.x;
float hover_y = localPositionFull.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;
std::cout << hover_x << " " << hover_y << std::endl;
guiSelectBuilding.setPosition(guiStartPos[turn][0],guiStartPos[turn][1]);
guiSelectBuilding.active = true;
sfxClick.play();
currentState = state_gui_elem;
}
break;
}
// nextPlayer();
}
if (currentState==state_gui_elem)
{
resultCommand = guiSelectBuilding.getElem(localPositionFull);
if (resultCommand.find("elem_")==0)
{
std::string resultCommandWrapped = "build_" + resultCommand;
command(resultCommandWrapped);
} else if (resultCommand.find("close_gui")==0)
{ command(resultCommand);}
}
if (currentState==state_menu)
{
hideMenu();
showGameBoard();
}
if (currentState==state_gui_end_round)
{
resultCommand = guiRoundDice.getElem(localPosition);
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);
}
}
+// character.play();
+ for (int i=0;i<4;i++)
+ {
+ players[i].play();
+ }
+// animatedSprite.play(*currentAnimation);
+// animatedSprite.update(frameTime);
+ sf::Vector2f movement(-10.f, 0.f);
+ character.move(movement * frameTime.asSeconds());
+ for (int i=0;i<4;i++)
+ {
+ players[i].update(frameTime);
+ }
+
+ character.update(frameTime);
render();
}
}
void Game::nextRound() {
turn = 0;
std::string result = roundDice.drawRound();
roundNumber += 1;
std::cout << "END OF ROUND " << roundNumber << " " << result << std::endl;
month++;
if (month==13)
month=1;
if (month%4==0)
currentSeason++;
if (currentSeason>3)
currentSeason=0;
command(result);
}
void Game::nextPlayer(){
players[turn].updatePlayer();
turn++;
if (turn==4)
{
nextRound();
}
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();
std::cout << roundNumber << " " << roundNumber % 16 << std::endl;
groupHud.setRoundName(roundNumber);
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
window.draw(players[i]);
}
window.draw(seasons[currentSeason]);
}
void Game::drawSquares() {
if (showPlayerBoardElems)
{
window.draw(selector);
}
}
void Game::update()
{
}
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);
drawPlayersGui();
window.setView(viewTiles);
}
+void Game::drawCharacters(){
+ window.setView(viewFull);
+ for (int i=0;i<4;i++)
+ {
+ for (auto&& j: players[i].characters)
+ {
+ window.draw(j);
+ }
+
+ }
+}
+
void Game::render()
{
window.clear();
if (currentState==state_game)
{
window.setView(viewFull);
window.draw(spriteBackgroundDark);
window.setView(viewTiles);
+
+
+
drawBaseGame();
+drawCharacters();
+
} else if (currentState==state_gui_elem) {
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
- window.setView(viewFull);
+ drawCharacters();
window.draw(guiSelectBuilding);
} else if (currentState==state_menu) {
window.draw(menuBackground);
window.draw(menuTxt);
window.draw(groupHud);
- // window.setView(viewFull);
+ window.setView(viewFull);
// window.draw(spriteBackgroundDark);
} else if (currentState==state_gui_end_round){
window.setView(viewFull);
window.draw(spriteBackgroundDark);
drawBaseGame();
window.draw(guiRoundDice);
- // window.setView(viewFull);
+drawCharacters();
// window.draw(spriteBackgroundDark);
}
window.setView(viewFull);
// window.draw(spriteBackgroundDark);
window.draw(spriteBackground);
window.draw(groupHud);
+
+
window.display();
}
void Game::command(std::string command){
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("end_of_round")==0)
{
std::string subResult = command.substr(13);
std::cout << "SUB RESULT " << subResult << std::endl;
guiRoundDice.active = true;
guiRoundDice.setTitle(subResult);
currentState = state_gui_end_round;
}
if (command.find("elem_")==0)
{
if (currentState==state_gui_elem)
{
int buildingType = std::stoi(command.substr(5));
int cashUpd = textures.tilesDescription[buildingType][0];
int cashCost = textures.tilesDescription[buildingType][1];
int foodUpd = textures.tilesDescription[buildingType][2];
int foodCost = textures.tilesDescription[buildingType][3];
int enrgUpd = textures.tilesDescription[buildingType][4];
int enrgCost = textures.tilesDescription[buildingType][5];
std::string descTxt = textures.tilesTxt[buildingType];
-
char priceTxtChar [100];
int cx = snprintf ( priceTxtChar, 100, "Price: cash: %2d food: %2d energy: %2d \n", cashUpd, foodUpd, enrgUpd);
std::string priceTxt = priceTxtChar;
-
-
char costTxtChar [100];
cx = snprintf ( costTxtChar, 100, "Cost: cash: %2d food: %2d energy: %2d \n", cashCost, foodCost, enrgCost);
std::string costTxt = costTxtChar;
-
- // std::string priceTxt = "Price: cash:" + std::to_string(cashUpd) + " food: " + std::to_string(foodUpd) + " energy: " + std::to_string(enrgUpd);
- // std::string costTxt = "Cost: cash:" + std::to_string(cashCost) + " food: " + std::to_string(foodCost) + " energy: " + std::to_string(enrgCost);
-
-
guiSelectBuilding.setDescriptionTxt(priceTxt + costTxt + "\n"+descTxt);
guiSelectBuilding.descriptionActive = true;
}
}
if (command=="end_turn")
nextPlayer();
if (command.find("build_")==0)
{
int buildingType = std::stoi(command.substr(11));
bool purchaseResult = players[turn].addElem(selectedPos, buildingType);
if (purchaseResult)
{
currentState = state_game;
setCurrentNeighbours();
guiSelectBuilding.active = false;
sfxDone.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 2d72eb2..755a15e 100644
--- a/game.h
+++ b/game.h
@@ -1,124 +1,144 @@
#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"
#include "rounddice.h"
#include "guirounddice.h"
#include "grouphud.h"
+#include "animatedsprite.h"
+#include "character.h"
+
namespace efc {
+static int initScreenX = 800;
+static int initScreenY = 600;
+
class Game
{
public:
Game();
sf::RenderWindow window;
sf::View viewTiles;
private:
+ sf::Vector2i screenSize;
+
+
void initBoard();
void loadAssets();
void drawPlayersGui();
void drawSquares();
void drawMenu();
sf::Vector2f getMousePos();
enum states {
state_init,
state_menu,
state_game,
state_gui_elem,
state_select_building,
state_gui_end_round,
state_quit
};
states currentState;
sf::Texture textureBackground;
sf::Sprite spriteBackground;
sf::Sprite spriteBackgroundDark;
sf::Texture textureTiles;
sf::Texture textureFaces;
sf::Font gameFont;
sf::Font menuFont;
sf::Text menuTxt;
std::string gameTitle;
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;
RoundDice roundDice;
int roundNumber;
GuiChooseBuilding guiSelectBuilding;
GuiRoundDice guiRoundDice;
void setCurrentNeighbours ();
void nextPlayer();
void nextRound();
sf::Sprite menuBackground;
sf::Sprite seasons[4];
int currentSeason = 0;
sf::Music musicGame;
sf::Music musicBackground;
sf::Music musicMenu;
sf::SoundBuffer sfxClickBuffer;
sf::Sound sfxClick;
sf::SoundBuffer sfxDoneBuffer;
sf::Sound sfxDone;
void showMenu();
void hideMenu();
void showGameBoard();
void hideGameBoard();
GroupHud groupHud;
bool showPlayerBoardElems;
void drawBaseGame();
int month = 0;
+
+ Animation walkingAnimationDown;
+ Animation walkingAnimationUp;
+ Animation walkingAnimationLeft;
+ Animation walkingAnimationRight;
+ Animation* currentAnimation;
+ AnimatedSprite animatedSprite;
+
+ Character character;
+ void drawCharacters();
+
};
}
#endif // GAME_H
diff --git a/pagan_board.pro b/pagan_board.pro
index cd9f42d..7069167 100644
--- a/pagan_board.pro
+++ b/pagan_board.pro
@@ -1,52 +1,58 @@
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
+ grouphud.cpp \
+ animation.cpp \
+ animatedsprite.cpp \
+ character.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
+ data.h \
+ animation.h \
+ animatedsprite.h \
+ character.h
RESOURCES += \
images.qrc
OTHER_FILES += \
CREDITS.md
diff --git a/playerhud.cpp b/playerhud.cpp
index 3cf6e86..79f6f95 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,254 +1,296 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
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();
+ characters.push_back(Character (this->textures, this->pos));
+
return true;
+
}
return false;
}
std::set<int> PlayerHud::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrain)
{
// std::cout << i << std::endl;
terrain.insert(i);
}
return terrain;
}
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( "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][5];
int faithUpd = textures->tilesDescription[i.type][7];
cash += cashUpd;
energy += enrgUpd;
food += foodUpd;
faith += faithUpd;
updateTxt();
}
}
PlayerHud::PlayerHud()
{
}
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;
+ Character character(this->textures, pos);
+ characters.push_back(Character (this->textures, pos));
efc::BoardElem startElem(textures, startPlayers[pos],444);
startElem.setColor(efc::playersColors[pos]);
elems.items.push_back(startElem);
elems.items_map.insert({startPlayers[pos], startElem});
this->faceSize = faceSize;
spriteFace.setTexture(textures->textureFaces);
this->pos = pos;
symbol.setTexture(this->textures->textureSymbols);
sf::IntRect symbolsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
symbol.setTextureRect(symbolsRect[pos]);
symbol.setScale(sf::Vector2f(0.2f, 0.20f));
symbol.setColor(sf::Color(25, 25, 25, 105));
symbol.setPosition(60, (pos*100)+40);
food = 0;
cash = 20;
energy = 0;
faith = 0;
int x = faceNumber % 10;
int y = (int) faceNumber /10;
txtCash.setFont(*gameFont);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
// txtNextRound.setScale(sf::Vector2f(0.25f, 1.f));
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(pos*100)+10);
txtCash.setPosition(1,(pos*100)+40);
// 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.setCharacterSize(10);
// txtFood.setScale(sf::Vector2f(0.25f, 1.f));
txtEnergy.setPosition(1,(pos*100)+70);
// txtEnergy.setString("Enrg: " + std::to_string(energy));
txtEnergy.setCharacterSize(10);
// txtEnergy.setScale(sf::Vector2f(0.25f, 1.f));
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)*7, this->faceSize));
rectangle2.setSize(sf::Vector2f((this->faceSize)*7, (this->faceSize*2)+3));
if (pos==0)
{
rectangle.setFillColor(sf::Color(50, 50, 200,68));
rectangle2.setFillColor(sf::Color(100, 100, 150,38));
rectangle.setOutlineColor(sf::Color(0,0,128,68));
}
else if (pos==1)
{
rectangle.setFillColor(sf::Color(50, 150, 50,68));
rectangle2.setFillColor(sf::Color(100, 150,100,38));
rectangle.setOutlineColor(sf::Color(0,128,0,68));
}
else if (pos==2)
{
rectangle.setFillColor(sf::Color(150, 50, 50,68));
rectangle2.setFillColor(sf::Color(150, 100,100,38));
rectangle.setOutlineColor(sf::Color(128,0,0,68));
}
else if (pos==3)
{
rectangle.setFillColor(sf::Color(150, 150, 150,68));
rectangle2.setFillColor(sf::Color(200, 200,200,38));
rectangle.setOutlineColor(sf::Color(128,128,128,68));
}
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;
// std::cout << closeRect.left << " " << closeRect.top << " " << closeRect.width << " " << closeRect.height
// << hoverPos.x << " " << hoverPos.y << " OK"
// << std::endl;
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
{
// // 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(symbol, states);
target.draw(spriteFace, states);
}
+void PlayerHud::play()
+{
+ for (auto&& i: characters)
+ {
+
+ i.play();
+}
+
+}
+void PlayerHud::update(sf::Time deltaTime)
+{
+ 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.move(movement * deltaTime.asSeconds());
+ i.update(deltaTime);
+
+
+ }
+
+}
diff --git a/playerhud.h b/playerhud.h
index 1433ec2..cea0351 100644
--- a/playerhud.h
+++ b/playerhud.h
@@ -1,68 +1,77 @@
#ifndef PLAYERHUD_H
#define PLAYERHUD_H
#include <iostream>
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "boardelems.h"
#include "textureholder.h"
#include "elemsdescription.h"
#include "guiwindow.h"
+#include "character.h"
static int startPlayers[4] = {0,15,240,255};
namespace efc {
static 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)
};
}
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;
bool addElem(int pos, int type);
void updatePlayer();
std::string getElem(sf::Vector2f mousePosition);
std::map<std::string, sf::RectangleShape> buttons;
void updateTxt();
+ std::vector<Character> characters;
+
+ void update(sf::Time deltaTime);
+ void play();
+
+
+
+
private:
sf::Sprite spriteFace;
sf::Text txtCash;
sf::Text txtEnergy;
sf::Text txtFood;
sf::Text txtFaith;
sf::Text txtNextRound;
int faceSize;
int tileSize;
TextureHolder *textures;
sf::RectangleShape rectangle;
sf::RectangleShape rectangle2;
sf::Sprite symbol;
std::set<int> getTerrainSet();
};
#endif // PLAYERHUD_H
diff --git a/textureholder.cpp b/textureholder.cpp
index d0bff95..e606f53 100644
--- a/textureholder.cpp
+++ b/textureholder.cpp
@@ -1,80 +1,83 @@
#include "textureholder.h"
TextureHolder::TextureHolder()
{
// textureTiles.setSmooth(true);
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 (!textureCharacters.loadFromFile("assets/img/characters.png"))
+ std::exit(1);
+
if (!backgroundDark.loadFromFile("assets/img/background_dark.png"))
std::exit(1);
if (!textureMenu.loadFromFile("assets/img/menu.jpg"))
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 6a73d75..b902e03 100644
--- a/textureholder.h
+++ b/textureholder.h
@@ -1,47 +1,48 @@
#ifndef TEXTUREHOLDER_H
#define TEXTUREHOLDER_H
#include <set>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
namespace efc {
static int terrain[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
};
static std::set<int> getTerrainSet() {
std::set<int> terrain;
for (int i: efc::terrain)
{
terrain.insert(i);
}
return terrain;
}
}
class TextureHolder
{
public:
TextureHolder();
sf::Texture textureTiles;
sf::Texture textureFaces;
sf::Texture textureGui;
sf::Texture textureMenu;
sf::Texture textureSymbols;
sf::Texture textureSeasons;
sf::Texture backgroundDark;
+ sf::Texture textureCharacters;
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 8422978..69570a5 100644
--- a/tilemap.cpp
+++ b/tilemap.cpp
@@ -1,142 +1,150 @@
#include "tilemap.h"
namespace efc {
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;
}
+sf::Vector2i getCords(sf::Vector2f position){
+ int x = position.x/efc::BOARD_SIZE;
+ int y = position.y/efc::BOARD_SIZE;
+ return sf::Vector2i(x, y);
+
+}
+
+
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;
}
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 14b106f..1b60396 100644
--- a/tilemap.h
+++ b/tilemap.h
@@ -1,39 +1,41 @@
#ifndef TILEMAP_H
#define TILEMAP_H
#include <iostream>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "textureholder.h"
#include <set>
namespace efc {
enum {
TILE_SIZE = 25,
BOARD_SIZE = 16,
TILE_BOARD_SIZE = 40
};
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);
+
}
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);
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, Feb 4, 2:09 PM (2 h, 7 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55609
Default Alt Text
(62 KB)

Event Timeline