示例#1
0
 private bool empty(Vector2 test)
 {
     foreach (var cellother in cells)
     {
         if (Tool.distance(test, new Vector2(cellother.X, cellother.Y)) < 0.5f)
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
 /// <summary>
 /// This method returns a cell if the vector loc is close to it.
 /// </summary>
 /// <param name="x"> x quardnant </param>
 /// <param name="y"> y quardnat </param>
 /// <returns> The cell that covers the point, null in there is no cell. </returns>
 public Cell CellIntercect(Vector2 loc, int scale = 1, float buff = 0.5f)
 {
     foreach (var cell in cells)
     {
         if (Tool.distance(cell.Location(), loc) <= CellSize * buff * scale)
         {
             return(cell);
         }
     }
     return(null);
 }
示例#3
0
        public void update(PickupManager pickUps, Ship player, PlanetColecction planets)
        {
            for (int i = 0; i < roids.Count; i++)
            {
                roids[i].Update();

                // calculate force of gravity
                roids[i].setAcceleration(new Vector2(0, 0));
                float disPlanet = float.MaxValue; // distance to closest planet;
                foreach (var planet in planets.Planets)
                {
                    float disP = Tool.distance(roids[i].Locaion, planet.Position);
                    if (disPlanet > disP)
                    {
                        disPlanet = disP;
                    }
                    if (Tool.magnitude(roids[i].Acceleration) < 10f)
                    {
                        Vector2 planetAcel = Tool.getPlanetGravity(planet, roids[i].Locaion, roids[i].Mass);
                        roids[i].addAcceleration(planetAcel);
                    }
                }

                float distancePlayer = Tool.distance(roids[i].Locaion, player.Locaion);

                // test damage
                if (distancePlayer < 1000f)
                {
                    for (int j = 0; j < player.Shot.Count; j++)
                    {
                        float distanceShot = Tool.distance(roids[i].Locaion, player.Shot[j].Location);

                        if (distanceShot < roids[i].Size * roids[i].CellSize * 1.5f)
                        {
                            if (roids[i].testHit(player.Shot[j].Location, player.Shot[j].Damage, pickUps))
                            {
                                player.removeShot(j);
                                j--;
                            }
                        }
                    }
                }

                if (!roids[i].Live || disPlanet > 80000f)
                {
                    roids.RemoveAt(i);
                    i--;
                    continue;
                }
            }
        }
示例#4
0
        public void Update(PickupManager pickups)
        {
            UpdateMovement();

            if (shotCooldown > 0)
            {
                shotCooldown--;
            }

            for (int i = 0; i < Shot.Count; i++)
            {
                Shot[i].Update();
                if (Shot[i].Life < 0)
                {
                    Shot.RemoveAt(i);
                    i--;
                }
            }

            if (usedCargo < cargo)
            {
                for (int i = 0; i < pickups.Count; i++)
                {
                    float distance = Tool.distance(location, pickups.Index(i).Location);
                    if (distance < 50)
                    {
                        addItem(pickups.CollectAt(i));
                        continue;
                    }

                    if (distance < 400)
                    {
                        pickups.Index(i).MoveTo(Locaion, 10f);
                    }
                }
            }
        }