feat: described game objects

This commit is contained in:
Krzysztof Rudnicki 2023-09-04 02:46:48 +02:00
parent 917ae7e86d
commit 6ab187dea3
7 changed files with 74 additions and 2 deletions

View File

@ -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<int>& 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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 KiB