1
Fork 0

Add monster awareness

Now monsters should be aware of the player if he's in 3 tiles from them
This commit is contained in:
Lorenzo Balugani 2019-04-27 19:54:06 +02:00
parent 2dc6c440e1
commit 147f063d3f
6 changed files with 27 additions and 49 deletions

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ef3d86d84c224344a94715cdfa9fe32c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 043f304edcc831c4ea9fcf0e1a2e520d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 0460346d99d385241a6d87bbd10aceb8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e823a56cb429e4b49becdc740fba66b9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -15,26 +15,44 @@ public class Monster : MonoBehaviour
private Map map;
private Player player;
// Start is called before the first frame update
private void Start()
{
map = GameObject.FindGameObjectWithTag("Map").GetComponent<Map>();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
hasSpottedPlayer = false;
}
void Turn(){
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(Vector2Int.left)){
transform.Translate(Vector3.left);
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);
}
}
else if (direction == 1 && map.CanMoveTo(Vector2Int.right)){
transform.Translate(Vector3.right);
else{
//Put here pathfinding code
}
else if (direction == 2 && map.CanMoveTo(Vector2Int.up)){
transform.Translate(Vector3.up);
}
void IsPlayerNear(){
if ((player.transform.position.x-transform.position.x)<=3 || (transform.position.x-player.transform.position.x)>=-3){
hasSpottedPlayer=true;
}
else if (direction == 3 && map.CanMoveTo(Vector2Int.left)){
transform.Translate(Vector3.left);
if ((player.transform.position.y-transform.position.y)<=3 || (transform.position.y-player.transform.position.y)>=-3){
hasSpottedPlayer=true;
}
}
}

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 19c0d85909aede34bb371863f187b9e0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: