-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.lua
More file actions
225 lines (198 loc) · 5.35 KB
/
Copy pathcomponents.lua
File metadata and controls
225 lines (198 loc) · 5.35 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
-- components
component.create('hidden')
component.create('smash')
component.create('player')
component.create('floating')
component.create('bullet')
component.create('stats')
component.create('enemy_team')
component.create('redirectable')
component.create('collector', function()
return { letters = '' }
end)
component.create('crushable')
component.create('scorer')
component.create('timer', function(start_time)
return {start_time = start_time or time()}
end)
component.create('repeat_every', function(delay, code)
return { delay = delay or 30, reset = delay or 30, code = code or function(e) end }
end)
component.create('do_after', function(delay, code)
return { delay = delay or 30, reset = delay or 30, code = code or function(e) end }
end)
component.create('collectable_delay', function(delay)
return delay or 30
end)
component.create('collectable', function(type)
return { type = type }
end)
component.create('bounce', function(vx, vy)
return { vx = vx or 0, vy = vy or -4 }
end)
component.create('knockable')
component.create('knockback', function(vx, vy)
return { vx = vx or -10, vy = vy or 0 }
end)
component.create('tossable', function(rot, zoom, simple)
return { rot = rot or 700, zoom = zoom or 2, simple = simple or false }
end)
component.create('toss', function(sprite_comp)
return {
vx = 0,
vy = 0,
ttl = 0,
sprite = sprite_comp.num,
w = sprite_comp.w,
h = sprite_comp.h,
started = false,
bounce = false,
rotation = 0,
desired_rotation = 0,
zoom = sprite_comp.scale,
desired_zoom = 0
}
end)
-- Items related to the display of an entity
component.create('sprite', function(num, w, h, scale)
return { num = num or 255, w = w or 1, h = h or 1, scale = scale or 1}
end)
-- It's what you see when an enemy shoots code
component.create('recttext', function(color, char, w, h)
return { color = color, char = char, w = w or 6, h = h or 6, frame = 0, delay = 4, accumulator = 0 }
end)
function add_anim(e, name, anim)
-- if type(anim) == 'table' then printh('accepts only strings') end
local anim = split(anim, ',')
for k, v in pairs(anim) do
anim[k] = split(v, ':', true)
end
-- dump(anim)
e.frames[name] = anim
end
function change_anim(e, name, one_shot)
if e.frames.anim == name then return end
if type(e.frames[name]) != 'table' then return end
e.frames.anim = name
e.frames.one_shot = one_shot or false
e.frames.frame = 1
end
component.create('frames', function(e)
return {
animating = true,
anim = 'default',
tick = 0,
delay = 4,
frame = 1,
one_shot = false,
default = {
{ 255 }
}
}
end)
component.create('autorun', function(speed)
return { speed = speed or 1 }
end)
component.create('boss_autorun', function(speed)
return { speed = speed or 1 }
end)
component.create('controller', function()
return {
press = false,
hold = false,
release = false,
secs = 0
}
end)
-- Items related to physics
component.create('physics', function(vx, vy, mass)
return { grounded = false, vx = vx or 0, vy = vy or 0, mass = mass or 1, smashing = -1 }
end)
component.create('movement', function(speed, max_x, max_y)
return {speed = speed or 1, max_x = max_x or 5, max_y = max_y or 5}
end)
-- A timer to despawn the entity
-- Usually used while playing a death animation
component.create('despawn', function(ttl)
return { ttl = ttl or 0 } -- in frames
end)
component.create('sound_on_despawn', function(sound)
return sound
end)
component.create('on_despawn', function(code)
return code or function(e) end
end)
-- Stuff related to damaging stuff
component.create('damage', function(damage)
return damage or 1
end)
component.create('sound_on_damage', function(sound)
return sound
end)
component.create('on_damage', function(code)
return code or function(e, amount) end
end)
-- Entity health
component.create('health', function(num, limit)
return { current = num or 3, limit = limit or 16 }
end)
-- Entity colliders for physics and collisions
component.create('iframes', function(e)
if e:has('defensive_collider') then e.defensive_collider.enabled = false end
return { flash = true, ttl = 45 }
end)
component.create('offensive_collider', function(ox, oy, w, h)
return {
enabled = true,
ox = ox or 2,
oy = oy or 2,
w = w or 4,
h = h or 4
}
end)
component.create('defensive_collider', function(ox, oy, w, h)
return {
enabled = true,
ox = ox or 2,
oy = oy or 2,
w = w or 4,
h = h or 4
}
end)
component.create('ai_shoot_dumb', function ()
return {ttsa = 30}
end)
component.create('ai_shoot_smrt', function(max_range)
return {
max_range = max_range or 130,
ttsa = 40 --time to shoot again
}
end)
component.create('ai_boss', function(max_range_shoot, max_range_lunge, can_shoot, is_lunging, is_returning, times_struck)
return {
max_range_shoot = max_range_shoot or 30,
max_range_lunge = max_range_lunge or 30,
ttsa = 0,
ttla = 0,
can_shoot = can_shoot or true,
is_lunging = is_lunging or false,
is_returning = is_returning or false
}
end)
component.create('ai_boss_comp', function(max_range_shoot, is_charging)
return {
max_range_shoot = max_range_shoot or 30,
is_charging = is_charging or true,
ttsa = 0,
charge_time = 120
}
end)
component.create('parent', function (obj)
return obj
end)
component.create('scorable', function(amount)
return amount
end)
component.create('teleport', function(x, y, autorun, ends_game)
return {x = x or 0, y = y or 0, autorun = autorun or true, ends_game = ends_game or false}
end)