-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
character.lua
65 lines (52 loc) · 1.16 KB
/
character.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Character class
--
--==========================================================================--
entities.require( "entity" )
class "character" ( "entity" )
function character:character()
entity.entity( self )
end
function character:addTask( task, name )
if ( self._tasks == nil ) then
self._tasks = {}
end
table.insert( self._tasks, {
task = task,
name = name
} )
end
function character:moveTo( position, callback )
if ( callback ) then
callback()
end
end
function character:nextTask()
local tasks = self._tasks
table.remove( tasks, 1 )
if ( #tasks == 0 ) then
self:removeTasks()
end
end
function character:removeTasks()
self._tasks = nil
end
function character:tick( timestep )
self:updateTasks()
entity.tick( self, timestep )
end
function character:updateTasks()
local tasks = self._tasks
if ( tasks == nil ) then
return
end
local task = tasks[ 1 ]
if ( task and not task.running ) then
task.running = true
task.task( self, function() self:nextTask() end )
end
end
function character:__tostring()
return "character: " .. self.__type
end