Beispiel #1
0
 public static void tileCoordinateConverter(CMap map)
 {
     for (int i = 0; i < map._layers.Count; i++)
     {
         CLayer layer = map._layers[i];
         layer.tileCoordConverter();
     }
 }
Beispiel #2
0
        public void update(GameTime gameTime)
        {
            for (int i = 0; i < _componentRegistry.Count(); i++)
            {
                if (_componentRegistry[i].killMe)
                {
                    removeComponent(_componentRegistry[i], _componentRegistry[i].layer);
                }
            }

            for (int i = 0; i < _layers.Count; i++)
            {
                CLayer layer = _layers[i];
                layer.updateLayer(gameTime);
            }

            //handle collisions
            for (int i = 0; i < _componentRegistry.Count(); i++)
            {
                _componentRegistry[i].doCollision();
            }
            CMasterControl.mapManager.checkAndSwapMap();
        }
Beispiel #3
0
        public CMap(string fileName)
            : base(Gears.Cartography.Map.deserializeFromXml(fileName))
        {
            _layers = new CLayer[base.NUM_LAYERS];
            int layerCount = 0;
            foreach (Gears.Cartography.layer layer in base.LAYERS)
            {

                uint componentAddresses = 0;
                uint componentCount = 0;
                Actors.CComponent[] compList = new CComponent[layer.COMPONENTS.Count()];

                //=======================================================================
                //Tiles
                //=======================================================================
                CTile[] tiles = new CTile[layer.TILE.Count()];
                int tileCounter = 0;
                foreach (Gears.Cartography.tile tile in layer.TILE)
                {
                    if (!_coordFormat.IsMatch(tile.COORDS))
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.COORDS);

                    if (!_coordFormat.IsMatch(tile.TILESELECTION))
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.TILESELECTION);

                    Vector2 atlasCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[0]),
                                                      (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[1]));
                    Vector2 mapCoords =   new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[0]),
                                                      (float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[1]));

                    tiles[tileCounter++] = new CTile(atlasCoords,mapCoords,tile.TILESET);
                }

                //=======================================================================
                //Components
                //=======================================================================
                foreach (Gears.Cartography.component component in layer.COMPONENTS)
                {
                    CComponent tempComp = new CComponent(componentAddresses++);

                    foreach (Gears.Cartography.actors actor in component.ACTORS)
                    {
                        Type actorType = actor.actor;
                        CActor tempActor = (CActor)Activator.CreateInstance(actorType);

                        Vector2 coordinates = Vector2.Zero;

                        if (!_coordFormat.IsMatch(actor.COORDS))
                            throw new FormatException("The coordinate format provided was not valid.\n" + "Actor: " + actor.actor.ToString() + " " + actor.name);

                        coordinates.X = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[0]);
                        coordinates.Y = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[1]);

                        tempActor.init(actor.name, coordinates, componentAddresses - 1, _valSplitter.Split(actor.param));

                        tempComp.actors.Add(actor.name, tempActor);

                    }
                    compList[componentCount++] = tempComp;

                }
                _layers[layerCount] = new CLayer(layer.NAME, compList, tiles);

            }
        }
