mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 11:35:54 +00:00
Ability for enemies to shoot when controlled
This commit is contained in:
parent
dfd9abe91b
commit
2d6bcc5f00
10 changed files with 93 additions and 34 deletions
|
|
@ -41,7 +41,7 @@ radius = 85.0529
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_0tkae"]
|
||||
radius = 5.09902
|
||||
|
||||
[node name="FairyGuard" type="CharacterBody2D"]
|
||||
[node name="Thermathron" type="CharacterBody2D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 113
|
||||
script = ExtResource("1_8mmna")
|
||||
|
|
@ -52,9 +52,11 @@ Health = 6.0
|
|||
sprite_frames = ExtResource("2_7asxc")
|
||||
animation = &"down"
|
||||
|
||||
[node name="PosessionMovementProvider" type="Node2D" parent="." node_paths=PackedStringArray("PossessionSprite")]
|
||||
[node name="PosessionMovementProvider" type="Node2D" parent="." node_paths=PackedStringArray("PossessionSprite", "DamageReceiver", "EquippedWeapon")]
|
||||
script = ExtResource("3_81a26")
|
||||
PossessionSprite = NodePath("PossessionWings")
|
||||
DamageReceiver = NodePath("../DamageReceiver")
|
||||
EquippedWeapon = NodePath("../EnemyWeapon")
|
||||
|
||||
[node name="InputProvider" type="Node2D" parent="PosessionMovementProvider"]
|
||||
script = ExtResource("4_nr5hj")
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ script = ExtResource("7_l32kg")
|
|||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("6_khabp")])
|
||||
|
||||
[sub_resource type="Shader" id="Shader_ji7au"]
|
||||
[sub_resource type="Shader" id="Shader_gmqhp"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
|
|
@ -111,9 +111,9 @@ void fragment() {
|
|||
COLOR = color;
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_yot54"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ksslq"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("Shader_ji7au")
|
||||
shader = SubResource("Shader_gmqhp")
|
||||
shader_parameter/blink_color = Color(0, 0, 0, 1)
|
||||
shader_parameter/blink_intensity = 0.0
|
||||
shader_parameter/teleport_progress = 0.0
|
||||
|
|
@ -152,7 +152,7 @@ source = 5
|
|||
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_81ys3"]
|
||||
input_name = "time"
|
||||
|
||||
[sub_resource type="VisualShader" id="VisualShader_fasrq"]
|
||||
[sub_resource type="VisualShader" id="VisualShader_jn1m0"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
|
@ -234,11 +234,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_oplhi"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_usuub"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("VisualShader_fasrq")
|
||||
shader = SubResource("VisualShader_jn1m0")
|
||||
|
||||
[sub_resource type="Shader" id="Shader_74px5"]
|
||||
[sub_resource type="Shader" id="Shader_h0jm4"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
|
|
@ -262,15 +262,15 @@ void fragment() {
|
|||
COLOR = color;
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_gmqhp"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_oy44o"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("Shader_74px5")
|
||||
shader = SubResource("Shader_h0jm4")
|
||||
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_ksslq"]
|
||||
[sub_resource type="VisualShader" id="VisualShader_pniyx"]
|
||||
resource_local_to_scene = true
|
||||
code = "shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
|
@ -352,9 +352,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_jn1m0"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5ews6"]
|
||||
resource_local_to_scene = true
|
||||
shader = SubResource("VisualShader_ksslq")
|
||||
shader = SubResource("VisualShader_pniyx")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_hppa0"]
|
||||
script = ExtResource("40_7qam0")
|
||||
|
|
@ -439,7 +439,7 @@ ActivationType = 0
|
|||
Targets = Array[NodePath]([NodePath("../Rumia")])
|
||||
WaitForCompletion = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_usuub"]
|
||||
[sub_resource type="Resource" id="Resource_pqe7f"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("49_0si7g")
|
||||
Target = NodePath(".")
|
||||
|
|
@ -614,13 +614,13 @@ position = Vector2(-779, -550)
|
|||
|
||||
[node name="HorizontalForceField" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
|
||||
position = Vector2(-749, -496)
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_yot54")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_oplhi")
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_ksslq")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_usuub")
|
||||
|
||||
[node name="HorizontalForceField2" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
|
||||
position = Vector2(-735, -532)
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_gmqhp")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_jn1m0")
|
||||
TurnOffMaterial = SubResource("ShaderMaterial_oy44o")
|
||||
ActiveMaterial = SubResource("ShaderMaterial_5ews6")
|
||||
|
||||
[node name="ControllabeFairyGuard" parent="Factory Tilemaps/Debug Room" instance=ExtResource("73_ier4h")]
|
||||
position = Vector2(-581, -346)
|
||||
|
|
@ -713,7 +713,7 @@ IsEnabled = true
|
|||
Target = NodePath("../DebugTeleporter")
|
||||
|
||||
[node name="DebugTeleporter" parent="Factory Tilemaps/LevelProps" instance=ExtResource("30_8fdby")]
|
||||
position = Vector2(-1050, -562)
|
||||
position = Vector2(-1363, -210)
|
||||
Invisible = true
|
||||
|
||||
[node name="BlueKeycard2" parent="Factory Tilemaps/LevelProps" instance=ExtResource("35_rblsn")]
|
||||
|
|
@ -995,7 +995,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_usuub")])
|
||||
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_pqe7f")])
|
||||
|
||||
[node name="Enemy13" parent="Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
|
||||
position = Vector2(-1657, -788)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ public partial class ActorFreeMovement : MovementHandler
|
|||
set => _parent.MovementDirection = value;
|
||||
}
|
||||
|
||||
[Export] public string StrafeAction { get; private set; } = "strafe";
|
||||
|
||||
public bool IsDestroyed => _parent.IsDestroyed;
|
||||
|
||||
public override void Init(Actor parent)
|
||||
|
|
@ -39,7 +41,7 @@ public partial class ActorFreeMovement : MovementHandler
|
|||
MovementDirection = AggregateInputProviders().Normalized();
|
||||
|
||||
var aimingDirection = GetAimingDirection().Normalized();
|
||||
var isStrafing = GetStrafing();
|
||||
var isStrafing = GetActionPressed(StrafeAction);
|
||||
|
||||
if (!isStrafing && aimingDirection.Length() > 0.1f)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public partial class DamageReceiverActorModule : ActorModule
|
|||
[Export]
|
||||
public bool Invulnerable { get; private set; } = false;
|
||||
|
||||
[Export] protected BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
||||
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
||||
|
||||
public override void Init(Actor actor)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using Godot;
|
||||
|
||||
public partial class EnemyPossessionMovement : ActorFreeMovement
|
||||
|
|
@ -11,6 +12,14 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
[Export]
|
||||
public AnimatedSprite2D PossessionSprite { get; private set; }
|
||||
|
||||
[Export] public string ControlEndAction { get; private set; } = "pause";
|
||||
|
||||
[Export] public string ShootAction { get; private set; } = "shoot";
|
||||
|
||||
[Export] public DamageReceiverActorModule DamageReceiver { get; private set; }
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
public override void Init(Actor parent)
|
||||
{
|
||||
base.Init(parent);
|
||||
|
|
@ -19,11 +28,26 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
_parent.OnControlAssumed += AssumeControl;
|
||||
|
||||
_previousAiState = _actorAi.Ai;
|
||||
|
||||
parent.OnDeath += () =>
|
||||
{
|
||||
if (_actorAi.Ai is AiState.Controlled)
|
||||
{
|
||||
ResumeControl();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
if (_actorAi.Ai is AiState.Controlled && Input.IsActionJustPressed("pause"))
|
||||
if (_actorAi.Ai is not AiState.Controlled) return;
|
||||
|
||||
if (GetActionPressed(ShootAction))
|
||||
{
|
||||
Shoot();
|
||||
}
|
||||
|
||||
if (GetActionJustPressed(ControlEndAction))
|
||||
{
|
||||
if (GameManager.Instance.ToggleControlMode() is GameState.Playing)
|
||||
{
|
||||
|
|
@ -31,6 +55,17 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
|
||||
var direction = FacingDirection.Normalized();
|
||||
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
|
||||
EquippedWeapon.Shoot(BulletOwner.Player);
|
||||
}
|
||||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
|
|
@ -47,6 +82,8 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
_previousAiState = _actorAi.Ai;
|
||||
_actorAi.Ai = AiState.Controlled;
|
||||
|
||||
DamageReceiver.BulletGroup = BulletOwner.Player;
|
||||
|
||||
PossessionSprite?.Show();
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +94,8 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
GameManager.Instance.CameraTargetPlayer();
|
||||
GameManager.Instance.Player.RequestMovementDisable(false);
|
||||
|
||||
DamageReceiver.BulletGroup = BulletOwner.Enemy;
|
||||
|
||||
PossessionSprite?.Hide();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ public abstract partial class InputProvider : Node2D
|
|||
public abstract Vector2 GetMovementInput();
|
||||
public abstract Vector2 GetAimInput();
|
||||
|
||||
public abstract bool GetStrafing();
|
||||
public abstract bool GetActionJustPressed(string action);
|
||||
public abstract bool GetActionPressed(string action);
|
||||
}
|
||||
|
|
@ -11,9 +11,7 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
|
||||
public override Vector2 GetAimInput()
|
||||
{
|
||||
var rightStickInput = GetRightStickInput();
|
||||
|
||||
return GetRightStickInput();
|
||||
return GetRightStickInput();
|
||||
}
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
|
|
@ -24,8 +22,13 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
);
|
||||
}
|
||||
|
||||
public override bool GetStrafing()
|
||||
public override bool GetActionJustPressed(string action)
|
||||
{
|
||||
return Input.IsActionPressed("strafe");
|
||||
return Input.IsActionJustPressed(action);
|
||||
}
|
||||
|
||||
public override bool GetActionPressed(string action)
|
||||
{
|
||||
return Input.IsActionPressed(action);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,9 +36,14 @@ public abstract partial class MovementHandler : ActorModule
|
|||
return _inputProviders.Aggregate(Vector2.Zero, (current, inputProvider) => current + inputProvider.GetAimInput());
|
||||
}
|
||||
|
||||
public virtual bool GetStrafing()
|
||||
public virtual bool GetActionJustPressed(string action)
|
||||
{
|
||||
return _inputProviders.Aggregate(false, (current, inputProvider) => current && inputProvider.GetStrafing());
|
||||
return _inputProviders.Aggregate(false, (current, inputProvider) => current || inputProvider.GetActionJustPressed(action));
|
||||
}
|
||||
|
||||
public virtual bool GetActionPressed(string action)
|
||||
{
|
||||
return _inputProviders.Aggregate(false, (current, inputProvider) => current || inputProvider.GetActionPressed(action));
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/FSM/EnemyIdle.cs.uid
Normal file
1
Scripts/Components/FSM/EnemyIdle.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c5x8kd1ftr25s
|
||||
|
|
@ -67,7 +67,7 @@ public partial class Weapon : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
public void Shoot()
|
||||
public void Shoot(BulletOwner? ownerOverride = null)
|
||||
{
|
||||
// Waiting on reload or Rate of Fire cooldown?
|
||||
if (!_cooldownTimer.IsStopped())
|
||||
|
|
@ -106,8 +106,14 @@ public partial class Weapon : Node2D
|
|||
GD.PrintErr("Bullet is null, not shooting");
|
||||
return;
|
||||
};
|
||||
|
||||
var bulletData = WeaponData.MakeBullet(_muzzle.GlobalPosition);
|
||||
if (ownerOverride.HasValue)
|
||||
{
|
||||
bulletData.Owner = ownerOverride.Value;
|
||||
}
|
||||
|
||||
bullet.Initialize(WeaponData.MakeBullet(_muzzle.GlobalPosition), _gameManager);
|
||||
bullet.Initialize(bulletData, _gameManager);
|
||||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
bullet.SetDirection(spreadDirection);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue