Player-field manipulations

This commit is contained in:
Фёдор Веселов 2024-09-15 19:19:59 +05:00
commit 74759e9e16
21 changed files with 270 additions and 54 deletions

View file

@ -0,0 +1,7 @@
shader_type canvas_item;
uniform sampler2D mask : filter_nearest;
void fragment() {
COLOR.a = texture(mask, UV).a * COLOR.a;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dxyf557m4mq1p"
path="res://.godot/imported/EmptyPlantCard.png-1c00937df6b4404c406414f4f4aadc00.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/gui/EmptyPlantCard.png"
dest_files=["res://.godot/imported/EmptyPlantCard.png-1c00937df6b4404c406414f4f4aadc00.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,7 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://cmgaryx5wgu14"] [gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://iw75j816gbc"]
[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_bxos1"] [ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_x8dof"]
[resource] [resource]
atlas = ExtResource("1_bxos1") atlas = ExtResource("1_x8dof")
region = Rect2(259, 172, 41, 56) region = Rect2(54, 3, 42, 56)

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c1afy0ga6h1ic"
path="res://.godot/imported/white_box.png-eab8f329b0dc39a0d0cf36a0bf998644.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/white_box.png"
dest_files=["res://.godot/imported/white_box.png-eab8f329b0dc39a0d0cf36a0bf998644.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -37,6 +37,12 @@ cheat_add_sun={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
] ]
} }
cancel_plant={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(82, 2),"global_position":Vector2(91, 41),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[layer_names] [layer_names]

View file

@ -1,3 +1,6 @@
[gd_resource type="Theme" format=3 uid="uid://b8l285cjcgeyi"] [gd_resource type="Theme" load_steps=2 format=3 uid="uid://b8l285cjcgeyi"]
[ext_resource type="FontFile" uid="uid://nbrt5q3t8tud" path="res://assets/fonts/pico12.ttf" id="1_103to"]
[resource] [resource]
default_font = ExtResource("1_103to")

View file

@ -11,3 +11,4 @@ Scene = ExtResource("1_rqf2x")
ReloadTime = 5.0 ReloadTime = 5.0
StartReloadTime = 0.0 StartReloadTime = 0.0
Preview = ExtResource("1_rnq6r") Preview = ExtResource("1_rnq6r")
layer = 1

View file

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="PlantResource" load_steps=4 format=3 uid="uid://drm42f48urvc4"]
[ext_resource type="Texture2D" uid="uid://iw75j816gbc" path="res://assets/sprites/plants/sunflower.tres" id="1_8rd5i"]
[ext_resource type="PackedScene" uid="uid://be1kgukmiu0hs" path="res://scenes/entities/plants/peashooter.tscn" id="2_7mcb6"]
[ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="3_vt4jc"]
[resource]
script = ExtResource("3_vt4jc")
Cost = 50
Scene = ExtResource("2_7mcb6")
ReloadTime = 5.0
StartReloadTime = 0.0
Preview = ExtResource("1_8rd5i")
Layer = 1

View file

