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:18:44 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
playerMovement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void playerMovement()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKey(KeyCode.A))
|
|
|
|
|
{
|
2019-04-27 15:18:44 +00:00
|
|
|
|
if (is_valid_movement("left")) transform.Translate(Vector3.left);
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.D))
|
|
|
|
|
{
|
2019-04-27 15:18:44 +00:00
|
|
|
|
if (is_valid_movement("right")) transform.Translate(Vector3.right);
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.W))
|
|
|
|
|
{
|
2019-04-27 15:18:44 +00:00
|
|
|
|
if (is_valid_movement("up")) transform.Translate(Vector3.up);
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.S))
|
|
|
|
|
{
|
2019-04-27 15:18:44 +00:00
|
|
|
|
if (is_valid_movement("down")) transform.Translate(Vector3.down);
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
2019-04-27 15:18:44 +00:00
|
|
|
|
// Qui c'è da aggiungere la condizione per il controllo degli hp
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_valid_movement(string direction)
|
|
|
|
|
{
|
|
|
|
|
Tile tile;
|
2019-04-27 15:18:44 +00:00
|
|
|
|
int posX = (int) transform.position.x;
|
|
|
|
|
int posY = (int) transform.position.y;
|
2019-04-27 12:40:09 +00:00
|
|
|
|
if (direction == "left") tile = map.GetTile(posX - 1, posY);
|
|
|
|
|
else if (direction == "right") tile = map.GetTile(posX + 1, posY);
|
|
|
|
|
else if (direction == "up") tile = map.GetTile(posX, posY + 1);
|
|
|
|
|
else tile = map.GetTile(posX, posY - 1);
|
2019-04-27 12:52:24 +00:00
|
|
|
|
return tile.walkable;
|
2019-04-27 12:40:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|