* Made a few additions to the file formats reference.
[supertux.git] / docs / fileformats / fileformats.xml
1 <?xml version='1.0' ?>
2 <!--
3 $Id$
4
5 SuperTux Documentation
6 Copyright (C) 2005 Ondra Hosek <ondra.hosek@gmail.com>
7
8 This document is free; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This document is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program (see the file named 'COPYING'); if not,
20 write to the Free Software Foundation, Inc., 59 Temple Place -
21 Suite 330, Boston, MA 02111-1307, USA.
22
23 -->
24 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
25
26 <article xml:lang="en">
27
28 <articleinfo>
29 <title>SuperTux File Format Documentation</title>
30 <author><firstname>Ondra</firstname><surname>Hosek</surname></author>
31 </articleinfo>
32 <para>This document serves the simple purpose of a reference for the files specific to SuperTux (levels, worldmaps, ...). Some of these files can be modified using an editor such as Flexlay.</para>
33 <sect1><title>Brackets, brackets, brackets (About the Language)</title>
34 <para>As you might have already noticed, the SuperTux definition files (just about for everything) are full of brackets ('(' and ')'). I know that <acronym>BASIC</acronym> programmers already freak out when seeing the vast amount of brackets used in C. The truth is that you can never have too many brackets. (Okay, that's a lie, but I don't know how lenient your compiler is.)</para>
35 <para>"That Crazy File Format" used by SuperTux is Lisp. In most of its implementations, it is used as a programming language, but the devs simply thought why not to implement it as a data storage language. And so, the SuperTux data language, nearly fully based on Lisp, was born.</para>
36
37 <sect2><title>Basic Syntax</title>
38 <para>So now you expect me to teach you Lisp. "You'd like that, wouldn't ya?" Okay, okay, let me teach you a bit.</para>
39 <para>Language syntax is (nearly) always best consumable when demonstrated on an example, like so:
40 <programlisting>(supertux-lisp-example
41     ; This is a comment. It is initiated by a semi-colon. (Yes, you un-believer.)
42     (some-integer 120)      ; Integer values are simple to input and to understand.
43     (floaty-float 58.5)     ; Floating-point numbers should be self-explanatory too.
44     (string-thong "omg")    ; Strings are simple and C-like.
45     (intl-string _("wtf"))  ; Internationalised strings are implemented not unlike in C.
46     (boo-bool #t)           ; That's a "true"...
47     (second-bool #f)        ; ... and that's a "false". (Well duh.)
48     (integer-list 10 20 30) ; A list of integers, much like an array.
49 )  ; Don't forget the closing bracket!!!
50 </programlisting>
51 </para>
52 </sect2>
53
54 </sect1>
55
56 <sect1><title>Level Files</title>
57 <para>The level format is a bit complex, which is why <ulink url="http://flexlay.berlios.de/">Flexlay</ulink> can prove itself very useful as an editor. If you are interested in how the levels look like or want to edit them manually (and find some of the parameters not self-explanatory enough), then you may read or skim through this section.
58 <programlisting>;; Generated by Flexlay Editor (or Emacs or Vi or whatever)
59 (supertux-level                      ;; This initiates a level.
60
61   (version 2)                        ;; This document only describes version 2. Version 1 is deprecated
62                                      ;; and I'm not going to teach it since it lacks a lot of features.
63
64   (name _("Some demo level"))        ;; Name of the level. Call it a nice name. Note that this should be
65                                      ;; internationalised (that's why the extra underscore and brackets).
66
67   (author "Ondra Hosek")             ;; Put your name here unless you are me (very improbable)
68
69   (sector                            ;; A level is divided into independent sectors that can be connected
70                                      ;; by doors.
71
72     (name "main")                    ;; Tux begins in the sector named "main".
73
74     (music "Ondras_chipdisko.mod")   ;; Name of the music file. See the data/music/ directory.
75     
76     (gravity 10.0)                   ;; Gravity of Tux. 10.0 is the default and sanest value (unless you
77                                      ;; apply the level design correctly).
78     
79     (tilemap                         ;; Here come the files.
80       (layer  "background"           ;; Currently, there are three layer types: "background",
81                                      ;; "interactive" and "foreground".
82
83       (solid  #f)                    ;; Will Tux collide with tiles in this tilemap?
84       
85       (speed  1.0)                   ;; If the tilemap is solid, this has to be 1. Basically sets how
86                                      ;; fast the tilemap scrolls.
87       
88       (width  5)                     ;; Number of tiles you plan to put in a row...
89       (height 5)                     ;; ... and in a column. (5x5 is pretty tiny; small Tux
90                                      ;; takes up 1x1 tiles, big Tux 1x2 tiles).
91       
92       (tiles                         ;; Integer lists of which tiles you want to use.
93         0 0 0 0 0                    ;; The tiles and their numbers are defined in
94         0 0 0 0 0                    ;; data/images/tiles.strf.
95         0 0 0 0 0
96         0 0 0 0 0
97         0 0 0 0 0
98       )
99     )
100     (tilemap
101       (layer  "interactive")
102       ;; See the bacgkround layer definition.
103     )
104     (tilemap
105       (layer  "foreground")
106       ;; ...
107     )
108     
109     (camera                          ;; Definitions of the camera paths
110
111       (mode "autoscroll")            ;; This can be set to "normal" to deactivate
112                                      ;; forced scrolling. Then you can omit the
113                                      ;; "path" directive.
114       
115       (path                          ;; Forced scrolling path
116         
117         (point (x 2) (y 3) (speed 2) ;; Point to where camera will scroll.
118           )
119         
120         (point
121           ;; ...
122         )
123       )
124       
125       (backscrolling #f)             ;; You can prevent the camera from scrolling
126                                      ;; backwards with this setting.
127     )
128     
129     (background
130       (image "ocean.jpg")            ;; Background from data/images/background
131       (speed 0.5)                    ;; Scrolling speed
132     )
133     
134     (spawnpoint (name "main") (x 0)  ;; A spawning point for Tux. By default, he is
135       (y 0)                          ;; spawned at spawnpoint named "main".
136     )
137     
138     ;; THE FOLLOWING OBJECTS ARE OPTIONAL.
139     (init-script "
140 // A Squirrel script
141 // See the scripting reference for more information.
142 ")
143
144     ;; Here you can add badguys of your choice.
145     ;; A reference on badguy types and their parameters is a TODO.
146     
147     ;; Particle systems
148     ;; It is advisable only to use one particle system at a time.
149     
150     (particles-&lt;type&gt;          ;; Valid values for &lt;type&gt; are rain, snow and clouds
151     
152       (layer 201)                    ;; -100 are background, 0 are interactive, 200 are foreground tiles.
153                                      ;; Choose a number to put the rain between two layers. In this case,
154                                      ;; the rain is in front of the foreground tiles. (see also
155                                      ;; src/video/drawing_context.hpp)
156     )
157     
158     (leveltime
159     
160       (time 300)                     ;; The player must complete this level
161                                      ;; within 300 seconds.
162     )
163   ) ;; End of sector
164   
165   ;; You can add other sectors here.
166 )
167 ;; End of level</programlisting>
168 </para>
169
170 <sect2><title>Badguys</title>
171 <para>This section describes the various badguys and their parameters.</para>
172
173 <sect3><title>Common parameters</title>
174 <para><programlisting>(&lt;badguy-name&gt;
175   (x 270)                 ;; The badguy's X coordinate.
176   (y 126)                 ;; The badguy's Y coordinate. (Note that the origin is in the top-left corner!)
177   (stay-on-platform #f)   ;; Optional. Should the badguy do its best not to fall from the platform it's on? (NYI)
178 )
179 </programlisting></para>
180 <para>Bouncing Snowballs, Flying Snowballs, Jumpies, Mr Bombs, Mr Iceblocks, Mr Rockets, Mr Trees, World 1 Noloks, Poison Ivies, Snowballs, Spikies, Stalactites, Yeti Stalactites and Zeeklings only require this list of parameters. Simply substitute <code>&lt;badguy-name&gt;</code> with one of the following:
181 <itemizedlist>
182 <listitem><code>bouncingsnowball</code></listitem>
183 <listitem><code>flyingsnowball</code></listitem>
184 <listitem><code>jumpy</code></listitem>
185 <listitem><code>mrbomb</code></listitem>
186 <listitem><code>mriceblock</code></listitem>
187 <listitem><code>mrrocket</code></listitem>
188 <listitem><code>mrtree</code></listitem>
189 <listitem><code>nolok_01</code></listitem>
190 <listitem><code>poisonivy</code></listitem>
191 <listitem><code>snowball</code></listitem>
192 <listitem><code>spiky</code></listitem>
193 <listitem><code>stalactite</code></listitem>
194 <listitem><code>yeti_stalactite</code></listitem>
195 <listitem><code>zeekling</code></listitem>
196 </itemizedlist></para>
197 </sect3>
198
199 <para>The next few sections describe the extra parameters for the other badguys.</para>
200
201 <sect3><title>Dispenser</title>
202 <para><programlisting>(dispenser
203   (cycle 3)               ;; How often should a badguy be dispensed?
204   
205   (badguy random)         ;; Valid values are "snowball", "bouncingsnowball", "mrbomb",
206                           ;; "mriceblock", "mrrocket", "poisonivy" or "random".
207 )</programlisting></para>
208 </sect3>
209
210 <sect3><title>Flame</title>
211 <para><programlisting>(flame
212   (radius 3)              ;; How big should the radius of the circle be that the flame
213                           ;; follows?
214   
215   (speed 10)              ;; How fast should the flame be?
216 )</programlisting></para>
217 </sect3>
218
219 <sect3><title>Lightning orb</title>
220 <para>The lighting orb ("kugelblitz") ignores the <code>y</code> coordinate, spawning above the visible screen.</para>
221 </sect3>
222
223 <sect3><title>Spike</title>
224 <para>Don't mistake this badguy for Spiky! Spiky is the snowball-like creature with spikes, whilst a spike is an object serving the same purpose like the stalactite.</para>
225 <para><programlisting>(spike
226   (direction 2)           ;; 0: north, 1: south, 2: west, 3: east
227 )</programlisting></para>
228 </sect3>
229
230 <sect3><title>Yeti</title>
231 <para><programlisting>(yeti
232   (dead-script "
233 // A squirrel script that is executed once the Yeti dies.
234 ")
235 )</programlisting></para>
236 </sect3>
237
238 </sect2>
239
240 </sect1>
241
242 <sect1><title>Scrolling texts</title>
243 <para>Scrolling texts are used for the credits and were used for the intro and extro in Milestone 1. The format is simple:
244 <programlisting>(supertux-text
245   (background "extro.jpg") ; Background image (see data/images/background)
246   
247   (speed 1.5)             ;; Default speed of text
248   
249   ;; Here we demonstrate the formatting characters
250   (text _("
251
252 -This is a heading
253 &lt;tab&gt;This is a normal line.
254  This is a line in a small font.
255 #This is a left-aligned line.
256 *This should be printed in a blue font.
257 !Filename of the picture to be embedded into the scrolling text (relative to scrolltext file path)
258
259 ")
260   )
261 )</programlisting>
262 </para>
263
264 </sect1>
265
266 <sect1><title>Worldmaps</title>
267 <para>Worldmaps are basically level files with a few nuances. To explain the syntax, let's just picture somebody with the idea to write a level set that takes place in London (represented by a lonely island):
268 <programlisting>(supertux-worldmap
269   (properties                               ;; Global worldmap properties.
270     (name (_ "London"))                     ;; Name of the worldmap
271     (music "bigben.ogg")                    ;; Music to be played while on worldmap
272   )
273   (spawnpoint                               ;; At the moment, defining multiple spawnpoints on a worldmap is useless.
274     (name "main")                           ;; Call your spawn point "main".
275     (x 3)                                   ;; Note that the coordinates are, unlike in a level, bound to the tilemap.
276     (y 3)
277   )
278   (tilemap
279     (width 5)                               ;; Number of tiles in a row. Four is just for demonstrational purposes.
280     (height 5)
281     (layer "interactive")                   ;; This has to be "interactive".
282     (solid #t)                              ;; This has to be true.
283     (speed 1.000000)                        ;; This has to be 1.0.
284     (tiles
285       0  0  0  0  0                         ;; The tiles as defined in data/images/worldmap.strf.
286       0  11 16 12 0
287       0  15 60 17 0
288       0  14 18 13 0
289       0  0  0  0  0
290     )
291   )
292   (level                                  ;; Repeat this block for each level. Continuing from a level tile is only possible when the level is completed.
293     (x 3)                                 ;; Coordinates of the level entry point.
294     (y 3)
295     (name "heathrow.stl")                 ;; Filename of the level, relative to the location of the worldmap file.
296     (extro-script "
297 // A Squirrel script to execute once this level is completed.
298     ")
299   )
300   (special-tile                           ;; This is a sample message tile.
301     (x 4)
302     (y 3)
303     (map-message (_ "Hello."))            ;; Display the following text when Tux steps on this tile.
304     (passive-message #t)                  ;; Set to #f to stop Tux when he steps on this tile.
305     (apply-to-direction "north-west")     ;; The message is displayed only when Tux comes from one of the specified directions (north, south, west, east, concatenate with a hyphen).
306   )
307   (special-tile                           ;; This is a sample portal tile.
308     (x 2)
309     (y 3)
310     (map-message (_ "Warp to the Tower"))
311     (teleport-to-x 1)                     ;; Worldmap coordinates to which Tux is teleported.
312     (teleport-to-y 1)
313   )
314 )</programlisting></para>
315
316 </sect1>
317
318 <sect1><title>Level subsets</title>
319 <para>Whilst creating a worldmap is optional, you'll need to write a level subset file to make your level package to appear in the contribs menu (or, ironically, inhibiting this behaviour). A file containing a level subset is called <code>info</code> and lies in <code>data/levels/&lt;subset_name&gt;.</code>
320 <programlisting>(supertux-level-subset
321   (title "Domain of the Hosek siblings")                        ;; Give your levelset a nice name...
322   (description "Levels by Ondra and Klara, the Hosek siblings") ;; ... and a short description.
323   (hide-from-contribs #f)                                       ;; Set to true if you don't want your levelset to appear in the "Contrib Levels" menu.
324 )</programlisting></para>
325 </sect1>
326
327 <!--
328
329 TODO:
330 * Sprite definitions
331 * Tile definitions
332
333 -->
334
335 </article>