Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client.Common.Views.RegionViewHex"/> class.
        /// </summary>
        /// <param name="region">The Region to draw.</param>
        public RegionViewHex(Region region)
            : base(region)
        {
            var tileMapInfo = new CCTileMapInfo(Common.Constants.ClientConstants.TILEMAP_FILE_HEX);
            m_tileMap = new CCTileMap(tileMapInfo);

            m_terrainLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_TERRAIN);
            m_buildingLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_BUILDING);
            m_menueLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_MENU);
            m_indicatorLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_INDICATOR);

            m_drawNodes = new Dictionary<Account, CCDrawNode>();

            m_childs = new Dictionary<LayerTypes, CCNode>();
            m_childs[LayerTypes.Terrain] = m_tileMap.TileLayersContainer;
            m_childs[LayerTypes.Building] = null;
            m_childs[LayerTypes.Unit] = new CCNode();
            m_childs[LayerTypes.Border] = new CCNode();
            m_childs[LayerTypes.Indicator] = null; // new CCNode();
            m_childs[LayerTypes.Menu] = null; // new CCNode();

            Init();
            LoadRegionViewAsync();
        }
 public PathFinder(CCTileMap setMap)
 {
     map = setMap;
     mapLayer = map.LayerNamed("Map");
 }
        private void LoadLevel(int levelNumber)
		{
			currentLevel = new CCTileMap ("level" + levelNumber + ".tmx");
			currentLevel.Antialiased = false;
			backgroundLayer = currentLevel.LayerNamed ("Background");

			// CCTileMap is a CCLayer, so we'll just add it under all entities
			this.AddChild (currentLevel);

			// put the game layer after
			this.RemoveChild(gameplayLayer);
			this.AddChild(gameplayLayer);

			this.RemoveChild (hudLayer);
			this.AddChild (hudLayer);
		}
        public void PopulateFrom(CCTileMap tileMap)
        {
            //得到瓦片地图里面的瓦片信息,比如说哪些瓦片可以与entity接触,具体是瓦片的哪个方向的面可以接触

            collisions=new List<RectWithDirection> ();

            //每个小瓦片的边长加上0.5,这样碰撞时就不会陷进去才弹出
            tileDimensionWidth = (int)(tileMap.TileTexelSize.Width + .5f);
            tileDimensionHeight = (int)(tileMap.TileTexelSize.Height + .5f);
            mBrickLayer = tileMap.LayerNamed ("BrickLayer");

            TileMapPropertyFinder finder = new TileMapPropertyFinder (tileMap);

            foreach (var propertyLocation in finder.GetPropertyLocations())
            {
                //如果在这个位置的瓦片是一个固体
                if (propertyLocation.Properties.ContainsKey ("SolidCollision"))
                {
                    //worldX worldY 是每个瓦片的中心的坐标
                    float centerX = propertyLocation.WorldX;
                    float centerY = propertyLocation.WorldY;

                    //得到每个小瓦片的左边界和下边界
                    float left = centerX - tileDimensionWidth/2.0f;
                    float bottom = centerY - tileDimensionHeight/2.0f;

                    //在那个点构造一个小瓦片
                    RectWithDirection rectangle = new RectWithDirection {
                        Left = left,
                        Bottom = bottom,
                        Width = tileDimensionWidth,
                        Height = tileDimensionHeight,
                        tiledMapCoordinate=propertyLocation.TileCoordinates

                    };

                    //得到地图上所有的固体小块
                    collisions.Add (rectangle);
                }
            }

            // Sort by XAxis to speed future searches:
            //collisions是把整个瓦片地图按每个瓦片的左边的坐标进行排序的list
            //在每一个左边坐标有一列的瓦片
            //debug看一下
            collisions = collisions.OrderBy(item=>item.Left).ToList();

            // now let's adjust the directions that these point
            //调整每个小块的角度

            for (int i = 0; i < collisions.Count; i++)
            {
                var rect = collisions [i];

                // By default rectangles can reposition objects in all directions:
                int valueToAssign = (int)Directions.All; //15

                float centerX = rect.CenterX;
                float centerY = rect.CenterY;

                // If there are collisions on the sides, then this
                // rectangle can no longer repositon objects in that direction.
                // 一开始小瓦片的方向valueToAssign可能是所有的方向,每次减去一种不可能的方向值,最后得到的就是正确的方向的值的和
                //direction是这个实体瓦片暴露在外,可以与entity接触的方向
                //比如说瓦片地图里的地面,方向就为up
                if (HasCollisionAt (centerX - tileDimensionWidth, centerY))
                {
                    valueToAssign -= (int)Directions.Left;
                }
                if (HasCollisionAt (centerX + tileDimensionWidth, centerY))
                {
                    valueToAssign -= (int)Directions.Right;
                }
                if (HasCollisionAt (centerX, centerY + tileDimensionHeight))
                {
                    valueToAssign -= (int)Directions.Up;
                }
                if (HasCollisionAt (centerX, centerY - tileDimensionHeight))
                {
                    valueToAssign -= (int)Directions.Down;
                }

                rect.Directions = (Directions)valueToAssign;
                //更新瓦片列表中的瓦片的方向
                collisions [i] = rect;
            }

            for (int i = collisions.Count - 1; i > -1; i--)
            {
                //经过筛选后,遍历删除那些没有方向的瓦片
                if (collisions [i].Directions == Directions.None)
                {
                    collisions.RemoveAt (i);
                }
            }
        }
        void loadTileMap()
        {
            //加载tiledmap预处理

            mLevelTest = new CCTileMap ("LevelTest.tmx");
            mLevelTest.Antialiased = false;
            mTiledLayer = mLevelTest.LayerNamed("BrickLayer");
            gameplayLayer.AddChild (mTiledLayer);

            //初始化地图
            levelCollision = new LevelCollision ();
            levelCollision.PopulateFrom (mLevelTest);
        }
