Moved events inside the player

This commit is contained in:
Maddo 2025-02-28 18:50:42 +01:00
commit 7d9db8cfb6
7 changed files with 57 additions and 75 deletions

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=13 format=4 uid="uid://6a6tjohypmmb"] [gd_scene load_steps=12 format=4 uid="uid://6a6tjohypmmb"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"] [ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"]
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_v2pdx"] [ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_v2pdx"]
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_3pdf7"]
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_s1vkf"] [ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_s1vkf"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_06rc0"] [ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_06rc0"]
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_up0ka"] [ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_up0ka"]
@ -23,7 +22,6 @@ PlayerTemplate = ExtResource("2_v2pdx")
SpawnMarkers = Dictionary[int, NodePath]({ SpawnMarkers = Dictionary[int, NodePath]({
0: NodePath("PlayerStartPosition") 0: NodePath("PlayerStartPosition")
}) })
WeaponTemplate = ExtResource("3_3pdf7")
MapStartData = SubResource("Resource_6wo78") MapStartData = SubResource("Resource_6wo78")
[node name="Tilemaps" type="Node2D" parent="."] [node name="Tilemaps" type="Node2D" parent="."]

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=19 format=4 uid="uid://dqyfnby0t7gu1"] [gd_scene load_steps=18 format=4 uid="uid://dqyfnby0t7gu1"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_c3v4x"] [ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_c3v4x"]
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_w1v1g"] [ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_w1v1g"]
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_b3hxm"]
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_u1i8n"] [ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_u1i8n"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_6314l"] [ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_6314l"]
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_yyg8m"] [ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_yyg8m"]
@ -32,7 +31,6 @@ PlayerTemplate = ExtResource("2_w1v1g")
SpawnMarkers = Dictionary[int, NodePath]({ SpawnMarkers = Dictionary[int, NodePath]({
0: NodePath("PlayerStartPosition") 0: NodePath("PlayerStartPosition")
}) })
WeaponTemplate = ExtResource("3_b3hxm")
MapStartData = SubResource("Resource_6wo78") MapStartData = SubResource("Resource_6wo78")
[node name="Tilemaps" type="Node2D" parent="."] [node name="Tilemaps" type="Node2D" parent="."]

View file

