mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:15:45 +00:00
Enemy Control
This commit is contained in:
parent
85f0ae95d7
commit
6e8031da10
8 changed files with 184 additions and 17 deletions
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=33 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
[gd_scene load_steps=34 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
|
||||
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/Weapons/bullet.tscn" id="2_ov36d"]
|
||||
[ext_resource type="PackedScene" uid="uid://chkpk7erlqajg" path="res://Scenes/Selector.tscn" id="3_8wt6s"]
|
||||
[ext_resource type="Texture2D" uid="uid://b2v6j7lsyltrc" path="res://Sprites/Actors/CirnoWings.png" id="3_ul15q"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"]
|
||||
[ext_resource type="Texture2D" uid="uid://ddwhrlrgj6i00" path="res://Sprites/Actors/Cirno.png" id="5_hq878"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/Weapons/crosshair.tscn" id="6_l43rf"]
|
||||
|
|
@ -170,6 +171,7 @@ StrafeSpeed = 35
|
|||
CrosshairDistance = 35.0
|
||||
SelectorScene = ExtResource("3_8wt6s")
|
||||
GameOverScene = "res://Scenes/GameOver.tscn"
|
||||
WingsSprite = ExtResource("3_ul15q")
|
||||
Muzzle = NodePath("Muzzle")
|
||||
HitboxSprite = NodePath("Smoothing2D/HitboxSprite")
|
||||
metadata/_edit_group_ = true
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=65 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=67 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
|
||||
|
|
@ -57,9 +57,15 @@
|
|||
[ext_resource type="PackedScene" uid="uid://b0pb078xylxy" path="res://Scenes/Interactable/Valve.tscn" id="48_8usll"]
|
||||
[ext_resource type="PackedScene" uid="uid://cd36ch65jijg0" path="res://Scenes/Activable/BulletEmitter.tscn" id="49_64oga"]
|
||||
[ext_resource type="PackedScene" uid="uid://c5fiv1nioghfb" path="res://Scenes/Actors/Marisa.tscn" id="50_mp5ma"]
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/Events/ControlEnemyEvent.cs" id="52_5m7td"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_8wuck"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_hdht4"]
|
||||
script = ExtResource("52_5m7td")
|
||||
Target = NodePath("../../Enemy15")
|
||||
WaitForCompletion = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_068l7"]
|
||||
script = ExtResource("46_i0omr")
|
||||
TimelineName = "rumia_defeat"
|
||||
|
|
@ -396,7 +402,11 @@ position = Vector2(-1239.5, 10.9699)
|
|||
position = Vector2(-1432, 12)
|
||||
|
||||
[node name="Enemy7" parent="." instance=ExtResource("18_ixcwn")]
|
||||
position = Vector2(-1506, -167)
|
||||
position = Vector2(-1539, -148)
|
||||
|
||||
[node name="Enemy15" parent="." instance=ExtResource("18_ixcwn")]
|
||||
position = Vector2(-580.856, -351.801)
|
||||
Ai = 1
|
||||
|
||||
[node name="Elevator" parent="." instance=ExtResource("16_n40rt")]
|
||||
position = Vector2(-914, -611)
|
||||
|
|
@ -472,6 +482,14 @@ Target = NodePath("DialogueStarter")
|
|||
position = Vector2(16.0001, -22)
|
||||
_trackName = "computer2"
|
||||
|
||||
[node name="Computer3" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-612.57, -358.528)
|
||||
Target = NodePath("Node2D")
|
||||
|
||||
[node name="Node2D" type="Node2D" parent="Computer3"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = Array[Object]([SubResource("Resource_hdht4")])
|
||||
|
||||
[node name="Ammo1" parent="." instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-792, -396)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ public partial class Enemy : CharacterBody2D
|
|||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
[Export] public Node2D DefeatScript;
|
||||
|
||||
[Export] public AiState Ai { get; private set; }
|
||||
|
||||
protected float _currentHealth = 0f;
|
||||
|
||||
|
|
@ -34,6 +36,13 @@ public partial class Enemy : CharacterBody2D
|
|||
private NavigationAgent2D _navigationAgent;
|
||||
|
||||
protected bool _invulnerable = false;
|
||||
|
||||
#region Manual Movement
|
||||
|
||||
private Vector2 _movementDirection { get; set; } = Vector2.Zero;
|
||||
private Vector2 _facingDirection { get; set; } = Vector2.Right;
|
||||
|
||||
#endregion
|
||||
|
||||
private bool IsPlayerInRange => _playerDetection is { IsPlayerInRange: true };
|
||||
|
||||
|
|
@ -50,7 +59,7 @@ public partial class Enemy : CharacterBody2D
|
|||
private AlarmManager _alarmManager;
|
||||
public bool NavigationEnabled
|
||||
{
|
||||
get => _navigationEnabled && _navigationAgent != null;
|
||||
get => Ai is AiState.Enabled && _navigationEnabled && _navigationAgent != null;
|
||||
set => _navigationEnabled = value;
|
||||
}
|
||||
|
||||
|
|
@ -95,23 +104,55 @@ public partial class Enemy : CharacterBody2D
|
|||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
switch (_currentState)
|
||||
// switch (_currentState)
|
||||
// {
|
||||
// case EnemyState.Idle:
|
||||
//
|
||||
// break;
|
||||
// case EnemyState.Alert:
|
||||
// break;
|
||||
//
|
||||
// //case EnemyState.Shooting:
|
||||
// // Shoot
|
||||
// //break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (Ai is AiState.Controlled && !_isDestroyed)
|
||||
{
|
||||
case EnemyState.Idle:
|
||||
_movementDirection = GetInput();
|
||||
_facingDirection = _movementDirection;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetInput()
|
||||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
break;
|
||||
case EnemyState.Alert:
|
||||
break;
|
||||
|
||||
//case EnemyState.Shooting:
|
||||
// Shoot
|
||||
//break;
|
||||
default:
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (_isDestroyed) return;
|
||||
|
||||
switch (Ai)
|
||||
{
|
||||
case AiState.Enabled:
|
||||
HandleAi(delta);
|
||||
return;
|
||||
case AiState.Controlled:
|
||||
HandleManualControl(delta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
private void HandleManualControl(double delta)
|
||||
{
|
||||
Velocity = _movementDirection * (float)(WalkSpeed * delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private void HandleAi(double delta)
|
||||
{
|
||||
switch (_currentState)
|
||||
{
|
||||
|
|
@ -261,10 +302,23 @@ public partial class Enemy : CharacterBody2D
|
|||
return _isDestroyed;
|
||||
}
|
||||
|
||||
private enum EnemyState
|
||||
public void AssumeControl()
|
||||
{
|
||||
GD.Print("Assuming direct control");
|
||||
Ai = AiState.Controlled;
|
||||
}
|
||||
|
||||
protected enum EnemyState
|
||||
{
|
||||
Idle,
|
||||
Alert,
|
||||
Patrolling
|
||||
}
|
||||
|
||||
public enum AiState
|
||||
{
|
||||
Enabled,
|
||||
Disabled,
|
||||
Controlled
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
[Export]
|
||||
public string GameOverScene { get; set; }
|
||||
|
||||
[Export]
|
||||
public Texture2D WingsSprite { get; set; }
|
||||
|
||||
private Selector _selector;
|
||||
|
||||
|
|
@ -332,7 +335,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
if (!_canMove) return;
|
||||
|
||||
Velocity = _movementDirection * (float)( MovementSpeed/* * delta*/);
|
||||
Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
|
|
|||
50
Scripts/Resources/Events/ControlEnemyEvent.cs
Normal file
50
Scripts/Resources/Events/ControlEnemyEvent.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.Events;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ControlEnemyEvent : 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 Enemy enemy)
|
||||
{
|
||||
_gameManager.CameraTargetObject(enemy);
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
enemy.AssumeControl();
|
||||
if (_gameManager.Player.WingsSprite != null)
|
||||
{
|
||||
var sprite = new Sprite2D();
|
||||
sprite.SetTexture(_gameManager.Player.WingsSprite);
|
||||
//sprite.GlobalPosition = enemy.GlobalPosition;
|
||||
sprite.SetZIndex(1);
|
||||
enemy.CallDeferred("add_child", sprite);
|
||||
}
|
||||
}
|
||||
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta) { }
|
||||
|
||||
}
|
||||
BIN
Sprites/Actors/CirnoWings.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/Actors/CirnoWings.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Sprites/Actors/CirnoWings.png
(Stored with Git LFS)
Normal file
BIN
Sprites/Actors/CirnoWings.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/Actors/CirnoWings.png.import
Normal file
34
Sprites/Actors/CirnoWings.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b2v6j7lsyltrc"
|
||||
path="res://.godot/imported/CirnoWings.png-e2f6353e3a9fef485751400a507180c1.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/Actors/CirnoWings.png"
|
||||
dest_files=["res://.godot/imported/CirnoWings.png-e2f6353e3a9fef485751400a507180c1.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Loading…
Add table
Add a link
Reference in a new issue