Exemple #6
0
        private void LoadLevel(int levelNumber)
        {
            //读取瓦片地图
            currentLevel = new CCTileMap ("level" + levelNumber + ".tmx");
            currentLevel.Antialiased = false;
            //backgroundLayer是游戏中不动的背景图, 每个currentLevel都有一个对应的backgroundLayer, currentLevel中的其他部分随画面滚动
            backgroundLayer = currentLevel.LayerNamed ("Background");

            // CCTileMap is a CCLayer, so we'll just add it under all entities
            this.AddChild (currentLevel);

            //levelCollision 是确定地图中哪些部分是游戏人物不可以进入的
            levelCollision = new LevelCollision ();
            levelCollision.PopulateFrom (currentLevel);

            // put the game layer after
            this.RemoveChild(gameplayLayer);
            this.AddChild(gameplayLayer);

            this.RemoveChild (hudLayer);
            this.AddChild (hudLayer);
        }
Exemple #7
0
        protected override void AddedToScene()
        {
            base.AddedToScene ();

            Background = new CCSprite ("background");
            Background.Scale = screenSize.Width / Background.ContentSize.Width;

            Map = new CCTileMap (new CCTileMapInfo ("tilemaps/bitte.tmx"));
            //bei einer Invocation Exception einfach ne neue Map machen
            //vielleicht auch mal schauen, ob die XML_Datei korrekt ist(Attribute, fehlende < etc.)
            //wenn die Maplayer nicht vollständig geladen werden, muss man die Compression umstellen

            //mapproperties
            if (Map.MapPropertyNamed ("Creator") != null)
                mapCreator = Map.MapPropertyNamed ("Creator");
            if (Map.MapPropertyNamed ("Version") != null)
                mapVersion = Map.MapPropertyNamed ("Version");
            if (Map.MapPropertyNamed ("Name") != null)
                mapName = Map.MapPropertyNamed ("Name");

            Map.Scale = 3f; //Scale auch beim Spawnpoint ändern
            Map.Antialiased = false;
            //Map.LayerNamed ("mainlayer")
            pointLayer = Map.ObjectGroupNamed ("points");
            Dictionary<string,string> spawnPoint = pointLayer.ObjectNamed ("SpawnPoint");

            gameContainer.mainCharacter.Position = new CCPoint ((float)Convert.ToInt32 (spawnPoint ["x"]) * Map.ScaleX, (float)Convert.ToInt32 (spawnPoint ["y"]) * Map.ScaleY);
            gameContainer.physicsHandler.Initialize (Map.MapDimensions.Size.Width * Map.TileTexelSize.Width * Map.ScaleX, gameContainer.mainCharacter, Map.LayerNamed ("mainlayer"), Map, gameContainer);
            gameContainer.mainCharacter.bindToPhysicsHandler (gameContainer.physicsHandler);

            //Platform hinzufügen
            gameContainer.platformContainer.AddRange (TMXLayerDataLoader.LoadPlatformFromLayer (Map, Map.ObjectGroupNamed ("aditionallayer"), gameContainer));
            gameContainer.jumpPadContainer.AddRange (TMXLayerDataLoader.LoadJumpPadFromLayer (Map, Map.ObjectGroupNamed ("aditionallayer"), gameContainer));

            this.AddChild (Background, -1);

            this.AddChild (Map, 0);
            this.AddChild (gameContainer.mainCharacter.Sprite, 2);
            this.AddChild (gameContainer.physicsHandler.debugDrawer.DrawNode, 1);

            foreach (Platform knownPlatform in gameContainer.platformContainer) {
                this.AddChild (knownPlatform);
            }
            foreach (JumpPad knownJumpPad in gameContainer.jumpPadContainer) {
                this.AddChild (knownJumpPad);
            }

            //particle init

            PlayerMovingParticle = new GroundParticle ();
            this.AddChild (PlayerMovingParticle);
            PlayerMovingParticle.Position = gameContainer.mainCharacter.Position;
        }