Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

The Environment

Kyle Martin edited this page Aug 23, 2017 · 1 revision

The Environment

The environment is where all the entities live - it's the map. The map is made of hexagon tiles, and every Hex Tile has its own set of properties. All entity plugins require there to be an environment in mind when creating them, since the map is where they get all of their data. The environment for a game such as Frogger could be as simple as a boolean: "Is this tile a road tile?" Entities for such a game would then be cars, trucks, and of course the frog. A template for the environment is provided in Plugins/Environment/Hex.(cpp/h).

What you need to know to code:

File requirements:

  • Plugins/Environment/Hex.h
  • Plugins/Environment/Hex.cpp

Inside that Hex.h must be a class with at least:

class Hex : public HexInternals
{
public:
    Hex(const unsigned int col, const unsigned int row, const double hexRadius) : HexInternals(col, row, hexRadius) {}

    virtual void update(unsigned int resolution) override;
}

But of course the constructor can be in Hex.cpp.

The two files in the Environment folder must have the names they have, since they are included by name by EMA. Furthermore, the Hex class needs to exist with the name Hex, since the data structures inside of EMA hold Hex tiles. This class Hex must inherit publically from HexInternals (and as such construct it... See Main/dataStructure/Hex.h) and have an void update(int) function. There can be any number of other files in this folder, with any names. You can also have any number of other functions inside the class. EMA will create a map with the specifications made in Main/main.cpp, populated by your Hex tiles.


Constructor/Internal Details:

If you don't want to read code, I can tell you what you need to know about HexInternals and constructing it here.

EMA holds the Hex tiles in a 2D Vector, as such they all have a row and column number... These are passed with the hexagon's radius to Hex internals so that it can determine where in a cartesian plane it is located. You can get these data with the getX(), getY(), and getRadius() functions (which would be useful, in example, for drawing).

If you did read the code, you'll also notice that the Hexes have an insert/delete function, some templates, and a buildNear function. In short, those are what work the magic of fetching nearby entities in the map.