1
Fork 0
slime-blood-and-pain/Assets/Scripts/Player.cs

62 lines
1.7 KiB
C#
Raw Normal View History

2019-04-27 14:40:09 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-04-27 22:19:35 +02:00
public class Player : Entity
2019-04-27 14:40:09 +02:00
{
2019-04-27 17:57:01 +02:00
public int exp;
2019-04-27 22:19:35 +02:00
public int level;
2019-04-27 14:40:09 +02:00
void Update()
{
2019-04-27 17:28:38 +02:00
CheckForMovementInput();
2019-04-27 14:40:09 +02:00
}
2019-04-27 17:28:38 +02:00
void CheckForMovementInput()
2019-04-27 14:40:09 +02:00
{
2019-04-27 17:28:38 +02:00
bool hasMoved = false;
2019-04-27 17:24:26 +02:00
if (Input.GetKeyDown(KeyCode.A))
2019-04-27 14:40:09 +02:00
{
2019-04-27 22:19:35 +02:00
if (map.CanMoveTo(MapPosition + Vector2Int.left)) {
2019-04-27 17:57:01 +02:00
transform.Translate(Vector3.left);
hasMoved = true;
2019-04-28 14:11:21 +02:00
spriteRenderer.flipX = false;
2019-04-27 17:57:01 +02:00
}
2019-04-27 14:40:09 +02:00
}
2019-04-27 17:28:38 +02:00
else if (Input.GetKeyDown(KeyCode.D))
2019-04-27 14:40:09 +02:00
{
2019-04-27 22:19:35 +02:00
if (map.CanMoveTo(MapPosition + Vector2Int.right)) {
2019-04-27 17:28:38 +02:00
transform.Translate(Vector3.right);
2019-04-27 17:57:01 +02:00
hasMoved = true;
2019-04-28 14:11:21 +02:00
spriteRenderer.flipX = true;
2019-04-27 17:28:38 +02:00
}
2019-04-27 14:40:09 +02:00
}
2019-04-27 17:28:38 +02:00
else if (Input.GetKeyDown(KeyCode.W))
2019-04-27 14:40:09 +02:00
{
2019-04-27 22:19:35 +02:00
if (map.CanMoveTo(MapPosition + Vector2Int.up)) {
2019-04-27 17:28:38 +02:00
transform.Translate(Vector3.up);
2019-04-27 17:57:01 +02:00
hasMoved = true;
2019-04-27 17:28:38 +02:00
}
2019-04-27 14:40:09 +02:00
}
2019-04-27 17:28:38 +02:00
else if (Input.GetKeyDown(KeyCode.S))
2019-04-27 14:40:09 +02:00
{
2019-04-27 22:19:35 +02:00
if (map.CanMoveTo(MapPosition + Vector2Int.down)) {
2019-04-27 17:28:38 +02:00
transform.Translate(Vector3.down);
2019-04-27 17:57:01 +02:00
hasMoved = true;
2019-04-27 17:28:38 +02:00
}
2019-04-27 14:40:09 +02:00
}
2019-04-27 17:57:01 +02:00
if(hasMoved) {
2019-04-28 14:11:21 +02: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 22:19:35 +02:00
turnHandler.OnTurn();
2019-04-27 17:57:01 +02:00
}
2019-04-27 14:40:09 +02:00
}
}