Thaks Xaby . Coming from a great programmer like you, it's a nice compliment
.
Here's the lihgting trick ... of course here's not all the code but just a bit to show how I did it. This snippet is a part of the code that I use in Dbpro and runs at more than 650 or 700 FPS . I have to find out how to acelerate this in Agk . It's supposed that Agk is faster than Dbpro, but not in 2D commands.
// Project: Raycasting Example
// Created: 2019-06-23
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Raycasting Example" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
`mapa
rd=makecolor(255,0,0)
drawbox(0,0,10,200,rd,rd,rd,rd,1) `left wall
drawbox(190,0,200,200,rd,rd,rd,rd,1) `right wall
drawbox(0,190,200,200,rd,rd,rd,rd,1) `south wall
drawbox(0,0,200,10,rd,rd,rd,rd,1) `north wall
`some rooms
drawbox(0,0,60,60,rd,rd,rd,rd,1)
drawbox(150,0,200,60,rd,rd,rd,rd,1)
getimage(1,0,0,200,200)
clearscreen()
createsprite(1,1)
imgmemblock = CreateMemblockFromImage(1)
width = GetMemblockInt(imgmemblock,0)
height = GetMemblockInt(imgmemblock,4)
dim mapa[400,400]
for mx=0 to width-1
for my=0 to height-1
offset = (12+((my * width) + mx) * 4) - 4
r=GetMemblockByte(imgmemblock,offset)
g=GetMemblockByte(imgmemblock,offset+1)
b=GetMemblockByte(imgmemblock,offset+2)
a=GetMemblockByte(imgmemblock,offset+3)
col=makecolor(r,g,b)
mapa[mx,my]=col
next
next
`--------------------------------------------------
x as float
y as float
lx=160
ly=160
angle=-144
x=lx
y=ly
counter as float
ang as float
angle as float
screen=550
fish_off as float
`some colors
pink=makecolor(255,0,255)
b=makecolor(0,0,0)
do
`Mooving blok animation
ct=ct+1
if ct<20 then m#=m#+3
if ct>20 then m#=m#-3
if ct=40 then ct=-1
r=makecolor(255,0,255)
drawbox(20,60+m#,40,80+m#,r,r,r,r,1)
`sky
sky=makecolor(100,100,255)
drawbox(190,0,914,150,sky,sky,sky,sky,1)
`floor
f=makecolor(90,70,0)
drawbox(190,150,914,248,f,f,f,f,1)
ja=125 `horizont
for kk= 1 to 500
for i= 1 to 60 step 2
x=x+cos(ang+angle)*2
y=y+sin(ang+angle)*2
fish_off=counter*cos(ang*0.9)
`Distance from moving block to walls
dx#=x
dz#=y-50-m#
dist#=sqrt((dx#*dx#)+(dz#*dz#))
co=255-dist#*3 `))))))))) Now we play with the maximum rgb(255) less distance
if co<10 then co=10
wall=3000/fish_off
borde=3200/fish_off
if wall<6 then wall=6
cant_wll=ja+wall
cant_wll2=ja+borde
if cant_wll>250 then cant_wll=250
if cant_wll2>250 then cant_wll2=250
`Moving blok ************************************
blok=0
if x>20 and x<40 and y>60+m# and y<80+m# then blok=1
`************************************************
if blok=1
drawbox(screen+colu,ja-wall,screen+colu+4,cant_wll,pink,pink,pink,pink,1)
endif
if mapa[trunc(x),trunc(y)]=-16776961
` Wall borders
drawbox(screen+colu,ja-borde,screen+colu+4,cant_wll2,b,b,b,b,1)
`walls
w=makecolor(co,0,co)
drawbox(screen+colu,ja-wall,screen+colu+4,cant_wll,w,w,w,w,1)
endif
wide=4
counter=counter+1
if counter>200 or mapa[trunc(x),trunc(y)]=-16776961 or blok=1 or x<5 or y<5 or x>195 or y>195
counter=0
x=lx
y=ly
ang=ang+0.5
colu=colu+wide
endif
if ang>45 then ang=-45
if colu>90*wide then colu=-90*wide
w=makecolor(255,255,0)
drawline(x,y,x,y,w,w)
next
next
`area limits
if lx<15 then lx=15
if lx>185 then lx=185
if ly<15 then ly=15
if ly>185 then ly=185
if ( GetRawKeyState( 38 ) )
lx=lx+cos(angle)*2
ly=ly+sin(angle)*2
endif
if ( GetRawKeyState( 40 ) )
lx=lx+cos(angle)*-2
ly=ly+sin(angle)*-2
endif
if ( GetRawKeyState( 37 ) ) then angle=angle-4
if ( GetRawKeyState( 39 ) ) then angle=angle+4
for i= 1 to 18
print("")
next
print( ScreenFPS())
sync()
loop
I'm not a grumpy grandpa