Ask a question »

Introduction to Dark Basic

July 2015

Dark Basic is a programming language that is structured on BASICwhich allows users to create personalized games using object-oriented programming language. It can also be used to create demos, slideshows or other business applications. Dark Basic being an object-oriented program is easier to learn for novices as well. It provides many features like automated double buffering, mouse, keyboard and gaming controller input, video animation control, audio control, fast pixel perfect collision, full model manipulation, super-fast 2D blitting, file handling, system handling, 2D drawing , ambient lighting, directional lighting etc...just to name a few.


What is Dark Basic?


Dark Basic is an object-oriented programming language that allows you to create and personalize games, slideshows or other applications. You don't need to be an expert in software programming to be able to understand and use Dark Basic as it is provided with a set of simple commands, suitable for any beginner.

Dark BASIC also allows you to create your own games, demos, slideshows or business applications based upon the BASIC programming methodology and rest assured a lot of tutorials are available.

You can get a free trial version of the program from the following link: http://darkbasic.thegamecreators.com/

Step 1: how to start?


You will be prompted to enter all the commands in a window in order to create your own environment or whatever game you have in mind. Hence, the first thing required is to know what you want the screen to display. You can use the sample below in order to display a window entitled EDPLN 2 Freeware SE and that will enable your mouse use but disable the ESC key.

set window on    
set window layout 1,1,1    
set window title "System backup copy (1.1)"    
show window    
show mouse    
disable escapekey    
sync on    
gosub start    
end

Step 2: how to create a simple menu?


Creating a simple menu will allow the user to use and go through the program. Hence, you can use the codes below to create a basic menu with the command â€~A' to Save, â€~B' to define a filter, â€~C' to choose a way out of the game or environment and â€~Q' to quit the game.

start:     
rem Definition defaults     
$ access = 'E: \ "     
rem Start the main loop     
do     
cls 0     

To replace print text on the screen (and not to print)     
print "Utility Backups."     
print ""     
print "to save A, B to define a filter, C to change the output path, Q to exit."     

rem Request a value to the user and saves it as $ key     
input "Choose the action to do and press Enter>", $ key     

rem analysis of data received     
if key $ <> "A" and $ key <> "a" and key $ <> "B" and key $ <> "b" and key $ <> "C" and key $ <> "c" and key $ <> "Q" and key $ <> "q" then print "Please choose a valid choice." : Sleep 2000: GOSUB start     
rem The previous line displays an error message for 2 seconds and then back to the beginning if the election is invalid.     
rem I have not forgotten in the previous line to analyze the upper and lower case.     
rem Another solution would have been $ key turning in capitalisation to shorten the code.     

rem Now that the analysis is done, use the data.     
It will replace begin to see if the first choice was made:     

if $ key = "a" or $ key = "A" then save GOSUB     
rem If the choice was A or A, then we will save.     

if $ key = "b" or $ key = "B" then GOSUB option1     
Similarly to replace B, you arrive at the sub-menu option1     

if $ key = "c" or $ key = "C" then GOSUB option2     
Similarly rem for C to reach the submenu option2     

if $ key = "q" or $ key = "Q" then end     
rem Here, we saw that if the choice was to leave, leave the program without warning.     

rem Now that diversions have been made, it closes the loop for security (which will save us, you should see it if you run this code when we have finished).     
loop     
return

How to create sub functions


Sub functions cannot be placed anywhere. There will be 3 examples of sub functions given and they must each be placed in a specific place.

Subfunction 1


This subfunction should be used where the filters are located.


option1:     
do     
cls 0     
print "menu Filtering Files"     
print ""     
input "Please enter a file name to exclude or '/' to exit", next $     
rem Now we will create an array called $ exclude data may contain 255x1, 255: p     
Sunday exclude $ (255.1)     