@ -1,19 +1,10 @@
[gd_scene load_steps=10 format=3 uid="uid://crxsvv7drckpw"] [gd_scene load_steps=6 format=3 uid="uid://crxsvv7drckpw"]
[ext_resource type="Script" path="res://scripts/components/level/RuntimeLevelData.cs" id="1_i3bf5"] [ext_resource type="Script" path="res://scripts/components/level/RuntimeLevelData.cs" id="1_i3bf5"]
[ext_resource type="Texture2D" uid="uid://b0tb2hjum40aw" path="res://assets/sprites/summertime_saga.png" id="2_vmxhy"] [ext_resource type="Texture2D" uid="uid://b0tb2hjum40aw" path="res://assets/sprites/summertime_saga.png" id="2_vmxhy"]
[ext_resource type="PackedScene" uid="uid://cg8713v6c5w15" path="res://scenes/pools.tscn" id="3_jv7x4"] [ext_resource type="PackedScene" uid="uid://cg8713v6c5w15" path="res://scenes/pools.tscn" id="3_jv7x4"]
[ext_resource type="Script" path="res://scripts/components/level/PlantField.cs" id="5_rcajd"] [ext_resource type="PackedScene" uid="uid://devn21c7luf45" path="res://scenes/level components/field_controller.tscn" id="5_lwpg6"]
[ext_resource type="Shader" path="res://assets/shaders/greyscale.gdshader" id="5_xsv1x"]
[ext_resource type="PackedScene" uid="uid://cfnmspei3k4p7" path="res://scenes/gui/runtime_gui.tscn" id="6_0baou"] [ext_resource type="PackedScene" uid="uid://cfnmspei3k4p7" path="res://scenes/gui/runtime_gui.tscn" id="6_0baou"]
[ext_resource type="Texture2D" uid="uid://ot1n4nval86w" path="res://assets/sprites/plants/peashooter.tres" id="6_1r0ne"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_0miwm"]
shader = ExtResource("5_xsv1x")
shader_parameter/amount = 0.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_j04hk"]
size = Vector2(50, 60)
[node name="debug_lvl" type="Node2D"] [node name="debug_lvl" type="Node2D"]
@ -28,27 +19,17 @@ metadata/_edit_lock_ = true
[node name="RuntimeLevelData" type="Node" parent="."] [node name="RuntimeLevelData" type="Node" parent="."]
script = ExtResource("1_i3bf5") script = ExtResource("1_i3bf5")
SunCount = 5000
[node name="Pools" parent="." instance=ExtResource("3_jv7x4")] [node name="Pools" parent="." instance=ExtResource("3_jv7x4")]
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="GuiLayer" type="CanvasLayer" parent="."]
layer = 10 layer = 10
[node name="RuntimeGUI" parent="CanvasLayer" instance=ExtResource("6_0baou")] [node name="RuntimeGUI" parent="GuiLayer" instance=ExtResource("6_0baou")]
[node name="FieldController" type="Node2D" parent="."] [node name="Overlay" type="CanvasLayer" parent="."]
visible = false layer = 5
material = SubResource("ShaderMaterial_0miwm") follow_viewport_enabled = true
script = ExtResource("5_rcajd")
[node name="PlantSetter" type="Area2D" parent="FieldController"] [node name="FieldController" parent="Overlay" instance=ExtResource("5_lwpg6")]
use_parent_material = true
collision_layer = 0
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="FieldController/PlantSetter"]
shape = SubResource("RectangleShape2D_j04hk")
[node name="Peashooter" type="Sprite2D" parent="FieldController/PlantSetter"]
use_parent_material = true
texture = ExtResource("6_1r0ne")

View file

