2019-04-27 15:57:01 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Monster : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public int hpMax;
|
|
|
|
|
public int hp;
|
|
|
|
|
public bool isUndead;
|
|
|
|
|
public int movesPerTurn;
|
|
|
|
|
public bool hasSpottedPlayer;
|
|
|
|
|
|
|
|
|
|
[BeforeStartAttribute]
|
|
|
|
|
public Sprite sprite;
|
|
|
|
|
|
|
|
|
|
private Map map;
|
2019-04-27 17:54:06 +00:00
|
|
|
|
|
|
|
|
|
private Player player;
|
2019-04-27 15:57:01 +00:00
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
2019-04-27 17:04:27 +00:00
|
|
|
|
private void Start()
|
2019-04-27 15:57:01 +00:00
|
|
|
|
{
|
|
|
|
|
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
|
2019-04-27 17:54:06 +00:00
|
|
|
|
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
|
2019-04-27 15:57:01 +00:00
|
|
|
|
hasSpottedPlayer = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Turn(){
|
2019-04-27 17:54:06 +00:00
|
|
|
|
IsPlayerNear();
|
|
|
|
|
if (!hasSpottedPlayer){
|
|
|
|
|
int direction = Random.Range(0, 4);
|
|
|
|
|
if (direction == 0 && map.CanMoveTo(Vector2Int.left)){
|
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 1 && map.CanMoveTo(Vector2Int.right)){
|
|
|
|
|
transform.Translate(Vector3.right);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 2 && map.CanMoveTo(Vector2Int.up)){
|
|
|
|
|
transform.Translate(Vector3.up);
|
|
|
|
|
}
|
|
|
|
|
else if (direction == 3 && map.CanMoveTo(Vector2Int.left)){
|
|
|
|
|
transform.Translate(Vector3.left);
|
|
|
|
|
}
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
2019-04-27 17:54:06 +00:00
|
|
|
|
else{
|
|
|
|
|
//Put here pathfinding code
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
2019-04-27 17:54:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IsPlayerNear(){
|
|
|
|
|
if ((player.transform.position.x-transform.position.x)<=3 || (transform.position.x-player.transform.position.x)>=-3){
|
|
|
|
|
hasSpottedPlayer=true;
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
2019-04-27 17:54:06 +00:00
|
|
|
|
if ((player.transform.position.y-transform.position.y)<=3 || (transform.position.y-player.transform.position.y)>=-3){
|
|
|
|
|
hasSpottedPlayer=true;
|
2019-04-27 15:57:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|