
#TODO: This platform is intended to be supported by two vertical ropes,
#one holding up each side. However the ropes have some measure of give,
#and when the player walks to one side of the platform it tilts in that
#direction and they'll eventually fall off it.
{
id: "tilting_platform-dungeon",
platform_area: [0,0,80,1],
properties: {
	tilt_angle: "if(target_angle < -20, -20, if(target_angle > 20, 20, target_angle)) where target_angle = level.player.ctrl_tilt/10",
	player_weight: "if(level.player.standing_on != me, 0, if(level.player.midpoint_x < me.midpoint_x, -1, 1)*sqrt(abs(level.player.midpoint_x - me.midpoint_x))*0.1)",
	regression_force: "if(vars.tilt_angle > 0.0, 1.0, -1.0)*min(force, abs(me.vars.tilt_angle)) where force = 0.5",
},
vars: {
	tilt_angle: 0.0,
},
editor_info: {
	category: "platforms",
	var: [
		{
			name: "control_points",
			type: "points",
			value: "[]",
		},
	],
},
on_process: "[
	   if(vars.control_points and size(vars.control_points) >= 2,
		([
			set(midpoint_x, (this_node[0]*this_portion + next_node[0]*next_portion)/100),
			set(midpoint_y, (this_node[1]*this_portion + next_node[1]*next_portion)/100)
	    ] where this_node = vars.control_points[index],
		        next_node = vars.control_points[(index+1)%size(vars.control_points)],
				this_portion = 100 - cycle%100,
				next_portion = cycle%100)
		            where index = (cycle/100)%size(vars.control_points)),

	   add(vars.tilt_angle, player_weight - regression_force),

	   #make Frogatto slip off the platform if it tilts too much -- TODO:
	    should we have a more general slipping mechanic in the game?#
	   if(level.player.standing_on = me and abs(vars.tilt_angle) > 30, add(level.player.velocity_x, (vars.tilt_angle - 30*if(vars.tilt_angle > 0, 1, -1))*6.0)),
	   
	   set(platform_area, [80 - 80*cos(angle), 17, 80 + 80*cos(angle)]),
	   set(rotate, angle),
	   set(platform_offsets, [-160*sin(angle), 160*sin(angle)])
	   ] where angle = vars.tilt_angle",
animation: {
	id: "normal",
	no_remove_alpha_borders: true,
	image: "experimental/crazy-platform.png",
	x: 0,
	y: 0,
	w: 160,
	h: 32,
	duration: 10000,
},
}
