-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacca.lua
More file actions
executable file
·261 lines (218 loc) · 6.77 KB
/
acca.lua
File metadata and controls
executable file
·261 lines (218 loc) · 6.77 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
--[[
ACCA: Automatic Constructor for Character Animation in LÖVE
Copyright (C) 2015 Nelson Lombardo
License: MIT
Based on Bart Bes work.
]]
local anim_mt = {}
anim_mt.__index = anim_mt
function newCharacter(folder, element, ext, delay, default)
local a = {
list = {},
action = {},
actual = default,
previous = ""
}
--love.graphics.print(folder.."/"..element, 0, 0)
local actions = love.filesystem.getDirectoryItems(folder.."/"..element)
for k, v in ipairs(actions) do
--love.graphics.print(action, 0, 0)
if love.filesystem.isDirectory(folder.."/"..element.."/"..v) then
a.action[v] = {
img = {},
frames = 1,
delays = {},
timer = 0,
position = 1,
speed = 1,
playing = true,
mode = 1,
direction = 1
}
table.insert(a.list, v)
-- Need get all pictures
local file = "01."..ext
local path = folder.."/"..element.."/"..v.."/"
while love.filesystem.exists(path..file) do
a.action[v].img[a.action[v].frames] = love.graphics.newImage(path..file)
a.action[v].frames = a.action[v].frames + 1
if a.action[v].frames <= 9 then
file = "0"..a.action[v].frames.."."..ext
else
file = a.action[v].frames.."."..ext
end
end
a.action[v].frames = a.action[v].frames - 1
-- Ready
for i=1,a.action[v].frames do
table.insert(a.action[v].delays, delay)
end
end
end
a.action[a.actual].playing = true
return setmetatable(a, anim_mt)
end
function anim_mt:setAction(action)
self.actual = action
self.action[action].playing = true
end
function anim_mt:getAction()
return self.actual
end
function anim_mt:resetAction(action)
--self.action[action].position
--local selfie = self.action[action]
self:seek(1)
self.actual = action
self.action[action].playing = true
end
function anim_mt:setActionSpeed(action,speed)
--self:seek(1)
self.actual = action
self.action[action].speed = speed
end
function anim_mt:update(dt)
local selfie = self.action[self.actual]
if not selfie.playing then return end
selfie.timer = selfie.timer + dt * selfie.speed
if selfie.timer > selfie.delays[selfie.position] then
selfie.timer = selfie.timer - selfie.delays[selfie.position]
selfie.position = selfie.position + 1 * selfie.direction
if selfie.position == 0 then
selfie.position = selfie.frames
elseif selfie.position > selfie.frames then
if selfie.mode == 1 then
selfie.position = 1
elseif selfie.mode == 2 then
selfie.position = selfie.position - 1
self:stop()
elseif selfie.mode == 3 then
selfie.direction = -1
selfie.position = selfie.position - 1
end
elseif selfie.position < 1 then
if selfie.mode == 2 then
selfie.position = 1
selfie:stop()
elseif selfie.mode == 3 then
selfie.direction = 1
selfie.position = selfie.position + 1
end
end
end
end
function anim_mt:updateAction(action, dt)
local selfie = self.action[action]
if not selfie.playing then return end
selfie.timer = selfie.timer + dt * selfie.speed
if selfie.timer > selfie.delays[selfie.position] then
selfie.timer = selfie.timer - selfie.delays[selfie.position]
selfie.position = selfie.position + 1 * selfie.direction
if selfie.position == 0 then
selfie.position = selfie.frames
elseif selfie.position > selfie.frames then
if selfie.mode == 1 then
selfie.position = 1
elseif selfie.mode == 2 then
selfie.position = selfie.position - 1
self:stop()
elseif selfie.mode == 3 then
selfie.direction = -1
selfie.position = selfie.position - 1
end
elseif selfie.position < 1 then
if selfie.mode == 2 then
selfie.position = 1
selfie:stop()
elseif selfie.mode == 3 then
selfie.direction = 1
selfie.position = selfie.position + 1
end
end
end
end
function anim_mt:setDirection (dir)
local selfie = self.action[self.actual]
if dir == "Forward" then
selfie.direction = 1
elseif dir == "Backward" then
selfie.direction = -1
end
end
function anim_mt:draw( x, y, angle, sx, sy)
local selfie = self.action[self.actual]
love.graphics.draw(selfie.img[selfie.position], x, y, angle, sx, sy)
end
function anim_mt:play()
local selfie = self.action[self.actual]
selfie.playing = true
end
function anim_mt:resettwo()
local selfie = self.action[self.actual]
if selfie.playing then
selfie.position = 0
end
end
function anim_mt:stop()
local selfie = self.action[self.actual]
selfie.playing = false
end
function anim_mt:reset()
local selfie = self.action[self.actual]
selfie:seek(0)
end
function anim_mt:seek(frame)
local selfie = self.action[self.actual]
selfie.position = frame
selfie.timer = 0
end
function anim_mt:seekAction(act,frame)
local selfie = self.action[act]
selfie.position = frame
selfie.timer = 0
end
function anim_mt:getFrameAction(act)
local selfie = self.action[act]
return selfie.position
end
function anim_mt:timerAction(act,timer)
local selfie = self.action[act]
selfie.timer = timer
selfie.timer = 0
end
function anim_mt:getTimerAction(act)
local selfie = self.action[act]
return selfie.timer
end
function anim_mt:getCurrentFrame()
local selfie = self.action[self.actual]
return selfie.position
end
function anim_mt:getSize()
local selfie = self.action[self.actual]
return selfie.frames
end
function anim_mt:setDelay(frame, delay)
local selfie = self.action[self.actual]
self[self.action].delays[frame] = delay
end
function anim_mt:setSpeed(speed)
local selfie = self.action[self.actual]
self[self.action].speed = speed
end
function anim_mt:getWidth()
return self[self.action].frames[self.position]:getWidth()
end
function anim_mt:getHeight()
return self[self.action].frames[self.position]:getHeight()
end
function anim_mt:setMode(mode)
local selfie = self.action[self.actual]
if mode == "loop" then
selfie.mode = 1
elseif mode == "once" then
selfie.mode = 2
elseif mode == "bounce" then
selfie.mode = 3
end
end