counter +1

This commit is contained in:
Rendo 2025-07-19 19:29:45 +05:00
commit 92ebb2868d
11 changed files with 50 additions and 39 deletions

View file

@ -1,5 +1,5 @@
using Godot;
using System;
using Newlon.Components.GUI;
namespace Newlon.Components;
@ -10,7 +10,7 @@ public partial class LevelGUIElements : Control
[Export]
public HBoxContainer SeedpacketsHotbar;
[Export]
public TextureRect SunCounter;
public SunCounter SunCounter;
public override void _Ready()
{
Instance = this;

View file

@ -1,4 +1,5 @@
using Godot;
using Newlon.Components.GUI;
using Newlon.Components.Level;
@ -6,8 +7,6 @@ namespace Newlon;
public partial class Sun : Area2D
{
public static Control Counter;
[Export] public int amount = 25;
[Export] private Timer _deathTimer;
[Export] private AnimationPlayer _rotation;
@ -39,21 +38,22 @@ public partial class Sun : Area2D
}
public override void _MouseEnter()
{
if (Settings.SunClick) return;
if (Settings.SunClick || scoring) return;
ScoreSun();
}
private void ScoreSun()
{
_fade.Stop();
scoring = true;
RuntimeLevelData.Instance.AddSun(amount);
GetNode<ChannelPlayer>("SunPlayer").Play();
var tween = CreateTween();
tween.TweenInterval(0.1);
tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (Counter.GlobalPosition + Counter.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (SunCounter.Instance.sunImage.GlobalPosition + SunCounter.Instance.sunImage.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
tween.TweenCallback(Callable.From(() =>
{
RuntimeLevelData.Instance.AddSun(amount);
SunCounter.Update();
QueueFree();
}));
}

View file

@ -1,12 +1,32 @@
using System.Globalization;
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class SunCounter : Label
public partial class SunCounter : Control
{
public override void _Process(double delta)
public static SunCounter Instance { get; private set; }
private Tween tween;
[Export] private Label text;
[Export] public TextureRect sunImage { get; private set;}
public override void _EnterTree()
{
Text = RuntimeLevelData.Instance.SunCount.ToString();
Instance = this;
}
public static void Update()
{
if (Instance.tween != null) Instance.tween.Kill();
Instance.tween = Instance.CreateTween();
Instance.tween.TweenMethod(Callable.From<int>(Instance.SetText), int.Parse(Instance.text.Text), RuntimeLevelData.Instance.SunCount, 1.0);
}
public static void UpdateInstantly()
{
Instance.text.Text = RuntimeLevelData.Instance.SunCount.ToString();
}
private void SetText(int value)
{
text.Text = value.ToString();
}
}

View file

@ -1,11 +0,0 @@
using Godot;
using Newlon;
using System;
public partial class SunCounterImage : Control
{
public override void _Ready()
{
Sun.Counter = this;
}
}

View file

@ -1 +0,0 @@
uid://0ekxnoq6cyt4

View file

@ -59,7 +59,7 @@ public partial class PlantField : Node2D
bool canPlace = _resource != null
&& inBoundary
&& PoolContainer.Instance.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
&& RuntimeLevelData.Instance.CheckSpendSun(_resource.Cost);
&& RuntimeLevelData.Instance.CheckSpendSun((int)_resource.Cost);
// Setting visuals
if (_previousCanPlace != canPlace)
@ -97,7 +97,7 @@ public partial class PlantField : Node2D
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant);
RuntimeLevelData.Instance.SpendSun(_resource.Cost);
RuntimeLevelData.Instance.SpendSun((int)_resource.Cost);
PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * FieldParams.TileHeight/2.0f);

View file

@ -1,5 +1,6 @@
using System;
using Godot;
using Newlon.Components.GUI;
namespace Newlon.Components.Level;
@ -14,8 +15,7 @@ public partial class RuntimeLevelData : Node
Loose
}
[Export]
public float SunCount { get; private set; } = 0;
public int SunCount { get; private set; } = 0;
[Export]
private LevelRunner levelRunner;
[Export]
@ -37,20 +37,24 @@ public partial class RuntimeLevelData : Node
public override void _Ready()
{
Engine.TimeScale = 1.0;
SunCount = LevelResource.startSun;
SunCounter.UpdateInstantly();
SetLevelState(LevelStates.ChooseYourSeeds);
}
#region Sun
public void AddSun(float amount)
public void AddSun(int amount)
{
SunCount += amount;
SunCounter.Update();
}
public void SpendSun(float amount)
public void SpendSun(int amount)
{
SunCount -= amount;
SunCounter.Update();
}
public bool CheckSpendSun(float amount)
public bool CheckSpendSun(int amount)
{
if (SunCount - amount < 0) return false;