It replaced the data ...     
if next = $ "/ \" or next $ $ = chr (34) + "/ \" + $ chr (34) then exit     
When replacing the analysis of data, it was back to the main menu on the user's request     
replaced by leaving the loop exit.     
rem Now, fill the table with a loop: for the, to, next     

    for nb = 1 to # 255     

       rem is analyzed if the space is free     
       if exclude $ (# nb, 1) = "" then exclude $ (# nb, 1) = next $: exit     
       rem fill up only if it is free then we go out of the loop.     

    next nb #     
But rem ... and if the table was full!?     
rem Well you know how to analyze the data now, good luck ^ ^     

rem So now we close the loop     
loop     
And we replaced the compiler that the sub-function stops there, to return to the main menu.     
return    

Subfunction 2


This one should be placed in the way out. Then you should ask the user if he is willing to modify the access for this type of filter.

option2:     
do     
cls 0     

print "Change copy output."     
print ""     
print "current output path:" $ + access     
input "Do you really want to change the path (o: yes / n: no)>", $ choice     

choice if $ <> "o" and choice $ <> "O" and choice $ <> "yes" and choice $ <> "Yes" and choice $ <> "YES" and choice $ <> "n" and choice $ <> "N" and choice $ <> "no" and choice $ <> "No" choice and $ <> "NO"     
    print "Invalid Choice."     
    sleep 2000     
    GOSUB option2     
endif     

if $ choice = "o" or choice $ = "O" or choice $ = "yes" or choice $ = "Yes" or choice $ = "YES"     
    input "Please enter a new path>", $ access     
else     
    exit     
endif     
loop     
return    


===Subfunction 3:The Batch file

You can also use DarkBasic to make a batch file simply by pasting the following codes:

save:     
cls 0     

print "System backup copy"     
print ""     
print "Source:" + get $ dir ()     
print "Destination:" $ + access     
print "Do you really want to copy the file"     
input current to "access + $ +" (o: yes / n: no)> ", $ choice     

choice if $ <> "o" and choice $ <> "O" and choice $ <> "yes" and choice $ <> "Yes" and choice $ <> "YES" and choice $ <> "n" and choice $ <> "N" and choice $ <> "no" and choice $ <> "No" choice and $ <> "NO"     
    print "Invalid Choice."     
    sleep 2000     
    GOSUB save     
endif     

rem closing of any open file.     
if file open (1) = 1 then close file 1     

rem Delete any file with the same name already exists.     
if file exist ( "code.bat") = 1 then delete file "code.bat"     

rem Creating and opening a batch file (. bat)     
open to write 1, "code.bat"     

rem Writing code.     
write string 1, "@ echo off"     
write string 1, "cd" $ dir + get ()     
write string 1, "xcopy" + $ chr (34) + get $ dir () + $ chr (34) + "" + $ chr (34) + $ access + $ chr (34) + "/ s / c / q / g / h / x / y "     
write string 1, "exit"     
close file 1     

rem Now that the code is created, it runs ...     

executable file get $()+" dir \ code.bat "," ", get $ dir (), 0     

rem is not 100% sure that this works: s     
rem Our application will wait for the copy is complete before continuing.     
will not be replaced copied the files and subfolders in the current directory of DarkBASIC code.     

print "When the copy is complete, you can continue. Use CTRL + C in the window"     
print "MS-BATCH (black) to stop his execution."     
sync     

rem The next block will wait for a response from the user.     
while Scancode 0 =     
endwhile     

rem And so is the end of the code ...     
return    

Key features of Dark Basic

  • Automated Double Buffering
  • Full-Screen Display Modes
  • Gamma Control
  • Mouse, Keyboard and Gaming controller input.
  • Force-Feedback Control
  • System Handling
  • File Handling
  • Video Animation Control
  • Audio Control
  • Super-Fast 2D blitting
  • Mirror, Stretch, Blur and Fade
  • Screen-Sized and animated sprites
  • Transparency
  • Fast pixel perfect Collision
  • 2D Drawing Functions
  • Landscape Terraforming
  • Built-in 3D Primitives
  • Polygon Collision Detection
  • Full Model Manipulation
  • Model Animation
  • Ambient lighting
  • Directional Lighting
  • Texture filtering
  • Alpha blending
  • Fogging
For unlimited offline reading, you can download this article for free in PDF format:
Introduction-to-dark-basic.pdf

See also

In the same category

Introducción a Dark Basic
By Carlos-vialfa on January 18, 2010
Introduction au Dark Basic
By kilian on April 22, 2008
Introdução ao Dark Basic
By pintuda on November 8, 2011
Original article published by kilian. Translated by jad05. - Latest update by Jeff
This document entitled « Introduction to Dark Basic » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.