@ -1,25 +1,33 @@
[gd_scene load_steps=5 format=3 uid="uid://c8qru1yhnbbkl"] [gd_scene load_steps=9 format=3 uid="uid://c8qru1yhnbbkl"]
[ext_resource type="Texture2D" uid="uid://cmgaryx5wgu14" path="res://assets/sprites/gui/PlantCard.tres" id="1_fugf5"]
[ext_resource type="Texture2D" uid="uid://cabpf23ndlvx0" path="res://assets/sprites/gui/Selection.tres" id="2_5mpv8"] [ext_resource type="Texture2D" uid="uid://cabpf23ndlvx0" path="res://assets/sprites/gui/Selection.tres" id="2_5mpv8"]
[ext_resource type="Script" path="res://scripts/components/gui/PlantSlot.cs" id="3_eer7n"] [ext_resource type="Script" path="res://scripts/components/gui/PlantSlot.cs" id="3_eer7n"]
[ext_resource type="Shader" path="res://assets/shaders/gui_masking.gdshader" id="4_bryew"]
[ext_resource type="Texture2D" uid="uid://dxyf557m4mq1p" path="res://assets/sprites/gui/EmptyPlantCard.png" id="5_2k0xq"]
[ext_resource type="Texture2D" uid="uid://c1afy0ga6h1ic" path="res://assets/sprites/white_box.png" id="5_7xerl"]
[ext_resource type="Script" path="res://scripts/components/gui/VeilResizer.cs" id="5_d6igb"]
[sub_resource type="LabelSettings" id="LabelSettings_js4li"] [sub_resource type="LabelSettings" id="LabelSettings_js4li"]
font_size = 13 font_size = 13
font_color = Color(0, 0, 0, 1) font_color = Color(0, 0, 0, 1)
[node name="PlantSlot" type="TextureButton" node_paths=PackedStringArray("_cost", "_icon")] [sub_resource type="ShaderMaterial" id="ShaderMaterial_qxf0q"]
shader = ExtResource("4_bryew")
shader_parameter/mask = ExtResource("5_2k0xq")
[node name="PlantSlot" type="TextureButton" node_paths=PackedStringArray("_cost", "_icon", "_timer")]
anchors_preset = -1 anchors_preset = -1
anchor_right = 0.137 anchor_right = 0.137
anchor_bottom = 0.28 anchor_bottom = 0.28
offset_right = -0.200005 offset_right = -0.200005
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
texture_normal = ExtResource("1_fugf5") texture_normal = ExtResource("5_2k0xq")
texture_focused = ExtResource("2_5mpv8") texture_focused = ExtResource("2_5mpv8")
stretch_mode = 0 stretch_mode = 0
script = ExtResource("3_eer7n") script = ExtResource("3_eer7n")
_cost = NodePath("Cost") _cost = NodePath("Cost")
_icon = NodePath("PlantPreviewContainer/Preview") _icon = NodePath("PlantPreviewContainer/Preview")
_timer = NodePath("RechargeTimer")
metadata/_edit_use_anchors_ = true metadata/_edit_use_anchors_ = true
[node name="Cost" type="Label" parent="."] [node name="Cost" type="Label" parent="."]
@ -68,3 +76,28 @@ mouse_filter = 2
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
expand_mode = 1 expand_mode = 1
stretch_mode = 5 stretch_mode = 5
[node name="Veil" type="TextureProgressBar" parent="." node_paths=PackedStringArray("_referenceTimer")]
material = SubResource("ShaderMaterial_qxf0q")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
max_value = 1.0
step = 0.001
fill_mode = 3
nine_patch_stretch = true
texture_progress = ExtResource("5_7xerl")
tint_progress = Color(0, 0, 0, 0.843137)
script = ExtResource("5_d6igb")
_referenceTimer = NodePath("../RechargeTimer")
[node name="RechargeTimer" type="Timer" parent="."]
one_shot = true
[connection signal="focus_exited" from="." to="." method="OnFocusExited"]
[connection signal="pressed" from="." to="." method="OnPressed"]
[connection signal="timeout" from="RechargeTimer" to="." method="Timeout"]

View file

@ -1,11 +1,13 @@
[gd_scene load_steps=9 format=3 uid="uid://cfnmspei3k4p7"] [gd_scene load_steps=11 format=3 uid="uid://cfnmspei3k4p7"]
[ext_resource type="PackedScene" uid="uid://ky35veswaytr" path="res://scenes/gui/sun_counter.tscn" id="1_le3od"] [ext_resource type="PackedScene" uid="uid://ky35veswaytr" path="res://scenes/gui/sun_counter.tscn" id="1_le3od"]
[ext_resource type="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/GameStyle.tres" id="1_xf6ra"]
[ext_resource type="PackedScene" uid="uid://c8qru1yhnbbkl" path="res://scenes/gui/plant_card.tscn" id="2_cjtsw"] [ext_resource type="PackedScene" uid="uid://c8qru1yhnbbkl" path="res://scenes/gui/plant_card.tscn" id="2_cjtsw"]
[ext_resource type="Texture2D" uid="uid://bbh0uwloi87tn" path="res://assets/sprites/gui/PlantPanel.png" id="2_eg3hk"] [ext_resource type="Texture2D" uid="uid://bbh0uwloi87tn" path="res://assets/sprites/gui/PlantPanel.png" id="2_eg3hk"]
[ext_resource type="Resource" uid="uid://c8rr1dc7mjr3d" path="res://resources/plants/Peashooter.tres" id="3_42s2d"] [ext_resource type="Resource" uid="uid://c8rr1dc7mjr3d" path="res://resources/plants/Peashooter.tres" id="3_42s2d"]
[ext_resource type="PackedScene" uid="uid://t0vpmycj6c8j" path="res://scenes/gui/shovel_button.tscn" id="3_bheea"] [ext_resource type="PackedScene" uid="uid://t0vpmycj6c8j" path="res://scenes/gui/shovel_button.tscn" id="3_bheea"]
[ext_resource type="PackedScene" uid="uid://cgm7td1hgs0rr" path="res://scenes/gui/fast_forward_button.tscn" id="4_66uy4"] [ext_resource type="PackedScene" uid="uid://cgm7td1hgs0rr" path="res://scenes/gui/fast_forward_button.tscn" id="4_66uy4"]
[ext_resource type="Resource" uid="uid://drm42f48urvc4" path="res://resources/plants/Sunflower.tres" id="5_6vih5"]
[ext_resource type="PackedScene" uid="uid://u5l3jd00s8vd" path="res://scenes/gui/pause_button.tscn" id="5_jyq78"] [ext_resource type="PackedScene" uid="uid://u5l3jd00s8vd" path="res://scenes/gui/pause_button.tscn" id="5_jyq78"]
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_ps2iw"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_ps2iw"]
@ -23,6 +25,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme = ExtResource("1_xf6ra")
[node name="Hotbar" type="HBoxContainer" parent="."] [node name="Hotbar" type="HBoxContainer" parent="."]
layout_mode = 1 layout_mode = 1
@ -51,6 +54,7 @@ _resource = ExtResource("3_42s2d")
[node name="SecondSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")] [node name="SecondSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")]
layout_mode = 2 layout_mode = 2
_resource = ExtResource("5_6vih5")
[node name="ThirdSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")] [node name="ThirdSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")]
layout_mode = 2 layout_mode = 2

