Introduction to eAdventure Schema - e-ucm/ead GitHub Wiki

Introduction

eAdventure games are defined using several types of elements. Essentially, an eAdventure game is a set of scenes the player explores.

Each scene is compound of scene elements. These are the game objects present in the scene. A scene element can be a background, a character, an item, etc. Scene elements have an initial 2D transformation that sets its position, scale, rotation and color in the scene.

The scene element's representation in the scene (an image, an animation...) is set through its renderer.

Scene elements also contain a list of effects. These represent the effects we want to perform over the scene element or over the game state once the parent scene of the scene element is loaded. For example, if we add a Spin effect to a scene element, the game object will make a spin when the scene begins.

All scene elements contain a list of behaviors, defining which effects are launched when the scene element receives an input event (touch down, mouse moved...).

The eAdventure JSON schema (see http://json-schema.org/ for more info about the JSON schema initiative) is defined modularly and logically. It is structured in a set of different .json files for each of the components. The root folder for these files is schema project resources. Any new type of element or any modification of the existing ones must be done there.

This schema is used to automatically generate all the eAdventure Schema Java classes (see es.eucm.ead.schema package). As said, these classes are auto generated, and they should never be modified manually (modify the schema instead).

However, the schema can be generated through Maven:

mvn clean generate-sources java-formatter:format license:format -Pbuild-schema

An example

To define a game, we need to define the Game Folder Structure.

NOTE: For all json files that describe a game (not to be confused with the files that describe the schema, which have also .json extension), we use the simplified json notation with no double or simple quotes, which is parseable by the eAdventure json reader (Should we include a link to the reader here?). Double quotes are only to be used when a string contains blanks (e.g. text:"hello world"). Simple quotes are absolutely discouraged.

We want to define a game, with a camera view (camera view may need an explanation) of 800x600,

game.json:

{
   width:800,
   height:600,
   initialScene:scene1
}

then, we define the initial scene: scenes/scene1.json:

{
  children:[
   // Scene element 1 (Background)
  {
    renderer:{
      class:image,
      uri:"images/scenebg800x600.png"
  },
  // Scene element 2 (Character)
  {		
    transformation:{
      x:295,
      y:208
    },
    renderer:{
      class:image,
      uri:"images/character.png"
    }
  }
  ]
}

This scene contains 2 scene elements, a background and a character. The background has no transformation, meaning that it will be positioned on 0x0, which is what we want, since the scene element renders a image (scenebg800x600) that fills all the scene. The character is situated in position x and y, and its represented by the a renderer of type image (character.png).

Now, let's say we want to take the player to another scene when clicking on the character. For that, we need to define a behavior like this:

{
   input:{
     class:touch,
     event:touchDown
    },
    effect:{
     class:goscene,
     name:scene2
    }
}

And wee need to add it to the the scene element definition, so scene.json will look like this:

{
  children:[
   // Scene element 1 (Background)
  {
    renderer:{
      class:image,
      uri:"images/scenebg800x600.png"
  },
  // Scene element 2 (Character)
  {
    behaviors:[
     // Go to scene 2 when touch down (clicked)
     {
       input:{
         class:touch,
         event:touchDown
       },
       effect:{
         class:goscene,
         name:scene2
       }
      }
    ],
    transformation:{
      x:295,
      y:208
    },
    renderer:{
      class:image,
      uri:"images/character.png"
    }
  }
  ]
}

Engine Schema versioning

To facilitate the migration between engine's model version, a es.eucm.ead.schame.Version class is generated automatically that contains the following properties:

package es.eucm.ead.schema;

/**
 * Engine schema version
 */
public final class Version {
    /**
     * Maven artifact version.
     */
    public static final String POM_VERSION="1.0-SNAPSHOT";

    /**
     * Build time.
     */
    public static final String BUILD_TIME="20140410-1446";
}