OpenDBC
Menu

DBPro examples

Every DarkBASIC Professional example shipped in examples/dbpro: the complete demo games, the official showcase tutorials (one per command family) and the Hello World project. Each entry explains how the program is put together and links every command to its reference page.

37 example programs — 7527 lines of DBA source. Command chips link to the corresponding reference entries.

Type and status legend

Demos — complete games

Dusk Rally - an OpenDBC example for the DarkBASIC Professional profile dbproExample

examples/dbpro/demos/dusk_rally/dusk_rally.dba · 1072 lines (938 code)

Three laps of a coastal circuit against three rivals while the sun sets over the sea: headlights and street lamps take over as the light fades. The title screen races on its own until a key is hit. Up/W accelerates, Down/S brakes and reverses, Left/Right or A/D steer, SPACE is the handbrake, C changes the camera, ESC quits. Code and media are part of OpenDBC (MIT code, CC0 media).

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 15 user function(s): DriveCar, AIInputs, KeepOnTrack, PlaceCar, Shadowed, Clock$, anykey, Wrap (+7 more); 20 GOSUB subroutine(s): simulate, build_circuit, build_world, build_cars, build_minimap, load_sounds, new_race, read_input (+12 more).
  • Data. 7 array(s) declared with DIM; constant tables in DATA blocks read with READ; 1 user-defined TYPE(s).
  • Assets. Loads 36 media file(s) from the example folder: textures/detail.jpg, textures/sea.jpg, textures/gloss.jpg, textures/flare.jpg, textures/flare_red.jpg, textures/barrier_bump.jpg (+30 more).

Commands used (137)

View source (1072 lines)
rem ==================================================================
rem Dusk Rally - an OpenDBC example for the DarkBASIC Professional profile
rem Three laps of a coastal circuit against three rivals while the sun
rem sets over the sea: headlights and street lamps take over as the
rem light fades. The title screen races on its own until a key is hit.
rem Up/W accelerates, Down/S brakes and reverses, Left/Right or A/D
rem steer, SPACE is the handbrake, C changes the camera, ESC quits.
rem Code and media are part of OpenDBC (MIT code, CC0 media).
rem ==================================================================

#constant CONTROLS 14
#constant SPS 24
#constant SAMPLES 336
#constant ROAD_HALF 7.0
#constant CURB_OUT 8.6
#constant BARRIER 14.0
#constant LAMP_STEP 12
#constant LAMP_SIDE 16.5
#constant LAMP_REACH 12.5
#constant LAMP_HEIGHT 7.4
#constant LAMPS 28
#constant CARS 4
#constant LAPS 3
#constant DT 0.0166667
#constant MAX_STEPS 4
#constant TOP_SPEED 62.0
#constant SUN_AZIMUTH -35.0

rem Object, image and light numbers
#constant OBJ_SKY 1
#constant OBJ_GROUND 3
#constant OBJ_SEA 4
#constant OBJ_BULBS 5
#constant OBJ_GANTRY 6
#constant OBJ_STAND 7
#constant OBJ_LIGHTHOUSE 8
#constant OBJ_STARTLAMP 10
#constant OBJ_CIRCUIT 20
#constant OBJ_ROAD 21
#constant OBJ_WALL 41

First 40 lines shown — 1032 more in examples/dbpro/demos/dusk_rally/dusk_rally.dba.

Reactor Breach - an OpenDBC example for the DarkBASIC Professional profile dbproExample

examples/dbpro/demos/reactor_breach/reactor_breach.dba · 1337 lines (1156 code)

The research reactor is in lockdown and its security drones have turned on the staff. Close the three coolant valves to drop the force field, then reach the exit lift before the core melts down. WASD or arrow keys move, the mouse aims, left button fires, R reloads, hold E at a valve to close it, SPACE jumps, ESC quits. Code and media are part of OpenDBC (MIT code, CC0 media).

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 37 user function(s): read_layout, add_box, build_collision, load_media, build_world, reset_game, start_mode, player_update (+29 more).
  • Data. 8 array(s) declared with DIM; constant tables in DATA blocks read with READ; 7 user-defined TYPE(s).
  • Assets. Loads 44 media file(s) from the example folder: textures/lightmap.jpg, textures/glow.jpg, textures/flash.jpg, textures/crate.jpg, textures/crate_normal.jpg, textures/plasma.jpg (+38 more).

Commands used (160)

View source (1337 lines)
rem ==================================================================
rem Reactor Breach - an OpenDBC example for the DarkBASIC Professional profile
rem The research reactor is in lockdown and its security drones have
rem turned on the staff. Close the three coolant valves to drop the
rem force field, then reach the exit lift before the core melts down.
rem WASD or arrow keys move, the mouse aims, left button fires, R reloads,
rem hold E at a valve to close it, SPACE jumps, ESC quits.
rem Code and media are part of OpenDBC (MIT code, CC0 media).
rem ==================================================================

set display mode 1280, 720, 32
sync on : sync rate 60
hide mouse
disable escapekey
autocam off
backdrop on
color backdrop 0
set camera range 1, 1200
set camera fov 70

rem LEVEL_TILING matches the Blender bake of the level: it turns the
rem lightmap atlas UVs back into material repeats of 32 world units.
#constant LEVEL_TILING 21.7687
#constant EYE 16.0
#constant RADIUS 4.5
#constant MAX_ROOMS 12
#constant MAX_BOXES 40
#constant MAX_DRONES 8
#constant MAX_BOLTS 10
#constant MAX_PICKUPS 8
#constant CORE_SECONDS 420

rem Object numbers
#constant OBJ_LEVEL 1
#constant OBJ_LAMPS 2
#constant OBJ_GLASS 3
#constant OBJ_ENERGY 4
#constant OBJ_FIELD 5
#constant OBJ_PAD 6
#constant OBJ_GUN 7

First 40 lines shown — 1297 more in examples/dbpro/demos/reactor_breach/reactor_breach.dba.

Sky Gardens - an OpenDBC example for the DarkBASIC Professional profile dbproExample

examples/dbpro/demos/sky_gardens/sky_gardens.dba · 1274 lines (1114 code)

Run, jump and wall-jump across floating garden islands at golden hour, gather the thirty glowing seeds and wake the shrine at the top. WASD or arrows move, SPACE jumps (again in the air for a double jump, against a tall wall for a wall jump), the mouse orbits the camera, ESC quits. The title screen plays itself until a key or click. Code and media are part of OpenDBC (MIT code, CC0 media).

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 20 user function(s): new_object, add_solid, make_block, add_seed, scatter_ferns, activate_check, respawn, set_anim (+12 more); 16 GOSUB subroutine(s): load_media, build_level, build_route, new_run, read_controls, autopilot, move_player, collect_seeds (+8 more).
  • Data. 15 array(s) declared with DIM; constant tables in DATA blocks read with READ; 5 user-defined TYPE(s).
  • Assets. Loads 34 media file(s) from the example folder: textures/sky.jpg, textures/clouds.jpg, textures/wisps.jpg, textures/ruin.jpg, textures/ruin_normal.jpg, textures/glow.jpg (+28 more).

Commands used (132)

View source (1274 lines)
rem ==================================================================
rem Sky Gardens - an OpenDBC example for the DarkBASIC Professional profile
rem Run, jump and wall-jump across floating garden islands at golden
rem hour, gather the thirty glowing seeds and wake the shrine at the top.
rem WASD or arrows move, SPACE jumps (again in the air for a double jump,
rem against a tall wall for a wall jump), the mouse orbits the camera,
rem ESC quits. The title screen plays itself until a key or click.
rem Code and media are part of OpenDBC (MIT code, CC0 media).
rem ==================================================================

set display mode 1280, 720, 32
sync on : sync rate 60
autocam off
hide mouse
randomize 7

#constant GRAVITY 0.032
#constant JUMP_SPEED 0.56
#constant BOUNCE_SPEED 1.2
#constant RUN_SPEED 0.30
#constant PLAYER_RADIUS 0.6
#constant PLAYER_HEIGHT 2.9
#constant SEED_TOTAL 30
#constant FIRST_OBJECT 100
#constant FOG_RGB rgb(250, 214, 172)

rem Animation timeline of explorer.x: looping clips end on their first pose
#constant ANIM_IDLE 1
#constant ANIM_RUN 2
#constant ANIM_JUMP 3
#constant ANIM_FALL 4
#constant ANIM_WALL 5

type Solid
   kind as integer
   x as float
   z as float
   hx as float
   hz as float
   bottom as float

First 40 lines shown — 1234 more in examples/dbpro/demos/sky_gardens/sky_gardens.dba.

Hello World

Hello World dbproExample

examples/dbpro/Hello World/Hello World.dba · 6 lines (3 code)

How it is built

  • Program shape. Linear: runs once from top to bottom.

Commands used (1)

View source (6 lines)
Rem Project: Hello World
Rem Created: Friday, November 20, 2015

_ten:
print "hello world"
goto _ten

Tutorials — 3D maths

3DMaths Showcase dbproExample

examples/dbpro/tutorials/3dmaths/3dmaths1.dba · 183 lines (65 code)

A COMPLETE FVF, USAGE and TYPE list at end of program

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Assets. Loads 1 media file(s) from the example folder: vshader.vsh.

Commands used (33)

View source (183 lines)
rem 3DMaths Showcase
rem A COMPLETE FVF, USAGE and
rem TYPE list at end of program

ObjectNumber=1
VertexShaderNumber=1

rem Constants for vertex shader
#constant CSCALE          1
#constant CTRANSLATION    2
#constant CXROTATE        3
#constant CYROTATE        4
#constant CZROTATE        5
#constant CROTATION       6
#constant CWORLD          7
#constant CVIEW           8
#constant CPROJECTION     9
#constant CTEMP           10
#constant CLIGHT          11
#constant CDEGTORAD       ( 3.14 / 180.0 )

rem Provide vertex shader with stream count
set vertex shader streamcount VertexShaderNumber, 4

rem Provide vertex shader with stream
VSDT_FLOAT2=0x01 : VSDT_FLOAT3=0x02 : VSDT_D3DCOLOR=0x04
VSDE_POSITION=0 : VSDE_NORMAL=3 : VSDE_DIFFUSE=10 : VSDE_TEXCOORD0=5
set vertex shader stream VertexShaderNumber, 1, VSDE_POSITION, VSDT_FLOAT3
set vertex shader stream VertexShaderNumber, 2, VSDE_NORMAL, VSDT_FLOAT3
set vertex shader stream VertexShaderNumber, 3, VSDE_DIFFUSE, VSDT_D3DCOLOR
set vertex shader stream VertexShaderNumber, 4, VSDE_TEXCOORD0, VSDT_FLOAT2

rem Create a vertex shader from a text file
create vertex shader from file VertexShaderNumber, "vshader.vsh"

rem Make simple object
make object sphere ObjectNumber,100

rem Convert object to correct mesh format
FVF_XYZ=0x002 : FVF_NORMAL=0x010 : FVF_DIFFUSE=0x040 : FVF_TEX1=0x100

