private void CheckAggro() { int Count = 0; foreach (MobComponent thisMob in mobs) { if (thisMob.alive == true) { if (((Math.Abs(thisMob.position[0] - position[0]) + (Math.Abs(thisMob.position[1] - position[1])))) < 6) { targetMob = thisMob; Count += 1; } } } if (Count > 0) { Aggro = true; } else { Aggro = false; } if (((Math.Abs(playerposition[0] - position[0]) + (Math.Abs(playerposition[1] - position[1])))) > 5) { Aggro = false; } }
public void PopulateMobs() { int total; total = RandomNumber(30, 50); for (int i = 0; i <= total; i++) { MobComponent thisMob; int[] position = new int[2]; position[0] = RandomNumber(10, 90); position[1] = RandomNumber(10, 90); switch (iMap[position[0], position[1]]) { case 6: case 8: case 9: case 11: case 18: case 19: case 20: case 21: case 22: case 24: case 25: case 26: case 27: case 38: case 39: case 40: case 41: case 49: case 50: case 51: case 53: case 57: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 68: case 70: case 71: case 77: case 81: //Not safe to place a mob break; default: //Safe to place a mob thisMob = new MobComponent(Game, position, playerLevel, iMap, false, spriteBatch, sprite); thisMob.sprite = sprite; mobs.Add(thisMob); break; } } for (int y = 0; y < 100; y++) { for (int x = 0; x < 100; x++) { switch (iMap[y, x]) { case 67: MobComponent newMob; int[] newMobPosition = new int[2]; //Add a normal mob newMobPosition[0] = x; newMobPosition[1] = y; newMob = new MobComponent(Game, newMobPosition, playerLevel, iMap, false, spriteBatch, sprite); newMob.sprite = sprite; mobs.Add(newMob); break; case 80: MobComponent newBoss; int[] newBossPosition = new int[2]; //Add a boss newBossPosition[0] = x; newBossPosition[1] = y - 1; //Below the tile newBoss = new MobComponent(Game, newBossPosition, playerLevel, iMap, true, spriteBatch, bossSprite); newBoss.sprite = bossSprite; mobs.Add(newBoss); break; } } } }