Common

Hi and wellcome to DiNGS, your new programming lanuage.

Here you will learn how to permute your idea into a running game. One word in anticipation: DiNGS cannot do woders. It has its strenghts and weaknesses. If you want to program 3D games, take the next 2 years and don’t do anything but learing C++. But you can develop games that will have the level of NintendoFamicom(tm)(c), SEGA MegaDrive (tm)(r) or the good old Amiga500(tm)(c). DiNGS does sprite rotations, alpha blending and zooming with a smile. (If you don’t understand this, it’ll be explained later). To reach a stable framerate, DiNGS will be slowed down to a certain rate of frames per second.

Chapter 1: The Basics.

A program principally can do nearly nothing. And that’s the difficult thing about programming. Programms only can:
-Declare variables
-Make jumps to other program parts
-Operate with variables
-Transfer vasrialbes to functions

The Basics of DiNGS:

DiNGS is a programming language. Even if a very simple one. They have their own syntax. If you don’t keep it 100% it will understand you 0%.
DiNGS finishes every command with a ‘;’ (semocolon) or a new line.

All commands in DiNGS must be written in capital letters. The editor will do this automatically.

Every letter right of a ‘//’ or the command REM will be seen as a comment to the code and will not be evaluated when compiling.
DiNGS uses hidden surfaces for graphic display. If you code something in DiNGS you will see nothing before calling ‘SHOWSCREEN’. This command makes the currently used surface, the back buffer, visible and erases the new back buffer with a loaded image or black if no image was loaded. So, if you don’t see any result, think if you forgot ‘SHOWSCREEN’.

Our First Program:

Simply enter the following program and save it as: “...Projects/MyProjects/HelloWorld.src”. and select ‘Compiler/Compile’ and then ‘Compiler/Run’.

//////////////
// HELLO WORLD
//////////////

// Mein erstes Programm
PRINT "HELLO WORLD!" ,100,100;
SHOWSCREEN;
MOUSEWAIT
END;

You should see a black screen with “HELLO WORLD” printed on. After clicking the mouse button the program will exit. Now you made your first step into your new world.

Enough, lets start with the simplest thing: Declaring variables.

There’s 2 types of variables in DiNGS. Numbers and words. Variables can be seen as desk-drawers. On front of the drawer there’s the name of the variable and inside you’ll find the value of the variable. Let’s start with numbers and see what can be done.

Numbers

LET a=5;

We call the command LET and tell it we’d like to have a variable called ‘a’ that has the value 5.

To make it somewhat faster, LET can be left away. The line would look like this:

a=5;

and

LET a=5;
LET a=a+1;

looks like this then:

a=5;
a=a+1;

What are we doing here? Well, we say the variable with the name ‘a’ should have the value ‘a+1’. ‘a’ was set to 5 before, so a will be ‘5+1’ = 6. There’s other operations that can be done with numbers. DiNGS knows the following:
+, -, *, /; (Addition, Subtraction, Multiplication, Division)

ATTENTION:

LET a= 3+4*5; would be 3+(4*5) = 23. BUT NOT IN DiNGS!! This would be 35! (3+4 = 7 and this *5 = 35!). DiNGS evaluates mathematic expressions in the way it was written.

You can go around this if you don’t like it by writing code the way it does not matter. Or add some brackets to make it sure. But inside brackets terms will be evaluated from left to right, also:
LET a= 4*5 +3;
LET a=3+(4*5); // This would be right then
 

There are some special functions in DiNGS that work different to the rest.:
SIN(), COS(), TAN(), RND(), KEY()
These functions return a value. Good so far. Problem: DiNGS works with integers, so the functions SIN(), COS() and TAN() return 1000x the value of the mathematic functions. The argument (what you feed the function with) is an angle in DEG-Mode(0-360°)

LET a=100*COS(30)/100; // Von links nach rechts wird gerechnet

Attention!