@ -170,6 +170,7 @@ process_material = SubResource("ParticleProcessMaterial_hmqi5")
[node name="WeaponProvider" type="Node2D" parent="."] [node name="WeaponProvider" type="Node2D" parent="."]
script = ExtResource("17_qqcod") script = ExtResource("17_qqcod")
WeaponTemplate = ExtResource("9_wblq0")
[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"] [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_exited" from="InteractionController" to="." method="_on_interaction_controller_area_exited"]

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=121 format=4 uid="uid://bv451a8wgty4u"] [gd_scene load_steps=120 format=4 uid="uid://bv451a8wgty4u"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"] [ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"] [ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_2wlhc"]
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="3_kgs2x"] [ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="3_kgs2x"]
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="4_p1fl3"] [ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="4_p1fl3"]
[ext_resource type="PackedScene" uid="uid://rp4jhx0tuh24" path="res://Scenes/fragola.tscn" id="4_s7wq6"] [ext_resource type="PackedScene" uid="uid://rp4jhx0tuh24" path="res://Scenes/fragola.tscn" id="4_s7wq6"]
@ -89,7 +88,7 @@ script = ExtResource("7_l32kg")
EggIndex = 0 EggIndex = 0
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("6_khabp")]) StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("6_khabp")])
[sub_resource type="Shader" id="Shader_jn1m0"] [sub_resource type="Shader" id="Shader_ksslq"]
resource_local_to_scene = true resource_local_to_scene = true
code = "shader_type canvas_item; code = "shader_type canvas_item;
@ -113,9 +112,9 @@ void fragment() {
COLOR = color; COLOR = color;
}" }"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_usuub"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_jn1m0"]
resource_local_to_scene = true resource_local_to_scene = true
shader = SubResource("Shader_jn1m0") shader = SubResource("Shader_ksslq")
shader_parameter/blink_color = Color(0, 0, 0, 1) shader_parameter/blink_color = Color(0, 0, 0, 1)
shader_parameter/blink_intensity = 0.0 shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0 shader_parameter/teleport_progress = 0.0
@ -154,7 +153,7 @@ source = 5
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_81ys3"] [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_81ys3"]
input_name = "time" input_name = "time"
[sub_resource type="VisualShader" id="VisualShader_h0jm4"] [sub_resource type="VisualShader" id="VisualShader_usuub"]
resource_local_to_scene = true resource_local_to_scene = true
code = "shader_type canvas_item; code = "shader_type canvas_item;
render_mode blend_mix; render_mode blend_mix;
@ -236,11 +235,11 @@ nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
nodes/fragment/11/position = Vector2(1360, 480) 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) 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_oy44o"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_h0jm4"]
resource_local_to_scene = true resource_local_to_scene = true
shader = SubResource("VisualShader_h0jm4") shader = SubResource("VisualShader_usuub")
[sub_resource type="Shader" id="Shader_pniyx"] [sub_resource type="Shader" id="Shader_oy44o"]
resource_local_to_scene = true resource_local_to_scene = true
code = "shader_type canvas_item; code = "shader_type canvas_item;
@ -264,15 +263,15 @@ void fragment() {
COLOR = color; COLOR = color;
}" }"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ews6"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_pniyx"]
resource_local_to_scene = true resource_local_to_scene = true
shader = SubResource("Shader_pniyx") shader = SubResource("Shader_oy44o")
shader_parameter/blink_color = Color(0, 0, 0, 1) shader_parameter/blink_color = Color(0, 0, 0, 1)
shader_parameter/blink_intensity = 0.0 shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0 shader_parameter/teleport_progress = 0.0
shader_parameter/scanline_density = 50.0 shader_parameter/scanline_density = 50.0
[sub_resource type="VisualShader" id="VisualShader_pqe7f"] [sub_resource type="VisualShader" id="VisualShader_5ews6"]
resource_local_to_scene = true resource_local_to_scene = true
code = "shader_type canvas_item; code = "shader_type canvas_item;
render_mode blend_mix; render_mode blend_mix;
@ -354,9 +353,9 @@ nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
nodes/fragment/11/position = Vector2(1360, 480) 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) 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_xof4a"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_pqe7f"]
resource_local_to_scene = true resource_local_to_scene = true
shader = SubResource("VisualShader_pqe7f") shader = SubResource("VisualShader_5ews6")
[sub_resource type="Resource" id="Resource_hppa0"] [sub_resource type="Resource" id="Resource_hppa0"]
script = ExtResource("40_7qam0") script = ExtResource("40_7qam0")
@ -441,7 +440,7 @@ ActivationType = 0
Targets = Array[NodePath]([NodePath("../Rumia")]) Targets = Array[NodePath]([NodePath("../Rumia")])
WaitForCompletion = true WaitForCompletion = true
[sub_resource type="Resource" id="Resource_ati1v"] [sub_resource type="Resource" id="Resource_xof4a"]
resource_local_to_scene = true resource_local_to_scene = true
script = ExtResource("49_0si7g") script = ExtResource("49_0si7g")
Target = NodePath(".") Target = NodePath(".")
@ -476,7 +475,6 @@ SpawnMarkers = Dictionary[int, NodePath]({
2: NodePath("Factory Tilemaps/LevelProps/BossDebugTeleporterDestination"), 2: NodePath("Factory Tilemaps/LevelProps/BossDebugTeleporterDestination"),
255: NodePath("Factory Tilemaps/Debug Room/DebugRoomStartPosition") 255: NodePath("Factory Tilemaps/Debug Room/DebugRoomStartPosition")
}) })
WeaponTemplate = ExtResource("3_2wlhc")
StartingEquipment = [ExtResource("4_swym2"), ExtResource("5_nqier")] StartingEquipment = [ExtResource("4_swym2"), ExtResource("5_nqier")]
MapStartData = SubResource("Resource_6sau4") MapStartData = SubResource("Resource_6sau4")
metadata/_edit_lock_ = true metadata/_edit_lock_ = true
@ -617,13 +615,13 @@ position = Vector2(-779, -550)
[node name="HorizontalForceField" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")] [node name="HorizontalForceField" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
position = Vector2(-749, -496) position = Vector2(-749, -496)
TurnOffMaterial = SubResource("ShaderMaterial_usuub") TurnOffMaterial = SubResource("ShaderMaterial_jn1m0")
ActiveMaterial = SubResource("ShaderMaterial_oy44o") ActiveMaterial = SubResource("ShaderMaterial_h0jm4")
[node name="HorizontalForceField2" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")] [node name="HorizontalForceField2" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
position = Vector2(-735, -532) position = Vector2(-735, -532)
TurnOffMaterial = SubResource("ShaderMaterial_5ews6") TurnOffMaterial = SubResource("ShaderMaterial_pniyx")
ActiveMaterial = SubResource("ShaderMaterial_xof4a") ActiveMaterial = SubResource("ShaderMaterial_pqe7f")
[node name="ControllabeFairyGuard" parent="Factory Tilemaps/Debug Room" instance=ExtResource("73_ier4h")] [node name="ControllabeFairyGuard" parent="Factory Tilemaps/Debug Room" instance=ExtResource("73_ier4h")]
position = Vector2(-581, -346) position = Vector2(-581, -346)
@ -998,7 +996,7 @@ Events = Array[Object]([SubResource("Resource_068l7"), SubResource("Resource_l3n
[node name="BossBattleStartScript" parent="Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")] [node name="BossBattleStartScript" parent="Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
position = Vector2(-1487, -396) position = Vector2(-1487, -396)
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_ati1v")]) Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_xof4a")])
[node name="Enemy13" parent="Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")] [node name="Enemy13" parent="Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
position = Vector2(-1657, -788) position = Vector2(-1657, -788)

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using Cirno.Scripts.Resources;
using Godot; using Godot;
using Godot.Collections; using Godot.Collections;
@ -7,6 +8,7 @@ namespace Cirno.Scripts.Components.Actors;
public partial class PlayerWeaponProvider : Node2D public partial class PlayerWeaponProvider : Node2D
{ {
[Export] public PackedScene WeaponTemplate { get; private set; }
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>(); public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
public int CurrentWeaponIndex { get; set; } = 0; public int CurrentWeaponIndex { get; set; } = 0;
@ -21,6 +23,16 @@ public partial class PlayerWeaponProvider : Node2D
public override void _Ready() public override void _Ready()
{ {
_inventoryManager = this.GetInventoryManager(); _inventoryManager = this.GetInventoryManager();
_inventoryManager.WeaponEquip += this.EquipWeapon;
_inventoryManager.ItemAdded += (LootItem item, int amount) =>
{
if (item.Item == ItemTypes.Weapon)
{
SpawnPlayerWeapon(item);
}
};
} }
public void Init(PlayerMovement parent) public void Init(PlayerMovement parent)
@ -81,4 +93,23 @@ public partial class PlayerWeaponProvider : Node2D
EquippedWeapon.Shoot(); EquippedWeapon.Shoot();
} }
private void SpawnPlayerWeapon(LootItem startingItem)
{
if (WeaponTemplate == null)
{
GD.Print("Could not spawn weapon because template is null");
return;
}
var weapon = this.CreateSibling<Weapon>(WeaponTemplate);
weapon.WeaponData = startingItem.WeaponData;
this.AddWeapon(weapon);
if (this.EquippedWeapon == null)
{
this.EquipWeapon(weapon);
}
}
} }

