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 < LocalArea.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)) { _heroSprite.Velocity = new PointF(100, 0); _heroSprite.Flip = true; _heroSpriteAnimating = true; _heroSprite.Vertical = false; _direction = HeroDirection.Right; _heroPosition.X++; setDestination(); } } 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)) { _heroSprite.Velocity = new PointF(-100, 0); _heroSprite.Flip = false; _heroSpriteAnimating = true; _heroSprite.Vertical = false; _direction = HeroDirection.Left; _heroPosition.X--; setDestination(); } } 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)) { _heroSprite.Velocity = new PointF(0, -100); _heroSprite.Flip = true; _heroSpriteAnimating = true; _heroSprite.Vertical = true; _direction = HeroDirection.Up; _heroPosition.Y--; setDestination(); } } break; case Keys.Down: //Are we at the edge of the map? if (_heroPosition.Y < LocalArea.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)) { _heroSprite.Velocity = new PointF(0, 100); _heroSprite.Flip = false; _heroSpriteAnimating = true; _heroSprite.Vertical = true; _direction = HeroDirection.Down; _heroPosition.Y++; setDestination(); } } break; } } }
public static void SetHeroDirection(HeroDirection direction) { Direction = direction; }
/// <summary> /// Gestion du déplacement du héro /// </summary> /// <param name="key"></param> public void KeyDown(Keys key) { //Ignore keypresses while we are animating or fighting if (!_heroSpriteAnimating && !_heroSpriteFighting) { //Pt chercher beginx beginy here 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)) { _heroSprite.Velocity = new PointF(100, 0); _heroSprite.Flip = true; _heroSpriteAnimating = true; _direction = HeroDirection.Right; _heroPosition.X++; _gameState.Hero.x++; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); } } else if (_gameState.Hero.x + 1 >= _currentWorld.LimiteX) { break; } else /*if (_currentArea.EastArea != "-")*/ // Droite { //Edge of map - move to next area List <WorldItemDetailsDTO> listItems = GetWorldItems(_gameState.Hero.x + 1, _gameState.Hero.y); if (!(listItems == null)) { _currentArea.ChangeMap(listItems, GetBeginPos(_gameState.Hero.x + 1), GetBeginPos(_gameState.Hero.y)); _heroPosition.X = 0; _gameState.Hero.x++; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); _heroSprite.Location = _heroDestination; } } 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)) { _heroSprite.Velocity = new PointF(-100, 0); _heroSprite.Flip = false; _heroSpriteAnimating = true; _direction = HeroDirection.Left; _heroPosition.X--; _gameState.Hero.x--; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); } } else if (_gameState.Hero.x - 1 < 0) { break; } else { List <WorldItemDetailsDTO> listItems = GetWorldItems(_gameState.Hero.x - 1, _gameState.Hero.y); if (!(listItems == null)) { _currentArea.ChangeMap(listItems, GetBeginPos(_gameState.Hero.x - 1), GetBeginPos(_gameState.Hero.y)); _heroPosition.X = Area.MapSizeX - 1; _gameState.Hero.x--; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); _heroSprite.Location = _heroDestination; } } 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)) { _heroSprite.Velocity = new PointF(0, -100); _heroSpriteAnimating = true; _direction = HeroDirection.Up; _heroPosition.Y--; _gameState.Hero.y--; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); } } else if (_gameState.Hero.y - 1 < 0) { break; } else { //Edge of map - move to next area List <WorldItemDetailsDTO> listItems = GetWorldItems(_gameState.Hero.x, _gameState.Hero.y - 1); if (!(listItems == null)) { _currentArea.ChangeMap(listItems, GetBeginPos(_gameState.Hero.x), GetBeginPos(_gameState.Hero.y - 1)); _heroPosition.Y = Area.MapSizeY - 1; _gameState.Hero.y--; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); _heroSprite.Location = _heroDestination; } } 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)) { _heroSprite.Velocity = new PointF(0, 100); _heroSpriteAnimating = true; _direction = HeroDirection.Down; _heroPosition.Y++; _gameState.Hero.y++; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); } } else if (_gameState.Hero.y + 1 >= _currentWorld.LimiteY) { break; } else { //Edge of map - move to next area List <WorldItemDetailsDTO> listItems = GetWorldItems(_gameState.Hero.x, _gameState.Hero.y + 1); if (!(listItems == null)) { _currentArea.ChangeMap(listItems, GetBeginPos(_gameState.Hero.x), GetBeginPos(_gameState.Hero.y + 1)); _heroPosition.Y = 0; _gameState.Hero.y++; HeroService.MoveHero(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y); setDestination(); _heroSprite.Location = _heroDestination; } } break; case Keys.P: //Potion - if we have any if (_gameState.Potions > 0) { Sounds.Magic(); _gameState.Potions--; _heroSpriteFighting = true; _startFightTime = -1; //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, _currentArea._monsters.First(m => m.x == i && m.y == j)); } } } } break; } } }
public void KeyDown(Keys key) { //Ignore keypresses while we are animating or fighting if (!_heroSpriteAnimating && !_heroSpriteFighting) { 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)) { _heroSprite.Velocity = new PointF(100, 0); _heroSprite.Flip = true; _heroSpriteAnimating = true; _direction = HeroDirection.Right; _heroPosition.X++; setDestination(); } } else if (_currentArea.EastArea != "-") { //Edge of map - move to next area _currentArea = _world[_currentArea.EastArea]; _heroPosition.X = 0; setDestination(); _heroSprite.Location = _heroDestination; } 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)) { _heroSprite.Velocity = new PointF(-100, 0); _heroSprite.Flip = false; _heroSpriteAnimating = true; _direction = HeroDirection.Left; _heroPosition.X--; setDestination(); } } else if (_currentArea.WestArea != "-") { _currentArea = _world[_currentArea.WestArea]; _heroPosition.X = Area.MapSizeX - 1; setDestination(); _heroSprite.Location = _heroDestination; } 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)) { _heroSprite.Velocity = new PointF(0, -100); _heroSpriteAnimating = true; _direction = HeroDirection.Up; _heroPosition.Y--; setDestination(); } } else if (_currentArea.NorthArea != "-") { //Edge of map - move to next area _currentArea = _world[_currentArea.NorthArea]; _heroPosition.Y = Area.MapSizeY - 1; setDestination(); _heroSprite.Location = _heroDestination; } 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)) { _heroSprite.Velocity = new PointF(0, 100); _heroSpriteAnimating = true; _direction = HeroDirection.Down; _heroPosition.Y++; setDestination(); } } else if (_currentArea.SouthArea != "-") { //Edge of map - move to next area _currentArea = _world[_currentArea.SouthArea]; _heroPosition.Y = 0; setDestination(); _heroSprite.Location = _heroDestination; } break; case Keys.P: //Potion - if we have any if (_gameState.Potions > 0) { Sounds.Magic(); _gameState.Potions--; _heroSpriteFighting = true; _startFightTime = -1; //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; } } }
/// <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; } } }
public void ChangeDirection(HeroDirection _direction) { speed = Random.Range(minSpeed, maxSpeed); direction = _direction; }