diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 05a4350679dcf50cc645e4904cce2696d6762ba8..f7dd925ba12e9bf838e208df8071e46bba7104ab 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -16,33 +16,33 @@ namespace BigSock { public partial class PlayerController : Character { - public UtilBar utilBar; - + public UtilBar utilBar; + - public float collisionOffset = 0.05f; - public ContactFilter2D movementFilter; - - public GameObject attack; + public float collisionOffset = 0.05f; + public ContactFilter2D movementFilter; + + public GameObject attack; - Vector2 movementInput; - SpriteRenderer spriteRenderer; - //Rigidbody2D rb; - Animator animator; - List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); + Vector2 movementInput; + SpriteRenderer spriteRenderer; + //Rigidbody2D rb; + Animator animator; + List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); - bool canMove = true; + bool canMove = true; - protected IAttack _testAttack; - protected IAttack _testAttack2; - protected IAbility _dodge; + protected IAttack _testAttack; + protected IAttack _testAttack2; + protected IAbility _dodge; - public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now; + public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now; public PlayerController() - { + { TryPickUpItem(ItemService.SINGLETON.Get(201)); TryPickUpItem(ItemService.SINGLETON.Get(201)); TryPickUpItem(ItemService.SINGLETON.Get(202)); @@ -51,70 +51,70 @@ namespace BigSock { // Start is called before the first frame update protected override void Start() - { - base.Start(); + { + base.Start(); - + - utilBar?.WithXP((int)xp, (int)maxXp) - ?.WithHealth(Convert.ToInt32(HP), Convert.ToInt32(MaxHP)); + utilBar?.WithXP((int)xp, (int)maxXp) + ?.WithHealth(Convert.ToInt32(HP), Convert.ToInt32(MaxHP)); - animator = GetComponent<Animator>(); - spriteRenderer = GetComponent<SpriteRenderer>(); - + animator = GetComponent<Animator>(); + spriteRenderer = GetComponent<SpriteRenderer>(); + - //!! DEBUG: Add item to player at start to test if it works. - /* - TryPickUpItem(ItemService.SINGLETON.Get(201)); - TryPickUpItem(ItemService.SINGLETON.Get(201)); - TryPickUpItem(ItemService.SINGLETON.Get(202)); - TryPickUpItem(ItemService.SINGLETON.Get(101)); - */ - //var tmp = PrefabService.SINGLETON; - var tmp = SpriteService.SINGLETON; + //!! DEBUG: Add item to player at start to test if it works. + /* + TryPickUpItem(ItemService.SINGLETON.Get(201)); + TryPickUpItem(ItemService.SINGLETON.Get(201)); + TryPickUpItem(ItemService.SINGLETON.Get(202)); + TryPickUpItem(ItemService.SINGLETON.Get(101)); + */ + //var tmp = PrefabService.SINGLETON; + var tmp = SpriteService.SINGLETON; - _testAttack = (IAttack) AbilityService.SINGLETON.Get(101); - _testAttack2 = (IAttack) AbilityService.SINGLETON.Get(102); - _dodge = AbilityService.SINGLETON.Get(201); - } + _testAttack = (IAttack) AbilityService.SINGLETON.Get(101); + _testAttack2 = (IAttack) AbilityService.SINGLETON.Get(102); + _dodge = AbilityService.SINGLETON.Get(201); + } private void FixedUpdate() { - if(canMove) { - // If movement input is not 0, try to move - if(movementInput != Vector2.zero){ - - bool success = TryMove(movementInput); - - if(!success) { - success = TryMove(new Vector2(movementInput.x, 0)); - } - - if(!success) { - success = TryMove(new Vector2(0, movementInput.y)); - } - - animator.SetBool("isMoving", success); - } else { - animator.SetBool("isMoving", false); - } - - // Set direction of sprite to movement direction - var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); - var pos = transform.position; - var temp = (mouse - pos); - //temp.z = 0; - //direction = temp.normalized; - - if(temp.x < 0) { - spriteRenderer.flipX = true; - } else if (temp.x > 0) { - spriteRenderer.flipX = false; - } - } - + if(canMove) { + // If movement input is not 0, try to move + if(movementInput != Vector2.zero){ + + bool success = TryMove(movementInput); + + if(!success) { + success = TryMove(new Vector2(movementInput.x, 0)); + } + + if(!success) { + success = TryMove(new Vector2(0, movementInput.y)); + } + + animator.SetBool("isMoving", success); + } else { + animator.SetBool("isMoving", false); + } + + // Set direction of sprite to movement direction + var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); + var pos = transform.position; + var temp = (mouse - pos); + //temp.z = 0; + //direction = temp.normalized; + + if(temp.x < 0) { + spriteRenderer.flipX = true; + } else if (temp.x > 0) { + spriteRenderer.flipX = false; + } + } + } diff --git a/MrBigsock/Assets/Code/UI/ItemPref.cs b/MrBigsock/Assets/Code/UI/ItemPref.cs index b86c281903e3883e74a044aea8021886b8c59ec1..4887c581573e9a443add5f17314ce8d8eab3e6a1 100644 --- a/MrBigsock/Assets/Code/UI/ItemPref.cs +++ b/MrBigsock/Assets/Code/UI/ItemPref.cs @@ -7,52 +7,61 @@ using BigSock.Item; namespace BigSock.UI { - public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler - { - public IItem item; - public ItemSlot itemSlot; - private RectTransform rectTransform; - private CanvasGroup canvasGroup; - public Vector2? position; - - private void Awake() - { - rectTransform = GetComponent<RectTransform>(); - canvasGroup = GetComponent<CanvasGroup>(); - } - public void OnBeginDrag(PointerEventData eventData) - { - - position = transform.position; - canvasGroup.alpha = .6f; - canvasGroup.blocksRaycasts = false; - } - - public void OnDrag(PointerEventData eventData) - { - - rectTransform.anchoredPosition += eventData.delta; - - } - - public void OnEndDrag(PointerEventData eventData) - { - - if (position != null) - { - transform.position = position.Value; - } - - canvasGroup.alpha = 1f; - canvasGroup.blocksRaycasts = true; - } - - public void OnPointerDown(PointerEventData eventData) - { - - } - - - } + public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler + { + public IItem item; + public ItemSlot itemSlot; + private RectTransform rectTransform; + private CanvasGroup canvasGroup; + public Vector2? position; + + void Start() + { + // Change the sprite if the item has one. + var sprite = item?.Icon; + if(sprite != null) + GetComponent<UnityEngine.UI.Image>().overrideSprite = sprite; + } + + private void Awake() + { + rectTransform = GetComponent<RectTransform>(); + canvasGroup = GetComponent<CanvasGroup>(); + + } + public void OnBeginDrag(PointerEventData eventData) + { + + position = transform.position; + canvasGroup.alpha = .6f; + canvasGroup.blocksRaycasts = false; + } + + public void OnDrag(PointerEventData eventData) + { + + rectTransform.anchoredPosition += eventData.delta; + + } + + public void OnEndDrag(PointerEventData eventData) + { + + if (position != null) + { + transform.position = position.Value; + } + + canvasGroup.alpha = 1f; + canvasGroup.blocksRaycasts = true; + } + + public void OnPointerDown(PointerEventData eventData) + { + + } + + + } }