Characters

From Open Surge Engine Wiki
Revision as of 00:11, 5 July 2019 by Alexandre (Talk | contribs) (Explaining about custom abilities)

Jump to: navigation, search

Overview

Character files are human-readable configuration files located in the characters/ folder. They're used to create playable characters and have the .chr extension.

Each level has one or more playable characters. See also: How to set the players on a level.

Structure

Character files are used to specify the following data:

  • the name of the character;
  • the multipliers. These values are used to specify how fast a character runs, how high it jumps, how fast it accelerates, etc. For example, if you set the acceleration to one, it will accelerate by the default rate (set by the game engine). If you set it to two, it will accelerate two times faster than that. If you set it to 0.5, it will accelerate by half of the default rate, and so on. By default, all the multipliers are set to 1.0;
  • the animations for each action the character performs: walk, run, jump, etc., as well as the sprite name. See also: Sprites;
  • the sound effects this character uses: jump, brake, etc.;
  • the abilities this character has: roll, charge, etc.;
  • optionally, the name of one or more companion objects. If defined, companion objects can be used to give custom abilities to characters.

Example: Surge

//
// Surge (example)
// File: characters/surge.chr
//

character "Surge"
{
    companions                      "Surge's Light Sneakers" // "Surge's Light Sneakers" is an object created in SurgeScript

    multipliers
    {
        acceleration                1.0    // modifies the acceleration rate
        deceleration                1.0    // used when moving in opposition to the current movement
        friction                    1.0    // modifies the friction (since version 0.5.0)
        topspeed                    1.0    // modifies how fast the character can run
        jump                        1.0    // modifies how high the character jumps
        gravity                     1.0    // gravity modifier
        slope                       1.0    // affects the physics on slopes
        charge                      1.0    // modifies the charge-and-release speed (since version 0.5.0)
        airacceleration             1.0    // the rate at which the horizontal speed can change while midair (since 0.5.0)
        airdrag                     1.0    // air drag / air friction (since version 0.5.0)
    }
    
    animations
    {
        sprite_name                 "SD_SURGE"
        stopped                     0
        walking                     1
        running                     2
        jumping                     3
        springing                   13
        rolling                     18
        charging                    6
        pushing                     14
        gettinghit                  11
        dead                        8
        braking                     7
        ledge                       10
        drowned                     9
        breathing                   12
        waiting                     15
        ducking                     4
        lookingup                   5
        winning                     17
        ceiling                     16
    }
    
    abilities
    {
        roll                        TRUE
        brake                       TRUE
        charge                      TRUE
    }
    
    samples
    {
        jump                        "samples/jump.wav"
        roll                        "samples/roll.wav"
        death                       "samples/death.wav"
        brake                       "samples/brake.wav"
        charge                      "samples/charge.wav"
        release                     "samples/release.wav"
    }    
}

Compatibility notes: animation charging, sounds charge and release, the abilities block, as well as some multipliers (indicated above) are available since Open Surge version 0.5.0.

Companion objects: companions is available since Open Surge version 0.5.0. It is followed by one or more names of objects surrounded by double quotes ("). These objects should be created in SurgeScript. In older versions of the engine, you'd write companion_object instead (it supports only one companion).

Creating custom abilities

One of the exciting features of Open Surge is the possibility to create custom abilities (custom moves) for your characters. You can create these abilities by adding companion objects to your characters. These objects should be created in SurgeScript.

To understand better how to create your own custom abilities, let's study the case of a dash movement (affectionally called "Super Peel Out"). If your character is endowed with that ability, you can give it instant speed when it's stopped. In Open Surge, character Tux features that ability. Surge does not. To add this custom move to Surge, add the corresponding object to his companions:

companions                      "Surge's Light Sneakers" "Super Peel Out"

The new companion is defined in a script, a .ss file located in the scripts/ folder. The script of this move has been reproduced here for clarity:

using SurgeEngine.Audio.Sound;

//
// This is a dash move that should be configured as a
// companion object in a character definition file (.chr)
//
// When you are stopped, hold up and press jump to charge.
// Release up after 0.3 second and you'll gain a nice boost!
//
object "Super Peel Out"
{
    speed = 720;     // dash speed, in pixels/second

    charge = Sound("samples/charge.wav");
    release = Sound("samples/release.wav");
    player = parent; // since this object is configured as a
                     // companion, parent is the reference
                     // to the correct Player object

    // capture the event
    state "main"
    {
        if(player.lookingUp) {
            if(player.input.buttonPressed("fire1")) {
                charge.play();
                state = "charging";
            }
        }
    }

    // charging the dash
    state "charging"
    {
        player.anim = 2; // running animation
        player.animation.speedFactor = 1.85;
        player.frozen = true; // disable physics (temporarily)

        // ready to go?
        if(player.input.buttonReleased("up")) {
            if(timeout(0.3)) {
                player.gsp = speed * player.direction; // dash!!!
                release.play();
            }
            player.frozen = false; // enable physics
            state = "main";
        }
        else if(player.input.buttonPressed("fire1"))
            charge.play();
    }
}

What custom abilities can you add? Whatever you can imagine! Swimming, flying, climbing, wall kicking, you name it! The sky is the limit for those who learn SurgeScript! ;)

Curiosity: regular platformers

Even though Open Surge provides built-in 360º physics (with curvy roads, loops, and so on), careful modification of the character files can make it behave like a regular platformer. Example: if you create a character named SuperTux without the special abilities listed above, set its slope multiplier to zero (and adjust the others), as well as build levels mainly out of rectangular platforms, you'll end up with a platformer like SuperTux.

SuperTux, a jump'n run inspired by Mario