Beispiel #4
0
        public CMap(string fileName)
        {
            //_internalMap = Gears.Cartography.Map.
            _internalMap = Gears.Cartography.Map.deserialize(fileName);
            _layers      = new CLayer[_internalMap.NUM_LAYERS];
            int layerCount = 0;

            _tileIndex = new Graphics.CSprite(_internalMap.TILESET, Graphics.CTextures.textures[_internalMap.TILESET]);

            foreach (Gears.Cartography.layer layer in _internalMap.LAYERS)
            {
                uint componentAddresses      = 0;
                int  componentCount          = 0;
                Actors.CComponent[] compList = new CComponent[layer.COMPONENTS == null ? 0 : layer.COMPONENTS.Count()];

                //=======================================================================
                //Tiles
                //=======================================================================
                CTile[] tiles       = new CTile[layer.TILES.Count()];
                int     tileCounter = 0;
                foreach (Gears.Cartography.tile tile in layer.TILES)
                {
                    if (!_coordFormat.IsMatch(tile.COORDS))
                    {
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.COORDS);
                    }

                    if (!_coordFormat.IsMatch(tile.TILESELECTION))
                    {
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.TILESELECTION);
                    }

                    Vector2 atlasCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[0]),
                                                      (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[1]));
                    Vector2 mapCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[0]),
                                                    (float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[1]));

                    tiles[tileCounter++] = new CTile(atlasCoords, mapCoords, tile.TILESET);
                }

                if (layer.COMPONENTS != null)
                {
                    //=======================================================================
                    //Components
                    //=======================================================================
                    foreach (Gears.Cartography.component component in layer.COMPONENTS)
                    {
                        CComponent tempComp = new CComponent(componentAddresses);
                        bool       root     = true;
                        foreach (Gears.Cartography.actors actor in component.ACTORS)
                        {
                            Type   actorType = Type.GetType(actor.TYPE);
                            CActor tempActor = (CActor)Activator.CreateInstance(actorType);

                            Vector2 coordinates = Vector2.Zero;

                            if (!_coordFormat.IsMatch(actor.COORDS))
                            {
                                throw new FormatException("The coordinate format provided was not valid.\n" + "Actor: " + actor.TYPE.ToString() + " " + actor.NAME);
                            }

                            coordinates.X = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[0]);
                            coordinates.Y = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[1]);

                            tempActor.init(actor.NAME, coordinates, componentAddresses, actor.param == null ? null : actor.param.Split(','));
                            tempActor.layer = layerCount;

                            if (root)
                            {
                                tempComp.root = tempActor;
                            }
                            else
                            {
                                tempComp.actors.Add(actor.NAME, tempActor);
                            }

                            root = false;
                            _actorRegistry.Add(tempActor);
                        }
                        //register component
                        CMasterControl.commNet.Add((int)componentAddresses++, new List <CActorPacket>());
                        compList[componentCount++] = tempComp;
                    }
                }
                _layers[layerCount++] = new CLayer(layer.NAME, compList, tiles, ref _tileIndex);
            }
        }
