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

68 lines
1.7 KiB
C#
Raw Normal View History

2019-04-27 12:40:09 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
2019-04-27 15:57:01 +00:00
public int exp;
public int level;
public int hpMax;
[AfterStartAttribute]
public int hp;
private Map map;
private GameObject gameController;
2019-04-27 12:40:09 +00:00
void Start()
{
2019-04-27 15:57:01 +00:00
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
gameController = GameObject.FindGameObjectWithTag("GameController");
hp = hpMax;
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 17:19:46 +00:00
Vector2Int posizione = new Vector2Int();
posizione.x = (int)transform.position.x+1;
posizione.y = (int)transform.position.y+1;
2019-04-27 15:24:26 +00:00
if (Input.GetKeyDown(KeyCode.A))
2019-04-27 12:40:09 +00:00
{
2019-04-27 17:19:46 +00:00
if (map.CanMoveTo(posizione + Vector2Int.left)) {
2019-04-27 15:57:01 +00:00
transform.Translate(Vector3.left);
hasMoved = true;
}
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 17:19:46 +00:00
if (map.CanMoveTo(posizione + 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-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 17:19:46 +00:00
if (map.CanMoveTo(posizione + 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 17:19:46 +00:00
if (map.CanMoveTo(posizione + 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) {
gameController.BroadcastMessage("Turn");
}
2019-04-27 12:40:09 +00:00
}
}