Hello.
I have this code (below) and I'm trying to make a radar appear on the bottom-right corner of the screen. Aside from the fact that this code doesn't even work correctly, it also causes massive slowdown for my machine. I'm not too experienced with DarkBASIC and therefore I don't know any techniques to reduce slowdown. Anybody's insight would be helpful. (this is a flying game by the way)
ships(0) is an array that holds the enemy ships, it's declared dim ships(10). It is created of the type Ship, and the "num" member simply holds the object number of that ship.
p_num is a global variable that holds the player's object number.
xzobjdistance() and FindYDir() are self-declared functions and are posted below...
If I comment out that whole bit of code listed below, it runs at a normal speed, but if I comment out the first half or second half ("half" meaning above or below the for loop) separately, neither time does the program speed up.
rem Radar
rad=25
scale=5000
x=screen width()-rad-8
y=screen height()-rad-8
ink rgb(0,255,0),rgb(0,180,0)
circle x,y,rad
circle x,y,floor(rad*0.67)
circle x,y,floor(rad*0.33)
rem loop through each ship and display on radar if close enough
for e=1 to (array count(ships(0)))
if ships(e).num>0
dist=xzobjdistance(ships(e).num,p_num)
if (dist<scale)
direction=FindYDir(p_num,ships(e).num)
xx=sin(direction)*((dist/scale)*rad)
yy=cos(direction)*((dist/scale)*rad)
ink rgb(255,0,0),rgb(255,0,0)
circle x+xx,y+yy,3
endif
endif
next e
xzobjdistance()
rem This function calculates the xz distance of 2 objects
function xzobjdistance(obj1,obj2)
dx#=object position x(obj1)-object position x(obj2)
dz#=object position z(obj1)-object position z(obj2)
objdist#=(sqrt(abs(dx#*dx#)+abs(dz#*dz#)))
endfunction objdist#
rem -----------------------------------------------------------------------------
FindYDir()
rem This function calculates the y direction from two objects
function FindYDir(obj1,obj2)
rem Differences
xdif#=object position x(obj2)-object position x(obj1)
zdif#=object position z(obj2)-object position z(obj1)
text 200,5,str$(xdif#)
text 200,15,str$(zdif#)
rem y direction
ydir#=wrapvalue(atanfull(xdif#,zdif#))
endfunction ydir#
rem -----------------------------------------------------------------------------
Thank you for any help!
ZOMG