Пример #1
0
        private void Explode()
        {
            List <GEntity> EntitiesAround = GameLevel.GetIntersectingEntities(ExplosionRange, IntersectionType.BY_DIFF_OWNER);

            foreach (GEntity P in GameLevel.GetIntersectingPlayers(ExplosionRange, IntersectionType.BY_DIFF_OWNER))
            {
                EntitiesAround.Add(P);
            }

            if (EntitiesAround.Count > 0)
            {
                EntitiesAround.Sort(
                    delegate(GEntity A, GEntity B)
                {
                    return(GetTwoPointsDist(A.X, X, A.Y, Y).CompareTo(GetTwoPointsDist(B.X, X, B.Y, Y)));
                }
                    );

                int Damage = MAX_DAMAGE;

                foreach (GEntity E in EntitiesAround)
                {
                    E.Damage(Damage);
                    Damage -= DAMAGE_DELTA;
                }
            }
        }
Пример #2
0
        private void UpdateMoving()
        {
            float Dx = 0.0f;
            float Dy = 0.0f;

            if (GameGuiScreen.IsPlaying())
            {
                if (GameLevel.Input.Left.Down)
                {
                    ReqAngle = (int)Direction * 90;
                    MoveLeft(Speed);
                    Dx = Speed;
                }
                else if (GameLevel.Input.Right.Down)
                {
                    MoveRight(Speed);
                    Dx = -Speed;
                }
                else if (GameLevel.Input.Up.Down)
                {
                    MoveUp(Speed);
                    Dy = Speed;
                }
                else if (GameLevel.Input.Down.Down)
                {
                    MoveDown(Speed);
                    Dy = -Speed;
                }
            }

            if (GameLevel.GetIntersectingEntities(this).Count > 0 || GameLevel.GetIntersectingPlayers(this, IntersectionType.BY_ID).Count > 0)
            {
                X += Dx;
                Y += Dy;
            }

            Moving = Dx != 0 || Dy != 0;
            GameLevel.CenterCameraOnPlayer();

            if (Moving)
            {
                if (Speed < MaxSpeed)
                {
                    Speed += SpeedDelta;
                }
                if (SkippedTrackTicks++ > 2)
                {
                    SkippedTrackTicks = 0;
                    if (TrackState++ >= 2)
                    {
                        TrackState = 0;
                    }
                }
            }
            else
            {
                Speed      = MinSpeed;
                TrackState = 0;
            }
        }
Пример #3
0
 public override void Die()
 {
     foreach (GEntity Tile in GameLevel.GetIntersectingTiles(ExplosionRange))
     {
         if (GameLevel.GetIntersectingEntities(Tile).Count == 0)
         {
             GameLevel.AddParticle(new MineExplosion(Tile.X, Tile.Y));
         }
     }
 }
Пример #4
0
        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();
                }
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        public override void Update()
        {
            if (Direction == Directions.Left)
            {
                MoveLeft(Speed);
            }
            if (Direction == Directions.Right)
            {
                MoveRight(Speed);
            }
            if (Direction == Directions.Up)
            {
                MoveUp(Speed);
            }
            if (Direction == Directions.Down)
            {
                MoveDown(Speed);
            }

            List <GEntity> IntersectingEntities = GameLevel.GetIntersectingEntities(this);

            foreach (GEntity Entity in IntersectingEntities)
            {
                if (!Entity.CanBulletPass)
                {
                    Entity.Damage(BDamage);
                    if (Entity.IsMetallic || Entity.IsBrick)
                    {
                        Remove(Entity);
                    }
                    else
                    {
                        Remove();
                    }
                }
            }

            List <Player> IntersectingEnemies = GameLevel.GetIntersectingPlayers(this, IntersectionType.BY_DIFF_OWNER);

            foreach (Player Enemy in IntersectingEnemies)
            {
                if ((GameLevel.GetMode() == Modes.TeamDeathmatch || GameLevel.GetMode() == Modes.CaptureFlag) && Player.GetTeamById(Enemy.Id) != Player.GetTeamById(Owner))
                {
                    Enemy.Damage(BDamage);

                    if (Player.IsMe(Owner))
                    {
                        ++GameComponent.Gs.IntStatsHits;
                        if (Enemy.Removed)
                        {
                            Player.IncrementKills(Owner);
                        }
                    }
                }

                Remove(Enemy);
            }

            List <Bullet> IntersectingBullets = GameLevel.GetIntersectingBullets(this);

            foreach (Bullet B in IntersectingBullets)
            {
                B.Remove();
                this.Remove();
            }

            // Dispose the memory
            if (X <= 0 || Y <= 0 || X >= GameLevel.MAX_LEVEL_WIDTH || Y >= GameLevel.MAX_LEVEL_HEIGHT)
            {
                Remove();
            }
        }