Pixel-Composer/scripts/node_VFX_attract/node_VFX_attract.gml

41 lines
1.3 KiB
Text
Raw Normal View History

2023-02-28 15:43:01 +07:00
function Node_VFX_Attract(_x, _y, _group = noone) : Node_VFX_effector(_x, _y, _group) constructor {
2022-12-13 15:20:36 +07:00
name = "Attract";
2022-12-16 15:18:09 +07:00
node_draw_icon = s_node_vfx_attract;
2022-12-13 15:20:36 +07:00
2024-08-08 11:57:51 +07:00
inputs[4].setVisible(false, false);
2023-01-17 14:11:55 +07:00
2024-08-18 11:16:20 +07:00
newInput(effector_input_length + 0, nodeValue_Bool("Destroy when reach middle", self, false ));
2023-10-29 12:29:10 +07:00
array_push(input_display_list, effector_input_length + 0);
2024-12-25 10:52:25 +07:00
destroyMiddle = false;
static onVFXUpdate = function(frame = CURRENT_FRAME) {
destroyMiddle = getInputData(effector_input_length + 0);
}
2022-12-13 15:20:36 +07:00
function onAffect(part, str) {
2024-12-25 10:52:25 +07:00
var _rot = random_range(rotateX, rotateY);
var _scX = random_range(scaleX0, scaleX1);
var _scY = random_range(scaleY0, scaleY1);
2022-12-13 15:20:36 +07:00
2024-12-25 10:52:25 +07:00
var pv = part.getPivot();
var dirr = point_direction(pv[0], pv[1], area_x, area_y);
part.x = part.x + lengthdir_x(strength * str, dirr);
part.y = part.y + lengthdir_y(strength * str, dirr);
2022-12-13 15:20:36 +07:00
part.rot += _rot * str;
2024-12-25 10:52:25 +07:00
var scx_s = _scX * str;
var scy_s = _scY * str;
2023-01-17 14:11:55 +07:00
if(scx_s < 0) part.sc_sx = lerp_linear(part.sc_sx, 0, abs(scx_s));
else part.sc_sx += sign(part.sc_sx) * scx_s;
2024-12-25 10:52:25 +07:00
2023-01-17 14:11:55 +07:00
if(scy_s < 0) part.sc_sy = lerp_linear(part.sc_sy, 0, abs(scy_s));
else part.sc_sy += sign(part.sc_sy) * scy_s;
2023-10-29 12:29:10 +07:00
2024-12-25 10:52:25 +07:00
if(!destroyMiddle) return;
if(point_distance(part.x, part.y, area_x, area_y) <= strength)
2023-10-29 12:29:10 +07:00
part.kill();
2022-12-13 15:20:36 +07:00
}
}