68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using Godot;
|
|
using System;
|
|
using Movementtests.interfaces;
|
|
using Movementtests.systems;
|
|
|
|
public partial class MainSceneTemplate : Node3D
|
|
{
|
|
private Marker3D? _playerRespawnMarker;
|
|
private AnimationPlayer? _animationPlayer;
|
|
private Node3D? _respawnabble;
|
|
|
|
private Area3D? _playerFellPlane;
|
|
private Area3D? _deathPlane;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_playerRespawnMarker = GetNode<Marker3D>("PlayerFellRespawn");
|
|
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
|
|
|
_playerFellPlane = GetNode<Area3D>("PlayerFellTP");
|
|
_deathPlane = GetNode<Area3D>("DeathPlane");
|
|
|
|
if (_playerRespawnMarker == null) throw new Exception("Player respawn marker is null");
|
|
if (_animationPlayer == null) throw new Exception("Animation player is null");
|
|
if (_playerFellPlane == null) throw new Exception("Player reset plane is null");
|
|
if (_deathPlane == null) throw new Exception("Enemy death plane is null");
|
|
|
|
_playerFellPlane.BodyEntered += StartResetPlayerAnimation;
|
|
_deathPlane.BodyEntered += KillEnemy;
|
|
|
|
}
|
|
|
|
public void ResetPlayerPosition()
|
|
{
|
|
if (_respawnabble == null || _playerRespawnMarker == null) throw new Exception("Player or respawn marker is null");
|
|
_respawnabble.GlobalPosition = _playerRespawnMarker.GlobalPosition;
|
|
}
|
|
|
|
public void StartResetPlayerAnimation(Node3D body)
|
|
{
|
|
if (body is WeaponSystem weapon)
|
|
{
|
|
if (_playerRespawnMarker == null) throw new Exception("Respawn marker is null");
|
|
weapon.GlobalPosition = _playerRespawnMarker.GlobalPosition;
|
|
weapon.SetLinearVelocity(Vector3.Down);
|
|
return;
|
|
}
|
|
_respawnabble = body as PlayerController;
|
|
if (_respawnabble == null || _animationPlayer == null) throw new Exception("Player or anim player is null");
|
|
_animationPlayer.Play("player_fell");
|
|
}
|
|
|
|
public void KillEnemy(Node3D body)
|
|
{
|
|
if (body is not IKillable killable)
|
|
{
|
|
body.QueueFree();
|
|
return;
|
|
}
|
|
if (killable is not IHealthable healthable)
|
|
{
|
|
body.QueueFree();
|
|
return;
|
|
}
|
|
killable.Kill(healthable);
|
|
}
|
|
}
|