The driver file
To keep things simple, we'll divide the whole world up into several files. First, we need the main file (which is loaded into WissenSchaf(f)t? as the world), which we'll call the driver. I call the file index.txt.
I'll discuss the driver part by part.
As we'll use a lot of classes from the package net.daniel_kraft.wissenSchafft.standard in the future, and I don't like it being typing this name all the time, we can - similiar to the Java language - import this package:
/* I suppose this package will be used frequently. */ imports: net.daniel_kraft.wissenSchafft.standard
C/C++ style comments are allowed anywhere in a world file.
I don't like hard-coding any translateable strings into my code, which is true for WissenSchaf(f)t? worlds, too. Using string resources we can move them all to a separate file. First, create it (at Lang/en.txt):
// Standard-components (DialogBox) in English #../../../Sprachen/std-en.txt
As we (at this point) don't need any strings so far, we just include those for the standard-components. Inclusion is done by the # character followed by the filename on a single line. The file included here is part of WissenSchaf(f)t?.
Now, we include the new file into the driver using the same syntax:
/* Include resources for internationalized strings. */ strings: #Lang/en.txt
Objects: Avatar and Control
You also need to tell WissenSchaf(f)t? which object to use as avatar (which represents the user in the game and is capable of moving around) and control (which processes user inputs and moves the avatar respectively). Those are components which can be programmed freely in Java, but in most cases you will be completly satisfied with the predefined solutions we'll use here:
/* Needed objects: Avatar, Control. */ objekte: Avatar = DG_Avatar("Images/AvatarN.png", "Images/AvatarE.png", "Images/AvatarS.png", "Images/AvatarW.png", 4, W) Steuerung = DG_Steuer
As you can see, we use an object of type DG_Avatar (in the package net.daniel_kraft.wissenSchafft.standard) as avatar. The parameters specify the images to use when the avatar "is looking" upwards, to the right, downwards and to the left. Then, you specify the number of fields which are visible to the user in each of those directions, and the direction, the avatar is looking at the beginning of the game: N for north, O for east, S for south or W for west.
As control we use DG_Steuer (also part of net.daniel_kraft.wissenSchafft.standard), which perfectly fits together with DG_Avatar and allows the user to move or turn in any of the four main directions.
A map consists of several fields, which are instances of prototypes; this way it is possible to save lots of resources, as those instances, for instance, of empty fields, which need not to do anything complicated, can share their image data. Also, this way you just once specify what such a field should look like, and reference this definition whereever needed.
As most of the fields needed will either be empty (just gras) or obstacles (walls), we'll define those two prototypes here:
/* General prototypes */ prototypen: // Empty field, just gras e = FreiesFeld("Images/Empty.png") // Wall w = Hindernis("Images/Bricks.png")
Like the former definitions, we generate objects of predefined component classes, part of net.daniel_kraft.wissenSchafft.standard: FreiesFeld, which generates an empty field, and Hindernis, which means an obstacle. The parameter is the image to be drawn in place of such fields. Optionally, one could pass a second parameter, which is a background image (when you need to compose, for example, a rock in front of gras).
At this point in the file, we'll incrementally add lines including the different maps later. As we currently don't have any maps, there's no code here at the moment.
The last thing to define is the point where the avatar should be located at the start of the game. This has to be placed at the end of the world, as we'll refer a named coordinate, which has to be definied earlier (and which will defined in one of the maps, included prior to this code):
/* Last-but-not-least: Where to start? */ variablen: Start = start
This code sets the starting position to the coordinate named start (not Start, which tells the processor to set the starting position!).