Items #3

Merged
dddushesss merged 61 commits from Alexei into main 2022-01-05 12:48:28 +00:00
9 changed files with 91 additions and 187 deletions
Showing only changes of commit 1b3d4fb8bd - Show all commits

View File

@ -5,15 +5,21 @@ public class PlayerView : MonoBehaviour
{ {
public Action OnStep; public Action OnStep;
public Action OnAttackEnd; public Action OnAttackEnd;
public Action OnAttack;
public GameObject charBarCanvas; public GameObject charBarCanvas;
public void Step() private void Step()
{ {
OnStep?.Invoke(); OnStep?.Invoke();
} }
public void AttackEnd() private void AttackEnd()
{ {
OnAttackEnd?.Invoke(); OnAttackEnd?.Invoke();
} }
private void Attack()
{
OnAttack?.Invoke();
}
} }

View File

@ -213792,6 +213792,13 @@ AnimationClip:
m_HasGenericRootTransform: 0 m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0 m_HasMotionFloatCurves: 0
m_Events: m_Events:
- time: 1.4333333
functionName: Attack
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 2 - time: 2
functionName: AttackEnd functionName: AttackEnd
data: data:

View File

@ -400,49 +400,49 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: BackToIdle - m_Name: BackToIdle
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: Build - m_Name: Build
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: TreeAttack - m_Name: TreeAttack
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: Move - m_Name: Move
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: SuperJump - m_Name: SuperJump
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: Frozen - m_Name: Frozen
m_Type: 9 m_Type: 9
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
- m_Name: isMoving - m_Name: isMoving
m_Type: 4 m_Type: 4
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 9100000}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer

View File

@ -17,4 +17,4 @@ MonoBehaviour:
type: 3} type: 3}
manaCost: 10 manaCost: 10
damage: 10 damage: 10
speed: 0.1 speed: 10

View File

@ -1,4 +1,5 @@
using HexFiled; using HexFiled;
using UnityEngine;
namespace Chars namespace Chars
{ {
@ -19,11 +20,12 @@ namespace Chars
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public void Attack(HexDirection direction) public void Attack(Vector2 direction)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public void Damage(float dmg) public void Damage(float dmg)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();

View File

@ -1,4 +1,6 @@
using HexFiled; 
using HexFiled;
using UnityEngine;
namespace Chars namespace Chars
{ {
@ -7,7 +9,7 @@ namespace Chars
public void Move(HexDirection direction); public void Move(HexDirection direction);
public void Spawn(); public void Spawn();
public void Death(); public void Death();
public void Attack(HexDirection direction); public void Attack(Vector2 direction);
public void Damage(float dmg); public void Damage(float dmg);
} }
} }

View File

