That's some really great code Ben!
It works really well and without the 'Math' shown looks very smooth.
You can show your code like this:
Rem Project: Ship Path Movement
Rem Created: Saturday, January 29, 2011
Rem ***** Main Source File *****
sync on : sync rate 0 : backdrop off : autocam off
if check display mode(1024, 768, 32)=1 then set display mode 1024, 768, 32
set image colorkey 255,0,255
set normalization on
d3d_init
d3d_font 1, "Ariel", 10, 0, 0, 1 : ` Print Values Font
position camera 0, 100, 0
point camera 0, 0, 0
`Array for storing on/off state of all keys
dim key_state(300,1)
for set_loop = 0 to 300
key_state(set_loop,0) = 0
key_state(set_loop,1) = 0
next set_loop
dim fps_movement_correction#(0) as float : fps_movement_correction#(0) = 0.4
dim g_mouseclick(4) as integer
for set_mse_lp = 1 to 4
g_mouseclick(set_mse_lp) = -1
next set_mse_lp
global g_num_filesnames_found as integer : g_num_filesnames_found = 0
dim filenames$(200) as string
` ---------------- Neccessary for Nemesis ------------------
type SRTS_path_obj_in_range_type
array_pos as integer
distance# as float
endtype
dim SRTS_path_obj_in_range(100) as SRTS_path_obj_in_range_type
global g_SRTS_path_num_obj_in_range as integer
dim g_SRTS_PathColl_OldWrldCoordinates#(2)
dim g_SRTS_PathColl_NewWrldCoordinates#(2)
dim g_SRTS_PathColl_PathFreeWrldCoordinates(2)
global g_SRTS_PathColl_Closest_Obj_Arr as integer
global g_SRTS_PathColl_Closest_Dist# as float
` ----------------------------------------------------------
`Create an array to manage any added objects to distort and test the demonstration object's path
type obstacle_object_type
in_use as integer
object_number as integer
name$ as string
endtype
dim obstacle_object(50) as obstacle_object_type
`NOTE : Obstacle Object Numbers range from 100 to 150
for set_lp = 0 to 50
obstacle_object(set_lp).in_use = -1
obstacle_object(set_lp).object_number = set_lp + 100
make object sphere obstacle_object(set_lp).object_number, 4
hide object obstacle_object(set_lp).object_number
SC_setupObject obstacle_object(set_lp).object_number, 0, 0
color object obstacle_object(set_lp).object_number, rgb(rnd(255), rnd(255), rnd(255))
if set_lp = 0 then color object obstacle_object(set_lp).object_number, rgb(255,0,0)
if set_lp = 1 then color object obstacle_object(set_lp).object_number, rgb(0,255,0)
if set_lp = 2 then color object obstacle_object(set_lp).object_number, rgb(0,0,255)
if set_lp = 3 then color object obstacle_object(set_lp).object_number, rgb(255,255,0)
if set_lp = 4 then color object obstacle_object(set_lp).object_number, rgb(255,0,255)
if set_lp = 5 then color object obstacle_object(set_lp).object_number, rgb(255,255,255)
if set_lp = 6 then color object obstacle_object(set_lp).object_number, rgb(255,128,0)
if set_lp = 7 then color object obstacle_object(set_lp).object_number, rgb(0,255,255)
next set_lp
define_variables()
setup_engine()
main_code()
function define_variables()
`******** Variables Required in Nemesis ********
` Note: Nemesis is the main space RTS I am coding
` Nemesis since it is my nemesis, because I never finish it.
`See sliding collision type for the required array
#constant c_SRTS_CollisionPath_Obj 10
`***********************************************
`TEMP VARIABLES
global temp_flt1# as float
`OBSTACLE VARIABLES
global g_obstacle_selected_objnum as integer : g_obstacle_selected_objnum = -1
`MOVING OBJECT VARIABLES
global g_MOVEOBJ_speed# as float : g_MOVEOBJ_speed# = 0.3
`ENGINE VARIABLES
null = make vector3(distance_vector)
global g_total_num_obstacles as integer : g_total_num_obstacles = -1
global g_sprite2hit as integer : g_sprite2hit = -1
global g_DIST_obj_to_obj# as float
global g_srts_mse_pick_world_x# as float
global g_srts_mse_pick_world_y# as float
global g_srts_mse_pick_world_z# as float
global g_time_loop as integer : g_time_loop = 0
global g_show_graphics as integer : g_show_graphics = 1
global g_pause_value as integer : g_pause_value = 1
`INPUT Variables
global g_print_data_toggle as integer : g_print_data_toggle = 1
endfunction
function setup_engine()
`load image "Mouse_Icon - DOT Image.bmp", 1, 1
create bitmap 1, 1, 1
get image 1, 0, 0, 1, 1
delete bitmap 1
`Add Object Images
set text size 50
create bitmap 1, 128, 128
ink rgb(0, 146, 144), rgb(0,0,0) : text 10, 10, "ADD" : text 10, 70, "OBJ" : get image 2, 0, 0, 128, 128
ink rgb(27, 255, 252), rgb(0,0,0) : text 10, 10, "ADD" : text 10, 70, "OBJ" : get image 3, 0, 0, 128, 128
delete bitmap 1
sprite 2, screen width() - 100, screen height()-100, 2
scale sprite 2, 50
set text size 8
ink rgb(255,255,255), rgb(0,0,0)
`Add Objects A and B
#constant g_ObjA 11
make object cube g_ObjA, 1
position object g_ObjA, -50, 0, -40
#constant g_ObjB 12
make object cube g_ObjB, 1
position object g_ObjB, 50, 0, 40
`Add the moving object that represents the ship
#constant moving_obj 13
make object cone moving_obj, 3
position object moving_obj, -20, 0, -20
rotate limb moving_obj, 0, 90, 0, 0
`Add an object in the path
lib_Add_Obstacle(0, 0, 0, 1)
`[2] - Temp Object - Dot Plain Object - used as the simple object for the moveobj movement
#constant c_ENG_Temp_DOT_obj_num 2
make object plain c_ENG_Temp_DOT_obj_num, 0.1, 0.1
position object c_ENG_Temp_DOT_obj_num, 0, 0, 0
hide object c_ENG_Temp_DOT_obj_num
set object collision off c_ENG_Temp_DOT_obj_num
`[4] - World XYZ Movement Detection Plain
#constant c_drag_detection_plain_objnum 4
make object plain c_drag_detection_plain_objnum, 300000, 230000 : `Each value is 10k above just visible on the screen
position object c_drag_detection_plain_objnum, 0, 0, 0
xrotate object c_drag_detection_plain_objnum, 90
hide object c_drag_detection_plain_objnum
set object collision off c_drag_detection_plain_objnum
`---------------------------------REQUIRED BY NEMESIS -------------------------------------
`[10] - collision path detection object + world coordinates limb
make object cube c_SRTS_CollisionPath_Obj, 0.5
make mesh from object 1, c_SRTS_CollisionPath_Obj
add limb c_SRTS_CollisionPath_Obj, 1, 1
delete mesh 1
offset limb c_SRTS_CollisionPath_Obj, 1, 0, 0, 25
color limb c_SRTS_CollisionPath_Obj, 1, rgb(255,0,0)
position object c_SRTS_CollisionPath_Obj, 0, 0, 0
`------------------------------------------------------------------------------------------
endfunction
function main_code()
do
if g_time_loop = 0
if screen fps() > 0
fps_movement_correction#(0) = 100.0 / screen fps()
if fps_movement_correction#(0) > 10
fps_movement_correction#(0) = 1
endif
else
fps_movement_correction#(0) = 0
endif
else
fps_movement_correction#(0) = 0.5
endif
sprite 1, mousex(), mousey(), 1
if mouseclick() = 0 and g_sprite2hit = 1 then g_sprite2hit = -1
if sprite collision(1, 2) = 1
sprite 2, screen width() - 100, screen height()-100, 3
if mouseclick() = 1 and g_sprite2hit = -1
g_sprite2hit = 1
x = rnd(20) + -10
z = rnd(20) + -10
lib_Add_Obstacle(x, 0, z, 1)
endif
else
sprite 2, screen width() - 100, screen height()-100, 2
endif
INPUT_keyboard()
INPUT_mouse()
MOVEMENT_Move_Object()
if g_print_data_toggle = 1
print_data()
endif
fastsync
`Cheap time slowdown
if g_time_loop > 0
for pause_loop = 1 to g_time_loop * 1000000
next pause_loop
endif
loop
endfunction
function INPUT_keyboard()
if scancode() > 1 and scancode() < 11
`2-10
if scancode() - 1 = 1 then g_MOVEOBJ_speed# = 0.1
if scancode() - 1 = 2 then g_MOVEOBJ_speed# = 0.21
if scancode() - 1 = 3 then g_MOVEOBJ_speed# = 0.32
if scancode() - 1 = 4 then g_MOVEOBJ_speed# = 0.44
if scancode() - 1 = 5 then g_MOVEOBJ_speed# = 0.55
if scancode() - 1 = 6 then g_MOVEOBJ_speed# = 0.66
if scancode() - 1 = 7 then g_MOVEOBJ_speed# = 0.77
if scancode() - 1 = 8 then g_MOVEOBJ_speed# = 0.89
if scancode() - 1 = 9 then g_MOVEOBJ_speed# = 1
endif
`[ P ] - Pause object movement
if KEYSTATE(25)= 1 and key_state(25,0)= 0
if g_pause_value = 0
g_pause_value = 1
else
g_pause_value = 0
endif
key_state(25,0)=1
endif
if KEYSTATE(25)=0 and key_state(25,0)=1 then key_state(25,0)=0
`[ [ ] - Decrease Time Speed
if KEYSTATE(26)= 1 and key_state(26,0)= 0
inc g_time_loop, 1
key_state(26,0)=1
endif
if KEYSTATE(26)=0 and key_state(26,0)=1 then key_state(26,0)=0
`[ ] ] - Increase Time Speed
if KEYSTATE(27)= 1 and key_state(27,0)= 0
if g_time_loop > 0
dec g_time_loop, 1
endif
key_state(27,0)=1
endif
if KEYSTATE(27)=0 and key_state(27,0)=1 then key_state(27,0)=0
`[Spacebar] - Reset moving obj position to the start position
if KEYSTATE(57)= 1 and key_state(57,0)= 0
position object moving_obj, object position x(g_ObjA), object position y(g_ObjA), object position z(g_ObjA)
key_state(57,0)=1
endif
if KEYSTATE(57)=0 and key_state(57,0)=1 then key_state(57,0)=0
`[S] - Save Obstacle Data
if KEYSTATE(31)= 1 and key_state(31,0)= 0
save_data()
key_state(31,0)=1
endif
if KEYSTATE(31)=0 and key_state(31,0)=1 then key_state(31,0)=0
`[G] - Math Graphics Display Toggle
if KEYSTATE(34)= 1 and key_state(34,0)= 0
if g_show_graphics = -1
g_show_graphics = 1
show object c_SRTS_CollisionPath_Obj
else
g_show_graphics = -1
hide object c_SRTS_CollisionPath_Obj
endif
key_state(34,0)=1
endif
if KEYSTATE(34)=0 and key_state(34,0)=1 then key_state(34,0)=0
`[L] - Load Obstacle Data
if KEYSTATE(38)= 1 and key_state(38,0)= 0
load_data()
key_state(38,0)=1
endif
if KEYSTATE(38)=0 and key_state(38,0)=1 then key_state(38,0)=0
`[F1] - Toggle display test variables
if KEYSTATE(59)= 1 and key_state(59,0)= 0
if g_print_data_toggle = -1
g_print_data_toggle = 1
else
g_print_data_toggle = -1
endif
key_state(59,0)=1
endif
if KEYSTATE(59)=0 and key_state(59,0)=1 then key_state(59,0)=0
`[F2] - Toggle display data variables
if KEYSTATE(60)= 1 and key_state(60,0)= 0
key_state(60,0)=1
endif
if KEYSTATE(60)=0 and key_state(60,0)=1 then key_state(60,0)=0
endfunction
function INPUT_mouse()
if mouseclick() = 1 and g_mouseclick(1) = -1
for pick_lp1 = 0 to 50
g_mouseclick(1) = 1
obj_num = obstacle_object(pick_lp1).object_number
target = pick object(mousex(), mousey(), obj_num, obj_num)
if target <> 0
g_obstacle_selected_objnum = target
exit
else
g_obstacle_selected_objnum = -1
endif
next pick_lp1
endif
if mouseclick() = 1 and g_mouseclick(1) = 1
if g_obstacle_selected_objnum <> -1
lib_CAM_MOUSE_2d_to_3d()
position object g_obstacle_selected_objnum, g_srts_mse_pick_world_x#, g_srts_mse_pick_world_y#, g_srts_mse_pick_world_z#
endif
endif
if mouseclick() = 0 and g_mouseclick(1) = 1
g_mouseclick(1) = -1
endif
endfunction
function MOVEMENT_Move_Object()
`Standardised search parameters
local l_spherecast_radius# as float : l_spherecast_radius# = 3
local l_object_react_distance# as float : l_object_react_distance# = (g_MOVEOBJ_speed# * fps_movement_correction#(0) * 150) : `Distance where actions are made
local l_object_detect_distance# as float : l_object_detect_distance# = (g_MOVEOBJ_speed# * fps_movement_correction#(0) * 300) : `Distance where future collisions are anticipated
`NOTE: At the start the moving object does not move, just the test object. The moving object moves at the end only
`GET THE MOVE OBJECT (SHIP) START AND END COORDINATES FOR SPHERECASTING USING A SIMPLER TEST OBJECT
`1 - Position zero always stores the object start coordinates
`Old coordinates
g_SRTS_PathColl_OldWrldCoordinates#(0) = object position x(moving_obj)
g_SRTS_PathColl_OldWrldCoordinates#(1) = object position y(moving_obj)
g_SRTS_PathColl_OldWrldCoordinates#(2) = object position z(moving_obj)
`2 - Place the test object in the correct location and move it to the distance# coordinates
position object 2, g_SRTS_PathColl_OldWrldCoordinates#(0), g_SRTS_PathColl_OldWrldCoordinates#(1), g_SRTS_PathColl_OldWrldCoordinates#(2)
rotate object 2, object angle x(moving_obj), object angle y(moving_obj), object angle z(moving_obj)
`3 - Move the test object to the [l_object_react_distance#] coordinates
`Length of the spherecast determined by this line, adjust for the speed of the craft taking into account the distance required to miss something - not the distance travelled per code loop
move object 2, l_object_react_distance# * g_pause_value
g_SRTS_PathColl_NewWrldCoordinates#(0) = object position x(2)
g_SRTS_PathColl_NewWrldCoordinates#(1) = object position y(2)
g_SRTS_PathColl_NewWrldCoordinates#(2) = object position z(2)
`4 - Record all objects within [l_object_detect_distance#] radius
g_SRTS_path_num_obj_in_range = 0
for search_lp = 0 to 50
if obstacle_object(search_lp).in_use = 1
Lib_DISTANCE_object_to_object(moving_obj, obstacle_object(search_lp).object_number)
if g_DIST_obj_to_obj# < l_object_detect_distance#
inc g_SRTS_path_num_obj_in_range, 1
SRTS_path_obj_in_range(g_SRTS_path_num_obj_in_range).array_pos = search_lp
SRTS_path_obj_in_range(g_SRTS_path_num_obj_in_range).distance# = g_DIST_obj_to_obj#
endif
endif
next search_lp
`Doesn't do anything, just displays lines to each detected obj etc for me to see in blue
d3d_color 0, 0, 255, 255
if g_SRTS_path_num_obj_in_range > 0
for aloop = 1 to g_SRTS_path_num_obj_in_range
if g_show_graphics = 1
d3d_line3d object position x(moving_obj), object position y(moving_obj), object position z(moving_obj), object position x(obstacle_object(SRTS_path_obj_in_range(aloop).array_pos).object_number), object position y(obstacle_object(SRTS_path_obj_in_range(aloop).array_pos).object_number), object position z(obstacle_object(SRTS_path_obj_in_range(aloop).array_pos).object_number)
endif
next aloop
endif
d3d_color 255, 255, 255, 255
`5 - Setup the collision test object + its limb number 1
offset limb c_SRTS_CollisionPath_Obj, 1, 0, 0, l_object_react_distance#
position object c_SRTS_CollisionPath_Obj, g_SRTS_PathColl_OldWrldCoordinates#(0), g_SRTS_PathColl_OldWrldCoordinates#(1), g_SRTS_PathColl_OldWrldCoordinates#(2)
rotate object c_SRTS_CollisionPath_Obj, object angle x(moving_obj), object angle y(moving_obj), object angle z(moving_obj)
`5 - Perform a Spherecast in the direction the moving object is heading to determine if it is going
` to collide against any of the objects found within the distance_scanned# radius
if g_SRTS_path_num_obj_in_range > 0
collision_confirmed = -1
for chk_heading_lp = 1 to g_SRTS_path_num_obj_in_range
if SRTS_path_obj_in_range(chk_heading_lp).distance# < l_object_react_distance#
sc_updateobject obstacle_object(SRTS_path_obj_in_range(chk_heading_lp).array_pos).object_number
if SC_spherecast (obstacle_object(SRTS_path_obj_in_range(chk_heading_lp).array_pos).object_number, object position x(c_SRTS_CollisionPath_Obj), object position y(c_SRTS_CollisionPath_Obj), object position z(c_SRTS_CollisionPath_Obj), limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1), l_spherecast_radius#, 0 ) = 1
collision_confirmed = 1
endif
endif
next chk_heading_lp
endif
if collision_confirmed = 1
rotate object c_SRTS_CollisionPath_Obj, object angle x(moving_obj), object angle y(moving_obj), object angle z(moving_obj)
turn_value_counter = 0
repeat
if turn_value_counter < 60
inc turn_value_counter, 5
else
if turn_value_counter < 180
inc turn_value_counter, 15
else
inc turn_value_counter, 20
endif
endif
`Check Left
turn object left c_SRTS_CollisionPath_Obj, turn_value_counter
if g_show_graphics = 1
d3d_color 0, 255, 255, 255 : `Show the LEFT line Spehercast lines in CYAN
d3d_line3d object position x(c_SRTS_CollisionPath_Obj), object position y(c_SRTS_CollisionPath_Obj), object position z(c_SRTS_CollisionPath_Obj), limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1)
d3d_color 255, 255, 255, 255
endif
collision_detected = -1
for chk_all_obj_lp = 1 to g_SRTS_path_num_obj_in_range
if sc_spherecast(obstacle_object(SRTS_path_obj_in_range(chk_all_obj_lp).array_pos).object_number, object position x(c_SRTS_CollisionPath_Obj), object position y(c_SRTS_CollisionPath_Obj), object position z(c_SRTS_CollisionPath_Obj), limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1), l_spherecast_radius#, 0) = 1
collision_detected = 1
endif
next chk_all_obj_lp
if collision_detected = -1
g_SRTS_PathColl_PathFreeWrldCoordinates(0) = limb position x(c_SRTS_CollisionPath_Obj, 1)
g_SRTS_PathColl_PathFreeWrldCoordinates(1) = limb position y(c_SRTS_CollisionPath_Obj, 1)
g_SRTS_PathColl_PathFreeWrldCoordinates(2) = limb position z(c_SRTS_CollisionPath_Obj, 1)
exit
else
`Check Right
if turn_value_counter < 60
inc turn_value_counter, 5
else
if turn_value_counter < 180
inc turn_value_counter, 15
else
inc turn_value_counter, 20
endif
endif
turn object right c_SRTS_CollisionPath_Obj, turn_value_counter
if g_show_graphics = 1
d3d_color 255, 255, 0, 255 : `Show the RIGHT line Spehercast lines in YELLOW
d3d_line3d object position x(c_SRTS_CollisionPath_Obj), object position y(c_SRTS_CollisionPath_Obj), object position z(c_SRTS_CollisionPath_Obj), limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1)
d3d_color 255, 255, 255, 255
endif
collision_detected = -1
for chk_all_obj_lp = 1 to g_SRTS_path_num_obj_in_range
if sc_spherecast(obstacle_object(SRTS_path_obj_in_range(chk_all_obj_lp).array_pos).object_number, object position x(c_SRTS_CollisionPath_Obj), object position y(c_SRTS_CollisionPath_Obj), object position z(c_SRTS_CollisionPath_Obj), limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1), l_spherecast_radius#, 0) = 1
collision_detected = 1
endif
next chk_all_obj_lp
if collision_detected = -1
g_SRTS_PathColl_PathFreeWrldCoordinates(0) = limb position x(c_SRTS_CollisionPath_Obj, 1)
g_SRTS_PathColl_PathFreeWrldCoordinates(1) = limb position y(c_SRTS_CollisionPath_Obj, 1)
g_SRTS_PathColl_PathFreeWrldCoordinates(2) = limb position z(c_SRTS_CollisionPath_Obj, 1)
exit
endif
endif
until turn_value_counter > 320
if collision_detected = -1
Lib_MOVEMENT_rotate_to_xyz(moving_obj, g_SRTS_PathColl_PathFreeWrldCoordinates(0), g_SRTS_PathColl_PathFreeWrldCoordinates(1), g_SRTS_PathColl_PathFreeWrldCoordinates(2))
endif
else
Lib_MOVEMENT_rotate_to_object(moving_obj, g_ObjB)
endif
move object moving_obj, g_MOVEOBJ_speed# * fps_movement_correction#(0) * g_pause_value
`Place the move object back at the start point if it is close to the end point.
Lib_DISTANCE_object_to_object(moving_obj, g_ObjB)
if g_DIST_obj_to_obj# < 2
position object moving_obj, object position x(g_ObjA), object position y(g_ObjA), object position z(g_ObjA)
endif
if g_show_graphics = 1
`Displays the end of the Speherecast in white
d3d_circle3d l_spherecast_radius#, limb position x(c_SRTS_CollisionPath_Obj, 1), limb position y(c_SRTS_CollisionPath_Obj, 1), limb position z(c_SRTS_CollisionPath_Obj, 1), 0, 1, 0
` l_object_detect_distance# radius in GREEN CIRCLE
d3d_color 0, 255, 0, 255 : d3d_circle3d l_object_react_distance#, object position x(moving_obj), object position y(moving_obj), object position z(moving_obj), 0, 1, 0
` l_object_detect_distance# radius in RED CIRCLE
d3d_color 255, 0, 0, 255 : d3d_circle3d l_object_detect_distance#, object position x(moving_obj), object position y(moving_obj), object position z(moving_obj), 0, 1, 0
d3d_color 255, 255, 255, 255
endif
endfunction
function lib_CAM_MOUSE_2d_to_3d()
show object c_drag_detection_plain_objnum
target = pick object(mousex(), mousey(), c_drag_detection_plain_objnum, c_drag_detection_plain_objnum)
hide object c_drag_detection_plain_objnum
g_srts_mse_pick_world_x# = get pick vector x() + camera position x()
g_srts_mse_pick_world_y# = get pick vector y() + camera position y()
g_srts_mse_pick_world_z# = get pick vector z() + camera position z()
endfunction
function Lib_MOVEMENT_rotate_to_object(main_object_num, point_to_obj_num)
EZro_SetEuler object angle x(main_object_num), object angle y(main_object_num), object angle z(main_object_num)
EZro_SetPos object position x(main_object_num), object position y(main_object_num), object position z(main_object_num)
EZro_RotateTo 2, object position x(point_to_obj_num), object position y(point_to_obj_num), object position z(point_to_obj_num), 3
EZro_FindEuler
rotate object main_object_num ,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
endfunction
function Lib_MOVEMENT_rotate_to_xyz(r_objnum, r_x#, r_y#, r_z#)
EZro_SetEuler object angle x(r_objnum), object angle y(r_objnum), object angle z(r_objnum)
EZro_SetPos object position x(r_objnum), object position y(r_objnum), object position z(r_objnum)
EZro_RotateTo 2, r_x#, r_y#, r_z#, 3
EZro_FindEuler
rotate object r_objnum ,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
endfunction
function Lib_DISTANCE_object_to_object(object1, object2)
local x1# as float : local y1# as float : local z1# as float
local x2# as float : local y2# as float : local z2# as float
x1# = object position x(object1) : y1# = object position y(object1)
z1# = object position z(object1)
x2# = object position x(object2) : y2# = object position y(object2)
z2# = object position z(object2)
set vector3 distance_vector, x1#-x2#, y1#-y2#, z1#-z2#
g_DIST_obj_to_obj# = length vector3(distance_vector)
endfunction
function lib_Add_Obstacle(r_x#, r_y#, r_z#, incr_objnum)
for search_lp = 0 to 50
if obstacle_object(search_lp).in_use = -1
if incr_objnum = 1
inc g_total_num_obstacles, 1
endif
obstacle_object(search_lp).in_use = 1
show object obstacle_object(search_lp).object_number
position object obstacle_object(search_lp).object_number, r_x#, r_y#, r_z#
exit
endif
next search_lp
endfunction
function save_data()
delete file "Save_Data1.ben"
open to write 1, "Save_Data1.ben"
write long 1, g_total_num_obstacles
for write_lp = 0 to g_total_num_obstacles
if obstacle_object(write_lp).in_use = 1
x# = object position x(obstacle_object(write_lp).object_number)
y# = object position y(obstacle_object(write_lp).object_number)
z# = object position z(obstacle_object(write_lp).object_number)
write float 1, x#
write float 1, y#
write float 1, z#
endif
next write_lp
close file 1
endfunction
function load_data()
empty checklist
g_num_filesnames_found = 0
perform checklist for files
for files_lp = 1 to checklist quantity()
if checklist value a(files_lp) = 0
if right$(checklist string$(files_lp), 3) = "ben"
inc g_num_filesnames_found, 1
filenames$(g_num_filesnames_found) = checklist string$(files_lp)
endif
endif
next files_lp
if g_num_filesnames_found > 0
file_number_selected = 1
exit_condition = -1
get_key_press = 1
filenumber_chosen = -1
repeat
print "Please select the file to load (use up and down cursors to select a file)"
print
for prnt_scr_lp = 1 to g_num_filesnames_found
if prnt_scr_lp = file_number_selected
print filenames$(prnt_scr_lp) + "[SELECTED]"
else
print filenames$(prnt_scr_lp)
endif
next prnt_scr_lp
`
if get_key_press = -1 and scancode() <> 0
if upkey() = 1 and file_number_selected > 1
dec file_number_selected, 1
endif
if downkey() = 1 and file_number_selected < g_num_filesnames_found
inc file_number_selected, 1
endif
if returnkey() = 1
filenumber_chosen = file_number_selected
exit_condition = 1
endif
get_key_press = 1
endif
if scancode() = 0 and get_key_press = 1
get_key_press = -1
endif
`
sync
until exit_condition = 1
`Reset all the obstacles to zero
g_total_num_obstacles = 0
for set_lp = 0 to 50
obstacle_object(set_lp).in_use = -1
hide object obstacle_object(set_lp).object_number
next set_lp
`Read the file and add all the obstacles back in the right place
open to read 1, filenames$(filenumber_chosen)
read long 1, g_total_num_obstacles
for read_loop = 0 to g_total_num_obstacles
read float 1, x#
read float 1, y#
read float 1, z#
if obstacle_object(read_loop).in_use = -1
lib_Add_Obstacle(x#, y#, z#, 0)
endif
next read_loop
close file 1
endif
endfunction
function print_data()
d3d_starttext
sp = 19
inc sp, 19 : d3d_text 1, screen width() * 0.85, sp, 0, "FPS : " + str$(screen fps())
if g_time_loop = 0
inc sp, 19 : d3d_text 1, screen width() * 0.85, sp, 0, "Slowdown : OFF"
else
inc sp, 19 : d3d_text 1, screen width() * 0.85, sp, 0, "Slowdown : x" + str$(g_time_loop)
endif
if g_pause_value = 0
inc sp, 19 : d3d_text 1, screen width() * 0.85, sp, 0, "Pause : ON"
else
inc sp, 19 : d3d_text 1, screen width() * 0.85, sp, 0, "Pause : OFF"
endif
sp = 19
inc sp, 19 : d3d_text 1, 30, sp, 0, "1-9 : Change Object Speed"
inc sp, 19 : d3d_text 1, 30, sp, 0, "[ ] : Change Time"
inc sp, 19 : d3d_text 1, 30, sp, 0, "Spacebar : Reset Object position to start"
inc sp, 19 : d3d_text 1, 30, sp, 0, "G : Hide/Show Program Maths"
inc sp, 19 : d3d_text 1, 30, sp, 0, "L : Load Object Positions"
inc sp, 19 : d3d_text 1, 30, sp, 0, "S : Save Object Positions to Default.ben"
inc sp, 19 : d3d_text 1, 30, sp, 0, "P : Pause Object"
d3d_text 1, screen width() * 0.3 , screen height() * 0.95, 0, "SPACEBAR - RETURN TO START : '[' AND ']' TO CHANGE PROGRAM SPEED"
d3d_endtext
endfunction
...by putting it between two boxes like this (just take the dots out):
[.code lang=dbp]
your code here[./code]