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

58 lines
1.3 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
{
private int exp, level, hp, maxhp;
2019-04-27 12:40:09 +00:00
public int startingHp;
public Map map;
//TODO: Aggiungi gli oggetti in inventario
// Start is called before the first frame update
void Start()
{
hp = startingHp;
}
// Update is called once per frame
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 15:28:38 +00:00
if (CanMoveTo(Vector2Int.left)) {
transform.Translate(Vector3.left);}
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 15:28:38 +00:00
if (CanMoveTo(Vector2Int.right)) {
transform.Translate(Vector3.right);
}
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 15:28:38 +00:00
if (CanMoveTo(Vector2Int.up)) {
transform.Translate(Vector3.up);
}
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 15:28:38 +00:00
if (CanMoveTo(Vector2Int.down)) {
transform.Translate(Vector3.down);
}
2019-04-27 12:40:09 +00:00
}
2019-04-27 15:28:38 +00:00
2019-04-27 12:40:09 +00:00
}
2019-04-27 15:22:02 +00:00
bool CanMoveTo(Vector2Int direction)
2019-04-27 12:40:09 +00:00
{
2019-04-27 15:24:26 +00:00
return map.GetTile(direction).walkable;
2019-04-27 12:40:09 +00:00
}
}