-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcirllet_build.p8
1331 lines (1320 loc) · 39.6 KB
/
cirllet_build.p8
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
pico-8 cartridge // http://www.pico-8.com
version 29
__lua__
--table
function swap(a, b)
local t = a
a = b
b = t
end
function sort (arr, comp)
if not comp then
comp = function (a, b)
return a < b
end
end
local function partition (a, lo, hi)
pivot = a[hi]
i = lo - 1
for j = lo, hi - 1 do
if comp(a[j], pivot) then
i = i + 1
a[i], a[j] = a[j], a[i]
end
end
a[i + 1], a[hi] = a[hi], a[i + 1]
return i + 1
end
local function quicksort (a, lo, hi)
if lo < hi then
p = partition(a, lo, hi)
quicksort(a, lo, p - 1)
return quicksort(a, p + 1, hi)
end
end
return quicksort(arr, 1, #arr)
end
function dump(value, call_indent)
if not call_indent then
call_indent = ""
end
local indent = call_indent .. " "
local output = ""
if type(value) == "table" then
output = output .. "{"
local first = true
for inner_key, inner_value in pairs ( value ) do
if not first then
output = output .. ", "
else
first = false
end
output = output .. "\n" .. indent
output = output .. inner_key .. " = " .. dump ( inner_value, indent )
end
output = output .. "\n" .. call_indent .. "}"
elseif type (value) == "userdata" then
output = "userdata"
elseif type (value) == "function" then
output = "function"
elseif type(value) == "boolean" then
output = value and "true" or "false"
else
output = value
end
return output
end
function unpack (arr, i, j)
local n = {}
local k = 0
local initial_i = i
j = j or #arr
for i = i or 1, j do
k = k + 1
n[k] = arr[i]
end
local l = k
local function create_arg(l, ...)
if l == 0 then
return ...
else
return create_arg(l - 1, n[l], ...)
end
end
return create_arg(l)
end
function clone(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[clone(orig_key)] = clone(orig_value)
end
setmetatable(copy, clone(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
--sprite
s = {
id = 0,
flip = {
x = false,
y = false
},
add_to = function(o)
o.s = clone(s)
o.draw = function (self)
spr(self.s.id, self.pos.x, self.pos.y, 1, 1, self.s.flip.x, self.s.flip.y)
end
end
}
--pos
v = {
x = 0,
y = 0,
print = function(self)
printh("x="..self.x)
printh("y="..self.y)
end,
new = function(x, y)
local r = clone(v)
r.x = x or 0
r.y = y or 0
return r
end,
pos_or_scalar = function(i, p)
if type(p) == "table" then
return p[i]
else
return p
end
end
}
do
local mt = {
__add = function(left, right)
return v.new(left.x + right.x, left.y + right.y)
end,
__sub = function(left, right)
return v.new(left.x - right.x, left.y - right.y)
end,
__mul = function(left, right)
return v.new(
v.pos_or_scalar("x", left) * v.pos_or_scalar("x", right),
v.pos_or_scalar("y", left) * v.pos_or_scalar("y", right)
)
end,
__div = function(left, right)
return v.new(
v.pos_or_scalar("x", left) / v.pos_or_scalar("x", right),
v.pos_or_scalar("y", left) / v.pos_or_scalar("y", right)
)
end
}
setmetatable(v, mt)
end
--all objects
objects_list = {}
objects = {
list = {},
len = 1,
add = function(self, o)
self.list[self.len] = o
local id = self.len
self.len = self.len + 1
local destroy = function(o_self)
self.list[id] = nil
end
objects.concat_destroy(o, function(o_self)
destroy(o_self)
end)
return id
end,
remove = function(self, id)
self.list[id] = nil
end,
concat_destroy = function(o, destroy)
local last_destroy = o.destroy
if last_destroy ~= nil then
o.destroy = function(o_self)
last_destroy(o_self)
destroy(o_self)
end
else
o.destroy = destroy
end
end,
new = function()
local r = clone(objects)
add(objects_list, r)
return r
end,
clear_all = function()
for _, os in pairs(objects_list) do
os.list = {}
os.len = 1
end
end
}
os = objects.new()
--constant
frame_rate = 60
frame_time = 1 / frame_rate
animation_rate = 0.1
max_bullet_count = 3
face_to_dir = {
v.new(-1, 0),
v.new(1, 0),
v.new(0, -1),
v.new(0, 1)
}
face_revert = {2, 1, 4, 3}
--collider box
tile_map = {
new = function()
local r = {}
for i = 0, 15 do
r[i] = {}
end
r.get_tile = function(p)
return r[flr(p.x)][flr(p.y)]
end
r.get = function(p)
p = p / 8
return r.get_tile(p)
end
r.set_tile = function(p, o)
r[flr(p.x)][flr(p.y)] = o
end
r.set = function(p, o)
p = p / 8
r.set_tile(p, o)
end
return r
end
}
box = {
offset = v.new(),
size = v.new(1, 1),
f = {false, false, false, false, false, false, false, false},
get_f = function(self, i)
return self.f[i + 1]
end,
set_f = function(self, i, b)
self.f[i + 1] = b
end,
add_to = function(o)
o.box = clone(box)
local last_draw = o.draw
o.box_pos = function(self)
return self.pos + self.box.offset
end
o.check_collision = function(self, face, distance)
if face ~= nil then
local from = {
v.new(0, 1),
v.new(1, 0),
v.new(0, 0),
v.new(1, 1),
}
local line_dir = {
v.new(0, -1),
v.new(0, 1),
v.new(1, 0),
v.new(-1, 0),
}
local len = {
self.box.size.y,
self.box.size.y,
self.box.size.x,
self.box.size.x
}
local box_pos = self:box_pos()
local from = box_pos + (self.box.size - v.new(1, 1)) * from[face]
--local ps = line_pixels(from, line_dir[face], len[face])
local to = from + line_dir[face] * (len[face] - 1)
local p_from, s_from = block_move(from, face, distance, self.block_flags)
local p_to, s_to = block_move(to, face, distance, self.block_flags)
if s_from and not s_to then
return line_dir[face], s_from
end
if not s_from and s_to then
return line_dir[face] * -1, s_to
end
if s_from and s_to then
return v.new(0, 0), s_from
end
if p_from or p_to then
return p_from or p_to
end
end
if self.collision_list ~= nil then
local box_pos = self:box_pos()
if face ~= nil then
box_pos = box_pos + face_to_dir[face] * distance
end
local max = box_pos + self.box.size
for _, l in pairs(self.collision_list) do
for _, o in pairs(l.list)do
if o.box ~= nil then
local o_box_pos = o:box_pos()
local o_max = o_box_pos + o.box.size
if box_pos.x < o_max.x and box_pos.y < o_max.y and
o_box_pos.x < max.x and o_box_pos.y < max.y then
return o
end
end
end
end
end
end
o.box_block_move = function(self)
if self.move then
local p, s = self:check_collision(self.face, self.speed)
if p ~= nil then
if self.on_collision ~= nil then
self:on_collision(p, s)
end
if p.x ~= nil then
self.pos = self.pos + p
return
elseif p.box and p.box.block then
return
end
end
self.pos = self.pos + face_to_dir[self.face] * self.speed
end
end
--o.draw = function(self)
-- last_draw(self)
-- local pos = self:box_pos()
-- rect(pos.x, pos.y, pos.x + self.box.size.x - 1, pos.y + self.box.size.y - 1, 8)
--end
end
}
--animation
--
animation = {
t = 0,
current_animation = function(animation)
return animation.data[animation.name]
end,
change = function(animation, name, after_finish)
animation.name = name
animation.after_finish = after_finish
end,
update = function(animation, self)
local current_animation = animation:current_animation()
local rate = current_animation.rate or 1
self.s.id = current_animation.series[flr(animation.t) % #current_animation.series + 1]
animation.t = animation.t + animation_rate * rate
if animation.t >= #current_animation.series then
if current_animation.loop then
animation.t = animation.t % #current_animation.series
else
animation.t = #current_animation.series - 1
if animation.after_finish ~= nil then
animation.after_finish()
animation.after_finish = nil
end
end
end
end,
new = function()
return clone(animation)
end
}
--player
parrying_players = objects.new()
players = objects.new()
player = {
block_flags = {0},
depth = 1,
face = 2,
faces = {"right", "right", "up", "down"},
flip_x = false,
reload_time = 2,
reload_time_left = 0,
fsm = {
states = {
idle = {
update = function(state, self)
self:process_move()
--trigger bullet
if abtnp(4) then
self:fire_bullet()
self.reload_time_left = self.reload_time
self.fsm:change(self, "reload")
return
end
if abtnp(5) then
self.fsm:change(self, "prepare_parry")
end
end
},
reload = {
enter = function(state, self)
if self.reload_time_left <= 0 then
self.fsm:change(self, "idle")
return
end
local pos_f = function()
return self.pos
end
state.progress_bar = progress_bar.new(pos_f, v.new(-1, -2), self.reload_time, self.reload_time_left)
end,
update = function(state, self)
self:process_move()
if self.reload_time_left > 0 then
self.reload_time_left = self.reload_time_left - frame_time
else
self.fsm:change(self, "idle")
end
if abtnp(5) then
self.fsm:change(self, "prepare_parry")
end
end,
exit = function(state, self)
if state.progress_bar ~= nil then
state.progress_bar:destroy()
end
end
},
prepare_parry = {
enter = function(state, self)
self.animation.t = 0
self.animation:change("prepare_parry_"..self:up_or_down(), function()
self.fsm:change(self, "parry")
end)
sfx(-2, 0)
sfx(4)
end,
update = function(state, self)
self.animation:update(self)
end
},
parry = {
on_parry_bullet = function(state, self)
state.parried_bullet = state.parried_bullet + 1
end,
play_animation = function(self)
self:fetch_face()
self.animation:change("parry_"..self:up_or_down())
end,
enter = function(state, self)
self.animation.t = 0
state.play_animation(self)
state.parring_id = parrying_players:add(self)
state.parried_bullet = 0
state.counter = bullet_counter.new(function()
return self.pos
end, v.new(2, -4), function()
return state.parried_bullet
end)
sfx(3, 0)
end,
update = function(state, self)
self.animation:update(self)
state.play_animation(self)
if not btn(5) then
self.fsm.states.after_parry.parried_bullet = state.parried_bullet
self.fsm:change(self, "after_parry")
end
end,
exit = function(state, self)
parrying_players:remove(state.parring_id)
state.counter:destroy()
sfx(-2, 0)
end
},
after_parry = {
bullet_step_time = 0.1,
bullet_step_time_left = 0,
parried_bullet = 0,
animation_finish = false,
enter = function(state, self)
self.animation.t = 0
state.bullet_step_time_left = 0
state.animation_finish = false
self.animation:change("after_parry_"..self:up_or_down(), function()
state.animation_finish = true
end)
sfx(5)
end,
update = function(state, self)
self.animation:update(self)
if state.bullet_step_time_left > 0 then
state.bullet_step_time_left = state.bullet_step_time_left - frame_time
elseif state.parried_bullet > 0 then
self:fire_bullet()
state.parried_bullet = state.parried_bullet - 1
state.bullet_step_time_left = state.bullet_step_time_left + state.bullet_step_time
elseif state.animation_finish then
--self.reload_time_left = self.reload_time
self.fsm:change(self, "reload")
end
end
}
},
current_name = "idle",
current = function(fsm)
return fsm.states[fsm.current_name]
end,
change = function(fsm, self, state_name)
local next = fsm.states[state_name]
local current = fsm:current()
if current.exit ~= nil then
current:exit(self)
end
if next.enter ~= nil then
next:enter(self)
end
fsm.current_name = state_name
end
},
group = {},
pos = v.new(),
--player new
new = function(pos)
local r = clone(player)
player.singleton = r
s.add_to(r)
r.s.id = 1
r.pos = pos
box.add_to(r)
r.box.offset = v.new(1, 0)
r.box.size = v.new(6, 8)
r.animation = animation.new()
r.animation.data = {
right = {
series = {1, 2, 3, 2, 1},
loop = true
},
right_walk = {
series = {65, 66},
loop = true,
rate = 3
},
up = {
series = {7, 8, 9, 8, 7},
loop = true
},
up_walk = {
series = {69, 70},
loop = true,
rate = 3
},
down = {
series = {4, 5, 6, 5, 4},
loop = true
},
down_walk = {
series = {67, 68},
loop = true,
rate = 3
},
prepare_parry_down = {
series = {17, 18, 19},
rate = 1
},
parry_down = {
series = {20, 19},
rate = 3,
loop = true
},
after_parry_down = {
series = {19, 17, 3},
rate = 6,
},
prepare_parry_up = {
series = {21, 22, 23},
rate = 1
},
parry_up = {
series = {24, 23},
rate = 3,
loop = true
},
after_parry_up = {
series = {23, 21, 9},
rate = 6,
}
}
r.animation.name = "right"
os:add(r)
players:add(r)
objects.concat_destroy(r, function(self)
sfx(-2, 0)
end)
end,
on_collision = function(self, o, s)
if o.other ~= nil then --portal
local valid_face = o.other:valid_face(self)
if valid_face ~= nil then
self.face = valid_face
local target_pos = {
v.new(-8, 0),
v.new(8, 0),
v.new(0, -8),
v.new(0, 8),
}
local after_pos = o.other.pos + target_pos[self.face]
o:on_transport(self.pos + v.new(3.5, 3.5), after_pos + v.new(3.5, 3.5), self.face)
self.pos = o.other.pos + target_pos[self.face]
end
end
if s ~= nil then
if s == 29 then
sfx(-2, 0)
sfx(6)
maps:next()
end
end
end,
fire_bullet = function(self)
local target_pos = {
v.new(8, 5),
v.new(8, 5),
v.new(4, 2),
v.new(5, 8)
}
local offset = (target_pos[self.face] - v.new(3.5, 0))
* v.new(self:flip_x_sign(), 1) + v.new(3.5, 0)
local pos = self.pos + offset
for i = 1, 15 do
particle.new(clone(pos), 2, 0.05, 0.5, 0, 5)
end
sfx(0)
bullet.new(self.face, pos)
end,
on_parry_bullet = function(self)
self.fsm.states.parry:on_parry_bullet(self)
end,
up_or_down = function(self)
local table = {"down", "down", "up", "down"}
return table[self.face]
end,
face_dir = function (self)
local face = {
v.new(-1, 0),
v.new(1, 0),
v.new(0, -1),
v.new(0, 1),
}
return face[self.face]
end,
flip_x_sign = function (self)
return self.flip_x and -1 or 1
end,
fetch_face = function(self)
self.move = true
if btn(0) then
self.face = 1
self.flip_x = true
elseif btn(1) then
self.face = 2
self.flip_x = false
elseif btn(2) then
self.face = 3
elseif btn(3) then
self.face = 4
else
self.move = false
end
self.s.flip.x = self.flip_x
end,
process_move = function(self)
local animation = self.animation
local current = animation.current
local last_move = self.move
self:fetch_face()
local next_name = ""
if self.move then
next_name = self.faces[self.face].."_walk";
if not last_move and self.move then
sfx(7, 0)
end
else
next_name = self.faces[self.face];
if last_move and not self.move then
sfx(-2, 0)
end
end
self.animation:change(next_name)
--move
--self.pos = self.pos + self.sign * self.speed
self:box_block_move()
--animation
self.animation:update(self)
end,
update = function (self)
local current_state = self.fsm:current()
if current_state.update ~= nil then
current_state:update(self)
end
end,
speed = 1
}
do
local index = 0
local function insert_animation_group(animations)
for _, animation in pairs(animations) do
player.group[animation] = index
end
index = index + 1
end
insert_animation_group({"right", "up", "down"})
insert_animation_group({"right_walk", "up_walk", "down_walk"})
end
--bullet
bullets = objects.new()
bullets.size = 0
do
local last_add = bullets.add
bullets.add_bullet = function(self, o)
if bullets.size >= max_bullet_count then
for _, bullet in pairs(bullets.list) do
bullet:destroy()
break
end
end
bullets:add(o)
objects.concat_destroy(o, function(o_self)
bullets.size = bullets.size - 1
end)
bullets.size = bullets.size + 1
end
end
bullet = {
block_flags = {1, 2},
depth = 2,
speed = 1,
move = true,
update = function(self)
self:box_block_move()
end,
hit_destroy = function(self)
for i = 1, 10 do
particle.new(self.pos + v.new(1, 1), 1, 0.05, 0.5, 7, 7, face_revert[self.face])
end
sfx(1)
self:destroy()
end,
on_collision = function(self, p, s)
if p.box == nil then
if fget(s, 1) then
self.face = face_revert[self.face]
else
self:hit_destroy()
end
else
local o = p
if o.other ~= nil then --portal
local valid_face = o.other:valid_face(self)
if valid_face == nil then
self:hit_destroy()
end
self.face = valid_face
local target_pos = {
v.new(-1, 3.5),
v.new(8, 3.5),
v.new(3.5, -1),
v.new(3.5, 8),
}
local after_pos = o.other.pos + target_pos[self.face]
o:on_transport(self.pos + v.new(1, 1), after_pos, self.face)
self:set_pos(after_pos)
elseif o.on_parry_bullet ~= nil then
o:on_parry_bullet()
self:hit_destroy()
elseif o.hit_by_bullet ~= nil then
o:hit_by_bullet()
self:hit_destroy()
end
end
end,
set_pos = function(self, pos)
self.pos = pos - v.new(1, 1)
end,
new = function(face, pos)
local r = clone(bullet)
r:set_pos(pos)
r.face = face
s.add_to(r)
box.add_to(r)
r.s.id = 10
r.box.size = v.new(3, 3)
r.collision_list = { parrying_players }
os:add(r)
bullets:add_bullet(r)
return r
end
}
--block move
function block_move(p, face, len, block_flags)
local test_flag = function(s)
if block_flags ~= nil then
for _, f in pairs(block_flags) do
if fget(s, f) then
return true
end
end
end
return false
end
for i = 1, len do
local target_p = p + face_to_dir[face] * len
target_p = target_p / 8
local map_p = target_p + maps:current()
local s = mget(map_p.x, map_p.y)
if test_flag(s) then
return target_p, s
end
local o = maps.tile.get_tile(target_p)
if o ~= nil then
return o
end
end
end
function line_pixels(from, dir, len)
local r = {}
for i = 0, len - 1 do
add(r, from + dir * i)
end
return r
end
--progress_bar
progress_bar = {
new = function(follow_pos_f, offset, time, time_left)
local r = {}
r.depth = 100
r.follow_pos_f = follow_pos_f
r.offset = offset
r.time_left = time_left or time
r.time = time
r.len = 10
r.c = 8
r.update = function(self)
self.time_left = self.time_left - frame_time
end
r.draw = function(self)
local len = self.len * self.time_left / self.time
for i = 0, len - 1 do
local pos = self.follow_pos_f() + self.offset
pset(pos.x + i, pos.y, self.c)
end
end
os:add(r)
return r
end
}
--particle
particle = {
new = function(pos, rr, rv, vv, c1, c2, face)
local r = {}
r.depth = 90
r.pos = pos
if face ~= nil then
local vs = {
v.new(-rnd(vv / 2), -vv/2 + rnd(vv)),
v.new(rnd(vv / 2), -vv/2 + rnd(vv)),
v.new(-vv/2 + rnd(vv), -rnd(vv / 2)),
v.new(-vv/2 + rnd(vv), rnd(vv / 2)),
}
r.v = vs[face]
else
r.v = v.new(- vv/2 + rnd(vv), -vv/2 + rnd(vv))
end
r.r = 0.5 + rnd(rr)
r.rv = rv
r.c = c1 + flr(rnd(2)) * (c2 - c1)
r.update = function(self)
self.pos = self.pos + self.v
self.r = self.r - self.rv
if self.r <= 0 then
self:destroy()
end
end
r.draw = function(self)
circfill(self.pos.x, self.pos.y, self.r, self.c)
end
os:add(r)
return r
end
}
--bullet counter
bullet_counter = {
new = function(follow_pos_f, offset, bullet_count_f)
local r = {}
r.follow_pos_f = follow_pos_f
r.offset = offset
r.bullet_count_f = bullet_count_f
r.bullets = {}
r.last_count = 0
r.space = 4
for i = 1, max_bullet_count do
local bullet = {}
s.add_to(bullet)
bullet.s.id = 10
bullet.depth = 100
add(r.bullets, bullet)
end
r.update = function(self)
local this_count = self.bullet_count_f()
for i = self.last_count + 1, this_count do
os:add(self.bullets[i])
end
for i = this_count + 1, self.last_count do
self.bullets[i]:destroy()
self.bullets[i].destroy = nil
end
for i = 0, this_count - 1 do
local follow_pos = self.follow_pos_f() + self.offset
local x = (i - (this_count - 1) / 2) * self.space
self.bullets[i + 1].pos = v.new(x, 0) + follow_pos
end
self.last_count = this_count
end
os:add(r)
objects.concat_destroy(r, function(self)
for i = 1, r.last_count do
self.bullets[i]:destroy()
end
end)
return r
end
}
text = {
new = function(s, pos)
local r = {}
r.depth = 100
r.draw = function(self)
print(s, pos.x, pos.y, 0)
end
os:add(r)
end
}
--portal
portals = objects.new()
portal = {
new = function(begin_s, c1, c2)
local generator = {}
maps.dynamic[begin_s] = {
o = generator,
into_tile = true
}
generator.new = function(pos)
local r = {}
r.c1 = c1
r.c2 = c2
r.depth = 1
r.begin_s = begin_s
r.pos = pos
s.add_to(r)
r.animation = animation.new()
r.animation.data = {
idle = {
series = {begin_s, begin_s + 1, begin_s + 2, begin_s + 3},
loop = true
}
}
r.animation.name = "idle"
r.update = function(self)
self.animation:update(self)
end
box.add_to(r)
r.box.size = v.new(8, 8)
r.box.block = true
for _, portal in pairs(portals.list) do
if portal.begin_s == r.begin_s then
r.other = portal
portal.other = r
break
end
end
r.valid_face = function(self, o)
self.block_flags = o.block_flags
local next = {
3, 4, 2, 1
}
local face = o.face
local current_face = face
local first = true
while true do
if current_face == face and not first then
return
end
first = false
local p = self:check_collision(current_face, 1)
if p ~= nil then