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

@ -5,7 +5,7 @@ using Godot.Collections;
[Tool] [Tool]
public partial class AdventureLevelResource : Resource public partial class AdventureLevelResource : Resource
{ {
[Export] public float startSun = 50; [Export] public int startSun = 50;
//[Export] public Array<Conditions> conditions; //[Export] public Array<Conditions> conditions;
[Export(PropertyHint.Range, "0,1,0.01")] public float wavePercentage; [Export(PropertyHint.Range, "0,1,0.01")] public float wavePercentage;
[Export] public float standardWaveDelay; [Export] public float standardWaveDelay;

View file

@ -1,16 +1,15 @@
[gd_scene load_steps=7 format=3 uid="uid://ky35veswaytr"] [gd_scene load_steps=6 format=3 uid="uid://ky35veswaytr"]
[ext_resource type="Texture2D" uid="uid://bhp3vuvwf7lak" path="res://assets/sprites/gui/suncounter.tres" id="1_e5x4k"] [ext_resource type="Texture2D" uid="uid://bhp3vuvwf7lak" path="res://assets/sprites/gui/suncounter.tres" id="1_e5x4k"]
[ext_resource type="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/themes/GameStyle.tres" id="1_vhhcn"] [ext_resource type="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/themes/GameStyle.tres" id="1_vhhcn"]
[ext_resource type="Texture2D" uid="uid://c47rflkf2wap0" path="res://assets/sprites/sun.tres" id="2_gugre"] [ext_resource type="Texture2D" uid="uid://c47rflkf2wap0" path="res://assets/sprites/sun.tres" id="2_gugre"]
[ext_resource type="Script" uid="uid://dwxohya1exdkh" path="res://scripts/gui/SunCounter.cs" id="3_qhmb8"] [ext_resource type="Script" uid="uid://dwxohya1exdkh" path="res://scripts/gui/SunCounter.cs" id="3_qhmb8"]
[ext_resource type="Script" uid="uid://0ekxnoq6cyt4" path="res://scripts/gui/SunCounterImage.cs" id="4_c68ge"]
[sub_resource type="LabelSettings" id="LabelSettings_lxkq5"] [sub_resource type="LabelSettings" id="LabelSettings_lxkq5"]
font_size = 10 font_size = 10
font_color = Color(0, 0, 0, 1) font_color = Color(0, 0, 0, 1)
[node name="SunCounter" type="TextureRect"] [node name="SunCounter" type="TextureRect" node_paths=PackedStringArray("text", "sunImage")]
anchors_preset = -1 anchors_preset = -1
anchor_right = 0.082 anchor_right = 0.082
anchor_bottom = 0.067 anchor_bottom = 0.067
@ -19,6 +18,9 @@ offset_bottom = 0.199999
size_flags_vertical = 0 size_flags_vertical = 0
theme = ExtResource("1_vhhcn") theme = ExtResource("1_vhhcn")
texture = ExtResource("1_e5x4k") texture = ExtResource("1_e5x4k")
script = ExtResource("3_qhmb8")
text = NodePath("Label")
sunImage = NodePath("Sun")
[node name="Sun" type="TextureRect" parent="."] [node name="Sun" type="TextureRect" parent="."]
show_behind_parent = true show_behind_parent = true
@ -34,7 +36,6 @@ offset_right = 22.5
offset_bottom = 22.487 offset_bottom = 22.487
pivot_offset = Vector2(23, 22) pivot_offset = Vector2(23, 22)
texture = ExtResource("2_gugre") texture = ExtResource("2_gugre")
script = ExtResource("4_c68ge")
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
process_mode = 3 process_mode = 3
@ -48,8 +49,8 @@ offset_left = 0.0219994
offset_top = 0.00599957 offset_top = 0.00599957
offset_right = -0.0219994 offset_right = -0.0219994
offset_bottom = -0.00500107 offset_bottom = -0.00500107
text = "0"
label_settings = SubResource("LabelSettings_lxkq5") label_settings = SubResource("LabelSettings_lxkq5")
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1
text_overrun_behavior = 3 text_overrun_behavior = 3
script = ExtResource("3_qhmb8")

View file

@ -194,7 +194,6 @@ size = Vector2(282, 399)
[node name="Data" type="Node" parent="."] [node name="Data" type="Node" parent="."]
script = ExtResource("1_tnxdx") script = ExtResource("1_tnxdx")
SunCount = 50.0
[node name="Camera2D" type="Camera2D" parent="."] [node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(481, 200) position = Vector2(481, 200)

View file

@ -434,7 +434,6 @@ libraries = {
[node name="Data" type="Node" parent="." node_paths=PackedStringArray("levelRunner", "player")] [node name="Data" type="Node" parent="." node_paths=PackedStringArray("levelRunner", "player")]
script = ExtResource("1_31ltw") script = ExtResource("1_31ltw")
SunCount = 50.0
levelRunner = NodePath("../LevelRunner") levelRunner = NodePath("../LevelRunner")
player = NodePath("../MainAnimationPlayer") player = NodePath("../MainAnimationPlayer")

View file

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

View file

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

View file

@ -1,12 +1,32 @@
using System.Globalization;
using Godot; using Godot;
using Newlon.Components.Level; using Newlon.Components.Level;
namespace Newlon.Components.GUI; 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 bool canPlace = _resource != null
&& inBoundary && inBoundary
&& PoolContainer.Instance.EntityField[_resource.Layer].ContainsKey(expected_pos) == false && PoolContainer.Instance.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
&& RuntimeLevelData.Instance.CheckSpendSun(_resource.Cost); && RuntimeLevelData.Instance.CheckSpendSun((int)_resource.Cost);
// Setting visuals // Setting visuals
if (_previousCanPlace != canPlace) if (_previousCanPlace != canPlace)
@ -97,7 +97,7 @@ public partial class PlantField : Node2D
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant); 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); PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * FieldParams.TileHeight/2.0f);

View file

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