void respawn(bool enable) { CharacterController controller = GetComponent <CharacterController>(); if (controller == null) { return; } MovementController movement = GetComponent <MovementController>(); if (movement != null) { movement.enabled = enable; } else { IAMovement m = GetComponent <IAMovement>(); if (m != null) { m.enabled = enable; GetComponent <IAFire>().enabled = enable; } } controller.detectCollisions = enable; controller.enabled = enable; SpriteRenderer[] renderers = GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer render in renderers) { render.enabled = enable; } }
private void OnTriggerStay(Collider other) { if(Actif && other.GetComponent<IAMovement>() != null && other.GetComponent<IAMovement>().myType == Type.Civilian) { IAMovement theIA = other.GetComponent<IAMovement>(); theIA.Hited(transform.position, true, true, true); } }
void OnTriggerEnter(Collider ship) { //Debug.Log("Algo ha entrado en el" + this.gameObject.name); Funciona if (ship.gameObject.GetComponent <IAMovement>() != null) //para evitar el null reference error { IAShip = ship.gameObject.GetComponent <IAMovement>(); IAShip.nextWaypoint(this.gameObject.name); } }
void GetReactor(IAMovement[] iam, int level) { for (int i = 0; i < iam.Length; i++) { if (iam[i].data.moduleLevel == level) { iaMovement = iam[i]; } } }
public void SpawnCivil() { int theIndexSpawn = Random.Range(0, SpawnPoints.Count); GameObject anAI = Instantiate(Resources.Load <GameObject>("Prefabs/IA"), SpawnPoints[theIndexSpawn].position, transform.rotation); IAMovement theMovement = anAI.GetComponent <IAMovement>(); theMovement.myType = Type.Civilian; theMovement.Activation(); Population.Add(theMovement); }
public void SetUpIA() { renderers = GetComponentsInChildren <Renderer>(); players = GameManager.instance.players; trsf = transform; trsf.SetParent(GameManager.instance.mobsGroup); eyes = GetComponentsInChildren <IAEye>(); if (eyes.Length == 0) { blind = true; } else { blind = false; for (int i = 0; i < eyes.Length; i++) { eyes[i].iaBase = this; eyes[i].SetUpIA(); } } iaMovement = GetComponentInChildren <IAMovement>(); iaMovement.navMeshAgent = GetComponent <NavMeshAgent>(); iaMovement.SetUpIA(); iaBody = GetComponentInChildren <IABody>(); iaBody.orientationSpeed = iaMovement.data.orientationSpeed; iaBody.SetUpIA(); iaWeapons = GetComponentsInChildren <IAWeapon>(); for (int i = 0; i < iaWeapons.Length; i++) { iaWeapons[i].SetUpIA(); } rgdBody = GetComponent <Rigidbody>(); damageable = GetComponentInChildren <Damageable>(); damageable.maxLifePoint = data.maxLifePoint; moveSoundSource = GetComponent <AudioSource>(); collectableGenerator = GetComponent <CollectableGenerator>(); target = players[0].iaTarget; iaBody.target = target; SetUpPools(); setuped = true; StartCoroutine(SpawnCoroutine()); }
public void Utilisation(IAMovement theIA) { Amorçé = false; CS.CameraShake(); theIA.Hited(transform.position, false, false); theIA.Brulé = true; switch (PiegeType) { case aPiege.Barbecue: GameObject theFeu = Instantiate(Resources.Load <GameObject>("Prefabs/Feu"), theIA.transform.position, Resources.Load <GameObject>("Prefabs/Feu").transform.rotation); theFeu.GetComponent <enFeu>().cible = theIA.transform; GameObject theExplosion = Instantiate(Resources.Load <GameObject>("Prefabs/SonExplosion"), theIA.transform.position, Resources.Load <GameObject>("Prefabs/SonExplosion").transform.rotation); break; } }
void Awake() { if (Instance != this) { Destroy(gameObject); } int a = 0; for (int i = 0; i < LimitePopulation; i++) { int theIndexSpawn = Random.Range(0, SpawnPoints.Count); GameObject anAI = Instantiate(Resources.Load <GameObject>("Prefabs/IA"), SpawnPoints[theIndexSpawn].position, transform.rotation); IAMovement theMovement = anAI.GetComponent <IAMovement>(); bool mustBeATarget = false; if (a >= PersonnesPourUnGarde) { theMovement.myType = Type.Guard; a = 0; } else { if (i % 2 == 1 && Limite_target > 0) { Targets_.Add(theMovement); Limite_target--; //Debug.Log("IM A TARGET"); mustBeATarget = true; var p = (GameObject)Instantiate(Resources.Load("Particles/HERE"), anAI.transform); p.transform.position = anAI.transform.position; } theMovement.myType = Type.Civilian; } theMovement.BasePerso = true; theMovement.Activation(mustBeATarget, true); Population.Add(theMovement); a += 1; Poursuivants = new Dictionary <IAMovement, string>(); } }
public TileToThread(List <Movement>[] movs) { numbers = new List <int>(); for (int i = 0; i < movs.Length; i++) { if (movs[i].Count == 0) { numT++; numbers.Add(i); if (i == 0) { numbers.Add(i); } } } IAMovement.Shuffle <int>(ref numbers); }
//dir must be {1,1}, {1,-1} {-1,1} {-1,-1} public Tile[] GetPosibleMovementsDirection(Vector2 start, Vector2 dir) { List <Tile> resul = new List <Tile>(); for (int i = 1; i < MAX_DIAG; i++) { Tile t = CheckExistTile((int)start.x + (int)dir.x * i, (int)start.y + (int)dir.y * i); if (t && IAMovement.CheckPiece(t.x, t.y)) { resul.Add(t); } else { i = MAX_DIAG; } } return(resul.ToArray()); }
private void Update() { if (PoliceIncoming) { TempsPolice += Time.deltaTime; if (TempsPolice >= LatencePolice) { SpawnPoliceman(); PolicemanOnGround = true; VictimesActuelles = 0; PoliceIncoming = false; TempsPolice = 0; } } if (needNewPopulation) { TempsNouveauxArrivants += Time.deltaTime; if (TempsNouveauxArrivants >= LatenceNouveauxArrivants) { needNewPopulation = false; TempsNouveauxArrivants = 0; int nombreNecessaire = LimitePopulation - Population.Count; for (int i = 0; i < nombreNecessaire; i++) { int theIndexSpawn = Random.Range(0, SpawnPoints.Count); GameObject anAI = Instantiate(Resources.Load <GameObject>("Prefabs/IA"), SpawnPoints[theIndexSpawn].position, transform.rotation); IAMovement theMovement = anAI.GetComponent <IAMovement>(); theMovement.myType = Type.Civilian; theMovement.Activation(); Population.Add(theMovement); } } } }
public virtual Tile[] GetPosibleMovementsNoPlayerColumn() { List <Tile> lt = new List <Tile>(); List <Tile> resul = new List <Tile>(GetPosibleMovements()); for (int i = 0; i < resul.Count; i++) { Tile t = resul[i]; if (t.y == player.y) { lt.Add(t); } } foreach (Tile t in lt) { resul.Remove(t); } IAMovement.Shuffle <Tile>(ref resul); return(resul.ToArray()); }
public void SpawnPoliceman() { int theIndexSpawn = Random.Range(0, SpawnPoints.Count); GameObject anAI = Instantiate(Resources.Load <GameObject>("Prefabs/IA"), SpawnPoints[theIndexSpawn].position, transform.rotation); IAMovement theMovement = anAI.GetComponent <IAMovement>(); theMovement.myType = Type.Policeman; theMovement.Activation(); Population.Add(theMovement); if (!first) { first = true; CamZoom_g.SetActive(true); CamZoom_g.transform.position = anAI.transform.position; Tuto.Instance.step = 7; Invoke("CamZoom", 0.1f); } }
void RunGame() { players = new PlayerMovement[1]; PlayerMovement newPlayer = ((GameObject)GameObject.Instantiate( (UnityEngine.Object)playerPrefab, playerPrefab.transform.position, playerPrefab.transform.rotation)).GetComponent <PlayerMovement>(); newPlayer.SetCoolFace(coolFaces[Random.Range(0, coolFaces.Length)]); newPlayer.SetAngryFace(angryFaces[Random.Range(0, angryFaces.Length)]); players[0] = newPlayer; ias = new IAMovement[5]; for (int i = 0; i < ias.Length; ++i) { IAMovement newIA = ((GameObject)GameObject.Instantiate( (UnityEngine.Object)IAPrefab, IAPrefab.transform.position, IAPrefab.transform.rotation)).GetComponent <IAMovement>(); newIA.SetCoolFace(coolFaces[Random.Range(0, coolFaces.Length)]); ias[i] = newIA; } }
public void SomeoneLeave(IAMovement theIA) { theIA.ReadytoLeave = true; SomeoneLeft = true; }
public void LoadSkin(IAMovement theIA) { SpriteRenderer[] LesSprites = GetComponentsInChildren <SpriteRenderer>(); for (int i = 0; i < LesSprites.Length; i++) { switch (LesSprites[i].gameObject.name) { case "Corps": Corps = LesSprites[i]; break; case "Tête": Tête = LesSprites[i]; break; case "EpauleDroite": EpauleDroite = LesSprites[i]; break; case "BrasDroite": BrasDroit = LesSprites[i]; break; case "MainDroite": MainDroite = LesSprites[i]; break; case "EpauleGauche": EpauleGauche = LesSprites[i]; break; case "BrasGauche": BrasGauche = LesSprites[i]; break; case "MainGauche": MainGauche = LesSprites[i]; break; } } myIA = GetComponentInParent <IAMovement>(); IAM = IAManager.Instance; if (theIA.myType == Type.Guard) { Corps.sprite = Resources.Load <Sprite>("Skins/Guard/Corps"); Tête.sprite = Resources.Load <Sprite>("Skins/Guard/Tête"); EpauleDroite.sprite = Resources.Load <Sprite>("Skins/Guard/Epaule"); EpauleGauche.sprite = Resources.Load <Sprite>("Skins/Guard/Epaule"); BrasDroit.sprite = Resources.Load <Sprite>("Skins/Guard/Bras"); BrasGauche.sprite = Resources.Load <Sprite>("Skins/Guard/Bras"); MainDroite.sprite = Resources.Load <Sprite>("Skins/Guard/Main"); MainGauche.sprite = Resources.Load <Sprite>("Skins/Guard/Main"); theIA.SkinChemin = "Skins/Guard"; } else if (theIA.myType == Type.Civilian && AlreadyAsignedOnTarget == false) { DirectoryInfo dir = new DirectoryInfo("Assets/Resources/Skins/Civil"); DirectoryInfo[] info = dir.GetDirectories("*.*"); int count = dir.GetDirectories().Length; int rnd = Random.Range(1, count + 1); Corps.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Corps"); Tête.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Tête"); EpauleDroite.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Epaule"); EpauleGauche.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Epaule"); BrasDroit.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Bras"); BrasGauche.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Bras"); MainDroite.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Main"); MainGauche.sprite = Resources.Load <Sprite>("Skins/Civil/Civil_" + rnd + "/Main"); theIA.SkinChemin = "Skins/Civil/Civil_" + rnd; if (myIA.IsTarget) { IAM.AddPortraits(theIA.SkinChemin); AlreadyAsignedOnTarget = true; } } else if (theIA.myType == Type.Policeman) { Corps.sprite = Resources.Load <Sprite>("Skins/Policeman/Corps"); Tête.sprite = Resources.Load <Sprite>("Skins/Policeman/Tête"); EpauleDroite.sprite = Resources.Load <Sprite>("Skins/Policeman/Epaule"); EpauleGauche.sprite = Resources.Load <Sprite>("Skins/Policeman/Epaule"); BrasDroit.sprite = Resources.Load <Sprite>("Skins/Policeman/Bras"); BrasGauche.sprite = Resources.Load <Sprite>("Skins/Policeman/Bras"); MainDroite.sprite = Resources.Load <Sprite>("Skins/Policeman/Main"); MainGauche.sprite = Resources.Load <Sprite>("Skins/Policeman/Main"); theIA.SkinChemin = "Skins/Policeman"; } }
//return true if player is killed public void DecideNextMovement() { int destroyedPieces = 0; List <Movement> movsToExec = new List <Movement>(); List <ChessPieces> destroyed = new List <ChessPieces>(); for (int i = 0; i < pieces.Count; i++) { Debug.Log(pieces[i]); ChessPieces cp = pieces[i]; if (cp.ShouldDestroy()) { destroyed.Add(cp); ++destroyedPieces; } } foreach (ChessPieces cp in destroyed) { pieces.Remove(cp); if (cp is Rook) { rook = false; } cp.UnMarkThreatsTile(); cp.DestroyPiece(); } if (pieces.Count < MAX_PIECES / 2) { CreatePiece(); } if (pieces.Count == 0) { CreatePiece(); CreatePiece(); } List <Movement>[] movs = UpdateState(); switch (state) { case State.Clear: //There are no threats, create one or move random Debug.Log("No threats"); List <ChessPieces> copied0 = new List <ChessPieces>(pieces); bool threated0 = false; while (!threated0 && copied0.Count != 0) { int i = Random.Range(0, copied0.Count); Movement mov; TileToThread ttt = new TileToThread(movs); int auxx; while (!threated0 && (auxx = ttt.Get()) != -1) { if (copied0[i].CanThreatInAMov(out mov, player.x + auxx, player.y)) { //Execute movement threated0 = true; Debug.Log("MOVE TO THREAT"); movsToExec.Add(new Movement(copied0[i], mov.tile)); } } if (!threated0) { copied0.RemoveAt(i); } } if (threated0 == false) { //Create another piece of chess, maybe with a probability to measure difficulty, or move random Debug.Log("Create piece and random movement"); //pieces[Random.Range(0, pieces.Count)].MoveToRandom(); CreatePiece(); } break; case State.One: //There is one threat, create another one, eliminate that one Debug.Log("One threat"); bool threated1 = false; if (Random.Range(0.0f, 1.0f) <= 0.4f * (1 + difficult)) { Movement mov; TileToThread ttt = new TileToThread(movs); int auxx; while (!threated1 && (auxx = ttt.Get()) != -1) { List <ChessPieces> copied1 = new List <ChessPieces>(pieces); while (!threated1 && copied1.Count != 0) { int i = Random.Range(0, copied1.Count); //CHANGE TO FIRST TRY TO THREAT NON THREATED TILES if (copied1[i].CanThreatInAMov(out mov, player.x + auxx, player.y)) { //Execute movement threated1 = true; Debug.Log("MOVE TO THREAT"); movsToExec.Add(new Movement(copied1[i], mov.tile)); } if (!threated1) { copied1.RemoveAt(i); } } } } if (!threated1 || Random.Range(0.0f, 1.0f) <= 0.25 * difficult) { Debug.Log("CREATE A PIECE"); //pieces[Random.Range(0, pieces.Count)].MoveToRandom(); CreatePiece(); if (!threated1) { Movement auxMov = new Movement(); pieces[Random.Range(0, pieces.Count)].MoveToRandom(out auxMov); movsToExec.Add(auxMov); } } break; case State.Two: //There are two threat, eliminate one or move random Debug.Log("Two threats"); Debug.Log("Move one to reduce threat"); bool avoided = false; //while (!avoided) //{ int infinity = 10; int t = Random.Range(1, movs.Length); while (!avoided) { bool all = true; foreach (Movement m in movs[t]) { Movement auxMov = new Movement(); all &= m.piece.CanAvoidThreatInAMov(out auxMov); if (all) { movsToExec.Add(auxMov); avoided = true; } } while (movs[t].Count == 0 && !avoided) { t = Random.Range(0, movs.Length); } infinity--; if (infinity < 0) { foreach (Movement m in movs[t]) { Movement auxMov; m.piece.MoveToRandom(out auxMov); movsToExec.Add(auxMov); } break; } } //} break; case State.Three: // TOO MANY THREATS, PLAYER CANT WIN Debug.Log("PLAYER IS GOING TO LOSE"); foreach (Movement m in movs[0]) { Movement auxMov = new Movement(); bool aux = m.piece.CanAvoidThreatInAMov(out auxMov); if (aux) { movsToExec.Add(auxMov); avoided = true; } } foreach (Movement m in movs[2]) { Movement auxMov = new Movement(); bool aux = m.piece.CanAvoidThreatInAMov(out auxMov); if (aux) { movsToExec.Add(auxMov); avoided = true; } } break; } List <Vector2> auxPos = new List <Vector2>(); foreach (Movement mov in movsToExec) { auxPos.Add(new Vector2(mov.piece._x, mov.piece._y)); mov.piece.MoveToNoAnim(mov.tile.x, mov.tile.y); } movs = UpdateState(); int i_des = 0; foreach (Movement mov in movsToExec) { mov.piece.MoveToNoAnim((int)auxPos[i_des].x, (int)auxPos[i_des].y); i_des++; } if (state == State.Three) { movsToExec = new List <Movement>(); Debug.Log("KILL MY LIFE"); foreach (Movement m in movs[0]) { Movement auxMov = new Movement(); bool aux = m.piece.CanAvoidThreatInAMov(out auxMov); if (aux) { movsToExec.Add(auxMov); } } foreach (Movement m in movs[2]) { Movement auxMov = new Movement(); bool aux = m.piece.CanAvoidThreatInAMov(out auxMov); if (aux) { movsToExec.Add(auxMov); } } } IAMovement.Shuffle <ChessPieces>(ref pieces); foreach (Movement mov in movsToExec) { lastMoved = mov.piece; mov.piece.MoveTo(mov.tile.x, mov.tile.y); } }
public void Reset() { _instance = new IAMovement(); }