feat: started game level class

This commit is contained in:
Krzysztof Rudnicki 2023-08-31 19:36:05 +02:00
parent 39c9bedb1a
commit 9c3f286ff8
2 changed files with 81 additions and 0 deletions

View File

@ -1411,7 +1411,78 @@ void Game::handleActiveGame() {
\end{figure}
\subsection{Rendering}
As mentioned in main loop, the game runs a render method every frame.
\begin{figure}[H]
\centering
\begin{tikzpicture}[node distance=2cm]
\useasboundingbox (-5,0) rectangle (5, -9); % Set a custom bounding box
\node (start) [startstop] {Render};
\node (dec1) [decision, below of=start] {State};
\draw [arrow] (start) -- (dec1);
\node (pro1) [process, below of=dec1, xshift=2cm] {Render win view};
\draw [arrow] (dec1) -- node[anchor=west] {Game won} (pro1);
\node (pro2) [process, below of=dec1, xshift=-2cm] {Render menu view};
\draw [arrow] (dec1) -- node[anchor=east] {Menu} (pro2);
\node (stop) [startstop, below of=dec1, yshift=-4cm] {Render main view};
\draw [arrow] (dec1) -- node[anchor=east] {Active} (stop);
\draw [arrow] (pro1) -- (stop);
\draw [arrow] (pro2) -- (stop);
\end{tikzpicture}
\caption{Rendering logic}
\label{fig:main_function_logic}
\end{figure}
\paragraph{Rendering text}
Rendering menu and win view consists of giving a text class correct coordinates and what text should be displayed
\begin{lstlisting}[style=C++Style]
From constants.hpp file:
namespace text {
...
constexpr float WON_X_POSITION = 320.0F;
constexpr float WON_Y_OFFSET = -20.0F;
constexpr float WON_ESCAPE_X_POSITION = 130.0F;
...
}
From game.cpp file:
void Game::renderWin() const {
if (this->State == GAME_WIN) {
const float screenMiddleYCoordinate =
static_cast<float>(this->Height) / 2.0F;
Text->RenderText("You WON!", {text::WON_X_POSITION,
screenMiddleYCoordinate + text::WON_Y_OFFSET}, 1.0F,
glm::vec3(0.0F, 1.0F, 0.0F));
Text->RenderText("Press ENTER to retry or ESC to quit",
{text::WON_ESCAPE_X_POSITION, screenMiddleYCoordinate}, 1.0F,
glm::vec3(1.0F, 1.0F, 0.0F));
}
}
\end{lstlisting}
\newpage
\paragraph{Rendering main view}
Rendering main view consists of rendering map and then applying postprocesses and text represending number of turns
\begin{lstlisting}[style=C++Style]
void Game::renderMain() {
if (this->State == GAME_ACTIVE || this->State == GAME_MENU ||
this->State == GAME_WIN) {
// begin rendering to postprocessing framebuffer
Effects->BeginRender();
this->renderDraw();
// end rendering to postprocessing framebuffer
Effects->EndRender();
// render postprocessing quad
const auto time = static_cast<float>(glfwGetTime());
Effects->Render(time);
// render turns (don't include in postprocessing)
this->renderTurns();
}
}
\end{lstlisting}
\section{Game level class}
Game level class takes a 2D array of game objects instances (tiles), receives inputs from game class and reacts to them, it handles removing, swaping, adding new tiles on a map and checking for sequences of tiles
\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.

View File

@ -0,0 +1,10 @@
<mxfile host="app.diagrams.net" modified="2023-08-31T13:37:56.874Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" etag="kFgdjMSiNFFh3ecqtN5u" version="21.7.1" type="device">
<diagram name="Page-1" id="7iqlcoXXWV2kU_wQwe1n">
<mxGraphModel dx="1430" dy="753" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
</root>
</mxGraphModel>
</diagram>
</mxfile>