-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsword.lua
More file actions
170 lines (154 loc) · 3.74 KB
/
Copy pathsword.lua
File metadata and controls
170 lines (154 loc) · 3.74 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
directions = {
up = 0,
down = 1,
left = 2,
right = 3
}
function create_sword()
local new_sword = {
direction = directions.up,
frame = 1,
}
return new_sword
end
local sword_frames = {
-- first four frames moving up
{
x0 = 8,
y0 = 4,
x1 = 12,
y1 = 4
},
{
x0 = 8,
y0 = 3,
x1 = 12,
y1 = 3
},
{
x0 = 8,
y0 = 2,
x1 = 12,
y1 = 2
},
{
x0 = 8,
y0 = 1,
x1 = 12,
y1 = 1
},
-- next follow curve diagonal
{
x0 = 8,
y0 = 0,
x1 = 11,
y1 = -3
},
{
x0 = 7,
y0 = -1,
x1 = 10,
y1 = -4
},
{
x0 = 6,
y0 = -2,
x1 = 9,
y1 = -5
},
-- now move vertically over head
{
x0 = 5,
y0 = -2,
x1 = 5,
y1 = -6
},
{
x0 = 4,
y0 = -2,
x1 = 4,
y1 = -6
},
{
x0 = 3,
y0 = -2,
x1 = 3,
y1 = -6
},
{
x0 = 2,
y0 = -2,
x1 = 2,
y1 = -6
},
{
x0 = 1,
y0 = -2,
x1 = 1,
y1 = -6
},
-- one last frame of follow-through
{
x0 = 0,
y0 = -2,
x1 = -3,
y1 = -5
}
}
local computed_swords = {}
local function init_sword_frame(frame)
local new_frame_up = {
x0 = frame.x0, y0 = frame.y0,
x1 = frame.x1, y1 = frame.y1
}
add(computed_swords[directions.up], frame)
local new_frame_left = {}
new_frame_left.x0, new_frame_left.y0 = rotate270(frame.x0, frame.y0)
new_frame_left.x1, new_frame_left.y1 = rotate270(frame.x1, frame.y1)
add(computed_swords[directions.left], new_frame_left)
local new_frame_down = {}
new_frame_down.x0, new_frame_down.y0 = rotate180(frame.x0, frame.y0)
new_frame_down.x1, new_frame_down.y1 = rotate180(frame.x1, frame.y1)
add(computed_swords[directions.down], new_frame_down)
local new_frame_right = {}
new_frame_right.x0, new_frame_right.y0 = rotate90(frame.x0, frame.y0)
new_frame_right.x1, new_frame_right.y1 = rotate90(frame.x1, frame.y1)
add(computed_swords[directions.right], new_frame_right)
end
function init_swords()
computed_swords[directions.up] = {}
computed_swords[directions.left] = {}
computed_swords[directions.down] = {}
computed_swords[directions.right] = {}
foreach(sword_frames, init_sword_frame)
end
function draw_sword(sword, actor)
local x,y = actor.x*8, actor.y*8
if (sword.direction == directions.left) then x,y = x,y+7
elseif (sword.direction == directions.down) then x,y = x+7,y+7
elseif (sword.direction == directions.right) then x,y = x+7,y end
local sword_frame = computed_swords[sword.direction][sword.frame]
local x0, y0 = sword_frame.x0+x, sword_frame.y0+y
local x1, y1 = sword_frame.x1+x, sword_frame.y1+y
line(x0, y0, x1, y1, 7)
end
function check_sword_collisions(sword, owner)
local x,y = owner.x*8, owner.y*8
if (sword.direction == directions.left) then x,y = x,y+7
elseif (sword.direction == directions.down) then x,y = x+7,y+7
elseif (sword.direction == directions.right) then x,y = x+7,y end
local sword_frame = computed_swords[sword.direction][sword.frame]
local x1, y1 = sword_frame.x1+x, sword_frame.y1+y
for_each_actor(
function (actor)
if (actor.enabled and actor.on_sword_collision != nil) then
if (point_inside_actor(x1, y1, actor)) then
actor.on_sword_collision(actor.parent)
end
end
end
)
end
function num_sword_frames()
return #sword_frames
end