sun now drops properly
This commit is contained in:
parent
b551c7f012
commit
0f6445d677
2 changed files with 34 additions and 0 deletions
30
scripts/droppable-items/DropMover.cs
Normal file
30
scripts/droppable-items/DropMover.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -13,9 +13,13 @@ public partial class PlantSunSpawner : Node2D
|
||||||
public void Spawn()
|
public void Spawn()
|
||||||
{
|
{
|
||||||
var sun = _sunScene.Instantiate<Sun>();
|
var sun = _sunScene.Instantiate<Sun>();
|
||||||
|
|
||||||
sun.amount = _amountPerSun;
|
sun.amount = _amountPerSun;
|
||||||
|
|
||||||
PoolContainer.Instance.Projectiles.AddChild(sun);
|
PoolContainer.Instance.Projectiles.AddChild(sun);
|
||||||
sun.GlobalPosition = GlobalPosition;
|
sun.GlobalPosition = GlobalPosition;
|
||||||
|
|
||||||
|
var mover = new DropMover();
|
||||||
|
sun.AddChild(mover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue