void Start() { controller = GameObject.FindGameObjectWithTag("GameController").GetComponent <gameController>(); numberOfIAs = controller.GetComponent <gameController>().numberOfIAs; TrustInOthers = new int[numberOfIAs]; myMemory = GetComponent <Memory>(); base.behaviourManager = controller.GetComponent <BehaviourAdder>(); // interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK; initializeTrustInOthers(numberOfIAs); aiGroup = GetComponent <GroupScript> (); cone = GetComponent <VisibilityConeCycleIA> (); playerNormalStateImage = gameObject.GetComponent <SpriteRenderer> ().sprite; }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("wall")) { Debug.Log("wall hit"); y = y * -1; yy = yy * -1; } if (collision.gameObject.CompareTag("Player1") || collision.gameObject.CompareTag("Player2")) { x = x * -1; xx = xx * -1; } if (collision.gameObject.CompareTag("goal1")) { g.GetComponent <gameController>().point1(); Destroy(this.gameObject); } if (collision.gameObject.CompareTag("goal2")) { g.GetComponent <gameController>().point2(); Destroy(this.gameObject); } }
// Update is called once per frame void FixedUpdate() { float xAxis = Input.GetAxis("Horizontal"); float yAxis = Input.GetAxis("Vertical"); GetComponent <Rigidbody2D>().AddForce(new Vector2(xAxis, yAxis), ForceMode2D.Impulse); playerConstraint(playfieldLocation.position, innerRadius, outerRadius); if (safe && !safeStarted) // On entre en mode safe (frame invulnaribilité) { StartCoroutine(safePlayerMode()); } if (updateEnergy(-1 * Time.deltaTime) <= 0) { gc.GetComponent <gameController>().gameOver(); } // gestion anim Vector3 playerVelocity = GetComponent <Rigidbody2D>().velocity; Debug.Log(playerVelocity); if (playerVelocity.magnitude <= 0.3) { GetComponent <Animator>().SetBool("goRight", false); GetComponent <Animator>().SetBool("goLeft", false); GetComponent <Animator>().SetBool("goUp", false); GetComponent <Animator>().SetBool("goDown", false); } else { if (playerVelocity.x > 1) { GetComponent <Animator>().SetBool("goRight", true); } else { GetComponent <Animator>().SetBool("goRight", false); } if (playerVelocity.x < -1) { GetComponent <Animator>().SetBool("goLeft", true); } else { GetComponent <Animator>().SetBool("goLeft", false); } if (playerVelocity.y > 1) { GetComponent <Animator>().SetBool("goUp", true); } else { Debug.Log("Go Up"); GetComponent <Animator>().SetBool("goUp", false); } if (playerVelocity.y < -1) { GetComponent <Animator>().SetBool("goDown", true); } else { GetComponent <Animator>().SetBool("goDown", false); } } }
public override void takeDamage(int damage, PersonalityBase personality) { health -= (int)(damage * defense); HealthImage.GetComponent <Image>().fillAmount = health / 100f; if (health <= 50 && health > 33) { HealthImage.GetComponent <Image>().color = new Color(255, 255, 0); } else if (health <= 33 && health > 0) { HealthImage.GetComponent <Image>().color = new Color(255, 0, 0); } else if (health <= 0) { if (personality.isMonster && !theThing) { theThing = true; HealthImage.GetComponent <Image>().color = new Color(0, 255, 0); controller.numberOfMonsters++; controller.decreaseHumans(); Debug.Log("me mata un puto monstruo y me he convertido.\thumanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters); } else { if (theThing) { controller.numberOfMonsters--; if (controller.CheckPlayerWin()) { //Debug.Log ("ha devuelto true en win"); controller.youWin(true); } else if (controller.CheckPlayerLost()) { //Debug.Log ("ha devuelto true en lost"); controller.youWin(false); } } else { controller.decreaseHumans(); } Debug.Log("humanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters + "muere " + this.name); this.GetComponent <VisibilityConeCycleIA>().enabled = false; VisibleElements.visibleGameObjects.Remove(this.gameObject); string nameIAdeath = this.name + "ghost"; Vector3 IADeathPosition = this.transform.position; this.enabled = false; var mygroup = this.GetComponent <GroupScript>(); if (mygroup.groupMembers.Count > 0) { if (mygroup.IAmTheLeader) { var members = mygroup.groupMembers; mygroup.ExitGroup(); foreach (var m in members) { GroupScript memberGroup = m.GetComponent <GroupScript>(); memberGroup.groupLeader = members[0]; } members[0].GetComponent <GroupScript>().makeLeader(); members[0].GetComponent <PersonalityBase>().formacionGrupo(members[0], members[0].GetComponent <GroupScript>()); } else { mygroup.ExitGroup(); } } var IAs = GameObject.FindGameObjectsWithTag("IA"); foreach (var ia in IAs) { var arbol = ia.GetComponent <DecisionTreeCreator>(); if (arbol != null) { if (arbol.target == this.gameObject) { Destroy(this.GetComponent <DecisionTreeCreator>()); ia.GetComponent <AIPersonality>().oldNodes = ia.GetComponents <DecisionTreeNode>(); foreach (var item in ia.GetComponent <AIPersonality>().oldNodes) { DestroyImmediate(item); } } } } PlayerMenuController menu = controller.GetComponent <PlayerMenuController> (); menu.CloseAttackMenu(); menu.menuConversation.SetActive(false); menu.CloseJoinMenu(); menu.CloseObjectMenu(); GameObject ghost = new GameObject(); ghost.AddComponent <SpriteRenderer>(); ghost.GetComponent <SpriteRenderer>().sprite = ghostSprite; ghost.GetComponent <SpriteRenderer>().sortingLayerName = "Personajes"; ghost.transform.localScale = new Vector2(5f, 5f); ghost.name = nameIAdeath; ghost.transform.position = IADeathPosition; Destroy(personality.gameObject.GetComponent <Pursue> ()); this.gameObject.SetActive(false); Invoke("DestroyIA", 1f); } } }
public void moveAdjacent(int h, int w, int dir, bool checkValid) { gameController gCon = gamecontrol.GetComponent <gameController>(); int removeCount = 0; if (timecontrol.currentTime == 0) //if timeout, do nothing { return; } if (dir == 0) //left { if (w > 0) { buttonList[h, w].GetComponent <interaction>().SlideObject(0, 1); //swap L-R buttonList[h, w - 1].GetComponent <interaction>().SlideObject(1, 1); swapObj(h, w, h, w - 1); removeCount = gCon.checkValidMoves(); //check if this is a valid move if (checkValid && removeCount == 0) //invalid { StartCoroutine(swapOnFailedMove(h, w, 0)); //swap back } } } else if (dir == 1) //right { if (w < maxW - 1) { buttonList[h, w].GetComponent <interaction>().SlideObject(1, 1); //swap R-L buttonList[h, w + 1].GetComponent <interaction>().SlideObject(0, 1); swapObj(h, w, h, w + 1); removeCount = gCon.checkValidMoves(); if (checkValid && removeCount == 0) { StartCoroutine(swapOnFailedMove(h, w, 1)); } } } else if (dir == 2) //up { if (h > 0) { buttonList[h, w].GetComponent <interaction>().SlideObject(2, 1); //swap U-D buttonList[h - 1, w].GetComponent <interaction>().SlideObject(3, 1); swapObj(h, w, h - 1, w); removeCount = gCon.checkValidMoves(); if (checkValid && removeCount == 0) { StartCoroutine(swapOnFailedMove(h, w, 2)); } } } else if (dir == 3) //down { if (h < maxH - 1) { buttonList[h, w].GetComponent <interaction>().SlideObject(3, 1); //swap D-U buttonList[h + 1, w].GetComponent <interaction>().SlideObject(2, 1); swapObj(h, w, h + 1, w); removeCount = gCon.checkValidMoves(); if (checkValid && removeCount == 0) { StartCoroutine(swapOnFailedMove(h, w, 3)); } } } //Debug.Log("On main event, " + removeCount + " objects were removed."); //if this is a valid move if (checkValid && removeCount != 0) { StartCoroutine(gCon.slideDownAndFillBoard()); //fill the board again scorecontrol.addPoints(removeCount, false); //add scores, no combo } }