// Use this for initialization void Start() { //Figure out our level level = GameController.GetInstance().WaveNumber - baseWave; if (level < 0) { level = 0; } //Upgrade unit on creation TakesDamage health = GetComponent <TakesDamage> (); health.Health += level * healthPerLevel; //Switch image int image = level / levelsPerImage; if (image >= images.Length) { image = images.Length - 1; } SpriteRenderer renderer = GetComponent <SpriteRenderer> (); renderer.sprite = images [image]; }
public override void ActivateEffect(GameObject activator, float value, Collision2D coll, Collider2D other) { TakesDamage takesDamage = activator.GetComponent <TakesDamage>(); if (takesDamage != null) { takesDamage.Heal(healAmount); } }
private void OnTriggerEnter2D(Collider2D collision) { TakesDamage tD = collision.GetComponent <TakesDamage>(); if (tD != null) { tD.TakeDamage(); } Destroy(gameObject); }
public virtual void OnTriggerEnter2D(Collider2D other) { if (doDealDamage) { TakesDamage takesDamage = other.gameObject.GetComponent <TakesDamage>(); if (takesDamage != null) { Collider2D thisCollider = gameObject.GetComponent <Collider2D>(); takesDamage.ApplyDamage(actualDamage, damageType, null, thisCollider); } } }
/// <summary> /// Deals damage to other /// </summary> /// <param name="other">Other.</param> void dealDamage(GameObject other) { TakesDamage receiver = other.gameObject.GetComponent <TakesDamage>(); if (receiver != null) { // if the receiver is currently taking damage if (receiver.isTakingDamage()) { receiver.adjustLife(-damage); } } }
// Use this for initialization void Start() { // get components _character = GetComponentInParent <Character>(); _takesDamage = GetComponentInParent <TakesDamage>(); _unbrokenHeartSprite = heartPrefab.GetComponent <SpriteRenderer>().sprite; _heartWidth = heartPrefab.GetComponent <SpriteRenderer>().sprite.bounds.size.x; // set values _maxHealth = _takesDamage.maxHealth; _currentHealth = _takesDamage.currentHealth; InitializeHeartDisplays(); // if for some reason current and max health are not the same, update the display adjustDisplay(0); }
void OnTriggerEnter2D(Collider2D other) { Projectile missile = other.GetComponent <Projectile> (); if (missile) { TakeDamage(missile.GetDamage()); missile.Hit(); } else { //If hitting another solid object take full damage TakesDamage solidObject = other.GetComponent <TakesDamage>(); if (solidObject) { TakeDamage(this.Health); } } }
public Bullet(GameEnvironment env, TakesDamage s,Vector2 position, double angle) : base(env) { owner = s; LoadTexture(env.contentManager, "bullet"); Registration = new Vector2(Texture.Width, Texture.Height) * 0.5f; Zindex = 0.0f; CreateCollisionBody(env.CollisionWorld, FarseerPhysics.Dynamics.BodyType.Dynamic, CollisionFlags.IsBullet | CollisionFlags.DisableSleep | CollisionFlags.FixedRotation); AddCollisionCircle(Texture.Height/2, Vector2.Zero); VisualRotationOnly = true; CollisionBody.LinearDamping = 0.0f; Position = position; Rotation = (float) angle; SetPhysicsVelocityOnce(new Vector2(k_speed * (float) Math.Cos(angle), k_speed * (float) Math.Sin(angle))); AllowTeleport = true; }
private void CollideWithObject(Collision2D coll) { if (targetLayer == -1 || coll.gameObject.layer == targetLayer) { TakesDamage touched = coll.gameObject.GetComponent <TakesDamage>(); if (touched != null) { Collider2D thisCollider = gameObject.GetComponent <Collider2D>(); bool damageDone = touched.ApplyDamage(damage, damageType, coll, thisCollider); if (bounceWhenDealingDamage && damageDone) { Vector2 contactPoint = coll.contacts[0].point; Vector2 direction = (contactPoint - (Vector2)transform.position).normalized; thisRigidbody.AddForce(direction * bounceMagnitude, ForceMode2D.Impulse); } } } }
bool DealDamage(GameObject target, int damage_amount = 0) { // if amount is 0, use TakesDamage takesDamage = target.GetComponent <TakesDamage>(); if (takesDamage == null) { return(false); } if (damage_amount == 0) { damage_amount = amount; } if (ondealdamageCallback) { SendMessage("OnDealDamage", target, SendMessageOptions.DontRequireReceiver); } takesDamage.TakeDamage(damage_amount, gameObject); if (removeOnDamage) { stTools.Remove(gameObject, 0); } return(true); }
protected virtual void CollideWithObject(Collision2D coll) { TakesDamage enemy = coll.gameObject.GetComponent <TakesDamage>(); bool doDestroy = true; if (enemy != null) { if (enemy.MarkedForDeath) { this.thisRB.velocity = previousVelocity; doDestroy = false; } else { enemy.ApplyDamage(damage, damageType, coll, thisCollider); } } if (doDestroy) { Destroy(this.gameObject); } }
public bool IsAllied(TakesDamage s) { if (s == this) return true; //I like myself else if (s is Ship) { if (((Ship)s).ai.IsDisabled()) //No mercy for the weak return false; else return !((Ship)s).IsFriendly(); //I only hate sputnik and his friends } else return false; //If ur not a ship or me, I dont like you }
//Tells if this is allied to s public bool IsAllied(TakesDamage s) { if (this == s) { return true; //I like myself } else if (this == Environment.sputnik.controlled) //Im sputnik { return s.IsFriendly(); //Sputnik only likes his friendly buddies } else if (s is Ship) //Im a ship, and I better have the AI controlling me and my target is a ship { if (((Ship)s).ai.IsDisabled()) { return false; //No mercy for the weak } else if (!(ai is AIController)) return false; //This case is strange, I'm actually not sure when this happens, but I don't like it else if (ai.IsAlliedWithPlayer()) //Means Im allied with player { return s.IsFriendly(); } else if (((AIController)ai).target == s) //You are my target { if (((Ship)s).sputnikDetached) //We forgive you if sputnik did bad things to you return ((Ship)s).timeSinceDetached >= 3.0f; else return false; //Otherwise we don't like you } else return true; //You aren't my target, you are okay } else if (s is Boss) //Im a ship and my target is a boss { return !IsFriendly(); //Only friendly people hate boss } else { return false; //If its not a ship or a boss, we don't like it } }
public bool IsAllied(TakesDamage other) { return false; }