View file

@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=3 uid="uid://devn21c7luf45"]
[ext_resource type="Shader" path="res://assets/shaders/greyscale.gdshader" id="1_d73yj"]
[ext_resource type="Script" path="res://scripts/components/level/PlantField.cs" id="2_84bqh"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_0miwm"]
shader = ExtResource("1_d73yj")
shader_parameter/amount = 0.0
[node name="FieldController" type="Node2D"]
material = SubResource("ShaderMaterial_0miwm")
script = ExtResource("2_84bqh")
[node name="Preview" type="Sprite2D" parent="."]
use_parent_material = true

View file

@ -1,11 +1,18 @@
using Godot; using Godot;
using System; using System;
public partial class PlantSlot : Node public partial class PlantSlot : TextureButton
{ {
[Export] private PlantResource _resource; [Export] private PlantResource _resource;
[Export] private Label _cost; [Export] private Label _cost;
[Export] private TextureRect _icon; [Export] private TextureRect _icon;
[Export] private Timer _timer;
public override void _Ready()
{
if (_resource != null)
UpdateContents();
}
public void SetPlantResource( PlantResource resource ) public void SetPlantResource( PlantResource resource )
{ {
@ -18,5 +25,35 @@ public partial class PlantSlot : Node
{ {
_cost.Text = _resource.Cost.ToString(); _cost.Text = _resource.Cost.ToString();
_icon.Texture = _resource.Preview; _icon.Texture = _resource.Preview;
_timer.WaitTime = _resource.ReloadTime;
}
private void OnPressed()
{
if (_timer.TimeLeft == 0)
{
LevelController.Instance.PlantField.SetPlant(this, _resource);
}
}
private void OnFocusExited()
{
LevelController.Instance.PlantField.SetPlant(null, null);
}
public void Recharge()
{
Disabled = true;
FocusMode = FocusModeEnum.None;
ReleaseFocus();
_timer.Start();
}
private void Timeout()
{
Disabled = false;
FocusMode = FocusModeEnum.All;
} }
} }

View file

@ -0,0 +1,12 @@
using Godot;
using System;
public partial class VeilResizer : TextureProgressBar
{
[Export] private Timer _referenceTimer;
public override void _Process(double delta)
{
Value = (_referenceTimer.TimeLeft/_referenceTimer.WaitTime);
}
}

View file

@ -4,15 +4,21 @@ public partial class PlantField : Node2D
{ {
private Sprite2D _plantSetter; private Sprite2D _plantSetter;
private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight); private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
private bool _canPlace;
[Export] private PlantResource _resource;
private PlantResource _plant; private PlantSlot _slot;
public override void _Ready() public override void _Ready()
{ {
LevelController.Instance.PlantField = this; LevelController.Instance.PlantField = this;
_plantSetter = GetChild<Sprite2D>(0); _plantSetter = GetChild<Sprite2D>(0);
} }
public void SetPlant(PlantSlot slot, PlantResource plant)
{
_resource = plant;
_slot = slot;
}
public override void _Process(double delta) public override void _Process(double delta)
{ {
// Getting and storing global mouse position, setting plant-poiner to it // Getting and storing global mouse position, setting plant-poiner to it
@ -25,28 +31,50 @@ public partial class PlantField : Node2D
// Checking for boundaries // Checking for boundaries
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 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
&& inBoundary
&& LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
&& LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost);
// Setting visuals // Setting visuals
if (_plant != null && inBoundary) if (_canPlace)
{ {
_canPlace = true;
Material.Set("shader_parameter/amount", 0); Material.Set("shader_parameter/amount", 0);
Cursor.Instance.SetPlantCursor(); Cursor.Instance.SetPlantCursor();
_plantSetter.GlobalPosition = expected_pos; _plantSetter.GlobalPosition = expected_pos;
} }
else else
{ {
_canPlace = false;
Cursor.Instance.SetDefaultCursor(); Cursor.Instance.SetDefaultCursor();
Material.Set("shader_parameter/amount", 1); Material.Set("shader_parameter/amount", 1);
} }
// Spawning plant _plantSetter.Texture = _resource == null ? null : _resource.Preview;
if (Input.IsMouseButtonPressed(MouseButton.Left) && _canPlace)
{
var plant = _plant.Scene.Instantiate<Node2D>(); // Spawning plant
if (Input.IsMouseButtonPressed(MouseButton.Left)
&& _canPlace )
{
var plant = _resource.Scene.Instantiate<RuntimePlantData>();
LevelController.Instance.Pools.Plants.AddChild(plant); LevelController.Instance.Pools.Plants.AddChild(plant);
plant.GlobalPosition = expected_pos; plant.GlobalPosition = expected_pos;
LevelController.Instance.Pools.EntityField[_resource.Layer].Add(expected_pos, 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

@ -1,5 +1,5 @@
using Godot; using Godot;
using System; using System.Collections.Generic;
// //
// PoolContainer contains nodes that contain different elemnts that generate during runtime // PoolContainer contains nodes that contain different elemnts that generate during runtime
@ -17,6 +17,7 @@ public partial class PoolContainer : Node
[Export] [Export]
public Node Structures { get; private set; } public Node Structures { get; private set; }
public Dictionary<Vector2, IEntity>[] EntityField = { new Dictionary<Vector2, IEntity>(), new Dictionary<Vector2, IEntity>(), new Dictionary<Vector2, IEntity>() };
public override void _Ready() public override void _Ready()
{ {
LevelController.Instance.Pools = this; LevelController.Instance.Pools = this;

View file

@ -4,6 +4,7 @@ using System;
public partial class RuntimeLevelData : Node public partial class RuntimeLevelData : Node
{ {
[Export]
public int SunCount { get; private set; } = 0; public int SunCount { get; private set; } = 0;
public override void _Ready() public override void _Ready()
@ -15,13 +16,15 @@ public partial class RuntimeLevelData : Node
{ {
SunCount += amount; SunCount += amount;
} }
public void SpendSun(int amount)
{
SunCount -= amount;
}
public bool TrySpendSun(int amount) public bool CheckSpendSun(int amount)
{ {
if (SunCount - amount < 0) return false; if (SunCount - amount < 0) return false;
SunCount -= amount;
return true; return true;
} }

View file

@ -15,6 +15,7 @@ public partial class RuntimePlantData : Node2D, IEntity
public int Hp => _hp; public int Hp => _hp;
public int MaxHp => _maxHP; public int MaxHp => _maxHP;
public int Line => _line; public int Line => _line;
public int Layer;
public override void _Ready() public override void _Ready()
{ {
@ -37,6 +38,7 @@ public partial class RuntimePlantData : Node2D, IEntity
if (_hp <= 0) if (_hp <= 0)
{ {
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition);
QueueFree(); QueueFree();
} }
} }

View file

@ -14,4 +14,5 @@ public partial class PlantResource : Resource
public float StartReloadTime; public float StartReloadTime;
[Export] [Export]
public Texture2D Preview; public Texture2D Preview;
[Export] public int Layer = 1;
} }