Beispiel #5
0
        public CMap(string fileName, Dictionary <string, Graphics.CSprite> atlasCache = null)
        {
            _hasMapStateChanged = true;
            _internalMap        = Gears.Cartography.Map.deserialize(fileName);
            _layers             = new List <CLayer>(_internalMap.NUM_LAYERS);
            int layerCount = 0;


            //cache bgm
            if (_internalMap.BGM_FILE != null)
            {
                if (!CMasterControl.audioPlayer.soundBank.ContainsKey(_internalMap.BGM_FILE.BGM_REF_NAME))
                {
                    CMasterControl.audioPlayer.soundBank.Add(_internalMap.BGM_FILE.BGM_REF_NAME,
                                                             new Sound.CSound(CMasterControl.glblContent.Load <Song>(_internalMap.BGM_FILE.BGM_FILE_LOC), true, -1));
                }

                _bgmRef = _internalMap.BGM_FILE.BGM_REF_NAME;
                _bgmLoc = _internalMap.BGM_FILE.BGM_FILE_LOC;
            }

            /*if (_internalMap.TILESET != null)
             *  _tileIndex = new Graphics.CSprite(_internalMap.TILESET, Graphics.CTextures.textures[_internalMap.TILESET]);*/

            _width          = _internalMap.WIDTH;
            _height         = _internalMap.HEIGHT;
            _largestAddress = 0;
            foreach (Gears.Cartography.layer layer in _internalMap.LAYERS)
            {
                int componentAddresses = 2;
                int componentCount     = 0;
                int hitboxAddress      = CReservedAddresses.HITBOX_NOT_PRESENT;

                Actors.CComponent[] compList = new CComponent[layer.COMPONENTS == null ? 0 : layer.COMPONENTS.Count()];
                Dictionary <string, Graphics.CSprite> tileSets = new Dictionary <string, Graphics.CSprite>();
                //=======================================================================
                //Tiles
                //=======================================================================
                CTile[] tiles       = new CTile[layer.TILES.Count()];
                int     tileCounter = 0;
                foreach (Gears.Cartography.tile tile in layer.TILES)
                {
                    if (!_coordFormat.IsMatch(tile.COORDS))
                    {
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.COORDS);
                    }

                    if (!_coordFormat.IsMatch(tile.TILESELECTION))
                    {
                        throw new FormatException("The coordinate format provided was not valid.\n" + "Tile: " + tile.TILESELECTION);
                    }

                    Vector2 atlasCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[0]),
                                                      (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTION)[1]));
                    Vector2 mapCoords = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[0]),
                                                    (float)Convert.ToDouble(_valSplitter.Split(tile.COORDS)[1]));
                    Vector2 atlasCoordsEnd = Vector2.Zero;
                    if (tile.TILESELECTIONEND != null)
                    {
                        atlasCoordsEnd = new Vector2((float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTIONEND)[0]),
                                                     (float)Convert.ToDouble(_valSplitter.Split(tile.TILESELECTIONEND)[1]));
                    }

                    if (!tileSets.ContainsKey(tile.TILESET))
                    {
                        tileSets.Add(tile.TILESET, new Graphics.CSprite(tile.TILESET));
                    }

                    if (tile.TILESELECTIONEND == null)
                    {
                        tiles[tileCounter++] = new CTile(atlasCoords, mapCoords, tile.TILESET);
                    }
                    else
                    {
                        tiles[tileCounter++] = new CAnimatedTile(atlasCoords, atlasCoordsEnd, mapCoords, tile.TILESET, tile.SPEED);
                    }
                }

                List <CActor> actorsForDrawList = new List <CActor>();
                if (layer.COMPONENTS != null)
                {
                    //=======================================================================
                    //Components
                    //=======================================================================

                    foreach (Gears.Cartography.component component in layer.COMPONENTS)
                    {
                        CComponent tempComp = new CComponent(component.ADDRESS);
                        foreach (Gears.Cartography.actors actor in component.ACTORS)
                        {
                            Type actorType = Type.GetType(actor.TYPE);

                            if (actorType == typeof(King_of_Thieves.Actors.Collision.CSolidTile))
                            {
                                hitboxAddress  = component.ADDRESS;
                                hitBoxCounter += 1;
                            }

                            CActor tempActor = (CActor)Activator.CreateInstance(actorType);

                            Vector2 coordinates = Vector2.Zero;

                            if (!_coordFormat.IsMatch(actor.COORDS))
                            {
                                throw new FormatException("The coordinate format provided was not valid.\n" + "Actor: " + actor.TYPE.ToString() + " " + actor.NAME);
                            }

                            coordinates.X = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[0]);
                            coordinates.Y = (float)Convert.ToDouble(_valSplitter.Split(actor.COORDS)[1]);

                            tempComp.addActor(tempActor, actor.NAME);

                            tempActor.init(actor.NAME, coordinates, actorType.ToString(), componentAddresses, actor.param == null ? null : actor.param.Split(','));
                            tempActor.layer = layerCount;
                            tempActor.swapImage(CActor._MAP_ICON);
                            _actorRegistry.Add(tempActor);
                            actorsForDrawList.Add(tempActor);

                            //add queued actors
                            while (tempActor.registrationsQueued)
                            {
                                CActor registration = tempActor.popActorForRegistration();
                                tempComp.addActor(registration, registration.name);
                                registration.layer = layerCount;
                                _actorRegistry.Add(registration);
                                actorsForDrawList.Add(registration);
                            }
                        }
                        //register component
                        _componentRegistry.Add(tempComp);
                        tempComp.layer = layerCount;
                        if (tempComp.address > _largestAddress)
                        {
                            _largestAddress = tempComp.address;
                        }

                        compList[componentCount++] = tempComp;
                        componentAddresses++;
                    }
                }
                CLayer tempLayer = new CLayer(layer.NAME, compList, tiles, ref _tileIndex, layerCount, Convert.ToDouble(_internalMap.VERSION), hitboxAddress);
                tempLayer.addToDrawList(actorsForDrawList);
                actorsForDrawList.Clear();
                _layers.Add(tempLayer);
                layerCount++;
                //_layers[layerCount] = new CLayer(layer.NAME, compList, tiles, ref _tileIndex, Convert.ToDouble(_internalMap.VERSION));

                if (atlasCache == null)
                {
                    tempLayer.otherImages = tileSets;
                }
                else
                {
                    tempLayer.otherImages = atlasCache;
                }
            }

            /*Actors.CComponent[] managers = _createManagers();
             * //add controllers
             * foreach (Actors.CComponent component in managers)
             * {
             *  _layers[0].addComponent(component);
             *  _componentRegistry.Add(component);
             * }*/
        }