1
Fork 0
This commit is contained in:
Steffo 2019-04-27 17:24:26 +02:00
parent 681e8bb0f1
commit 09dd536edf
2 changed files with 12 additions and 18 deletions

View file

@ -148,14 +148,14 @@ public class Map : MonoBehaviour
private List<MapRoom> rooms;
private System.Random rnd;
public Tile GetTile(int x, int y) {
GameObject tileObject = tiles[x, y];
public Tile GetTile(Vector2Int position) {
GameObject tileObject = tiles[position.x, position.y];
Tile tile = tileObject.GetComponent<Tile>();
return tile;
}
private void InitTile(int x, int y, bool walkable, Sprite tileSprite, bool roomPart) {
Tile tile = GetTile(x, y);
Tile tile = GetTile(new Vector2Int(x, y));
tile.walkable = walkable;
tile.sprite = tileSprite;
tile.roomPart = roomPart;

View file

@ -23,21 +23,21 @@ public class Player : MonoBehaviour
void playerMovement()
{
if (Input.GetKey(KeyCode.A))
if (Input.GetKeyDown(KeyCode.A))
{
if (CanMoveTo("left")) transform.Translate(Vector3.left);
if (CanMoveTo(Vector2Int.left)) transform.Translate(Vector3.left);
}
if (Input.GetKey(KeyCode.D))
if (Input.GetKeyDown(KeyCode.D))
{
if (CanMoveTo("right")) transform.Translate(Vector3.right);
if (CanMoveTo(Vector2Int.right)) transform.Translate(Vector3.right);
}
if (Input.GetKey(KeyCode.W))
if (Input.GetKeyDown(KeyCode.W))
{
if (CanMoveTo("up")) transform.Translate(Vector3.up);
if (CanMoveTo(Vector2Int.up)) transform.Translate(Vector3.up);
}
if (Input.GetKey(KeyCode.S))
if (Input.GetKeyDown(KeyCode.S))
{
if (CanMoveTo("down")) transform.Translate(Vector3.down);
if (CanMoveTo(Vector2Int.down)) transform.Translate(Vector3.down);
}
// Qui c'è da aggiungere la condizione per il controllo degli hp
}
@ -45,12 +45,6 @@ public class Player : MonoBehaviour
bool CanMoveTo(Vector2Int direction)
{
Tile tile;
int posX = (int) transform.position.x;
int posY = (int) transform.position.y;
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);
return tile.walkable;
return map.GetTile(direction).walkable;
}
}