Platformer example started
This commit is contained in:
1 parent
efcfaae647
commit
9f026b76d6
325 files changed
+23540
-270
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using DG.Tweening.Core;
|
||||
using DG.Tweening.Plugins.Options;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
{
|
||||
public class Bee : Entity
|
||||
{
|
||||
[SerializeField] private List<Transform> partolPoints;
|
||||
private bool _onPatrol;
|
||||
private bool _onPatrolMoveDamnit;
|
||||
private int _currentPartolPoint;
|
||||
|
||||
private Transform _currentTarget;
|
||||
private TweenerCore<Vector3, Vector3, VectorOptions> _patrolAction;
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
if (_onPatrol && !_onPatrolMoveDamnit)
|
||||
{
|
||||
_onPatrolMoveDamnit = true;
|
||||
_patrolAction = transform.DOMove(partolPoints[_currentPartolPoint].position, 3f);
|
||||
_patrolAction.onComplete += OnControlPointReached;
|
||||
}
|
||||
else
|
||||
{
|
||||
var direction = _currentTarget.position - transform.position;
|
||||
direction.Normalize();
|
||||
var targetPosition = _currentTarget.position + direction * -2f;
|
||||
|
||||
UnityEngine.Debug.DrawLine(transform.position, targetPosition, Color.red);
|
||||
|
||||
transform.DOMove(_currentTarget.position, 2f).onComplete += OnControlPointReached;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnControlPointReached()
|
||||
{
|
||||
if (++_currentPartolPoint >= partolPoints.Count) _currentPartolPoint = 0;
|
||||
_onPatrolMoveDamnit = false;
|
||||
}
|
||||
|
||||
public void GotTarget(Transform other)
|
||||
{
|
||||
_onPatrol = false;
|
||||
_currentTarget = other;
|
||||
_patrolAction?.Complete();
|
||||
}
|
||||
|
||||
public void LostTarget()
|
||||
{
|
||||
_onPatrol = true;
|
||||
_currentTarget = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2abf74ae7a894c5abc850fe852fdf4e7
|
||||
timeCreated: 1771433363
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
{
|
||||
public class BeeRadar : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Bee bee;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) => bee.GotTarget(other.transform);
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other) => bee.LostTarget();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 582294c360404f6d952d9e28bde1fbea
|
||||
timeCreated: 1771434696
|
||||
@@ -0,0 +1,32 @@
|
||||
using Code.Infrastructure.Configs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
{
|
||||
public class Snail : Entity
|
||||
{
|
||||
[SerializeField] private Vector2 groundLeft;
|
||||
[SerializeField] private Vector2 groundRight;
|
||||
[SerializeField] private bool _directionRight;
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
CheckupDirection();
|
||||
rigidbody2D.linearVelocityX = _directionRight ? 0.5f : -0.5f;
|
||||
}
|
||||
protected override void HandleFlipX() => spriteRenderer.flipX = rigidbody2D.linearVelocity.x > -0.01f;
|
||||
|
||||
private void CheckupDirection()
|
||||
{
|
||||
if (_directionRight)
|
||||
{
|
||||
if (!Physics2D.OverlapPoint((Vector2)transform.position + groundRight,
|
||||
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
|
||||
_directionRight = false;
|
||||
}
|
||||
else if (!Physics2D.OverlapPoint((Vector2)transform.position + groundLeft,
|
||||
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
|
||||
_directionRight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bb753139de944f69f426cbc1ec9ec92
|
||||
timeCreated: 1771430576
|
||||
Reference in new issue
Block a user