/// <summary> /// recupere un block de font /// </summary> /// <param name="bx"></param> /// <param name="by"></param> /// <returns>peut etre null</returns> public Block GetBackBlock(int bx, int by) { Chunk chunk = GetBlockBackChunk(bx, by); if (chunk == null) { backChunks.Add(GenerateurParDefault.Convert(bx) + "/" + GenerateurParDefault.Convert(by), new Chunk(new Block[16, 16], true)); chunk = GetBlockBackChunk(bx, by); } int tx = bx % 16; int ty = by % 16; if (bx < 0) { tx += 15; } if (by < 0) { ty += 15; } return(chunk.GetBlock(tx, ty)); }
/// <summary> /// place un block dans le font /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="block"></param> public void SetBackBlock(int x, int y, Block block) { Chunk chunk = GetBlockBackChunk(x, y); int tx = x % 16; int ty = y % 16; if (x < 0) { tx += 15; } if (y < 0) { ty += 15; } if (chunk == null) { chunk = new Chunk(new Block[16, 16], true); backChunks.Add(GenerateurParDefault.Convert(x) + "/" + GenerateurParDefault.Convert(y), chunk); } chunk.SetBlock(tx, ty, block); }
/// <summary> /// Permet de Charger un monde</br> /// System.IO.Directory.GetCurrentDirectory() pour recuperer le dossier de l'application</br> /// le monde recuperer (si le dossier du monde exists) il sera dans Sauvegarde.monde</br> /// le joueur sera initer avec le monde /// </summary> /// <param name="path"></param> public static void ChargerMonde(string path) { if (Directory.Exists(path)) { string[] mondeOptions = File.ReadAllLines(path + "\\info.txt"); long seed = long.Parse(mondeOptions[1].Split(':')[1]); Generateur generateur = null; switch (mondeOptions[0].Split(':')[1]) { case "GenerateurParDefault": generateur = new GenerateurParDefault(new Noise(seed)); break; case "VoidGenerateur": generateur = new VoidGenerateur(new Noise(seed)); break; case "FlatGenerateur": generateur = new FlatGenerateur(new Noise(seed)); break; } if (generateur != null) { string[] ents = Directory.GetDirectories(path + "\\Entities"); int max = -1; List <KeyValuePair <int, Entite> > entities = new List <KeyValuePair <int, Entite> >(); foreach (string entpath in ents) { string[] n = entpath.Split('\\'); string[] a = n[n.Length - 1].Split('.'); Entite ent = Entite.Entites()[a[1]].Charger(entpath); int i = int.Parse(a[0]); if (i > max) { max = i; } entities.Add(new KeyValuePair <int, Entite>(i, ent)); if (ent is Joueur j) { joueur = j; } } Entite[] entites = new Entite[max + 1]; foreach (KeyValuePair <int, Entite> ent in entities) { entites[ent.Key] = ent.Value; } monde = new Monde(generateur, entites.ToList()); string[] chunks = Directory.GetDirectories(path + "\\Chunks"); foreach (string cpath in chunks) { string[] blocksFile = Directory.GetDirectories(cpath); Block[,] blocks = new Block[16, 16]; foreach (string blockfile in blocksFile) { string[] bnom = blockfile.Split('\\'); string[] bcoord = bnom[bnom.Length - 1].Split('.'); int bx = int.Parse(bcoord[0]); int by = int.Parse(bcoord[1]); Block block = Block.Blocks()[bcoord[2]].Charger(blockfile); blocks[bx, by] = block; } string[] cnom = cpath.Split('\\'); string[] coord = cnom[cnom.Length - 1].Split('.'); int cx = int.Parse(coord[0]); int cy = int.Parse(coord[1]); bool generer = bool.Parse(coord[2]); monde.SetChunk(cx, cy, new Chunk(blocks, generer)); } } } }