fixed weapon speed, setted hp bar
This commit is contained in:
parent
2b404fd7bf
commit
ae101ba773
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Data;
|
using Data;
|
||||||
using DefaultNamespace.Weapons;
|
using DefaultNamespace.Weapons;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
@ -14,6 +15,7 @@ namespace Chars
|
|||||||
public float Attack;
|
public float Attack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Player : IUnit
|
public class Player : IUnit
|
||||||
{
|
{
|
||||||
private HexCoordinates _spawnPos;
|
private HexCoordinates _spawnPos;
|
||||||
@ -31,7 +33,7 @@ namespace Chars
|
|||||||
private float _hp;
|
private float _hp;
|
||||||
private float _mana;
|
private float _mana;
|
||||||
private Weapon _weapon;
|
private Weapon _weapon;
|
||||||
private HexCell _cellEdge;
|
private List<HexCell> _cellsToEdge;
|
||||||
private CharBar _charBar;
|
private CharBar _charBar;
|
||||||
|
|
||||||
public bool IsBusy => _isBusy;
|
public bool IsBusy => _isBusy;
|
||||||
@ -47,6 +49,7 @@ 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)
|
||||||
@ -101,6 +104,13 @@ namespace Chars
|
|||||||
_charBar = _playerView.charBarCanvas.GetComponent<CharBar>();
|
_charBar = _playerView.charBarCanvas.GetComponent<CharBar>();
|
||||||
SetAnimLength();
|
SetAnimLength();
|
||||||
_mana = 100f;
|
_mana = 100f;
|
||||||
|
_hp = 100f;
|
||||||
|
SetUpActions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetUpActions()
|
||||||
|
{
|
||||||
_playerView.OnStep += () =>
|
_playerView.OnStep += () =>
|
||||||
{
|
{
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
@ -114,15 +124,28 @@ namespace Chars
|
|||||||
UpdateCanvas();
|
UpdateCanvas();
|
||||||
var ball = Object.Instantiate(_weapon.objectToThrow,
|
var ball = Object.Instantiate(_weapon.objectToThrow,
|
||||||
_instance.transform.position + new Vector3(0, 2), Quaternion.identity);
|
_instance.transform.position + new Vector3(0, 2), Quaternion.identity);
|
||||||
ball.transform.DOMove(_cellEdge.transform.position + new Vector3(0, 2), _weapon.speed, false)
|
var sequence = DOTween.Sequence();
|
||||||
.OnComplete(() => { Object.Destroy(ball); });
|
_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()
|
||||||
{
|
{
|
||||||
_charBar.ManaBar.fillAmount = _mana / 100;
|
_charBar.ManaBar.fillAmount = _mana / 100;
|
||||||
|
_charBar.HealthBar.fillAmount = _hp / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Death()
|
public void Death()
|
||||||
@ -132,22 +155,30 @@ namespace Chars
|
|||||||
|
|
||||||
public void Attack(HexDirection direction)
|
public void Attack(HexDirection direction)
|
||||||
{
|
{
|
||||||
if (_cell.GetNeighbor(direction))
|
if (_cell.GetNeighbor(direction) && _mana - _weapon.manaCost >= 0)
|
||||||
{
|
{
|
||||||
|
_cellsToEdge = new List<HexCell>();
|
||||||
_isBusy = true;
|
_isBusy = true;
|
||||||
_instance.transform.DOLookAt(_cell.GetNeighbor(direction).transform.position, 0.1f);
|
_instance.transform.DOLookAt(_cell.GetNeighbor(direction).transform.position, 0.1f);
|
||||||
_animator.SetTrigger("Attack");
|
_animator.SetTrigger("Attack");
|
||||||
_cellEdge = _cell.GetNeighbor(direction);
|
var curCell = _cell.GetNeighbor(direction);
|
||||||
while (_cellEdge.GetNeighbor(direction) != null)
|
_cellsToEdge.Add(curCell);
|
||||||
|
while (curCell.GetNeighbor(direction) != null)
|
||||||
{
|
{
|
||||||
_cellEdge = _cellEdge.GetNeighbor(direction);
|
curCell = curCell.GetNeighbor(direction);
|
||||||
|
_cellsToEdge.Add(curCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Damage(float dmg)
|
public void Damage(float dmg)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (_hp - dmg <= 0f)
|
||||||
|
{
|
||||||
|
Death();
|
||||||
|
}
|
||||||
|
|
||||||
|
_hp -= dmg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user