OpenFL - Creating the Hero
A role-playing game cannot exist without a user controlled character.
A RPG is full of many monsters, npcs and interactive objects. We need a way to hold all of the definitions and easily create any number of them when needed. So similar to the
TileData classes. Lets create an
EntityData class. The
EntityStore will hold all the entity datas in the game.
This creates one empty entity data and an other called cloth which will be our hero. The cloth.png image is a sprite sheet with a variety of directions and animations. Right now only the first sprite will be used. The
yTiles is the number of tiles the sprite sheet has in the the y direction. This is used to find the height of the sprite tiles. This is needed because entities do not have a static height like normal tiles and it can be greater than the tile size.
Entity class has to be created. This will create the hero instance with our choosen sprite. The
Entity class simply holds a bitmap and extends the
Generic base object
GameObject is a new base class which
Entity extend from.
It gives each instance a unique id and implements x / y getters and setters. Finally it implementes xt / yt getters and setters which are short for xTile and yTile. They will convert tile coordinates into world space and the getters will convert world coordinates back into tile coordinates like so.
The purpose of the
GameObject is to provide a coordinate interface for all map objects. If you notice it does not hold a bitmap because not all map objects display anything, ie teleporters, traps.
Now back to the
Entity class, because entities can have heights larger than tiles. An entity needs to be positioned higher to stay on its tile.
This is a special hook which listens for y coordinate change events and positions the entity's bitmap correctly.
With all that, the hero entity instance can be created.
Portal class is a simple value-object which holds xt, yt, and an id which is used to identify an entityData definition. Portals will be used more often during map creation, it can be used to place entities, items, events and any game object.
The rest is quite simple, a new entity is created with the portal and added to the map.
Next tutorial: Movement