46 lines
938 B
C#
46 lines
938 B
C#
|
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;
|
||
|
}
|
||
|
}
|