@ -7,6 +7,7 @@ using HexFiled;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
namespace Chars namespace Chars
{ {
struct AnimLength struct AnimLength
@ -33,7 +34,7 @@ namespace Chars
private float _hp; private float _hp;
private float _mana; private float _mana;
private Weapon _weapon; private Weapon _weapon;
private List<HexCell> _cellsToEdge; private Vector3 _direction;
private CharBar _charBar; private CharBar _charBar;
public bool IsBusy => _isBusy; public bool IsBusy => _isBusy;
@ -49,7 +50,6 @@ namespace Chars
_hexGrid = hexGrid; _hexGrid = hexGrid;
_isBusy = false; _isBusy = false;
_color = playerData.color; _color = playerData.color;
} }
public void Move(HexDirection direction) public void Move(HexDirection direction)
@ -109,37 +109,34 @@ namespace Chars
} }
} }
private void Step()
{
_isBusy = false;
_cell.PaintHex(_color);
_animator.SetBool("isMoving", _isBusy);
}
private void AttackEnd()
{
_isBusy = false;
_mana -= _weapon.manaCost;
UpdateCanvas();
}
private void Attacking()
{
var ball = Object.Instantiate(_weapon.objectToThrow,
_instance.transform.position + new Vector3(0, 2), Quaternion.identity);
ball.transform.DOMove(new Vector3(_direction.x * 100,2, _direction.y * 100), _weapon.speed)
.SetEase(Ease.Linear)
.OnComplete(() => Object.Destroy(ball));
}
private void SetUpActions() private void SetUpActions()
{ {
_playerView.OnStep += () => _playerView.OnStep += Step;
{ _playerView.OnAttackEnd += AttackEnd;
_isBusy = false; _playerView.OnAttack += Attacking;
_cell.PaintHex(_color);
_animator.SetBool("isMoving", _isBusy);
};
_playerView.OnAttackEnd += () =>
{
_isBusy = false;
_mana -= _weapon.manaCost;
UpdateCanvas();
var ball = Object.Instantiate(_weapon.objectToThrow,
_instance.transform.position + new Vector3(0, 2), Quaternion.identity);
var sequence = DOTween.Sequence();
_cellsToEdge.ForEach(cell =>
{
sequence.Append(ball.transform
.DOMove(cell.transform.position + new Vector3(0, 2), _weapon.speed).SetEase(Ease.Linear));
});
sequence.onComplete += () => { Object.Destroy(ball); };
sequence.onUpdate += () =>
{
if (ball == null)
{
sequence.Kill();
}
};
};
} }
private void UpdateCanvas() private void UpdateCanvas()
@ -153,22 +150,17 @@ namespace Chars
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Attack(HexDirection direction)
public void Attack(Vector2 direction)
{ {
if (_cell.GetNeighbor(direction) && _mana - _weapon.manaCost >= 0) _isBusy = true;
{ _animator.SetTrigger("Attack");
_cellsToEdge = new List<HexCell>(); }
_isBusy = true;
_instance.transform.DOLookAt(_cell.GetNeighbor(direction).transform.position, 0.1f); public void Aim(Vector2 direction)
_animator.SetTrigger("Attack"); {
var curCell = _cell.GetNeighbor(direction); _playerView.transform.LookAt(new Vector3(direction.x,0, direction.y) + _playerView.transform.position);
_cellsToEdge.Add(curCell); _direction = direction;
while (curCell.GetNeighbor(direction) != null)
{
curCell = curCell.GetNeighbor(direction);
_cellsToEdge.Add(curCell);
}
}
} }
public void Damage(float dmg) public void Damage(float dmg)

View File

@ -14,6 +14,7 @@ namespace Chars
private FloatingJoystick _moveJoystick; private FloatingJoystick _moveJoystick;
private FloatingJoystick _attackJoystick; private FloatingJoystick _attackJoystick;
private Camera _camera; private Camera _camera;
private Vector2 _attackDircetion;
public PlayerControl(Player player, PlayerData playerData) public PlayerControl(Player player, PlayerData playerData)
@ -23,25 +24,27 @@ namespace Chars
_moveJoystick = joyView.MoveJoystick; _moveJoystick = joyView.MoveJoystick;
_attackJoystick = joyView.AttackJoystick; _attackJoystick = joyView.AttackJoystick;
_camera = Camera.main; _camera = Camera.main;
_attackJoystick.OnTouchUp += DoAttack;
} }
private void DoAttack()
{
_player.Attack(_attackDircetion);
}
public void FixedExecute() public void FixedExecute()
{ {
if (!_player.IsBusy && _moveJoystick.Direction != Vector2.zero) if (!_player.IsBusy && _moveJoystick.Direction != Vector2.zero)
{ {
_player.Move(VectorToDirection(_moveJoystick.Direction.normalized)); _player.Move(VectorToDirection(_moveJoystick.Direction.normalized));
} }
if (!_player.IsBusy && _attackJoystick.Direction != Vector2.zero) if (!_player.IsBusy && _attackJoystick.isPressed)
{ {
_player.Attack(VectorToDirection(_attackJoystick.Direction.normalized)); _attackDircetion = _attackJoystick.Direction.normalized;
_player.Aim(_attackDircetion);
} }
} }
private static HexDirection VectorToDirection(Vector2 dir) private static HexDirection VectorToDirection(Vector2 dir)
@ -78,7 +81,7 @@ namespace Chars
return HexDirection.W; return HexDirection.W;
} }
public void Execute() public void Execute()
{ {

File diff suppressed because one or more lines are too long