hi Gutsplatt ..
I would write the program something like the following - which is only to give you an idea ... it has a lot of variables undefined so dont try to run it as is .. it is just an outline which will hopefully help you ..
.. the code assumes the stated *.x file and *.jpg files are in your project folder. please feel free to use / change / ignore this code as you like .. this code also allows for a different set of animations to be played depending on the characters direction .. which doesnt have to be so - but might be more interesting ..
#constant model_walking_left 1
#constant model_walking_right 2
#constant model_turning_left 324
#constant bottom_of_world 2000
#constant camera_light_error 2467
#constant model_mov_error 16
global gamehalted = 0
global startframe = 0
global endframe = 0
global curr_frame =0
global curr_frames_running = 0
global curr_ind_curr_frame = 0
x# = -5.0
y# = 0.0
z# = 10.0
setup()
objnumber = getobjnumber()
if objnumber = 0 then raise_alarm(1)
imgnumber = getimagenumber()
if imgnumber = 0 then raise_alarm(2)
if gamehalted=0
load object "myobj.x", objnumber
load image "myimage.jpg", imgnumber
texture object objnumber, imgnumber
position object objnumber, x#,y#,z#
endif
if object exist(objnumber)=0
raise_alarm(3)
endif
do
if condition = met and gamehalted = 0
play object objnumber, startframe, finishframe
pass_value = 0
if leftkey() then retval = updatemodelposition(model_walking_left)
if rightkey() then retval = updatemodelposition(model_walking_right)
if controlkey() and leftkey() then retval = updatemodelposition(model_turning_left)
if retval = 0
raise_alarm(model_mov_error)
else
set object frame objnumber, curr_frame, 1
endif
if scancode() = scannumber then pass_value = 1
if scancode() = anotherscannumber then pass_value = 749
retval= update_camera_light(pass_value)
if retval = 0 then raise_alarm(camera_light_error)
endif
sync
loop
cleanup()
end
function setup()
hide mouse
set display mode 1280,1024,32
sync rate 30: sync on
color backdrop rgb(0,0,0)
backdrop on
autocam off
position camera 0,0,-100
point camera 0,0,0
make light 1
position light 1, 0,0,-100
point light 1, 0,0,0
endfunction
function getobjectnumber()
for av_num = 1 to 65500
if object exist (av_num) =0
exitfunction av_num
next ave_num
endfunction 0
function getimagenumber()
for av_img = 1 to 65500
if image exist (av_img) = 0
exitfunction av_num
next av_img
endfunction 0
function updatemodelposition(i as integer, dir as integer)
retval = 0
select dir
case model_walking_left : dec x#, speed : curr_frame = helperfn_calc_curr_frame(model_walking_left) : retval = 1 :endcase
case model_walking_right : inc x#, speed :curr_frame = helperfn_calc_curr_frame(model_walking_right) : retval = 2 : endcase
case model_walking_toward_screen : dec z#, speed : curr_frame = helperfn_calc_curr_frame(model_walking_toward_screen) : retval = 3 : endcase
case model_walking_away_screen : inc z#, speed : curr_frame = helperfn_calc_curr_frame(model_walking_away_screen): retval = 4 : endcase
case model_climbing_up : dec y# : curr_frame = helperfn_calc_curr_frame(model_climbingup): retval = 5: endcase
case model_climbing_down : if y# < bottom_of_world then curr_frame = helperfn_calc_curr_frame(model_climbing_down): retval = 6 : endcase
case Model_turning_left : curr_frame = helperfn_calc_curr_frame(model_turning_left) : retval = 7 : endcase
case model_turning_right : curr_frame = helperfn_calc_curr_frame(model_turning_right) : retval = 8 : endcase
case default : retval = 0 : endcase
endselect
if retval = 0 then exitfunction retval
helperfn_face_my_model(i, retval)
position model i, x#,y#,z#
endfunction retval
function helperfn_calc_curr_frame(i as integer)
if curr_frames_running <> i
select i
case object_moving_left
curr_ind_curr_frames = start_of_left_animation
curr_frames_running = object_moving_left
endcase
case whatever other foreseen values
find start of animation sequence for relevant movement
maybe held in data structure
endcase
case default: raise some error : endcase
endselect
else
select i
case object_moving_left
init through object's left animation sequence by inc curr_ind_curr_frame until end of loop found and then return to start of left sequence
endcase
case anything else foreseen
init through relevant sequence by inc curr_ind_curr_frame
endcase
case anything unforeseen
raise an error - eg. by calling raise_alarm with a suitable value
endcase
endselect
endif
endfunction
function helperfn_face_my_model( i, d)
whatever it takes to face model in correct direction based on movement direction
eg, if d = model_walking_left then yrotate model i, facing_left
endfuntion
function update_camera_light(received_value)
allok = 0
if received_value = 0 : allok = 1 : exitfunction allok : endif
if received_value = 1 : position camera 0, 25.0,5.0,0.0 : allok = 1 : endif
if received_value = 794 : set light range 1, light range 1 + reqdis : allok = 1: endif
endfunction allok
function cleanup()
gamehalted=1
for num = 1 to 65500
if object exist (num)
delete object num
else
exit
endif
next num
for num = 1 to 65500
if image exist (num)
delete image(num)
else
exit
endif
next num
endfunction
function raise_alarm(erno as integer)
gamehalted = 1
dealtwitherror = 0
set cursor 10,10
if erno = 1 : print "error 1" : dealtwitherror = 1: endif
if erno = 2 : print "error 2" : dealtwitherror = 1: endif
if erno = 3 : print "error 3" : dealtwitherror = 1: endif
if erno = camera_light_error : print "error cam / light" : dealtwitherror = 1: endif
if erno = model_mov_error : print "model move error" : dealtwitherror = 1: endif
if dealtwitherror = 0 then print "unknown error occured"
set cursor 10,20
print "program halted"
set cursor 10,30
print "press escape key to go fix error"
endfunction
if effort>reward : gosub home : endif