Morning-Murder/Scripts/Pillow.cs

46 lines
938 B
C#
Raw Permalink Normal View History

2023-09-14 10:29:52 +03:00
using Godot;
using System;
public partial class Pillow : RigidBody2D
{
[Export] public float angularSpeed = 1f;
[Export] public Vector2 velocity = new Vector2(1, 0);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Rotation = (float)Random.Shared.NextDouble();
AngularVelocity = ((float)Random.Shared.NextDouble() + .5f) * angularSpeed;
LinearVelocity = velocity;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public override void _PhysicsProcess(double delta)
{
base._PhysicsProcess(delta);
Godot.Collections.Array<Node2D> node2Ds = GetCollidingBodies();
Node2D candy = null;
foreach (var node2D in node2Ds)
{
if (node2D.Name != "Candy")
continue;
candy = node2D;
break;
}
if (candy == null)
return;
candy.Visible = false;
Visible = false;
}
}