Esempio n. 1
0
 public override void move()
 {
     if (!TemporarilyDead)
     {
         if (CurrentPickup != null)
         {
             //change "State" of the Pickup, to implement single use, cooldown and so on
             CurrentPickup = CurrentPickup.interactWithFighter(this);
         }
         CurrentState.move();
     }
     else
     {
         if (CurrentRespawnCycleTime-- < 0)
         {
             CurrentRespawnCycleTime = RespawnTime;
             TemporarilyDead         = false;
             IsFiring      = true;
             CurrentPickup = new ShieldPickup(0, 0, TheGame);
             HP            = 100;
         }
         CurrentState.move();
     }
 }
Esempio n. 2
0
        public override void move()
        {
            if (CurrentPickup != null)
            {
                //change "State" of the Pickup, to implement single use, cooldown and so on
                CurrentPickup = CurrentPickup.interactWithFighter(this);
            }

            GameObject target         = null;
            GameObject targetPickup   = null;
            double     distance2Enemy = 10000000000;
            double     dx             = 0;
            double     dy             = 0;
            double     d               = 1;
            int        Enemyindex      = -1;
            double     distance2PickUp = 1000000000000;
            int        PickupIndex     = -1;
            double     dPickup         = 1;
            double     dxPickup        = 0;
            double     dyPickup        = 0;
            GameObject element;

            lock (TheGame.GameElementListLock)
                for (int i = 0; i < TheGame.GameElements.Count; i++)
                {
                    element = TheGame.GameElements[i];
                    if (element is Fighter)
                    {
                        if (((Fighter)element).Team == this.Team)
                        {
                            continue;
                        }

                        dx = element.X - this.X;
                        dy = element.Y - this.Y;
                        d  = Math.Sqrt(dx * dx + dy * dy);
                        if (d < distance2Enemy)
                        {
                            distance2Enemy = d;
                            Enemyindex     = i;
                        }
                    }
                }
            lock (TheGame.PickupListLock)
                for (int i = 0; i < TheGame.PickupElements.Count; i++)
                {
                    element = TheGame.PickupElements[i];
                    if (element is PickUp)
                    {
                        dxPickup = element.X - this.X;
                        dyPickup = element.Y - this.Y;
                        dPickup  = Math.Sqrt(dx * dx + dy * dy);
                        if (dPickup < distance2PickUp)
                        {
                            distance2PickUp = dPickup;
                            PickupIndex     = i;
                        }
                    }
                }
            if (Enemyindex != -1)
            {
                target = TheGame.GameElements[Enemyindex];
                shoot(target.X, target.Y);


                dx = target.X - this.X;
                dy = target.Y - this.Y;
                d  = Math.Sqrt(dx * dx + dy * dy);
            }
            if (PickupIndex != -1)
            {
                targetPickup = TheGame.PickupElements[PickupIndex];

                dxPickup = targetPickup.X - this.X;
                dyPickup = targetPickup.Y - this.Y;
                dPickup  = Math.Sqrt(dxPickup * dxPickup + dyPickup * dyPickup);
            }
            //include Randomness

            /*if(Lucky.Next(0,100) < Randomness)
             * {
             *
             *  if (Lucky.Next(0, 10) < 0)
             *      this.X += Lucky.Next(-1, 1) * speed;
             *  else
             *      this.Y += Lucky.Next(-1, 1) * speed;
             * }
             * else
             * {*/
            if (distance2PickUp < distance2Enemy)
            {
                this.X += (int)(dxPickup / dPickup * speed);
                this.Y += (int)(dyPickup / dPickup * speed);
            }
            else
            {
                if (HP > 80)
                {
                    this.X += (int)(dx / d * speed);
                    this.Y += (int)(dy / d * speed);
                }
                else
                {
                    //don't run away, but try to get the pickup
                    //this.X -= (int)(dx / d * speed);
                    //this.Y -= (int)(dy / d * speed);
                    this.X += (int)(dxPickup / dPickup * speed);
                    this.Y += (int)(dyPickup / dPickup * speed);
                }
            }
            // }
        }