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

Pictures

What an object looks like: its sprites, looks, animation and poses, and how light and height change the drawing.

Sprites

A <sprite> holds one shape. A name is needed only when an object has several (as looks or animation frames). A <color> left out is color.white.

Shape Contents Draws
<circle> <radius>, <color> a filled circle
<rectangle> <width>, <height>, <color> a filled rectangle
<text> pieces, then <size>, <color>, <font>; style= text
<image> <path>, <flip> an image file, loaded by the window library
<line>s each <from>, <to>, <color>, <thickness> straight lines
<polygon>s each three or more <point>s, <color> filled shapes
<bitmap> <row>s, <scale>, <color>s, <flip>; style= a picture written as text
<svg> <path>, a part, <scale>, <hide>s, <flip> part of an SVG file
<tether from="a" to="b"> <thickness>, <color> a line between two objects’ middles, redrawn every frame; in play while both are (a fishing line, a missile’s trail)

The engine draws its own pictures. Lines, polygons, bitmaps and SVGs are drawn once at load into the engine’s own Bitmap (buildPicture, load/expr.cpp). So every window library shows the same pixels, an object’s size is known with no window, and a pixel collision tests exactly what is drawn. Text and image files are the exception: only a window library can measure them.

Turning. An object with a <heading> shows its picture turned, to the nearest whole degree, redrawn only when that changes. Lines are redrawn turned, so they stay sharp; a bitmap’s pixels are turned one for one, so chunky pixels stay chunky. Every heading gives the same square, which is the object’s size.

Lines

<sprite>
  <line><from><x>10</x><y>2</y></from><to><x>20</x><y>2</y></to></line>
  <line><from><x>20</x><y>2</y></from><to><x>25</x><y>7</y></to><color>color.red</color><thickness>2</thickness></line>
</sprite>

Polygons

<sprite>
  <polygon>
    <point><x>0</x><y>600</y></point>
    <point><x>0</x><y>450</y></point>
    <point><x>390</x><y>270</y></point>
    <point><x>800</x><y>445</y></point>
    <point><x>800</x><y>600</y></point>
    <color>color.forestgreen</color>
  </polygon>
</sprite>

Bitmaps

<sprite>
  <bitmap>
    <row>..*...*..</row>
    <row>..*****..</row>
    <row>.**w*w**.</row>
    <row>*********</row>
    <scale>5</scale>
    <color>color.green</color>             <!-- the * pixels -->
    <color char="w">color.white</color>    <!-- the w pixels -->
  </bitmap>
</sprite>

SVG pictures

<sprite>
  <svg>
    <path>assets/Space Invaders Color Sprites.svg</path>
    <x>96</x> <y>64</y> <width>32</width> <height>32</height>
    <scale>2</scale>
    <hide>backdrop</hide>
  </svg>
</sprite>

Text

A <text> is pieces, in any order, then <size>, <color> and <font> (or a style= for those it leaves out):

<text style="hud"><content>SCORE</content><number>ship.score</number></text>   <!-- SCORE 120 -->
Piece Shows
<content>PONG</content> the words as written
<number>paddle1.score</number> a number; one owner.variable is live and redraws when it changes, anything else is worked out once
<letter>entry.first</letter> a number as a letter, 0 is A and 25 Z, wrapping: initials are three variables
<choose><by>value</by><word>LOVE</word><word>15</word>...</choose> one of its words, the first for 0 (past either end, the end word), live like a number

Animation

<object name="crab">
  <sprite name="open"> <bitmap> ... </bitmap> </sprite>
  <sprite name="closed"> <bitmap> ... </bitmap> </sprite>
  <animation>
    <interval>1</interval>
    <frame sprite="open" />
    <frame sprite="closed" />
  </animation>
</object>

Looks

An object with several named sprites and no unnamed animation has looks. It starts as the first; <become sprite="name" /> shows another; a reset brings back the first.

<collision object="bailey" sprite="white">     <!-- only while this floe is white -->
  <become object="row1" sprite="blue" />
  <inc variable="bailey.score">10</inc>
</collision>

Poses, mirror, grip and blinking

Three parts, after <facing>, give a walking, jumping thing its look and feel without a rule for each:

<poses>
  <standing sprite="stand" />
  <walking sprite="walking" />
  <skidding sprite="skid" />
  <rising sprite="rising" />
  <falling sprite="falling" />
  <thrusting sprite="burning" />
</poses>
<mirror>left</mirror>
<grip>0.15</grip>

Surfaces

A piece with a <surface> is ground that changes how a gripping thing goes:

<group name="grass" char="g">
  <sprite><rectangle><width>40</width><height>40</height><color>color.forestgreen</color></rectangle></sprite>
  <surface><drag>0.08</drag><grip>0.3</grip></surface>
</group>

While its middle is over a surface (in play, drawn or not), a thing with a <grip> has that surface’s <drag> and <grip> instead of its own; over several, the last in the file. Things without a <grip> (a shot, a path follower) feel nothing.

Turning about a pivot

A <pivot> is the point of the drawing the object turns about; its <position> is where that point sits on the table.

<object name="leftflipper" from="flipper">
  <position><x>141</x><y>539</y></position>
  <heading>30</heading>
  <pivot><x>0</x><y>0</y></pivot>
  <actions>
    <action name="flip"><swing direction="counterclockwise"><degrees>60</degrees><seconds>0.1</seconds></swing></action>
  </actions>
</object>

Light and dark

What is <dark> is drawn only where there is light. Something in play with a <light> lights everything within that many pixels of its middle.

<action name="strike"><set variable="player.light">match</set></action>

Height and shadows

An object with an <altitude> is in the air over its position: it touches at the point on the ground, and is drawn raised.

<object name="shadow"> ... <shadow object="ball" /></object>      <!-- written first, drawn under -->
<object name="ball">
  ...
  <altitude><start>80</start><fall>0.25</fall><bounce>0.7</bounce></altitude>
  <collisions>
    <collision object="player">
      <condition variable="altitude"><below>reach</below></condition>
      <set variable="ball.rise">loft</set>
    </collision>
  </collisions>
</object>