Hey, yea im finaly a happy owner of dbproo(Thanks to the support dude
)
I got a litle project going on(started it in trail version), and decided to give out some waypoint
functions+some other functions.
Hope this is usefull for someone
The code is remed out, and includes a demo that sould show how to use em.
If you got any questions just post them here(offcorse), and i will try to answer them.
the editor:
Rem Project: Waypoint Editor
Rem Created: 26-05-2006 04:39:47
REM Written by: Mika J, also known as coder#05
Rem ***** Main Source File *****
REM normal setup
if check display mode(800,600,32)=1 then set display mode 800,600,32
sync on
sync rate 0
autocam off
set window title \"Waypoint editor by coder#05\"
REM text setup
temp=text size()
set text size temp*1.5
set text to bold
REM ini editor variables
type Teditor
x# as float
y# as float
z# as float
angy# as float
angx# as float
endtype
REM arrays
global DIM cone(1) as Teditor
global DIM camera(1) as Teditor
global DIM mx#(1) as float
global DIM my#(1) as float
REM Ini the click matrix function(subroutine), made by an unknown wise person
screenwidth2# = screen width() / 2.0
screenheight2# = screen height() / 2.0
scalefactor# = screen height() / 1.2
REM just something to transfer the 3dmouse cordinates over in another variable
global DIM positionx#(1) as float
global DIM positionz#(1) as float
REM ini_waypoints
`Variable declariation
`TYPES
TYPE Tpath
waypointID
x#
y#
z#
ENDTYPE
`dynamic arrays
global DIM waypoint() as Tpath
global DIM path() as integer : REM the number off path sould equal the number off enemy objects
global DIM waypoint_location() as Tpath : REM this will hold the location values for the difrent waypoint in the current path the user is woorking on
REM i dont use element 0
add to queue waypoint()
add to queue path()
add to queue waypoint_location()
REM this is just use to color the object that represent the waypoints(NOTE the objects arent needed when using the waypoints)
global object_color as integer
object_color=rgb(200,0,200)
REM make the cone (because the click matrix position needs a \"location to look at\"
make object cone 1,30
REM load test level
REM Just change this to load any level you made. if your level is .x or any other format,
REM you need to change the way i find the position for where to make a new waypoint
load_Mtrix(\"levelDATA\\level1.dat\")
REM position the camera in the midle of the level, and 500 units over the current level
camera(1).x#=camera(1).x#+500 : camera(1).y#=camera(1).y#+500 : camera(1).z#=camera(1).z#+500
REM make a new path (path 1)
`new_path()
REM main loop
DO
REM display simple info to user(normaly just me :-)
text 10,10,\"you are currently working on path number \"+str$(get_path())
text 10,20+text height(\"l\"),\"to make a new path press n(case sensetive)\"
text 10,30+text height(\"l\"),\"to save current path press s(case sensetive)\"
REM simple control over camera and cone
if upkey()=1
x#=x#+newxvalue(0,camera(1).angy#,1)
z#=z#+newzvalue(0,camera(1).angy#,1)
endif
if downkey()=1
x#=x#+newxvalue(0,camera(1).angy#,1)*(-1)
z#=z#+newzvalue(0,camera(1).angy#,1)*(-1)
endif
if leftkey()=1
x#=x#+newxvalue(0,wrapvalue(camera(1).angy#-90),1)
z#=z#+newzvalue(0,wrapvalue(camera(1).angy#-90),1)
endif
if rightkey()=1
x#=x#-newxvalue(0,wrapvalue(camera(1).angy#-90),1)
z#=z#-newzvalue(0,wrapvalue(camera(1).angy#-90),1)
endif
if inkey$()=(\"+\")
y#=y#+newyvalue(0,camera(1).angx#,3)
endif
if inkey$()=(\"-\")
y#=y#+newyvalue(0,camera(1).angx#,3)*(-1)
endif
x#=x#*0.5
y#=y#*0.5
z#=z#*0.5
camera(1).x#=camera(1).x#+x#
camera(1).y#=camera(1).y#+y#
camera(1).z#=camera(1).z#+z#
cone(1).x#=camera(1).x#
cone(1).z#=camera(1).z#
cone(1).y#=get ground height(1,cone(1).x#,cone(1).z#)+(object size y(1)/2)
position camera camera(1).x#,camera(1).y#,camera(1).z#
position object 1,cone(1).x#,cone(1).y#,cone(1).z#
point camera cone(1).x#,cone(1).y#,cone(1).z#
REM simple waypoint placer
if inkey$()=(\"n\") and delay<1
new_path()
delay=100
endif
if mouseclick()=1 and delay<1
ADDnew_waypoint(get_path(),positionx#(1),cone(1).y#,positionz#(1))
delay=100
endif
if inkey$()=(\"s\")
save_path(get_path())
delay=100
endif
REM control simple delay
delay=delay-1
REM opdate position vars(you sould normaly do this at the start of your loop)
opdate_values()
gosub click_matrix_position
sync
loop
REM Click_Matrix_Position function by unknow wise person
REM Taken from the RTS tut(who made this? :-)
Click_Matrix_Position:
offsetx#=cone(1).x#
offsety#=cone(1).y#
offsetz#=cone(1).z#
mouseposx#=mousex() - screenwidth2#
mouseposy#=screenheight2# - mousey()
dist#=sqrt((camera position x()-offsetx#)^2+(camera position y()-offsety#)^2+(camera position z()-offsetz#)^2)
if mouseposy#<>0
vectorang#=atanfull(scalefactor#,mouseposy#)
else
vectorang#=90.0
endif
if vectorang#+camera angle x()>90.965
ratio#=mouseposy#/(sin((vectorang#+camera angle x() )-90.0))
cursorposy#=ratio#*sin(180.0-vectorang#)
else
cursorposy#=1000000.0
endif
hyplength#=scalefactor#/sin(vectorang#)
cursorposx#=(((ratio#*sin(90.0-camera angle x() ))/hyplength#)+1.0)*mouseposx#
if mouseposx#<>0
angtotal#=wrapvalue(camera angle y()-atanfull(mouseposy#,mouseposx#))
else
if mouseposy#<0
angtotal#=wrapvalue(camera angle y()+90.0)
else
angtotal#=wrapvalue(camera angle y()-90.0)
endif
endif
cameraang#=wrapvalue(360.0-camera angle y() )
cosang#=cos(cameraang#)
sinang#=sin(cameraang#)
movex# = (dist#/scalefactor#)*((cosang#*cursorposx#)+((-1*sinang#)*cursorposy#))
movez# = (dist#/scalefactor#)*((sinang#*cursorposx#)+(cosang#*cursorposy#))
rem 3D position stored into these variables
movex#=movex#+offsetx#
movez#=movez#+offsetz#
movey#=0
positionx#(1)=movex#
positionz#(1)=movez#
RETURN
FUNCTION opdate_values()
REM pointer values
cone(1).x#=object position x(1)
cone(1).y#=object position y(1)
cone(1).z#=object position z(1)
REM camera values
camera(1).x#=camera position x()
camera(1).y#=camera position y()
camera(1).z#=camera position z()
camera(1).angx#=camera angle x()
camera(1).angy#=camera angle y()
REM mouse values
mx#(1)=mousemovex()
my#(1)=mousemovey()
ENDFUNCTION
REM makes a new path
FUNCTION new_path()
add to queue path() : REM add a new path
add to queue waypoint() : REM add a new element to waypoint, for storing new waypointID positions
path(array count(path()))=array count(path())
object_color=rgb(rnd(255),rnd(255),rnd(255))
ENDFUNCTION
REM get number off total paths
FUNCTION get_path()
n=array count(path())
re=path(n)
ENDFUNCTION re
REM adds new way point to current path
FUNCTION ADDnew_waypoint(path,x#,y#,z#)
waypoint(path).waypointID=waypoint(path).waypointID+1 : REM gives us a new waypointID to work with
add to queue waypoint_location()
waypoint_location(waypoint(path).waypointID).x#=x# : REM waypoint_location(the new waypoint in the current path).x# y# and z#
waypoint_location(waypoint(path).waypointID).y#=y#
waypoint_location(waypoint(path).waypointID).z#=z#
note_object=freeobject() : make object box note_object,10,50,10 : position object note_object,x#,y#+5,z# : color object note_object,object_color
ENDFUNCTION
REM function for saving path
FUNCTION save_path(path)
file_path$=\"pathnumber\"+str$(path)+\" level\"+str$(level_id(1))+\".dat\"
REM check to see if file exist, if so then delete it
if file exist(file_path$)=1 then delete file file_path$
REM start writing to file
open to write 1,file_path$
REM file is written in this order->-> path/enemy_number, total way points, for 1 to total waypoints in path. waypointID, x#, y#, z#
write string 1,str$(path)
write string 1,str$(waypoint(path).waypointID)
for n=1 to waypoint(path).waypointID
write string 1,str$(n)
write string 1,str$(waypoint_location(n).x#)
write string 1,str$(waypoint_location(n).y#)
write string 1,str$(waypoint_location(n).z#)
next n
close file 1
text 400,400,\"waypoint path saved succes fully!\"
ENDFUNCTION
REM loads level file from my Mtrix_editor
FUNCTION Load_Mtrix(path$)
local DIM tile_texture1_pox(100)
local DIM tile_texture1_poz(100)
local DIM tile_texture2_pox(100)
local DIM tile_texture2_poz(100)
local DIM tile_texture3_pox(100)
local DIM tile_texture3_poz(100)
local DIM tile_texture4_pox(100)
local DIM tile_texture4_poz(100)
DIM start_Obj(1)
DIM total_obj(1)
DIM level_id(1)
DIM textureNUM(1)
local DIM texture_name$(1)
DIM player_startPO(3)
REM load_matrix
open to read 1,path$
for x=1 to 3
read string 1,h$:player_startPO(x)=val(h$)
next x
read string 1,h$:level_id(1)=val(h$)
read string 1,h$:matrix_number=val(h$)
read string 1,h$:matrix_width=val(h$)
read string 1,h$:matrix_depth=val(h$)
read string 1,h$:x_segments=val(h$)
read string 1,h$:z_segments=val(h$)
read string 1,h$:texture1_total=val(h$)
for x=1 to texture1_total
read string 1,pox$:tile_texture1_pox(x)=val(pox$)
read string 1,poz$:tile_texture1_poz(x)=val(poz$)
next x
read string 1,h$:texture2_total=val(h$)
for x=1 to texture2_total
read string 1,pox$:tile_texture2_pox(x)=val(pox$)
read string 1,poz$:tile_texture2_poz(x)=val(poz$)
next x
read string 1,h$:texture3_total=val(h$)
for x=1 to texture3_total
read string 1,pox$:tile_texture3_pox(x)=val(pox$)
read string 1,poz$:tile_texture3_poz(x)=val(poz$)
next x
read string 1,h$:texture4_total=val(h$)
for x=1 to texture4_total
read string 1,pox$:tile_texture4_pox(x)=val(pox$)
read string 1,poz$:tile_texture4_poz(x)=val(poz$)
next x
make matrix matrix_number,matrix_width,matrix_depth,x_segments,z_segments
load image \"levelDATA\\tiles.bmp\",8000
prepare matrix texture 1,8000,2,2
for x= 1 to texture1_total
set matrix tile matrix_number,tile_texture1_pox(x),tile_texture1_poz(x),1
update matrix matrix_number
next x
for x=1 to texture2_total
set matrix tile matrix_number,tile_texture2_pox(x),tile_texture2_poz(x),2
update matrix matrix_number
next x
for x=1 to texture3_total
set matrix tile matrix_number,tile_texture3_pox(x),tile_texture3_poz(x),3
update matrix matrix_number
next x
for x=1 to texture4_total
set matrix tile matrix_number,tile_texture4_pox(x),tile_texture4_poz(x),4
update matrix matrix_number
next x
for x=0 to x_segments-1
for z=0 to z_segments-1
read string 1,h$:height=val(h$)
set matrix height matrix_number,x,z,height
update matrix matrix_number
next z
next x
rem make objects
read string 1,h$ : start_obj(1)=val(h$)
read string 1,h$ : total_obj(1)=val(h$)
for x= start_obj(1) to total_obj(1)
read string 1,h$ : sx#=val(h$)
read string 1,h$ : sy#=val(h$)
read string 1,h$ : sz#=val(h$)
read string 1,h$ : x#=val(h$)
read string 1,h$ : y#=val(h$)
read string 1,h$ : z#=val(h$)
read string 1,h$ : textureNUM(1)=val(h$)
read string 1,h$ : texture_name$(1)=h$
if textureNUM(1) > 1005 and textureNUM(1) < 2000
if image exist(textureNUM(1))=0 and path exist(\"levelDATA\\textures\\\"+texture_name$(1)) then load image \"levelDATA\\textures\\\"+texture_name$(1),textureNUM(1)
endif
make object box x,sx#,sy#,sz#
position object x,x#,y#,z#
if textureNUM(1) > 1005 and textureNUM(1) < 2000
if image exist(textureNUM(1))=1 then texture object x,textureNUM(1)
endif
next x
close file 1
ENDFUNCTION
REM deletes a level
FUNCTION delete_Mtrix(matrixNumber)
delete matrix matrixNUMBER
delete image 8000
for x = 1006 to total_obj(1)
if object exist(x)=1
delete object x
endif
next x
for x= 1006 to 1999
if image exist(x)=1 then delete image x
next x
ENDFUNCTION
FUNCTION freeobject()
local obj as integer
local found as integer
repeat
obj=obj+1
if object exist(obj)=0
exitfunction obj
found=1
else
found=0
endif
until found=1
ENDFUNCTION found
the demo:
Rem Project: Waypoint demo
Rem Created: 26-05-2006 04:39:47
REM Written by: Mika J, also known as coder#05
Rem ***** Main Source File *****
REM normal setup
if check display mode(800,600,32)=1 then set display mode 800,600,32
sync on
sync rate 0
autocam off
REM text setup
temp=text size()
set text size temp*1.5
set text to bold
REM ini demo
REM initialize moveing objects
global DIM enemys(1)
enemys(1)=5
totalEnemys as integer
totalEnemys=enemys(1)
for n=1 to 5
make object cube n,25
color object n,rgb(rnd(255),rnd(255),rnd(255))
next n
global DIM ox#(enemys(1))
global DIM oy#(enemys(1))
global DIM oz#(enemys(1))
global DIM oay#(enemys(1))
global DIM forward(enemys(1))
global DIM right(enemys(1))
TYPE TenemyPath
id as integer
reached as integer
x# as float
y# as float
z# as float
ENDTYPE
REM ini preapre path data
global DIM pathnumber(totalEnemys) as integer : REM hmm
global DIM totalwaypoints(totalEnemys) as integer : REM keeps track off total waypoints in a path
global DIM firstWayPoint(totalEnemys) as integer : REM used to localize waypoint(wp)
global DIM current_waypoint(totalEnemys) as integer : REM used to find next waypoint inside a path
global DIM waypoint() as TenemyPath
global DIM waypointTimer(totalEnemys) as integer
global DIM dist_to_waypoint#(totalEnemys) as float : REM holds the dist to next waypoint
global DIM wayPoint_fov#(totalEnemys) as float : REM used to check if way-point is in enemys field of view
REM make world
load_Mtrix(\"levelDATA\\level1.dat\")
REM prepare waypoints
gosub prepare_enemy_path_data
REM positon enemys at their first waypoint id
for x=1 to enemys(1)
position object x,waypoint(firstwaypoint(x)).x#,waypoint(firstwaypoint(x)).y#,waypoint(firstwaypoint(x)).z#
next x
REM main loop
REM NOTE!: You sould never use as many camera position x, object position x, commands like i do in this demo, its better just to make variables to hold that info, and only opdate them when needed
REM NOTE!: Sorry for my typeing :/ ?
REM I would like to know if you decides to use this, or if you have made it better?
DO
REM display some info
text 10,10,\"Some info\"
text 10,30,\"Object 1 is moveing towards waypoint \"+str$(current_waypoint(1))
text 10,50,\"Object 2 is moveing towards waypoint \"+str$(current_waypoint(2))
text 10,70,\"Object 3 is moveing towards waypoint \"+str$(current_waypoint(3))
text 10,80,\"Object 4 is moveing towards waypoint \"+str$(current_waypoint(4))
text 10,100,\"Object 5 is moveing towards waypoint \"+str$(current_waypoint(5))
text 10,140,\"You are nearest object= \"+str$(get_nearestObjectFROM(camera position x(),camera position y(),camera position z(),1,5))
text 10,180,\"control camera with arrow keys\"
REM simple control
if upkey()=1 then move camera 1
if downkey()=1 then move camera -1
cay#=camera angle y()
if leftkey()=1 then yrotate camera wrapvalue(cay#-2)
if rightkey()=1 then yrotate camera wrapvalue(cay#+2)
position camera camera position x(),get ground height(1,camera position x(),camera position z())+18,camera position z()
REM just call this in your main loop, just alter the way object moves towards the next waypoint, if you dont like the way its done here
REM This might not fit your need, if not then just create your own function/routine for moveing objects to their next waypoint
for x=1 to enemys(1)
control_cubes(x)
next x
sync
loop
end
REM function that controls the cubes
FUNCTION control_cubes(id)
REM opdate values
ox#(id)=object position x(id)
oy#(id)=object position y(id)
oz#(id)=object position z(id)
oay#(id)=object angle y(id)
current_waypoint(id)=get_next_waypoint(id,ox#(id),oy#(id),oz#(id))
REM move objects around the map
control_ai_movement(id,current_waypoint(id))
oay#(id)=wrapvalue(oay#(id))
yrotate object id,oay#(id)
if forward(id)=1
move object id,1
endif
if right(id)=1
move object right id,1
endif
ENDFUNCTION
REM make way-points
REM call this before your main loop
REM it prepares the arrays/vars with the values needed
prepare_enemy_path_data:
wp=0
enemyNumber=0
DIM all_waypoints(1) as integer
add to queue waypoint()
tempvalue=enemys(1)
for x= 1 to tempvalue
enemyNumber=enemyNumber+1
file_path$=\"levelDATA\\pathnumber\"+str$(enemyNumber)+\" level\"+str$(level_id(1))+\".dat\"
` if file exist(file_path$)=1
open to read 1,file_path$
read string 1,h$ : pathnumber(enemyNumber)=val(h$) : `read current enemys path number and the total number off waypoints in that path
read string 1,h$ : totalwaypoints(enemyNumber)=val(h$) : `Then opdate the waypoint() array to hold the position info, that we later on will use to move our enemy around the current level
if enemyNumber = 1 then all_waypoints(1)=totalwaypoints(1)
if enemyNumber > 1
all_waypoints(1)=totalwaypoints(enemyNumber-1) + totalwaypoints(enemyNumber)
endif
firstWayPoint(enemyNumber)=wp+1
for temp=1 to totalwaypoints(enemyNumber)
add to queue waypoint()
next temp
for n=1 to totalwaypoints(enemyNumber):`read the position off the waypoints into the correct element off the waypoint array
wp=wp+1
read string 1,h$ : waypoint(wp).id=val(h$)
read string 1,h$ : waypoint(wp).x#=val(h$)
read string 1,h$ : waypoint(wp).y#=val(h$)
read string 1,h$ : waypoint(wp).z#=val(h$)
next n
totalwaypoints(enemyNumber)=all_waypoints(1)
close file 1
` else
` exit prompt \"file error\",\"in prepare_enemy_path_data\"
` endif
next x
RETURN
FUNCTION get_next_waypoint(id,x#,y#,z#)
REM store values for current path , NOTE variable current represents the current waypoint
REM find the first waypoint in path, only if not fund before, this only needs to be done at the start up to any level
if current_waypoint(id)=0
current_waypoint(id)=firstWayPoint(id)
endif
dist_to_waypoint#(id)=get_dist#(x#,waypoint(current_waypoint(id)).x#,y#,y#,z#,waypoint(current_waypoint(id)).z#)
if dist_to_waypoint#(id) < 20 and waypoint(current_waypoint(id)).reached=0
waypoint(current_waypoint(id)).reached=1
current_waypoint(id)=current_waypoint(id)+1
if current_waypoint(id) > totalwaypoints(id)
current_waypoint(id) = firstWaypoint(id)
endif
else
waypoint(current_waypoint(id)).reached=0
endif
local output as integer
output=current_waypoint(id)
ENDFUNCTION output
FUNCTION control_ai_movement(id,wid)
`get the distance to the waypoint enemy is suposed to be heading for
dist#=dist_to_waypoint#(id)
`then work out the enemys fov, for later check on, if its heding for the waypoint
wayPoint_fov#(id)=wrapvalue(atanfull(ox#(id)-waypoint(wid).x#,oz#(id)-waypoint(wid).z#))
if wayPoint_fov#(id)>180 then wayPoint_fov#(id)=wayPoint_fov#(id)-360
REM now check to see if waypoint is inside enemys fov
REM then rotate it to face the next point, if so then move it forward, rotate faster if far away from waypoint
if abs(wayPoint_fov#(id)-oay#(id))>0 and abs(wayPoint_fov#(id)-oay#(id))<175
if dist_to_waypoint#(id) > 200
oay#(id)=oay#(id)+5
else
oay#(id)=oay#(id)+2.5
endif
endif
if abs(wayPoint_fov#(id)-oay#(id))>185 and abs(wayPoint_fov#(id)-oay#(id))<360
if dist_to_waypoint#(id) > 200
oay#(id)=oay#(id)-5
else
oay#(id)=oay#(id)-2.5
endif
endif
REM something wierd happens, the fov# some times goes over 360 and all the way up to 500+
REM tempuary solution
if abs(wayPoint_fov#(id)-oay#(id))>360
right(id)=1
oay#(id)=oay#(id)+5
else
right(id)=0
endif
REM waypoint is in field of view so move forward
if abs(wayPoint_fov#(id)-oay#(id))>175 and abs(wayPoint_fov#(id)-oay#(id))<185
forward(id)=1
else
forward(id)=0
endif
ENDFUNCTION
REM loads level file from my Mtrix_editor
FUNCTION Load_Mtrix(path$)
local DIM tile_texture1_pox(100)
local DIM tile_texture1_poz(100)
local DIM tile_texture2_pox(100)
local DIM tile_texture2_poz(100)
local DIM tile_texture3_pox(100)
local DIM tile_texture3_poz(100)
local DIM tile_texture4_pox(100)
local DIM tile_texture4_poz(100)
DIM start_Obj(1)
DIM total_obj(1)
DIM level_id(1)
DIM textureNUM(1)
local DIM texture_name$(1)
DIM player_startPO(3)
REM load_matrix
open to read 1,path$
for x=1 to 3
read string 1,h$:player_startPO(x)=val(h$)
next x
read string 1,h$:level_id(1)=val(h$)
read string 1,h$:matrix_number=val(h$)
read string 1,h$:matrix_width=val(h$)
read string 1,h$:matrix_depth=val(h$)
read string 1,h$:x_segments=val(h$)
read string 1,h$:z_segments=val(h$)
read string 1,h$:texture1_total=val(h$)
for x=1 to texture1_total
read string 1,pox$:tile_texture1_pox(x)=val(pox$)
read string 1,poz$:tile_texture1_poz(x)=val(poz$)
next x
read string 1,h$:texture2_total=val(h$)
for x=1 to texture2_total
read string 1,pox$:tile_texture2_pox(x)=val(pox$)
read string 1,poz$:tile_texture2_poz(x)=val(poz$)
next x
read string 1,h$:texture3_total=val(h$)
for x=1 to texture3_total
read string 1,pox$:tile_texture3_pox(x)=val(pox$)
read string 1,poz$:tile_texture3_poz(x)=val(poz$)
next x
read string 1,h$:texture4_total=val(h$)
for x=1 to texture4_total
read string 1,pox$:tile_texture4_pox(x)=val(pox$)
read string 1,poz$:tile_texture4_poz(x)=val(poz$)
next x
make matrix matrix_number,matrix_width,matrix_depth,x_segments,z_segments
load image \"levelDATA\\tiles.bmp\",8000
prepare matrix texture 1,8000,2,2
for x= 1 to texture1_total
set matrix tile matrix_number,tile_texture1_pox(x),tile_texture1_poz(x),1
update matrix matrix_number
next x
for x=1 to texture2_total
set matrix tile matrix_number,tile_texture2_pox(x),tile_texture2_poz(x),2
update matrix matrix_number
next x
for x=1 to texture3_total
set matrix tile matrix_number,tile_texture3_pox(x),tile_texture3_poz(x),3
update matrix matrix_number
next x
for x=1 to texture4_total
set matrix tile matrix_number,tile_texture4_pox(x),tile_texture4_poz(x),4
update matrix matrix_number
next x
for x=0 to x_segments-1
for z=0 to z_segments-1
read string 1,h$:height=val(h$)
set matrix height matrix_number,x,z,height
update matrix matrix_number
next z
next x
rem make objects
read string 1,h$ : start_obj(1)=val(h$)
read string 1,h$ : total_obj(1)=val(h$)
for x= start_obj(1) to total_obj(1)
read string 1,h$ : sx#=val(h$)
read string 1,h$ : sy#=val(h$)
read string 1,h$ : sz#=val(h$)
read string 1,h$ : x#=val(h$)
read string 1,h$ : y#=val(h$)
read string 1,h$ : z#=val(h$)
read string 1,h$ : textureNUM(1)=val(h$)
read string 1,h$ : texture_name$(1)=h$
if textureNUM(1) > 1005 and textureNUM(1) < 2000
if image exist(textureNUM(1))=0 and path exist(\"levelDATA\\textures\\\"+texture_name$(1)) then load image \"levelDATA\\textures\\\"+texture_name$(1),textureNUM(1)
endif
make object box x,sx#,sy#,sz#
position object x,x#,y#,z#
if textureNUM(1) > 1005 and textureNUM(1) < 2000
if image exist(textureNUM(1))=1 then texture object x,textureNUM(1)
endif
next x
close file 1
REM save the level objects position for use in the get_nearestObjectFROM() function
global DIM level_objectX#(total_obj(1))
global DIM level_objectY#(total_obj(1))
global DIM level_objectZ#(total_obj(1))
tempvalue=start_obj(1) : tempvalue2=total_obj(1)
for n=tempvalue to tempvalue2
e=n-start_obj(1)+1
level_objectX#(e)=object position x(n)
level_objectY#(e)=object position y(n)
level_objectZ#(e)=object position z(n)
next n
ENDFUNCTION
FUNCTION get_Dist#(x1#,x2#,y1#,y2#,z1#,z2#)
n=make vector3(1)
set vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
output#=length vector3(1)
n=delete vector3(1)
ENDFUNCTION output#
REM two other functions i just put in here
REM create a collision box
FUNCTION prepare_collision(obj,flag)
xoffset2=object size x(obj)/2
yoffset2=object size y(obj)/2
zoffset2=object size z(obj)/2
xoffset=object size x(obj)/2*(-1)
yoffset=object size y(obj)/2*(-1)
zoffset=object size z(obj)/2*(-1)
make object collision box obj,xoffset,yoffset,zoffset,xoffset2,yoffset2,zoffset2,flag
ENDFUNCTION
REM get nearest object from a location
REM could maby be usefull for someone ?
FUNCTION get_nearestObjectFROM(x#,y#,z#,startobj,endobj)
totalobj=endobj-startobj+1
local DIM dist_to_obj#(totalobj)
local DIM object(totalobj)
REM store the distance to objects in an array
temp=startobj
for n=1 to totalobj
dist_to_obj#(n)=get_Dist#(x#,object position x(temp),y#,object position y(temp),z#,object position z(temp))
object(n)=temp
inc temp,1
next n
REM now sort the distance arrays for the array with the lowest number,(lowest distance)
temp#=dist_to_obj#(1)
output=object(1)
for n=1 to totalobj
if temp#>dist_to_obj#(n)
temp#=dist_to_obj#(n)
output=object(n)
endif
next n
ENDFUNCTION output
You need the included media in the download(1.28 mb).
Still a noob. easy comes easy goes