diff --git a/Thesis/Thesis.tex b/Thesis/Thesis.tex index e32694b..d83e648 100644 --- a/Thesis/Thesis.tex +++ b/Thesis/Thesis.tex @@ -1629,18 +1629,90 @@ To simplify finding matches first game objects tiles is transformed into vector \label{fig:findingMatches} \end{figure} -\subsubsection{Processing matches} +\newpage +\subsection{Processing matches} \paragraph{Removing blocks} After finding matches, blocks where matches appear are set to be replaced by replacing their tile ids with -1 \paragraph{Replacing blocks} After setting tiles to be replaced, algorithm goes through blocks with ids equal to -1, checks if there are any blocks above, if yes it replaces the block from above with block from below, if there is no block above, it generates one randomly -\begin{figure}[htp] +\begin{figure}[H] \centering \includegraphics{images/processLogicMatches.pdf} \caption{Logic for processing matches} \end{figure} +\subsection{Game objects} +Game object class holds informations about tiles, its position, textures and statuses + +\paragraph{Tile draw} +Based on a status of tile it can be drawn in 4 ways: +\begin{enumerate} +\item No status at all, it is drawn without any color overlayed on it +\item Highlighted, it is drawn with red overlay +\item Selected, it is drawn with green overlay +\item ToSwap, it is drawn with orange overlay +\end{enumerate} + +\begin{lstlisting}[style=C++Style] + +void GameObject::Draw(SpriteRenderer &renderer) +{ + if(ToSwap) { + glm::vec3 color = hexToVec3("#f97316"); + renderer.DrawSprite(this->Sprite, this->Position, this->Size, this->Rotation, color); + return; + } + if(!Highlighted) { + glm::vec3 empty(1.0f, 1.0f, 1.0f); + renderer.DrawSprite(this->Sprite, this->Position, this->Size, this->Rotation, empty); + return; + renderer.DrawSprite(this->Sprite, this->Position, this->Size, this->Rotation, this->Color); + return; + } + if(!Selected) { + glm::vec3 red(1.0f, 0.0f, 0.0f); + renderer.DrawSprite(this->Sprite, this->Position, this->Size, this->Rotation, red); + return; + } + glm::vec3 green(0.0f, 1.0f, 0.0f); + renderer.DrawSprite(this->Sprite, this->Position, this->Size, this->Rotation, green); +} +\end{lstlisting} + +Engine uses two helpful methods to easily translate color hex to glm::vec3 color + +\begin{lstlisting}[style=C++Style] +glm::vec3 hexToVec3(const std::string& hex) { + if (hex.size() != 6 && hex.size() != 7) { + throw std::invalid_argument("Invalid hex string length."); + } + size_t offset = hex[0] == '#' ? 1 : 0; + + int r = std::stoi(hex.substr(offset, 2), nullptr, 16); + int g = std::stoi(hex.substr(offset + 2, 2), nullptr, 16); + int b = std::stoi(hex.substr(offset + 4, 2), nullptr, 16); + + return glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f); +} + +glm::vec3 vectorToVec3(const std::vector& vec) { + if (vec.size() != 3) { + throw std::invalid_argument("Vector must have exactly 3 elements."); + } + + return glm::vec3(vec[0] / 255.0f, vec[1] / 255.0f, vec[2] / 255.0f); +} +\end{lstlisting} + + +\begin{figure}[htp] +\centering +\includegraphics[scale=0.75]{images/statesGameObject.pdf} +\caption{Game object states} +\end{figure} + + \subsection{Dependency Management} There are several libraries: OpenGL, GLFW, stb\_image and freetype being integrated into engine, they are simply included at the top of any files that need them. diff --git a/Thesis/images/highlighted.drawio.png b/Thesis/images/highlighted.drawio.png new file mode 100644 index 0000000..5e39dfd Binary files /dev/null and b/Thesis/images/highlighted.drawio.png differ diff --git a/Thesis/images/matchseProcessLogic.drawio.pdf b/Thesis/images/matchseProcessLogic.drawio.pdf new file mode 100644 index 0000000..28228f0 Binary files /dev/null and b/Thesis/images/matchseProcessLogic.drawio.pdf differ diff --git a/Thesis/images/noParameter.drawio.png b/Thesis/images/noParameter.drawio.png new file mode 100644 index 0000000..12303e6 Binary files /dev/null and b/Thesis/images/noParameter.drawio.png differ diff --git a/Thesis/images/selected.drawio.png b/Thesis/images/selected.drawio.png new file mode 100644 index 0000000..5e6769f Binary files /dev/null and b/Thesis/images/selected.drawio.png differ diff --git a/Thesis/images/statesGameObject.pdf b/Thesis/images/statesGameObject.pdf new file mode 100644 index 0000000..ecc11bc Binary files /dev/null and b/Thesis/images/statesGameObject.pdf differ diff --git a/Thesis/images/toSwap.drawio.png b/Thesis/images/toSwap.drawio.png new file mode 100644 index 0000000..895a713 Binary files /dev/null and b/Thesis/images/toSwap.drawio.png differ