Anyone can help figure out whats wrong with this function?
function move(direction, object)
rem if object isnt moving, set its status to moving and set distance
if moving(object)=1
if direction(object)=1 then goal_z(object)=object position z(object) + 10
if direction(object)=2 then goal_x(object)=object position x(object) + 10
if direction(object)=3 then goal_z(object)=object position z(object) - 10
if direction(object)=4 then goal_x(object)=object position x(object) - 10
moving(object)=2
endif
rem if its moving....
if moving(object)=2
rem up
if goal_z(object)>object position z(object)
position object object, object position x(object), 5, object position z(object)+speed(object)
rem right
if goal_x(object)>object position x(object)
position object object, object position x(object)+speed(object), 5, object position z(object)
endif
rem down
if goal_z(object)<object position z(object)
position object object, object position x(object), 5, object position z(object)-speed(object)
endif
rem left
if goal_x(object)<object position x(object)
position object object, object position x(object)-speed(object), 5, object position z(object)
endif
rem if its at its destination
rem
rem Here I think something needs to be changed... Just a feeling :P
rem
rem Anyways, i think the error is somewhere in this function. Because the debugging
rem function shows that both direction and movement flags are updated when a key is pressed.
if object position z(object)=goal_z(object) then moving(object)=0
if object position x(object)=goal_x(object) then moving(object)=0
endif
endfunction
The direction is sorted out in a player_input function then this move function is called. But it doesnt want to move! I have a print_status function that shows that goal_x and goal_y is updated if i press an arrowkey, but it still wont move.
Direction variable:
1 = up
2 = right
3 = down
4 = left
Full source if you want to run it yourself
Rem Project: subtanks
Rem Created: 2004-06-05 21:29:49
Rem ***** Main Source File *****
rem setup
set display mode 1024, 768, 32
sync on
sync rate 60
rem variables
max_players = 2
dim goal_x (max_players)
dim goal_z (max_players)
dim direction (max_players)
dim moving (max_players)
dim speed (max_players)
rem LOAD
load_level()
DO
player_input(1)
update_cam()
print_status()
SYNC
LOOP
function load_level()
rem make temp player char
make object box 1, 10, 10, 10
position object 1, 25, 5, 20
color object 1, rgb(0,60,80)
direction(1) = 0
moving(1) = 0
speed(1) = 1
rem goal_z(1) = object position z(1)
rem goal_x(1) = object position x(1)
rem 1 will be added so its the same thing as 10
block=9
worldwidth = 200
worldheight = 200
rem make world, matrix
make matrix 1, worldwidth, worldheight, worldwidth/10, worldheight/10
position matrix 1, 0, -5, 0
remstart
load image "textures/ground.bmp",1
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
remend
update matrix 1
for mazey = 1 to worldheight/10
for mazex = 1 to worldwidth/10
read maze
rem if a block was found
if maze = 1
inc block
make object box block, 10, 10, 10
color object block, rgb(40,15,15)
position object block, mazex*10-5, groundheight, mazey*10-5
endif
next mazex
next mazey
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
endfunction
function player_input(object)
remstart check player input
up - 1
right - 2
down - 3
left - 4
remend
if moving(object)=0
direction(object)=0
if upkey()=1 then direction(object)=1
if rightkey()=1 then direction(object)=2
if downkey()=1 then direction(object)=3
if leftkey()=1 then direction(object)=4
if direction(object) > 0 then moving(object)=1
endif
rem BIG CHANGE here, moved the part when setting moving(object) to 1 up to
rem where it decides direction from input and only calls the move function
rem if the cube is moving (i.e. moving(object)=1). The reason is that the cube wont move,
rem i added the print status / debugging thing and found out that moving(1) is always 1,
rem so the game wont take input... it only does so if the moving(object)=0.
rem
rem I did solve that by setting the an if statment to only make moving(object) to 1
rem if direction is greater than 0. See that?
rem
rem The main problem now is that the cube wont move :( still... i dont know what i am
rem doing wrong :P. The print status claims that both direction and moving are changed
rem accordingly if an arrowkey is pressed. No idea what could be wrong...
if moving(object)=1 or moving(object)=2 then move(direction(object), object)
endfunction
function move(direction, object)
rem if object isnt moving, set its status to moving and set distance
if moving(object)=1
if direction(object)=1 then goal_z(object)=object position z(object) + 10
if direction(object)=2 then goal_x(object)=object position x(object) + 10
if direction(object)=3 then goal_z(object)=object position z(object) - 10
if direction(object)=4 then goal_x(object)=object position x(object) - 10
moving(object)=2
endif
rem if its moving....
if moving(object)=2
rem up
if goal_z(object)>object position z(object)
position object object, object position x(object), 5, object position z(object)+speed(object)
rem right
if goal_x(object)>object position x(object)
position object object, object position x(object)+speed(object), 5, object position z(object)
endif
rem down
if goal_z(object)<object position z(object)
position object object, object position x(object), 5, object position z(object)-speed(object)
endif
rem left
if goal_x(object)<object position x(object)
position object object, object position x(object)-speed(object), 5, object position z(object)
endif
rem if its at its destination
rem
rem Here I think something needs to be changed... Just a feeling :P
rem
rem Anyways, i think the error is somewhere in this function. Because the debugging
rem function shows that both direction and movement flags are updated when a key is pressed.
if object position z(object)=goal_z(object) then moving(object)=0
if object position x(object)=goal_x(object) then moving(object)=0
endif
endfunction
function update_cam()
camdistance = 50
rem place camera
position camera object position x(1), object position y(1)+camdistance, object position z(1)-camdistance
point camera object position x(1), object position y(1), object position z(1)
endfunction
function print_status()
set cursor 0,0
print "direction: ";direction(1)
print "moving: ";moving(1)
print "speed: ";speed(1)
print "goal_z";goal_z(1)
print "goal_x";goal_x(1)
endfunction
Thanks in advance
Mizipzor
Dreaming of creating a highly advanced AI mind