From 9c3f286ff805642e8ab1ffec11dab8fe6abb2805 Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Thu, 31 Aug 2023 19:36:05 +0200 Subject: [PATCH] feat: started game level class --- Thesis/Thesis.tex | 71 +++++++++++++++++++++++++++++++++ Thesis/images/renderGame.drawio | 10 +++++ 2 files changed, 81 insertions(+) create mode 100644 Thesis/images/renderGame.drawio diff --git a/Thesis/Thesis.tex b/Thesis/Thesis.tex index 53d1857..3f6d47e 100644 --- a/Thesis/Thesis.tex +++ b/Thesis/Thesis.tex @@ -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(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(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. diff --git a/Thesis/images/renderGame.drawio b/Thesis/images/renderGame.drawio new file mode 100644 index 0000000..d504c6c --- /dev/null +++ b/Thesis/images/renderGame.drawio @@ -0,0 +1,10 @@ + + + + + + + + + +