private int _width, _height; //PIXELS!!! #endregion Fields #region Constructors public CLayer(string name, Actors.CComponent[] components, CTile[] tiles) { NAME = name; _tiles = tiles; _components = new ComponentManager(new ComponentFactory[]{ new ComponentFactory(components) } ); _image = Graphics.CTextures.generateLayerImage(this, tiles); }
public void updateLayer(Microsoft.Xna.Framework.GameTime gameTime) { //components _components.Update(gameTime); //update tiles for (int i = 0; i < _tiles.Count; i++) { CTile tile = _tiles[i]; Vector2 dimensions = Vector2.Zero; //get tileset info if (string.IsNullOrEmpty(tile.tileSet)) { dimensions = _imageVector; } else { dimensions = tile.dimensions; } tile.shouldDraw = CMasterControl.buttonController.checkCullBoundary(tile.tileCoords, dimensions); if (tile.shouldDraw) { tile.update(); } } }
public void tileCoordConverter() { for (int i = 0; i < _tiles.Count; i++) { CTile tile = _tiles[i]; tile.tileCoords.X *= 16; tile.tileCoords.Y *= 16; } }
public CTile getTileInfo(int index) { CTile temp = _tiles[index] as CAnimatedTile; if (temp == null) { return(new CTile(_tiles[index].atlasCoords, _tiles[index].tileCoords, _tiles[index].tileSet)); } else { CAnimatedTile anim = (CAnimatedTile)temp; return(new CAnimatedTile(anim.startingPosition, anim.atlasCoordsEnd, anim.tileCoords, anim.tileSet, anim.speed)); } }
public CTile(CTile copy) { this.tileCoords = copy.tileCoords; this.tileSet = copy.tileSet; this._tileBounds = copy._tileBounds; if (_boundary == null) { _boundary = new Actors.Collision.CHitBox(null, tileCoords.X, tileCoords.Y, Graphics.CTextures.textures[tileSet].FrameWidth, Graphics.CTextures.textures[tileSet].FrameHeight); } else { _dimensions = new Vector2(Graphics.CTextures.textures[tileSet].FrameWidth, Graphics.CTextures.textures[tileSet].FrameHeight); } }
public void drawLayer(SpriteBatch spriteBatch = null) { for (int i = 0; i < _tiles.Count; i++) { CTile tile = _tiles[i]; if (spriteBatch == null && !tile.shouldDraw) { continue; } otherImages[tile.tileSet].draw((int)(tile.tileCoords.X), (int)(tile.tileCoords.Y), (int)(tile.atlasCoords.X), (int)(tile.atlasCoords.Y), 1, 1, true, spriteBatch); } if (_components != null) { _drawlist.drawAll(_layerIndex, spriteBatch); } _tilesOnScreen.Clear(); }
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); } }
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); } }
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); * }*/ }
public void writeMap(string fileName) { //Gears.Cartography.Map _internalMap = new Gears.Cartography.Map(); _internalMap.VERSION = "1"; _internalMap.LAYERS = new Gears.Cartography.layer[_layers.Count()]; _internalMap.NUM_LAYERS = (byte)_internalMap.LAYERS.Count(); _internalMap.TILESET = _tileIndex == null ? null : _tileIndex.atlasName; if (!string.IsNullOrWhiteSpace(_bgmLoc) && !string.IsNullOrWhiteSpace(_bgmRef)) { _internalMap.BGM_FILE = new Gears.Cartography.bgmFile(); _internalMap.BGM_FILE.BGM_FILE_LOC = _bgmLoc; _internalMap.BGM_FILE.BGM_REF_NAME = _bgmRef; } for (int i = 0; i < _layers.Count(); i++) { Dictionary <int, List <string> > actorData = null; _internalMap.LAYERS[i] = new Gears.Cartography.layer(); _internalMap.LAYERS[i].LAYER_WIDTH = _layers[i].width; _internalMap.LAYERS[i].LAYER_HEIGHT = _layers[i].height; _internalMap.LAYERS[i].NAME = _layers[i].NAME; _internalMap.LAYERS[i].TILES = new Gears.Cartography.tile[_layers[i].numberOfTiles]; actorData = _layers[i].getActorHeaderInfo(); _internalMap.LAYERS[i].COMPONENTS = new Gears.Cartography.component[_layers[i].componentCount]; int componentCounter = 0; foreach (CComponent component in _componentRegistry) { if (component.layer == i) { _internalMap.LAYERS[i].COMPONENTS[componentCounter] = new Gears.Cartography.component(); Gears.Cartography.component comp = _internalMap.LAYERS[i].COMPONENTS[componentCounter]; comp.ADDRESS = component.address; comp.ACTORS = new Gears.Cartography.actors[component.actors.Count + 1]; //write the root component comp.ACTORS[0] = new Gears.Cartography.actors(); comp.ACTORS[0].NAME = component.root.name; comp.ACTORS[0].TYPE = component.root.dataType; comp.ACTORS[0].COORDS = component.root.position.X + ":" + component.root.position.Y; foreach (string param in component.root.mapParams) { comp.ACTORS[0].param += param + ","; } if (comp.ACTORS[0].param != null) { comp.ACTORS[0].param = comp.ACTORS[0].param.Substring(0, comp.ACTORS[0].param.Length - 1); } //write the rest for (int j = 1; j < comp.ACTORS.Count(); j++) { List <CActor> actors = component.actors.Values.ToList(); comp.ACTORS[j] = new Gears.Cartography.actors(); comp.ACTORS[j].NAME = actors[j - 1].name; comp.ACTORS[j].TYPE = actors[j - 1].dataType; comp.ACTORS[j].COORDS = actors[j - 1].position.X + ":" + actors[j - 1].position.Y; foreach (string param in actors[j - 1].mapParams) { comp.ACTORS[j].param += param + ","; } if (comp.ACTORS[j].param != null) { comp.ACTORS[j].param = comp.ACTORS[j].param.Substring(0, comp.ACTORS[j].param.Length - 1); } } componentCounter++; } } for (int j = 0; j < _internalMap.LAYERS[i].TILES.Count(); j++) { _internalMap.LAYERS[i].TILES[j] = new Gears.Cartography.tile(); CTile temp = _layers[i].getTileInfo(j); _internalMap.LAYERS[i].TILES[j].COORDS = temp.tileCoords.X + ":" + temp.tileCoords.Y; _internalMap.LAYERS[i].TILES[j].TILESELECTION = temp.atlasCoords.X + ":" + temp.atlasCoords.Y; _internalMap.LAYERS[i].TILES[j].TILESET = temp.tileSet; CAnimatedTile animTemp = temp as CAnimatedTile; if (animTemp != null) { _internalMap.LAYERS[i].TILES[j].TILESELECTION = animTemp.startingPosition.X + ":" + animTemp.startingPosition.Y; _internalMap.LAYERS[i].TILES[j].TILESELECTIONEND = animTemp.atlasCoordsEnd.X + ":" + animTemp.atlasCoordsEnd.Y; _internalMap.LAYERS[i].TILES[j].SPEED = animTemp.speed; } temp = null; animTemp = null; } } _internalMap.serializeToXml(fileName); }
public void addTile(CTile tile) { _tiles.Add(tile); }