Heres my new RPG engine. As anyone who has tried making an RPG (or RPG Maker like myself), you know media is a big hassle. This engine is all made in DBPro with no external media. It's based on Roguelike rpgs (use ascii characters only), only I've added a few bells and whistles. Take a look and see what you think. I plan to work on this basic model and maybe develop it into a small game or a simple rpg editor.
btw, i know it looks like a whole load of code for what it is, but thats just for the memblock matrices (all the functions that I probably dont need).
edit:code now here
` rpg engine test
` " - plains
` ~ - hills
` ^ - mountains
` . - road
` & - forest
` = - water
` setup
sync on:sync rate 0
set text font "Tahoma"
set text size 40:set text to bold
set camera range 1,99999999
color backdrop 0
` needed vars!
dim tilex(128)
dim tilez(128)
dim tilesizex#(128)
dim tilesizez#(128)
dim texture(128)
dim xpart#(128)
dim ypart#(128)
dim object(128)
` matrix
dim height#(100,100):dim color(100,100)
` edit
dim tsize#(1)
dim func(1):dim clr(1):dim hi#(2)
` make random map
dim tile(200,200): `dim color(200,200,3)
` generate
for x=1 to 10
for z=1 to 10
`tile(x,z)=1+rnd(5)
`color(x,z,1)=rnd(255)
`color(x,z,2)=rnd(255)
`color(x,z,3)=rnd(255)
`restore map
read tile(x,z)
`if tile(x,z)<1 or tile(x,z)>5 then tile(x,z)=1
next z
next x
` draw tileset
w#=text width("O")/2
h#=text height("O")/2
ink RGB(16,157,0),0: center text w#,h#,"''"
ink RGB(123,80,51),0: center text w#,h#*3,"~":` center text w#,h#*3.5,"~"
ink RGB(128,128,128),0: center text w#,h#*5.25,"^":` center text w#,h#*6,"^"
ink RGB(196,197,133),0: center text w#,h#*7,"::"
ink RGB(0,64,0),0: center text w#,h#*9,"&"
ink RGB(0,0,160),0: center text w#,h#*11,"="
` get tileset
get image 10,0,h#,w#*2,h#*15
`load image "tile.jpg",1
new()
position object object(1),50,-5,50
` matrix
make matrix 1,10000,10000,100,100
prepare matrix texture 1,10,1,7
` texture
for x=0 to 50
for z=0 to 50
if tile(x,z)=0 then tile(x,z)=7
t=7
if x>0 and z>0 then t=tile(x,z)
set matrix tile 1,x,z,t
next z
next x
ghost matrix on 1
update matrix 1
for x=0 to 50
for z=0 to 50
color=rgb(0,0,0)
if x>0 and z>0
if tile(x,z)=1 then color=RGB(16,157,0)
if tile(x,z)=2 then color=RGB(123,80,51)
if tile(x,z)=3 then color=RGB(128,128,128)
if tile(x,z)=4 then color=RGB(196,197,133)
if tile(x,z)=5 then color=RGB(0,64,0)
if tile(x,z)=6 then color=RGB(0,0,160)
endif
setmatrixcolor(1,x,z,color)
next z
next x
updatematrix(1)
` player
cls
ink RGB(255,255,255),0
center text w#,h#,"@"
get image 2,0,h#,w#*2,h#*3
make object plain 1,100,100
texture object 1,2:xrotate object 1,90
ghost object on 1: set object light 1,0
set object transparency 1,1
position object 1,250,25,250
do
move=0
x=object position x(1)/100:z=object position z(1)/100
if rightkey()=1 then move=1
if leftkey()=1 then move=2
if upkey()=1 then move=3
if downkey()=1 then move=4
` camera
camera(1)
` collision
col=1
if move=1 and tile(x+1,z)<6 and tile(x+1,z)<>3 then col=0
if move=2 and tile(x-1,z)<6 and tile(x-1,z)<>3 then col=0
if move=3 and tile(x,z+1)<6 and tile(x,z+1)<>3 then col=0
if move=4 and tile(x,z-1)<6 and tile(x,z-1)<>3 then col=0
if col=1 then move=0
` move
if move>0
dif#=2
if move=1 then sx#=dif#:sy#=0
if move=2 then sx#=0-dif#:sy#=0
if move=3 then sx#=0:sy#=dif#
if move=4 then sx#=0:sy#=0-dif#
for turn=1 to 50
position object 1,object position x(1)+sx#,object position y(1),object position z(1)+sy#
` camera
camera(1)
sync
next turn
endif
sync
loop
map:
data 4,4,4,3,3,3,3,3,3,3,
data 3,2,4,2,3,3,3,3,5,3,
data 3,2,4,1,1,3,3,3,5,3,
data 3,3,4,4,4,4,4,4,5,3,
data 3,3,1,6,6,1,5,4,5,3,
data 3,1,1,6,6,1,5,4,2,3,
data 3,1,6,6,6,1,5,4,2,3,
data 3,1,1,1,1,1,5,4,3,3,
data 3,1,4,4,4,4,4,4,6,6,
data 3,3,4,1,1,1,5,5,6,6,
data 3,3,4,3,3,3,3,6,6,6,
` camera
function camera(o)
cx#=curvevalue(object position x(o),camera position x(),30)
cz#=curvevalue(object position z(o)-200,camera position z(),30)
cy#=curvevalue(object position y(o)+1400,camera position y(),30)
position camera cx#,cy#,cz#:point camera object position x(o),object position y(o),object position z(o)
endfunction
function new()
` temporary startup
for x=0 to 258
for z=0 to 258
r#=100
ink rgb(r#,r#,r#),0
dot x,z
next z
next x
get image 1,0,0,256,256
`tilex(1)=val(input dialog("Tiles X","Enter number of tiles wide"))
`tilez(1)=val(input dialog("Tiles Z","Enter number of tiles deep"))
`tsize#(1)=val(input dialog("Tile size","Enter tile size"))
tilex(1)=50:tilez(1)=50:tsize#(1)=100
makematrix(1,tilex(1)*tsize#(1),tilez(1)*tsize#(1),tilex(1),tilez(1))
texturematrix(1,1,tilex(1),tilez(1))
normalizematrix(1,1,1,80,80)
updatematrix(1)
` set all tiles
for x=0 to tilex(1)
for z=0 to tilez(1)
color(x,z)=RGB(255,255,255)
next z
next x
endfunction
function makematrix(mem,x#,z#,tilex,tilez)
tilex(mem)=tilex
tilez(mem)=tilez
tilesizex#(mem)=x#/tilex(mem)
tilesizez#(mem)=z#/tilez(mem)
polys=2*tilex*tilez
size=(polys*36*3)+12
make memblock mem,size
write memblock dword mem,0,338
write memblock dword mem,4,36
write memblock dword mem,8,polys*3
pos=12
for x=1 to tilex(mem)
for z=1 to tilez(mem)
writevectordata(mem,pos,(x-1.0)*tilesizex#(mem),0.000,(z-1.0)*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),0.000,1.000)
writevectordata(mem,pos+36,x*tilesizex#(mem),0.000,z*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),1.000,0.000)
writevectordata(mem,pos+72,x*tilesizex#(mem),0.000,(z-1.0)*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),1.000,1.000)
writevectordata(mem,pos+108,(x-1.0)*tilesizex#(mem),0.000,(z-1.0)*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),0.000,1.000)
writevectordata(mem,pos+144,(x-1.0)*tilesizex#(mem),0.000,z*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),0.000,0.000)
writevectordata(mem,pos+180,x*tilesizex#(mem),0.000,z*tilesizez#(mem),0.000,1.000,0.000,rgb(255,255,255),1.000,0.000)
pos=pos+216
next z
next x
object(mem)=mem+50000
make mesh from memblock object(mem),mem
make object object(mem),object(mem),0
endfunction
function writevectordata(mem,pos,X# as float,Y# as float,Z# as float,NX# as float,NY# as float,NZ# as float,color as dword,TU# as float,TV# as float)
write memblock float mem,pos,X#
write memblock float mem,pos+4,Y#
write memblock float mem,pos+8,Z#
write memblock float mem,pos+12,NX#
write memblock float mem,pos+16,NY#
write memblock float mem,pos+20,NZ#
write memblock dword mem,pos+24,color
write memblock float mem,pos+28,TU#
write memblock float mem,pos+32,TV#
endfunction
function setmatrixheight(mem,x,z,y#)
if x-1>=0 and z-1>=0
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+40,y#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+184,y#
endif
if x-1>=0 and z<tilez(mem)
write memblock float mem,12+(216*(((x-1)*tilez(mem))+z))+76,y#
endif
if x<tilex(mem) and z-1>=0
write memblock float mem,12+(216*((x*tilez(mem))+(z-1)))+148,y#
endif
if x<tilex(mem) and z<tilez(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+4,y#
write memblock float mem,12+(216*((x*tilez(mem))+z))+112,y#
endif
endfunction
function setmatrixcolor(mem,x,z,color)
if x-1>=0 and z-1>=0
write memblock dword mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+60,color
write memblock dword mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+204,color
endif
if x-1>=0 and z<tilez(mem)
write memblock dword mem,12+(216*(((x-1)*tilez(mem))+z))+96,color
endif
if x<tilex(mem) and z-1>=0
write memblock dword mem,12+(216*((x*tilez(mem))+(z-1)))+168,color
endif
if x<tilex(mem) and z<tilez(mem)
write memblock dword mem,12+(216*((x*tilez(mem))+z))+24,color
write memblock dword mem,12+(216*((x*tilez(mem))+z))+132,color
endif
endfunction
function setmatrixnormal(mem,x,z,nx#,ny#,nz#)
if x-1>=0 and z-1>=0
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+48,nx#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+52,ny#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+56,nz#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+192,nx#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+196,ny#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+200,nz#
endif
if x-1>=0 and z<tilez(mem)
write memblock float mem,12+(216*(((x-1)*tilez(mem))+z))+84,nx#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+z))+88,ny#
write memblock float mem,12+(216*(((x-1)*tilez(mem))+z))+92,nz#
endif
if x<tilex(mem) and z-1>=0
write memblock float mem,12+(216*((x*tilez(mem))+(z-1)))+156,nx#
write memblock float mem,12+(216*((x*tilez(mem))+(z-1)))+160,ny#
write memblock float mem,12+(216*((x*tilez(mem))+(z-1)))+164,nz#
endif
if x<tilex(mem) and z<tilez(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+12,nx#
write memblock float mem,12+(216*((x*tilez(mem))+z))+16,ny#
write memblock float mem,12+(216*((x*tilez(mem))+z))+20,nz#
write memblock float mem,12+(216*((x*tilez(mem))+z))+120,nx#
write memblock float mem,12+(216*((x*tilez(mem))+z))+124,ny#
write memblock float mem,12+(216*((x*tilez(mem))+z))+128,nz#
endif
endfunction
function getmatrixheight(mem,x,z)
if x-1>=0 and z-1>=0
height#=memblock float(mem,12+(216*(((x-1)*tilez(mem))+(z-1)))+40)
else
if x<tilex(mem) and z<tilez(mem)
height#=memblock float(mem,12+(216*((x*tilez(mem))+z))+4)
else
height#=memblock float(mem,12+(216*(((x-1)*tilez(mem))+z))+76)
endif
endif
endfunction height#
function randomizematrix(mem,bx,bz,ex,ez,value#)
for x=bx to ex
for z=bz to ez
setmatrixheight(mem,x,z,(rnd(int(value#*100))/100.0)-(0.5*value#))
next z
next x
endfunction
function normalizematrix(mem,bx,bz,ex,ez)
if bx<=0 then bx=1
if bz<=0 then bz=1
if ex>=tilex(mem) then ex=tilex(mem)-1
if ez>=tilez(mem) then ez=tilez(mem)-1
rem Use matrix normals to make it smooth
for z=bz to ez
for x=bx to ex
rem Get matrix heights
h8#=getmatrixheight(mem,x,z-1)
h4#=getmatrixheight(mem,x-1,z)
h#=getmatrixheight(mem,x,z)
h2#=getmatrixheight(mem,x,z)
rem Calculate projected angle X using heights
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem Setting matrix normal for smoothness
setmatrixnormal(1,x,z,nx#,ny#,nz#)
next x
next z
endfunction
function updatematrix(mem)
change mesh from memblock object(mem),mem
change mesh object(mem),0,object(mem)
texture object object(mem),texture(mem)
endfunction
function getgroundheight(mem,x#,z#)
if x#>=0 and z#>=0 and x#<tilex(mem)*tilesizex#(mem) and z#<tilez(mem)*tilesizez#(mem)
xt=int(x#/tilesizex#(mem))
zt=int(z#/tilesizez#(mem))
if (((xt+1)*tilesizex#(mem))-x#)+(z#-(zt*tilesizez#(mem)))<=tilesizex#(mem)
dx#=getmatrixheight(mem,xt+1,zt)-getmatrixheight(mem,xt,zt)
dz#=getmatrixheight(mem,xt+1,zt+1)-getmatrixheight(mem,xt+1,zt)
else
dx#=getmatrixheight(mem,xt+1,zt+1)-getmatrixheight(mem,xt,zt+1)
dz#=getmatrixheight(mem,xt,zt+1)-getmatrixheight(mem,xt,zt)
endif
height#=(((x#-(xt*tilesizex#(mem)))/tilesizex#(mem))*dx#)+(((z#-(zt*tilesizez#(mem)))/tilesizez#(mem))*dz#)+getmatrixheight(mem,xt,zt)
endif
endfunction height#
function preparematrixtexture(mem,image,xsplit,ysplit)
texture(mem)=image
xpart#(mem)=1.000/xsplit
ypart#(mem)=1.000/ysplit
for x=0 to tilex(mem)-1
for z=0 to tilez(mem)-1
setmatrixtile(mem,x,z,1,1)
next z
next x
endfunction
function setmatrixtile(mem,x,z,xtex,ytex)
write memblock float mem,12+(216*((x*tilez(mem))+z))+28,(xtex-1)*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+32,ytex*ypart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+64,xtex*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+68,(ytex-1)*ypart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+100,xtex*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+104,ytex*ypart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+136,(xtex-1)*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+140,ytex*ypart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+172,(xtex-1)*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+176,(ytex-1)*ypart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+208,xtex*xpart#(mem)
write memblock float mem,12+(216*((x*tilez(mem))+z))+212,(ytex-1)*ypart#(mem)
endfunction
function texturematrix(mem,image,xtile#,ztile#)
texture(mem)=image
texx#=xtile#/tilex(mem)
texz#=ztile#/tilez(mem)
for x=0 to tilex(mem)-1
for z=0 to tilez(mem)-1
z2=(tilez(mem)-z)-1
write memblock float mem,12+(216*((x*tilez(mem))+z2))+28,(x*texx#)
value#=((z+1)*texz#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+32,value#
value#=((x+1)*texx#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+64,value#
write memblock float mem,12+(216*((x*tilez(mem))+z2))+68,(z*texz#)
value#=((x+1)*texx#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+100,value#
value#=((z+1)*texz#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+104,value#
write memblock float mem,12+(216*((x*tilez(mem))+z2))+136,(x*texx#)
value#=((z+1)*texz#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+140,value#
write memblock float mem,12+(216*((x*tilez(mem))+z2))+172,(x*texx#)
write memblock float mem,12+(216*((x*tilez(mem))+z2))+176,(z*texz#)
value#=((x+1)*texx#) : if value#=0.00 then value#=1.00
write memblock float mem,12+(216*((x*tilez(mem))+z2))+208,value#
write memblock float mem,12+(216*((x*tilez(mem))+z2))+212,(z*texz#)
next z
next x
endfunction
function positionmatrix(mem,x#,y#,z#)
position object object(mem),x#,y#,z#
endfunction
function ghostmatrix(mem,ghost)
ghost object on object(mem),ghost
endfunction
function smooth_matrix(t,mx,mz)
for times=1 to t
for x=0 to mx
for z=0 to mz
height#(x,z)=(height#(x,z)+height#(x+1,z)+height#(x,z+1)+height#(x+1,z+1))/4
next z
next x
next times
endfunction
coincidence? how about pure cosmic convergence!