Skip to content
zackhehuman edited this page Feb 20, 2014 · 12 revisions

Object Templates describe how different kinds of objects should be created. The templates are used to create a prototype object from which other objects are created by cloning. Objects are differentiated by type: Enemy, Item, Projectile, and Particle. Each type of object has different properties that can be configured individually.

Template files should be placed in the assets/templates/ directory.

Items

JSON Structure

Properties

  • name {String} the name of the object type, must be unique
  • effect {String} the name of the effect that the item applies when collected
  • effectConfig {Object} an object of effect-specific configuration values
  • animationSet {String} the path to the animation set this item uses
  • animationName {String} the name of the animation (from the above set) that should be used
  • boundingBox {Object} the physical shape of the item
  • ageless {Boolean} whether this item ages over time; if false then the item will never disappear on its own
  • maximumAge {Number} the maximum age, in ms, a non-ageless item can be before it self-destructs

Example

This example shows how to create a template object for an "extra life".

{
    "name": "Extra Life",
    "effect": "AddExtraLifeEffect",
    "effectConfig": {
        "amount": 1
    },
    "animationSet": "assets/animations/items.json",
    "animationName": "extra-life-rockman",
    "boundingBox": {
        "width": 14,
        "height": 14,
        "originX": 7,
        "originY": 7
    },
    "ageless": false,
    "maximumAge": 3000
}

Enemies

JSON Structure

Properties

  • name {String} the name of the enemy type, must be unique
  • behavior {Object} the objects behavior configuration
  • type {String} the type of behavior, one of: ["scripted", "unscripted"]
  • name {String} the name of the behavior controller (if the type is "scripted", this is the name of the EnemyBehavior class to use)
  • config {Object} any behavior-specific configuration values (key-value pairs), this of this as a class-wide table for default values
  • animationSet {String} the path to the animation set this enemy uses
  • boundingBox {Object} the physical shape of the enemy
  • width {Number} the width, in pixels, of the enemy's bounding box
  • height {Number} the height, in pixels, of the enemy's bounding box
  • originX {Number} the X coordinate of the bounding box's "origin", which is an offset from the top-left corner that should be considered the "actual" X coordinate of the enemy
  • originY {Number} the Y coordinate of the bounding box's "origin", which is an offset from the top-left corner that should be considered the "actual" Y coordinate of the enemy
  • states {not implemented yet} a set of property changes to make when the given state is active
  • characteristics {Object} physical characteristics present in the enemy
  • gravitated {Boolean} sets whether this enemy is affected by gravity
  • phasing {Boolean} sets whether this enemy walks through walls or not
  • actionSpot (optional) {Object} a position, relative to the enemy's origin, where bullets are fired from. Defaults to (0, 0).
  • x {Number} the X coordinate of the action spot
  • y {Number} the Y coordinate of the action spot
  • deathType (optional) {String} the type of death this enemy has, one of: ["Nothing", "Large", "Small", "Hero"]. Defaults to "Small". This mainly control the type of explosion that happens once the enemy is destroyed. "Hero" is the kind of explosion that happens when Rock or a Robot Master is destroyed.
  • bonusTableIndex (optional) {Number} a number indicating which bonus table to use. Defaults to 0. The bonus table affects which items the enemy will drop when destroyed.

Note about boundingBox's origin: The origin is used to calculate the "real" position of an enemy since the top-left corner is not always the most convenient location. The origin is also used to position the animation on top of the bounding box, so there is usually a correlation between the two. Typically the origin should be either at the "feet" of an enemy, or at its center/waist. When an enemy changes direction (from left to right or vice-versa) its bounding box is mirrored around its origin.

Example

{
    "name": "Telly",
    "behavior": {
        "type": "scripted",
        "name": "TellyEnemyBehavior",
        "config": {

        }
    },
    "animationSet": "assets/animations/telly.json",
    "boundingBox": {
        "width": 14,
        "height": 14,
        "originX": 7,
        "originY": 7
    },
    "states": {
        "default": {
            
        }
    },
    "characteristics": {
        "gravitated": false,
        "phasing": true
    }
}

More about behavior.config

Any values specified in the config property of the behavior property are converted to a Squirrel table and fed to the constructor of the behavior class. This allows you to have pre-set configuration for an enemy prototype. For example, let's say you create a MoveAroundBehavior that moves an enemy between two locations. With the config property, you can specify default locations to move in between and all enemy instances using that behavior will have the default locations. This configuration is not the same as an instance-level config, and instance-level config values overwrite class-level config values.

Behaviors

Behaviors control how an enemy behaves. See the Behaviors page for more information.