This commit is contained in:
Фёдор Веселов 2024-09-17 21:52:44 +05:00
commit 2c8bb1d652
6 changed files with 199 additions and 15 deletions

View file

@ -0,0 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://g2oppl54efja"]
[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_rqu4e"]
[resource]
atlas = ExtResource("1_rqu4e")
region = Rect2(104, 12, 41, 46)

View file

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="PlantResource" load_steps=4 format=3 uid="uid://c2e2yj7rgoswi"]
[ext_resource type="Texture2D" uid="uid://g2oppl54efja" path="res://assets/sprites/plants/Wallnut.tres" id="1_2akap"]
[ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="1_27l0t"]
[ext_resource type="PackedScene" uid="uid://dh6rm7o3taaek" path="res://scenes/entities/plants/wallnut.tscn" id="2_l87er"]
[resource]
script = ExtResource("1_27l0t")
Cost = 50
Scene = ExtResource("2_l87er")
ReloadTime = 20.0
StartReloadTime = 0.0
Preview = ExtResource("1_2akap")
Layer = 1

View file

@ -0,0 +1,129 @@
[gd_scene load_steps=12 format=3 uid="uid://dh6rm7o3taaek"]
[ext_resource type="Texture2D" uid="uid://dstqh1wc5dvmo" path="res://assets/sprites/atlases/plants/wallnut.png" id="1_571nl"]
[ext_resource type="Script" path="res://scripts/components/plants/RuntimePlantData.cs" id="1_mt5mt"]
[ext_resource type="Script" path="res://scripts/components/plants/behaviours/WallnutBehaviour.cs" id="3_tu4pm"]
[sub_resource type="Animation" id="Animation_s4r5j"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="Animation" id="Animation_lfaj3"]
resource_name = "idle_full"
length = 6.00005
loop_mode = 1
step = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33]
}
[sub_resource type="Animation" id="Animation_u73od"]
resource_name = "idle_low"
length = 5.50005
loop_mode = 1
step = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32]
}
[sub_resource type="Animation" id="Animation_c8ofx"]
resource_name = "idle_mid"
length = 6.00005
loop_mode = 1
step = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_7mgid"]
_data = {
"RESET": SubResource("Animation_s4r5j"),
"idle_full": SubResource("Animation_lfaj3"),
"idle_low": SubResource("Animation_u73od"),
"idle_mid": SubResource("Animation_c8ofx")
}
[sub_resource type="VisualShader" id="VisualShader_w5h5j"]
code = "shader_type canvas_item;
render_mode blend_mix;
"
graph_offset = Vector2(-551.922, -202.033)
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2(660, 100)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_a0k73"]
shader = SubResource("VisualShader_w5h5j")
[sub_resource type="RectangleShape2D" id="RectangleShape2D_523ui"]
size = Vector2(33, 46)
[node name="Wallnut" type="Node2D"]
script = ExtResource("1_mt5mt")
_maxHP = 1000
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_7mgid")
}
autoplay = "idle_full"
[node name="Sprite" type="Sprite2D" parent="."]
material = SubResource("ShaderMaterial_a0k73")
texture = ExtResource("1_571nl")
hframes = 3
vframes = 12
[node name="Behaviour" type="Node" parent="."]
script = ExtResource("3_tu4pm")
[node name="Hitbox" type="Area2D" parent="."]
collision_layer = 2
collision_mask = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2(3.5, 5)
shape = SubResource("RectangleShape2D_523ui")
[connection signal="OnHPChanged" from="." to="Behaviour" method="OnHPChanged"]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://cfnmspei3k4p7"]
[gd_scene load_steps=15 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="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/GameStyle.tres" id="1_xf6ra"]
@ -9,6 +9,7 @@
[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="Resource" uid="uid://c2e2yj7rgoswi" path="res://resources/plants/Wallnut.tres" id="7_x5txp"]
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_ps2iw"]
texture = ExtResource("2_eg3hk")
@ -18,6 +19,20 @@ texture_margin_right = 4.0
texture_margin_bottom = 4.0
axis_stretch_horizontal = 1
[sub_resource type="Animation" id="Animation_c8fnk"]
length = 0.001
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:color:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="Animation" id="Animation_ffxdv"]
resource_name = "flash"
length = 0.3
@ -34,20 +49,6 @@ tracks/0/keys = {
"times": PackedFloat32Array(0, 0.3)
}
[sub_resource type="Animation" id="Animation_c8fnk"]
length = 0.001
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:color:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_myv2j"]
_data = {
"RESET": SubResource("Animation_c8fnk"),
@ -96,6 +97,7 @@ _resource = ExtResource("5_6vih5")
[node name="ThirdSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")]
layout_mode = 2
_resource = ExtResource("7_x5txp")
[node name="FourthSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")]
layout_mode = 2

View file

@ -15,6 +15,9 @@ public partial class RuntimePlantData : Node2D, IEntity
public int Line {get; set;}
public PlantResource Resource;
[Signal]
public delegate void OnHPChangedEventHandler(int amount);
public override void _Ready()
{
_hp = _maxHP;
@ -24,6 +27,8 @@ public partial class RuntimePlantData : Node2D, IEntity
{
_hp += amount;
EmitSignal(SignalName.OnHPChanged,amount);
if (MaxHp > 0)
{
_hp = MaxHp;
@ -34,6 +39,8 @@ public partial class RuntimePlantData : Node2D, IEntity
{
_hp -= amount;
EmitSignal(SignalName.OnHPChanged,-amount);
if (_hp <= 0)
{
Kill();

View file

@ -0,0 +1,25 @@
using Godot;
using System;
public partial class WallnutBehaviour : Node
{
private AnimationPlayer _player;
private RuntimePlantData _data;
public override void _Ready()
{
_player = GetNode<AnimationPlayer>("../AnimationPlayer");
_data = GetParent<RuntimePlantData>();
}
public void OnHPChanged(int amount)
{
if(_data.Hp <= _data.MaxHp*2.0/3.0 && _data.Hp > _data.MaxHp/3.0)
{
_player.Play("idle_mid");
}
else if(_data.Hp < _data.MaxHp/3.0)
{
_player.Play("idle_low");
}
}
}