Sun, Shovel, Fastforward, GUI Improvements
This commit is contained in:
parent
26c3aeb7e9
commit
63935d5978
28 changed files with 546 additions and 45 deletions
31
scripts/components/gui/FastForwardButton.cs
Normal file
31
scripts/components/gui/FastForwardButton.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class FastForwardButton : TextureButton
|
||||
{
|
||||
[Export] private Texture2D firstSpeed;
|
||||
[Export] private Texture2D secondSpeed;
|
||||
[Export] private Texture2D thirdSpeed;
|
||||
|
||||
private int speed = 1;
|
||||
|
||||
public void OnPressed()
|
||||
{
|
||||
speed = Mathf.Wrap(speed+1, 1, 4);
|
||||
|
||||
switch (speed)
|
||||
{
|
||||
case 1:
|
||||
TextureNormal = firstSpeed;
|
||||
break;
|
||||
case 2:
|
||||
TextureNormal = secondSpeed;
|
||||
break;
|
||||
case 3:
|
||||
TextureNormal = thirdSpeed;
|
||||
break;
|
||||
}
|
||||
|
||||
Engine.TimeScale = speed;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,11 +8,21 @@ public partial class PlantSlot : TextureButton
|
|||
[Export] private TextureRect _icon;
|
||||
[Export] private Timer _timer;
|
||||
|
||||
private bool _recharging;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_resource != null)
|
||||
UpdateContents();
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_resource != null)
|
||||
{
|
||||
Disabled = _recharging || LevelController.Instance.LevelData.SunCount < _resource.Cost;
|
||||
FocusMode = Disabled ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPlantResource( PlantResource resource )
|
||||
{
|
||||
|
|
@ -43,8 +53,7 @@ public partial class PlantSlot : TextureButton
|
|||
|
||||
public void Recharge()
|
||||
{
|
||||
Disabled = true;
|
||||
FocusMode = FocusModeEnum.None;
|
||||
_recharging = true;
|
||||
|
||||
ReleaseFocus();
|
||||
|
||||
|
|
@ -53,7 +62,6 @@ public partial class PlantSlot : TextureButton
|
|||
|
||||
private void Timeout()
|
||||
{
|
||||
Disabled = false;
|
||||
FocusMode = FocusModeEnum.All;
|
||||
_recharging = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
scripts/components/gui/ShovelButton.cs
Normal file
39
scripts/components/gui/ShovelButton.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ShovelButton : TextureButton
|
||||
{
|
||||
private RayCast2D _shovelCast;
|
||||
public override void _Ready()
|
||||
{
|
||||
_shovelCast = GetNode<RayCast2D>("RayCast2D");
|
||||
_shovelCast.CallDeferred("reparent", GetTree().CurrentScene);
|
||||
}
|
||||
private void OnFocusExited()
|
||||
{
|
||||
ButtonPressed = false;
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_shovelCast.GlobalPosition = _shovelCast.GetGlobalMousePosition();
|
||||
}
|
||||
public override void _Toggled(bool toggledOn)
|
||||
{
|
||||
_shovelCast.Enabled = toggledOn;
|
||||
|
||||
Cursor.Instance.shovel = toggledOn;
|
||||
Cursor.Instance.UpdateCursor();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("primary_action"))
|
||||
{
|
||||
if (_shovelCast.IsColliding() && (_shovelCast.GetCollider() as CollisionObject2D).GetParent() is RuntimePlantData plant)
|
||||
{
|
||||
plant.Kill();
|
||||
}
|
||||
ButtonPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
scripts/components/level/SunSpawner.cs
Normal file
28
scripts/components/level/SunSpawner.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,8 +38,13 @@ public partial class RuntimePlantData : Node2D, IEntity
|
|||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition);
|
||||
QueueFree();
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue