mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 18:05:53 +00:00
Enemies drop items with speed
This commit is contained in:
parent
632b5cfa6b
commit
95837b75fe
8 changed files with 84 additions and 25 deletions
15
Scenes/Items/PhysicsDropWrapper.tscn
Normal file
15
Scenes/Items/PhysicsDropWrapper.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://d3hds3dbosfcm"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://q806qngbukt8" path="res://Scripts/Interactables/ItemDrop.cs" id="1_lk7fn"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_k5j4v"]
|
||||
radius = 4.47214
|
||||
|
||||
[node name="PhysicsDropWrapper" type="RigidBody2D"]
|
||||
gravity_scale = 0.0
|
||||
lock_rotation = true
|
||||
linear_damp = 2.5
|
||||
script = ExtResource("1_lk7fn")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_k5j4v")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=82 format=4 uid="uid://6a6tjohypmmb"]
|
||||
[gd_scene load_steps=81 format=4 uid="uid://6a6tjohypmmb"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_2jsgm"]
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="9_mnq21"]
|
||||
[ext_resource type="Script" uid="uid://bdshph801ac2i" path="res://Scenes/CameraTarget.gd" id="10_4nd4a"]
|
||||
[ext_resource type="Script" uid="uid://cnkipcolyj61w" path="res://Scripts/AlarmManager.cs" id="11_7an4p"]
|
||||
[ext_resource type="Script" uid="uid://b5fesrd4lv8t1" path="res://Scripts/Resources/Events/EventResource.cs" id="14_5j8ks"]
|
||||
[ext_resource type="Script" uid="uid://bwox5lmgiijcs" path="res://Scripts/Resources/Events/ActivateEvent.cs" id="14_s23f3"]
|
||||
[ext_resource type="PackedScene" uid="uid://oi8svqsspcsj" path="res://Scenes/Interactable/ScriptableMovementSensor.tscn" id="16_ehuec"]
|
||||
[ext_resource type="PackedScene" uid="uid://crph24e6e0v0q" path="res://Scenes/Interactable/Control_Pad.tscn" id="16_s23f3"]
|
||||
|
|
@ -357,7 +356,7 @@ position = Vector2(196, 296)
|
|||
|
||||
[node name="MotionSensor" parent="Tilemaps/Actors" instance=ExtResource("16_ehuec")]
|
||||
position = Vector2(254, 296)
|
||||
Events = Array[ExtResource("14_5j8ks")]([SubResource("Resource_s23f3")])
|
||||
Events = [SubResource("Resource_s23f3")]
|
||||
|
||||
[node name="ControlPad" parent="Tilemaps/Actors" node_paths=PackedStringArray("Targets") instance=ExtResource("16_s23f3")]
|
||||
position = Vector2(205, 292)
|
||||
|
|
@ -378,11 +377,11 @@ position = Vector2(504, 468)
|
|||
|
||||
[node name="MovementSensorLonger" parent="Tilemaps/Actors" instance=ExtResource("20_fdi4d")]
|
||||
position = Vector2(226, 486)
|
||||
Events = Array[ExtResource("14_5j8ks")]([SubResource("Resource_qi6uc")])
|
||||
Events = [SubResource("Resource_qi6uc")]
|
||||
|
||||
[node name="MovementSensorLonger2" parent="Tilemaps/Actors" instance=ExtResource("20_fdi4d")]
|
||||
position = Vector2(391, 455)
|
||||
Events = Array[ExtResource("14_5j8ks")]([SubResource("Resource_mq37i")])
|
||||
Events = [SubResource("Resource_mq37i")]
|
||||
|
||||
[node name="WallEmitter" parent="Tilemaps/Actors" instance=ExtResource("21_qi6uc")]
|
||||
position = Vector2(264, 482)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=105 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
[gd_scene load_steps=106 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_c3v4x"]
|
||||
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="3_6314l"]
|
||||
|
|
@ -69,6 +69,7 @@
|
|||
[ext_resource type="Texture2D" uid="uid://cnayqn8jgb8jj" path="res://Models/carr/carr_rotating.png" id="56_5glx6"]
|
||||
[ext_resource type="PackedScene" uid="uid://iooa4gqy2uu2" path="res://Scenes/Items/Nuclear_Gun_Pickup.tscn" id="56_iv5wi"]
|
||||
[ext_resource type="PackedScene" uid="uid://ey71mxa5ocpn" path="res://Scenes/Items/Shield_Extend_Pickup.tscn" id="60_bjd5y"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3hds3dbosfcm" path="res://Scenes/Items/PhysicsDropWrapper.tscn" id="62_5glx6"]
|
||||
[ext_resource type="PackedScene" uid="uid://d360rx247qywn" path="res://3D/3DTest.tscn" id="68_8n581"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_6wo78"]
|
||||
|
|
@ -160,7 +161,7 @@ TimeModifiers = Array[ExtResource("43_8n581")]([])
|
|||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_bjd5y"]
|
||||
[sub_resource type="Resource" id="Resource_5glx6"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("39_83jc5")
|
||||
Patterns = Array[Object]([SubResource("Resource_kuo18")])
|
||||
|
|
@ -553,7 +554,7 @@ InvertSignal = true
|
|||
|
||||
[node name="FloorEmitter2" parent="Tilemaps/Actors" instance=ExtResource("44_b8ffn")]
|
||||
position = Vector2(601, 147)
|
||||
Script = SubResource("Resource_bjd5y")
|
||||
Script = SubResource("Resource_5glx6")
|
||||
InvertSignal = true
|
||||
|
||||
[node name="Camera" parent="Tilemaps/Actors" instance=ExtResource("48_r562v")]
|
||||
|
|
@ -632,6 +633,12 @@ position = Vector2(616, 88)
|
|||
[node name="ShieldExtendPickup" parent="Tilemaps" instance=ExtResource("60_bjd5y")]
|
||||
position = Vector2(664, 38)
|
||||
|
||||
[node name="PhysicsDropWrapper" parent="Tilemaps" instance=ExtResource("62_5glx6")]
|
||||
position = Vector2(616, 18)
|
||||
collision_layer = 4
|
||||
collision_mask = 33
|
||||
ItemToDrop = ExtResource("23_1ajuh")
|
||||
|
||||
[node name="CameraController" type="Camera2D" parent="."]
|
||||
process_mode = 1
|
||||
script = ExtResource("9_dj0ui")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Interactables;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
|
@ -9,8 +10,12 @@ public partial class EnemyDropsProvider : Node2D
|
|||
|
||||
[Export] public float DropRadius { get; private set; } = 8f;
|
||||
|
||||
[Export] public float DropSpeed { get; set; } = 40f;
|
||||
|
||||
[Export]
|
||||
public EnemyStorageModule StorageModule { get; private set; }
|
||||
public EnemyStorageModule StorageModule { get; private set; }
|
||||
|
||||
private readonly StringName _dropPhysicsWrapperScene = "uid://d3hds3dbosfcm";
|
||||
|
||||
public void DropLoot()
|
||||
{
|
||||
|
|
@ -29,23 +34,30 @@ public partial class EnemyDropsProvider : Node2D
|
|||
|
||||
private void DropItem(LootItem item)
|
||||
{
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(item.DropScenePath))
|
||||
{
|
||||
GD.Print($"Dropped item: {item.ItemName}");
|
||||
var scene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
var droppedItem = StorageModule.Root.CreateSibling<Node2D>(scene);
|
||||
var dropScene = GD.Load<PackedScene>(_dropPhysicsWrapperScene);
|
||||
var dropInstance = StorageModule.Root.CreateSibling<ItemDrop>(dropScene);
|
||||
dropInstance.ItemToDrop = item;
|
||||
dropInstance.StartingSpeed = DropSpeed;
|
||||
|
||||
// Generate random point within DropRadius
|
||||
float angle = _rng.RandfRange(0, Mathf.Tau); // Random angle (0 to 2π)
|
||||
float radius = _rng.RandfRange(0, DropRadius); // Random radius within range
|
||||
|
||||
// Convert polar to cartesian coordinates
|
||||
float xOffset = radius * Mathf.Cos(angle);
|
||||
float yOffset = radius * Mathf.Sin(angle);
|
||||
|
||||
Vector2 spawnPosition = StorageModule.Root.GlobalPosition + new Vector2(xOffset, yOffset);
|
||||
|
||||
droppedItem.GlobalPosition = spawnPosition;
|
||||
// var scene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
// var droppedItem = StorageModule.Root.CreateSibling<Node2D>(scene);
|
||||
//
|
||||
// // Generate random point within DropRadius
|
||||
// float angle = _rng.RandfRange(0, Mathf.Tau); // Random angle (0 to 2π)
|
||||
// float radius = _rng.RandfRange(0, DropRadius); // Random radius within range
|
||||
//
|
||||
// // Convert polar to cartesian coordinates
|
||||
// float xOffset = radius * Mathf.Cos(angle);
|
||||
// float yOffset = radius * Mathf.Sin(angle);
|
||||
//
|
||||
// Vector2 spawnPosition = StorageModule.Root.GlobalPosition + new Vector2(xOffset, yOffset);
|
||||
//
|
||||
// droppedItem.GlobalPosition = spawnPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
25
Scripts/Interactables/ItemDrop.cs
Normal file
25
Scripts/Interactables/ItemDrop.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class ItemDrop : RigidBody2D
|
||||
{
|
||||
[Export] public LootItem ItemToDrop { get; set; }
|
||||
|
||||
[Export] public float StartingSpeed { get; set; } = 40f;
|
||||
|
||||
private RandomNumberGenerator _rng = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
PackedScene dropScene = GD.Load<PackedScene>(ItemToDrop.DropScenePath);
|
||||
Node dropInstance = dropScene.Instantiate();
|
||||
AddChild(dropInstance);
|
||||
|
||||
float angle = _rng.RandfRange(0, Mathf.Tau); // 0 to 2π
|
||||
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)).Normalized();
|
||||
|
||||
// Apply impulse in that direction
|
||||
ApplyImpulse(direction * StartingSpeed);
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/ItemDrop.cs.uid
Normal file
1
Scripts/Interactables/ItemDrop.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://q806qngbukt8
|
||||
|
|
@ -6,7 +6,7 @@ namespace Cirno.Scripts.Interactables;
|
|||
|
||||
public partial class ItemPickup : Interactable
|
||||
{
|
||||
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
||||
[Export] public Array<LootItem> LootTable = [];
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1292,7 +1292,7 @@ texture = ExtResource("21_u4jco")
|
|||
0:0/animation_frame_3/duration = 1.0
|
||||
0:0/0 = 0
|
||||
0:0/0/physics_layer_2/linear_velocity = Vector2(40, 0)
|
||||
0:0/0/physics_layer_2/polygon_0/points = PackedVector2Array(-6, -6, 6, -6, 6, 6, -6, 6)
|
||||
0:0/0/physics_layer_2/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
0:0/0/custom_data_0 = Vector2(20, 0)
|
||||
0:1/animation_columns = 4
|
||||
0:1/animation_frame_0/duration = 1.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue