示例#1
0
文件: Enemy.cs 项目: Zhangerr/azsh
 public static void spawnWave()
 {
    
     Rectangle bounds = Program.theGame.Window.ClientBounds;
     Random r = new Random();//need at the beginning for diff seed value ^_^
     for (int i = 0; i < 360; i += r.Next(13, 20))
     {
         if (enemies.Count > 10)
         {
             return;
         }
         int multiply = new Random().Next(20, 100);
        /* if (bounds.Width > bounds.Height)
         {
             multiply = bounds.Width;
         }
         else
         {
             multiply = bounds.Height;
         }*/
         double radians = MathHelper.ToRadians(i);
         Vector2 unit = new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians));
         unit *= multiply;
     //    Console.WriteLine(new Random().Next(bounds.Width));
         unit += new Vector2(r.Next(bounds.Width), r.Next(bounds.Height));
    //     Console.WriteLine(unit.X);
         Enemy e = new Enemy(radians, Color.Red, unit, 10, r.Next(1,2), r.Next(8,15));
         enemies.Add(e);
         
     }
 }
示例#2
0
文件: Bullet.cs 项目: Zhangerr/azsh
        public void update()
        {
            if (!Program.theGame.Window.ClientBounds.Contains((int)pos.X + Program.theGame.Window.ClientBounds.X, (int)pos.Y + Program.theGame.Window.ClientBounds.Y))
            {
                Bullet.toremove.Add(this);
            }
            Vector2 vec = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            if (lockOn == null && !found && tracking)
            {
                float smallest = float.MaxValue;
                Enemy temp = null;
                foreach (Enemy e in Enemy.enemies)
                {

                    float theDist = Vector2.Distance(e.pos, pos);
                    if (smallest > theDist)
                    {
                        smallest = theDist;
                        temp = e;
                    }

                }
                lockOn = temp;
                found = true;
            }
            if (lockOn != null && tracking)
            {
                if (lockOn.health > 0)
                {
                    Vector2 tocalc = new Vector2(pos.X - lockOn.pos.X, pos.Y - lockOn.pos.Y);
                      
                    tocalc.Normalize();
                    tocalc *= 5;
                    
                    if (!initi)
                    {
                        tocalc = Vector2.Lerp(inertia, tocalc, .03f);
                    }
                    else
                    {
                        inertia = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                        inertia *= (int)speed;
                        tocalc = Vector2.Lerp(inertia, tocalc, .01f);
                        initi = false;
                    }
                    angle = Math.Atan2(tocalc.Y, tocalc.X);
                 /*   inertia += tocalc;
                    if (inertia.X > inertiafact)
                    {
                        inertia.X = inertiafact;
                    }
                    if (inertia.X < -inertiafact)
                    {
                        inertia.X = -inertiafact;
                    }
                    if (inertia.Y > inertiafact)
                    {
                        inertia.Y = inertiafact;
                    }
                    if (inertia.Y < -inertiafact)
                    {
                        inertia.Y = -inertiafact;
                    }*/
                    pos -= tocalc;
                    //pos -= inertia;
                    inertia = tocalc;
                    
                 //   double angle2 = Math.Atan2(pos.Y, pos.X);
                  //  Console.WriteLine();
                //    Console.WriteLine(angle);
                }
                else
                {
                    lockOn = null;
                    found = false;
                }
            }
            else
            {
                pos -= (vec * (int)speed);
            }
        }