public override void Die(GEntity ContactedWith) { if (ContactedWith.IsMetallic) { Sound.MetalHit.Play(); GameLevel.AddParticle(new Spark(X, Y, Direction)); } else if (ContactedWith.IsBrick) { Sound.BrickHit.Play(); GameLevel.AddParticle(new BrickDust(X, Y, Direction)); } }
public bool IntersectsWith(GEntity E) { if (IsElliptic && !E.IsElliptic) { return(RectangleIntersectsWithCircle(E.iX, E.iY, E.W, E.H, iX, iY, R)); } else if (!IsElliptic && E.IsElliptic) { return(RectangleIntersectsWithCircle(iX, iY, W, H, E.iX, E.iY, E.R)); } else if (!IsElliptic && !E.IsElliptic) { return(new Rectangle((int)X, (int)Y, W, H).IntersectsWith(new Rectangle((int)E.X, (int)E.Y, E.W, E.H))); } return(false); }
private void DropBindedEntity() { GEntity SlaveEntity = GetSlaveEntityMoving(); if (SlaveEntity != null) { int[] Offs = GameLevel.GetNewEntityOffsets(); SlaveEntity.X = X + Offs[0]; SlaveEntity.Y = Y + Offs[1]; if (GameLevel.GetNonDraggableIntersectingEntities(SlaveEntity).Count > 0) { SlaveEntity.X -= Offs[0]; SlaveEntity.Y -= Offs[1]; AddInvItem(InvItem.FindInvItem(SlaveEntity.ToString())); } else { SlaveEntity.UnbindMasterEntityMoving(); SetSlaveEntityMoving(null); } } }
public override void Update() { base.Update(); if (Enabled) { if (SkippedAnimTicks++ > 12) { SkippedAnimTicks = 0; int NewDir = (int)Direction + 1; if (NewDir >= 4) { Direction = (Directions)(4 - NewDir); } else { Direction = (Directions)NewDir; } } GEntity[] Ranges = new GEntity[] { new GEntity(Owner, X, Y + H / 2 - SRange / 2, W, SRange / 2, Directions.Unknown), new GEntity(Owner, X + W / 2, Y, SRange / 2, H, Directions.Unknown), new GEntity(Owner, X, Y + H / 2, W, SRange / 2, Directions.Unknown), new GEntity(Owner, X + W / 2 - SRange / 2, Y, SRange / 2, H, Directions.Unknown) }; List <Player>[] InRangePlayers = new List <Player>[] { GameLevel.GetIntersectingPlayers(Ranges[0], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingPlayers(Ranges[1], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingPlayers(Ranges[2], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingPlayers(Ranges[3], IntersectionType.BY_DIFF_OWNER) }; bool PlayersInRange = false; double MinDist = GameComponent.GetScreenWidth() * GameComponent.GetScreenHeight(); for (int i = 0; i < InRangePlayers.Length; ++i) { InRangePlayers[i].Sort( delegate(Player A, Player B) { return(GetTwoPointsDist(A.X, X, A.Y, Y).CompareTo(GetTwoPointsDist(B.X, X, B.Y, Y))); } ); if (InRangePlayers[i].Count > 0) { double Dist = GetTwoPointsDist(InRangePlayers[i][0].X, X, InRangePlayers[i][0].Y, Y); if (i == 2 || Dist < MinDist) { MinDist = Dist; Direction = (Directions)i; PlayersInRange = true; } } } bool TurretsInRange = false; if (!PlayersInRange) { List <GEntity>[] InRangeTurrets = new List <GEntity>[] { GameLevel.GetIntersectingEntities(Ranges[0], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingEntities(Ranges[1], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingEntities(Ranges[2], IntersectionType.BY_DIFF_OWNER), GameLevel.GetIntersectingEntities(Ranges[3], IntersectionType.BY_DIFF_OWNER) }; MinDist = GameComponent.GetScreenWidth() * GameComponent.GetScreenHeight(); List <GEntity> Turrets = new List <GEntity>(); for (int i = 0; i < InRangeTurrets.Length; ++i) { Turrets.Clear(); foreach (GEntity E in InRangeTurrets[i]) { if (E.Type == EntityType.TURRET && E.Owner != Owner) { Turrets.Add(E); } } Turrets.Sort( delegate(GEntity A, GEntity B) { return(GetTwoPointsDist(A.X, X, A.Y, Y).CompareTo(GetTwoPointsDist(B.X, X, B.Y, Y))); } ); if (Turrets.Count > 0) { double Dist = GetTwoPointsDist(Turrets[0].X, X, Turrets[0].Y, Y); if (Dist < MinDist) { MinDist = Dist; Direction = (Directions)i; TurretsInRange = true; } } } } if (PlayersInRange || TurretsInRange) { Shoot(); } } }
public void SetCoordinates(GEntity Coor) { this.X = Coor.X; this.Y = Coor.Y; }
public void Hand(GEntity e) { DropBindedEntity(); HandedItem = e.GetAsInvItem(); e.Disable(); }
public override void Update() { Shooting = false; UpdateMoving(); UpdateBonuses(); UpdateInventory(); IntersectingTiles = GameLevel.GetIntersectingTiles(this); // Self-destruction, yay! if (GameLevel.Input.Z.Clicked) { Damage(10); } LastUsedInvItem = null; if (GameLevel.Input.Attack.Clicked) { LastUsedInvItem = InvItem.GetPlayersInvItem(Id, CurrentInvItemAKey); LastUsedInvItem.Use(Id); } else { Shooting = false; } if (SkippedAnimTicks++ > 1) { SkippedAnimTicks = 0; if (AnimState++ >= 2) { AnimState = 0; } } if (ReqAngle != 0) { Angle += 6; if (Angle >= ReqAngle) { ReqAngle = 0; Angle = 0; } } // ================= // Dragging entities GEntity Range = null; if (Direction == Directions.Up) { Range = new GEntity(X, Y - 4, W, H); } if (Direction == Directions.Right) { Range = new GEntity(X, Y, W + 8, H); } if (Direction == Directions.Down) { Range = new GEntity(X, Y, W, H + 8); } if (Direction == Directions.Left) { Range = new GEntity(X - 8, Y, W, H); } List <GEntity> InRangeEntities = GameLevel.GetIntersectingEntities(Range); bool PassUnbindTick = false; if (InRangeEntities.Count > 0) { GEntity E = InRangeEntities[0]; if (E.Draggable && E.Owner == Id) { E.HasFocus = true; if (GameLevel.Input.E.Clicked) { DropBindedEntity(); E.BindMasterEntityMoving(this); SetSlaveEntityMoving(E); PassUnbindTick = true; } } } if (!PassUnbindTick && BindingMaster && GameLevel.Input.E.Clicked) { DropBindedEntity(); } GameLevel.ShowGrid = !IsHolding() && BindingMaster && InvItem.GetInvItem(GetSlaveEntityMoving().ToString()).ToString().Equals("inventory-item") || CurrentInvItemAKey != 1; int r = 200; GameLevel.RevealFog(iX - r / 2 + W / 2, iY - r / 2 + H / 2, r); }
public void SetSlaveEntityMoving(GEntity SlaveEntity) { this.BindedSlaveEntityMoving = SlaveEntity; BindingMaster = SlaveEntity != null; }
public void BindMasterEntityMoving(GEntity MasterEntity) { this.BindedMasterEntityMoving = MasterEntity; Enabled = false; BindingSlave = true; }
public virtual void Die(GEntity ContactedWith) { }
public void Remove(GEntity ContactedWith) { Removed = true; Die(ContactedWith); }