LibreWands/Documentation/Articles/EngineDesign.tex

131 lines
6.4 KiB
TeX

% Copyright © 2023 Ryan "Lofenyy" Medeiros.
%
% This file is part of LibreWands.
%
% LibreWands is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
%
% LibreWands is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along with LibreWands. If not, see https://www.gnu.org/licenses/.
\chapter{Engine Design}
To initialize the game engine, fist run \texttt{initEngine()}. This sets up the graphics, at the very least.
\section{Controls}
The controls used in this engine are based solely on the original Gameboy controls for simplicity and compatibility reasons, particularly with the Pinephone. Support for controllers is planned, but can currently be achieved through keybinding. Keyboard controls include the arrow keys, along with the \texttt{Z} and \texttt{X} buttons, as the primary and secondary buttons respectively. Instead of arrow keys, users of exotic keyboards such as on the Pinephone may use the \texttt{IJKL} keys instead of the arrow keys.
To get output from a controller, use \texttt{joycon()}. The possible outputs are as follows.
\begin{description}
\item['w'] The player pressed 'up' on the directional pad.
\item['s'] The player pressed 'down' on the directional pad.
\item['a'] The player pressed 'left' on the directional pad.
\item['d'] The player pressed 'right' on the directional pad.
\item['\\n'] The player pressed the 'start' key.
\item['\\\\'] The player pressed the 'select' key.
\item['z'] The player pressed the 'primary' key.
\item['x'] The player pressed the 'secondary' key.
\end{description}
\section{Maps}
The best way to understand how maps work in this engine, is to look at the source code, as found in \texttt{engineMaps.h} and \texttt{engineMaps.c} respectively. Maps are stored in a struct array, and each map contains five types of tiles. Every tile has an \texttt{X} and \texttt{Y} coordinate, as well as a \texttt{T} and \texttt{C} attribute, which record the printable character representing the tile, and color code, respectively. See the five types of tiles in the \texttt{Map Editor} chapter in this book. Each tile then contains additional attributes, along with its type.
\subsection{Tile Types and Attributes}
It should be noted that all of these tiles contain an \texttt{active} attribute, that notes whether or not the tile is in use. This is only done in memory, and is to simplify memory management. These states \textit{should not} be saved to external files. For information on color codes, see the \texttt{Color Codes} section of this book.
\subsubsection{Basic Tiles}
Basic tiles are the funamental building blocks of any level. They'll certainly be used the most. They're used for anything that one cannot use another tile type for. They're usede for things such as walls and walkable tiles. These include one-way walls.
\begin{description}
\item[x] The X coordinate where it appears.
\item[y] The Y coordinate where it appears.
\item[t] The printable character that represents this tile.
\item[c] The color code of the tile.
\item[walk] Whether one can walk on this tile or not.
\end{description}
\subsubsection{Information Signs}
Information signs are used to give information to a player.
\begin{description}
\item[x] The X coordinate where it appears.
\item[y] The Y coordinate where it appears.
\item[t] The printable character that represents this tile.
\item[c] The color code of the tile.
\item[dialog] The information that should be displayed to the player.
\end{description}
\subsubsection{Object}
An item on the ground that a player can collect.
\begin{description}
\item[x] The X coordinate where it appears.
\item[y] The Y coordinate where it appears.
\item[t] The printable character that represents this tile.
\item[c] The color code of the tile.
\item[ID] The item ID number.
\end{description}
\subsubsection{Door}
A tile that, if steped on, transports the player to a new place.
\begin{description}
\item[x] The X coordinate where it appears.
\item[y] The Y coordinate where it appears.
\item[t] The printable character that represents this tile.
\item[c] The color code of the tile.
\item[ID] The map number that the player gets transported to.
\item[nx] The X coordinate that the player gets transported to.
\item[nx] The Y coordinate that the player gets transported to.
\end{description}
\subsubsection{Character}
A tile that represents a person. Every person is either passive or aggressive. They may walk or they may not. If they are aggressive, they'll battle the player using the monsters that they have in their inventory.
\begin{description}
\item[x] The X coordinate where it appears.
\item[y] The Y coordinate where it appears.
\item[t] The printable character that represents this tile.
\item[c] The color code of the tile.
\item[type] Whether this character is aggressive or not.
\item[move] Whether this character moves or not.
\item[name] The characters name.
\item[dialog1] What the character says when they are aggressive.
\item[dialog2] What the character says when they are passive.
\item[mon] The monsters that this character carries.
\end{description}
The monsters that a character carries are strored in a struct array with five elements. Each element includes the following attribues.
\begin{description}
\item[type] The ID number of the monster. 0 means there is no monster in this slot.
\item[level] The level of the monster in this slot.
\end{description}
\subsection{Functions}
For the following functions, see \texttt{engineMaps.c} for details.
\begin{description}
\item[addBase()] Add a base tile to our map.
\item[addInfo()] Add a info tile to our map.
\item[addItem()] Add a item tile to our map.
\item[addDoor()] Add a door tile to our map.
\item[addChar()] Add a character tile to our map.
\item[delTile()] Delete all tiles at a specific location on the map.
\item[newMap()] Allocate memory for our maps. (misnomer)
\item[saveMaps()] Save our maps from internal memory to an external file.
\item[loadMaps()] Load our maps from an external file into internal memory.
\end{description}