Threepeater added and line system removed

This commit is contained in:
Фёдор Веселов 2024-10-03 01:21:02 +05:00
commit b5d2466be4
16 changed files with 131 additions and 209 deletions

View file

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="1_amvh8"]
[ext_resource type="Texture2D" uid="uid://ot1n4nval86w" path="res://assets/sprites/plants/peashooter.tres" id="1_rnq6r"]
[ext_resource type="PackedScene" uid="uid://be1kgukmiu0hs" path="res://scenes/entities/plants/peashooter.tscn" id="1_rqf2x"]
[ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_rqf2x"]
[resource]
script = ExtResource("1_amvh8")

View file

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="PlantResource" load_steps=4 format=3 uid="uid://bnhwg57euiyf5"]
[ext_resource type="Texture2D" uid="uid://ot1n4nval86w" path="res://assets/sprites/plants/peashooter.tres" id="1_78bhe"]
[ext_resource type="PackedScene" uid="uid://eegv1qihfv2q" path="res://scenes/entities/plants/threepeater.tscn" id="2_uqpu0"]
[ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="3_3lugi"]
[resource]
script = ExtResource("3_3lugi")
Cost = 300
Scene = ExtResource("2_uqpu0")
ReloadTime = 5.0
StartReloadTime = 0.0
Preview = ExtResource("1_78bhe")
Layer = 1

View file

@ -23,7 +23,7 @@ metadata/_edit_lock_ = true
[node name="RuntimeLevelData" type="Node" parent="."]
script = ExtResource("1_i3bf5")
SunCount = 300
SunCount = 999999
[node name="Pools" parent="." instance=ExtResource("3_jv7x4")]

View file

