private void StartupGame(GameSession session) { session.State = GameState.LoadState; session.Players.ForEach(p => p.State = PlayerState.Loading); try { var mapLoader = new MapFromImageParser(session.SelectedMap); session.MapData = mapLoader.ParseImage(); session.MapHandler = new ServerMap(session); if (session.Players.Count == 1) { AddRace(session, 1, 0, 0); //AddRace(session, 0, 1, 0); //AddRace(session, 2, 2, 1); //AddRace(session, 3, 3, 1); } session.GameLoop = new GameLoop(_gr, session); } catch (Exception ex) { TStuffLog.Error(ex.ToString()); } session.Players.ForEach(p => p.User.Send(RequestNames.GetMapData, session.MapData)); }
public void NewAStar() { var mapData = new MapFromImageParser(new MapModel { FileName = "2_map.png", Cols = 64, Rows = 64 }).ParseImage(); var data = new byte[64, 64]; mapData.Data.OrderBy(p => p.Y).ThenBy(p => p.X).ToList().ForEach(e => { var node = new Node(new Vector2(e.X, e.Y), !e.Block && e.TowerId == null); data[e.X, e.Y] = (byte)(!e.Block && e.TowerId == null?1:0); // Console.WriteLine("Walkable: " + (node.Walkable ? "ja" : "nein")); }); var pathFinder = new PathFinder(data, new PathFinderOptions { Diagonals = false }); var pathList = BuildSpawnListByTeam(mapData); var bm = new Bitmap(64, 64); for (int x = 0; x < 64; x++) { for (int y = 0; y < 64; y++) { bm.SetPixel(x, y, data[x, y] == 1 ? Color.White : Color.Black); } } pathList.ForEach(pr => { var path = pathFinder.FindPath(new Point(pr.Item1.X, pr.Item1.Y), new Point(pr.Item3.X, pr.Item3.Y)); path.ForEach(p => { bm.SetPixel(p.X, p.Y, Color.Blue); output.WriteLine("X: " + p.X + "Y: " + p.Y); }); }); bm.Save("TESTMAP_new.png", ImageFormat.Png); }
public void MapAstarTest() { var mapData = new MapFromImageParser(new MapModel { FileName = "1_map.png", Cols = 55, Rows = 55 }).ParseImage(); var erg = new List <List <Node> >(); mapData.Data.OrderBy(p => p.Y).ThenBy(p => p.X).ToList().ForEach(e => { if (erg.Count - 1 != e.Y) { erg.Add(new List <Node>()); } var node = new Node(new Vector2(e.X, e.Y), !e.Block && e.TowerId == null); erg[e.Y].Add(node); // Console.WriteLine("Walkable: " + (node.Walkable ? "ja" : "nein")); }); var bm = new Bitmap(55, 55); erg.ForEach(l => { l.ForEach(n => { bm.SetPixel(n.Position.X, n.Position.Y, n.Walkable?Color.White:Color.Black); }); }); var astar = new Astar(erg); var path = astar.FindPath(new Vector2(21, 26), new Vector2(25, 22)); path.ForEach(pa => { bm.SetPixel(pa.Position.X, pa.Position.Y, Color.Red); output.WriteLine("X: " + pa.Position.X + "Y: " + pa.Position.Y); }); bm.Save("TESTMAP.png", ImageFormat.Png); }