LET a=COS(30)/1000*5; // ERROR:
This line will be interpreted as: Set a with cosinus of 30°, divide it by 100 (=0) and multiply it with 5. But COS(30) =700~ And 700/1000 = 0.

The command RND() returns a random number in the range of 0 and the argument.

LET a=RND(50); // a= random number from 0 to 50

Words:

Words differ in their variables name by an added ‘$’ at the end. Numbers can be easily converted into words and vice versa if possible. Later more in an example.
Sample.
LET a$="HELLO";
As seen above, we set the value of the variable with the name ‘a$’ to “HELLO”. Words that are static, meaning no variables, are seperated with “ ” to have them distinguished from variable names.
The command LET offers some nice functions with words.

LET a$="My";
LET b$="favourite number:";
LET c= 7;
// Now look!!
LET c$=a$ + " " + b$ + " : " + c;
PRINT c$,0,20;
SHOWSCREEN;

Output:
My favourit number: 7
The ‘LET’ command can be left in this case, too. So you see, numbers can be converted to words like this: c$=c and words can be linked together like this: a$=a$+b$. So what? Assume a game, you want to load a level from a file. The level = 5 and the level file’s name is “Level5.dat”. What to do is the following lines:

LET levelnumber=5; // This happens somewhere in the game...
LET level$="Level" + levelnumber + ".dat";

DiNGS offers some special functions for handling words.

INPUT name$, x, y;

At the position x, y a blinking carret will appear and wait for the player to input a word. After hitting ‘Return’ the varaible name$ will contain the entered word. This works with numbers, too

(
INPUT zahl, x,y;)

MIDSTR source$, aim$, start, length;

This command copies sub word out of words. The word aim$ will contain the sub word of source$ starting with ‘start’ and the length ‘length’. The index of the first letter is 0.

Sample:

name$="My house is blue";
MIDSTR name$, mid$, 3, 5;
PRINT mid$ , 20, 20;
SHOWSCREEN;

Output:

house

You can trim the names of a highscore list e.g. to 7 latters by simply copying the first 7 letters in a sub word.

INPUT enter$, 100, 100;
MIDSTR enter$, name$, 0, 7;

Data Arrays:

Now you have an overview of varialbes. But how would you store a playfield with this knowledge? Right! Not at all. For this you use arrays.
An array can be imagined as a checkerboard. It’s 8 fields in x-dimension and 8 fields in y-dimension. In DiNGS you define an array like this:

DIM checker[8][8];

The computer will allocate memory to store an 8x8 array and set each field to 0.
If we want the field 3 right, 4 down to have the value 7, we would write this:

LET schachbrett[2][3]=7;

Why 2 and not 3? Because the first index=0. 0,1,2,3,4,5,6,7 are 8 fields. This is somewhat confusing at the beginning, but you’ll get used to it very soon.
You also can call an array’s field also via variables:

LET x=2;
LET y=6;
LET a=checker[x][y];
PRINT "Checkerboard[2][6] has the value:", 100, 80;
PRINT a, 100, 100;

Output:
Checkerboard[2][6] has the value:
7

because you wrote it there before.

Attention:

Arrays may not have more than 8 dimensions.
DIM a[1][2][3][4][5][6][7][8]; // just OK
 

Data arrays can be made of words, too
Samples:
DIM space[10][10][10]; // A space with x, y and z
                      // each 10 fields (0-9)
DIM name$[5]; // 5 Words
LET name$[0]="Hugo";
LET name$[1]="Tim";
DIM cinemavisitor$[30][10];
LET cinemavisitor$[seat][row]="Tom";

Jumpmarks:

Problem: The program runs once and then exits. Solution: We let the program jump to the start:
Sample:
// A GOTO sample
beginning:
LET a=RND(600);
LET b=RND(400);
PRINT "Wow",a ,b;
SHOWSCREEN;
MOUSEWAIT;
GOTO beginning;

