Example #1
0
        public virtual void Update()
        {
            if (!Active)
            {
                return;
            }
            if (_expireTicks <= 0)
            {
                Active = false;
                return;
            }
            _expireTicks--;

            if (Tracking > 0 && Target != null && Target.Active)
            {
                var newHeading = (float)Utils.AngleBetweenPoints(Center, Target.CenterPoint);

                // adjust heading to cover 180 to -180 (<-)
                var adjustHeading    = (Heading < -90);
                var adjustNewHeading = (newHeading < -90);
                var angle            = Heading + (adjustHeading ? 360 : 0);
                var newAngle         = newHeading + (adjustNewHeading ? 360 : 0);
                var diff             = angle - newAngle;
                if (diff < 0)
                {
                    angle = angle + Tracking;
                    if (angle > newAngle)
                    {
                        angle = newAngle;
                    }
                }
                else if (diff > 0)
                {
                    angle = angle - Tracking;
                    if (angle < newAngle)
                    {
                        angle = newAngle;
                    }
                }

                // restore heading
                Heading = (adjustHeading ? angle - 360 : angle);
            }

            // move towards the target
            var newPoint = Utils.GetNewPoint(Center, Speed, Heading);

            LastPoint     = PreviousPoint;
            PreviousPoint = Center;
            Center        = newPoint;

            // check for collisions
            if (Target != null && Target.Active && Target.Bounds.Contains(Center))
            {
                Target.Damage(Damage, Team);
                _game.OnGameEvent(Target, EGameEventType.MissileHit);
                Active = false;
            }
        }
Example #2
0
        private void Map_MouseClick(object sender, MouseEventArgs e)
        {
            var mousePos = PointToClient(MousePosition);

            foreach (var s in _game.Map.Sectors)
            {
                if (s.Bounds.Contains(mousePos))
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        _game.OnGameEvent(s, EGameEventType.SectorLeftClicked);
                    }
                    if (e.Button == MouseButtons.Right)
                    {
                        _game.OnGameEvent(s, EGameEventType.SectorRightClicked);
                    }
                    return;
                }
            }
        }
Example #3
0
 private void Info_DoubleClick(object sender, System.EventArgs e)
 {
     _game.OnGameEvent(Pilot, EGameEventType.ShipClicked);
     SoundEffect.Play(ESounds.mousedown);
 }