newlon/scripts/droppable-items/DropMover.cs
2025-07-25 18:48:49 +05:00

32 lines
769 B
C#

using Godot;
namespace Newlon.Components.Droppables;
public partial class DropMover : Node
{
public float ySpeed = -200.0f;
public float xSpeed = 150.0f;
private float stop_y;
private Node2D parent;
private Vector2 velocity;
private float gravity;
public override void _Ready()
{
parent = GetParent<Node2D>();
stop_y = ((parent.GlobalPosition / FieldParams.Tile).Ceil() * FieldParams.Tile).Y;
gravity = (float)ProjectSettings.GetSetting("physics/2d/default_gravity");
velocity = new Vector2((GD.Randf() - 0.5f) * xSpeed, ySpeed);
}
public override void _Process(double delta)
{
if (parent.GlobalPosition.Y >= stop_y) QueueFree();
velocity += Vector2.Down * gravity * (float)delta;
parent.GlobalPosition += velocity * (float)delta;
}
}