public void HandleCollisionPlanet(Planet planet) { //if (planet.ID != Destination.ID && planet.ID != Origin.ID) //{ // var d = Position - planet.Position; // Velocity += (3f / ObjectSize) * d / (d.LengthSquared() + 1); // var r = Position - lastPosition; // LocalOrientation = r.ToAngle(); // Colliding = true; //} }
public void Spawn() { GeneratePositions(); Console.WriteLine("Positions created: " + PositionsCreated); for (int i = TeamManager.teams.Count; i < PositionsCreated; i++) { Planet planet = new Planet(Positions[i], Color.White, sizeMultipliers[i], PlanetIDs[i], null); EntityManager.Add(planet); } }
public void AddHomePlanets(Planet[] homePlanets) { int i = 0; foreach (Planet planet in homePlanets) { Positions[i] = planet.Position; sizeMultipliers[i] = 1.0f; EntityManager.Add(planet); i++; } PositionsCreated = i; }
public static void sendShips(Team team, float percentageOfShips, Planet origin, Planet destination) { if (origin.ID != destination.ID) { int TotalShips = TeamManager.teamShipCount[0] + TeamManager.teamShipCount[1]; float value = (float)Math.Pow((double)(.0001f * TotalShips), (double)2) + 1; // this should be a log/exponential function so we can cap how many ships go out... need help implementing. int numShips = (int)(origin.shipCount * percentageOfShips*(1/value)); if (numShips <= 0) { numShips = 1; } if (numShips >= origin.shipCount) { numShips = (int)Math.Floor((double)origin.shipCount); for (int i = 0; i < numShips; i++) { Ship ship = new Ship(team, origin, destination, 1); EntityManager.Add(ship); } } else { if (value < origin.shipCount) { for (int i = 0; i < numShips; i++) { Ship ship = new Ship(team, origin, destination, value); EntityManager.Add(ship); } } else { for (int i = 0; i <origin.shipCount; i++) { Ship ship = new Ship(team, origin, destination, 1f); EntityManager.Add(ship); } } } } }
public static void GenerateTeams(LevelSpawner level, int n) { for (int i = 0; i < n; i++) teams.Add(new Team(i)); Team.GenerateHomePositions(n); int j = 0; Planet[] homePlanets = new Planet[n]; foreach (Team team in TeamManager.teams) { homePlanets[j] = team.getHomePlanet(); j++; } level.AddHomePlanets(homePlanets); }
//Texture2D markerImage; public Ship(Team team, Planet sourcePlanet, Planet destinationPlanet,float value) { image = Art.Ship; Radius = 8; Team = team; Direction = destinationPlanet.Position - sourcePlanet.Position; color = team.getColor(); ObjectSize = 0.65f; Value = value; spawnRadius = sourcePlanet.Radius + Radius; Destination = destinationPlanet; Origin = sourcePlanet; //Colliding = true; GeneratePosition(sourcePlanet.Position, destinationPlanet.Position); //getDirection(Position, Destination.Position); //getDirection(); Origin.shipCount -= Value; planetsNotCrossed = planetsNotCrossed.Where(planet => planet.ID != sourcePlanet.ID).ToList(); GeneratePathPoints(); //markerImage = Art.Marker; //pathPoints.ReconstructPath(sourcePlanet, destinationPlanet, 250); }
public static void ReconstructPath(this List<Vector2> list, Planet source, Planet destination, int n) { bool reverse = false; if (source.Position.X > destination.Position.X) reverse = true; if (reverse) list.Reverse(); //#region Bezier Curve //BezierCurve bc = new BezierCurve(); //List<float> tempList = new List<float>(); //for (int i = 0; i < list.Count; i++) //{ // tempList.Add(list[i].X); // tempList.Add(list[i].Y); //} //list.Clear(); //list.TrimExcess(); //int POINTS_ON_CURVE = n; //float[] ptind = new float[tempList.Count]; //float[] p = new float[POINTS_ON_CURVE]; //tempList.CopyTo(ptind, 0); //bc.Bezier2D(ptind, (POINTS_ON_CURVE) / 2, p); //for (int i = 1; i < POINTS_ON_CURVE - 1; i += 2) // list.Add(new Vector2(p[i + 1], p[i])); //#endregion #region Spline Stuff float xDistance = Math.Abs(list.First().X - list.Last().X); float[] x = list.ExtractValues('x'); float[] y = list.ExtractValues('y'); list.Clear(); list.TrimExcess(); int nInterpolated = (int)(xDistance / 5); float[] xs = new float[nInterpolated]; for (int i = 0; i < nInterpolated; i++) xs[i] = ((float)i / (float)(nInterpolated - 1)) * xDistance + x[0]; CubicSpline spline = new CubicSpline(); float[] ys = spline.FitAndEval(x, y, xs, Single.NaN, Single.NaN, false); for (int j = 0; j < nInterpolated; j++) { Vector2 point = new Vector2(xs[j], ys[j]); foreach (Planet planet in EntityManager.planets) { if (planet.ID != source.ID && planet.ID != destination.ID) { if ((point - planet.Position).LengthSquared() < 2.25f * planet.Radius * planet.Radius) { Vector2 direction = point - planet.Position; direction.Normalize(); point = new Vector2(planet.Position.X + (direction * 1.5f * planet.Radius).X, planet.Position.Y + (direction * 1.5f * planet.Radius).Y); } } } list.Add(point); } if (reverse) list.Reverse(); #endregion }
private void getNextPosition(Vector2 position, Vector2 dest, Planet origin, Planet destination) { Vector2 finalPoint = dest; Planet finalPlanet = destination; foreach (Planet planet in planetsNotCrossed) { Rectangle bound = new Rectangle(position.X < dest.X ? (int)(position.X - 50) : (int)(dest.X - 50), position.Y < dest.Y ? (int)(position.Y - 50) : (int)(dest.Y - 50), (int)Math.Abs(position.X - dest.X) + 100, (int)Math.Abs(position.Y - dest.Y) + 100); if (planet.ID != destination.ID && planet.ID != origin.ID && planet.Position.X > bound.Left && planet.Position.X < bound.Right && planet.Position.Y > bound.Top && planet.Position.Y < bound.Bottom) { float slope = (dest.Y - position.Y) / (dest.X - position.X); float b2 = (-1 / slope) * (-planet.Position.X) + planet.Position.Y; float b1 = slope * (-position.X) + position.Y; float y = (slope * slope * b2 + b1) / (1 + slope * slope); float x = -slope * (y - b2); Vector2 possiblePoint = new Vector2(x, y); if ((possiblePoint - planet.Position).LengthSquared() < (planet.Radius + 2 * Radius) * (planet.Radius + 2 * Radius)) { int randomSide = rand.Next(0, 100); Vector2 direction = new Vector2(0, 0); if (randomSide % 2 == 0) direction = possiblePoint - planet.Position; else if (randomSide % 2 == 1) direction = planet.Position - possiblePoint; direction.Normalize(); Vector2 moreLikelyPoint = new Vector2(planet.Position.X + (direction * (planet.Radius + 2 * Radius)).X, planet.Position.Y + (direction * (planet.Radius + 2 * Radius)).Y); if ((moreLikelyPoint - position).LengthSquared() < (finalPoint - position).LengthSquared()) { finalPoint = moreLikelyPoint; finalPlanet = planet; } } } } if (finalPoint != dest) { nextPosition = finalPoint; nextPlanet = finalPlanet; getNextPosition(position, nextPosition, origin, nextPlanet); } else { if (dest != Destination.Position) { checkingAhead = true; pathPoints.Add(nextPosition); planetsNotCrossed = planetsNotCrossed.Where(planet => planet.ID != destination.ID).ToList(); Origin = destination; } else checkingAhead = false; } }
//we may want to implement a a team manager that can keep track of these things. but maybe here will be ok too. public static void addPlanet(Team t, Planet p) { t.planetsColonized.Add(p); }
public static void removePlanet(Team t, Planet p) { List<Planet> planet = t.planetsColonized.Where(x => x.ID == p.ID).ToList(); t.planetsColonized.Remove(planet[0]); }