Add monster awareness
Now monsters should be aware of the player if he's in 3 tiles from them
This commit is contained in:
parent
2dc6c440e1
commit
147f063d3f
6 changed files with 27 additions and 49 deletions
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ef3d86d84c224344a94715cdfa9fe32c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 043f304edcc831c4ea9fcf0e1a2e520d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0460346d99d385241a6d87bbd10aceb8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e823a56cb429e4b49becdc740fba66b9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -14,27 +14,45 @@ public class Monster : MonoBehaviour
|
|||
public Sprite sprite;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 19c0d85909aede34bb371863f187b9e0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue