![]() |
![]() |
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: 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%. 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. Our First Program: Simply enter the following program and save it as: “...Projects/MyProjects/HelloWorld.src”. and select ‘Compiler/Compile’ and then ‘Compiler/Run’. //////////////
// Mein erstes Programm 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; looks like this then: a=5; 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: 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. There are some special functions in DiNGS that work different to the rest.: Attention!
LET a=COS(30)/1000*5; // ERROR: 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. LET a$="My";
Output: LET levelnumber=5; // This happens somewhere in the game... 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 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"; 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; 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. DIM checker[8][8]; The computer will allocate memory to store an 8x8 array and set each field to 0. 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. LET x=2; Output:
because you wrote it there before. Attention:
Arrays may not have more than 8 dimensions. Data arrays can be made of words, too Jumpmarks: Problem: The program runs once and then exits. Solution: We let the program jump to the start: 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 Output: 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). 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? 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: Now we fill an 100x100 array with 1. FOR x=0 TO 99; 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; 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 Or a number from 0 to 10, but not the 5! 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:
A little test that will prepare you for the next chapter: Class: Output e.g. Sabine Tips:
|