@ -1,123 +1,71 @@
[gd_scene load_steps=19 format=3 uid="uid://be1kgukmiu0hs"]
[gd_scene load_steps=11 format=3 uid="uid://dy41q1kxray5t"]
[ext_resource type="Texture2D" uid="uid://cksryh4w5dbbx" path="res://assets/sprites/atlases/plants/peashooter.png" id="1_cmjrw"]
[ext_resource type="Script" path="res://scripts/components/plants/RuntimePlantData.cs" id="1_f4h5i"]
[ext_resource type="AnimationLibrary" uid="uid://bv1dl1g4dmbho" path="res://resources/animations/plants/peashooter.res" id="2_vs0tj"]
[ext_resource type="Script" path="res://scripts/components/plants/Shooter.cs" id="4_sbggp"]
[ext_resource type="PackedScene" uid="uid://b2hrv0aqbui7u" path="res://scenes/projectiles/pea.tscn" id="5_66an8"]
[ext_resource type="Script" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="6_0812i"]
[ext_resource type="Script" path="res://scripts/components/plants/behaviours/PeashooterBehaviour.cs" id="6_tdkoh"]
[ext_resource type="Script" path="res://scripts/components/plants/Eyesight.cs" id="7_fdkt2"]
[ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_pyk3o"]
[ext_resource type="Texture2D" uid="uid://cksryh4w5dbbx" path="res://assets/sprites/atlases/plants/peashooter.png" id="2_14qlx"]
[ext_resource type="AnimationLibrary" uid="uid://bv1dl1g4dmbho" path="res://resources/animations/plants/peashooter.res" id="3_8lrhp"]
[ext_resource type="Script" path="res://scripts/components/plants/Shooter.cs" id="3_a4ew1"]
[ext_resource type="PackedScene" uid="uid://b2hrv0aqbui7u" path="res://scenes/projectiles/pea.tscn" id="4_saxds"]
[ext_resource type="Script" path="res://scripts/components/plants/behaviours/PeashooterBehaviour.cs" id="5_7qiua"]
[ext_resource type="Script" path="res://scripts/components/plants/Eyesight.cs" id="7_2bki8"]
[ext_resource type="Script" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="8_nl4jc"]
[sub_resource type="Animation" id="Animation_pephc"]
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="RectangleShape2D" id="RectangleShape2D_r7xnh"]
size = Vector2(20, 44)
[sub_resource type="AnimationLibrary" id="AnimationLibrary_djmlc"]
_data = {
"RESET": SubResource("Animation_pephc")
}
[sub_resource type="SegmentShape2D" id="SegmentShape2D_8iovl"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_w1am6"]
animation = &"peashooter/idle"
[node name="Peashooter" instance=ExtResource("1_pyk3o")]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_irqfm"]
animation = &"peashooter/shoot"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_4oxpj"]
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_bjldt"]
advance_mode = 2
advance_condition = &"ready"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_srdpm"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_8qsie"]
states/Start/position = Vector2(192, 100)
states/peashooter_idle/node = SubResource("AnimationNodeAnimation_w1am6")
states/peashooter_idle/position = Vector2(457, 91)
states/peashooter_shoot/node = SubResource("AnimationNodeAnimation_irqfm")
states/peashooter_shoot/position = Vector2(660, 91)
transitions = ["Start", "peashooter_idle", SubResource("AnimationNodeStateMachineTransition_4oxpj"), "peashooter_idle", "peashooter_shoot", SubResource("AnimationNodeStateMachineTransition_bjldt"), "peashooter_shoot", "peashooter_idle", SubResource("AnimationNodeStateMachineTransition_srdpm")]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4stx8"]
size = Vector2(26, 48)
[sub_resource type="SegmentShape2D" id="SegmentShape2D_v570y"]
resource_local_to_scene = true
b = Vector2(5.865, 0)
[node name="Peashooter" type="Node2D"]
y_sort_enabled = true
script = ExtResource("1_f4h5i")
_maxHP = 100
[node name="Sprite" type="Sprite2D" parent="."]
use_parent_material = true
texture = ExtResource("1_cmjrw")
[node name="Sprite2D" parent="." index="0"]
texture = ExtResource("2_14qlx")
hframes = 2
vframes = 10
frame = 6
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="AnimationPlayer" parent="." index="1"]
libraries = {
"": SubResource("AnimationLibrary_djmlc"),
"peashooter": ExtResource("2_vs0tj")
"peashooter": ExtResource("3_8lrhp")
}
autoplay = "peashooter/idle"
[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource("AnimationNodeStateMachine_8qsie")
anim_player = NodePath("../AnimationPlayer")
parameters/conditions/ready = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2(0, 5)
shape = SubResource("RectangleShape2D_r7xnh")
[node name="Hitbox" type="Area2D" parent="."]
collision_layer = 2
collision_mask = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2(0, 4)
shape = SubResource("RectangleShape2D_4stx8")
[node name="Shooter" type="Node2D" parent="." node_paths=PackedStringArray("_timer")]
position = Vector2(17, -4)
script = ExtResource("4_sbggp")
_projectile = ExtResource("5_66an8")
[node name="Shooter" type="Marker2D" parent="." index="3" node_paths=PackedStringArray("_timer")]
position = Vector2(12, -4)
script = ExtResource("3_a4ew1")
_projectile = ExtResource("4_saxds")
_timer = NodePath("Timer")
[node name="Timer" type="Timer" parent="Shooter"]
[node name="Timer" type="Timer" parent="Shooter" index="0"]
wait_time = 1.5
one_shot = true
[node name="Behaviour" type="Node" parent="." node_paths=PackedStringArray("_animationTree", "_shootTimer", "_sight")]
script = ExtResource("6_tdkoh")
_animationTree = NodePath("../AnimationTree")
[node name="Behaviour" type="Node" parent="." index="4" node_paths=PackedStringArray("_player", "_shootTimer", "_sight")]
script = ExtResource("5_7qiua")
_player = NodePath("../AnimationPlayer")
_shootTimer = NodePath("../Shooter/Timer")
_sight = NodePath("../Eyesight")
_sight = NodePath("../Eysight")
_libName = "peashooter"
[node name="Eyesight" type="Area2D" parent="."]
collision_layer = 0
[node name="Eysight" type="Area2D" parent="." index="5"]
collision_layer = 4
collision_mask = 8
script = ExtResource("7_fdkt2")
script = ExtResource("7_2bki8")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Eyesight"]
shape = SubResource("SegmentShape2D_v570y")
script = ExtResource("6_0812i")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Eysight" index="0"]
shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
max_polyphony = 2
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Eysight" index="1"]
position = Vector2(0, 60)
shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc")
[connection signal="area_entered" from="Eyesight" to="Eyesight" method="OnAreaEntered"]
[connection signal="area_exited" from="Eyesight" to="Eyesight" method="OnAreaExited"]
[node name="CollisionShape2D3" type="CollisionShape2D" parent="Eysight" index="2"]
position = Vector2(0, -60)
shape = SubResource("SegmentShape2D_8iovl")
script = ExtResource("8_nl4jc")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." index="6"]

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=16 format=3 uid="uid://b7innrovtmf5u"]
[gd_scene load_steps=7 format=3 uid="uid://b7innrovtmf5u"]
[ext_resource type="PackedScene" uid="uid://be1kgukmiu0hs" path="res://scenes/entities/plants/peashooter.tscn" id="1_lp85e"]
[ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_lp85e"]
[ext_resource type="Texture2D" uid="uid://cu0651pvvkmvm" path="res://assets/sprites/atlases/plants/snow_pea.png" id="2_ytrm0"]
[ext_resource type="AudioStream" uid="uid://dp6k7xiptn68n" path="res://assets/audio/sfx/pop.mp3" id="3_4fpbe"]
[ext_resource type="AnimationLibrary" uid="uid://cke5wmmrvevbs" path="res://resources/animations/plants/snowpea.res" id="4_jvx5y"]
[ext_resource type="PackedScene" uid="uid://domeukw4ucmyr" path="res://scenes/projectiles/snowpea_projectile.tscn" id="5_bv86m"]
@ -11,7 +10,7 @@ length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite:frame")
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
@ -21,103 +20,26 @@ tracks/0/keys = {
"values": [0]
}
[sub_resource type="Animation" id="Animation_ip1gy"]
resource_name = "shoot_2"
length = 0.666675
step = 0.0833333
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.0833333, 0.166667, 0.25, 0.333333, 0.416667),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1),
"update": 1,
"values": [5, 7, 9, 11, 13, 15]
}
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Shooter")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.25),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"Shoot"
}]
}
tracks/2/type = "audio"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("AudioStreamPlayer2D")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"clips": [{
"end_offset": 0.0,
"start_offset": 0.0,
"stream": ExtResource("3_4fpbe")
}],
"times": PackedFloat32Array(0.25)
}
tracks/2/use_blend = true
[sub_resource type="AnimationLibrary" id="AnimationLibrary_djmlc"]
_data = {
"RESET": SubResource("Animation_pephc"),
"shoot_2": SubResource("Animation_ip1gy")
"RESET": SubResource("Animation_pephc")
}
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_7tu1y"]
animation = &"snowpea/idle"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_nhra5"]
animation = &"snowpea/shoot"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_iyvb5"]
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_63spy"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_yr2qp"]
advance_mode = 2
advance_condition = &"ready"
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_owox6"]
states/Start/position = Vector2(192, 100)
states/snowpea_idle/node = SubResource("AnimationNodeAnimation_7tu1y")
states/snowpea_idle/position = Vector2(425, 100)
states/snowpea_shoot/node = SubResource("AnimationNodeAnimation_nhra5")
states/snowpea_shoot/position = Vector2(644, 96)
transitions = ["Start", "snowpea_idle", SubResource("AnimationNodeStateMachineTransition_iyvb5"), "snowpea_shoot", "snowpea_idle", SubResource("AnimationNodeStateMachineTransition_63spy"), "snowpea_idle", "snowpea_shoot", SubResource("AnimationNodeStateMachineTransition_yr2qp")]
[sub_resource type="SegmentShape2D" id="SegmentShape2D_k2110"]
resource_local_to_scene = true
b = Vector2(5.865, 0)
[node name="Snowpea" instance=ExtResource("1_lp85e")]
[node name="Sprite" parent="." index="0"]
[node name="Sprite2D" parent="." index="0"]
texture = ExtResource("2_ytrm0")
frame = 0
[node name="AnimationPlayer" parent="." index="1"]
libraries = {
"": SubResource("AnimationLibrary_djmlc"),
"snowpea": ExtResource("4_jvx5y")
}
autoplay = "snowpea/idle"
[node name="AnimationTree" parent="." index="2"]
tree_root = SubResource("AnimationNodeStateMachine_owox6")
[node name="Shooter" parent="." index="4"]
[node name="Shooter" parent="." index="3"]
_projectile = ExtResource("5_bv86m")
[node name="CollisionShape2D" parent="Eyesight" index="0"]
shape = SubResource("SegmentShape2D_k2110")
[node name="Behaviour" parent="." index="4"]
_libName = "snowpea"

