Repository navigation
Entity API
To be able to become powerful and wage war, it makes sense to be able to create infrastructure. Dominion inclues an API so you can easily accomplish this.
Currently, this API is mainly used for drawing buildings, though it can also be used to draw other stationary objects such as vehicles and topographical features. All you really need is a isometric image and some very basic Javascript skills.
You might want to check out Creating Isometric Graphics.
Displaying an entity in Dominion is actually a fairly easy task with minimal coding. For the most part, there are two parts to displaying an entity:
- loading the image for the entity
- adding the entity to the entities array and make it visible
Loading the entity's image only requires two lines of code. At the top of game.js:
/**
* entity resources
*/
var factory = new Image();
factory.src = "./assets/entities/factory.png";The first line creates an image object. Make sure to name it accordingly. The second line defines the path to the entity's image.
Once that's all said and done, it's time to move onto adding the entity to the entities array. Also in game.js:
/**
* game variables
*/
$(document).ready(function()
{
/*** other code ***/
// entities
addEntity(new Entity("factory", factory, new Point(4,5), true));
/*** more other code ***/
});In this example, we've simply using the addEntity() function to add a new Entity object to the entities array. The Entity object has four basic attributes:
-
name(string): Name of the entity. This is what you'll use to reference the entity on the screen -
image(image object): Image object for this entity. This is the image object you created earlier. Multiple entities can use the same image object. -
point(point object): Point object for this entity. Defines the location of the entity. Simply usenew Point(x,y), replacingxandywith grid coordinates. -
visible(boolean): True or false. Determines whether object should be drawn on canvas.
In the above example, addEntity() occurs in the Game Variables section of game.js. Please note that addEntity() can be placed anywhere in any file as long as it falls inside a document.ready(). This is to ensure that the entity's image has been loaded first.