http://alpha-thema-online.uv.ro
Fa-ti si tu propriul forum, pe www.myforum.ro!
Pagina de start a forumului http://alpha-thema-online.uv.ro Autentificare Inregistrare FAQ Membri Cautare

Pagina de start a forumului http://alpha-thema-online.uv.ro » Tutoriale EN » Variables , Instructions
Creaza un subiect nou  Raspunde la subiect Subiectul anterior :: Subiectul urmator 
Variables , Instructions
MesajTrimis: 21/07/2007 22:45 Raspunde cu citat (quote)
Ad_Infinitum
Administrator
Administrator
Ad_Infinitum
Data inscrierii: 23/Iun/2007
Mesaje: 212




Dark basic Tutorial
Tobi - 2002



Introduction


This is an introduction into programming with Dark basic. In the Internet a 30-Tage-Trial-Version is available free of charge for the Download. For progressing this Tutorial is expressly suitable, since it concerns itself only with the 2D functions of Dark basic. It is recommended much to try the examples out mentioned themselves to try and also calmly times „on own fist “something. But not directly it despair if it does not function at first attempt that is completely normally. If you have questions, which are not answered in the text, you can send email to me to klein_tobi2@web.de.
If you have an error in one of your source codes and him do not find, you can send him to me gladly times, and I look him after errors through. No concern, I can abuse it not „“, because I have as so no more compiler. My Trialversion ran off, and I do not have desire to spend the 75$ on the full version.
It offers the possibilities, the one programming language such as Dark basic is so various that it is not possible to specify here all. I recommend to leaf therefore simply times through the index of the instructions and to look at themselves the interesting things once more exactly. However you should begin the 3D with instructions only if you well controls the 2D instruction, or a better Tutorial found; -).





Chapter 1 dissolution specify


At the beginning of each program the dissolution must be specified as the depth of shade in bits. In Dark basic one can settle both with only one instruction (usually to have these attitudes during the program sequence not to be no more changed).
This instruction is called set display mode. After the instruction parameters must follow 3. Indeed 2 for the dissolution and one for the depth of shade. The parameters are separated with commas from each other.


set display mode 640,480,16


That would be a dissolution of 640*480 pixel and 16 bits depth of shade.






Chapter 2 variables


Variable ones should most from mathematics instruction admit to be. There they are substitute symbols for still unknown numbers. In Dark basic and in so rather all other programming languages also, variables are substitute symbols for numbers likewise, however white the computer at each time which value the variable has (in some programming languages e.g. C/C++ is this not always like that). But a variable can do still much more, it can not only numbers but also letters, individual words or whole sentences and/or texts store. The only problem is that one says to the computer „“must which kind of variable one means. In Dark basic gives it to 3 different types of variables, which are marked by a symbol after their name:



Type symbol example
Text character (stringer) $ a$
Integers (Integer) &a
Comma numbers (float) of # a#



If one a symbol does not indicate treats the computer the variable like an integer.
In order to assign variable a value, one writes the value behind an equals sign.


a=10
b#=0.123
c$= “Hello World “


the variable A b# the value 0.123 and the variable c$ the value Hello World assigns the value 10, the variable. If one liked to assign variable a stringer, one must write the stringer in quotation marks. With comma numbers one must pay attention to always set in place of the comma one point.





Chapter 3 operators


The most well-known operators (and the only one, whom we will treat here) are rakes, and comparison operators.


Type operator action example
Computing operator + add a+b
Computing operator - subtract A-B
Computing operator * multiply a*b
Computing operator/divide a/b
Comparison operator = is alike a=b
Comparison operator < is smaller than a<b
Comparison operator > is larger than a>b


One can use these operators except with Integervariablen also still with floating variables or directly with numbers. More to it stands in chapter 5.






Chapter 4 the instruction print


The simplest instruction, in order to spend something on the screen, is print.
As print one can spend all types of variables, or indicate directly one.



a$= “Hello World “
print a$


is the same how


print “Hello World “


Functions naturally also with numbers:


a=2
print A


or


print 2












Chapter 5 use of the computing operators



One can spend the result of a calculation in two kinds.
1. into variable
2. directly on the screen spend


a=1
b=2
c=a+b
print C


is thus the same how


a=1
b=2
print a+b


or still more simply


print 1+2







Chapter 6 inputs


