コード例 #1
0
ファイル: World.cs プロジェクト: MLemonde/HugoWorld1
        public World(GameState gameState, Dictionary<string, Tile> tiles, int mondeid, bool dead)
        {
            _gameState = gameState;
            _tmrRefresh.Interval = 2000;
            _tmrRefresh.Enabled = true;
            _tmrRefresh.Elapsed += _tmrRefresh_Tick;
            _tiles = tiles;
            Classe currentclasse = Data.ClassController.GetListClasses(Data.WorldId).FirstOrDefault(c=> c.Id == Data.ClassId);
            _currentHero = Data.HeroController.GetListHero(Data.UserId).First(c => c.Id == Data.CurrentHeroId);
            _heroClasse = currentclasse.Description;
            //load la map
            CreerAreaDic(mondeid);
            //load les stat du hero
            UpdateGameState();

            //Find the start point
            _heroid = _currentHero.Id;
            //trouve l'area du hero
            int xarea = _currentHero.x / 8;
            int yarea = _currentHero.y / 8;

            _currentArea = _world[xarea.ToString() + "," + yarea.ToString()];
            
            _heroPosition = new Point(3, 3);

            //si mort, retourne debut full life
            if (dead)
            {
               _currentArea = _world["0,0"];

                Data.vie = Data.Stam * 10;
            }
            if (!dead)
            {
                //si pas mort, trouve pos
                _heroPosition.X = _currentHero.x % 8;
                _heroPosition.Y = _currentHero.y % 8;
            }

            //set sprite selon classe
            _heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + Area.AreaOffsetX,
                                            _heroPosition.Y * Tile.TileSizeY + Area.AreaOffsetY,
                                            _tiles[_heroClasse].Bitmap, _tiles[_heroClasse].Rectangle, _tiles[_heroClasse].NumberOfFrames);
            
            //affiche nom
            _popups.Add(new textPopup((int)_heroSprite.Location.X, (int)_heroSprite.Location.Y +100, Data.HeroName));

            _heroSprite.Flip = true;
            _heroSprite.ColorKey = Color.FromArgb(75, 75, 75);
            _tmrRefresh.Start();
        }
コード例 #2
0
ファイル: World.cs プロジェクト: MLemonde/HugoWorld1
        /// <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;
                }
            }
        }
コード例 #3
0
ファイル: World.cs プロジェクト: MLemonde/HugoWorld1
        //load la map 
        private void CreerAreaDic(int mapid)
        {
            MondeControllerClient client = new MondeControllerClient();
            List<Monde> lstmonde = client.GetListMonde();
            _currentWorld = lstmonde.FirstOrDefault(c => c.Id == mapid);
            if (_currentWorld == null)
                return;
            int Mondex = int.Parse(_currentWorld.LimiteX) / 8;
            int Mondey = int.Parse(_currentWorld.LimiteY) / 8;

            for (int x = 0; x < Mondex; x++)
            {

                for (int y = 0; y < Mondey; y++)
                {
                    Area area = new Area(mapid, x, y, _tiles);
                    _world.Add(area.Name, area);
                }
            }
        }