Skip to content

Entity Prefab DSL

William Perreault edited this page Aug 12, 2017 · 1 revision

The Entity prefab DSL allows one to define entities using a simple lua syntax.

-- Prefab for a Mario Character
require 'priv_data/scripts/prefab_dsl'

local WIDTH = 0.5
local HEIGHT = 1.125

return Prefab "Mario" {

    -- GAME COMPONENTS

    Component "TAGS_COMPONENT" {
        tags = "mario"
    },
    
    Component "HEALTH_COMPONENT" {
        amount = 100,
        maxAmount = 100
    },

    Component "LAND_MOVEMENT_COMPONENT" {
        walkingSpeed = 2,
        runningSpeed = 3,
        maxRunningSpeed = 10,
        airControlSpeed = 8
    },

    Component "DIRECTION_COMPONENT" {
        facingDirection = "LEFT"
    },

    Component "JUMP_COMPONENT" {
        nbJumpsMax = 3,
        speed = 28,
        cooldown = 200,
    },

    -- GENERAL CHARACTER SETUP COMPONENTS
    Component "PHYSICS_COMPONENT" {
        width = 0.5,
        height = 1.125,
        position_x = 3,
        position_y = 0,
        body_type = "DynamicBody",
        fixed_rotation = true,
    },

    Component "PHYSICS_COLLIDER_CAPSULE" {
        type = "capsule",
        width = WIDTH,
        height = HEIGHT,
        position_x = 0,
        position_y = 0,
        is_sensor = false,
        top_tag = "head",
        middle_tag = "middle",
        bottom_tag = "legs",
        feet_tag = "feet"
    },

    -- Feet Sensor
    Component "PHYSICS_COLLIDER_BOX" {
        type = "box",
        width = 0.2,
        height = 0.2,
        tag = "feet_sensor",
        position_x = 0,
        position_y = -HEIGHT,
        is_sensor = true
    },

    -- Scripts
    Component "ENTITY_SCRIPT_COMPONENT" {},

    Component "SCRIPT_COMPONENT" {
        scripts = "MarioGraphicsScript"
    },

    Component "SPRITER_ANIMATION_COMPONENT" {
        animation_file = "animations://mario.scml",
        animation_title = "Running",
        entity_name = "Kubotz",
        offset_x = 0.0,
        offset_y = -1.05,
        scale = 0.005
    },

    Component "Z_INDEX_COMPONENT" {
        z_index = 10
    },
}
Clone this wiki locally