View file

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://eegv1qihfv2q"]
[ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_muntu"]
[ext_resource type="Script" path="res://scripts/components/plants/ThreepeaterShooter.cs" id="2_ieami"]
[node name="Threepeater" instance=ExtResource("1_muntu")]
[node name="Shooter" parent="." index="3"]
script = ExtResource("2_ieami")

View file

@ -19,6 +19,7 @@ public class Utility
#endregion
public const int EffectSlotCount = 3;
public const int LineCount = 5;
public const int TileWidth = 50;
public const int TileHeight = 60;
public const int LayersCount = 3;

View file

@ -7,7 +7,6 @@ public interface IEntity
{
public int Hp { get; }
public int MaxHp { get; }
public int Line { get; }
public void TakeDamage(int amount);
public void Heal(int amount);
}

View file

@ -26,7 +26,7 @@ public partial class LinearProjectile : Area2D, IProjectile
public void OnAreaEntered(Area2D area)
{
var entity = area.GetParent<IEntity>();
if (entity != null && entity.Line == _line)
if (entity != null)
{
entity.TakeDamage(_damage);
if (entity is IEffectHandler effectHandler && _impactEffect != null)

View file

@ -91,7 +91,6 @@ public partial class PlantField : Node2D
PoolContainer.Instance.Plants.AddChild(plant);
plant.GlobalPosition = (_plantSetter.GlobalPosition / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
plant.Resource = _resource;
plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight;
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant);

View file

@ -7,12 +7,14 @@ public partial class Eyesight : Area2D
{
private bool _enemyDetected;
public bool EnemyDetected => _enemyDetected;
private List<IEntity> _detectedEntities = new List<IEntity>();
private readonly List<IEntity> _detectedEntities = new List<IEntity>();
private RuntimePlantData _plantData;
public override void _Ready()
{
_plantData = GetParent<RuntimePlantData>();
AreaEntered += OnAreaEntered;
AreaExited += OnAreaExited;
}
public void OnAreaEntered(Area2D area)
@ -20,10 +22,7 @@ public partial class Eyesight : Area2D
var entity = area.GetParent<IEntity>();
if (entity != null)
{
if (_plantData.Line == entity.Line)
{
_detectedEntities.Add(entity);
}
_detectedEntities.Add(entity);
}
_enemyDetected = _detectedEntities.Count > 0;

View file

@ -6,10 +6,10 @@ namespace Newlon.Components.Plants;
// Shoot component of some plants
public partial class Shooter : Node2D
{
[Export] private PackedScene _projectile;
[Export] private Timer _timer;
[Export] protected PackedScene _projectile;
[Export] protected Timer _timer;
private RuntimePlantData _plantData;
protected RuntimePlantData _plantData;
public override void _Ready()
{
@ -22,13 +22,13 @@ public partial class Shooter : Node2D
if (_timer.TimeLeft > 0) return;
_timer.Start();
SpawnProjectile();
}
public virtual void SpawnProjectile()
{
var instance = _projectile.Instantiate<Node2D>();
PoolContainer.Instance.Projectiles.AddChild(instance);
instance.GlobalTransform = GlobalTransform;
if (instance is IProjectile projectile)
{
projectile.Line = _plantData.Line;
}
}
}

View file

@ -0,0 +1,26 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants;
public partial class ThreepeaterShooter : Shooter
{
public override void SpawnProjectile()
{
for(int i = -1; i <= 1; i++)
{
if ((int)GetParent<Node2D>().GlobalPosition.Y/Utility.TileHeight+i < 0 || (int)GetParent<Node2D>().GlobalPosition.Y/Utility.TileHeight+i > Utility.LineCount+1)
continue;
var instance = _projectile.Instantiate<Node2D>();
PoolContainer.Instance.Projectiles.AddChild(instance);
instance.GlobalTransform = GlobalTransform;
if(i != 0)
{
var tween = CreateTween().SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Sine);
tween.TweenProperty(instance,"position:y",instance.Position.Y+i*Utility.TileHeight,0.5);
}
}
}
}

View file

@ -4,14 +4,19 @@ namespace Newlon.Components.Plants.Behaviours;
public partial class PeashooterBehaviour : Node
{
[Export] private AnimationTree _animationTree;
[Export] private AnimationPlayer _player;
[Export] private Timer _shootTimer;
[Export] private Eyesight _sight;
[Export] private string _libName;
public override void _Process(double delta)
{
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
_animationTree.Set("parameters/conditions/ready", readyToShoot);
if(readyToShoot)
{
_player.Play(_libName+"/shoot");
_player.Queue(_libName+"/idle");
}
}
}