What is this doing? It’s defining a jump-mark with the name ‘beginning’, Prints “Wow” to a random position and shows this until the mouse button is triggered. Then the program jumps to the ‘beginning’. To end the whole thing push the “ESC” key. Keep this in mind. Pushing ESC will exit your program whenever you want to.

Knowing this a lot can be done. If you want to write some code that can be jumped to from anywhere, but should return to the position where it was called from you have to use another command. GOSUB.

To define a SUB check the menu command ‘Project/New SUB’ and use this wizzard to create a new SUB in your project.

 

A sample:

// A GOSUB Sample
PRINT "Start",0,0;
GOSUB middle;
PRINT "End",0 ,30;
END;

// A SUB Function called ‘middle’
SUB middle:
  PRINT "Middle",0,20;
  RETURN; // Jumps back to call if wanted
ENDSUB    // End of Sub->Return to call

Output:
Start
Middle
End

A good example of a SUB would be a function for loading a level of a game. So this function can be called from the main game and from the editor. Or a SUB that that handles a dead player. This can be called from anywhere the player may die in the game...

Attention:

SUBs are always placed at the end of the main program. Between the commands ENDSUB and SUB no code is allowed. (Only comments).
You are not allowed to call GOTO to a jump mark not inside the SUB you call from, nor are you allowed to call a GOTO from the main program to a jump mark inside a SUB.

FOR-Loops:

Assuming you want to fill an array with ‘1’, how long would this take to code when the array is 10 fields width?
Not long:
FOR x=0 TO 9;
  LET array[x]=1;
NEXT;

The code between FOR and NEXT is evaluated as long as x>9. After each call of NEXT x will be increased by 1. Too complicated? Again:
FOR x=0 TO 9;
There’s a variable called x with the value of 0. The following code is to be repeated until x is bigger than 9.
LET array[x]=1;
The array ‘array’ is filled at the index ‘x’ with the value of 1.
NEXT;
x is increased by 1. The code between FOR and NEXT is repeated.

Now we fill an 100x100 array with 1.

FOR x=0 TO 99;
  FOR y=0 TO 99;
    LET array[x][y]=1;
  NEXT;
NEXT;

This can be done backwards or in differrent steps, as well. With the command STEP you can set a step that will be added / subtracted with every call to NEXT.

FOR x=24 TO 0 STEP -5;
  PRINT x, 0, (x*20);
NEXT;

WHILE-Loops:

A WHILE loop will be evaluated as long as its argument is FALSE. We want to have a random number from 3 to 10. Now we have a random number from 0 to 10 and repeat the code as long as the number is bigger than 3.

LET z=0     // z starts < 3, otherwise WHILE loop
            // won’t be evaluated!
WHILE z<3   // As long as z is < 3,
  z=RND(10) // z is a random number from 0-10
WEND        // Repeat.

Or a number from 0 to 10, but not the 5!
LET z=5     // z=5, otherwise WHILE loop fails
WHILE z=5   // As long as z=5
  z=RND(10) // z is a random number from 0-10
WEND        // Repeat.

By the way, random numbers from 3 to 10 are better calculated this way:

z=RND(7)+3; // (0 to 7) +3 = (3 to 10)

Test:

So. Enough with the basics. You also learned the command PRINT. Here the syntax again:
PRINT [NUMBER/WORD], X-Pixel to the right, Y-Pixel towards the bottom;

A little test that will prepare you for the next chapter:
You are a teacher. and your class has 4 pupils (2 rows, 2 coloumns). Since you are such a nice teacher, you want to have a computer program that does choose a pupil to be asked for today. The program should give the name and the sitting position of the pupil printed to the screen.

Class:
           Col0     Col1
Row0  Tom     Markus
Row1  Sabine  Manuela

Output e.g.

Sabine
sitting in:
Row 1
Col   0

Tips:
-If you don’t change the standart font, the chars are 16x16 pixels each.
-A random number will be returned by the function RND(maximum). (Take a look back top)