public void DistanceDamage(Bullet Damager) { for (int i = 0; i < ObjectList.Count; i++) { BasicObject Object = ObjectList[i]; if (Object != null) { float Distance = Vector2.Distance(Object.Position + Object.Size / 2, Damager.Position + Damager.Size / 2); if (Distance <= Damager.Range) { Object.TakeDamage( (Damager.Range - Distance) / Damager.Range * Damager.Damage , Damager , Vector2.Normalize(Object.Position - Damager.Position)); } } } for (int i = 0; i < DynamicCollidables.Count; i++) { BasicObject Object = DynamicCollidables[i]; if (Object != null) { float Distance = Vector2.Distance(Object.Position, Damager.Position); if (Distance <= Damager.Range) { Object.TakeDamage((Damager.Range - Distance) / Damager.Range * Damager.Damage, Damager, Vector2.Normalize(Object.Position - Damager.Position)); } } } }
public override bool HitObject(BasicObject Object, GameTime gameTime) { if (Object != Creator) { if (LifeTime < 400) { Object.TakeDamage((float)Damage * gameTime.ElapsedGameTime.Milliseconds / 1000f * 60f, this, Direction); if (Object.GetType().IsSubclassOf(typeof(DynamicObject))) { for (int i = 0; i < 3; i++) { ParticleSystem.Add(ParticleType.Spark, (Position + Size / 2 + Object.Position + Object.Size / 2) / 2, Bullet.RandomSpeed(0.35f) * new Vector2(1, 5), 0, new Color(1f, 1, 1f), 1.5f); } ParticleSystem.Add(ParticleType.Spark, (Position + Size / 2 + Object.Position + Object.Size / 2) / 2, Bullet.RandomSpeed(0.1f) * new Vector2(1, 5), 0, new Color(1f, 1, 1f), 5); if (Vector2.Distance(Position + Size / 2, Object.Position + Object.Size / 2) < 25) { Slash(); } else { Speed = Vector2.Normalize((Object.Position + Object.Size / 2) - (Position + Size / 2)) * Vector2.Distance(Vector2.Zero, Speed); } } } } return(false); }
public virtual bool HitObject(BasicObject Object, GameTime gameTime) { Object.TakeDamage(Damage, this, Vector2.Normalize(Speed)); // if (Object.GetType().Equals(typeof(Block))) Destroy(); return(true); }
public override bool HitObject(BasicObject Object, GameTime gameTime) { if (Object.GetType().IsSubclassOf(typeof(DynamicObject))) { return(base.HitObject(Object, gameTime)); } else { Object.TakeDamage(gameTime.ElapsedGameTime.Milliseconds / 1000f * 60f * Damage, this, Vector2.Normalize(Speed)); return(false); } }
public override bool HitObject(BasicObject Object, GameTime gameTime) { if (Object.Damage < Object.Life) { if (Hits > 0 && Object.GetType().Equals(typeof(Block)) && Vector2.Distance(Position, GameManager.MyLevel.GetNearestEnemy(this).Position) > Range) { Hits--; Object.TakeDamage(1000, this, Vector2.Zero); Speed *= 0.5f; } else { Destroy(); } } return(true); }
private BasicObject UpdateGravity(GameTime gameTime) { if (!IsDashing) { PushTime -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f); JumpTimer -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f); BasicObject Other = GameManager.MyLevel.CheckForSolidCollision(GravityRectangle); if (Other == null) { Speed += Gravity * gameTime.ElapsedGameTime.Milliseconds; } else { JumpTimer = 60; Jumps = 1; } List <BasicObject> Victims = new List <BasicObject>(); Vector2 ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds)); int Reps = 1; if (GameManager.MyLevel.CheckForSolidCollision(ToPosition, Size) != null) { Reps = (int)Vector2.Distance(Vector2.Zero, Speed * gameTime.ElapsedGameTime.Milliseconds); } for (int i = 1; i < Reps + 1; i++) { ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds) / Reps); BasicObject Other2 = GameManager.MyLevel.CheckForSolidCollision(ToPosition, Size); if (Other2 == null) { Position = ToPosition; } else { if (PushTime > 0) { if (!Victims.Contains(Other2)) { Other2.TakeDamage((Math.Abs(Speed.X) + Math.Abs(Speed.Y)) * 150, null, Speed); Victims.Add(Other2); Speed *= 0.85f; } if (Other2.Damage <= Other2.Life) { Speed = Other2.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds / Reps); } Position = ToPosition; } else { Speed = Vector2.Zero; } } } if (Position.Y > GameManager.MyLevel.MyRectangle.Y + GameManager.MyLevel.MyRectangle.Height + 500) { Die(); } ChangePosition(); return(Other); } else { return(null); } }
public override void CollideWithEnemy(BasicObject Enemy) { Bounces++; Enemy.TakeDamage(50, this, Vector2.Normalize(Enemy.Position - Position)); }
public override void Update(GameTime gameTime) { PushTime -= 1f * (float)gameTime.ElapsedGameTime.Milliseconds / (1000f / 60f); if (PushTime < 0) { if (MyGun != null) { MyGun.Update(gameTime); if (MyGun.Primary != null) { MyGun.Primary.Shoot(Position + Size / 2, Direction); } if (MyGun.Secondary != null) { MyGun.Secondary.Shoot(Position + Size / 2, Direction); } } } Vector2 ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds)); int Reps = 1; Rectangle ToRectangle = new Rectangle((int)ToPosition.X, (int)ToPosition.Y, (int)Size.X, (int)Size.Y); if (GameManager.MyLevel.CheckForSolidCollision(ToRectangle) != null) { Reps = Math.Max(1, (int)Vector2.Distance(Vector2.Zero, Speed * gameTime.ElapsedGameTime.Milliseconds)); } bool CountedBounce = false; for (int i = 1; i < Reps + 1; i++) { ToPosition = Position + ((Speed * gameTime.ElapsedGameTime.Milliseconds) / Reps); ToRectangle = new Rectangle((int)ToPosition.X, (int)ToPosition.Y, (int)Size.X, (int)Size.Y); BasicObject Other2 = GameManager.MyLevel.CheckForSolidCollision(ToRectangle); if (Other2 == null) { Position = ToPosition; } else { if (!CountedBounce && Other2.GetType().Equals(typeof(Block))) { Other2.TakeDamage(DamageToBlock, null, Vector2.Zero); CountedBounce = true; Bounces++; } Speed *= 0.75f; if (Other2.Damage <= Other2.Life) { Speed = Other2.Bounce(MyRectangle, Speed, (int)Math.Max(Speed.X, Speed.Y) * gameTime.ElapsedGameTime.Milliseconds / Reps); } Position = ToPosition; } } ChangePosition(); foreach (BasicObject Object in GameManager.MyLevel.DynamicCollidables) { if (Object.Team != Team) { if (Object.MyRectangle.Intersects(MyRectangle)) { CollideWithEnemy(Object); break; } } } base.Update(gameTime); }