This isn't exactly a program of game, but an aid to help you develop your games (DBPro only) and I'm finding it very useful in my current project.
What it does
It creates map data that can easily be loaded into your game.
How does it do it?
The map data can be stored in a text file (which can be made in notepad or anything you wish). It consists of commands that load objects and alter them in anyway you wish, and once they've been loaded into your project, they can then be controlled however you like. The map can simply be imported into DBPro by calling the function:
name$=loadMap("MapName.txt")
(the name of the map is returned, but you obviously don't have to get it)
What does the data look like?
As I said, it's simply like a programming language, but not like DarkBASIC or any of the sort, here's an example of creating a sphere:
//Make a sphere
ADD Sphere
{
Pos X
Pos Y
Pos Z
Ang X
Ang Y
Ang Z
Size X
Size Y
Size Z
}
This will obviously create a sphere, at a certain point in 3D space, with an angle and size. There are extra commands for texturing and stuff.
What's the point when there's the DB commands?
Well, imagine making your game, and you need to change lecvel many times, it's a pain doing it like this:
if level=1
delete object 1
delete object 2
etc...
load object "level2-bin.x",1 : position object 1,100,0,100
endif
Which could go on forever, when you can just do this:
if level<>oldLevel
deleteMap() : loadMap("Level"+str$(level)+".txt")
endif
And that's the whole level changing bit done.
Now you may be thinking, "but you have to make lots of code in the text file anyway". Well, with this it is possible to:
1) Make your levels dynamic
2) Make your game modable
3) Make an editor which exports the code
4) Above all, keep your game code
organised
Commands and Syntax
I already showed you one example of a command, here are them all, incase you're interested.
NAME
{
Map Name
}
SET World
{
Ambient Light
Amb. L. Color Red
Amb. L. Color Green
Amb. L. Color Blue
Backdrop Red
Backdrop Green
Backdrop Blue
Fogging as boolean
Fog Distance
Fog Red
Fog Green
Fog Blue
}
ADD Object
{
Object Directory
Image Directory
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
SizeZ
}
ADD Sphere
{
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
SizeZ
}
ADD Cone
{
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
SizeZ
}
ADD Cube
{
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
SizeZ
}
ADD Cylinder
{
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
SizeZ
}
ADD Plain
{
PosX
PosY
POsZ
AngX
AngY
AngZ
SizeX
SizeY
}
ADD Triangle
{
X1
Y1
Z1
X2
Y2
Z2
X3
Y3
Z3
}
SET Object Alpha
{
Entity number (you'll just have to count them)
Alpha Value
}
SET Object Reflection
{
Entity number
}
SET Object Texture
{
Entity number
Image Directory
}
ADD PointLight
{
PosX
PosY
PosZ
Color Red
Color Green
Color Blue
Range
}
And that's them all so far. You may have noticed to set an entity's alpha, reflection or texture, you have to number it, well, for that you just count down through the entities.
The functions
There are many functions used for this, but you will only need a few:
startUp() - place at the top of code
Return String=loadMap(Map$) - used to load the map (the string is the map name)
DeleteMap() - Delete's the map
Return Integer=GetEntityObject(Entity) - input an entity number, and it will return the object number used for that entity, used for changing the object, or even using it during gameplay.
Return Integer=GetEntityLight(Entity) - Same as the previous, but for light numbers.
Example Program
Here's an example program for you, which comes with the functions and the script for a map, don't ask me what it's ment to be, because I don't know
DBPro Code + Functions:
`-MapScript V1
`setup
sync on : sync rate 60
set display mode 1024,768,32 : hide mouse
autocam off : set camera range 1,0x7fffffff
set normalization on
startUp()
`load a map
name$=loadMap("map1.txt")
`Camera
Dist#=500
AngX#=225
AngY#=45
`Main Loop
Do
`Control
AngX#=wrapvalue(AngX#+mousemovey())
AngY#=wrapvalue(AngY#+mousemovex())
if mouseclick()=1 then dec Dist#,2
if mouseclick()=2 then inc Dist#,2
cx#=sin(AngY#)*cos(angX#)*Dist#
cy#=-sin(AngX#)*Dist#
cz#=cos(AngY#)*cos(angX#)*Dist#
position camera cx#,cy#,cz#
rotate camera 180+AngX#,AngY#,0
`User Info
text 10,10,"Fps: "+str$(screen fps())
text 10,30,"Map Name: "+name$
text 10,100,"Move Mouse to Rotate Camera"
text 10,120,"RMB to zoom in, LMB to zoom out"
Sync
Loop
`Functions
function startUp()
dim objTaken(0) as boolean
dim imgTaken(0) as boolean
dim lgtTaken(0) as boolean
dim entObj(0) as integer
dim entLgt(0) as integer
endfunction
function loadMap(map as string)
local com as string
local brace as string
local objDir as string
local imgDir as string
local var as string
local done as boolean
local ents as integer
open to read 1,map
repeat
if file end(1)=1
done=1
else
read string 1,com
if left$(com,2)<>"//" or left$(com,1)<>"`" or lower$(left$(com,3))<>"rem"
if lower$(com)="name"
read string 1,brace
read string 1,name$
read string 1,brace
endif
if lower$(com)="set world"
read string 1,brace
read string 1,var : var=removeSpace(var) : amb=val(var)
read string 1,var : var=removeSpace(var) : ar=val(var)
read string 1,var : var=removeSpace(var) : ag=val(var)
read string 1,var : var=removeSpace(var) : ab=val(var)
read string 1,var : var=removeSpace(var) : bckr=val(var)
read string 1,var : var=removeSpace(var) : bckg=val(var)
read string 1,var : var=removeSpace(var) : bckb=val(var)
read string 1,var : var=removeSpace(var) : fog=val(var)
read string 1,var : var=removeSpace(var) : frng=val(var)
read string 1,var : var=removeSpace(var) : fr=val(var)
read string 1,var : var=removeSpace(var) : fg=val(var)
read string 1,var : var=removeSpace(var) : fb=val(var)
read string 1,brace
setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
endif
if lower$(com)="add sphere"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
o=addSphere(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cube"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCube(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cone"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCone(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cylinder"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCylinder(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add plain"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,brace
addPlain(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#)
endif
if lower$(com)="add triangle"
read string 1,brace
read string 1,var : var=removeSpace(var) : x1#=val(var)
read string 1,var : var=removeSpace(var) : y1#=val(var)
read string 1,var : var=removeSpace(var) : z1#=val(var)
read string 1,var : var=removeSpace(var) : x2#=val(var)
read string 1,var : var=removeSpace(var) : y2#=val(var)
read string 1,var : var=removeSpace(var) : z2#=val(var)
read string 1,var : var=removeSpace(var) : x3#=val(var)
read string 1,var : var=removeSpace(var) : y3#=val(var)
read string 1,var : var=removeSpace(var) : z3#=val(var)
read string 1,brace
addTriangle(x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#)
endif
if lower$(com)="add object"
read string 1,brace
read string 1,objDir : objDir=removeSpace(objDir)
read string 1,imgDir : imgDir=removeSpace(imgDir)
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addObject(objDir,imgDir,posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add pointlight"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : red=val(var)
read string 1,var : var=removeSpace(var) : green=val(var)
read string 1,var : var=removeSpace(var) : blue=val(var)
read string 1,var : var=removeSpace(var) : range#=val(var)
read string 1,brace
addLight(posx#,posy#,posz#,range#,rgb(red,green,blue))
endif
if lower$(com)="set object texture"
read string 1,brace
read string 1,var : var=removeSpace(var) : ent=val(var)
read string 1,imgDir : imgDir=removeSpace(imgDir)
read string 1,brace
setEntityTexture(ent,imgDir)
endif
if lower$(com)="set object alpha"
read string 1,brace
read string 1,var : var=removeSpace(var) : ent=val(var)
read string 1,var : var=removeSpace(var) : alpha=val(var)
read string 1,brace
setEntityAlpha(ent,alpha)
endif
if lower$(com)="set object reflection"
read string 1,brace
read string 1,var : var=removeSpace(var) : ent=val(var)
read string 1,brace
setEntityReflection(ent)
endif
endif
endif
until done
close file 1
endfunction name$
function deleteMap()
local oents as integer : oents=array count(entObj())
local lents as integer : lents=array count(entLgt())
for e=1 to oents
delete object entobj(e)
next e
for e=1 to lents
delete light entlgt(e)
next e
fog off
set ambient light 50
color ambient light 0
color backdrop 0
endfunction
function setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
set ambient light amb
color ambient light rgb(ar,ag,ab)
backdrop on : color backdrop rgb(bckr,bckg,bckb)
if fog=1
fog on
fog distance frng
fog color rgb(fr,fg,fb)
else
fog off
endif
endfunction
function addSphere(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object sphere oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCube(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cube oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCone(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cone oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCylinder(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cylinder oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addPlain(x#,y#,z#,ax#,ay#,az#,sx#,sy#)
local oNum as integer
oNum=freeObject()
make object plain oNum,sx#,sy#
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addTriangle(x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#)
local oNum as integer
oNum=freeObject()
make object triangle oNum,x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addObject(obj$,img$,x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
local iNum as integer
oNum=freeObject()
iNum=freeImage()
if lower$(removeSpace(img$))<>"void" then load image img$,iNum
if lower$(removeSpace(obj$))<>"void" then load object obj$,oNum : if image exist(iNum) then texture object oNum,iNum
set object normals oNum
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addLight(x#,y#,z#,r#,col)
local lNum as integer
lNum=freeLight()
make light lNum
set point light lNum,x#,y#,z#
set light range lNum,r#
color light lNum,col
endfunction lNum
function getEntityObject(ent)
local obj as integer
obj=entObj(ent)
endfunction obj
function getEntityLight(ent)
local lgt as integer
lgt=entLgt(ent)
endfunction lgt
function setEntityTexture(ent,img$)
local oNum as integer
local iNum as integer
oNum=getEntityObject(ent)
iNum=freeImage()
load image img$,iNum
if image exist(iNum) then texture object oNum,iNum
endfunction
function setEntityAlpha(ent,alpha)
local oNum as integer : oNum=getEntityObject(ent)
set object transparency oNum,3
set alpha mapping on oNum,alpha
endfunction
function setEntityReflection(ent)
local oNum as integer
oNum=getEntityObject(ent)
set reflection shading on oNum
endfunction
function removeSpace(st$)
local length as integer : length=len(st$)
for i=0 to length
let$=mid$(st$,i)
if let$<>" "
new$=new$+let$
endif
next i
endfunction new$
function freeObject()
local Num as integer
array insert at bottom objTaken() : num=array count(objTaken())
if object exist(num)=0 and objTaken(num)=0
objTaken(num)=1 : exitfunction num
endif
endfunction 0
function freeImage()
local Num as integer
array insert at bottom imgTaken() : num=array count(imgTaken())
if image exist(num)=0 and imgTaken(num)=0
imgTaken(num)=1 : exitfunction num
endif
endfunction 0
function freeLight()
local Num as integer
array insert at bottom lgtTaken() : num=array count(lgtTaken())
if light exist(num)=0 and lgtTaken(num)=0
lgtTaken(num)=1 : exitfunction num
endif
endfunction 0
MapScript Code
// Name Level
NAME
{
~Test Map~
}
// Set World
SET World
{
30
255
0
255
0
0
0
0
0
0
0
0
}
// Add Objects
ADD Sphere
{
-50
0
0
0
0
0
100
100
100
}
ADD Cone
{
-50
62
0
0
0
0
100
100
100
}
ADD Cube
{
50
0
0
0
0
0
100
100
100
}
ADD Cylinder
{
50
0
0
90
0
0
20
300
20
}
ADD Triangle
{
0
50
0
105
85
0
100
50
0
}
//Ground
ADD Plain
{
0
-100
0
90
0
0
500
500
}
// Add Lights
ADD PointLight
{
0
100
0
255
0
0
2000
}
ADD PointLight
{
0
-100
0
0
0
255
1500
}
ADD PointLight
{
0
0
150
255
0
0
1500
}
ADD PointLight
{
0
0
-150
0
255
0
1500
}
//Create markers for lights
ADD Sphere
{
0
100
0
0
0
0
5
5
5
}
ADD Sphere
{
0
-100
0
0
0
0
5
5
5
}
ADD Sphere
{
0
0
150
0
0
0
5
5
5
}
ADD Sphere
{
0
0
-150
0
0
0
5
5
5
}
//Make markers see-through
SET Object Alpha
{
7
50
}
SET Object Alpha
{
8
50
}
SET Object Alpha
{
9
50
}
SET Object Alpha
{
10
50
}
Last Words
You can put comments in your code just like you would in DarkBASIC. The prefixes for the remakrs are
// ,
` and
rem.
Finally, I would urge you to use this. It really takes the strain away from creating levels.
Enjoy
[edit]
On a further note, don't think this is just for Maps, I'll be using this for positioning health packs, guns, enemies, all of that.
[edit again]
Once I get my new computer I'll be able to add functionality for shaders. Meanwhile, I might just start making a level editor for this
[edit again]
Also, please tell me if you use it. You don't have to credit me (which would be nice
) but I'd be interested to know if it's popular and if I should expand on it more. Come to think about it, comment about it while you're here
(please)