void OnTriggerStay2D(Collider2D other) { MoveableGridObject otherGridObject = other.GetComponent <MoveableGridObject>(); BombObject bombObject = other.GetComponent <BombObject>(); if (bombObject) { bombObject.Roll(direction); } if (other.gameObject.CompareTag("Player")) { PlayerGridObject player = other.GetComponent <PlayerGridObject>(); if (player.platforms == 0) { player.Move(direction); } } else if (otherGridObject && !other.gameObject.CompareTag("WindSlime")) { otherGridObject.Move(direction); EnemyGridObject enemyGridObject = other.gameObject.GetComponent <EnemyGridObject>(); if (enemyGridObject) { enemyGridObject.TakeDamage(damage); } } }
// Update is called once per frame protected override void Update() { base.Update(); // TODO: pull up animator code for player up to here so monster can have their own // Get Left or Right horizontalAxis = Input.GetAxisRaw("Horizontal"); // Get Up or Down verticalAxis = Input.GetAxisRaw("Vertical"); // Up if (canMove) { if (!isAttacking && verticalAxis > 0) { Move(Globals.Direction.North); Move(Globals.Direction.North); // Double movespeed if (horizontalAxis == 0.0f) { Move(Globals.Direction.North); } } // Down else if (!isAttacking && verticalAxis < 0) { Move(Globals.Direction.South); Move(Globals.Direction.South); if (horizontalAxis == 0.0f) { Move(Globals.Direction.South); } } // Left if (!isAttacking && horizontalAxis < 0) { Move(Globals.Direction.West); Move(Globals.Direction.West); if (verticalAxis == 0.0f) { Move(Globals.Direction.West); } } // Right else if (!isAttacking && horizontalAxis > 0) { Move(Globals.Direction.East); Move(Globals.Direction.East); if (verticalAxis == 0.0f) { Move(Globals.Direction.East); } } if (!isAttacking && (horizontalAxis != 0.0f || verticalAxis != 0.0f)) { animator.SetBool("IsWalking", true); animator.SetInteger("Direction", (int)direction); } else { animator.SetBool("IsWalking", false); } } if (!canvas.dialogue && Input.GetKeyDown(KeyCode.Space)) { if (!isAttacking) { animator.SetTrigger("Attack"); Attack(); //knockBack logic foreach (KillableGridObject target in killList) { MoveableGridObject moveable = target.GetComponent <MoveableGridObject>(); if (moveable && target.faction == Globals.Faction.Enemy) { if (!(moveable.gameObject.GetComponent <BombObject>()) && !(moveable.gameObject.GetComponent <RollingBoulder>())) { for (int i = 0; i < this.gameObject.GetComponent <PlayerGridObject>().knockBackPower; i++) { moveable.Move(this.gameObject.GetComponent <PlayerGridObject>().direction); } } } } } } else if (!canvas.dialogue && Input.GetButtonDown("Deplant")) { switch (direction) { case Globals.Direction.South: killList = southHitCollider.GetKillList(); break; case Globals.Direction.East: killList = eastHitCollider.GetKillList(); break; case Globals.Direction.North: killList = northHitCollider.GetKillList(); break; case Globals.Direction.West: killList = westHitCollider.GetKillList(); break; } killList.RemoveAll((KillableGridObject target) => target == null); // Deal damage to all targets of the enemy faction foreach (KillableGridObject target in killList) { //deplant code MOVED so deplanting is a different button PlantGridObject plant = target.GetComponent <PlantGridObject>(); if (plant) { if (!plant.unharvestable) { plant.TakeDamage(100); } } } } else { for (int i = 0; i < 10; ++i) { if (!canvas.dialogue && Input.GetKeyDown("" + i)) { Plant(i - 1); } } } if (plantCooldown > 0) { plantCooldown--; if (plantCooldown <= 0) { canvas.UpdatePlantCooldown(true); } } }