public override void collideWith(Actor other) { if (other is Spear) { if (this.powerupState == powerupstate.SpearDeflection) { other.acceleration = Vector2.Zero; Vector2 reflectingVector = this.DirectionTo(other); float reflectingRotation = Physics.VectorToAngle(reflectingVector); other.velocity = other.MaxVel * reflectingVector; ((Spear)other).Owner = this; other.Rotation = reflectingRotation; AudioManager.getSound("Ding").Play(); } else { // Set delay so we can't immediately fire a spear after being hit this.FireTime = fireCooldown * 1.5f; this.Fire = false; // take damage based on the spear's owner's size if (other.CurrentSize == Size.Large) { AudioManager.getSound("Actor_Hit").Play(); if (((Spear)other).Owner.powerupState == powerupstate.RapidFire) this.calories -= Powerups.RapidFirePowerup.RAPID_FIRE_DAMAGE_LARGE; else this.calories -= SPEAR_MAX_DAMAGE; } else if (other.CurrentSize == Size.Medium) { if (((Spear)other).Owner.powerupState == powerupstate.RapidFire) this.calories -= Powerups.RapidFirePowerup.RAPID_FIRE_DAMAGE_MEDIUM; else this.calories -= SPEAR_MED_DAMAGE; } else if (other.CurrentSize == Size.Small) { if (((Spear)other).Owner.powerupState == powerupstate.RapidFire) this.calories -= Powerups.RapidFirePowerup.RAPID_FIRE_DAMAGE_SMALL; else this.calories -= SPEAR_SMALL_DAMAGE; } ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); getHit(); isBeingKnockedBack = true; knockbackTime = KNOCKBACK_DURATION; // get physics rotation to p's rotation, // normalize that, and magnify by the amount Vector2 pRotation = Physics.AngleToVector(other.Rotation); pRotation.Normalize(); // give us an acceleration in that direction this.Position += pRotation * Actor.SPEAR_DISPLACEMENT; } } else if (other is Shark) { if (!other.Bounds.isCollision(this.Bounds)) return; // gain health if (other.CurrState == state.Dying) { if (other.Powerup != null) this.calories += 2 * SHARK_CALORIES; else this.calories += SHARK_CALORIES; other.die(); } // take damage else if (other.CurrState == state.Dashing) { // we must not be dying and we must be colliding with // the mouth of the shark if (CurrState != state.Dying && this.Bounds.isCollision(((Shark)other).mouthCircle)) { ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); getHit(); this.calories -= SHARK_DAMAGE; } } } else if (other is Fish) { if (other.CurrState == state.Moving) { AudioManager.getSound("Fish_Eat").Play(); this.calories += FISH_CALORIES; other.startDying(); if (other.Powerup != null) applyPowerup(other.Powerup); } } else if (other is Penguin) { Penguin p = (Penguin)other; if (p.CurrState == state.MeleeAttack && this.Bounds.isCollision(p.spearCircle) && !isBeingKnockedBack) { isBeingKnockedBack = true; knockbackTime = KNOCKBACK_DURATION; getHit(); this.calories -= p.MeleeDamage; // get physics rotation to p's rotation, // normalize that, and magnify by the amount Vector2 pRotation = Physics.AngleToVector(p.Rotation); pRotation.Normalize(); // give us an acceleration in that direction this.velocity += pRotation * p.KnockbackAmount; this.Position += pRotation * (Actor.MELEE_DISPLACEMENT + p.calories / 10.0f); } } }
public override void collideWith(Actor other) { if (other is Spear) { if (other.CurrentSize == Size.Small) this.calories -= SPEAR_SMALL_DAMAGE; else if (other.CurrentSize == Size.Medium) this.calories -= SPEAR_MED_DAMAGE; else this.calories -= SPEAR_MAX_DAMAGE; Random rnd = new Random(); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble()*3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); ParticleManager.Instance.createParticle(ParticleType.HitSpark, new Vector2(this.Position.X + rnd.Next(-20, 20), this.Position.Y + rnd.Next(-20, 20)), new Vector2(0, 0), (float)(rnd.NextDouble() * 6.29f), 0.1f, (float)rnd.NextDouble(), -(float)rnd.NextDouble() * 3, 1, 1 + (float)rnd.NextDouble() * 2f, 1f); isBeingKnockedBack = true; knockbackTime = KNOCKBACK_DURATION; // get physics rotation to p's rotation, // normalize that, and magnify by the amount Vector2 pRotation = Physics.AngleToVector(other.Rotation); pRotation.Normalize(); this.Position += pRotation * Actor.SPEAR_DISPLACEMENT; getHit(); } else if (other is Fish) { if (other.CurrState == state.Moving && this.CurrState != state.Dying && this.IsAlive) { AudioManager.getSound("Fish_Eat").Play(); this.calories += SHARK_FISH_CALORIES; other.startDying(); if (other.Powerup != null) applyPowerup(other.Powerup); } } else if (other is Penguin) { Penguin p = (Penguin)other; if (p.CurrState == state.MeleeAttack && this.Bounds.isCollision(p.spearCircle) && !isBeingKnockedBack) { isBeingKnockedBack = true; knockbackTime = KNOCKBACK_DURATION; getHit(); this.calories -= p.MeleeDamage; // get physics rotation to p's rotation, // normalize that, and magnify by the amount Vector2 pRotation = Physics.AngleToVector(p.Rotation); pRotation.Normalize(); this.velocity = pRotation * p.KnockbackAmount; this.acceleration = Vector2.Zero; this.Position += pRotation * Actor.MELEE_DISPLACEMENT; } else if (other.CurrState == state.Dying) { this.calories += PENGUIN_CALORIES; other.die(); } else if (this.Bounds.isCollision(other.Bounds)) this.acceleration = Vector2.Zero; } }