1
2# Level controllers are generic objects designed to be used as triggers for scripts.
3# Various usages include modifying:
4#  - on_create to trigger something on the start of a level.
5#  - on_touch to trigger something when the player reaches a certain spot
6{
7id: "curvey_rope_controller_swaying",
8next_animation: "'normal'",
9always_active: true,
10timer_frequency: 3,
11properties: {
12	bcurve: "def(points, percent)
13		if(size(points)=2,
14			[(points[0][0]*(100-percent) + points[1][0]*percent)/100.0,
15			(points[0][1]*(100-percent) + points[1][1]*percent)/100.0],
16			bcurve(map(range(size(points)-1), 'ind', bcurve(points[ind:ind+2], percent)), percent)
17			)",
18	level_points: "map(level_points_objs, 'point', [point.midpoint_x, point.midpoint_y])",
19	level_points_objs: "sort(filter(level.chars, value.linked_object=sl) where sl=self.label, a.number < b.number)",
20},
21on_timer: "if(level_points, [
22			map(lpo[1:size(lpo)-1], 'lp', set(lp.x, lp.x+delta)) where delta = sin((cycle+vars.center)*vars.frequency)/vars.sway where lpo=level_points_objs,
23			fire_event('set_segments'),
24		])",
25on_create: "if(level_points, [set(alpha, 0),
26		[map(segments, 'seg', add_object(seg)),
27		set(vars.segments, segments),
28		fire_event('set_segments'),
29		]
30			where segments = map(range(0,resolution), 'point', object('rope_angled_controller', bcurve(level_points, ind)[0], bcurve(level_points, ind)[1], 0, {'index' -> ind})
31				where ind = point * (100.0/resolution)
32			)]
33			)
34		where resolution = vars.resolution",
35on_set_segments: "map(vars.segments, 'segment', [
36			segment.set_ends(
37				bcurve(level_points, segment.vars.index+0/resolution)[0],
38				bcurve(level_points, segment.vars.index+0/resolution)[1],
39				bcurve(level_points, segment.vars.index+100.0/resolution+1)[0],
40				bcurve(level_points, segment.vars.index+100.0/resolution+1)[1]
41			),
42		]) where resolution = vars.resolution",
43on_end_anim: "animation('normal')",
44zorder: 100,
45editor_info: {
46	category: "controllers",
47	help: "Assign the rope controller a label. Assign another
48		object a label_of_this_object space sequencial_number.
49		---
50		Resolution: Number of subsections. Lower is faster.
51		Sway: How much to move (x axis).",
52	var: [
53		{
54			name: "resolution",
55			type: "int",
56			value: 10,
57		},
58		{
59			name: "sway",
60			type: "int",
61			value: 70,
62		},
63		{
64			name: "frequency",
65			type: "int",
66			value: 2,
67		},
68		{
69			name: "center",
70			type: "int",
71			value: 40,
72		},
73	],
74},
75animation: {
76	id: "normal",
77	image: "effects/particles.png",
78	x: 179,
79	y: 104,
80	w: 28,
81	h: 28,
82	collide: [0,0,28,28],
83	frames: 1,
84	duration: 1000,
85},
86}
87