示例#1
0
        public override void Update()
        {
            if (Enabled)
            {
                base.Update();

                List <Player> PlayersInRange = GameLevel.GetIntersectingPlayers(EntityRange, IntersectionType.BY_EQUAL_OWNER);

                if (SkippedRenewTicks++ > SKIP_RENEW_TICKS)
                {
                    SkippedRenewTicks = 0;
                    foreach (Player P in PlayersInRange)
                    {
                        if (P.Health < P.MaxHealth)
                        {
                            P.Heal(1);
                            --Energy;
                            GameLevel.AddParticle(new DispenseBeam(this, P, DispenseBeamType.Heal));
                        }

                        if (P.Ammunition < P.MAX_AMMUNITION)
                        {
                            P.AddAmmunition(1);
                            --Energy;
                            GameLevel.AddParticle(new DispenseBeam(this, P, DispenseBeamType.Ammunition));
                        }
                    }
                }

                if (Energy <= 0)
                {
                    Remove();
                }
            }
        }
示例#2
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;
                }
            }
        }
示例#3
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;
            }
        }
示例#4
0
        public override void Update()
        {
            base.Update();

            int offset = 15;

            List <Player> IntersectingPlayers = GameLevel.GetIntersectingPlayers(new GEntity(X - offset / 2, Y - offset / 2, W + offset, H + offset));

            foreach (Player player in IntersectingPlayers)
            {
                if (player.Team != Team)
                {
                    player.Hand(this);
                }
                else if (player.Team == Team && player.IsHolding())
                {
                    GameLevel.Score.Increment(player.Team);
                    player.StopHolding();
                }
            }
        }
示例#5
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();
                }
            }
        }
示例#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();
            }
        }