Подробные изменения: - Расширен основной gameplay loop: джетпак, новые платформы, оборудование, враги, прогрессия сложности и ограничения взаимодействий игрока. - Добавлены Bootstrap-сервисы запуска приложения, защита, фокус окна, управление курсором и настройки сервисов через DI. - Добавлена COM-интеграция с технической схемой Input System, обработкой кнопок/ADC, подсветкой и консольной диагностикой. - Добавлен отдельный debug/logging модуль с каналами, обработчиками консоли и файловым выводом. - Добавлены asmdef, link.xml, EditMode/PlayMode тесты и обновлена дорожная карта проекта. Проверки: - dotnet build .\\DanroJump.Runtime.csproj --no-restore - dotnet build .\\DanroJump.Tests.EditMode.csproj --no-restore - dotnet build .\\DanroJump.Tests.PlayMode.csproj --no-restore
110 lines
3.6 KiB
C#
110 lines
3.6 KiB
C#
using UnityEngine;
|
|
|
|
namespace DanroJump.Gameplay
|
|
{
|
|
/// <summary>
|
|
/// Простая пружина платформы, которая задает игроку фиксированный вертикальный отскок.
|
|
/// </summary>
|
|
public sealed class SpringEquipment : PlatformEquipmentBase, ILandingEquipment
|
|
{
|
|
[SerializeField] private float bounceVelocity = 22f;
|
|
[SerializeField] private float landingVelocityThreshold = 0.05f;
|
|
[SerializeField] private float landingTopTolerance = 0.2f;
|
|
[SerializeField] private float activationCooldown = 0.08f;
|
|
|
|
private Collider2D springCollider;
|
|
private float lastActivationTime = -1f;
|
|
|
|
/// <summary>
|
|
/// Вертикальная скорость, которую пружина задает игроку.
|
|
/// </summary>
|
|
public float BounceVelocity => bounceVelocity;
|
|
|
|
/// <summary>
|
|
/// Сбрасывает cooldown и кэширует trigger-коллайдер.
|
|
/// </summary>
|
|
public override void ResetEquipment()
|
|
{
|
|
lastActivationTime = -1f;
|
|
EnsureTriggerCollider();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Отталкивает игрока вверх только при падении сверху.
|
|
/// </summary>
|
|
public override void HandlePlayerContact(JumpPlayerController player, Component source)
|
|
{
|
|
TryActivate(player);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Пробует активировать пружину от контакта игрока.
|
|
/// </summary>
|
|
public bool TryActivate(JumpPlayerController player)
|
|
{
|
|
if (player == null || player.IgnoresEnvironmentInteractions)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!CanActivate(player))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
NotifyPlatformLandingHandlers(player);
|
|
player.BounceWithEnemyPassThrough(bounceVelocity);
|
|
lastActivationTime = Time.time;
|
|
return true;
|
|
}
|
|
|
|
public bool TryActivateFromLanding(JumpPlayerController player)
|
|
{
|
|
return TryActivate(player);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Проверяет направление движения, cooldown и высоту GroundCheck относительно верха пружины.
|
|
/// </summary>
|
|
private bool CanActivate(JumpPlayerController player)
|
|
{
|
|
if (Time.time - lastActivationTime < activationCooldown)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var isLanding = player.VerticalVelocity <= landingVelocityThreshold ||
|
|
player.PreviousVerticalVelocity <= landingVelocityThreshold;
|
|
if (!isLanding)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (springCollider == null)
|
|
{
|
|
EnsureTriggerCollider();
|
|
}
|
|
|
|
if (springCollider == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var landingLineY = springCollider.bounds.max.y - landingTopTolerance;
|
|
return player.GroundCheckY >= landingLineY || player.PreviousGroundCheckY >= landingLineY;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Гарантирует, что коллайдер пружины работает как trigger.
|
|
/// </summary>
|
|
private void EnsureTriggerCollider()
|
|
{
|
|
springCollider = GetComponent<Collider2D>();
|
|
if (springCollider != null)
|
|
{
|
|
springCollider.isTrigger = true;
|
|
}
|
|
}
|
|
}
|
|
}
|