Game Development Reference
In-Depth Information
sic structure of a component and we'd be ready to simply plug it into the main game
logic script.
/entities
Entities are the main building blocks of the game. They are the generalized repres-
entation of anything that we can interact with—the player's ship, enemy ships, or
laser beams. Some people call their entities objects, characters, or actors, but the
idea behind them is the same.
In our game, we don't extend the base entity class in order to create a distinction
between ships and lasers. The only thing that sets them apart are the components
they use and how those components are used.
The structure of our game entities is basic and to the point. Each entity keeps track
of its own position within the game world, a flag that indicates its state (whether the
entity is active or not—dead or alive), a list of components, and an update function.
Also, for simplicity, each entity declares a draw function which delegates the actual
drawing to the sprite component, if the entity happens to have one. We also define
a few general purpose functions inside each entity so as to make adding, removing,
and using components a bit easier. Finally, each entity allows for a custom update
function, so that each instantiated entity can update itself differently.
var Packt = Packt || {};
Packt.ENTITY_TYPES = {
SHIP: 0,
BULLET: 1
};
Packt.Entity = function(type, x, y) {
var type = type;
var pos = {
x: x,
y: y
};
var isActive = true;
var components = new Object();
Search WWH ::




Custom Search