A program does not make (too mindest for beginners) a sense, if the user cannot make inputs and affect thus the expiration of the program.
The simplest instruction (however as you will see later with very large disadvantages) is input.
2 parameters must follow this instruction. A stringer, on the screen is spent around the user about the fact to inform that it must enter something, and a variable, in which the input is stored. One should pay attention absolutely to use the correct type. If one selects for example as type Integer, the user can enter only to numbers (that is also well like that, because letters would cause an error). However the user can also then to numbers enter, if you selected a stringer as type, only to become these numbers then as text treated (one cannot expect thus them).


input „as is called you? “, name$
print „hello “, name$


asks the user for his name, and welcomes it.


input „as is called you? “, name$
print „hello “, name$
input „are as old you? “, older
differenz=alter-15
print „you is older “, difference, “years than I. “


As you saw by the two upper examples, it is possible to spend several variables or direct text and/or numbers one behind the other. Here one must pay attention only to separate the variables by a comma from each other to.





Chapter 7 conditions


One needs „if instructions “, if one wants to indicate instructions, which are implemented only if a certain condition is true. Such „if instruction “is if… then… after if stands the condition, and after the then stands an instruction, which is to be implemented, if the condition is true. One can indicate also several instructions, which is to be implemented, if the condition is correct, and several instructions, which are to be implemented, if the condition does not apply.
then one writes
if condition
Instructions if true
else
Instructions if not true
endif


endif one may not forget, otherwise there is an error and the program cannot not be implemented!




input „are as old you? “, older
if alter>15
print „you is older than I! “
else print „you is younger or just as old as I! “


One can indicate also several conditions. One must connect those then with and, or or xor. With and both conditions must be fulfilled, with or must at least one be fulfilled and xor may only one be fulfilled (if both conditions are true, count them as wrong).



Chapter 8 loops


A loop is realms of instructions, which are to be implemented again and again, until a condition is true, or also always.
In Dark basic gives it to three different loops.
The simplest is DO… loop. It leads all instructions, those within the loop (thus between DO and loop) always stands. The only possibility of terminating it nevertheless is the instruction exit. It terminates the current loop, all the same which kind.
One can specify also exactly how often a loop continuously is. Then one uses for the I=eine number of ton a number of steps of steps… NEXT I quilts gives in which steps to be counted on is. If one quilt omits, in steps one counts automatically. Instead of I one can take also any other variable (only one should not take, which has already a certain value).
An example:


for I=1 ton of 5
print „Hello World “
NEXT I


this program writes Hello World to 4mal (1-5) on the screen. The third kind of loops is a loop, which is so often implemented, until a condition is fulfilled. It is called repeat ...... until condition for example:


a=1
repeat
print A
a=a+1
until a=10


All numbers of 1-10 are spent. Naturally one could have made also with one for NEXT loop for tons, but no better example occurred to me.






Chapter 9 simple diagram instructions


The most important diagram instruction, is ink. With ink the color for the foreground and the color for the background specifies. That is however not so simple, because one must mix the desired color from its red, green and blue values. In order to test, how a mixture looks, you can use the small program „Farbtester.exe “(as you see basic written with the demo version of Dark).
I listed the usually used colors times:



Color red value green value blue value
Red 255 0 0
Green 0,255 0
Blue 0 0 255
Yellow 150,150 0
White 255,255,255
Black 0 0 0
Brown 100 50 50



ink rgb (0,0,255), rgb (0,0,0)


That sets the foreground color on blue and the background colour on black. In order to delete the screen to thus over-paint (everything with the background colour) one uses the instruction cls.





Chapter 10 simple indication instructions


There are the following indication instructions, in order to draw something on the screen:


Instruction action parameter
DOT draws one point x, y
box draws a rectangle left, above, right, down
LINE draws a line left, above, right, down
circle draws a circle xmitte, ymitte, for radius


It gives still another few more instructions, but this are the most important. We look at ourselves the instructions times more exactly.
DOT draws only one pixels in the current foreground color. One must indicate only the coordinates. On the left of above in the corner the coordinates are always 0,0. In the case of a dissolution of 640*480 the coordinates of the right lower corner are 640.480, with 1024*768 are 1024.768 etc.
With the instruction box one needs already 4 coordinates. First the two stand for rear both for the left upper corner of the rectangle, for the right lower corner of the rectangle.
With the instruction LINE is întocmai it that same, only that a line between the two points is drawn here and no rectangle.
Circle needs the coordinates of the center and the radius (in pixels).


box 0,0,40,40


for example a square draws into the left upper corner.







Chapter 11 mouse control and functions