View file

@ -28,8 +28,6 @@ public partial class GameManager : Node2D
//[Export] public Marker2D PlayerSpawnMarker { get; set; } //[Export] public Marker2D PlayerSpawnMarker { get; set; }
[Export] public PackedScene WeaponTemplate { get; private set; }
[Export] public Array<LootItem> StartingEquipment { get; private set; } = new(); [Export] public Array<LootItem> StartingEquipment { get; private set; } = new();
private InventoryManager _inventoryManager { get; set; } private InventoryManager _inventoryManager { get; set; }
@ -150,21 +148,6 @@ public partial class GameManager : Node2D
return; return;
} }
if (_inventoryManager is not null)
{
_inventoryManager.ItemAdded += (LootItem item, int amount) =>
{
if (item.Item == ItemTypes.Weapon)
{
SpawnPlayerWeapon(item);
}
};
_inventoryManager.WeaponEquip += _player.EquipWeapon;
_inventoryManager.ItemUsed += _player.UseItem;
}
// Wait before the player is fully initialized before spawning weapons on it // Wait before the player is fully initialized before spawning weapons on it
CallDeferred(MethodName.SpawnWeapons); CallDeferred(MethodName.SpawnWeapons);
} }
@ -252,25 +235,6 @@ public partial class GameManager : Node2D
} }
} }
private void SpawnPlayerWeapon(LootItem startingItem)
{
if (WeaponTemplate == null)
{
GD.Print("Could not spawn weapon because template is null");
return;
}
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
weapon.WeaponData = startingItem.WeaponData;
_player.AddWeapon(weapon);
if (_player.EquippedWeapon == null)
{
_player.EquipWeapon(weapon);
}
}
private void SpawnBulletsContainer() private void SpawnBulletsContainer()
{ {
_bulletsContainer = new Node2D(); _bulletsContainer = new Node2D();

View file

@ -163,6 +163,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
_selector.Visible = false; _selector.Visible = false;
} }
_inventoryManager.ItemUsed += this.UseItem;
_lastCheckPointPosition = GlobalPosition; _lastCheckPointPosition = GlobalPosition;
_ = UnTeleport(); _ = UnTeleport();
@ -260,16 +262,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
_weaponProvider.EquipWeapon(weapon); _weaponProvider.EquipWeapon(weapon);
} }
public void NextWeapon()
{
_weaponProvider.NextWeapon();
}
public void PreviousWeapon()
{
_weaponProvider.PreviousWeapon();
}
private void FindInteractable() private void FindInteractable()
{ {
var selected = _selector.SelectedInteractable; var selected = _selector.SelectedInteractable;
@ -394,12 +386,12 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
if (Input.IsActionJustPressed(_nextWeaponActionName)) if (Input.IsActionJustPressed(_nextWeaponActionName))
{ {
NextWeapon(); _weaponProvider.NextWeapon();
} }
if (Input.IsActionJustPressed(_previousWeaponActionName)) if (Input.IsActionJustPressed(_previousWeaponActionName))
{ {
PreviousWeapon(); _weaponProvider.PreviousWeapon();
} }
_crosshair.Position = CalculateCrosshairPosition(); _crosshair.Position = CalculateCrosshairPosition();