XMLGameEngine

XMLGameEngine is a VGDL (video game description language) and an engine for running games completely contained within an XML file.

View the Project on GitHub beefviper/XMLGameEngine

Maps

A <map> is level data drawn as text: each <row> is a row of tiles, one character a tile, so the file shows the level as it looks. It stands in any <objects>, or in the kit. With <cells /> it is a playfield of cells for grid puzzles and board games.

Drawing a map

<map name="maze">
  <tile><width>tile</width><height>tile</height></tile>
  <position><x>0</x><y>top</y></position>
  <row>r--------T--------7</row>
  <row>|o.......|.......o|</row>
  <row>|.[].[-].u.[-].[].|</row>
  ...
  <group name="walls" class="wall">
    <group name="across" char="-"> <sprite>...</sprite> </group>
    <group name="corner" char="r"> <sprite>...</sprite> </group>
  </group>
  <group name="dots" char="." class="food"> ... </group>
  <object name="pacman" char="@"> ... </object>
</map>

Walking a map

An object with <maze map="maze"> walks that map’s tiles: it keeps to the middle of its lane, chooses its way only in the middle of a tile, and never steps onto a tile that is a wall to it.

<maze map="maze">
  <wall class="wall" />
  <wall class="door" sprite="normal" />    <!-- a wall only while it shows "normal" -->
  <slow class="tunnel">0.5</slow>          <!-- half speed on those tiles -->
</maze>

Cells

A map with <cells /> is a playfield such as Tetris’s well: pieces move a whole cell at a time, it knows which cell holds what, and it can be asked about its rows.

<map name="board">
  <tile><width>cell</width><height>cell</height></tile>
  <position><x>left</x><y>top</y></position>
  <columns>10</columns>                       <!-- in place of rows: an empty map -->
  <rows>20</rows>
  <cells />
  <group name="blocks" class="block">
    <group name="cyan" char="i"> ... </group> <!-- on no tile: waits to be spawned -->
  </group>
  <group name="pieces" class="falling">
    <timers><timer><every>status.gravity</every><hop direction="down" /></timer></timers>
    <collisions><collision edge="bottom"><settle /></collision></collisions>
    <group name="t">
      <shape>
        <row>.t.</row>
        <row>ttt</row>
        <row>...</row>
      </shape>
    </group>
  </group>
  <checks>
    <full class="block"><clear /><collapse /><inc variable="status.lines" /></full>
  </checks>
</map>

Pieces

Moving on cells

Verb Does
<hop direction="down" /> one cell (its content: that many)
<move direction="left">12<wait>0.2</wait></move> held: one step, waits, then 12 cells a second
<slide direction="down" /> cell by cell at once until refused (Tetris’s hard drop)
<turn direction="clockwise" /> a quarter turn of a shape, once a press
<cycle /> each cell of a shape moves on along its outline (Columns)
<go direction="up">8</go> keeps going 8 cells a second until another <go>

Chains

<chain object="body" /> on a piece: the pieces of that name behind it, drawn beside one another in the rows (ooo@), are its links; each step every link takes the cell of the one ahead. The tail is no blocker.

Settling and joining

Checks

Asked after each settle or put:

Check Finds Then
<full class="block"> each row whose every cell holds that class its commands run once a row, bottom up; <clear /> takes the row away, <collapse /> brings everything above down a row
<line class="jewel"><atleast>3</atleast> every line of that many alike, across, down or slanting (<straight />: no slants) its commands run once for all; asked again until nothing is taken (chains)

A second map: the next-piece box

A cell map may hold nothing: <map name="next"> with its tile, position, <columns>4</columns><rows>2</rows><cells />.