mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 12:45:55 +00:00
Title screen background and music
This commit is contained in:
parent
b78692f150
commit
5b2b11545a
12 changed files with 326 additions and 123 deletions
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class EnemyNavigationMovement : MovementHandler
|
||||
public partial class EnemyNavigationMovement : MovementHandler
|
||||
{
|
||||
public override Vector2 FacingDirection
|
||||
{
|
||||
|
|
@ -19,21 +19,19 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
set => _parent.MovementDirection = value;
|
||||
}
|
||||
|
||||
[Export]
|
||||
private bool _navigationEnabled = false;
|
||||
[Export] private bool _navigationEnabled = false;
|
||||
|
||||
[Export] public float AlarmReactRange = 200f;
|
||||
|
||||
[Export] public float PlayerDisengageRange = 500f;
|
||||
|
||||
public bool NavigationEnabled
|
||||
{
|
||||
get => _actorAi is not null && _actorAi.Ai is AiState.Enabled && _navigationEnabled && _navigationAgent != null;
|
||||
set => _navigationEnabled = value;
|
||||
}
|
||||
{
|
||||
get => _actorAi is not null && _actorAi.Ai is AiState.Enabled && _navigationEnabled && _navigationAgent != null;
|
||||
set => _navigationEnabled = value;
|
||||
}
|
||||
|
||||
[Export]
|
||||
private PlayerDetection _playerDetection;
|
||||
[Export] private PlayerDetection _playerDetection;
|
||||
|
||||
private ActorAi _actorAi;
|
||||
private NavigationAgent2D _navigationAgent;
|
||||
|
|
@ -43,122 +41,117 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
|
||||
private bool IsPlayerInRange => _playerDetection is { IsPlayerInRange: true };
|
||||
|
||||
private bool IsPlayerInSight => _playerDetection is not null && _playerDetection.IsPlayerInSight(_parent.CollisionMask);
|
||||
private bool IsPlayerInSight =>
|
||||
_playerDetection is not null && _playerDetection.IsPlayerInSight(_parent.CollisionMask);
|
||||
|
||||
public override void Init(Actor parent)
|
||||
public override void Init(Actor parent)
|
||||
{
|
||||
base.Init(parent);
|
||||
|
||||
|
||||
MovementDirection = Vector2.Zero;
|
||||
FacingDirection = Vector2.Down;
|
||||
|
||||
_actorAi = parent.GetNode<ActorAi>("ActorAi");
|
||||
_navigationAgent = _parent.GetNodeOrNull<NavigationAgent2D>("NavigationAgent2D");
|
||||
_alarmManager = this.GetAlarmManager();
|
||||
_actorAi = parent.GetNode<ActorAi>("ActorAi");
|
||||
_navigationAgent = _parent.GetNodeOrNull<NavigationAgent2D>("NavigationAgent2D");
|
||||
_alarmManager = this.GetAlarmManager();
|
||||
|
||||
if (_alarmManager != null)
|
||||
{
|
||||
_alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
|
||||
}
|
||||
|
||||
{
|
||||
_alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void AlarmManagerOnAlarmEnabled(Vector2 location)
|
||||
{
|
||||
if (NavigationEnabled && location.DistanceTo(this.GlobalPosition) <= AlarmReactRange)
|
||||
{
|
||||
GD.Print($"Enemy {Name} alerted");
|
||||
_actorAi.State = EnemyState.Alert;
|
||||
_lastPlayerPosition = location;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (NavigationEnabled && location.DistanceTo(this.GlobalPosition) <= AlarmReactRange)
|
||||
{
|
||||
GD.Print($"Enemy {Name} alerted");
|
||||
_actorAi.State = EnemyState.Alert;
|
||||
_lastPlayerPosition = location;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Move(double delta)
|
||||
{
|
||||
if (_actorAi.Ai is not AiState.Enabled)
|
||||
if (_actorAi.Ai is not AiState.Enabled)
|
||||
return;
|
||||
|
||||
|
||||
switch (_actorAi.State)
|
||||
switch (_actorAi.State)
|
||||
{
|
||||
case EnemyState.Idle:
|
||||
if (_playerDetection != null && _playerDetection.IsPlayerInSight(_parent.CollisionMask))
|
||||
{
|
||||
_actorAi.State = EnemyState.Alert;
|
||||
{
|
||||
_actorAi.State = EnemyState.Alert;
|
||||
GD.Print("Switching to alert");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case EnemyState.Alert:
|
||||
|
||||
// Update last known player position if it's in range
|
||||
if (IsPlayerInRange)
|
||||
{
|
||||
_lastPlayerPosition = _playerDetection.CachedPlayer.GlobalPosition;
|
||||
}
|
||||
|
||||
if (NavigationEnabled)
|
||||
{
|
||||
if (_lastPlayerPosition.HasValue)
|
||||
{
|
||||
_navigationAgent.SetTargetPosition(_lastPlayerPosition.Value);
|
||||
}
|
||||
|
||||
var currentAgentPosition = _parent.GlobalPosition;
|
||||
|
||||
var nextPathPosition = _navigationAgent.GetNextPathPosition();
|
||||
|
||||
var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * _parent.MovementSpeed;
|
||||
|
||||
|
||||
// Navigation is over, can do other things like shooting
|
||||
if (_navigationAgent.IsNavigationFinished())
|
||||
{
|
||||
// Shoot player
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
|
||||
}
|
||||
|
||||
// TODO: If player totally left the max range it should stop shooting and go back to idle
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_navigationAgent.AvoidanceEnabled)
|
||||
{
|
||||
_navigationAgent.SetVelocity(newVelocity);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_on_navigation_agent_2d_velocity_computed(newVelocity);
|
||||
}
|
||||
// Update last known player position if it's in range
|
||||
if (IsPlayerInRange)
|
||||
{
|
||||
_lastPlayerPosition = _playerDetection.CachedPlayer.GlobalPosition;
|
||||
}
|
||||
|
||||
_parent.MoveAndSlide();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
if (NavigationEnabled)
|
||||
{
|
||||
if (_lastPlayerPosition.HasValue)
|
||||
{
|
||||
_navigationAgent.SetTargetPosition(_lastPlayerPosition.Value);
|
||||
}
|
||||
|
||||
var currentAgentPosition = _parent.GlobalPosition;
|
||||
|
||||
var nextPathPosition = _navigationAgent.GetNextPathPosition();
|
||||
|
||||
var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * _parent.MovementSpeed;
|
||||
|
||||
|
||||
// Navigation is over, can do other things like shooting
|
||||
if (_navigationAgent.IsNavigationFinished())
|
||||
{
|
||||
// Shoot player
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
}
|
||||
|
||||
// TODO: If player totally left the max range it should stop shooting and go back to idle
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_navigationAgent.AvoidanceEnabled)
|
||||
{
|
||||
_navigationAgent.SetVelocity(newVelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
_on_navigation_agent_2d_velocity_computed(newVelocity);
|
||||
}
|
||||
|
||||
_parent.MoveAndSlide();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void _on_navigation_agent_2d_velocity_computed(Vector2 safeVelocity)
|
||||
{
|
||||
_parent.Velocity = safeVelocity;
|
||||
if (_parent.Velocity.Length() > 0) {
|
||||
{
|
||||
_parent.Velocity = safeVelocity;
|
||||
if (_parent.Velocity.Length() > 0)
|
||||
{
|
||||
_parent.FacingDirection = _parent.Velocity.Normalized();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ public partial class MainMenu : Control
|
|||
{
|
||||
|
||||
[Export]
|
||||
public string GameScene { get; set; }
|
||||
public PackedScene GameScene { get; set; }
|
||||
|
||||
[Export]
|
||||
public string MainMenuScene { get; set; }
|
||||
|
|
@ -23,7 +23,7 @@ public partial class MainMenu : Control
|
|||
private void _on_start_button_pressed()
|
||||
{
|
||||
if (GameScene != null) {
|
||||
GetTree().ChangeSceneToFile(GameScene);
|
||||
GetTree().ChangeSceneToFile(GameScene.ResourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue