41 lines
850 B
C#
41 lines
850 B
C#
using System;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
public partial class FallFloor : Node2D
|
|
{
|
|
private static FallFloor Instance;
|
|
private Array<StaticBody2D> bodies = [];
|
|
public override void _Ready()
|
|
{
|
|
Instance = this;
|
|
foreach (StaticBody2D body in GetChildren())
|
|
{
|
|
bodies.Add(body);
|
|
}
|
|
}
|
|
public static StaticBody2D GetNearest(Vector2 point)
|
|
{
|
|
var selected = Instance.bodies[0];
|
|
foreach (StaticBody2D body in Instance.bodies)
|
|
{
|
|
if (Math.Abs(selected.GlobalPosition.Y - point.Y) > Math.Abs(body.GlobalPosition.Y - point.Y))
|
|
{
|
|
selected = body;
|
|
}
|
|
}
|
|
return selected;
|
|
}
|
|
public static Array<StaticBody2D> GetEverythingElse(StaticBody2D except)
|
|
{
|
|
Array<StaticBody2D> bodys = [];
|
|
foreach (StaticBody2D body in Instance.bodies)
|
|
{
|
|
if (except != body)
|
|
{
|
|
bodys.Add(body);
|
|
}
|
|
}
|
|
return bodys;
|
|
}
|
|
}
|