Sun, Shovel, Fastforward, GUI Improvements

This commit is contained in:
Фёдор Веселов 2024-09-16 09:57:11 +05:00
commit 63935d5978
28 changed files with 546 additions and 45 deletions

View file

@ -7,6 +7,7 @@ public partial class PlantField : Node2D
private PlantResource _resource;
private PlantSlot _slot;
private bool _previousCanPlace;
public override void _Ready()
{
LevelController.Instance.PlantField = this;
@ -32,49 +33,52 @@ public partial class PlantField : Node2D
bool inBoundary = expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y;
bool _canPlace = _resource != null
bool canPlace = _resource != null
&& inBoundary
&& LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
&& LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost);
// Setting visuals
if (_canPlace)
if (_previousCanPlace != canPlace)
{
Material.Set("shader_parameter/amount", 0);
Cursor.Instance.SetPlantCursor();
if (canPlace)
{
Material.Set("shader_parameter/amount", 0);
}
else
{
Material.Set("shader_parameter/amount", 1);
}
Cursor.Instance.plant = canPlace;
Cursor.Instance.UpdateCursor();
}
_previousCanPlace = canPlace;
if (canPlace)
_plantSetter.GlobalPosition = expected_pos;
}
else
{
Cursor.Instance.SetDefaultCursor();
Material.Set("shader_parameter/amount", 1);
}
_plantSetter.Texture = _resource == null ? null : _resource.Preview;
}
// Spawning plant
if (Input.IsMouseButtonPressed(MouseButton.Left)
&& _canPlace )
public override void _UnhandledInput(InputEvent @event)
{
if (@event.IsActionPressed("cancel_plant") && _slot != null)
{
_slot.ReleaseFocus();
}
if (@event.IsActionPressed("primary_action") && _previousCanPlace)
{
var plant = _resource.Scene.Instantiate<RuntimePlantData>();
LevelController.Instance.Pools.Plants.AddChild(plant);
plant.GlobalPosition = expected_pos;
plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14);
plant.Layer = _resource.Layer;
LevelController.Instance.Pools.EntityField[_resource.Layer].Add(expected_pos, plant as IEntity);
LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity);
LevelController.Instance.LevelData.SpendSun(_resource.Cost);
// Unfocusing and recharging slot
_slot.Recharge();
}
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("cancel_plant"))
{
_slot.ReleaseFocus();
}
}
}

View file

@ -0,0 +1,28 @@
using Godot;
using System;
public partial class SunSpawner : Node
{
[Export]
public int MinSun = 25;
[Export]
public int MaxSun = 25;
[Export]
private PackedScene SunScene;
public void Spawn()
{
float x = GD.Randf()*9*Utility.TileWidth;
uint y = GD.Randi() % 5;
var sun = SunScene.Instantiate<Sun>();
LevelController.Instance.Pools.Projectiles.AddChild(sun);
sun.GlobalPosition = new Vector2(Utility.LeftFieldBoundary.X + x, -90);
var moveTween = CreateTween();
moveTween.TweenProperty(sun,"global_position", new Vector2(Utility.LeftFieldBoundary.X + x,
Utility.LeftFieldBoundary.Y + Utility.TileHeight * y + Utility.TileHeight/2.0f),9-y);
}
}