mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 09:13:47 +00:00
Moved weapon equipment logic to submodule
This commit is contained in:
parent
af46098aca
commit
11a22684d4
8 changed files with 128 additions and 59 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=25 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
[gd_scene load_steps=26 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqw1gfr3n6rl3" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
|
||||
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
[ext_resource type="Resource" uid="uid://b8apu0l5fm4k" path="res://Resources/Weapons/IcicleGun.tres" id="9_84o8f"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="9_wblq0"]
|
||||
[ext_resource type="Script" uid="uid://cqwvssstkrdmw" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="14_mfxfv"]
|
||||
[ext_resource type="Script" uid="uid://b4nixnxhj5qhw" path="res://Scripts/Components/Actors/PlayerWeaponProvider.cs" id="17_qqcod"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ai4rh"]
|
||||
size = Vector2(6, 6)
|
||||
|
|
@ -167,6 +168,9 @@ lifetime = 0.4
|
|||
one_shot = true
|
||||
process_material = SubResource("ParticleProcessMaterial_hmqi5")
|
||||
|
||||
[node name="WeaponProvider" type="Node2D" parent="."]
|
||||
script = ExtResource("17_qqcod")
|
||||
|
||||
[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"]
|
||||
[connection signal="area_exited" from="InteractionController" to="." method="_on_interaction_controller_area_exited"]
|
||||
[connection signal="area_entered" from="DamageHitBox" to="." method="_on_damage_hit_box_area_entered"]
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ script = ExtResource("7_l32kg")
|
|||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("6_khabp")])
|
||||
|
||||
[sub_resource type="Shader" id="Shader_gmqhp"]
|
||||
[sub_resource type="Shader" id="Shader_jn1m0"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
|
|
@ -113,9 +113,9 @@ void fragment() {
|
|||
COLOR = color;
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ksslq"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_usuub"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("Shader_gmqhp")
|
||||
shader = SubResource("Shader_jn1m0")
|
||||
shader_parameter/blink_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/blink_intensity = 0.0
|
||||
shader_parameter/teleport_progress = 0.0
|
||||
|
|
@ -154,7 +154,7 @@ source = 5
|
|||
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_81ys3"]
|
||||
input_name = "time"
|
||||
|
||||
[sub_resource type="VisualShader" id="VisualShader_jn1m0"]
|
||||
[sub_resource type="VisualShader" id="VisualShader_h0jm4"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
|
@ -236,11 +236,11 @@ nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
|
|||
nodes/fragment/11/position = Vector2(1360, 480)
|
||||
nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 3, 1, 4, 0, 6, 0, 7, 2, 7, 4, 8, 0, 5, 0, 8, 1, 8, 0, 0, 1, 9, 0, 10, 0, 4, 0, 11, 0, 10, 0, 11, 1, 11, 0, 5, 0)
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_usuub"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_oy44o"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("VisualShader_jn1m0")
|
||||
shader = SubResource("VisualShader_h0jm4")
|
||||
|
||||
[sub_resource type="Shader" id="Shader_h0jm4"]
|
||||
[sub_resource type="Shader" id="Shader_pniyx"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
|
|
@ -264,15 +264,15 @@ void fragment() {
|
|||
COLOR = color;
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_oy44o"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ews6"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("Shader_h0jm4")
|
||||
shader = SubResource("Shader_pniyx")
|
||||
shader_parameter/blink_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/blink_intensity = 0.0
|
||||
shader_parameter/teleport_progress = 0.0
|
||||
shader_parameter/scanline_density = 50.0
|
||||
|
||||
[sub_resource type="VisualShader" id="VisualShader_pniyx"]
|
||||
[sub_resource type="VisualShader" id="VisualShader_pqe7f"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
|
@ -354,9 +354,9 @@ nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
|
|||
nodes/fragment/11/position = Vector2(1360, 480)
|
||||
nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 3, 1, 4, 0, 6, 0, 7, 2, 7, 4, 8, 0, 5, 0, 8, 1, 8, 0, 0, 1, 9, 0, 10, 0, 4, 0, 11, 0, 10, 0, 11, 1, 11, 0, 5, 0)
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ews6"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xof4a"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("VisualShader_pniyx")
|
||||
shader = SubResource("VisualShader_pqe7f")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_hppa0"]
|
||||
script = ExtResource("40_7qam0")
|
||||
|
|
@ -441,7 +441,7 @@ ActivationType = 0
|
|||
Targets = Array[NodePath]([NodePath("../Rumia")])
|
||||
WaitForCompletion = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_pqe7f"]
|
||||
[sub_resource type="Resource" id="Resource_ati1v"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("49_0si7g")
|
||||
Target = NodePath(".")
|
||||
|
|
@ -477,7 +477,7 @@ SpawnMarkers = Dictionary[int, NodePath]({
|
|||
255: NodePath("Factory Tilemaps/Debug Room/DebugRoomStartPosition")
|
||||
})
|
||||
WeaponTemplate = ExtResource("3_2wlhc")
|
||||
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("4_swym2"), ExtResource("5_nqier")])
|
||||
StartingEquipment = [ExtResource("4_swym2"), ExtResource("5_nqier")]
|
||||
MapStartData = SubResource("Resource_6sau4")
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
|
|
@ -617,13 +617,13 @@ position = Vector2(-779, -550)
|
|||
|
||||
[node name="HorizontalForceField" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
|
||||
position = Vector2(-749, -496)
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_ksslq")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_usuub")
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_usuub")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_oy44o")
|
||||
|
||||
[node name="HorizontalForceField2" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
|
||||
position = Vector2(-735, -532)
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_oy44o")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_5ews6")
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_5ews6")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_xof4a")
|
||||
|
||||
[node name="ControllabeFairyGuard" parent="Factory Tilemaps/Debug Room" instance=ExtResource("73_ier4h")]
|
||||
position = Vector2(-581, -346)
|
||||
|
|
@ -998,7 +998,7 @@ Events = Array[Object]([SubResource("Resource_068l7"), SubResource("Resource_l3n
|
|||
|
||||
[node name="BossBattleStartScript" parent="Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-1487, -396)
|
||||
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_pqe7f")])
|
||||
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_ati1v")])
|
||||
|
||||
[node name="Enemy13" parent="Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
|
||||
position = Vector2(-1657, -788)
|
||||
|
|
@ -1183,10 +1183,10 @@ MusicData = ExtResource("82_ksslq")
|
|||
position = Vector2(-546, -525)
|
||||
|
||||
[node name="SpiderBomb2" parent="." instance=ExtResource("83_jn1m0")]
|
||||
position = Vector2(-509, -524)
|
||||
position = Vector2(-525, -524)
|
||||
|
||||
[node name="SpiderBomb3" parent="." instance=ExtResource("83_jn1m0")]
|
||||
position = Vector2(-544, -498)
|
||||
position = Vector2(-545, -503)
|
||||
|
||||
[node name="SpiderBomb4" parent="." instance=ExtResource("83_jn1m0")]
|
||||
position = Vector2(-512, -499)
|
||||
position = Vector2(-527, -504)
|
||||
|
|
|
|||
84
Scripts/Components/Actors/PlayerWeaponProvider.cs
Normal file
84
Scripts/Components/Actors/PlayerWeaponProvider.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class PlayerWeaponProvider : Node2D
|
||||
{
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
//private PlayerMovement _parent;
|
||||
|
||||
//public Vector2 FacingDirection
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
}
|
||||
|
||||
public void Init(PlayerMovement parent)
|
||||
{
|
||||
//_parent = parent;
|
||||
}
|
||||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
}
|
||||
|
||||
public void EquipWeapon(string itemKey)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemKey)) return;
|
||||
var weapon = EquippedWeapons.FirstOrDefault(x => x.WeaponData.ItemKey == itemKey);
|
||||
|
||||
if (weapon is null) return;
|
||||
|
||||
EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
{
|
||||
CurrentWeaponIndex += 1;
|
||||
if (CurrentWeaponIndex > EquippedWeapons.Count - 1)
|
||||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
if (CurrentWeaponIndex < 0)
|
||||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
public void Shoot(Vector2 direction)
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
|
||||
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/Actors/PlayerWeaponProvider.cs.uid
Normal file
1
Scripts/Components/Actors/PlayerWeaponProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b4nixnxhj5qhw
|
||||
1
Scripts/Components/FSM/Player/Active.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Active.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bl0o35xt8wxtg
|
||||
1
Scripts/Components/FSM/PlayerStateMachine.cs.uid
Normal file
1
Scripts/Components/FSM/PlayerStateMachine.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bw2hakslndaxm
|
||||
|
|
@ -165,7 +165,8 @@ public partial class GameManager : Node2D
|
|||
_inventoryManager.ItemUsed += _player.UseItem;
|
||||
}
|
||||
|
||||
SpawnWeapons();
|
||||
// Wait before the player is fully initialized before spawning weapons on it
|
||||
CallDeferred(MethodName.SpawnWeapons);
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
|
|
|
|||
|
|
@ -62,17 +62,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
[ExportCategory("Particles")]
|
||||
[Export] private PackedScene _deathParticles;
|
||||
[Export] private GpuParticles2D _shieldParticles;
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
private PlayerState _state;
|
||||
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
//private float _currentHealth = 0f;
|
||||
//private float _currentShield = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
|
@ -86,6 +78,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private bool _canMove = true;
|
||||
|
||||
public Weapon EquippedWeapon => _weaponProvider.EquippedWeapon;
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float maxHealth);
|
||||
|
||||
|
|
@ -121,6 +115,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
set => _lastCheckPointPosition = value;
|
||||
}
|
||||
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// CurrentHealth = MaxHealth;
|
||||
|
|
@ -128,6 +124,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_state = PlayerState.Active;
|
||||
|
||||
_weaponProvider = GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
||||
|
|
@ -212,17 +210,12 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
_weaponProvider.AddWeapon(weapon);
|
||||
}
|
||||
|
||||
public void EquipWeapon(string itemKey)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemKey)) return;
|
||||
var weapon = EquippedWeapons.FirstOrDefault(x => x.WeaponData.ItemKey == itemKey);
|
||||
|
||||
if (weapon is null) return;
|
||||
|
||||
EquipWeapon(weapon);
|
||||
_weaponProvider.EquipWeapon(itemKey);
|
||||
}
|
||||
|
||||
public void UseItem(LootItem item, int currentAmount)
|
||||
|
|
@ -264,30 +257,17 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
_weaponProvider.EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
{
|
||||
CurrentWeaponIndex += 1;
|
||||
if (CurrentWeaponIndex > EquippedWeapons.Count - 1)
|
||||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
_weaponProvider.NextWeapon();
|
||||
}
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
if (CurrentWeaponIndex < 0)
|
||||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
_weaponProvider.PreviousWeapon();
|
||||
}
|
||||
|
||||
private void FindInteractable()
|
||||
|
|
@ -312,11 +292,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private void HandleShoot()
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
if (!Input.IsActionPressed(_shootActionName)) return;
|
||||
|
||||
EquippedWeapon.ShootDirection = this._facingDirection;
|
||||
EquippedWeapon.Shoot();
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
}
|
||||
|
||||
private void SetAnimation()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue