public static Map GetCustomInstance1() { var width = 5000; var height = 5000; var map = new Map(width, height); var units = new List<GameObject>(); for (int i = 600; i <= 720; i+=60) { for (int j = 600; j <= 720; j += 60) { units.Add(new Interceptor(new Vector2(i+200, j+2100), Allegiance.Player)); units.Add(new Interceptor(new Vector2(i+3000, j+2300), Allegiance.Computer)); } } units.Add(new Interceptor(new Vector2(4000,4000), Allegiance.Computer )); GlobalValues global = GlobalValues.GetInstance(); units.Add(new Asteroid(new Vector2(200,200))); units.Add(new Asteroid(new Vector2(1500, 3000))); units.Add(new Asteroid(new Vector2(1700, 3100))); units.Add(new Asteroid(new Vector2(1600, 3200))); units.Add(new Asteroid(new Vector2(1800, 3300))); units.Add(new Planet(new Vector2(4000, 2600), Allegiance.Computer, PlanetSize.Large, 90)); ((Planet) units[units.Count - 1]).UpgradeStarfleetAcademy(); units.Add(new Planet(new Vector2(4800, 2600), Allegiance.Computer, PlanetSize.Medium, 20)); units.Add(new Planet(new Vector2(4600, 3200), Allegiance.Computer, PlanetSize.Small, 10)); units.Add(new Planet(new Vector2(4100, 3600), Allegiance.Computer, PlanetSize.Small, 10)); units.Add(new Planet(new Vector2(1000, 3000), Allegiance.Player, PlanetSize.Small, 10)); units.Add(new Planet(new Vector2(500, 3500), Allegiance.Player, PlanetSize.Medium, 20)); units.Add(new Planet(new Vector2(1000, 2500), Allegiance.Player, PlanetSize.Medium, 20)); units.Add(new Planet(new Vector2(500, 3000), Allegiance.Player, PlanetSize.Large, 30)); units.Add(new Planet(new Vector2(2000, 3200), Allegiance.Neutral, PlanetSize.Small, global.NeutralPlanetStartValue[PlanetSize.Small])); units.Add(new Planet(new Vector2(1900, 2800), Allegiance.Neutral, PlanetSize.Medium, global.NeutralPlanetStartValue[PlanetSize.Medium])); units.Add(new Planet(new Vector2(2300, 2500), Allegiance.Neutral, PlanetSize.Medium, global.NeutralPlanetStartValue[PlanetSize.Medium])); units.Add(new Planet(new Vector2(3100, 3500), Allegiance.Neutral, PlanetSize.Medium, global.NeutralPlanetStartValue[PlanetSize.Medium])); units.Add(new Planet(new Vector2(2900, 3000), Allegiance.Neutral, PlanetSize.Large, global.NeutralPlanetStartValue[PlanetSize.Large])); // For testing the new Pathfinding for Minions: units.Add(new Interceptor(new Vector2(1000, 4200), Allegiance.Player)); units.Add(new Interceptor(new Vector2(1000, 3650), Allegiance.Player)); units.Add(new Planet(new Vector2(1000, 4000), Allegiance.Player, PlanetSize.Large, 30)); for (double angle = -0.25*Math.PI; angle <= 1.25*Math.PI; angle += 0.3) { Vector2 position = new Vector2(1000 + (float) (250 * Math.Cos(angle)), (float) (4000 - 250 * Math.Sin(angle))); units.Add(new Asteroid(position)); } units.Add(new DeathStar(new Vector2(3500, 1300), Allegiance.Computer, 20)); units.Add(new DeathStar(new Vector2(4500, 1700), Allegiance.Player, 20)); //EDGES // units.Add(new DeathStar(new Vector2(0, 0), Allegiance.Player, 10)); // units.Add(new DeathStar(new Vector2(width, 0), Allegiance.Player, 10)); // units.Add(new DeathStar(new Vector2(0, height), Allegiance.Player, 10)); // units.Add(new DeathStar(new Vector2(width, height), Allegiance.Player, 10)); // One of every Kind units.Add(new Interceptor(new Vector2(1000, 3200), Allegiance.Player)); units.Add(new Defender(new Vector2(1070, 3200), Allegiance.Player)); units.Add(new Predator(new Vector2(1140, 3200), Allegiance.Player)); map.mInitialGameObjects = units; return map; }
/// <summary> /// Returns a map instance with objCount many random-placed interceptors /// </summary> /// <param name="objCount">number of planets to create</param> /// <param name="width">map width</param> /// <param name="height">map height</param> /// <returns>new map instance</returns> public static Map GetRandomInstance2(int objCount, int width, int height) { var map = new Map(width, height); // create randomly game objects on the map var r = new Random(); for (int i = 0; i < objCount; i++) { int x = r.Next(width); int y = r.Next(height); var iceptor = new Interceptor(new Vector2(x, y), Allegiance.Player); map.mInitialGameObjects.Add(iceptor); } return map; }
public static Map GetRandomInstance3(int objCount, int width, int height) { Map map = new Map(width, height); Random r = new Random(); for (int i=0; i<objCount; i++) { int allegianceNo = r.Next(3); Allegiance allegiance = Allegiance.Neutral; switch (allegianceNo) { case 0: allegiance = Allegiance.Player; break; case 1: allegiance = Allegiance.Neutral; break; case 2: allegiance = Allegiance.Computer; break; } int sizeNo = r.Next(3); PlanetSize size = PlanetSize.Medium; switch (sizeNo) { case 0: size = PlanetSize.Small; break; case 1: size = PlanetSize.Medium; break; case 2: size = PlanetSize.Large; break; } int noOfMinions = r.Next(50); int type = r.Next(6); int x = r.Next(width); int y = r.Next(height); Vector2 pos = new Vector2(x, y); GameObject unit = null; switch (type) { case 0: unit = new Asteroid(pos); break; case 1: unit = new DeathStar(pos, allegiance, noOfMinions); break; case 2: unit = new Defender(pos,allegiance); break; case 3: unit = new Interceptor(pos, allegiance); break; case 4: unit = new Planet(pos, allegiance, size, noOfMinions); break; case 5: unit = new Predator(pos, allegiance); break; } if (unit != null) map.mInitialGameObjects.Add(unit); } return map; }
public static Map GetMapFromEditor(Texture2D mapTexture) { const int width = 10000; const int height = 10000; var homeBase = Vector3.Zero; var units = new List<GameObject>(); var size = mapTexture.Width*mapTexture.Height; var scale = new Vector2(1f*width/mapTexture.Width, 1f*height/mapTexture.Height); var colorArray = new Color[size]; mapTexture.GetData(colorArray); var pBase = new Color(0, 255, 0); //green var cBase = new Color(255, 0, 0); //red var nPlanetBig = new Color(0, 0, 255); // blue var nPlanetMed = new Color(255, 0, 128); //pink var nPlanetLil = new Color(0, 255, 255); //cyan var nAsteroid = new Color(255, 255, 0); // yellow for (var x = 0; x < mapTexture.Width; x++) { for (var y = 0; y < mapTexture.Height; y++) { var pos = new Vector2(x, y) * scale; var pixel = colorArray[(mapTexture.Height - y - 1)*mapTexture.Width + x]; if (pixel == nPlanetBig) units.Add(new Planet(pos,Allegiance.Neutral, PlanetSize.Large, GlobalValues.GetInstance().NeutralPlanetStartValue[PlanetSize.Large])); else if (pixel == nPlanetMed) units.Add(new Planet(pos, Allegiance.Neutral, PlanetSize.Medium, GlobalValues.GetInstance().NeutralPlanetStartValue[PlanetSize.Medium])); else if (pixel == nPlanetLil) units.Add(new Planet(pos, Allegiance.Neutral, PlanetSize.Small, GlobalValues.GetInstance().NeutralPlanetStartValue[PlanetSize.Small])); else if (pixel == nAsteroid) units.Add(new Asteroid(pos)); else if (pixel == pBase) { homeBase = new Vector3(pos, 1800); units.Add(new Planet(pos, Allegiance.Player, PlanetSize.Large, 100)); } else if (pixel == cBase) units.Add(new Planet(pos, Allegiance.Computer, PlanetSize.Large, 100)); } } var map = new Map(width, height); map.mInitialGameObjects = units; map.mHomeBase = homeBase; return map; }
/// <summary> /// Returns a map instance with objCount many random-placed planets /// </summary> /// <param name="objCount">number of planets to create</param> /// <param name="width">map width</param> /// <param name="height">map height</param> /// <returns>new map instance</returns> public static Map GetRandomInstance(int objCount , int width , int height) { var map = new Map(width, height); // create randomly game objects on the map var r = new Random(); for (int i = 0; i<objCount; i++) { int x = r.Next(width); int y = r.Next(height); var planet = new Planet(new Vector2(x, y), Allegiance.Player, PlanetSize.Large, 100); map.mInitialGameObjects.Add(planet); } return map; }
/// <summary> /// Sets the map. Please prefer using LoadMap(), as this method will not /// initialise neither navigation mesh nor collision manager! /// </summary> /// <param name="map"></param> public void SetMap(Map map) { mMap = map; if (map != null) SectorManager = new UnitSectorManager(map.GetWidth(), map.GetHeight()); else { SectorManager = null; } }
/// <summary> /// Loads a map to start a new game. This method is just an abbreviation for /// GameLogic.GetInstance().GetGameStateManager().LoadMap(map); /// </summary> /// <param name="map">the map to load</param> public void LoadMap(Map map) { mGameStateManager.LoadMap(map); }
/// <summary> /// Initializes game from a given map /// </summary> /// <returns>returns true if successful, else false</returns> public void LoadMap(Map map) { UnloadGame(); GameLogic gameLogic = GameLogic.GetInstance(); gameLogic.SetMap(map); // already initialised sectorManager by setting new map //gameLogic.SectorManager = new UnitSectorManager(map.GetWidth(), map.GetHeight()); CollisionManager collisionManager = new CollisionManager(); collisionManager.Init(); gameLogic.SetCollisionManager(collisionManager); gameLogic.SuperFogManager = new SuperFogManager(); PlayerFogManager playerFogManager = new PlayerFogManager(); playerFogManager.Init(); gameLogic.SuperFogManager.PlayerFogManager = playerFogManager; PcFogManager pcFogManager = new PcFogManager(); pcFogManager.Init(); gameLogic.SuperFogManager.PcFogManager = pcFogManager; GameObjectManager objectManager = GameObjectManager.GetInstance(); IEnumerable<GameObject> list = map.GetGameObjects(); foreach (GameObject obj in list) { objectManager.AddUnit(obj); } Debug.Assert(map != null); PathFinder.GetInstance().LoadMeshFromObstructions(map.GetWidth(), map.GetHeight(), GlobalValues.GetInstance().MeshScale); // hinzugefügt von jonas (ka ob das wo besser passt) view.HumanView.GetInstance().GetRenderer().GetCamera().SetBoundaries(new Rectangle(0, 0, map.GetWidth(), map.GetHeight())); }
// ReSharper restore UnusedMember.Local // ReSharper disable UnusedMember.Local // Sometimes I want to call this test for debugging, so it's okay that it's currently // not used. private static void ModifyMeshTest() { /*{ PathFinder.GetInstance().ClearObstructions(); int oldScale = GlobalValues.GetInstance().MeshScale; GlobalValues.GetInstance().MeshScale = 1; Map map1 = new Map(6, 6); GameLogic.GetInstance().SetMap(map1); NavigationMesh mesh = NavigationMesh.GetTestInstance(1, 1, 6, 6, false); mesh.CheckIntegrity(); PathFinder.GetInstance().SetMesh(mesh); Obstruction obstruction = new Obstruction(new Vector2(3, 3), 0); PathFinder.GetInstance().AddObstruction(obstruction); mesh = PathFinder.GetInstance().GetMesh(); mesh.CheckIntegrity(); PathFinder.GetInstance().RemoveObstruction(obstruction); mesh = PathFinder.GetInstance().GetMesh(); mesh.CheckIntegrity(); GlobalValues.GetInstance().MeshScale = oldScale; GameLogic.GetInstance().GetGameStateManager().UnloadGame(); } // ******************* Next test *********************** { PathFinder.GetInstance().ClearObstructions(); int oldScale = GlobalValues.GetInstance().MeshScale; GlobalValues.GetInstance().MeshScale = 1; Map map2 = new Map(8, 8); GameLogic.GetInstance().SetMap(map2); List<MeshNode> nodes = new List<MeshNode>(); List<Polygon> polygons = new List<Polygon>(); polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 0, 3, 3), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 0, 2, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 0, 3, 3), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 2, 2, 1), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 3, 2, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(2, 3, 1, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 3, 2, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 3, 1, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(6, 3, 2, 2), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 5, 3, 3), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 5, 2, 1), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 5, 3, 3), nodes, polygons)); polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 6, 2, 2), nodes, polygons)); foreach (Polygon p in polygons) p.ImposeOwnership(); NavigationMesh mesh = new NavigationMesh(polygons, 8, 8); PathFinder.GetInstance().SetMesh(mesh); mesh.CheckIntegrity(); PathFinder.GetInstance().AddObstruction(new Obstruction(new Vector2(4, 4), 0)); mesh = PathFinder.GetInstance().GetMesh(); mesh.CheckIntegrity(); List<MeshNode> singleUsedMeshNodes = new List<MeshNode>(); foreach (Polygon p in mesh.GetPolygons()) { foreach (MeshNode m in p.GetNodes()) { if (m.mPolyOwners.Count < 2) singleUsedMeshNodes.Add(m); } } Debug.Assert(singleUsedMeshNodes.Count == 4); GlobalValues.GetInstance().MeshScale = oldScale; GameLogic.GetInstance().GetGameStateManager().UnloadGame(); } // ******************* Next test *********************** { }*/ // ******************* Next test *********************** { PathFinder.GetInstance().ClearObstructions(); int width = 5000; int height = 5000; Map map = new Map(width, height); NavigationMesh[] mesh = NavigationMeshFactory.GetTestInstance(500, 500, 10, 10, false); PathFinder.GetInstance().SetMesh(mesh); GameLogic.GetInstance().SetMap(map); Random random = new Random(); List<Planet> planetList = new List<Planet>(); Debug.WriteLine("ModifyMeshTest will add obstructions with "+GlobalValues.GetInstance().MeshScale+" granularity..."); for (int i = 0; i < 10; i++) { sParent.DrawNow(); int x = random.Next(width+1); int y = random.Next(height+1); int planetSizeInt = random.Next(3); PlanetSize planetSize = PlanetSize.Small; switch (planetSizeInt) { case 0: planetSize = PlanetSize.Small; break; case 1: planetSize = PlanetSize.Medium; break; case 2: planetSize = PlanetSize.Large; break; } if (i == 2) Debug.WriteLine("Achtung!"); Planet planet = new Planet(new Vector2(x, y), Allegiance.Player, planetSize, 0); GameObjectManager.GetInstance().AddUnit(planet); planetList.Add(planet); Debug.WriteLine("----- "+i+"th added."); } Debug.WriteLine("Adding obstructions finished. Now removing them..."); foreach (Planet p in planetList) { GameObjectManager.GetInstance().RemoveGameObject(p); Debug.WriteLine("---One removed.---"); } //GameObjectManager.GetInstance().AddUnit(new Interceptor(new Vector2(3700, 2000), Allegiance.Player)); GameLogic.GetInstance().GetGameStateManager().UnloadGame(); } }
private static void GetNearestFreeNodesTest() { PathFinder.GetInstance().ClearObstructions(); int oldScale = GlobalValues.GetInstance().MeshScale; GlobalValues.GetInstance().MeshScale = 1; Map map = new Map(500, 500); Vector2 obstructionPos = new Vector2(250,250); PathFinder.GetInstance().AddObstruction(new Obstruction(obstructionPos, 9)); GameLogic.GetInstance().SetMap(map); PathFinder.GetInstance().LoadMeshFromObstructions(500, 500, 1); List<MeshNode> nodes = PathFinder.GetInstance().GetNearestFreeNodes(obstructionPos, typeof (Minion)); foreach(MeshNode node in nodes) { double distance = HelperMethods.EuklidDistance(node.mVector, obstructionPos); Debug.Assert(distance <= 11); } Debug.WriteLine("GetNearestFreeNodesTest done."); GlobalValues.GetInstance().MeshScale = oldScale; GameLogic.GetInstance().GetGameStateManager().UnloadGame(); }