3.2. Structures.md

September 22, 2019 ยท View on GitHub

3.2. Structures

3.2.1. mob

This section was last checked in the 2.0.3. version of the engine
//   This strcture holds entities in the world (right now these entities are just the
// player and the camera).
struct mob
{
	//   These variables hold the coordinate/the position of the mob/entity in the world.
	int row;
	int col;
	//   These variables hold the orientation of the mob. There are 8 different
	// orientatins. Currentaly only the player entity uses these sub variables.
	bool up;
	bool down;
	bool right;
	bool left;
};

Usage: Any entity that can move is stored as a mob, right now these entities are the player character and the camera.

Sub variables:

  • row: This variable stores the row of the newWorld array the mob is currently in.
  • col: This variable stores the column of the newWorld array the mob is currently in.
  • up: This is true if the mob is looking up.
  • down: This is true if the mob is looking down.
  • right: This is true if the mob is looking right.
  • left: This is true if the mob is looking left.

Notes: Out of the four last bools one is always true, and up to two can be true at once, however these two can not be contradictory for example: up and down. As of 2.0.3. the latter 4 sub variables are only used by the player. The col and row coordinates are coordinates of cells, this should not be confused with coordinates of points! Details about the difference between cell and point coordinates can be found here.

3.2.2. map

This section was last checked in the 2.0.3. version of the engine
//   This structure holds information about the map in the engine.
struct map
{
	//   This sub variable holds the texture of the cell.
	char texture;
	//   These sub variables hold the properties of the different cells. Solid si true 
	// when the given cell blocks light, and walkable is true when the given cell does
	// not block movement.
	bool solid;
	bool walkable;
	//   These sub variables hold information about the visibility of the different 
	// cells. When mapInView is true the cell is in view, when mapIsEdge is true a 
	// less intense shadow gets displayed in the game on that cell.
	bool mapInView;
	bool mapIsEdge;
};

Usage: This structure alone can hold every needed information about a cell of any map. In the engine it is used as a base for the newWorld array, that array holds every parsed information from the map editor.

Sub variables:

  • texture: This is the ASCII character that is displayed in game.
  • solid: This is true if this cell blocks light and thus creates shadows.
  • walkable: This is true if this cell does not block player movement.
  • mapInView: This is true if the texture of the cell should be displayed.
  • mapIsEdge: This is true if the texture of the cell should be replaced with 'โ–’', because it is between a cell that is in view and another that isn't.

Notes: Throughout the game loop mapInView is changed, firstly it is true for every cell that is in the field of view of the player, after that the shadows are calculated and mapInView is actually only true for cells that are in fact in view.

3.2.3. fov

This section was last checked in the 2.0.3. version of the engine
//   This structure holds information about the FOV arrays.
struct fov
{
	//   This is true if the cell is in view in the FOV array.
	bool inView;
	//   This is true on the cell where the player is in the FOV array.
	bool isPlayer;
};

Usage: This structure alone can hold every needed information about a cell in the FOV arrays or the FOV text files. In the engine it is used as the base for every FOV array.

Sub variables:

  • inView: This is true if this cell of the FOV is in view.
  • isPlayer: This is true if this cell of the FOV is the player.

Notes: In version 2.0.3. isPlayer is not dynamically used by the engine, further information can be found here.

3.2.4. line

This section was last checked in the 2.0.3. version of the engine
//   This structure holds the variables that define a line in the engine.
struct line
{
	//   This is the slope of the line.
	double mSlope;
	//   This is the point where the line intercepts the y axis.
	double bIntercept;
	//   This is true if the line is below any given object we want to "compare" it to.
	bool isItUnderLine;
};

Usage: This is the structure that holds every needed information about the lines that are cast from the player to the correct objects.

Sub variables:

  • mSlope: The slope of the line.
  • bIntercept: The value where the line intercepts the y axis.
  • isItUnderLine: This is true if the line is under the object which we are trying to shade.

Notes: The line equation I am using for this project is the following: y = (mSlope * x) + bIntercept. This equation can't describe lines that are vertical, but I prevented that from happening, no lines that are cast are not cast vertically (or horizontally for that matter). The isItUnderLine sub variable is only used when determining what is and what isn't in shade, when the lines are not for that purpose this sub variable can be left untouched. If the point (a; b) is under a line this inequality would be true: b < (mSlope * a) + bIntercept, if said point is over the line this inequality would be true: b > (mSlope * a) + bIntercept, if the point is on the line this equation is true: b = (mSlope * a) + bIntercept. For more information about this formula of the line click here.

3.2.5. edgeLines

This section was last checked in the 2.0.3. version of the engine
//   This structure holds two lines at once.
struct edgeLines
{
	line first;
	line second;
};

Usage: This structure holds two lines at once.

Sub variables:

  • first: The first line.
  • second: The second line.

Notes: This structure makes accessing the two lines that are cast to a rectangle (binary shading is produced by casting lines to only rectangles) from a player easier.

3.2.6. koordinate

This section was last checked in the 2.0.3. version of the engine
//   This structure holds coordinates.
struct koordinate
{
	double x;
	double y;
};

Usage: This structure holds the values of a coordinate.

Sub variables:

  • x: The x value.
  • y: The y value.

Notes: This should not be confused with the coordinates of cells. This is the coordinate of points, this structure is used when casting lines from the player to objects. Details about the difference between cell and point coordinates can be found here.

3.2.7. animation

This section was last checked in the 2.0.3. version of the engine
//   This structure holds animations.
struct animation
{
	//   The number of frames in the animation.
	int frames;
	//   The current frame of the animation the engine is playing/displaying.
	int currentFrame;
	//   The "height" of every frame of the animation.
	int height;
	//   The "width" of every frame of the animation.
	int width;
	//   This array holds every frame of the animation.
	char frameArray[MAXAMOUNTOFANIMATIONFRAMES][CONSOLEROWS][SCREENCOLS + MENUCOLS];
};

Usage: This structure holds the properties of an animation, parsed from a .txt file

Sub variables:

  • frames: The number of frames in the animation.
  • currentFrame: The current frame the animation is on, this is in use when playing the animation with the proper function.
  • height: The "height" of the animation, or the number of rows it contains.
  • width: The "width" of the animation, or the number of columns it contains.
  • frameArray: This 3 dimensional array holds the characters in every row and column of every frame.

Notes: You should only change the number of frames in the frameArray sub array, since the other two dimensions (CONSOLEROWS and SCREENCOLS + MENUCOLS) are exactly 24 by 80 which is equal to the dimensions of the console window. Evidently the maximum value of height should not exceed the second dimension of the frameArray array (which is CONSOLEROWS = 24) and the maximum value of width should not exceed the third dimension of the frameArray array (which is SCEENCOLS + MENUCOLS = 80). To learn more about the animation pipeline click here.