First 40 lines shown — 143 more in examples/dbpro/tutorials/3dmaths/3dmaths1.dba.

Tutorials — Animation

Animation Showcase dbproExample

examples/dbpro/tutorials/animation/animation1.dba · 76 lines (53 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 1 media file(s) from the example folder: avi\demo1.avi.

Commands used (42)

View source (76 lines)
rem Animation Showcase

rem Standard Setup Code for all examples
sync on : sync rate 60 : color backdrop rgb(0,128,0)
set text font "arial" : set text size 20
set text to bold : set text transparent

rem Produce Title
ink rgb(0,0,0),0 : center text (screen width()/2)+1,7,"Full Animation Support"
ink rgb(255,255,255),0 : center text screen width()/2,6,"Full Animation Support"

rem Load Animation and Set Up
load animation "avi\demo1.avi",1

rem Set Animation to Loop
play animation to image 1,1,0,0,animation width(1),animation height(1)
loop animation 1

rem Create models for 3D animation effect
make object box 1,350,350,1000
scale object 1,100,100,-100
set object 1,1,0,0,0,0,0,0
texture object 1,1
make object sphere 2,50
texture object 2,1
set sphere mapping on 2,1
for t=0 to 7
 make object cube 3+t,25
 texture object 3+t,1
next t

rem Main loop
do

rem 3D effects
a#=wrapvalue(a#-4)
scale object 2,100+cos(a#)*25,100+sin(a#)*25,100
for t=0 to 7
 position object 3+t,cos(wrapvalue(a#+(t*45)))*40,sin(wrapvalue(a#+(t*45)))*30,sin(wrapvalue(a#+(t*45)))*40
 if t=0 or t=3 or t=6 then xrotate object 3+t,wrapvalue(object angle x(3+t)+2)
 if t=1 or t=4 or t=7 then yrotate object 3+t,wrapvalue(object angle y(3+t)+2)
 if t=2 or t=5 then zrotate object 3+t,wrapvalue(object angle z(3+t)+2)
next t
position camera cos(a#)*10,sin(a#)*10,-100
point camera 0,0,0

rem Show Buttons
over=0
for but=1 to 3
 for high=0 to 1
  if high=0 then ink rgb(20,20,20),0 : bx=1 : by=1
  if high=1 then ink rgb(200,200,255),0 : bx=0 : by=0
  if high=1 and mousey()>420 and mousey()<460
   if but=1 and abs(mousex()-170)<50 then ink rgb(255,255,255),0 : over=1
   if but=2 and abs(mousex()-320)<50 then ink rgb(255,255,255),0 : over=2
   if but=3 and abs(mousex()-470)<50 then ink rgb(255,255,255),0 : over=3
  endif
  if but=1 then but$="STOP"
  if but=2 then but$="PLAY"
  if but=3 then but$="EXIT"
  center text 320+bx+((but-2)*150),420+by,but$
 next high
next but

rem Controls
if mouseclick()=1
 if over=1 then pause animation 1
 if over=2 then resume animation 1
 if over=3 then end
endif

rem Update screen
sync

rem End loop
loop

Tutorials — 2D drawing

Basic2D Showcase dbproExample

examples/dbpro/tutorials/basic2d/basic2d1.dba · 129 lines (102 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 1 media file(s) from the example folder: parchment.jpg.

Commands used (30)

View source (129 lines)
rem Basic2D Showcase

rem Standard Setup Code for all examples
sync on : sync rate 0
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Nice backdrop
load bitmap "parchment.jpg"

rem Produce Title
ink rgb(0,0,0),0 : center text (screen width()/2)+1,7,"2D Graphics Support"
ink rgb(255,255,255),0 : center text screen width()/2,6,"2D Graphics Support"

rem Create an array to hold pixeldatas
bitsperpixel=bitmap depth()/8
workA = make memory(640*480*bitsperpixel)
fill memory workA, 0, 640*480*bitsperpixel

rem Create Art Space
set current bitmap 0
box 48,48,640-48,450-48,rgb(255,255,0),rgb(255,200,255),rgb(255,255,200),rgb(200,255,255)
lock pixels
pitch=get pixels pitch() : ptr=get pixels pointer()
workAptr=workA : linesize=640*bitsperpixel
for y=0 to 479
 copy memory workAptr, ptr, linesize : inc workAptr,640*bitsperpixel : inc ptr,pitch
next y
unlock pixels

rem Main loop
do

rem Draw to Memory
mx=mousex() : my=mousey()
focus=16*(1+size)
if mx>focus and mx<640-focus and my>focus and my<479-focus
 for focus=1 to 16*(1+size)
  for y=my-focus to my+focus
   penwidth=focus-abs(y-my)
   for x=mx-penwidth to mx+penwidth
    workptr=workA+(x*bitsperpixel)+(y*640*bitsperpixel)
    col = *workptr
    colb = col && %1111111111111111
    if bitsperpixel=2
     cr = (col && %11111000000000000000000000000000)>>27
     cg = (col && %00000111111000000000000000000000)>>21
     cb = (col && %00000000000111110000000000000000)>>16
     dec cr
     dec cg
     dec cb
    endif
    if bitsperpixel=4
     cr = rgbr(col) - 1
     cg = rgbg(col) - 1
     cb = rgbb(col) - 1
    endif
    if nocap=0
     if cr<0 then cr=0
     if cg<0 then cg=0
     if cb<0 then cb=0
    endif
    if bitsperpixel=2
     col = (cr<<27)+(cg<<21)+(cb<<16)
     *workptr = col+colb
    endif
    if bitsperpixel=4
     col = rgb(cr,cg,cb)
     *workptr = col
    endif
   next x
  next y
 next focus
endif

rem Draw Memory to screen
workAptr=workA+(640*48*bitsperpixel)
ymax=450-48
lock pixels
linesize=(640-48-48)*bitsperpixel
pitch=get pixels pitch()
ptr=get pixels pointer()+(48*pitch)
for y=48 to ymax
 copy memory ptr+(48*bitsperpixel), workAptr+(48*bitsperpixel), linesize
 inc workAptr,640*bitsperpixel
 inc ptr,pitch
next y
unlock pixels

rem Show Buttons
over=0
for but=1 to 3
 for high=0 to 1
  if high=0 then ink rgb(20,20,20),0 : bx=-1 : by=-1
  if high=1 then ink rgb(100,200,100),0 : bx=0 : by=0
  if high=1 and mousey()>420 and mousey()<460
   if but=1 and abs(mousex()-170)<50 then ink rgb(255,255,255),0 : over=1
   if but=2 and abs(mousex()-320)<50 then ink rgb(255,255,255),0 : over=2
   if but=3 and abs(mousex()-470)<50 then ink rgb(255,255,255),0 : over=3
  endif
  if but=1 then but$="SIZE"
  if but=2 then but$="PLASMA"
  if but=3 then but$="EXIT"
  center text 320+bx+((but-2)*150),420+by,but$
 next high
next but

rem Controls
if mouseclick()=1
 if once=0
  once=1
  if over=1 then size=size+1
  if over=2 then nocap=1-nocap
  if size=3 then size=0
  if over=3 then delete memory workA : end
 endif
else
 once=0
endif

rem Update screen
sync

rem End loop
loop

rem Free memory
delete memory workA
delete memory workB

Tutorials — 3D objects

Basic3D Showcase dbproExample

examples/dbpro/tutorials/basic3d/basic3d1.dba · 187 lines (138 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Data. 4 array(s) declared with DIM.
  • Assets. Loads 20 media file(s) from the example folder: space.wav, microid.png, a.png, b.png, c.png, models\ast4.png (+14 more).

Commands used (70)

View source (187 lines)
rem Basic3D Showcase

rem Standard Setup Code for all examples
backdrop off : cls : sync on : sync rate 0 : hide mouse
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Create availability chart
dim name$(11)
set image colorkey 32,32,32
set text size 14 : cls rgb(32,32,32)
text 10,0,"MODES AVAILABLE"
for t=1 to 11
 if t=1 then name$(t)="[1] Normal Texture"
 if t=2 then name$(t)="[2] Light Mapping"
 if t=3 then name$(t)="[3] Cube Mapping"
 if t=4 then name$(t)="[4] Sphere Mapping"
 if t=5 then name$(t)="[5] Detail Mapping"
 if t=6 then name$(t)="[6] Custom Blend Mapping"
 if t=7 then name$(t)="[7] Bump Mapping"
 if t=8 then name$(t)="[8] Cartoon Shading"
 if t=9 then name$(t)="[9] Rainbow Shading"
 if t=10 then name$(t)="[0] Reflection Shading"
 if t=11 then name$(t)="[-] Shadow Shading"
 t$=name$(t) : a$="Available"
 if t>=7 and t<=11
  if get maximum vertex shader version()<1.0 then a$="Not Available"
  if t>=10 and t<=11
   if statistic(2)=0 then a$="Not Available"
  endif
 endif
 text 10,(t*12),t$+" "+a$
next t
get image 31,0,0,256,256
set text size 16 : cls

rem User Prompt
center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load music

First 40 lines shown — 147 more in examples/dbpro/tutorials/basic3d/basic3d1.dba.

Basic3D Functionality dbproExample

examples/dbpro/tutorials/basic3d/basic3d2.dba · 678 lines (461 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 11 GOSUB subroutine(s): _legacycommands, _3dobjects, _3dmotion, _3dcollision, _3dlimbs, _newcommands, _newobjectcommands, _newtexturecommands (+3 more).
  • Assets. Loads 8 media file(s) from the example folder: models\model.x, iron.jpg, models\extraanim.x, mesh.x, model.x, vshader.vsh (+2 more).

Commands used (260)

View source (678 lines)
rem Basic3D Functionality

rem Standard Setup Code for all examples
backdrop off : cls : sync on : sync rate 0 : hide mouse
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Legacy or New Commands
legacyonly=rnd(1)
if legacyonly=1
 gosub _legacycommands
else
 gosub _newcommands
endif

rem End program
end

_legacycommands:

rem Test loop
do

rem Produce random values
ObjectNumber=1+rnd(500000)
Wireframe=rnd(1)
Transparency=rnd(1)
Cull=rnd(1)
Filter=rnd(1)
Light=rnd(1)
Fog=rnd(1)
Ambient=rnd(1)
MeshNumber=1+rnd(5)
TextureNumber=1+rnd(5)
LimbNumber=10
Size=10+rnd(90)
XSize=10+rnd(90)
YSize=10+rnd(90)
ZSize=10+rnd(90)
StartFrame=1+rnd(10)

First 40 lines shown — 638 more in examples/dbpro/tutorials/basic3d/basic3d2.dba.

Mesh Manipulation dbproExample

examples/dbpro/tutorials/basic3d/basic3d3.dba · 157 lines (109 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 4 media file(s) from the example folder: ninja.x, models\ninja.png, models\ninja.x, newmesh.x.

Commands used (70)

View source (157 lines)
rem Mesh Manipulation

rem Standard Setup Code for all examples
`set window off
sync on : sync rate 0 : color backdrop rgb(0,128,0)
set text font "arial" : set text size 16
set text to bold : set text transparent
ink rgb(255,255,0),0

rem Load model
ObjectNumber=1
set dir "models"
load object "ninja.x",ObjectNumber
rotate object ObjectNumber,0,0,0
scale object ObjectNumber,6000,6000,6000
loop object ObjectNumber
set dir ".."

rem Create mesh from primitive
randomize timer()
pr=1+rnd(5)
MeshIndex=1
if pr=1 then make object cube 5,50
if pr=2 then make object box 5,50,25,10
if pr=3 then make object sphere 5,50
if pr=4 then make object cylinder 5,50
if pr=5 then make object cone 5,50
if pr=6 then make object plain 5,100,50
if pr=7 then make object triangle 5,0,0,0,50,50,0,50,0,0
make mesh from object MeshIndex,5
delete object 5

rem Sphere to Shape
if mesh exist(MeshIndex)=1
 ObjectNumberB=2
 make object sphere ObjectNumberB,50
 change mesh ObjectNumberB,0,MeshIndex
 position object ObjectNumberB,50,100,0
 set object ObjectNumberB,0,1,1,0,0,0,0
 set object light ObjectNumberB,1

First 40 lines shown — 117 more in examples/dbpro/tutorials/basic3d/basic3d3.dba.

Primitive Texturing dbproExample

examples/dbpro/tutorials/basic3d/basic3d4.dba · 66 lines (42 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 9 media file(s) from the example folder: a.png, b.png, c.png, d.png, e.png, sphere.png (+3 more).

Commands used (41)

View source (66 lines)
rem Primitive Texturing

rem Standard Setup Code for all examples
`set window off
sync on : sync rate 0 : color backdrop rgb(0,128,0)
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Load images (textures)
load image "a.png",1
load image "b.png",2
load image "c.png",3
load image "d.png",4
load image "e.png",5
load image "sphere.png",6
load image "bump.png",7
load image "shade.png",8
load image "edge.dds",9

rem Make object
make object cube 1,10 : color object 1,rgb(255,0,0)
make object box 2,10,2,10 : color object 2,rgb(0,255,0)
make object sphere 3,10,6,6 : color object 3,rgb(0,0,255)
make object triangle 5,0,0,0,10,0,0,10,10,0
make object plain 6,10,10
make object cylinder 7,10
make object cone 8,10
make object sphere 4,10
for x=1 to 8
 position object x,(x-4)*10,0,0
next x

rem Set camera and light
move camera -100
set point light 0,0,0,0

rem Main loop
desc$="Texturing Primitives (Press 1-6)"
do

rem Affect object with textures
for t=1 to 8
 if inkey$()="1" then texture object t,1 : desc$="1. Normal Texture"
 if inkey$()="2" then set light mapping on t,2 : desc$="2. Light Mapping"
 if inkey$()="3" then set cube mapping on t,1,2,3,4,5,6 : desc$="3. Cube Mapping"
 if inkey$()="4" then set sphere mapping on t,6 : desc$="4. Sphere Mapping"
 if inkey$()="5" then set detail mapping on t,4 : desc$="5. Detail Mapping"
 if inkey$()="6" then set blend mapping on t,5,10 : desc$="6. Custom Blend Mapping"
 yrotate object t,wrapvalue(object angle y(t)+0.3)
next t

rem New object creator
if spacekey()=1 then delete object 4 : make object sphere 4,100

rem Move light using mouse
position light 0,mousex()-320,240-mousey(),-50

rem Show Framerate
text 20,screen height()-40,desc$
text screen width()-170,screen height()-40,"DBPro Fps: "+str$(screen fps())

rem Update screen
sync

rem End loop
loop

Pixel Shader Usage dbproExample

examples/dbpro/tutorials/basic3d/basic3d5.dba · 54 lines (24 code)

init screen

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Assets. Loads 2 media file(s) from the example folder: pixelshader.psh, face.png.

Commands used (15)

View source (54 lines)
rem Pixel Shader Usage

rem init screen
backdrop off

rem Create an object
ObjectNumber=1
make object sphere ObjectNumber,10

rem If Pixel Shaders supported
if get maximum pixel shader version()>0

 rem Create a pixel shader from a text file
 PixelShaderNumber=1
 create pixel shader from file PixelShaderNumber, "pixelshader.psh"

 rem Provide pixel shader with a texture
 ImageNumber=1
 load image "face.png",ImageNumber
 set pixel shader texture PixelShaderNumber, 0, ImageNumber

 rem Check if pixel shader was created
 if pixel shader exist(PixelShaderNumber)=1

  rem Apply pixel shader to object
  set pixel shader on ObjectNumber, PixelShaderNumber

 endif

 rem Main loop
 while mouseclick()<>2
  set cursor 0,0 : print "Press Right Mouse Button To Exit"
 endwhile

 rem Check if pixel shader was created
 if pixel shader exist(PixelShaderNumber)=1

  rem Deactivate pixel shader of the object
  set pixel shader off ObjectNumber

  rem Delete a pixel shader
  delete pixel shader PixelShaderNumber

 endif

else
 print "No Pixel Shader Support - Press Key" : wait key
endif

rem Delete object
delete object ObjectNumber

rem End program
end

Collision Functionality dbproExample

examples/dbpro/tutorials/basic3d/basic3d6.dba · 143 lines (91 code)

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 1 GOSUB subroutine(s): _delete_collision.
  • Assets. Loads 5 media file(s) from the example folder: impact.wav, marble.jpg, moss.jpg, fur.jpg, alien.x.

Commands used (61)

View source (143 lines)
rem Collision Functionality

sync on : sync rate 60 : hide mouse : color backdrop rgb(100,100,255)
set text transparent : set text font "Arial" : set text size 20

rem load sounds
load sound "impact.wav",1
for s=2 to 10 : clone sound s,1 : next s

rem load images
load image "marble.jpg",1
load image "moss.jpg",2
load image "fur.jpg",3

rem create floor
make object box 1,400,10,400 : position object 1,0,-5,0
texture object 1,2 : scale object texture 1,2,2

rem create walls
make object box 2,400,100,10 : position object 2,0,50,-200
make object box 3,400,100,10 : position object 3,0,50, 200
make object box 4,10,100,400 : position object 4,-200,50,0
make object box 5,10,100,400 : position object 5, 200,50,0
for t=2 to 5
 texture object t,2 : scale object texture t,4,1
next t

rem Set floor and walls to box collision for rectangle roamer
make object collision box 1,-200,-5,-200,200,5,200,0
make object collision box 2,-200,-50,-5,200,50,5,0
make object collision box 3,-200,-50,-5,200,50,5,0
make object collision box 4,-5,-50,-200,5,50,200,0
make object collision box 5,-5,-50,-200,5,50,200,0

rem create collision platform
make object box 6,100,12,100
position object 6,0,5,0
texture object 6,1

rem create bouncey ball and set bounce-vars
make object sphere 11,25
set object collision to spheres 11
set object radius 11,15
texture object 11,1
y#=75 : iy#=2

rem rectangle roamer for box collision
make object box 41,40,20,40 : position object 41,95,31,50
make object collision box 41,-20,-10,-20,20,10,20,0
texture object 41,1
set shadow shading on 41

rem load a model in center of world
load object "alien.x",51
set object collision to polygons 51
scale object 51,1500,1500,1500
position object 51,0,40,0
xrotate object 51,180
texture object 51,3
scale object texture 51,5,5
set object speed 51,100
loop object 51

rem create a crate for automatic collision
make object cube 61,15
automatic object collision 61,8.0,0
set object collision to spheres 61
position object 61,-75,30,75
texture object 61,1
set shadow shading on 61

rem setup camera and lights
set point light 0,0,0,0
make light 1 : set point light 1,0,0,0 : color light 1,255,-100,-100
position camera 0,30,-100

rem set automatic collision for camera
automatic camera collision 0,15,0
set global collision on

rem loop
do

rem delete all collision data
if spacekey()=1
 gosub _delete_collision
endif

rem move crate to test automatic object collision
yrotate object 61,wrapvalue(object angle y(61)-0.2)
move object down 61,0.5
move object 61,0.5

rem control camera
control camera using arrowkeys 0,1,2

rem control bouncey ball
y#=y#+(iy#/20.0) : iy#=iy#-0.2
position object 11,object position x(11),y#,object position z(11)
if object collision(11,0)>0 then iy#=iy#*-1.0 : play sound 1+rnd(9)

rem display types of collision
if object in screen(11)=1 then center text object screen x(11),object screen y(11)-25,"Polygon Collision"
if object in screen(41)=1 then center text object screen x(41),object screen y(41)-25,"Sliding Box Collision"
if object in screen(61)=1 then center text object screen x(61),object screen y(61)-25,"Automated Collision"

rem Add gravity to camera to test automatic collision
position camera camera position x(),camera position y()-1.01,camera position z()

rem rectangle roamer
move object 41,0.3
ballhit=object collision(41,0)
if ballhit>0
 spin#=rnd(45)
 ax#=object position x(41)-get object collision x()
 ay#=object position y(41)-get object collision y()
 az#=object position z(41)-get object collision z()
 position object 41,ax#,ay#,az#
endif
if spin#>0
 spin#=spin#-1.0
 yrotate object 41,wrapvalue(object angle y(41)+1)
endif

rem move default light with ball
position light 0,object position x(11),object position y(11),object position z(11)

rem move coloured light with roamer
position light 1,object position x(41),object position y(41)+25,object position z(41)

rem update screen
sync

rem end loop
loop

_delete_collision:
 for o=1 to 5
  delete object collision box o
 next o
 set global collision off
return

FX Mini Browser dbproExample

examples/dbpro/tutorials/basic3d/basic3d7.dba · 338 lines (228 code)

Init app

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 1 user function(s): scandir; 4 GOSUB subroutine(s): _initscreen, _refreshscreen, _loadmodelandeffect, _updateeffectvalues.
  • Data. 2 array(s) declared with DIM; 1 user-defined TYPE(s).

Commands used (91)

View source (338 lines)
Rem FX Mini Browser
Rem Created: 28/06/2003 03:57:13

rem Init app
sync on : sync rate 60 : hide mouse : backdrop off

rem Obtain information on shader capabilities
vs#=get maximum vertex shader version()
ps#=get maximum pixel shader version()

rem Screen dimensions
gap=screen height()/20
topline=gap+60
halfwidth=screen width()/2
middleline=screen width()/2
bottomline=screen height()-gap
verthalfline=topline+((bottomline-topline)/2)
rightline=screen width()-gap
displaymax=((bottomline-topline)/18)-2
valuesdisplaymax=((bottomline-(verthalfline+gap))/18)-2
displaywidthmax=((middleline-leftline)/10)-2
valuesdisplaywidthmax=((rightline-middleline)/10)-9

rem Create list of FX files
dim list$(0) : empty array list$()
scandir("fx","")
listmax=2+array count(list$())
listtop=1

rem Create list of Effect Values
type valuestype name$ vartype hooked endtype
dim values$(0) as valuestype : empty array values$()
valuesmax=1+array count(values$())
valuestop=1

rem Setup camera and light for preview camera
position camera 0,0,0,-1000
make camera 1 : set camera view 1,middleline,topline,rightline,verthalfline
set camera aspect 1,(rightline-middleline)/((verthalfline-topline)+0.0)
backdrop on 1 : color backdrop 1,0

First 40 lines shown — 298 more in examples/dbpro/tutorials/basic3d/basic3d7.dba.

U5Collection dbproExample

examples/dbpro/tutorials/basic3d/basic3d8.dba · 116 lines (60 code)

Version: Upgrade 5 or above

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 4 media file(s) from the example folder: spec.png, cartoon.fx, sphere.x, bubble.fx.

Commands used (53)

View source (116 lines)
Rem U5Collection
Rem Created: 12/06/2003 00:49:08
rem Version: Upgrade 5 or above

rem Init app
sync on : sync rate 60

rem Load image
load image "spec.png",1

rem Make matrix and texture with trimmed tile
load image "spec.png",1
make matrix 1,1000,1000,10,10
position matrix 1,-500,-50,-500
prepare matrix texture 1,1,1,1
set matrix trim 1,0.25,0.25
update matrix 1
set matrix priority 1,1
ghost matrix on 1,0

rem Create a particles object
make particles 1,1,50,100.0
ghost particles on 1,0

rem Create an object with an effect (one command)
make object sphere 1,100,29,28
set effect on 1,"cartoon.fx",1

rem Theese are the defaults for an object
enable object zwrite 1
enable object zread 1

rem Full object material control
make object sphere 3,100,30,30
position object 3,-50,50,0
set object diffuse 3,rgb(255,0,0)
set object ambience 3,rgb(0,0,0)
set object emissive 3,rgb(0,0,64)
set object specular 3,rgb(255,255,255)
set object specular power 3,5

rem Object using FX system effect
load object "sphere.x",4
position object 4,150,50,0
scale object 4,8000,8000,8000
load effect "bubble.fx",1,1
set object effect 4,1
set limb effect 4,0,1

rem Create copies of the effect object
for o=5 to 99
 instance object o,1
 position object o,rnd(400)-200,rnd(100)-100,rnd(800)
 scale object o,25+rnd(25),25+rnd(25),25+rnd(25)
next o

rem Create an object to fade in/out
make object sphere 2,250
scale object texture 2,100,100

rem Smooth out object by obj or limb
set object smoothing 1,100
set limb smoothing 2,0,100

rem The fading sphere does not respond to zbuffer
disable object zwrite 2
disable object zread 2

rem Apply image directly to stage zero of texture
texture object 2,0,1

rem Change camera aspect to a square
x#=640-480 : set camera view x#/2,0,640-(x#/2),480
set camera aspect 1.0

rem Main loop
do
 `
 rem Set light for best effect
 inc side#,4 : set point light 0,cos(side#)*200,125,-300
 `
 rem Hide and Show Object Bounds
 if tm<75 then show object bounds 1,1
 if tm>75 then hide object bounds 1
 if tm>200 then tm=0
 `
 rem Use alpha to fade in/out
 set alpha mapping on 2,abs(tm-100)
 `
 rem Rotate original object
 yrotate object 1,object angle y(1)+0.1
 `
 rem Rotate instanced objects
 for o=5 to 99
  rotate object o,object angle x(o)+1,object angle y(o)+2,object angle z(o)+3
 next o
 `
 rem Control timer counter
 tm=tm+1
 `
 rem User prompt
 center text 320,20,"CRAZY COMBINATION OF NEW U5 COMMANDS"
 `
 rem Update screen
 sync
 `
rem loopend
loop

rem Free resources
ghost particles off 1
delete effect 1

rem End program
end

Pick Object dbproExample

examples/dbpro/tutorials/basic3d/basic3d9.dba · 98 lines (73 code)

Init app

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 1 GOSUB subroutine(s): _drag_object.

Commands used (32)

View source (98 lines)
Rem Pick Object
Rem Created: 14/07/2003 18:54:11

rem Init app
sync on : sync rate 60

rem Make floor
make object plain 1,300,300
position object 1,0,-50,0
xrotate object 1,270

rem Make object to drag
make object cube 2,100
set shadow shading on 2

rem Setup camera and light
set point light 0,-100,500,-100
position camera -200,0,-200
point camera 0,0,0

rem main loop
do

rem Call drag subroutine
gosub _drag_object

rem User prompt
center text 320,20,"CLICK AND HOLD OBJECT TO DRAG - RIGHT BUTTON TO ROTATE"

rem Update screen
sync

rem End loop
loop


_drag_object:

if mouseclick()=0 then pickmode=0 : cursorobj=0
mclick=mouseclick()
if mclick>0
 if pickmode=0
  cursorobj=pick object(mousex(),mousey(),2,2)
  if cursorobj>0
   pickmode=mclick
   pickdistance#=get pick distance()
   pickfromx#=get pick vector x()
   pickfromy#=get pick vector y()
   pickfromz#=get pick vector z()
   if pickmode=1
    objx#=object position x(cursorobj)
    objy#=object position y(cursorobj)
    objz#=object position z(cursorobj)
   else
    objx#=object angle x(cursorobj)
    objy#=object angle y(cursorobj)
    objz#=object angle z(cursorobj)
    pickdiffx#=mousemovey() : pickdiffx#=0
    pickdiffy#=mousemovex() : pickdiffy#=0
   endif
  else
   highlightobj=0
  endif
 endif
 if pickmode>0
  if pickmode=1
   pick screen mousex(),mousey(),pickdistance#
   picktox#=get pick vector x()
   picktoy#=get pick vector y()
   picktoz#=get pick vector z()
   pickdiffx#=picktox#-pickfromx#
   pickdiffy#=picktoy#-pickfromy#
   pickdiffz#=picktoz#-pickfromz#
   grid=0
   if grid=1
    pickdiffx#=int(pickdiffx#/5)*5
    pickdiffy#=int(pickdiffy#/5)*5
    pickdiffz#=int(pickdiffz#/5)*5
   endif
   position object cursorobj,objx#+pickdiffx#,objy#+pickdiffy#,objz#+pickdiffz#
  else
   pickdiffx#=pickdiffx#+mousemovey()
   pickdiffy#=pickdiffy#+mousemovex()
   grid=0
   if grid=1
    tpickdiffx#=int(pickdiffx#/22.5)*22.5
    tpickdiffy#=int(pickdiffy#/22.5)*22.5
   else
    tpickdiffx#=pickdiffx#
    tpickdiffy#=pickdiffy#
   endif
   rotate object cursorobj,wrapvalue(objx#-tpickdiffx#),wrapvalue(objy#-tpickdiffy#),objz#
  endif
 endif
endif

return

Tutorials — Bitmaps

Bitmap Showcase dbproExample

examples/dbpro/tutorials/bitmap/bitmap1.dba · 110 lines (83 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 4 media file(s) from the example folder: foliage.jpg, 2DFiles\logo.jpg, 2DFiles\logo.dds, 2DFiles\logo.png.

Commands used (34)

View source (110 lines)
rem Bitmap Showcase

rem Standard Setup Code for all examples
sync on : sync rate 60 : draw to back
set text font "arial" : set text size 20
set text to bold : set text transparent

rem Load backdrop
load bitmap "foliage.jpg"
get image 1,0,0,640,480

rem Produce Title
ink rgb(0,0,0),0 : center text (screen width()/2)+1,7,"BMP DDS DIB JPG PNG RLE TGA"
ink rgb(255,255,255),0 : center text screen width()/2,6,"BMP DDS DIB JPG PNG RLE TGA"

rem Create offscreen sprite
set sprite 1,0,1
set sprite alpha 1,128
offset sprite 1,(640-96)/4,(450-96)/4
size sprite 1,(640-96)/2,(450-96)/2
sprite 1,320,48+((450-96)/2),1

rem Create offscreen bitmap
create bitmap 2,640,480
set current bitmap 0

rem Main loop
do

rem Provide backdrop to visual screen
set current bitmap 2
sprite 2,320,240,1
sr#=350+(cos(a#)*10)
rotate sprite 2,sr#
size sprite 2,1000,800
offset sprite 2,512,384
set sprite alpha 2,100
set sprite 2,0,0
paste sprite 2,320,240
sprite 2,-2000,-2000,1
set current bitmap 0
copy bitmap 2,48,48,640-48,450-48,0,48,48,640-48,450-48

rem Rotate sprite
a#=wrapvalue(a#+2)
r#=350+(cos(a#)*10)
rotate sprite 1,r#
set sprite alpha 1,128
sprite 1,320,48+((450-96)/2),1
set sprite 1,0,0
s#=s#+0.5 : if s#>100 then s#=100
size sprite 1,((640-96)/2)*(s#/100.0),((450-96)/2)*(s#/100.0)

rem Show filename
ink rgb(255,255,255),0
center text 320,350,file$

rem Show Buttons
over=0
for but=1 to 3
 for high=0 to 1
  if high=0 then ink rgb(20,20,20),0 : bx=-1 : by=-1
  if high=1 then ink rgb(100,200,100),0 : bx=0 : by=0
  if high=1 and mousey()>420 and mousey()<460
   if but=1 and abs(mousex()-170)<50 then ink rgb(255,255,255),0 : over=1
   if but=2 and abs(mousex()-320)<50 then ink rgb(255,255,255),0 : over=2
   if but=3 and abs(mousex()-470)<50 then ink rgb(255,255,255),0 : over=3
  endif
  if but=1 then but$="PREV"
  if but=2 then but$="NEXT"
  if but=3 then but$="EXIT"
  center text 320+bx+((but-2)*150),420+by,but$
 next high
next but

rem Controls
if mouseclick()=1
 if once=0
  once=1
  if over=1 then pic=pic-1 : picload=1 : s#=0
  if over=2 then pic=pic+1 : picload=1 : s#=0
  if picload=1
   picload=0
   if pic<0 then pic=6
   if pic>6 then pic=0
   if pic=0 then file$="2DFiles\logo.jpg"
   if pic=1 then file$="2DFiles\logo.dds"
   if pic=2 then file$="2DFiles\logo.dib"
   if pic=3 then file$="2DFiles\logo.jpg"
   if pic=4 then file$="2DFiles\logo.png"
   if pic=5 then file$="2DFiles\logo.rle"
   if pic=6 then file$="2DFiles\logo.jpg"
   load bitmap file$,1
   if bitmap exist(1)=1
    get image 1,0,0,bitmap width(1),bitmap height(1),1
    set current bitmap 0
    delete bitmap 1
   endif
  endif
  if over=3 then end
 endif
else
 once=0
endif

rem Update screen
sync

rem End loop
loop

Tutorials — Cameras

Camera Showcase dbproExample

examples/dbpro/tutorials/camera/camera1.dba · 142 lines (91 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 4 media file(s) from the example folder: misty.mp3, wall.jpg, miko\miko.x, Sphere2.x.

Commands used (63)

View source (142 lines)
rem Camera Showcase

rem Standard Setup Code for all examples
sync on : sync rate 60 : color backdrop rgb(0,128,0)
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Some music
load music "misty.mp3",1 : loop music 1

rem Loading Prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load image
load image "wall.jpg",1

rem Create character
for t=1 to 2
 load object "miko\miko.x",t
 set object specular t,0
 xrotate object t,270
 fix object pivot t
 if t=1
  position object t,0,0,200
  rotate object t,0,180,0
 else
  position object t,0,0,-200
  rotate object t,0,0,0
 endif
 loop object t,0,9000
 set object speed t,500
next t

rem Create sphere room
load object "Sphere2.x",3
scale object 3,1000,1000,1000
scale object texture 3,10,5
set object specular 3,0
texture object 3,1

rem Create reflective circular floor
make object sphere 5,1000
color object 5,0 : ghost object on 5
set reflection shading on 5
scale object 5,100,100,1
xrotate object 5,90+180
set object specular 5,0

rem Cut-out view close-up
make camera 1
set camera view 1,320+48,16,640-16,240-48
make light 1 : color light 1,256,512,2024 : set light range 1,1000

rem Create floating globe
make object sphere 4,125
scale object texture 4,300,100
ghost object on 4

rem Create buzz globe
make object sphere 999,10 : color object 999,rgb(255,0,0)
make light 7 : color light 7,1024,100,100
set light range 7,200

rem Setup main camera and light
set current camera 0
set camera range 1,7000
set point light 0,0,0,0
set light range 0,1500
color light 0,256,512,256
camdist#=0.0

rem Rim Object
for t=7 to 28
 s#=t : s#=s#/3.0
 make object cube t,s#
 texture object t,4
 set object t,1,1,1,0,0,0,0
 ghost object on t
next t

rem Effect Prompt
desc$="Multicamera and Reflection View"

rem Main loop
do

rem Character control
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-3)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+3)

rem Let camera track character
a#=object angle y(1)
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
set current camera 1
set camera to follow x#,y#,z#,a#,-115,135,10.0,0
set current camera 0

rem Handle camera collision within circle
a#=atanfull(x#,z#)
d#=sqrt((x#*x#)+(z#*z#))
if d#>500 then x#=sin(a#)*500 : z#=cos(a#)*500 : position object 1,x#,y#,z#

rem Slowly move camera out
if camdist#<100.0 then camdist#=camdist#+0.1

rem Slowly rotate sphere room
xrotate object 3,wrapvalue(object angle x(3)+0.1)
yrotate object 3,wrapvalue(object angle y(3)+0.2)
zrotate object 3,wrapvalue(object angle z(3)+0.3)

rem Hover the orb around center
v#=wrapvalue(v#+0.5) : h#=wrapvalue(h#+2.0)
position object 4,sin(v#)*-750,100+(cos(h#)*100),cos(v#)*-750 : yrotate object 4,v#+60
position light 1,sin(v#)*-800,100+(cos(h#)*100),cos(v#)*-800
position light 0,sin(v#)*-500,100+(cos(h#)*100),cos(v#)*-500
position camera 0,sin(v#)*(camdist#*7.0),200+(cos(h#)*100),cos(v#)*(camdist#*7.0)
point camera 0,x#,y#+100,z#

rem Fire light
position object 999,0,200+(cos(h#+10)*150),sin(h#+10)*150
position light 7,0,200+(cos(h#)*150),sin(h#)*150

rem Emit particles around rim
for t=7 to 28
 r#=wrapvalue(r#+0.5)
 rotate object t,r#,r#*2,r#*3
 position object t,cos(r#+t)*500,0,sin(r#+t)*500
next t

rem Show Framerate
center text (640-16)-(((640-16)-(320+48))/2),20,"Use Arrow Keys"
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Core language

Math Showcase dbproExample

examples/dbpro/tutorials/core/core1.dba · 100 lines (61 code)

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Structure. 1 user function(s): prettybackdrop.

Commands used (12)

View source (100 lines)
rem Math Showcase
prettybackdrop()

rem Standard Setup Code for all examples
set text font "arial" : set text size 20
set text to bold : set text transparent

rem TITLE
center text screen width()/2,2,"MATH OPERATIONS"
set cursor 0,40 : set text size 14

rem VARIABLE DATA TYPES
r as integer : a as integer : b as integer
`r as float : a as float : b as float
`r as boolean : a as boolean : b as boolean
`r as byte : a as byte : b as byte
`r as word : a as word : b as word
`r as dword : a as dword : b as dword

rem LITERAL RADIX FORMS (binary, decimal, octal, hexidecimal)
a=5
b=%1011
b=11
b=0x0B
b=0c13

rem VARIABLES
print "WHERE a=";a;" b=";b
print

rem BITWISE COMMANDS
print "BITWISE OPERATIONS"
r = a >> b : print "SHIFT a >> b = ";r
r = a << b : print "SHIFT a << b = ";r
r = a && b : print "AND   a && b = ";r
r = a || b : print "OR    a || b = ";r
r = a ~~ b : print "XOR   a ~~ b = ";r
r = a .. b : print "NOT   a .. b = ";r
print

rem LOGIC OPERATORS
print "LOGIC OPERATIONS"
print "IF a AND b is "; : if a and b then print "TRUE" else print "FALSE"
print "IF a OR b is "; : if a or b then print "TRUE" else print "FALSE"
print "IF NOT b is "; : if not b then print "TRUE" else print "FALSE"
print "IF a = b is "; : if a=b then print "TRUE" else print "FALSE"
print "IF a <> b is "; : if a<>b then print "TRUE" else print "FALSE"
print "IF a > b is "; : if a>b then print "TRUE" else print "FALSE"
print "IF a >= b is "; : if a>=b then print "TRUE" else print "FALSE"
print "IF a < b is "; : if a<b then print "TRUE" else print "FALSE"
print "IF a <= b is "; : if a<=b then print "TRUE" else print "FALSE"
print

rem MATHS
print "MATH OPERATIONS"
r = a ^ b : print "a ^ b = ";r;"     ";
r = a ^ 4 : print "a ^ 4 = ";r;"     ";
r = a ^ a : print "a ^ a = ";r
r = a / b : print "a / b = ";r;"     ";
r = a / 4 : print "a / 4 = ";r;"     ";
r = a / a : print "a / a = ";r
r = a %% b : print "a %% b = ";r;"     ";
r = a %% 4 : print "a %% 4 = ";r;"     ";
r = a %% a : print "a %% a = ";r
r = a * b : print "a * b = ";r;"     ";
r = a * 4 : print "a * 4 = ";r;"     ";
r = a * a : print "a * a = ";r
r = a - b : print "a - b = ";r;"     ";
r = a - 4 : print "a - 4 = ";r;"     ";
r = a - a : print "a - a = ";r
r = a + b : print "a + b = ";r;"     ";
r = a + 4 : print "a + 4 = ";r;"     ";
r = a + a : print "a + a = ";r;

rem INC/DEC
inc a : inc a,4
dec b : dec b,4

rem FOR NEXT
a=0 : for t=1 to 50000 : a=a+1 : next t

rem Wait for a key
wait key
end

rem Data Ranges
rem Integer = –2,147,483,648 to 2,147,483,647
rem Float = 3.4E +/- 38 (7 digits)
rem Boolean = 0 to 255
rem Byte = 0 to 255
rem Word = 0 to 65,535
rem DWord = 0 to 4,294,967,295
rem Double Integer = –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
rem Double Float = 1.7E +/- 308 (15 digits)

function prettybackdrop()
 set current bitmap 0
 box 0,0,640,480,rgb(0,128,128),rgb(128,0,0),rgb(128,0,128),rgb(128,128,0)
 set text transparent
endfunction

Extra Source File dbproExample

examples/dbpro/tutorials/core/extra.dba · 9 lines (5 code)

Attached to Main Program (using the #INCLUDE command)

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Structure. 1 user function(s): ExtraFunction.

Commands used (2)

View source (9 lines)
rem Extra Source File
rem Attached to Main Program
rem (using the #INCLUDE command)

FUNCTION ExtraFunction
 PRINT "Hello - I am an Extra Function!"
 PRINT "Hit Any Key"
 WAIT KEY
ENDFUNCTION

Tutorials — Display

Display Showcase dbproExample

examples/dbpro/tutorials/display/display1.dba · 43 lines (25 code)

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 1 media file(s) from the example folder: backdrop.jpg.

Commands used (29)

View source (43 lines)
rem Display Showcase
bitsperpixel=screen depth()/8

rem Standard Setup Code for all examples
sync on : sync rate 0
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Load nice backdrop
load bitmap "backdrop.jpg"

rem Main loop
desc$="Direct Display Access"
do

rem Draw to the visual bitmap
ink rgb(0,0,0),0 : box 0,240,640,480
ink rgb(255,255,0),0 : circle mousex(),mousey(),8

rem Read from display and write elsewhere
lock backbuffer
ptr=get backbuffer ptr()
pitch=get backbuffer pitch()
adv=pitch*(get backbuffer height()/2)
chunk=(screen width()-40)*bitsperpixel
chunka#=wrapvalue(chunka#+8)
for y=0 to (get backbuffer height()/2)-1 step 2
 chunkx=20+((cos(wrapvalue(chunka#+(y*2))))*15)
 copy memory ptr+adv+(y*pitch)+(chunkx*bitsperpixel),ptr+(y*pitch),chunk
next y
unlock backbuffer

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Files

File Showcase dbproExample

examples/dbpro/tutorials/file/file1.dba · 92 lines (58 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame with automatic screen refresh.
  • Structure. 1 user function(s): prettybackdrop.
  • Data. 1 array(s) declared with DIM; 1 user-defined TYPE(s).

Commands used (23)

View source (92 lines)
rem File Showcase

rem Standard Setup Code for all examples
set text font "arial" : set text size 20
set text to bold : set text transparent

rem Arra to hold data
type pos x y endtype
dim coord(100) as pos

rem Mainloop
coordmax=0
do

rem a pretty backdrop
prettybackdrop()

rem Title
center text screen width()/2,20,"SIMPLE DATABASE OF CO-ORDINATES"
center text screen width()/2,screen height()-30,"Click To Draw Lines then Press [R] to Replay"

rem Show coords so far
for n=0 to coordmax-1
 dot coord(n).x,coord(n).y
next n

rem Record or Playback
if mouseclick()=1
 if cl=0
  coord(coordmax).x=mousex()
  coord(coordmax).y=mousey()
  inc coordmax : if coordmax>99 then coordmax=99
  cl=1
 endif
else
 cl=0
endif

rem Playback
if inkey$()="r"

 rem Save data
 if coordmax>0
  delete file "coordata.dat"
  open to write 1,"coordata.dat"
  write file 1,coordmax
  for n=0 to coordmax
   write file 1,coord(n).x
   write file 1,coord(n).y
  next n
  close file 1
 endif

 rem Clear data
 for n=0 to 100
  coord(n).x=0
  coord(n).y=0
 next n

 rem Load data
 open to read 1,"coordata.dat"
 read file 1,coordmax
 for n=0 to coordmax
  read file 1,coord(n).x
  read file 1,coord(n).y
 next n
 close file 1

 rem Draw data
 for n=0 to coordmax-1
  if n>0 then line nx,ny,coord(n).x,coord(n).y
  nx=coord(n).x
  ny=coord(n).y
  sleep 100
 next n
 sleep 2000

 rem Reset write ptr
 coordmax=0

 endif

rem Update screen
sync

rem Endloop
loop

rem Pretty Backdrop Function
function prettybackdrop()
 box 0,0,640,480,rgb(0,128,128),rgb(128,0,0),rgb(128,0,128),rgb(128,128,0)
endfunction

Tutorials — FTP

Ftp Showcase dbproExample

examples/dbpro/tutorials/ftp/ftp1.dba · 65 lines (46 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Structure. 1 user function(s): prettybackdrop; 2 GOSUB subroutine(s): _connect, _viewfiles.

Commands used (24)

View source (65 lines)
rem Ftp Showcase

rem Standard Setup Code for all examples
set text font "arial" : set text size 20
set text to bold : set text transparent

rem a pretty backdrop
prettybackdrop()

rem Title
center text screen width()/2,10,"FTP CONNECTION AND VIEW"

rem Connect to FTP
gosub _connect

rem View FTP Files
gosub _viewfiles

rem Disconnect from FTP
ftp disconnect

rem Wait for exit
print
print "Press Any Key To Exit"
wait key
end

_connect:
 url$="www.thegamecreators.com"
 user$="anonymous"
 pass$="me@isp.com"
 time#=timer()
 set cursor 0,30
 print "Connecting..." : sync
 ftp connect url$,user$,pass$
 if get ftp failure()=0
  time#=timer()-time#
  print "Connection established in ";time#/1000.0;" seconds."
 else
  print "Could not connect to ";url$
  print "Error:";get ftp error$()
  wait key
  end
 endif
return

_viewfiles:
 print "VIEW EACH FTP FILE IN A FOLDER"
 if get ftp status()=1
  print "FTP DIR:";get ftp dir$();"..." : sync
  ftp find first
  while get ftp file type()<>-1
   print "Type:";get ftp file type();
   print " Name:";get ftp file name$();
   print " Size:";get ftp file size()
   ftp find next
   sync
  endwhile
 endif
return

rem Pretty Backdrop Function
function prettybackdrop()
 box 0,0,640,480,rgb(0,128,128),rgb(128,0,0),rgb(128,0,128),rgb(128,128,0)
endfunction

Tutorials — Images

Image Showcase dbproExample

examples/dbpro/tutorials/image/image1.dba · 29 lines (14 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 1 media file(s) from the example folder: image.png.

Commands used (16)

View source (29 lines)
rem Image Showcase

rem Standard Setup Code for all examples
sync on : sync rate 0
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Load image
load image "image.png",1
desc$="Fast Image Pasting (1000 per cycle)"

rem Main loop
do

rem Paste a thousand images on screen per cycle
for t=1 to 1000
 paste image 1,rnd(680)-16,rnd(520)-32,1
next t

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Input

Input Showcase dbproExample

examples/dbpro/tutorials/input/input1.dba · 114 lines (70 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 5 media file(s) from the example folder: wall.png, hole.png, crosshair.png, fire.png, gun.wav.

Commands used (53)

View source (114 lines)
rem Input Showcase

rem Standard Setup Code for all examples
sync on : sync rate 120 : hide mouse
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Prepare Force Feedback (if available)
desc$="Machine Gun Joystick"
ForcePresent=0
empty checklist
PERFORM CHECKLIST FOR CONTROL DEVICES
for c=1 to checklist quantity()
 if checklist value a(c)=1
  SET CONTROL DEVICE checklist string$(c)
  ForcePresent=1
  desc$=desc$+" (with Force)"
 endif
next c

rem Load wall and images
set image colorkey 255,0,255
load bitmap "wall.png",1
load image "hole.png",1
load image "crosshair.png",2
load image "fire.png",3

rem Load sound
load sound "gun.wav",1
for t=2 to 10
 clone sound t,1
next t

rem Setup crosshair sprite
set current bitmap 0
set sprite 1,0,1
offset sprite 1,16,16
draw to back

rem Setup bullet sprite
sprite 2,-100,-100,1
set sprite 2,0,1
offset sprite 2,8,8
size sprite 2,16,16
set sprite alpha 2,128

rem Particle effect setup
autocam off : backdrop off
make particles 1,3,50,2.0
rotate particles 1,270,0,0
set particle speed 1,0.02

rem Set start pos
posx#=320
posy#=240

rem Main loop
do

rem Read joystick
posx#=posx#+(joystick x()/500.0)
posy#=posy#+(joystick y()/500.0)
posx=posx# : posy=posy#
fire=joystick fire a()

rem Paste backdrop
copy bitmap 1,0

rem Position crosshair
sprite 1,posx,posy,2

rem Make bullet hole if triggered
if fire=1 and cool=0

 rem Make bullet hole
 set current bitmap 1
 r#=rnd(359)
 rx=cos(r#)*rnd(20)
 ry=sin(r#)*rnd(20)
 paste sprite 2,posx+rx,posy+ry
 paste sprite 2,1000,1000
 set current bitmap 0

 rem Generate some particles
 position particles 1,0,0,5
 position particle emissions 1,(posx-320)/120.0,0,(240-posy)/120.0
 emis=2

 rem Hear machine gun
 cool=10
 for t=1 to 10
  if sound playing(t)=0 then play sound t : t=11
 next t

 rem Gun recoil
 if ForcePresent=1 then force shoot 100,100

endif
if cool>0 then dec cool

rem Control emissions
set particle emissions 1, emis
if emis>0 then dec emis

rem Show Framerate
ink rgb(255,255,255),0 : text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Lights

Light Showcase dbproExample

examples/dbpro/tutorials/light/light1.dba · 114 lines (80 code)

Choose better display mode

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 4 media file(s) from the example folder: music\hero.mp3, models\statue.x, models\bumpmap.png, world\room.x.

Commands used (47)

View source (114 lines)
rem Light Showcase

rem Choose better display mode
if check display mode(1024,768,32)=1
 set display mode 1024,768,32
else
 if check display mode(1024,768,16)=1
  set display mode 1024,768,16
 endif
endif

rem Standard Setup Code for all examples
sync on : sync rate 0 : backdrop off
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Load Hero music
load music "music\hero.mp3",1 : loop music 1

rem User prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load Statue Model
set normalization on
load object "models\statue.x",1
load image "models\bumpmap.png",1
xrotate object 1,270 : fix object pivot 1
set light mapping on 1,1
set object specular 1,0
rotate object 1,0,0,0

rem Load room
load object "world\room.x",2
xrotate object 2,270 : fix object pivot 2
set object specular 2,0
rotate object 2,0,0,0

rem Set dynamic light zero
hide light 0

rem Create pixie lights and dots
for l=1 to 7
 make light l
 set point light l,0,0,0
 set light range l,2000
 make object sphere 2+l,50 : ghost object on 2+l
 if l>1 then hide light l : hide object 2+l
next l

rem Main loop
desc$="Pixie Lights (Select keys 1-7)"
do

rem Control light visibility
k$=inkey$()
if k$>="1" and k$<="7"
 if keypress=0
  keypress=1
  li=1+(asc(k$)-asc("1"))
  if light visible(li)=1
   hide light li : hide object 2+li
  else
   show light li : show object 2+li
  endif
  c#=wrapvalue(180+(a#+(li*85)))
 endif
else
 keypress=0
endif

rem Rotate around model
a#=wrapvalue(a#+0.5)
b#=wrapvalue(b#+0.2)
c#=wrapvalue(c#+0.05)
x#=cos(c#)*250.0
z#=sin(c#)*300.0
position light 0,x#,150,z#
position camera x#,100,z#
point camera 0,150,0

rem Rotate lights around model
for l=1 to 7
 x#=cos(a#+(l*85))*300.0
 z#=sin(a#+(l*85))*150.0
 position light l,x#,100+(sin(b#)*100),z#
 position object 2+l,x#,100+(sin(b#)*100),z#
next l

rem Alter light colours over time
leva#=wrapvalue(leva#+0.01)
level#=cos(leva#)
for l=1 to 7
 col=127.0+(127.0*level#)
 rev=col*-1
 if l=1 then color light l,col,rev,rev
 if l=2 then color light l,128,col,128
 if l=3 then color light l,255,255,col*2
 if l=4 then color light l,col,rev,col
 if l=5 then color light l,col,col,col
 if l=6 then color light l,500,500,500
 if l=7 then color light l,rev*3,rev*3,rev*3
next l

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Matrices

Matrix Showcase dbproExample

examples/dbpro/tutorials/matrix/matrix1.dba · 80 lines (58 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 2 media file(s) from the example folder: face.jpg, water.png.

Commands used (33)

View source (80 lines)
rem Matrix Showcase

rem Standard Setup Code for all examples
sync on : sync rate 0 : color backdrop 0
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Create matrix
load image "face.jpg",1
load image "water.png",2
for m=1 to 2
 if m=1 then s=200
 if m=2 then s=100
 make matrix m,s,s,36,36
 if m=1 then position matrix m,-50,20,-50
 if m=2 then position matrix m,0,120,0
 prepare matrix texture m,m,36,36
 ghost matrix on m
 tc=1
 for z=35 to 0 step -1
  x=0
  while x<=35
   set matrix tile m,x,z,tc
   inc tc : inc x
  endwhile
 next z
next m

rem Setup light
set point light 0,50,500,50
color light 0,1000,1000,200

rem Setup camera
position camera 50,170,50
point camera 50,0,50

rem Main loop
desc$="Water Matrix (Hit Space)"
do

rem Space controls wireframe
if spacekey()=1
 if wr=0
  wrstate=1-wrstate
  if wrstate=0 then set matrix wireframe off 1 : set matrix wireframe off 2
  if wrstate=1 then set matrix wireframe on 1 : set matrix wireframe on 2
  wr=1
 endif
else
 wr=0
endif

rem Control matrix like water
for m=1 to 2
 a#=wrapvalue(a#+1)
 for z=0 to 36
  for x=0 to 36
   x#=cos(a#+(x*10))
   y#=sin(a#+(z*10))
   nx#=0.0-(cos(a#+(x*10))*0.25)
   nz#=0.0-(sin(a#+(z*10))*0.25)
   ny#=1.0-nx#-nz#
   set matrix height m,x,z,(x#+y#)*15.0
   set matrix normal m,x,z,nx#,ny#,nz#
  next x
 next z
 update matrix m
next m

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Memblocks

Memblocks Showcase dbproExample

examples/dbpro/tutorials/memblocks/memblocks1.dba · 54 lines (25 code)

Requires 640x480x16 fullscreen

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Data. 1 array(s) declared with DIM.
  • Assets. Loads 1 media file(s) from the example folder: groovy.jpg.

Commands used (12)

View source (54 lines)
rem Memblocks Showcase

rem Requires 640x480x16 fullscreen
sync on : sync rate 60 : hide mouse

rem Create array for wavedata
dim wave_table(72)
for i = 1 to 72
   wave_table(i) = int(sin(i*5)*20.0)
next i

rem Load the first image and store it in memblock 1
load bitmap "groovy.jpg",0
make memblock from bitmap 1,0
make memblock from bitmap 2,0

rem Required variables
linesize = 640 * 2
topI = 0

rem Main loop
while mouseclick()=0

 rem Wrap topI variable
 topI = topI + 1
 if topI > 72 then topI = 1
 rollingI = topI

 rem For each vertical position
 for i = 0 to 479

 rem Calculate positions
 fromposition = 52 + (i*linesize)
 toposition = fromposition+(wave_table(rollingI)*2)

 rem Copy data from one area of memblock to another memblock
 copy memblock 1,2,FromPosition,ToPosition,1200

 rem Advance roll effect
 rollingI = rollingI+1
 if rollingI > 72 then rollingI = 1

next i

rem Update screen with memblock containing wave-bitmap
make bitmap from memblock 0,2 : sync

rem End loop
endwhile

rem Remove the memblocks before we exit
delete memblock 1
delete memblock 2

Tutorials — Multiplayer

Multiplayer Showcase dbproExample

examples/dbpro/tutorials/multiplayer/multiplayer1.dba · 71 lines (46 code)

Load backdrop and blob

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 2 media file(s) from the example folder: face.png, blob.png.

Commands used (24)

View source (71 lines)
rem Multiplayer Showcase

rem Load backdrop and blob
load image "face.png",1 : load image "blob.png",2

rem Start net game
text 20,20,"Getting net game.." : sync

rem Init
sync on : sync rate 80 : draw to back

rem Start net game
PlayerNumber=default net game("gamename","playername",4,1)
if net game exists()=1

 rem Show name of player as Window Title
 if PlayerNumber=1
  set window title "HOST Player "+str$(PlayerNumber)
 else
  set window title "CLIENT Player "+str$(PlayerNumber)
 endif

 rem Launch three more sessions as a demo
 if PlayerNumber=1
  cls 0
  okok=0
  while okok=0
   text 20,20,"Make sure Firewall is configured."
   text 20,35,"Launch More MP.EXE clients to"
   text 20,50,"see multiplayer in action!"
   text 20,65,"Remember to enter your local IP"
   text 20,80,"to HOST or JOIN a network game"
   text 20,95,"(i.e. 192.168.0.1)"
   text 20,110,"Press Any Key"
   tscancode=scancode()
   if tscancode=31 then okok=1
   if tscancode<>0 then okok=2
   sync
  endwhile
 endif

 rem Main loop
 do

  rem Draw Backdrop and handle player blob
  paste image 1,0,0
  send net message integer 0,mousex()+(mousey()*640)
  sprite PlayerNumber, mousex()-32, mousey()-32, 2

  rem Draw Others
  get net message
  while net message exists()=1
   PositionValue=net message integer()
   OtherNumber=net message player from()
   OtherY=PositionValue/640
   OtherX=PositionValue-(OtherY*640)
   sprite OtherNumber, OtherX, OtherY, 2
   get net message
  endwhile

  rem Update and/or Quit key
  sync : if escapekey()=1 then exit

 loop

 rem End net game
 free net game

else
 do : cls 0 : center text 160,113,"COULD NOT CREATED NET GAME" : sync : loop
endif

Tutorials — Music

Music Showcase dbproExample

examples/dbpro/tutorials/music/music1.dba · 100 lines (70 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 9 media file(s) from the example folder: world\room.x, models\harp\harp.x, models\trumpet\trumpet.x, models\piano\piano2.x, models\mandolin\mandolin.x, music\space.mp3 (+3 more).

Commands used (39)

View source (100 lines)
rem Music Showcase

rem Standard Setup Code for all examples
sync on : sync rate 240 : backdrop off
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load room
load object "world\room.x",1
xrotate object 1,270
fix object pivot 1
rotate object 1,0,0,0
set object specular 1,0

rem Load for selection
for t=2 to 5
 if t=2 then load object "models\harp\harp.x",t : tx=-100 : ta=135
 if t=3 then load object "models\trumpet\trumpet.x",t : tx=-200 : ta=90
 if t=4 then load object "models\piano\piano2.x",t : tx=100 : ta=315
 if t=5 then load object "models\mandolin\mandolin.x",t : tx=-150 : ta=90
 position object t,tx,0,40-(((t-3)*80))
 rotate object t,270,ta,0
 scale object t,25,25,25
 fix object pivot t
 rotate object t,0,180,0
 set object specular t,0
next t

rem Load music
load music "music\space.mp3",1 : loop music 1
load music "music\misty.mp3",2
load music "music\fun.mp3",3
load music "music\hero.mp3",4

rem Setup camera and light
set point light 0,0,0,0
position camera -450,100,10
yrotate camera 90

rem Select first globe (via Xangle trigger)
xrotate object 2,1

rem Main loop
desc$="Music Room (Select An Instrument)"
do

rem Control mouse selector
if mouseclick()=1
 sel=0
 if mousex()>70 and mousex()<600
   sel=1+((mousex()-70)/(530/4))
   if sel>4 then sel=4
 endif
 if sel>0
  for t=2 to 5
   if t<>(1+sel) and object angle x(t)=1
    xrotate object t,0
   if t=2 then stop music 1
   if t=3 then stop music 2
   if t=4 then stop music 3
   if t=5 then stop music 4
   endif
  next t
  if object angle x(1+sel)=0
   xrotate object 1+sel,1
   if sel=1 then loop music 1
   if sel=2 then loop music 2
   if sel=3 then loop music 3
   if sel=4 then loop music 4
  endif
 endif
endif

rem Control selected sphere
for t=2 to 5
 a#=wrapvalue(object angle y(t)+1)
 if object angle x(t)=0 and a#=1.0 then a#=0
 yrotate object t,a#
 a#=object angle y(t)
 position object t,object position x(t),50-(cos(a#)*50),40-(((t-3)*80))
 if object angle x(t)=1 then lightz#=object position z(t) : lighty#=object position y(t)
next t

rem Control light
position light 0,-250,lighty#+50,lightz#

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Particles

Particles Showcase dbproExample

examples/dbpro/tutorials/particles/particles1.dba · 64 lines (43 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 3 media file(s) from the example folder: fire.png, sky\spacesphere.png, sky\ss.x.

Commands used (41)

View source (64 lines)
rem Particles Showcase

rem Standard Setup Code for all examples
sync on : sync rate 0 : color backdrop rgb(0,128,0)
set text font "arial" : set text size 16
set text to bold : set text transparent
backdrop off

rem Load image
ImageNumber=1 : load image "fire.png",ImageNumber
ImageNumberB=2 : load image "sky\spacesphere.png",ImageNumberB

rem Make objects
load object "sky\ss.x",1
scale object 1,150,150,150
set object 1,1,1,1,1,0,0,0
set object texture 1,2,1
set camera range 1,10000
position object 1, 0, 3, 0
yrotate object 1,180
make object box 2,100,20,50
position object 2,0,-25,50
texture object 2,ImageNumberB
ghost object on 2,2

rem Make particles
ParticleNumber=1
make particles ParticleNumber, ImageNumber, 50, 20.0
position particles ParticleNumber, 0, -28, 0
color particles ParticleNumber, 255, 128, 0
set particle emissions ParticleNumber, 10
set particle speed ParticleNumber, 0.01
set particle gravity ParticleNumber, 2

rem Setup camera
position camera 0,3,0
point camera 0,3,400

rem Main loop
desc$="Sparkler Effect (Use Mouse Buttons)"
do

rem Spark Drawing
changetoparticlescaling#=10.0
position particle emissions ParticleNumber, (mousex()-320)*changetoparticlescaling#/40.0, (360-mousey())*changetoparticlescaling#/40.0, 10*changetoparticlescaling#
if mouseclick()>1 then color particles ParticleNumber, rnd(255), rnd(255), rnd(255)
if mouseclick()=1 or mouseclick()=3
 set particle emissions ParticleNumber, 10
 set particle velocity ParticleNumber, 4
else
 set particle emissions ParticleNumber, 1
 set particle velocity ParticleNumber, 1
endif

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Sound

Sound Showcase dbproExample

examples/dbpro/tutorials/sound/sound1.dba · 87 lines (57 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Assets. Loads 6 media file(s) from the example folder: world\room.x, models\notes\notes.x, sound\ghost.wav, sound\hit.wav, sound\smash.wav, sound\tube.wav.

Commands used (36)

View source (87 lines)
rem Sound Showcase

rem Standard Setup Code for all examples
sync on : sync rate 240 : backdrop off
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load room
load object "world\room.x",1
xrotate object 1,270
fix object pivot 1
rotate object 1,0,180,0
set object specular 1,0

rem Load selectors
for t=2 to 5
 load object "models\notes\notes.x",t
 position object t,-100,32,40-(((t-3)*80))
 rotate object t,270,90,0
 scale object t,50,50,50
 fix object pivot t
 rotate object t,0,0,0
 set object specular t,0
next t

rem Load sound
load sound "sound\ghost.wav",1
load sound "sound\hit.wav",2
load sound "sound\smash.wav",3
load sound "sound\tube.wav",4

rem Setup camera and light
set point light 0,0,0,0
position camera -450,100,10
set camera fov 45
yrotate camera 90

rem Select first note (via Xangle trigger)
yrotate object 2,1

rem Main loop
desc$="Sound Room (Select A Note)"
do

rem Control mouse selector
if mouseclick()=1
 sel=0
 if mousex()>70 and mousex()<600
   sel=1+((mousex()-70)/(530/4))
   if sel>4 then sel=4
 endif
 if sel>0
  if object angle y(1+sel)=0
   yrotate object 1+sel,1
   if sel=1 then play sound 1
   if sel=2 then play sound 2
   if sel=3 then play sound 3
   if sel=4 then play sound 4
  endif
 endif
endif

rem Control selected
for pace=0 to 9
 for t=2 to 5
  if object angle y(t)>0 then rotate object t,0,wrapvalue(object angle y(t)+1),0
  if object angle y(t)>0 then lightz#=object position z(t) : lighty#=object position y(t)
 next t
next pace

rem Control light
position light 0,-200,lighty#,lightz#

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Tutorials — Sprites

Sprite Showcase dbproExample

examples/dbpro/tutorials/sprite/sprite1.dba · 83 lines (53 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Data. 1 array(s) declared with DIM.
  • Assets. Loads 3 media file(s) from the example folder: animspr.png, ship.png, backdrop.png.

Commands used (27)

View source (83 lines)
rem Sprite Showcase

rem Standard Setup Code for all examples
sync on : sync rate 240 : backdrop on : color backdrop 0

rem Load images
set image colorkey 255,0,255
create animated sprite 1, "animspr.png", 4, 4, 16
load image "ship.png",2
load image "backdrop.png",3

rem Setup backdrop sprite
sprite 1001,0,0,3 : sprite 1002,0,0,3
set sprite priority 1001,0 : set sprite priority 1002,0
size sprite 1001,1024,1024 : size sprite 1002,1024,1024

rem Setup asteroid sprite
sprite 1,320,240,16 : size sprite 1,128,128 : offset sprite 1,64,64

rem Array for finer asteroid data
dim ast#(100)

rem Copy animating sprite
for t=2 to 99
 clone sprite 1,t
 sprite t,rnd(640+256)-128,rnd(1400)-400,16
 ast#(t)=sprite y(t)
 rotate sprite t,rnd(350)
 set sprite frame t,rnd(15)
 set sprite t,0,1
 a#=rnd(350) : s#=32
 sss#=64+(cos(a#)*s#)
 size sprite t,sss#,sss#
 offset sprite t,sss#/2,sss#/2
 if t<50
  set sprite priority t,1
 else
  set sprite priority t,3
 endif
next t

rem Setup ship sprite
sprite 100,200,140,2
set sprite priority 100,2

rem Backdrop shift
shiftx#=0

rem Main loop
do

 rem Move backdrop
 shiftx#=shiftx#+2.0
 sya#=wrapvalue(sya#+0.1)
 sy#=-260+(cos(sya#)*260)
 if shiftx#>1024.0 then shiftx#=shiftx#-1024
 sprite 1001,0-shiftx#,sy#,3 : sprite 1002,1024-shiftx#,sy#,3

 rem Control sprite auto-animation
 for t=1 to 99
  a#=wrapvalue(sprite angle(t)+1+rnd(2))
  rotate sprite t,90
  move sprite t,-3.0
  ast#(t)=ast#(t)-(sin(sya#)*0.3)
  if sprite x(t)<-128 then move sprite t,(640+256) : a#=rnd(350)
  sprite t,sprite x(t),ast#(t),sprite image(t)
  play sprite t,1,16,50
  rotate sprite t,a#
 next t

 rem Glide ship
 g#=wrapvalue(g#+1)
 h#=wrapvalue(h#+0.5)
 sprite 100,200,140+(sin(g#)*10),2
 scale sprite 100,100+sin(h#)*20.0
 rotate sprite 100,sin(sya#)*10.0

 rem Update screen
 sync

rem End loop
loop

Tutorials — System

System Showcase dbproExample

examples/dbpro/tutorials/system/system1.dba · 78 lines (59 code)

Screen transitions written in plain BASIC: a wipe, venetian blinds, a box zoom and a sprite cross-fade between two pictures, timed with TIMER(). Rewritten for OpenDBC (MIT licence); the pictures come from the Dark-Basic-Pro help examples (MIT, The Game Creators Ltd).

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Assets. Loads 2 media file(s) from the example folder: screen1.jpg, screen2.jpg.

Commands used (21)

View source (78 lines)
rem System Showcase
rem Screen transitions written in plain BASIC: a wipe, venetian blinds, a box
rem zoom and a sprite cross-fade between two pictures, timed with TIMER().
rem Rewritten for OpenDBC (MIT licence); the pictures come from the
rem Dark-Basic-Pro help examples (MIT, The Game Creators Ltd).

sync on : sync rate 60
backdrop off

load bitmap "screen1.jpg", 1
load bitmap "screen2.jpg", 2
w = bitmap width(1)
h = bitmap height(1)
steps = 45

rem The second picture is also kept as an image for the sprite cross-fade
load image "screen2.jpg", 1

copy bitmap 1, 0
sync

for effect = 1 to 4
   start = timer()
   rem Effects alternate between the two pictures
   if effect mod 2 = 1
      source = 1 : target = 2
   else
      source = 2 : target = 1
   endif

   for stepnum = 1 to steps
      progress# = stepnum / (steps * 1.0)
      copy bitmap source, 0
      select effect
         case 1
            rem Wipe from left to right
            x = int(w * progress#)
            if x > 0 then copy bitmap target, 0, 0, x, h, 0, 0, 0, x, h
         endcase
         case 2
            rem Venetian blinds: eight bands open together
            band = h / 8
            opened = int(band * progress#)
            for b = 0 to 7
               top = b * band
               if opened > 0 then copy bitmap target, 0, top, w, top + opened, 0, 0, top, w, top + opened
            next b
         endcase
         case 3
            rem Box zoom from the centre
            hw = int(w * progress# / 2) : hh = int(h * progress# / 2)
            if hw > 0 and hh > 0
               left = w / 2 - hw : top = h / 2 - hh
               copy bitmap target, left, top, left + hw * 2, top + hh * 2, 0, left, top, left + hw * 2, top + hh * 2
            endif
         endcase
         case 4
            rem Cross-fade: the target picture is a sprite whose alpha rises
            sprite 1, 0, 0, 1
            set sprite alpha 1, int(255 * progress#)
         endcase
      endselect
      ink rgb(255, 255, 255), 0
      text 8, 8, "Effect " + str$(effect) + " of 4"
      sync
   next stepnum

   if effect = 4 then delete sprite 1
   copy bitmap target, 0
   elapsed = timer() - start
   text 8, 24, "Last transition: " + str$(elapsed) + " ms at depth " + str$(screen depth())
   sync
next effect

delete bitmap 1
delete bitmap 2
delete image 1
end

Tutorials — Text

Text Showcase dbproExample

examples/dbpro/tutorials/text/text1.dba · 60 lines (37 code)

Declaration for function

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.
  • Structure. 1 user function(s): prettybackdrop.

Commands used (22)

View source (60 lines)
rem Text Showcase

rem Declaration for function
global sinwave#

rem Standard Setup Code for all examples
sync on : sync rate 0

rem Setup Font
set text font "book" : set text size 20
set text to bold : set text transparent

rem Scroll text
string$=space$(36)
string$=string$+"Dark Basic Professional gives you the power of past ages as well as the bounty of future technologies..."
string$=string$+space$(10)

rem Main loop
desc$="Retro Text Scroller"
do

rem Nice backdrop
prettybackdrop()

rem Scrolling text
spacer=spacer+1
if spacer>20
 spacer=0 : scx=scx+1
 if scx>len(string$) then scx=0
endif
sinwave#=wrapvalue(sinwave#+1)
for x=0 to 32
 if 1+x+scx<=len(string$) then a$=mid$(string$,1+x+scx) else a$=mid$(string$,(1+x+scx)-len(string$))
 text (x*20)-spacer,220-(cos(sinwave#+((x+scx)*10))*50),upper$(a$)
next x

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

function prettybackdrop()
 yy=0
 red=rgb(128+(cos(sinwave#)*127),0,0)
 green=rgb(0,128-(sin(sinwave#)*127),0)
 for y=0 to 49
  col=1-col
  ys=10
  if col=0 then box 0,yy,640,yy+ys,green,red,green,red
  if col=1 then box 0,yy,640,yy+ys,red,green,red,green
  yy=yy+ys
 next y
endfunction

Tutorials — World & terrain

World3D Showcase dbproExample

examples/dbpro/tutorials/world/world1.dba · 41 lines (19 code)

Standard Setup Code

How it is built

  • Program shape. Frame-driven: a main do … loop runs every frame under sync on, so the program calls sync itself to present each frame.

Commands used (27)

View source (41 lines)
rem World3D Showcase

rem Standard Setup Code
sync on : sync rate 0 : color backdrop rgb(0,0,64) : backdrop on
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Set camera
set camera range 0.1,5000
position camera 2,3,2
rotate camera 0,45,0

rem Load BSP world
load bsp "ikzdm1.pk3","ikzdm1.bsp"
set bsp camera collision 1,0,0.75,0
set bsp collision threshhold 1,0.001

rem Main loop
desc$="BSP in One Command"
do

rem Control camera automatically
control camera using arrowkeys 0,0.1,1

rem Apply simple gravity to camera
position camera camera position x(),camera position y()-0.1,camera position z()

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
loop

Terrain Functionality dbproExample

examples/dbpro/tutorials/world/world2.dba · 77 lines (48 code)

Standard Setup Code for all examples

How it is built

  • Program shape. Linear: runs once from top to bottom.
  • Assets. Loads 3 media file(s) from the example folder: land.png, grass.jpg, sky\sb.x.

Commands used (39)

View source (77 lines)
rem Terrain Functionality

rem Standard Setup Code for all examples
sync on : sync rate 0 : color backdrop 0
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Make Simple Terrain
TerrainNumber=1
make terrain TerrainNumber,"land.png"

rem Position The Terrain
position terrain TerrainNumber, 0, 0, 1025

rem Texture terrain
ImageNumber=1
load image "grass.jpg",ImageNumber
texture terrain TerrainNumber,ImageNumber
size#=1025

rem Load sky object
load object "sky\sb.x",1
scale object 1,40,40,40
set object cull 1,0
set object light 1,0
set object texture 1,2,1

rem Position camera in center of terrain
position camera 512,10,512

rem Main loop
desc$="LOD Terrain from Bitmap"
while mouseclick()=0

rem Control camera over terrain
control camera using arrowkeys 0,1,1
cx#=camera position x(0)
cz#=camera position z(0)
if cx#<0.0 then cx#=0
if cx#>size# then cx#=size#
if cz#<0.0 then cz#=0
if cz#>size# then cz#=size#
position camera cx#,get terrain height(TerrainNumber,cx#,cz#)+5,cz#

rem Terrain Data
set cursor 0,0
print "TERRAIN DATA"
print " exist:";terrain exist(TerrainNumber)
if terrain exist(TerrainNumber)=1
 print " x:";terrain position x(TerrainNumber)
 print " y:";terrain position y(TerrainNumber)
 print " z:";terrain position z(TerrainNumber)
 print " height:";get terrain height(TerrainNumber, cx#, cz#)
 print " totalheight:";get total terrain height(TerrainNumber)
endif
print
print "CAMERA DATA"
print " x:";camera position x(0)
print " y:";camera position y(0)
print " z:";camera position z(0)

rem Position sky at player
position object 1,camera position x(0),camera position y(0)-150,camera position z(0)

rem Show Framerate
text 20,screen height()-40,desc$
fps$="DBPro Fps: "+str$(screen fps())
text screen width()-20-text width(fps$),screen height()-40,fps$

rem Update screen
sync

rem End loop
endwhile

rem Delete Terrain
delete terrain TerrainNumber