2019-04-27 12:40:09 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2019-04-27 20:19:35 +00:00
|
|
|
|
public class Player : Entity
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 15:57:01 +00:00
|
|
|
|
public int exp;
|
2019-04-27 20:19:35 +00:00
|
|
|
|
public int level;
|
2019-04-27 12:40:09 +00:00
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2019-04-27 15:28:38 +00:00
|
|
|
|
CheckForMovementInput();
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-27 15:28:38 +00:00
|
|
|
|
void CheckForMovementInput()
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 15:28:38 +00:00
|
|
|
|
bool hasMoved = false;
|
2019-04-27 15:24:26 +00:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.A))
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 20:19:35 +00:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.left)) {
|
2019-04-27 15:57:01 +00:00
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
hasMoved = true;
|
2019-04-28 12:11:21 +00:00
|
|
|
|
spriteRenderer.flipX = false;
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
2019-04-27 15:28:38 +00:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.D))
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 20:19:35 +00:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.right)) {
|
2019-04-27 15:28:38 +00:00
|
|
|
|
transform.Translate(Vector3.right);
|
2019-04-27 15:57:01 +00:00
|
|
|
|
hasMoved = true;
|
2019-04-28 12:11:21 +00:00
|
|
|
|
spriteRenderer.flipX = true;
|
2019-04-27 15:28:38 +00:00
|
|
|
|
}
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
2019-04-27 15:28:38 +00:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.W))
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 20:19:35 +00:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.up)) {
|
2019-04-27 15:28:38 +00:00
|
|
|
|
transform.Translate(Vector3.up);
|
2019-04-27 15:57:01 +00:00
|
|
|
|
hasMoved = true;
|
2019-04-27 15:28:38 +00:00
|
|
|
|
}
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
2019-04-27 15:28:38 +00:00
|
|
|
|
else if (Input.GetKeyDown(KeyCode.S))
|
2019-04-27 12:40:09 +00:00
|
|
|
|
{
|
2019-04-27 20:19:35 +00:00
|
|
|
|
if (map.CanMoveTo(MapPosition + Vector2Int.down)) {
|
2019-04-27 15:28:38 +00:00
|
|
|
|
transform.Translate(Vector3.down);
|
2019-04-27 15:57:01 +00:00
|
|
|
|
hasMoved = true;
|
2019-04-27 15:28:38 +00:00
|
|
|
|
}
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
2019-04-27 15:57:01 +00:00
|
|
|
|
if(hasMoved) {
|
2019-04-28 12:11:21 +00:00
|
|
|
|
//Check for pickuppable items
|
|
|
|
|
List<Entity> entities = turnHandler.GetEntityAtPosition(MapPosition);
|
|
|
|
|
foreach(Entity entity in entities) {
|
|
|
|
|
if(entity is Item) {
|
|
|
|
|
Item item = entity as Item;
|
|
|
|
|
item.OnPickup(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Turn happens!
|
2019-04-27 20:19:35 +00:00
|
|
|
|
turnHandler.OnTurn();
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|