Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
66 KB
Referenced Files
None
Subscribers
None
diff --git a/.gitignore b/.gitignore
index 142e4e2..85abc84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,30 +1,33 @@
linuxdeploy-x86_64.AppImage
build/
parts/
prime/
snap/
stage/
DeerPortal
*.snap
*.o
enfucraft
enfucraft.pro.user
Makefile
docs/
pagan_board.pro.user
*.swo
*.swp
*.Release
*.Debug
*.debhelper.log
debian/deerportal
MakeCache.txt
CMakeFiles/
CPackConfig.cmake
CPackSourceConfig.cmake
cmake_install.cmake
CMakeCache.txt
.vs
out
install_manifest.txt
DeerPortal-*.AppImage
+SFML-2*
+DeerPortal.exe.gui
+CMakeSettings.json
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bff527b..919fe09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,85 +1,118 @@
#Change this if you need to target a specific CMake version
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
# To unify version handling
file (STRINGS "version.txt" DEERPORTAL_VERSION)
string(REGEX MATCH "^([0-9]+)" DEERPORTAL_VERSION_MAJOR ${DEERPORTAL_VERSION})
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\2" DEERPORTAL_VERSION_MINOR ${DEERPORTAL_VERSION})
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+.*)" "\\3" DEERPORTAL_VERSION_PATCH ${DEERPORTAL_VERSION})
MESSAGE( STATUS "DEERPORTAL_VERSION: " ${DEERPORTAL_VERSION} )
MESSAGE( STATUS "DEERPORTAL_VERSION_MAJOR: " ${DEERPORTAL_VERSION_MAJOR} )
MESSAGE( STATUS "DEERPORTAL_VERSION_MINOR: " ${DEERPORTAL_VERSION_MINOR} )
MESSAGE( STATUS "DEERPORTAL_VERSION_PATCH: " ${DEERPORTAL_VERSION_PATCH} )
# Enable debug symbols by default
# must be done before project() statement
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()
# (you can also set it on the command line: -D CMAKE_BUILD_TYPE=Release)
project(myproject)
#target_compile_definitions(DeerPortal PRIVATE FOO=1 BAR=1)
add_definitions(-DDEERPORTAL_VERSION="${DEERPORTAL_VERSION}.${CMAKE_BUILD_TYPE}")
# Set version information in a config.h file
# configure_file(
# "${PROJECT_SOURCE_DIR}/config.h.in"
# "${PROJECT_BINARY_DIR}/config.h"
# )
include_directories("${PROJECT_BINARY_DIR}")
include_directories(${YOUR_DIRECTORY})
# Define sources and executable
set(EXECUTABLE_NAME "DeerPortal")
file( GLOB SRCS src/*.cpp src/*.h )
-add_executable(${EXECUTABLE_NAME} ${SRCS})
+
+IF(WIN32)
+ #Now we are looking for "sfml-main.lib".
+ #Because we need it if we give ADD_EXECUTABLE the WIN32 switch to creat a GUI application (that one without a cmd promt)
+ FIND_LIBRARY( SFML_MAIN_LIBRARY
+ NAMES sfml-main
+ PATH_SUFFIXES lib64 lib
+ PATHS ${SFML_LIBRARY_SEARCH_DIR}
+ )
+ LIST(APPEND SFML_LIBRARY ${SFML_MAIN_LIBRARY})
+ENDIF(WIN32)
+
+
+
+
+IF (WIN32)
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
+
+add_executable(${EXECUTABLE_NAME} WIN32 ${SRCS}
+
+ ${CMAKE_CURRENT_SOURCE_DIR}/scripts/DeerPortal.rc
+ )
+
+ELSE()
+add_executable(${EXECUTABLE_NAME} ${SRCS}
+
+
+ )
+ENDIF()
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED network audio graphics window system)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget
RESOURCE "${RESOURCE_FILES}"
)
# Install target
+
+
IF (WIN32)
set (ASSETS_BASE_PATH data)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION .)
+ file(WRITE DeerPortal.exe.gui "")
+ install(FILES DeerPortal.exe.gui DESTINATION .)
+
ELSE()
set (ASSETS_BASE_PATH share/games/deerportal)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
ENDIF()
add_definitions(-DBASE_PATH="${CMAKE_INSTALL_PREFIX}")
IF (WIN32)
add_definitions(-DASSETS_PATH="${ASSETS_BASE_PATH}/")
#install(DIRECTORY assets DESTINATION share/games/deerportal)
install(DIRECTORY assets DESTINATION "${ASSETS_BASE_PATH}/")
ELSE()
add_definitions(-DASSETS_PATH="${CMAKE_INSTALL_PREFIX}/${ASSETS_BASE_PATH}/")
# install(DIRECTORY assets DESTINATION share/games/deerportal)
install(DIRECTORY assets DESTINATION "${CMAKE_INSTALL_PREFIX}/${ASSETS_BASE_PATH}/")
ENDIF()
# install(DIRECTORY assets DESTINATION share/games/deerportal)
# CPack packaging
include(InstallRequiredSystemLibraries)
# set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${DEERPORTAL_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${DEERPORTAL_VERSION_MINOR}.${DEERPORTAL_VERSION_PATCH}")
include(CPack)
diff --git a/handbook.tex b/handbook.tex
new file mode 100644
index 0000000..aa24191
--- /dev/null
+++ b/handbook.tex
@@ -0,0 +1,20 @@
+\documentclass[12pt]{article}
+\title{Deer Portal \\ \large Handbook}
+
+\date{\today}
+\author{Rafał Zawadzki}
+\usepackage{titling}
+\usepackage[showframe]{geometry}
+\usepackage{hyperref}
+\renewcommand\maketitlehooka{\null\mbox{}\vfill}
+\renewcommand\maketitlehookd{\vfill\null}
+\begin{document}
+\maketitle
+\newpage
+\tableofcontents
+\newpage
+\section*{Sample Chapter}
+Hello world \LaTeX
+
+\url{https://linuxconfig.org}
+\end{document}
\ No newline at end of file
diff --git a/make_appimage.sh b/make_appimage.sh
index f7712ff..82cf5d8 100644
--- a/make_appimage.sh
+++ b/make_appimage.sh
@@ -1,19 +1,39 @@
#!/bin/sh
[ -f "linuxdeploy-x86_64.AppImage" ] || wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod 755 linuxdeploy-x86_64.AppImage
rm -rf CMakeCache.txt CMakeFiles
+mkdir build
+cd build
+rm -rf CMakeCache.txt CMakeFiles
+[ -d "SFML-2.5.1" ] || wget https://www.sfml-dev.org/files/SFML-2.5.1-linux-gcc-64-bit.tar.gz && tar -xvf SFML-2.5.1-linux-gcc-64-bit.tar.gz
+export SFML_ROOT=SFML-2.5.1
+cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release
+make -j 4
+../linuxdeploy-x86_64.AppImage --appdir AppDir
+make install DESTDIR=AppDir
+cp ../AppRun AppDir/
+mkdir -p AppDir/usr/share/metainfo/
+cp ../net.devcarpet.deerportal.appdata.xml AppDir/usr/share/metainfo/
+#sed -i '/Exec/d' AppDir/deerportal.desktop
+../linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage -i ../assets/img/deerportal.png -d ../net.devcarpet.deerportal.desktop
+
+exit 0
+[ -f "linuxdeploy-x86_64.AppImage" ] || wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
+chmod 755 linuxdeploy-x86_64.AppImage
+rm -rf CMakeCache.txt CMakeFiles
+
mkdir build
cd build
rm -rf CMakeCache.txt CMakeFiles
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release
make -j 4
../linuxdeploy-x86_64.AppImage --appdir AppDir
make install DESTDIR=AppDir
cp ../AppRun AppDir/
mkdir -p AppDir/usr/share/metainfo/
cp ../net.devcarpet.deerportal.appdata.xml AppDir/usr/share/metainfo/
sed -i '/Exec/d' AppDir/deerportal.desktop
../linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage -i ../assets/img/deerportal.png -d ../net.devcarpet.deerportal.desktop
diff --git a/net.devcarpet.deerportal.appdata.xml b/net.devcarpet.deerportal.appdata.xml
index cffff3f..b0d7357 100644
--- a/net.devcarpet.deerportal.appdata.xml
+++ b/net.devcarpet.deerportal.appdata.xml
@@ -1,41 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
-​ <id>net.devcarpet.deerportal</id>
-​ <metadata_license>CC-BY-SA-3.0 </metadata_license>
-​ <project_license>Zlib</project_license>
-​ <name>Deer Portal</name>
-​ <summary>A hybrid game which utilize board and card games mechanisms </summary>
-​
-​ <description>
-​ <p>
-​ A multiplayer (0-4) full of the diamonds board game driven by a Deer god and classical elements.
-​ </p>
-​ </description>
-​
-​ <launchable type="desktop-id">net.devcarpet.deerportal.desktop</launchable>
-​
-​ <screenshots>
-​ <screenshot type="default">
-​ <caption>Game start and gameplay</caption>
-​ <image>https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_771.png/@@images/image.png</image>
-​ </screenshot>
-​ <screenshot>
-​ <image>https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_772.png/@@images/image.png</image>
-​ </screenshot>
-​ </screenshots>
-​
-​ <url type="homepage">https://devcarpet.net/deerportal/</url>
-<!-- ​ <project_group>GNOME</project_group> -->
-​
-​ <provides>
-​ <binary>deerportal</binary>
-​ </provides>
-​
-​ <releases>
-​ <release version="0.8.1" date="2013-04-12">
-​ <description>
-​ <p>Introduces AppImage metainfo file.</p>
-​ </description>
-​ </release>
-​ </releases>
-​</component>
+ <id>net.devcarpet.deerportal.desktop</id>
+ <metadata_license>CC-BY-SA-3.0 </metadata_license>
+ <project_license>Zlib</project_license>
+ <name>Deer Portal</name>
+ <summary>A hybrid game which utilize board and card games mechanisms </summary>
+
+ <description>
+ <p>
+ A multiplayer (0-4) full of the diamonds board game driven by a Deer god and classical elements.
+ </p>
+ </description>
+
+<!-- Does not work with Ubuntu 16.04 -->
+<!-- <launchable type="desktop-id">net.devcarpet.deerportal.desktop</launchable> -->
+
+
+ <screenshots>
+ <screenshot type="default">
+ <caption>Game start and gameplay</caption>
+ <image>https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_771.png/@@images/image.png</image>
+ </screenshot>
+ <screenshot>
+ <image>https://bluszcz.net/projects/games/deerportal/deerportal-game-about-how-human-can-be-upgraded-to-the-deer_772.png/@@images/image.png</image>
+ </screenshot>
+ </screenshots>
+
+ <url type="homepage">https://devcarpet.net/deerportal/</url>
+
+ <provides>
+ <binary>deerportal</binary>
+ </provides>
+
+ <releases>
+ <release version="0.8.1" date="2013-04-12">
+ <description>
+ <p>Introduces AppImage metainfo file.</p>
+ </description>
+ </release>
+ </releases>
+</component>
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 41b4e59..f518000 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -1,104 +1,104 @@
base: core18
name: deerportal
-version: "0.8.1"
+version: "0.8.2"
summary: Deer Portal" snap
description: Board game where you need to transfer yourself into the Deer God
grade: stable
confinement: strict
apps:
deerportal:
command: desktop-launch DeerPortal
environment:
DP_DIR: "$SNAP"
plugs:
# - alsa
- audio-playback
- desktop
- desktop-legacy
# - gsettings
# - home
- opengl
- pulseaudio
# - unity7
- wayland
- x11
# - alsa
parts:
desktop-gtk3:
build-packages:
- libgtk-3-dev
make-parameters:
- FLAVOR=gtk3
plugin: make
source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
source-subdir: gtk
stage-packages:
- libxkbcommon0
- ttf-ubuntu-font-family
- dmz-cursor-theme
- light-themes
- adwaita-icon-theme
- gnome-themes-standard
- shared-mime-info
- libgtk-3-0
- libgdk-pixbuf2.0-0
- libglib2.0-bin
- libgtk-3-bin
- unity-gtk3-module
- libappindicator3-1
- locales-all
- xdg-user-dirs
- ibus-gtk3
- libibus-1.0-5
source-deerportal:
plugin: cmake
configflags:
- -DCMAKE_BUILD_TYPE=Release
- -DCMAKE_INSTALL_PREFIX=/usr
source: .
source-type: local
# source-depth: 1
build-packages:
- g++
- libsfml-dev
- libgl1-mesa-dri
- libopenal-dev
- libsndio-dev
- libasound2-dev
- libasound2-data
# stage-packages:
# - libc6
# - alsa
stage-packages:
- alsa
- libasound2
- libflac8
- libfreetype6
- libgl1
- libglvnd0
- libglx0
- libjpeg-turbo8
- libogg0
- libopenal1
- libpng16-16
- libsfml-audio2.4
- libsfml-graphics2.4
- libsfml-system2.4
- libsfml-window2.4
- libsndio6.1
- libvorbis0a
- libvorbisenc2
- libvorbisfile3
- libx11-6
- libxau6
- libxcb1
- libxdmcp6
- libxext6
- libxrandr2
- libxrender1
- libasound2-data
- libasound2-plugins
after: [desktop-gtk3]
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index a7a4f4f..b306db5 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -1,196 +1,196 @@
////////////////////////////////////////////////////////////
//
// 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.
//
////////////////////////////////////////////////////////////
// This file has been created using Maximilian Wagenbach (aka. Foaly) sources
// further modificated. Thank you Foaly.
#include "animatedsprite.h"
#include <cmath>
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)
{
// setScale(1.9,1.9);
setFrameTime(sf::seconds(0.5f));
setFrameTime(sf::seconds(0.5f));
}
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::fabs(rect.width));
float height = static_cast<float>(std::fabs(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);
+ target.draw(m_vertices, 4, sf::TriangleFan, states);
}
}
diff --git a/src/banner.cpp b/src/banner.cpp
index a7ae9b1..e630587 100644
--- a/src/banner.cpp
+++ b/src/banner.cpp
@@ -1,54 +1,54 @@
#include "banner.h"
Banner::Banner(sf::Font *gameFont):
active(false),
textStr(""),
timeDownCounter(0)
{
text.setFont(*gameFont);
text.setCharacterSize(100);
}
-void Banner::setText(std::string newText)
+void Banner::setText(const std::string& newText)
{
textStr = newText;
text.setString(textStr);
active = true;
timeDownCounter = 1.5;
// 204,76
// 840, 718
// In [1]: 840 - 204
// Out[1]: 636
// In [2]: 718 - 76
// Out[2]: 642
// In [3]:
sf::FloatRect rectTxt = text.getLocalBounds();
text.setPosition(((636/2)-(rectTxt.width/2))+204,((642/2)-(rectTxt.height/2))+20);
}
void Banner::update(sf::Time frameTime)
{
if (active){
if (timeDownCounter>0){
timeDownCounter -= frameTime.asSeconds();
}
if (timeDownCounter<=0){
active = false;
setText("");
}
}
}
void Banner::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(text, states);
}
diff --git a/src/banner.h b/src/banner.h
index 6d96ed5..012cbbc 100644
--- a/src/banner.h
+++ b/src/banner.h
@@ -1,21 +1,21 @@
#ifndef BANNER_H
#define BANNER_H
#include <string>
#include <SFML/Graphics.hpp>
class Banner: public sf::Drawable, public sf::Transformable
{
public:
explicit Banner(sf::Font *gameFont);
- void setText(std::string newText);
+ void setText(const std::string& newText);
bool active;
std::string textStr;
sf::Text text;
float timeDownCounter;
void update(sf::Time frameTime);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
};
#endif // BANNER_H
diff --git a/src/elem.cpp b/src/elem.cpp
index 6926210..fbcccfc 100644
--- a/src/elem.cpp
+++ b/src/elem.cpp
@@ -1,47 +1,47 @@
#include "elem.h"
Elem::Elem()
{
boardPosition = -1;
}
/*!
* \brief Character::getBoardPosition
* \return
*/
int Elem::getBoardPosition()
{
sf::Vector2f currentPos(getPosition());
sf::Vector2i currentCords(DP::getCords(currentPos));
int currentBoardPosition = DP::transCords(currentCords);
return currentBoardPosition;
}
/*!
* \brief Character::setBoardPosition
* \param boardPosition
*/
void Elem::setBoardPosition(int boardPosition)
{
sf::Vector2i neededCords(DP::transPosition(boardPosition));
-
- sf::Vector2f newPos(DP::getScreenPos(neededCords));
+ sf::Vector2f newPos(DP::getScreenPos(neededCords));
setPosition(newPos.x, newPos.y);
this->boardPosition = boardPosition;
// std::array<int,2> movements(getMovements(diceResult));
// std::cout << "board pos >> " << boardPosition << " cords >>" << neededCords.x << " " << neededCords.y
// << "newpos >> " << newPos.x << " " << newPos.y << " "
// << "movements >> " << movements[0] << " " << movements[1]
// << std::endl;
- sf::Vector2i newVecPos(getPosition());
+ sf::Vector2i newVecPos(getPosition());
// sf::FloatRect newSize(getGlobalBounds());
- float newX = newVecPos.x + (DP::TILE_SIZE/3);
+ // float newX = newVecPos.x + (DP::TILE_SIZE / 3);
+ float newX = newVecPos.x + (DP::TILE_SIZE/4);
// newX = newX - (newSize.width);
setPosition(newX, newPos.y);
move(202,76);
}
diff --git a/src/game.cpp b/src/game.cpp
index dc27720..550dfef 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1,1191 +1,1224 @@
#include "game.h"
#include "particle.h"
#include "calendar.h"
#include <algorithm>
namespace DP {
int initScreenX = 1360;
int initScreenY = 768;
int currentSeason = 1;
int month = 0;
/*!
* \brief The ResultTable struct contains data for the end of the game screen.
*/
struct ResultTable
{
int playerNumber;
int playerResult;
bool reachedPortal;
bool reachedPortalFirst;
ResultTable(int number,int result, bool portal, bool portalFirst) :
playerNumber(number), playerResult(result), reachedPortal(portal), reachedPortalFirst(portalFirst) {}
bool operator < (const ResultTable& otherResult) const
{
if ((playerResult!=otherResult.playerResult) || ((reachedPortal==false) && (otherResult.reachedPortal==false)))
return (playerResult > otherResult.playerResult);
else if (reachedPortalFirst==true){
return true;
} else
{
return false;
}
;
}
};
/*!
* \brief Game::setTxtEndGameAmount orders the results text for the end of the game.
*/
void Game::setTxtEndGameAmount(){
std::string elementNames[4] = {"Water","Earth", "Fire", "Air"};
int width=1360;
// int height = 768;
// int startHeight = 100;
int separator = 40;
std::array<ResultTable, 4> results = {
{
ResultTable(0,players[0].cash, players[0].reachedPortal,players[0].reachedPortalFirst),
ResultTable(1,players[1].cash, players[1].reachedPortal,players[1].reachedPortalFirst),
ResultTable(2,players[2].cash, players[2].reachedPortal,players[2].reachedPortalFirst),
ResultTable(3,players[3].cash, players[3].reachedPortal,players[3].reachedPortalFirst)
}
};
std::vector < ResultTable > resultsVector;
txtSurvivors.clear();
txtLoosers.clear();
for (int i=0;i<4;i++)
{
resultsVector.push_back(results[i]);
};
std::sort(resultsVector.begin(), resultsVector.end());
txtWinner.setFont(gameFont);
txtWinner.setCharacterSize(40);
for (int i=0;i<4;i++)
{
int playerNumber = resultsVector[i].playerNumber;
std::string elementName = elementNames[playerNumber];
sf::Text tmpText;
tmpText.setFont(gameFont);
tmpText.setCharacterSize(25);
tmpText.setString(elementName+ " " + std::to_string(players[playerNumber].cash));
sf::FloatRect rectTxt = tmpText.getLocalBounds();
if (players[playerNumber].reachedPortal==true)
{
int counter = txtSurvivors.size();
tmpText.setPosition((1360/2)-(rectTxt.width/2),200+(counter*separator));
txtSurvivors.push_back(tmpText);
} else
{
int counter = txtLoosers.size();
tmpText.setPosition((width/2)-(rectTxt.width/2),540+(counter*separator));
txtLoosers.push_back(tmpText);
}
}
if (txtSurvivors.size()>0)
{
txtWinner.setString("Winner: " + txtSurvivors[0].getString());
txtSurvivors.erase(txtSurvivors.begin()+0);
}
txtWinner.setCharacterSize(40);
sf::FloatRect rectTxt = txtWinner.getLocalBounds();
txtWinner.setPosition((1360/2)-(rectTxt.width/2),120);
}
void Game::initBoard()
{
time_t t = time(0);
struct tm * now = localtime( & t );
int month = now->tm_mon + 1;
int day = now->tm_mday;
paganHolidayString = getHoliday(month, day);
paganHolidayTxt.setString(paganHolidayString);
sfxClick.setBuffer(sfxClickBuffer);
sfxDone.setBuffer(sfxDoneBuffer);
spriteBackgroundDark.setTexture(textures.backgroundDark);
spriteBackgroundDark.setPosition(0,0);
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);
cardsDeck.setFonts(&gameFont);
spriteBigDiamond.setTexture(textures.textureBigDiamond);
spriteBigDiamond.setPosition(474,342);
spriteBigDiamond.setColor(sf::Color (255, 255, 255,196));
restartGame();
launchNextPlayer();
endGameTxt.setFont(gameFont);
endGameTxt.setString("End of the Game");
endGameTxt.setCharacterSize(30);
sf::FloatRect ss = endGameTxt.getLocalBounds();
endGameTxt.setPosition((1360/2)-(ss.width/2),60);
setTxtEndGameAmount();
bubble.setPosition(players[turn].characters[0].getPosition().x-30,
players[turn].characters[0].getPosition().y-45);
txtSurvivorsLabel.setString("Survivors");
txtSurvivorsLabel.setFont(gameFont);
txtSurvivorsLabel.setCharacterSize(30);
sf::FloatRect rectSurvivors = txtSurvivorsLabel.getLocalBounds();
txtSurvivorsLabel.setPosition((1360/2)-(rectSurvivors.width/2),200);
txtLoosersLabel.setString("Digested by The Elements");
txtLoosersLabel.setFont(gameFont);
txtLoosersLabel.setCharacterSize(30);
sf::FloatRect rectLoosers = txtLoosersLabel.getLocalBounds();
txtLoosersLabel.setPosition((1360/2)-(rectLoosers.width/2),500);
credits.setTxt(0);
}
/*!
* \brief Game::restartGame sets all the variables to the default value
*/
void Game::restartGame()
{
Player playerHud1(&textures, &gameFont,0);
Player playerHud2(&textures, &gameFont,1);
Player playerHud3(&textures, &gameFont,2);
Player playerHud4(&textures, &gameFont,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);
for (int i=0;i<4;i++)
{
players[i].restartPlayer();
players[i].reachedPortal = false;
boardDiamonds.reorder(i);
bubble.setPosition(players[i].characters[0].getPosition().x-30,
players[i].characters[0].getPosition().y-45);
players[i].done=false;
}
numberFinishedPlayers = 0;
turn = 0;
currentSeason = 1;
roundNumber = 1;
month = 0;
cardsDeck.reloadCards();
deerModeActive = false;
deerModeCounter = 16;
}
void Game::setCurrentNeighbours ()
{
currentNeighbours = players[turn].getNeighbours();
}
/*!
* \brief Game::loadAssets
*/
void Game::loadAssets()
{
if (!gameFont.loadFromFile(get_full_path(ASSETS_PATH"assets/fnt/metal-mania.regular.ttf")))
{
std::exit(1);
}
if (!menuFont.loadFromFile(get_full_path(ASSETS_PATH"assets/fnt/metal-macabre.regular.ttf")))
{
std::exit(1);
}
menuBackground.setTexture(textures.textureMenu);
spriteDeerGod.setTexture(textures.textureDeerGod);
if (!shaderBlur.loadFromFile(get_full_path(ASSETS_PATH"assets/shaders/blur.frag"), sf::Shader::Fragment))
std::exit(1);
if (!shaderPixel.loadFromFile(get_full_path(ASSETS_PATH"assets/shaders/pixelate.frag"), sf::Shader::Fragment))
std::exit(1);
if (!shaderDark.loadFromFile(get_full_path(ASSETS_PATH"assets/shaders/dark.frag"), sf::Shader::Fragment))
std::exit(1);
if (!textureBackgroundArt.loadFromFile(get_full_path(ASSETS_PATH"assets/img/background_land.png")))
std::exit(1);
if (!musicGame.openFromFile(get_full_path(ASSETS_PATH"assets/audio/game.ogg")))
std::exit(1);
// if (!musicBackground.openFromFile(ASSETS_PATH"assets/audio/wind2.ogg"))
// std::exit(1);
if (!musicMenu.openFromFile(get_full_path(ASSETS_PATH"assets/audio/menu.ogg")))
std::exit(1);
if (!sfxClickBuffer.loadFromFile(get_full_path(ASSETS_PATH"assets/audio/click.ogg")))
std::exit(1);
if (!sfxDoneBuffer.loadFromFile(get_full_path(ASSETS_PATH"assets/audio/done.ogg")))
std::exit(1);
// if (!textureBackground.loadFromFile(ASSETS_PATH"assets/img/background.png"))
// std::exit(1);
spriteBackgroundArt.setTexture(textureBackgroundArt);
menuTxt.setFont(gameFont);
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.setFillColor(sf::Color(255, 255, 255, 85));
cardsDeck.setFonts(&gameFont);
paganHolidayTxt.setFont(gameFont);
paganHolidayTxt.setCharacterSize(20);
paganHolidayTxt.setPosition(20,20);
for (int i=0;i<4;i++)
{
playersSprites[i].setTexture(textureBackgroundArt);
playersSprites[i].setTextureRect(sf::IntRect(playersSpritesCords[i][0],
playersSpritesCords[i][1], 280, 280));
playersSprites[i].setPosition(playersSpritesCords[i][0], playersSpritesCords[i][1]);
}
}
void Game::showMenu()
{
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();
currentState = state_setup_players;
// currentState = state_lets_begin;
}
void Game::endGame()
{
musicGame.stop();
currentState = state_end_game;
downTimeCounter = 0;
numberFinishedPlayers = 4;
setTxtEndGameAmount();
// musicBackground.stop();
}
void Game::throwDiceMove() {
// Throw a dice action
diceResultPlayer = roundDice.throwDiceSix();
players[turn].characters[0].diceResult=diceResultPlayer;
currentState = state_game;
bubble.state = BubbleState::MOVE;
nextRotateElem.reset();
prevRotateElem.reset();
}
/*!
* \brief Game::playerMakeMove move the player into the position on the map
* \param mousePos
*/
void Game::playerMakeMove(int mousePos) {
players[turn].setFigurePos(mousePos);
commandManager.processField(mousePos);
const int *possibleExit = std::find(std::begin(DP::endPlayers),
std::end(DP::endPlayers), mousePos);
if (possibleExit != DP::endPlayers+4) {
players[turn].done=true;
players[turn].reachedPortal=true;
commandManager.removeAllItems(turn);
if (numberFinishedPlayers == 0)
{
players[turn].reachedPortalFirst=true;
int turnover = (rand() % 2)+5;
players[turn].cash += turnover;
players[turn].updatePlayer();
startDeerMode();
}
sfx.soundPortal.play();
numberFinishedPlayers += 1;
if (numberFinishedPlayers > 3)
{
endGame();
return;
}
}
nextPlayer();
return;
}
int Game::mostDiamonds() const
{
std::array<int,4> results = {{players[0].cash,players[1].cash,players[2].cash,players[3].cash}};
auto minmax = std::minmax_element(std::begin(results), std::end(results));
int maxResult = *(minmax.second);
int result = 0;
int pos = -1;
for (int i=0; i<4;i++)
{
if (players[i].cash == maxResult)
{
result += 1;
pos = i;
}
};
if (result==1)
{
return pos;
}
return -1;
}
/*!
* \brief Game::handleLeftClick
* \param pos
* \param posFull
* \param mousePos
*/
void Game::handleLeftClick(sf::Vector2f pos,sf::Vector2f posFull, int mousePos) {
if (currentState==state_game)
{
if (players[turn].human)
{
std::array<int,2> movements = players[turn].getMovements(diceResultPlayer);
if ((mousePos==movements[0]) || (mousePos==movements[1]))
{
playerMakeMove(mousePos);
}
}
}
if (currentState==state_setup_players)
{
for (int i=0;i<4;i++)
{
sf::IntRect spriteHumanRect(players[i].spriteAI.getGlobalBounds());
if (spriteHumanRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
players[i].swapHuman();
}
}
sf::IntRect startGameRect(580,640,180,80);
if (startGameRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
bigDiamondActive = true;
banner.setText("start game");
currentState=state_roll_dice;
launchNextPlayer();
return;
}
}
else if (currentState==state_roll_dice)
{
if (players[turn].human){
sf::IntRect diceRect(roundDice.spriteDice.getGlobalBounds());
if (diceRect.intersects(sf::IntRect(posFull.x, posFull.y, 1, 1)))
{
throwDiceMove();
}
}
}
if (currentState==state_menu)
{
downTimeCounter = 0;
hideMenu();
showGameBoard();
return;
}
if (currentState==state_gui_end_round)
{
std::string resultCommand = guiRoundDice.getElem(pos);
command(resultCommand);
}
if (currentState==state_lets_begin)
{
if (downTimeCounter>1)
{
currentState = state_roll_dice;
restartGame();
launchNextPlayer();
return;
}
}
if (currentState==state_end_game)
{
if (downTimeCounter>2)
{
currentState = state_menu;
musicMenu.play();
restartGame();
return ;
// restartGame();
}
}
}
Game::Game(bool newTestMode):
screenSize(DP::initScreenX,DP::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(DP::TILE_SIZE),
character(&textures, 3),
gameTitle("deerportal"),
roundDice(players),
roundNumber(1),
guiRoundDice(&textures),
boardDiamonds(&textures),
- window(sf::VideoMode(DP::initScreenX, DP::initScreenY), "Deerportal - game about how human can be upgraded to the Deer"),
+ window(sf::VideoMode(DP::initScreenX, DP::initScreenY), "Deerportal - game about how human can be upgraded to the Deer", sf::Style::Titlebar| sf::Style::Close),
turn(0),
oscilator(-1),
oscilatorInc(true),
particleSystem( 430, 230),
commandManager(*this),
cardsDeck(&textures, &menuFont,&commandManager),
banner(&gameFont),
bigDiamondActive(false),
credits(&gameFont),
cpuTimeThinkingInterval(1.0f),
deerModeCounter(4),
deerModeActive(false),
gameVersion(),
- v1(0.0f)
+ v1(0.0f),
+ textFPS()
{
+ sf::Image icon;
+ icon.loadFromFile(get_full_path(ASSETS_PATH"assets/img/deerportal.png"));
+ window.setIcon(256, 256, icon.getPixelsPtr());
+
testMode = newTestMode;
// TODO: perhaps get rid of the particles at all...
particleSystem.setDissolve( true );
particleSystem.setDissolutionRate( 10 );
particleSystem.setShape( DP::CIRCLE );
particleSystem.fuel( 1000 );
playersSpritesCords[0][0] = 202;
playersSpritesCords[0][1] = 76;
playersSpritesCords[1][0] = 562;
playersSpritesCords[1][1] = 76;
playersSpritesCords[3][0] = 202;
playersSpritesCords[3][1] = 436;
playersSpritesCords[2][0] = 562;
playersSpritesCords[2][1] = 436;
textLoading.setString("loading...");
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setFillColor(sf::Color::White);
textLoading.setCharacterSize(10);
renderTexture.create(1360,768);
renderTexture.clear(sf::Color::White);
renderTexture.draw(textLoading);
renderTexture.display();
renderSprite.setTexture(renderTexture.getTexture());
numberFinishedPlayers = 0;
sf::Clock frameClock;
+ sf::Clock clock;
guiRoundDice.active = true;
showPlayerBoardElems = false;
- window.setVerticalSyncEnabled(true);
+ //window.setVerticalSyncEnabled(true);
std::srand (time(NULL));
window.clear(sf::Color(55,55,55));
renderTexture.draw(textLoading);
// window.display();
+ textFPS.setFont(gameFont);
+ textFPS.setPosition(0,60);
+ textFPS.setCharacterSize(20);
loadAssets();
textLoading.setFont(menuFont);
textLoading.setPosition(200,200);
textLoading.setFillColor(sf::Color::White);
textLoading.setCharacterSize(10);
renderTexture.clear(sf::Color::Black);
renderTexture.draw(textLoading);
window.display();
gameVersion.setString("version: " + std::string(DEERPORTAL_VERSION)+"-"+std::string(BASE_PATH));
gameVersion.setFont(gameFont);
gameVersion.setPosition(10,10);
gameVersion.setFillColor(sf::Color::White);
gameVersion.setCharacterSize(15);
initBoard();
renderTexture.clear(sf::Color::Black);
renderTexture.draw(textLoading);
renderTexture.display();
showMenu();
// run the main loop
if (testMode){
std::exit(0);
}
-
+ float lastTime = 0;
+ float fpsTime = 0;
while (window.isOpen())
{
sf::Time frameTime = frameClock.restart();
// handle events
sf::Event event;
float xpos = 320.0f;
float ypos = 240.0f;
float xgrv = 0.0f;
float ygrv = 0.0f;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close(); break;
case sf::Event::KeyPressed:
if(event.key.code == sf::Keyboard::Escape )
window.close();
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Space ) )
particleSystem.fuel( 200/* * window.getFrameTime() */);
if( sf::Keyboard::isKeyPressed( sf::Keyboard::A ) )
particleSystem.setPosition( --xpos, ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
particleSystem.setPosition( ++xpos, ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::W ) )
particleSystem.setPosition( xpos, --ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::S ) )
particleSystem.setPosition( xpos, ++ypos );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
particleSystem.setGravity( --xgrv * 0.1f, ygrv * 0.1f);
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
particleSystem.setGravity( ++xgrv * 0.1f, ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
particleSystem.setGravity( xgrv * 0.1f, --ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
particleSystem.setGravity( xgrv * 0.1f, ++ygrv * 0.1f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::G ) )
particleSystem.setGravity( 0.0f, 0.0f );
if( sf::Keyboard::isKeyPressed( sf::Keyboard::P ) )
particleSystem.setPosition( 320.0f, 240.0f );
break;
default:
break;
}
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 / DP::TILE_SIZE;
int mousePosY = (int)localPosition.y / DP::TILE_SIZE;
int mousePos = DP::transCords(sf::Vector2i(mousePosX, mousePosY));
if(event.type == sf::Event::Closed)
window.close();
// Showing mouse hover
if (currentState==state_game)
{
if ((localPosition.x>DP::TILE_SIZE*DP::BOARD_SIZE) || (localPosition.x<0) || (localPosition.y>DP::TILE_SIZE*DP::BOARD_SIZE) || (localPosition.y<0))
{
showPlayerBoardElems = false;
} else {
showPlayerBoardElems = true;
}
}
if ((localPosition.x>=0) && (localPosition.y>=0) && (localPosition.x<=DP::BOARD_SIZE*DP::TILE_SIZE) && (localPosition.y<=DP::BOARD_SIZE*DP::TILE_SIZE))
{
selector.setPosition((int) (localPosition.x / DP::TILE_SIZE)*DP::TILE_SIZE, ((int) localPosition.y / DP::TILE_SIZE)*DP::TILE_SIZE);
}
/*!
* Handling mouse click
*/
if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
handleLeftClick(localPosition,
localPositionFull, mousePos);
}
}
+
+
+ fpsTime = fpsTime + frameTime.asSeconds();
+
+ float currentTime = clock.restart().asSeconds();
+ float fps = 1.f / (currentTime);
+ lastTime = currentTime;
+ // float fps = floor(1.f / (frameTime.asSeconds() - lastTime) + 0.5f);
+ if (fpsTime>0.25f)
+ {
+ textFPS.setString("FPS: " + std::to_string(fps));
+ // lastTime = frameTime.asSeconds();
+ fpsTime=0.0f;
+ }
+
+
+
update(frameTime);
render(frameTime.asSeconds());
}
}
void Game::update(sf::Time frameTime) {
banner.update(frameTime);
credits.update(frameTime);
runningCounter += frameTime.asSeconds();
cpuTimeThinking -= frameTime.asSeconds();
if (oscilatorInc)
{
oscilator += frameTime.asSeconds();
} else {
oscilator -= frameTime.asSeconds();
}
if (oscilator<-1)
oscilatorInc = true;
if (oscilator>1)
oscilatorInc = false;
float modifier = sin(oscilator/2.5)*30.0f;
spriteBigDiamond.setPosition(474,342+modifier);
if (currentState==state_roll_dice)
{
if ((cpuTimeThinking<0) && (players[turn].human==false))
{
cpuTimeThinking = cpuTimeThinkingInterval;
throwDiceMove();
}
}
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].getMovements(diceResultPlayer);
if ((cpuTimeThinking<0) && (players[turn].human==false))
{
std::vector<int> listRandomPos;
if (currentMovements[0]>-1) {
listRandomPos.push_back(currentMovements[0]);
}
if (currentMovements[1]>-1) {
listRandomPos.push_back(currentMovements[1]);
}
unsigned int sizeRndPos = listRandomPos.size();
if (sizeRndPos==0) {
} else if (sizeRndPos==1) {
playerMakeMove(listRandomPos[0]);
} else if (sizeRndPos==2) {
if (deerModeActive)
{
playerMakeMove(listRandomPos[1]);
} else
{
if (players[turn].reachPortalMode == true)
{
playerMakeMove(listRandomPos[1]);
}
else
{
if (boardDiamonds.ifFieldIsEmpty(listRandomPos[1])==false)
{
playerMakeMove(listRandomPos[1]);
return;
}
if (boardDiamonds.ifFieldIsEmpty(listRandomPos[0])==false)
{
playerMakeMove(listRandomPos[0]);
return;
}
if ((boardDiamonds.ifFieldIsEmpty(listRandomPos[0])==false) && (boardDiamonds.ifFieldIsEmpty(listRandomPos[1])==false))
{
playerMakeMove(listRandomPos[1]);
return;
}
int randPos = rand() % 2;
playerMakeMove(listRandomPos[randPos]);
};
}
}
}
if (currentMovements[0]>-1)
{
prevRotateElem.spriteRotate.setPosition(players[turn].characters[0].leftChar.getPosition());
prevRotateElem.spriteRotate.move(10,20);
// Modificator to fit on the bigger view
prevRotateElem.spriteRotate.move(-202,-76);
prevRotateElem.update(frameTime);
prevRotateElem.setColor();
}
if (currentMovements[1]>-1)
{
nextRotateElem.spriteRotate.setPosition(players[turn].characters[0].rightChar.getPosition());
nextRotateElem.spriteRotate.move(10,20);
// Modificator to fit on the bigger view
nextRotateElem.spriteRotate.move(-202,-76);
nextRotateElem.update(frameTime);
nextRotateElem.setColor();
}
}
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>5)
{
currentState = state_roll_dice;
bubble.state = BubbleState::DICE;
}
}
if (currentState==state_end_game)
{
downTimeCounter += frameTime.asSeconds();
}
bubble.update(frameTime);
}
/*!
* \brief Game::nextRound is happening each every 4 months
*/
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();
launchNextPlayer();
}
/*!
* \brief Game::nextPlayer calculates which player should play
*/
void Game::nextPlayer(){
// End of game - we don't calculate more players
if (currentState==state_end_game)
{
return;
}
// End of game - we don't calculate more players
if (numberFinishedPlayers==4)
{
endGame();
return ;
}
// Update old player
players[turn].updatePlayer();
if (turn>2)
{
nextRound();
return;
}
turn++;
launchNextPlayer();
}
void Game::launchNextPlayer(){
if (deerModeActive)
{
deerModeCounter -= 1;
}
if (deerModeCounter<0)
{
endGame();
return ;
}
// Just control
if (players[turn].done==true)
{
nextPlayer();
return;
}
// Frozen player
if (players[turn].frozenLeft>0)
{
players[turn].frozenLeft -= 1;
nextPlayer();
return;
}
// Here we process new player
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);
if (deerModeActive==false)
{
groupHud.setSeason(currentSeason);
groupHud.setMonthName(month%4);
} else
{
groupHud.setDeerModeActive();
int number = (deerModeCounter/4);
if (deerModeCounter<16)
number += 1;
if (number<0)
{
endGame();
return;
}
groupHud.setDeerModeCounter(number);
}
currentState = state_roll_dice;
bubble.state = BubbleState::DICE;
roundDice.setColor(turn);
bubble.setPosition(players[turn].characters[0].getPosition().x-30,
players[turn].characters[0].getPosition().y-45);
cpuTimeThinking = cpuTimeThinkingInterval;
if (mostDiamonds()==turn)
{
players[turn].reachPortalMode = true;
} else {
players[turn].reachPortalMode = false;
}
}
void Game::drawPlayersGui(){
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i]);
}
}
void Game::drawSquares() {
if (showPlayerBoardElems)
{
renderTexture.draw(selector);
}
}
void Game::drawBaseGame()
{
renderTexture.setView(viewTiles);
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i].elems);
}
drawSquares();
renderTexture.setView(viewGui);
renderTexture.setView(viewTiles);
renderTexture.setView(viewTiles); // Yeah Katia's inspiration
float v;
v = sin(runningCounter*0.01f);
shaderBlur.setUniform("blur_radius", v );
// renderTexture.draw(gameBackground);
renderTexture.setView(viewFull);
// renderTexture.draw(spriteBackgroundArt, &shaderDark);
// spriteBackgroundArt.setColor(sf::Color(255, 255, 255, 208));
shaderBlur.setUniform("blur_radius", 0.01f);
// shaderBlur.setParameter("blur_radius", sin(runningCounter*0.01) );
// shaderBlur.setParameter("blur_radius", sin(runningCounter*0.01) );
v = sin(runningCounter*0.005f);
shaderPixel.setUniform("pixel_threshold", v);
renderTexture.draw(spriteBackgroundArt);
spriteBackgroundArt.setColor(sf::Color(255, 255, 255));
v = sin(runningCounter*0.05f)/2;
shaderBlur.setUniform("blur_radius", v);
renderTexture.draw(cardsDeck);
if (currentState==state_roll_dice)
{
spriteBackgroundArt.setColor(sf::Color(255, 255, 255));
v = sin(runningCounter*0.5f)/4;
shaderBlur.setUniform("blur_radius", v);
renderTexture.draw(roundDice.spriteDice);
}
else
renderTexture.draw(roundDice.spriteDice);
renderTexture.setView(viewTiles);
drawSquares();
}
void Game::drawCharacters(){
if (currentState==state_game)
{
std::array<int,2> currentMovements = players[turn].characters[0].getMovements(diceResultPlayer);
if (currentMovements[1]>-1)
{
if (nextRotateElem.active)
renderTexture.draw(nextRotateElem);
}
if (currentMovements[0]>-1)
{
if (prevRotateElem.active)
renderTexture.draw(prevRotateElem);
}
}
renderTexture.setView(viewFull);
shaderBlur.setUniform("blur_radius", 0.005f);
for (int i=0;i<4;i++)
{
for (auto&& j: players[i].characters)
{
if (currentState==state_game)
j.drawMovements = true;
else
j.drawMovements = false;
renderTexture.draw(j);
// renderTexture.draw(j, &shaderBlur);
}
}
}
/*!
* \brief Game::render main function responsible for drawing all elements
* \param deltaTime
*/
void Game::render(float deltaTime)
{
window.clear();
renderTexture.clear();
if ((currentState==state_game) || (currentState==state_roll_dice))
{
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
renderTexture.setView(viewTiles);
drawBaseGame();
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
renderTexture.setView(viewTiles);
drawCharacters();
renderTexture.draw(boardDiamonds);
renderTexture.draw(bubble);
renderTexture.setView(viewFull);
drawPlayersGui();
renderTexture.setView(viewFull);
} else if (currentState==state_setup_players) {
renderTexture.setView(viewFull);
renderTexture.draw(spriteDeerGod);
for (int i=0;i<4;i++)
{
renderTexture.draw(players[i].spriteAI);
}
} else if (currentState==state_gui_elem) {
renderTexture.setView(viewFull);
shaderBlur.setUniform("blur_radius", 2.0f);
renderTexture.draw(spriteBackgroundDark, &shaderBlur);
drawBaseGame();
drawCharacters();
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
} else if (currentState==state_menu) {
// shaderBlur.setParameter("blur_radius", 15);
renderTexture.draw(menuBackground);
// // renderTexture.draw(menuTxt, &shaderBlur);
// renderTexture.draw(menuTxt);
renderTexture.draw(paganHolidayTxt);
+
+#ifndef NDEBUG
+ renderTexture.draw(textFPS);
renderTexture.draw(gameVersion);
+#endif
renderTexture.draw(credits);
} else if (currentState==state_lets_begin) {
renderTexture.setView(viewFull);
shaderBlur.setUniform("blur_radius", 4.0f);
renderTexture.draw(spriteBackgroundDark, &shaderBlur);
renderTexture.setView(viewTiles);
drawBaseGame();
drawCharacters();
renderTexture.draw(boardDiamonds, &shaderBlur);
renderTexture.setView(viewFull);
drawPlayersGui();
renderTexture.draw(spriteLestBegin,&shaderBlur);
} else if (currentState==state_gui_end_round){
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
drawBaseGame();
shaderBlur.setUniform("blur_radius", 0.05f);
renderTexture.draw(guiRoundDice, &shaderBlur);
renderTexture.setView(viewFull);
renderTexture.draw(groupHud);
}
else if (currentState==state_end_game){
renderTexture.setView(viewFull);
renderTexture.draw(spriteBackgroundDark);
renderTexture.draw(spriteLestBegin,&shaderBlur);
renderTexture.draw(endGameTxt);
// for (int i=0;i<4;i++){
// if (players[i].reachedPortal)
// renderTexture.draw(endGameTxtAmount[i]);
// }
renderTexture.draw(txtWinner);
renderTexture.draw(txtSurvivorsLabel);
for (unsigned int i=0; i<txtSurvivors.size();i++) {
renderTexture.draw(txtSurvivors[i]);
}
renderTexture.draw(txtLoosersLabel);
for (unsigned int i=0; i<txtLoosers.size();i++) {
renderTexture.draw(txtLoosers[i]);
}
}
if (bigDiamondActive)
renderTexture.draw(spriteBigDiamond);
if (banner.active)
renderTexture.draw(banner);
+
renderTexture.display();
renderSprite.setTexture(renderTexture.getTexture());
v1 = sin(deltaTime)*0.015f;
shaderBlur.setUniform("blur_radius", v1);
shaderBlur.setUniform("blur_radius", 0.0003f);
+
window.draw(renderSprite, &shaderBlur);
// particleSystem.remove();
// particleSystem.update();
// particleSystem.render();
// window.draw( particleSystem.getSprite() );
window.display();
}
void Game::command(std::string command){
if (command.compare("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();
}
/*!
* \brief Game::startDeerMode launches last episode of the game
*/
void Game::startDeerMode() {
deerModeActive = true;
deerModeCounter = 16;
banner.setText("deer mode");
bigDiamondActive = false;
sfx.soundDeerMode.play();
}
}
diff --git a/src/game.h b/src/game.h
index 603155b..c6cf892 100644
--- a/src/game.h
+++ b/src/game.h
@@ -1,222 +1,224 @@
#ifndef GAME_H
#define GAME_H
#include <stdlib.h>
#include <iostream>
#include <ctime>
#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 "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"
#include "calendar.h"
#include "particle.h"
#include "bubble.h"
//class Command;
#include "banner.h"
#include "credits.h"
namespace DP {
extern int initScreenX;
extern int initScreenY;
/*!
* \brief Game is a main class of the Deer Portal - contains most logic but also rendering.
*/
class Game
{
public:
sf::Vector2i screenSize;
sf::View viewFull;
sf::View viewGui;
sf::View viewTiles;
void setTxtEndGameAmount();
private:
Selector selector;
Character character;
std::string gameTitle;
std::string paganHolidayString;
RoundDice roundDice;
int roundNumber;
GuiRoundDice guiRoundDice;
float v1;
public:
Game(bool newTestMode);
BoardDiamondSeq boardDiamonds;
sf::RenderWindow window;
sf::RenderTexture renderTexture;
sf::Sprite renderSprite;
Player players[4];
SoundFX sfx;
int turn;
private:
void initBoard();
void restartGame();
void loadAssets();
void drawPlayersGui();
void drawSquares();
void drawMenu();
float runningCounter;
float oscilator;
bool oscilatorInc;
sf::Sprite playersSprites[4] ;
int playersSpritesCords[4][2];
enum states {
state_init,
state_menu,
state_setup_players,
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::Sprite spriteDeerGod;
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;
sf::Text endGameTxt;
sf::Text endGameTxtAmount[4];
sf::Text paganHolidayTxt;
sf::Text gameVersion;
sf::Shader shaderBlur;
sf::Shader shaderPixel;
sf::Shader shaderDark;
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(float deltaTime);
ParticleSystem particleSystem;
void setCurrentNeighbours ();
void nextPlayer();
void launchNextPlayer();
void nextRound();
sf::Sprite menuBackground;
sf::Sprite seasons[4];
sf::Music musicGame;
sf::Music musicMenu;
sf::SoundBuffer sfxClickBuffer;
sf::Sound sfxClick;
sf::SoundBuffer sfxDoneBuffer;
sf::Sound sfxDone;
void showMenu();
void hideMenu();
void showGameBoard();
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 posFull, int mousePos);
std::set<int> busyTiles;
int diceResultPlayer;
int numberFinishedPlayers;
RotateElem nextRotateElem;
RotateElem prevRotateElem;
void endGame();
float downTimeCounter;
Command commandManager;
sf::Text textLoading;
+ sf::Text textFPS;
+
public:
CardsDeck cardsDeck;
void startDeerMode();
sf::Text txtWinner;
sf::Text txtSurvivorsLabel;
sf::Text txtLoosersLabel;
std::vector<sf::Text> txtSurvivors;
std::vector<sf::Text> txtLoosers;
void throwDiceMove();
void playerMakeMove(int mousePos);
float cpuTimeThinking;
Banner banner;
sf::Sprite spriteBigDiamond;
bool bigDiamondActive;
int mostDiamonds() const;
Credits credits;
float cpuTimeThinkingInterval;
private:
Bubble bubble;
int deerModeCounter;
bool deerModeActive;
public:
bool testMode;
};
}
#endif // GAME_H
diff --git a/src/guiwindow.cpp b/src/guiwindow.cpp
index 0dba6f4..0e9fc8a 100644
--- a/src/guiwindow.cpp
+++ b/src/guiwindow.cpp
@@ -1,82 +1,82 @@
#include "guiwindow.h"
-void GuiWindow::setTitle(std::string newTitle) {
+void GuiWindow::setTitle(const 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));
if (!guiElemFont.loadFromFile(get_full_path(ASSETS_PATH"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.setFillColor(sf::Color(255, 255, 255, 200));
guiTitleTxt.setOutlineColor(sf::Color(255, 255, 255, 200));
guiTitleTxt.move(2,0);
guiTitleTxt.setString(title);
setPosition(150, 100);
}
GuiWindow::GuiWindow(){
if (!guiElemFont.loadFromFile(get_full_path(ASSETS_PATH"assets/fnt/metal-macabre.regular.ttf")))
{
std::exit(1);
};
setPosition(150, 100);
}
//void GuiWindow::setTextureHolder(TextureHolder *textures)
//{
//// spriteClose.setTexture(textures->textureGui);
//}
void GuiWindow::init(){
}
void GuiWindow::draw(sf::RenderTarget& target, sf::RenderStates states) const{
sf::RenderStates states2 = states;
states2.transform *= getTransform();
Hover::draw(target, states);
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/src/guiwindow.h b/src/guiwindow.h
index 9420054..f260f5b 100644
--- a/src/guiwindow.h
+++ b/src/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:
explicit GuiWindow(TextureHolder *textures);
GuiWindow();
// 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);
+ void setTitle(const std::string& newTitle);
sf::Sprite spriteClose;
private:
};
#endif // GUIWINDOW_H
diff --git a/src/utils.cpp b/src/utils.cpp
index 53b59bd..79b84d0 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,8 +1,8 @@
#include "utils.h"
namespace DP {
- std::string get_assets_path(std::string path) {
+ std::string get_assets_path(const std::string& path) {
return "hello";
};
-}
\ No newline at end of file
+}
diff --git a/version.txt b/version.txt
index 6f4eebd..100435b 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-0.8.1
+0.8.2

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:53 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72577
Default Alt Text
(66 KB)

Event Timeline