-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactor.lua
More file actions
48 lines (36 loc) · 1.05 KB
/
actor.lua
File metadata and controls
48 lines (36 loc) · 1.05 KB
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
module(..., package.seeall)
require 'tileset'
require 'vector'
require 'utils'
local requireds = {'filename'}
function Actor(opts)
self = {}
for _,n in ipairs(requireds) do assert(opts[n], n.." is required") end
self.image = tileset.XMLTileset(opts.filename)
self.pos = opts.startPos
self.script = opts.script
self.animState = 1
self.animPos = 0
self.dir = 'right'
self.anim = nil
self.scriptStep = 1
self.nextAction = function(self)
self.scriptStep = self.scriptStep + 1
if self.script[self.scriptStep] then
self[self.script[self.scriptStep].func](self, self.script[self.scriptStep].params)
end
end
self.move = function(self, params)
assert(params.x and params.y, 'X and Y missing from call to move')
self.pos.x = self.pos.x + params.x
self.pos.y = self.pos.y + params.y
end
self.moveTo = function(self, params)
assert(params.x and params.y, 'X and Y missing from call to move')
self.pos.x = params.x
self.pos.y = params.y
end
self.switchAnim = function(self)
end
return self
end