コード例 #1
0
        public Ship(int[] points, int size, Point startPosition, int direction, int speed, Color color) : base()
        {
            Points          = points;
            Size            = size;
            CurrentPosition = startPosition;
            CurrentAngle    = direction;
            CurrentSpeed    = speed;
            Brush           = new SolidBrush(color);

            WhoCollides.Add(typeof(Asteroid));
            Life = 10;
        }
コード例 #2
0
        public void DidCollide(Element target)
        {
            if (WhoCollides.Contains(target.GetType()))
            {
                if (DistanceBetweenTwoElements(target) <= (target.Size + Size))
                {
                    target.Life--;
                    Life--;

                    Ship     s = null;
                    Asteroid a = null;

                    if (target.GetType() == typeof(Asteroid))
                    {
                        a = (Asteroid)target;
                    }
                    else if (target.GetType() == typeof(Ship))
                    {
                        s = (Ship)target;
                    }
                    else if (target.GetType() == typeof(Shoot))
                    {
                        s = ((Shoot)target).Origin;
                    }

                    if (GetType() == typeof(Asteroid))
                    {
                        a = (Asteroid)this;
                    }
                    else if (GetType() == typeof(Ship))
                    {
                        s = (Ship)this;
                    }
                    else if (GetType() == typeof(Shoot))
                    {
                        s = ((Shoot)this).Origin;
                    }

                    if (s != null && a != null)
                    {
                        if (!a.IsAlive)
                        {
                            s.UpdateScore(a.Size + (int)(a.CurrentSpeed * 10));
                        }
                    }
                }
            }
        }
コード例 #3
0
        public Asteroid(int[] points, int size, Point startPosition, int direction, int speed, Color color) : base()
        {
            Points          = points;
            Size            = size;
            CurrentPosition = startPosition;
            CurrentAngle    = direction;
            CurrentSpeed    = speed;

            Brush     = new SolidBrush(color);
            FontBrush = new SolidBrush(Color.Black);

            WhoCollides.AddRange(new[]
            {
                typeof(Shoot),
                typeof(Ship)
            });
            Life = size / 10;
        }
コード例 #4
0
        public Shoot(Ship origin, int size, Point startPosition, int direction, float speed, Color color, int timeToLive) : base()
        {
            Size         = size;
            CurrentAngle = direction;
            CurrentSpeed = speed;
            Brush        = new SolidBrush(color);
            LifeTime     = timeToLive;

            startPosition.X -= size / 2;
            startPosition.Y -= size / 2;

            CurrentPosition = startPosition;

            Origin = origin;

            WhoCollides.Add(typeof(Asteroid));
            Life = 1;
        }