Planimeter / game-engine-2d

Planimeter Game Engine 2D - LÖVE-based game engine for Lua
https://github.com/Planimeter/game-engine-2d/wiki
MIT License
736 stars 74 forks source link

Add task queue for characters #66

Closed andrewmcwatters closed 8 years ago

andrewmcwatters commented 8 years ago

Rough draft sample API:

local function moveTo( position )
  return function( player, next )
    player:moveTo( position, next )
  end
end

local function pickupItem( item )
  return function( player, next )
    if ( not item or not item:isValid() ) then
      return next()
    end

    local classname = item:getClassname()
    item:remove()
    player:give( classname )
    next()
  end
end

function player:pickupItem( item )
  local pos = item:getPosition()
  self:addTask( moveTo( pos ) )
  self:addTask( pickupItem( item ) )
end

-- character:addTask( function( character, next )[, taskName ] )
-- character:removeTask( taskName )
-- character:removeTasks()
imthatgin commented 8 years ago

I think the API should include a queue system so people can stack up tasks. Unless I'm stupid and missed something.

andrewmcwatters commented 8 years ago

character:addTask() is like a task insert.

imthatgin commented 8 years ago

Excellent. Should each individual task have a "duration" argument so it can specify a "minimum" end time or does it just go through until "end" ?

andrewmcwatters commented 8 years ago

It's delegated to the task handler, so you basically have to call next() from your task to give up control. In the case of the moveTo() task above, I just pass next as a callback to character:moveTo(), thus calling next() when the player has arrived.

andrewmcwatters commented 8 years ago

I think a system like this would allow us to interrupt tasks in the event you were attacked, or a quest needed to override your task queue, etc.

imthatgin commented 8 years ago

Yeah, good planning.

andrewmcwatters commented 8 years ago

Pending downstream merge to grid-sdk from build 1141.

This is pretty cool stuff. For @Planimeter contributors, you can preview the changes in vertex-adventure upstream in master's latest commits.