Not sure if you found the solution yet or not, but here is something for that walking that you could perhaps use. this is not real working code, but only part of it, but i think you can figure what i am after:
Code: Select all
function movecharacter(character)
n = character.n
curx = character.x
cury = character.y
destx = character.destx
desty = character.desty
xtargetreached = character.xtargetreached
ytargetreached = character.ytargetreached - - - These seven lines are just to make code easier to read, so that from now on we dont have to use "character.n", but we can instead just use "n"
if xtargetreached = FALSE - - - This checks that if x target have been reached already, then it doesnt move character in x direction anymore, otherwise character will keep shaking one pixel left and right each time this line is executed.
if curx =< destx
curx = curx +1
if curx => destx then xtargetreached = TRUE - - - Since we started for example from left side of the target, if we after movement are either on right side of it (the opposite site) or at same spot, then we know character have reached its target and can stop moving anymore in next cycle.
else
curx = curx-1
if curx =< destx then xtargetreached = TRUE
endif
endif
- - - Either curx is smaller/same as destx or it is bigger than x, this way, all possibilites are gone through, and character will always either move one step left or right.
if ytargetreached = FALSE
if cury =< desty
cury = cury + 1
if cury => desty then ytargetreached=TRUE
else
cury = cury - 1
if cury =< desty then ytargetreached=TRUE
endif
endif
displaylayer(n, curx, cury) (draws the character in to its current location
character.curx = curx
character.cury = cury - - - saving current position for next cycles need.
character.xtargetreached = xtargetreached
character.ytargetreached = ytargetreached - - - y and x targets reached need to be memorised, so it knows not to execute movement towards x or y, if only one of them is reached yet.
if xtargetreached = true and ytargetreached=true
return(TRUE)
else
return(FALSE)
endif - - - When calling this function, it will return wether character have reached both its target co=ordinates or not yet, so you can do something else then.
ENDFUNCTION
FUNCTION SetDestination(character, targetx, targety)
character.destx = targetx
character.desty = targety
character.xtargetreached = FALSE
character.ytargetreached = FALSE
ENDFUNCTION
movingman1 = {n = 1, x = 600, y = 600, destx=1800, desty = 1600 }
movingwoman2 = {n = 2, x=300, y=200, destx=500, desty=500}
repeat
targetreached = movecharacter(movingman1)
if targetreached=true then SetDestination(movingman1, 400, 100)
movecharacter(movingwoman2)
until quit=TRUE
This is an non working example (as there are stuff missing from here), but idea would be that with this code there would be two characters moving on screen at same time, and when this movingman1 character would reach its destination, it would be given a new destination where to go after that.