private void checkDoors(MapTile mapTile, int x, int y) { //If the next tile is a closed door then check if we have the key if (mapTile.Tile.Name == "DoorClosed" && mapTile.Tile.IsBlock) { //For each key if it matches then open the door by switching the sprite & sprite to its matching open version if (_gameState.HasRedKey) { //Open the door mapTile.Tile = _tiles["DoorOpen"]; mapTile.SetSprite(x, y); } } }
/// <summary> /// Vérifie la nouvelle position héro /// </summary> /// <param name="mapTile"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private bool checkNextTile(MapTile mapTile, int x, int y) { //See if there is a door we need to open checkDoors(mapTile, x, y); //See if there is character to fight if (mapTile.ObjectTile != null && mapTile.ObjectTile.Category == "character") { if (mapTile.ObjectTile.Name == "Princess") { //Game is won Sounds.Kiss(); _gameState.GameIsWon = true; return false; //Don't want to walk on her } if (mapTile.ObjectTile.Health != 0) { Sounds.Fight(); _heroSpriteFighting = true; } #region Hero if (mapTile.ObjectTile.Name == "WarriorM" || mapTile.ObjectTile.Name == "WarriorF" || mapTile.ObjectTile.Name == "HunterM" || mapTile.ObjectTile.Name == "HunterF" || mapTile.ObjectTile.Name == "WizardM" || mapTile.ObjectTile.Name == "WizardF" || mapTile.ObjectTile.Name == "ClericM" || mapTile.ObjectTile.Name == "ClericF" || mapTile.ObjectTile.Name == "EvilWiz1" || mapTile.ObjectTile.Name == "EvilWiz2") { _popups.Clear(); //Fight vs Hero #region CurrentHeroTakingDamage if (_random.Next((_gameState.Health / 2) + 1) >= _gameState.Armour || (_gameState.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { string damage = String.Empty; try { damage = Data.HeroController.AttackHeroAt(Data.CurrentHeroId, x, y, _currentArea.Name); } catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, damage == "" ? "miss" : damage)); if (damage != "miss") { _gameState.Health -= int.Parse(damage); } if (_gameState.Health <= 0) { _gameState.Health = 0; //_heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + Area.AreaOffsetX, // _heroPosition.Y * Tile.TileSizeY + Area.AreaOffsetY, // _tiles["bon"].Bitmap, _tiles["bon"].Rectangle, _tiles["bon"].NumberOfFrames); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); } Data.HeroController.SetHeroHp(Data.CurrentHeroId, _gameState.Health); } else { _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, "miss")); } #endregion #region OtherHeroTakingDamage if (mapTile.ObjectTile.Health == 0) { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "dead")); return true; } else if (_random.Next((mapTile.ObjectTile.Health / 2) + 1) >= _gameState.Armour || (mapTile.ObjectTile.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { //int damage = _random.Next(_gameState.Attack * 2) + 1; string damage = Data.HeroController.AttackHeroAt(Data.CurrentHeroId, x, y, _currentArea.Name); _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, damage == "" ? "miss" : damage)); //_popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, damage.ToString() == "" ? "miss" : damage.ToString())); if (damage != "miss") { mapTile.ObjectTile.Health -= int.Parse(damage); } if (mapTile.ObjectTile.Health <= 0) { mapTile.ObjectTile.Health = 0; return true; } } else { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "miss")); } return false; #endregion } #endregion else { _popups.Clear(); #region AttackHero //A monsters attack ability is 1/2 their max health. Compare that to your armour //If you outclass them then there is still a chance of a lucky hit if (_random.Next((mapTile.ObjectTile.Health / 2) + 1) >= _gameState.Armour || (mapTile.ObjectTile.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { //Monsters do damage up to their max health - if they hit you. int heroDamage = _random.Next(mapTile.ObjectTile.Health) + 1; _gameState.Health = Data.HeroController.RemoveHitPoints(Data.CurrentHeroId, heroDamage); _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, heroDamage.ToString())); if (_gameState.Health == 0) { //_heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + Area.AreaOffsetX, // _heroPosition.Y * Tile.TileSizeY + Area.AreaOffsetY, // _tiles["bon"].Bitmap, _tiles["bon"].Rectangle, _tiles["bon"].NumberOfFrames); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); } //Data.HeroController.SetHeroHp(Data.CurrentHeroId, _gameState.Health); } else { //Hero _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, "miss")); } #endregion #region AttackMonster //A monsters armour is 1/5 of their max health if (_random.Next(_gameState.Attack + 1) >= (mapTile.ObjectTile.Health / 5)) { //Hero damage is up to twice the attack rating if (damageMonster(_random.Next(_gameState.Attack * 2) + 1, mapTile, x, y)) { //Monster is dead now try { Data.MonstreController.KillMonster(Data.WorldId, x + int.Parse(_currentArea.Name.Split(',')[0]) * 8, y + int.Parse(_currentArea.Name.Split(',')[1]) * 8); } catch (Exception ex) { MessageBox.Show(ex.Message); } return true; } } else { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "miss")); } //Monster not dead #endregion return false; //can't move because monster is not dead. } } //If the next tile is a blocker then we can't move return !mapTile.Tile.IsBlock; }
private bool damageMonster(int damage, MapTile mapTile, int x, int y) { //Do some damage, and remove the monster if its dead bool returnValue = false; //monster not dead //Set the monster health if its not already set if (mapTile.ObjectHealth == 0) { mapTile.ObjectHealth = mapTile.ObjectTile.Health; } mapTile.ObjectHealth -= damage; if (mapTile.ObjectHealth <= 0) { mapTile.ObjectHealth = 0; //Experience is the monsters max health _gameState.Experience += mapTile.ObjectTile.Health; //Remove the monster and replace with bones mapTile.ObjectTile = _currentArea.MapItem[x, y].Tile; //mapTile.Tile = null; mapTile.SetObjectSprite(x, y); returnValue = true; //monster is dead } _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, (damage != 0) ? damage.ToString() : "miss")); return returnValue; }
//refresh la map public void Refresh() { List <Monde> lstmonde = Data.MondeController.GetListMonde(); currentWorld = lstmonde.FirstOrDefault(c => c.Id == currentWorld.Id); FillGrass(); List <Monstre> lstmonstre = currentWorld.Monstres.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); List <ObjetMonde> lstobj = currentWorld.ObjetMondes.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); List <Item> lstitem = currentWorld.Items.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); foreach (var m in lstmonstre) { int xm = m.x - _x * MapSizeX; int ym = m.y - _y * MapSizeY; MapTile mapTile = new MapTile(); Map[xm, ym] = mapTile; mapTile.Tile = _tiles[m.Nom]; mapTile.ObjectTile = _tiles[m.Nom]; mapTile.SetSprite(xm, ym); } foreach (var m in lstobj) { int xo = m.x - _x * MapSizeX; int yo = m.y - _y * MapSizeY; if (m.Description != "Sand" && m.Description != "Snow" && m.Description != "Grass" && m.Description != "Dirt" && m.Description != "Path4way" && m.Description != "PathH" && m.Description != "PathV" && m.Description != "PathCornerUR") { MapTile mapTile = new MapTile(); Map[xo, yo] = mapTile; mapTile.Tile = _tiles[m.Description]; mapTile.ObjectTile = _tiles[m.Description]; mapTile.SetSprite(xo, yo); } else { MapTile mapTile = new MapTile(); MapItem[xo, yo] = mapTile; mapTile.Tile = _tiles[m.Description]; mapTile.SetSprite(xo, yo); } } foreach (var m in lstitem) { if (m.x.Value == 0 && m.y.Value == 0) { Console.WriteLine("inv"); } else { int xi = m.x.Value - _x * MapSizeX; int yi = m.y.Value - _y * MapSizeY; MapTile mapTile = new MapTile(); Map[xi, yi] = mapTile; mapTile.Tile = _tiles[m.Nom]; mapTile.ObjectTile = _tiles[m.Nom]; mapTile.SetSprite(xi, yi); } } List <Hero> lstheronear = Data.HeroController.GetListHeroNearHero(Data.CurrentHeroId); if (lstheronear != null) { if (lstheronear.Count != 0) { foreach (var her in lstheronear) { if (her.Id != Data.CurrentHeroId) { MapTile mapTile = new MapTile(); Map[her.x % 8, her.y % 8] = mapTile; mapTile.Tile = _tiles[her.Classe.Description]; mapTile.ObjectTile = _tiles[her.Classe.Description]; mapTile.SetSprite(her.x % 8, her.y % 8); _names[her.x % 8, her.y % 8] = her.Name; } } } } //for (int j = 0; j < MapSizeY; j++) //{ // for (int i = 0; i < MapSizeX; i++) // { // MapTile mapTile2 = new MapTile(); // if (MapItem[i, j] == null) // { // MapItem[i, j] = mapTile2; // mapTile2.Tile = _tiles["Grass"]; // mapTile2.SetSprite(i, j); // } // MapTile mapTile = new MapTile(); // if (Map[i, j] == null) // { // Map[i, j] = MapItem[i, j]; // } // } //} }
/// <summary> /// Vérifie la nouvelle position héro /// </summary> /// <param name="mapTile"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private bool checkNextTile(MapTile mapTile, int x, int y) { //See if there is a door we need to open checkDoors(mapTile, x, y); //See if there is character to fight if (mapTile.ObjectTile != null && mapTile.ObjectTile.Category == "character") { if (mapTile.ObjectTile.Name == "Princess") { //Game is won Sounds.Kiss(); _gameState.GameIsWon = true; return(false); //Don't want to walk on her } if (mapTile.ObjectTile.Health != 0) { Sounds.Fight(); _heroSpriteFighting = true; } #region Hero if (mapTile.ObjectTile.Name == "WarriorM" || mapTile.ObjectTile.Name == "WarriorF" || mapTile.ObjectTile.Name == "HunterM" || mapTile.ObjectTile.Name == "HunterF" || mapTile.ObjectTile.Name == "WizardM" || mapTile.ObjectTile.Name == "WizardF" || mapTile.ObjectTile.Name == "ClericM" || mapTile.ObjectTile.Name == "ClericF" || mapTile.ObjectTile.Name == "EvilWiz1" || mapTile.ObjectTile.Name == "EvilWiz2") { _popups.Clear(); //Fight vs Hero #region CurrentHeroTakingDamage if (_random.Next((_gameState.Health / 2) + 1) >= _gameState.Armour || (_gameState.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { string damage = String.Empty; try { damage = Data.HeroController.AttackHeroAt(Data.CurrentHeroId, x, y, _currentArea.Name); } catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, damage == "" ? "miss" : damage)); if (damage != "miss") { _gameState.Health -= int.Parse(damage); } if (_gameState.Health <= 0) { _gameState.Health = 0; //_heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + Area.AreaOffsetX, // _heroPosition.Y * Tile.TileSizeY + Area.AreaOffsetY, // _tiles["bon"].Bitmap, _tiles["bon"].Rectangle, _tiles["bon"].NumberOfFrames); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); } Data.HeroController.SetHeroHp(Data.CurrentHeroId, _gameState.Health); } else { _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, "miss")); } #endregion #region OtherHeroTakingDamage if (mapTile.ObjectTile.Health == 0) { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "dead")); return(true); } else if (_random.Next((mapTile.ObjectTile.Health / 2) + 1) >= _gameState.Armour || (mapTile.ObjectTile.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { //int damage = _random.Next(_gameState.Attack * 2) + 1; string damage = Data.HeroController.AttackHeroAt(Data.CurrentHeroId, x, y, _currentArea.Name); _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, damage == "" ? "miss" : damage)); //_popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, damage.ToString() == "" ? "miss" : damage.ToString())); if (damage != "miss") { mapTile.ObjectTile.Health -= int.Parse(damage); } if (mapTile.ObjectTile.Health <= 0) { mapTile.ObjectTile.Health = 0; return(true); } } else { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "miss")); } return(false); #endregion } #endregion else { _popups.Clear(); #region AttackHero //A monsters attack ability is 1/2 their max health. Compare that to your armour //If you outclass them then there is still a chance of a lucky hit if (_random.Next((mapTile.ObjectTile.Health / 2) + 1) >= _gameState.Armour || (mapTile.ObjectTile.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { //Monsters do damage up to their max health - if they hit you. int heroDamage = _random.Next(mapTile.ObjectTile.Health) + 1; _gameState.Health = Data.HeroController.RemoveHitPoints(Data.CurrentHeroId, heroDamage); _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, heroDamage.ToString())); if (_gameState.Health == 0) { //_heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + Area.AreaOffsetX, // _heroPosition.Y * Tile.TileSizeY + Area.AreaOffsetY, // _tiles["bon"].Bitmap, _tiles["bon"].Rectangle, _tiles["bon"].NumberOfFrames); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); } //Data.HeroController.SetHeroHp(Data.CurrentHeroId, _gameState.Health); } else { //Hero _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, "miss")); } #endregion #region AttackMonster //A monsters armour is 1/5 of their max health if (_random.Next(_gameState.Attack + 1) >= (mapTile.ObjectTile.Health / 5)) { //Hero damage is up to twice the attack rating if (damageMonster(_random.Next(_gameState.Attack * 2) + 1, mapTile, x, y)) { //Monster is dead now try { Data.MonstreController.KillMonster(Data.WorldId, x + int.Parse(_currentArea.Name.Split(',')[0]) * 8, y + int.Parse(_currentArea.Name.Split(',')[1]) * 8); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(true); } } else { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "miss")); } //Monster not dead #endregion return(false); //can't move because monster is not dead. } } //If the next tile is a blocker then we can't move return(!mapTile.Tile.IsBlock); }
/// <summary> /// Gestion du déplacement du héro /// fais bouger le nom et save dans la bd lors deplacement /// </summary> /// <param name="key"></param> public void KeyDown(Keys key) { //Ignore keypresses while we are animating or fighting if (!_heroSpriteAnimating) { switch (key) { case Keys.Right: //Are we at the edge of the map? if (_heroPosition.X < Area.MapSizeX - 1) { //Can we move to the next tile or not (blocking tile or monster) if (checkNextTile(_currentArea.Map[_heroPosition.X + 1, _heroPosition.Y], _heroPosition.X + 1, _heroPosition.Y)) { HeroClient.SetHeroPos(_heroid, _heroPosition.X, _heroPosition.Y, _currentArea.Name); _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X + 100, (int)_heroSprite.Location.Y + 100, Data.HeroName)); _heroSprite.Velocity = new PointF(100, 0); _heroSprite.Flip = false; _heroSpriteAnimating = true; _direction = HeroDirection.Right; _heroPosition.X++; HeroClient.SetHeroPos(_heroid, _heroPosition.X, _heroPosition.Y, _currentArea.Name); setDestination(); } } else if (_currentArea.EastArea != "-") { if (checkNextTile(_world[_currentArea.EastArea].Map[0, _heroPosition.Y], 0, _heroPosition.Y)) { //Edge of map - move to next area _currentArea = _world[_currentArea.EastArea]; _heroPosition.X = 0; setDestination(); _heroSprite.Location = _heroDestination; _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y + 100, Data.HeroName)); } } break; case Keys.Left: //Are we at the edge of the map? if (_heroPosition.X > 0) { //Can we move to the next tile or not (blocking tile or monster) if (checkNextTile(_currentArea.Map[_heroPosition.X - 1, _heroPosition.Y], _heroPosition.X - 1, _heroPosition.Y)) { _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X - 100, (int)_heroSprite.Location.Y + 100, Data.HeroName)); _heroSprite.Velocity = new PointF(-100, 0); _heroSprite.Flip = true; _heroSpriteAnimating = true; _direction = HeroDirection.Left; _heroPosition.X--; HeroClient.SetHeroPos(_heroid, _heroPosition.X, _heroPosition.Y, _currentArea.Name); setDestination(); } } else if (_currentArea.WestArea != "-") { if (checkNextTile(_world[_currentArea.WestArea].Map[7, _heroPosition.Y], 7, _heroPosition.Y)) { _currentArea = _world[_currentArea.WestArea]; _heroPosition.X = Area.MapSizeX - 1; setDestination(); _heroSprite.Location = _heroDestination; _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y + 100, Data.HeroName)); } } break; case Keys.Up: //Are we at the edge of the map? if (_heroPosition.Y > 0) { //Can we move to the next tile or not (blocking tile or monster) if (checkNextTile(_currentArea.Map[_heroPosition.X, _heroPosition.Y - 1], _heroPosition.X, _heroPosition.Y - 1)) { _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y, Data.HeroName)); _heroSprite.Velocity = new PointF(0, -100); _heroSpriteAnimating = true; _direction = HeroDirection.Up; _heroPosition.Y--; HeroClient.SetHeroPos(_heroid, _heroPosition.X, _heroPosition.Y, _currentArea.Name); setDestination(); } } else if (_currentArea.NorthArea != "-") { if (checkNextTile(_world[_currentArea.NorthArea].Map[_heroPosition.X, 7], _heroPosition.X, 7)) { //Edge of map - move to next area _currentArea = _world[_currentArea.NorthArea]; _heroPosition.Y = Area.MapSizeY - 1; setDestination(); _heroSprite.Location = _heroDestination; _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y + 100, Data.HeroName)); } } break; case Keys.Down: //Are we at the edge of the map? if (_heroPosition.Y < Area.MapSizeY - 1) { //Can we move to the next tile or not (blocking tile or monster) if (checkNextTile(_currentArea.Map[_heroPosition.X, _heroPosition.Y + 1], _heroPosition.X, _heroPosition.Y + 1)) { _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y + 200, Data.HeroName)); _heroSprite.Velocity = new PointF(0, 100); _heroSpriteAnimating = true; _direction = HeroDirection.Down; _heroPosition.Y++; HeroClient.SetHeroPos(_heroid, _heroPosition.X, _heroPosition.Y, _currentArea.Name); setDestination(); } } else if (_currentArea.SouthArea != "-") { if (checkNextTile(_world[_currentArea.SouthArea].Map[_heroPosition.X, 0], _heroPosition.X, 0)) { //Edge of map - move to next area _currentArea = _world[_currentArea.SouthArea]; _heroPosition.Y = 0; setDestination(); _heroSprite.Location = _heroDestination; _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y + 100, Data.HeroName)); } } break; case Keys.P: //Potion - if we have any if (_gameState.Potions > 0) { Sounds.Magic(); _gameState.Potions--; _heroSpriteFighting = true; //All monsters on the screen take maximum damage _popups.Clear(); for (int i = 0; i < Area.MapSizeX; i++) { for (int j = 0; j < Area.MapSizeY; j++) { MapTile mapTile = _currentArea.Map[i, j]; if (mapTile.ObjectTile != null && mapTile.ObjectTile.Category == "character") { damageMonster(_gameState.Attack * 2, mapTile, i, j); } } } } break; } } }
//met du gazon par defaut public void FillGrass() { for (int j = 0; j < MapSizeY; j++) { for (int i = 0; i < MapSizeX; i++) { MapTile mapTile2 = new MapTile(); MapItem[i, j] = mapTile2; mapTile2.Tile = _tiles["Grass"]; mapTile2.SetSprite(i, j); _names[i, j] = null; Map[i, j] = MapItem[i, j]; } } }
//refresh la map public void Refresh() { List<Monde> lstmonde = Data.MondeController.GetListMonde(); currentWorld = lstmonde.FirstOrDefault(c => c.Id == currentWorld.Id); FillGrass(); List<Monstre> lstmonstre = currentWorld.Monstres.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); List<ObjetMonde> lstobj = currentWorld.ObjetMondes.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); List<Item> lstitem = currentWorld.Items.Where(c => c.MondeId == currentWorld.Id && c.x >= _x * MapSizeX && c.x < (_x * MapSizeX + MapSizeX) && c.y >= _y * MapSizeY && c.y < (_y * MapSizeY + MapSizeY)).ToList(); foreach (var m in lstmonstre) { int xm = m.x - _x * MapSizeX; int ym = m.y - _y * MapSizeY; MapTile mapTile = new MapTile(); Map[xm, ym] = mapTile; mapTile.Tile = _tiles[m.Nom]; mapTile.ObjectTile = _tiles[m.Nom]; mapTile.SetSprite(xm, ym); } foreach (var m in lstobj) { int xo = m.x - _x * MapSizeX; int yo = m.y - _y * MapSizeY; if (m.Description != "Sand" && m.Description != "Snow" && m.Description != "Grass" && m.Description != "Dirt" && m.Description != "Path4way" && m.Description != "PathH" && m.Description != "PathV" && m.Description != "PathCornerUR") { MapTile mapTile = new MapTile(); Map[xo, yo] = mapTile; mapTile.Tile = _tiles[m.Description]; mapTile.ObjectTile = _tiles[m.Description]; mapTile.SetSprite(xo, yo); } else { MapTile mapTile = new MapTile(); MapItem[xo, yo] = mapTile; mapTile.Tile = _tiles[m.Description]; mapTile.SetSprite(xo, yo); } } foreach (var m in lstitem) { if (m.x.Value == 0 && m.y.Value == 0) { Console.WriteLine("inv"); } else { int xi = m.x.Value - _x * MapSizeX; int yi = m.y.Value - _y * MapSizeY; MapTile mapTile = new MapTile(); Map[xi, yi] = mapTile; mapTile.Tile = _tiles[m.Nom]; mapTile.ObjectTile = _tiles[m.Nom]; mapTile.SetSprite(xi, yi); } } List<Hero> lstheronear = Data.HeroController.GetListHeroNearHero(Data.CurrentHeroId); if (lstheronear != null) { if (lstheronear.Count != 0) { foreach (var her in lstheronear) { if (her.Id != Data.CurrentHeroId) { MapTile mapTile = new MapTile(); Map[her.x % 8, her.y % 8] = mapTile; mapTile.Tile = _tiles[her.Classe.Description]; mapTile.ObjectTile = _tiles[her.Classe.Description]; mapTile.SetSprite(her.x % 8, her.y % 8); _names[her.x % 8, her.y % 8] = her.Name; } } } } //for (int j = 0; j < MapSizeY; j++) //{ // for (int i = 0; i < MapSizeX; i++) // { // MapTile mapTile2 = new MapTile(); // if (MapItem[i, j] == null) // { // MapItem[i, j] = mapTile2; // mapTile2.Tile = _tiles["Grass"]; // mapTile2.SetSprite(i, j); // } // MapTile mapTile = new MapTile(); // if (Map[i, j] == null) // { // Map[i, j] = MapItem[i, j]; // } // } //} }