Moving based on path selection

Now that this path is being found as needed, the last crucial step is to actually carry it out.

Getting ready

Open the file character/init.lua, which includes specific actions and features used by both computer- and human-controlled players.

Getting on with it

The step function is in fact very similar to the network functions from TranslationBuddy, and that's what we're going to model it on:

function presence.step(target)
  local origin = getfenv(2).location()
  local self = coroutine.running()
  local function resume(event)
   event.target:removeEventListener('Moved', resume)
   coroutine.resume(self, 'finished')
  end
  local motion = origin.map:Move(character, getfenv(2).world, target.x - origin.x, target.y - origin.y)
  if motion then
   motion:addEventListener('Moved', resume)
   repeat local outcome = coroutine.yield()
   until outcome == 'finished'
   return true
  end
 end

What did we do?

We expanded the computer character control code to carry out an actual Move command over time, and return control to the character controller when the move is completed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.75.217