Zondre
This commit is contained in:
parent
c266d22f58
commit
2eb65c3092
24 changed files with 566 additions and 49 deletions
34
scripts/components/level/PlantField.cs
Normal file
34
scripts/components/level/PlantField.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using Godot;
|
||||
|
||||
public partial class PlantField : Node2D
|
||||
{
|
||||
private Area2D _plantSetter;
|
||||
private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
|
||||
private bool _canPlace;
|
||||
public override void _Ready()
|
||||
{
|
||||
LevelController.Instance.PlantField = this;
|
||||
_plantSetter = GetChild<Area2D>(0);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var mouse_pos = GetGlobalMousePosition();
|
||||
_plantSetter.GlobalPosition = mouse_pos;
|
||||
|
||||
var expected_pos = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14);
|
||||
if (expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y)
|
||||
{
|
||||
_canPlace = true;
|
||||
Material.Set("shader_parameter/amount", 0);
|
||||
Cursor.Instance.SetPlantCursor();
|
||||
_plantSetter.GlobalPosition = expected_pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
_canPlace = false;
|
||||
Cursor.Instance.SetDefaultCursor();
|
||||
Material.Set("shader_parameter/amount", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue