mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 05:45:54 +00:00
Possession handling
This commit is contained in:
parent
681510d75c
commit
31ffe6156e
9 changed files with 305 additions and 22 deletions
130
Scenes/Actors/Thermathron.tscn
Normal file
130
Scenes/Actors/Thermathron.tscn
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
[gd_scene load_steps=22 format=3 uid="uid://bdvj4cxnyr3w4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/Actor.cs" id="1_8mmna"]
|
||||||
|
[ext_resource type="SpriteFrames" uid="uid://ch2ll1on8im2p" path="res://Resources/Sprites/FairyGuard.tres" id="2_7asxc"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/EnemyPossessionMovement.cs" id="3_81a26"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/KeyboardInputProvider.cs" id="4_nr5hj"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/FourWayAnimationHandler.cs" id="5_wggo8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b2v6j7lsyltrc" path="res://Sprites/Actors/CirnoWings.png" id="5_wmgly"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorAi.cs" id="6_ck3ev"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/EnemyNavigationMovement.cs" id="7_ysmhb"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/ProximityPlayerDetection.cs" id="8_b0wmr"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="9_leabp"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cj63k0dmk7tl1" path="res://Scenes/Weapons/enemy_weapon_base.tscn" id="10_fduxx"]
|
||||||
|
[ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="11_2oavc"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/DamageReceiverActorModule.cs" id="12_fptwu"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/DeathAnimationHandler.cs" id="13_vhd3i"]
|
||||||
|
[ext_resource type="Resource" uid="uid://dk2rbf88a5irh" path="res://Resources/Bullets/Explosion_Harmless.tres" id="14_gs6c4"]
|
||||||
|
[ext_resource type="Script" path="res://Scripts/Components/Actors/ActorDefeatScriptHandler.cs" id="15_hkd4u"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_urwql"]
|
||||||
|
atlas = ExtResource("5_wmgly")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_du5wp"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_urwql")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"default",
|
||||||
|
"speed": 5.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_2b36v"]
|
||||||
|
radius = 5.0
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_sthwe"]
|
||||||
|
radius = 85.0529
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_0tkae"]
|
||||||
|
radius = 5.09902
|
||||||
|
|
||||||
|
[node name="FairyGuard" type="CharacterBody2D"]
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 113
|
||||||
|
script = ExtResource("1_8mmna")
|
||||||
|
MovementSpeed = 30.0
|
||||||
|
Health = 6.0
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
|
sprite_frames = ExtResource("2_7asxc")
|
||||||
|
animation = &"down"
|
||||||
|
|
||||||
|
[node name="PosessionMovementProvider" type="Node2D" parent="." node_paths=PackedStringArray("PossessionSprite")]
|
||||||
|
script = ExtResource("3_81a26")
|
||||||
|
PossessionSprite = NodePath("PossessionWings")
|
||||||
|
|
||||||
|
[node name="InputProvider" type="Node2D" parent="PosessionMovementProvider"]
|
||||||
|
script = ExtResource("4_nr5hj")
|
||||||
|
|
||||||
|
[node name="PossessionWings" type="AnimatedSprite2D" parent="PosessionMovementProvider"]
|
||||||
|
visible = false
|
||||||
|
sprite_frames = SubResource("SpriteFrames_du5wp")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("CircleShape2D_2b36v")
|
||||||
|
|
||||||
|
[node name="AnimationHandler" type="Node2D" parent="." node_paths=PackedStringArray("_animatedSprite")]
|
||||||
|
script = ExtResource("5_wggo8")
|
||||||
|
_animatedSprite = NodePath("../AnimatedSprite2D")
|
||||||
|
|
||||||
|
[node name="ActorAi" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("6_ck3ev")
|
||||||
|
Ai = 0
|
||||||
|
|
||||||
|
[node name="NavigationMovementProvider" type="Node2D" parent="." node_paths=PackedStringArray("EquippedWeapon", "_playerDetection")]
|
||||||
|
script = ExtResource("7_ysmhb")
|
||||||
|
_navigationEnabled = true
|
||||||
|
CollisionMask = 81
|
||||||
|
EquippedWeapon = NodePath("../EnemyWeapon")
|
||||||
|
_playerDetection = NodePath("../PlayerDetection")
|
||||||
|
|
||||||
|
[node name="PlayerDetection" type="Area2D" parent="."]
|
||||||
|
visible = false
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 2
|
||||||
|
script = ExtResource("8_b0wmr")
|
||||||
|
|
||||||
|
[node name="PlayerDetectionArea" type="CollisionShape2D" parent="PlayerDetection"]
|
||||||
|
shape = SubResource("CircleShape2D_sthwe")
|
||||||
|
|
||||||
|
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
|
||||||
|
target_desired_distance = 64.0
|
||||||
|
path_max_distance = 800.0
|
||||||
|
path_postprocessing = 1
|
||||||
|
avoidance_enabled = true
|
||||||
|
debug_path_custom_color = Color(1, 0, 0, 1)
|
||||||
|
|
||||||
|
[node name="HealthProvider" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("9_leabp")
|
||||||
|
ResourceName = "Health"
|
||||||
|
MaxResource = 6.0
|
||||||
|
|
||||||
|
[node name="EnemyWeapon" parent="." instance=ExtResource("10_fduxx")]
|
||||||
|
WeaponData = ExtResource("11_2oavc")
|
||||||
|
|
||||||
|
[node name="DamageReceiver" type="Node2D" parent="." node_paths=PackedStringArray("HealthProvider")]
|
||||||
|
script = ExtResource("12_fptwu")
|
||||||
|
HealthProvider = NodePath("../HealthProvider")
|
||||||
|
BulletGroup = 2
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="DamageReceiver"]
|
||||||
|
collision_layer = 16
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="DamageReceiver/Area2D"]
|
||||||
|
shape = SubResource("CircleShape2D_0tkae")
|
||||||
|
|
||||||
|
[node name="DeathAnimation" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("13_vhd3i")
|
||||||
|
ExplosionData = ExtResource("14_gs6c4")
|
||||||
|
|
||||||
|
[node name="DefeatScriptHandler" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("15_hkd4u")
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="PlayerDetection" to="PlayerDetection" method="_on_area_entered"]
|
||||||
|
[connection signal="area_exited" from="PlayerDetection" to="PlayerDetection" method="_on_area_exited"]
|
||||||
|
[connection signal="velocity_computed" from="NavigationAgent2D" to="NavigationMovementProvider" method="_on_navigation_agent_2d_velocity_computed"]
|
||||||
|
[connection signal="area_entered" from="DamageReceiver/Area2D" to="DamageReceiver" method="_on_damage_hitbox_area_entered"]
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -15,6 +15,9 @@ public partial class Actor : CharacterBody2D
|
||||||
[Export] public Node2D DefeatScript { get; set; }
|
[Export] public Node2D DefeatScript { get; set; }
|
||||||
|
|
||||||
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
|
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public AiState StartingAiState { get; private set; }
|
||||||
|
|
||||||
public Vector2 MovementDirection { get; set; }
|
public Vector2 MovementDirection { get; set; }
|
||||||
public Vector2 FacingDirection { get; set; }
|
public Vector2 FacingDirection { get; set; }
|
||||||
|
|
@ -25,6 +28,9 @@ public partial class Actor : CharacterBody2D
|
||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void OnDeathEventHandler();
|
public delegate void OnDeathEventHandler();
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void OnControlAssumedEventHandler();
|
||||||
|
|
||||||
public bool IsDestroyed { get; set; }
|
public bool IsDestroyed { get; set; }
|
||||||
|
|
||||||
|
|
@ -62,4 +68,9 @@ public partial class Actor : CharacterBody2D
|
||||||
EmitSignal(SignalName.OnDeath);
|
EmitSignal(SignalName.OnDeath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AssumeControl()
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.OnControlAssumed);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
using Cirno.Scripts.Components.Actors;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class ActorAi : Node2D
|
public partial class ActorAi : ActorModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public EnemyState State { get; set; } = EnemyState.Idle;
|
public EnemyState State { get; set; } = EnemyState.Idle;
|
||||||
|
|
@ -8,5 +9,22 @@ public partial class ActorAi : Node2D
|
||||||
[Export] // Temp until the special actor tha sets it
|
[Export] // Temp until the special actor tha sets it
|
||||||
public AiState Ai { get; set; } = AiState.Disabled;
|
public AiState Ai { get; set; } = AiState.Disabled;
|
||||||
|
|
||||||
|
protected Actor _actor;
|
||||||
|
|
||||||
|
public override void Init(Actor actor)
|
||||||
|
{
|
||||||
|
_actor = actor;
|
||||||
|
|
||||||
|
Ai = actor.StartingAiState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void PhysicsUpdate(double delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(double delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,12 +35,9 @@ public partial class ActorDefeatScriptHandler : ActorModule
|
||||||
{
|
{
|
||||||
if (DefeatScript is not IActivable target)
|
if (DefeatScript is not IActivable target)
|
||||||
{
|
{
|
||||||
GD.PrintErr($"Target {DefeatScript.Name} is not activable");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target?.Activate();
|
target?.Activate();
|
||||||
|
|
||||||
GD.Print($"{DefeatScript.Name} activated");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11
Scripts/Components/Actors/EnemyActor.cs
Normal file
11
Scripts/Components/Actors/EnemyActor.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Cirno.Scripts;
|
||||||
|
using Cirno.Scripts.Components.Actors;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
public partial class EnemyActor : Actor
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,11 +7,30 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
||||||
public bool IsDestroyed => _parent.IsDestroyed;
|
public bool IsDestroyed => _parent.IsDestroyed;
|
||||||
// State accessor
|
// State accessor
|
||||||
|
|
||||||
|
private AiState _previousAiState;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public AnimatedSprite2D PossessionSprite { get; private set; }
|
||||||
|
|
||||||
public override void Init(Actor parent)
|
public override void Init(Actor parent)
|
||||||
{
|
{
|
||||||
base.Init(parent);
|
base.Init(parent);
|
||||||
|
|
||||||
_actorAi = parent.GetNode<ActorAi>("ActorAi");
|
_actorAi = parent.GetNode<ActorAi>("ActorAi");
|
||||||
|
_parent.OnControlAssumed += AssumeControl;
|
||||||
|
|
||||||
|
_previousAiState = _actorAi.Ai;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(double deltaTime)
|
||||||
|
{
|
||||||
|
if (_actorAi.Ai is AiState.Controlled && Input.IsActionJustPressed("pause"))
|
||||||
|
{
|
||||||
|
if (GameManager.Instance.ToggleControlMode() is GameState.Playing)
|
||||||
|
{
|
||||||
|
ResumeControl();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PhysicsUpdate(double delta)
|
public override void PhysicsUpdate(double delta)
|
||||||
|
|
@ -21,4 +40,25 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
||||||
base.PhysicsUpdate(delta);
|
base.PhysicsUpdate(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AssumeControl()
|
||||||
|
{
|
||||||
|
GameManager.Instance.CameraTargetObject(_parent);
|
||||||
|
GameManager.Instance.Player.RequestMovementDisable(true);
|
||||||
|
|
||||||
|
_previousAiState = _actorAi.Ai;
|
||||||
|
_actorAi.Ai = AiState.Controlled;
|
||||||
|
|
||||||
|
PossessionSprite?.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResumeControl()
|
||||||
|
{
|
||||||
|
_actorAi.Ai = _previousAiState;
|
||||||
|
|
||||||
|
GameManager.Instance.CameraTargetPlayer();
|
||||||
|
GameManager.Instance.Player.RequestMovementDisable(false);
|
||||||
|
|
||||||
|
PossessionSprite?.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ public partial class GameManager : Node2D
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("pause"))
|
if (GameState is GameState.Playing && Input.IsActionJustPressed("pause"))
|
||||||
{
|
{
|
||||||
TogglePause();
|
TogglePause();
|
||||||
}
|
}
|
||||||
|
|
@ -288,6 +288,19 @@ public partial class GameManager : Node2D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameState ToggleControlMode() {
|
||||||
|
if (GameState is GameState.Playing)
|
||||||
|
{
|
||||||
|
ChangeState(GameState.Controlling);
|
||||||
|
}
|
||||||
|
else if (GameState is GameState.Controlling)
|
||||||
|
{
|
||||||
|
ChangeState(GameState.Playing);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GameState;
|
||||||
|
}
|
||||||
|
|
||||||
public void ChangeState(GameState state)
|
public void ChangeState(GameState state)
|
||||||
{
|
{
|
||||||
if (state == GameState) return;
|
if (state == GameState) return;
|
||||||
|
|
@ -302,5 +315,6 @@ public enum GameState
|
||||||
Menu,
|
Menu,
|
||||||
Paused,
|
Paused,
|
||||||
Playing,
|
Playing,
|
||||||
Dialogue
|
Dialogue,
|
||||||
|
Controlling
|
||||||
}
|
}
|
||||||
42
Scripts/Resources/Events/ControlActorEvent.cs
Normal file
42
Scripts/Resources/Events/ControlActorEvent.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Resources.Events;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class ControlActorEvent : EventResource
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public NodePath Target { get; set; }
|
||||||
|
|
||||||
|
private Node2D _parent;
|
||||||
|
|
||||||
|
private GameManager _gameManager;
|
||||||
|
private bool _isComplete = false;
|
||||||
|
public override bool IsComplete()
|
||||||
|
{
|
||||||
|
return _isComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init(Node2D parent)
|
||||||
|
{
|
||||||
|
_gameManager = parent.GetGameManager();
|
||||||
|
_parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Start(Node2D parentNode)
|
||||||
|
{
|
||||||
|
_isComplete = false;
|
||||||
|
|
||||||
|
if (_parent.GetNode<Node2D>(Target) is Actor enemy)
|
||||||
|
{
|
||||||
|
if (GameManager.Instance.ToggleControlMode() is GameState.Controlling)
|
||||||
|
{
|
||||||
|
enemy.AssumeControl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_isComplete = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateEvent(double delta) { }
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue