Skip to content
Tesserex edited this page Jan 23, 2012 · 2 revisions

Entities are the most important - and most complex - part of the engine. An entity is an object that exists during gameplay, while stages are being played, and during cutscenes. Entities represent everything that can have a state or behavior.

Some examples of entities include:

  • Mega Man himself
  • Projectiles
  • Enemies
  • Items and powerups
  • Yoku blocks and other "intelligent" platforms

##Declaration

Entities are declared in their own file. They are enclosed in a parent Entities tag at the root of the document. You can split your entities across multiple files if you like, but you can't mix entities with other declarations in the same file.

###Example

<Entities>
    <Entity name="PropFollower">
        <Tilesheet pallete="Default">images\enemies\propfollower.png</Tilesheet>
        <Sprite width="24" height="16">
            <Hotspot x="12" y="8" />
            <Frame x="0" y="0" duration="6" />
            <Frame x="24" y="0" duration="6" />
            <Frame x="48" y="0" duration="6" />
            <Frame x="72" y="0" duration="6" />
            <Frame x="96" y="0" duration="6" />
            <Frame x="120" y="0" duration="6" />
        </Sprite>
        <Health>
            <Max>1</Max>
            <Flash>8</Flash>
        </Health>
        <Collision>
            <Hitbox name="H" damage="2" x="-12" y="-8" width="24" height="16" environment="false">
                <Hits>Player</Hits>
                <Group>Enemy</Group>
            </Hitbox>
            <Enabled>True</Enabled>
        </Collision>
        <State name="Start">
            <Movement mode="Repeat">
                <Flying>true</Flying>
                <Velocity magnitude="0.4" direction="Player" />
            </Movement>
            <Collision>
                <EnableBox name="H" />
            </Collision>
        </State>
        <Trigger>
            <Condition>Health.Hit == True</Condition>
            <Effect>
                <Sound name="EnemyHurt" />
            </Effect>
        </Trigger>
        <Death>
            <Call>EnemyDeath</Call>
        </Death>
    </Entity>
</Entities>

There's clearly a lot going on in the above example. The Entity tag only has one required attribute: name. Most of the sections represent components, described below.

##Component System

A component-based system is a way of constructing entities as a collection of smaller parts. This isn't a unique concept to this engine - component systems are commonly used in game programming. For a primer, read Evolve Your Heirarchy. Each of the smaller components serves a single purpose, allowing you to use only the features you need. See the section below for how to include and use each of the components.

##List of Components

  • Collision - Gives entities the abilities to collide with each other and the environment. This component can also be used for sending messages between entities.
  • Input - Allows entities to accept input from the player. Mainly used by Mega Man, but can have other uses.
  • Health - Gives an entity health, allowing it to take damage and be killed. Also controls health bars.
  • Ladder - Allows an entity to climb ladders.
  • Movement - Allows an entity to move.
  • Position - Specifies a position on the screen. This component usually isn't specified explicitly in the entity definition.
  • Sound - Allows an entity to play sounds. To use this component, just specify the sound to play.
  • Sprite - Describes the entity's appearance using sprites.
  • State - Controls the entity's behavior. Think of this as the AI.
  • Timer - Allows you to set timers, which can be used in the state component.
  • Weapon - Pretty much just for Mega Man. Gives him weapons and controls their ammo bars.

##Additional Tags

Other than the components, there are a few tags that can be used directly within the Entity tag.

###Trigger You can use trigger tags outside of a state component tag, and they will apply to all states. See the state component page for more information.

###Tilesheet This tag is part of the sprite component declarations. See the Sprite page for more info.

###Death When an entity dies, the contents of the Death tag will be executed. This only applies when the object dies or is killed in the game. It does not get executed if the entity is simply removed by the system, for example by going off screen.

The Death tag behaves as a function, and can contain the same instructions. See the function page for more info.