protected override void OnTriggerEnter2D(Collider2D collision) { PlayerEntity player = collision.GetComponent <PlayerEntity>(); if (player != null) { player.OnTakeDamage?.Invoke(ContactDamage.GetValue()); Die(); } }
protected void ResetToOriginalValues() { ContactDamage contactDamage = GetComponent <ContactDamage>(); if (contactDamage != null) { contactDamage.willDamagePlayer = originalDamagePlayer; contactDamage.willDamageEnemies = originalDamageEnemies; } willDestroyOnHit.enemy = originalDestroyOnHit.enemy; willDestroyOnHit.player = originalDestroyOnHit.player; }
// Use this for initialization void Start() { //Get the componants moveTowardPlayerScript = GetComponent <MoveTowardPlayer>(); contactDamageScript = GetComponent <ContactDamage>(); healthScript = GetComponentInChildren <Health>(); //Set the stats of the enemt with values from the EnemyStats class moveTowardPlayerScript.movementSpeed = Data.enemyStats.movementSpeed; contactDamageScript.attackSpeed = Data.enemyStats.attackSpeed; contactDamageScript.damage = Data.enemyStats.damage; healthScript.maxHealth = Data.enemyStats.maxHealth; }
protected virtual void ProcessCollision(Collider2D col, CollisionType type = CollisionType.Enter) { if (col.tag != "Terrain") //Ignoring terrain collisions speeds up performance here { bool willBounce = false; if (type == CollisionType.Enter) { if (slots.controller) { BounceState bounce = slots.controller.bounceState; if (bounce && slots.collider) { if (bounce.CanBounce(slots.collider, col)) { willBounce = true; bounce.StartBounce(slots.collider, col); RexActor bouncedOnActor = col.GetComponent <RexActor>(); if (bouncedOnActor) { bouncedOnActor.Damage(bounce.damageDealt, false); bouncedOnActor.OnBouncedOn(slots.collider); } } } } } if (!willBounce) { ContactDamage contactDamage = col.GetComponent <ContactDamage>(); if (contactDamage != null) { if (col.GetComponent <RexActor>() && col.GetComponent <RexActor>().isDead) { return; } if (tag == "Player" && contactDamage.willDamagePlayer) { Damage(contactDamage.amount, true, BattleEnums.DamageType.Regular, col); } else if (tag == "Enemy" && contactDamage.willDamageEnemies) { Damage(contactDamage.amount, true, BattleEnums.DamageType.Regular, col); } } } } }
protected void SaveOriginalValues() { originalMovementSpeed = movementSpeed; ContactDamage contactDamage = GetComponent <ContactDamage>(); if (contactDamage != null) { originalDamagePlayer = contactDamage.willDamagePlayer; originalDamageEnemies = contactDamage.willDamageEnemies; } originalDestroyOnHit.enemy = willDestroyOnHit.enemy; originalDestroyOnHit.player = willDestroyOnHit.player; }
protected void Reflect(Reflector reflector) { if (sounds.reflectSound) { GetComponent <AudioSource>().PlayOneShot(sounds.reflectSound); } Vector2 distanceFromCenter = new Vector2(); distanceFromCenter.x = (transform.position.x - reflector.GetComponent <BoxCollider2D>().bounds.min.x) / (reflector.GetComponent <BoxCollider2D>().bounds.max.x - reflector.GetComponent <BoxCollider2D>().bounds.min.x) - 0.5f; distanceFromCenter.y = (transform.position.y - reflector.GetComponent <BoxCollider2D>().bounds.min.y) / (reflector.GetComponent <BoxCollider2D>().bounds.max.y - reflector.GetComponent <BoxCollider2D>().bounds.min.y) - 0.5f; if (distanceFromCenter.x > 0.5f) { distanceFromCenter.x = 0.5f; } else if (distanceFromCenter.x < -0.5f) { distanceFromCenter.x = -0.5f; } if (distanceFromCenter.y > 0.5f) { distanceFromCenter.y = 0.5f; } else if (distanceFromCenter.y < -0.5f) { distanceFromCenter.y = -0.5f; } movementSpeed.x = 0.0f; movementSpeed.y = 0.0f; float speed = 40.0f; if (reflector.orientation == Reflector.Orientation.Right || reflector.orientation == Reflector.Orientation.Left) { movementSpeed.x = speed; if (transform.position.x < reflector.transform.position.x) //Bullet is to the left of reflector { SetHorizontalDirection(Direction.Horizontal.Left); } else //Bullet is to the right of reflector { SetHorizontalDirection(Direction.Horizontal.Right); } if (reflection.willReflectAtAngles) { movementSpeed.x *= 1.0f - Mathf.Abs(distanceFromCenter.y); movementSpeed.y = speed * distanceFromCenter.y; } } else if (reflector.orientation == Reflector.Orientation.Up || reflector.orientation == Reflector.Orientation.Down) { SetHorizontalDirection(Direction.Horizontal.Right); if (transform.position.y > reflector.transform.position.y) { movementSpeed.y = speed; transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } else { movementSpeed.y = -speed; transform.localScale = new Vector3(1.0f, -1.0f, 1.0f); } if (reflection.willReflectAtAngles) { movementSpeed.y *= 1.0f - Mathf.Abs(distanceFromCenter.x); movementSpeed.x = speed * distanceFromCenter.x; } } slots.physicsObject.SetVelocityY(movementSpeed.y); ContactDamage contactDamage = GetComponent <ContactDamage>(); if (contactDamage != null) { contactDamage.willDamagePlayer = reflection.willDamagePlayerOnReflect; contactDamage.willDamageEnemies = reflection.willDamageEnemiesOnReflect; } willDestroyOnHit.enemy = reflection.reflectedDestroyOnHit.enemy; willDestroyOnHit.player = reflection.reflectedDestroyOnHit.player; slots.physicsObject.SetVelocityX((int)direction.horizontal * Mathf.Abs(movementSpeed.x)); slots.physicsObject.SetVelocityY((int)direction.vertical * Mathf.Abs(movementSpeed.y)); }
private void ProcessCollisionsOnGridBlock(List <GridBlock> gridBlocks) { for (int i = 0; i < gridBlocks.Count; i++) { if (gridBlocks[i].objectsOnBlock.Count > 1) { Debug.Log("Processing collision on " + gridBlocks[i].location.ToString()); for (int j = 0; j < gridBlocks[i].objectsOnBlock.Count; j++) { GameObject gameObject = gridBlocks[i].objectsOnBlock[j]; GridObject gridObject = gameObject.GetComponent <GridObject>(); Loot loot = gameObject.GetComponent <Loot>(); Health gameObjectHealth = gameObject.GetComponent <Health>(); ContactDamage gameObjectDamage = gameObject.GetComponent <ContactDamage>(); for (int k = 1 + j; k < gridBlocks[i].objectsOnBlock.Count; k++) { GameObject otherGameObject = gridBlocks[i].objectsOnBlock[k]; GridObject otherGridObject = otherGameObject.GetComponent <GridObject>(); Loot otherLoot = otherGameObject.GetComponent <Loot>(); Health otherGameObjectHealth = otherGameObject.GetComponent <Health>(); ContactDamage otherGameObjectDamage = otherGameObject.GetComponent <ContactDamage>(); if (gameObjectDamage != null && otherGameObjectHealth != null) { if (VerboseConsole) { Debug.Log("Subtracting " + gameObjectDamage.DamageAmount.ToString() + " from " + otherGameObject.name); } otherGameObjectHealth.SubtractHealth(gameObjectDamage.DamageAmount); } if (gameObjectHealth != null && otherGameObjectDamage != null) { if (VerboseConsole) { Debug.Log("Subtracting " + otherGameObjectDamage.DamageAmount.ToString() + " from " + gameObject.name); } gameObjectHealth.SubtractHealth(otherGameObjectDamage.DamageAmount); } if (gridObject is Player && otherGridObject is Loot) { if (VerboseConsole) { Debug.LogFormat("{0} is picking up {1}", gridObject.name, otherLoot.gameObject.name); } Player p = gridObject as Player; p.AcceptLoot(otherLoot.Type, otherLoot.LootAmount); } if (otherGridObject is Player && gridObject is Loot) { if (VerboseConsole) { Debug.LogFormat("{0} is picking up {1}", otherGridObject.name, loot.gameObject.name); } Player p = otherGridObject as Player; p.AcceptLoot(loot.Type, loot.LootAmount); } } } } } }