For the mouse control one needs three new instructions:


mousex ()
mousey ()
mouseclick ()


The new at these instructions are the clips at the end. They signal, which concerns it a function here. Functions always spend a value.
mousex () the current x-value of the pointer of mouse, mousey () spends the y-value and mouseclick () spends a 1 spends, if the left mouse button is pressed, and 2, if the right mouse button is pressed. One needs conditions over to test whether the user somewhat clicked, and over to specify which is to then happen.


box 0,0,40,40
if mousex () >-1 and mousey () >-1 and mousex ()<41 and="" mousey=""> print „you clicked on the box! “
print „Du hast auf die box geklickt!“
endif





Chapter 12 extended text edition


For the text edition on the screen you used so far the instruction print. It has the advantage, whom it needs very few parameters, in addition can it not only stringer, but also Integer and floats spends. In addition, it has a few disadvantages, which in the first programs, which we did not write so far yet to have disturbed, but with larger more beautiful programs quite nerves can. print can spend only in a certain character size and only in a certain character font. Therefore it is so well never used by advanced programmers (and I am sure to become that it your goal in such a way one). The instruction text does not have these disadvantages.
It is somewhat more complicated for it because it is to spend still two further parameters necessarily, which indicate where the text are spent except the text, it. In addition text can spend only stringers and no numbers. If one liked to spend numbers nevertheless, one must convert these before into stringers. As goes experience you somewhat later.


text 0.0, “Hello World “


Hello World in the left upper corner in current character size and the current character font spends the text.
Around character size to change one uses the instruction set text size.
Behind it character size comes.
In order to change the character font, one uses the instruction set text font „character font “
An example:


set text font „Comic Sans ms “
set text size 48
text 0.0, “Hello World “




Chapter 13 additional functions


You know already the functions for the indication of the mouse status, but there is still another number of other functions, and you can be written even own (as goes must you in the assistance of Dark basic reread, since that is quite complicated, and this Tutorial for all to be understandable is).


Name function
strg$ (Integer or float) a number converts into a stringer
rnd (maximum number) a random number between 0 and the maximum number spends
GET DATE () spends the date (from the system clock)
GET time () spends the time
timer () spends the system clock in milliseconds


With the instruction randomize one gives the seed number for the random number generator (rnd ()) on.
If one does not indicate a seed number for the random number generator, spends this coincidental numbers, but those are then alike with each program sequence. Thus one must find a way, as indicate one for each program start another seed number can without specially each mark the source code change. The best solution is, which one the number, which spends the function timer () with the program start as seed number used. That looks then in such a way:


more randomize=timer ()





Chapter 14 extended input


So far you know the instruction input to the input by the keyboard only. To and for itself this instruction is very well (simply) however it has a very large disadvantage, because it blocks the entire program sequence until the user of the program confirmed its input with the RETURN key (those presents times a Actionspiel, in which the opponents wait to you move!).
There is however a set of instructions, which do not have this disadvantage.
leftkey ()
right key ()
space key ()
returnkey ()
escape key ()
upkey ()
down key ()
inkey (scancode)


as you see, it concerns functions. Leftkey () spends 1, if the arrow key is pressed to the left, space key () with the space bar an etc.
inkey (scancode) one uses, if one liked to query keys, which do not have an own instruction. For this one needs the Scancode of the key. It orients itself at the position of the key on the keyboard (could be thus abroad different!).
I listed the Scancodes of the most important keys of a German keyboard.


F1=59
a=30 s=31 d=32 w=17
1=2 2=3 etc. 0=11
strg links=29
strg rechts=157
alt=56
altGr=184


So now you have enough foreknowledge, in order to write and to you still more teach funny 2D of plays. I hope you everything understood, otherwise I am available however for questions.
Vezi profilul utilizatorului Trimite mesaj privat

Variables , Instructions
 Pagina de start a forumului http://alpha-thema-online.uv.ro » Tutoriale EN
Nu puteti crea un subiect nou in acest forum
Nu puteti raspunde in subiectele acestui forum
Nu puteti modifica mesajele proprii din acest forum
Nu puteti sterge mesajele proprii din acest forum
Nu puteti vota in chestionarele din acest forum
Ora este GMT + 3 ore  
Pagina 1 din 1  

  
  
 Creaza un subiect nou  Raspunde la subiect  


Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
    Powered by phpBB © 2001-2004 phpBB Group. phpBB Skin by Vjacheslav Trushkin.