public EditCopyCommand(Layer layer, TileSelection tileSelection) { m_layer = layer; m_tileSelection = tileSelection; m_description = "Copy selection from layer \"" + m_layer.Id + "\""; }
protected List<DestroyableTileInfo> ExtractGameObjectPositions(Layer layer, string tileName) { TileArray tileArray = layer.Tiles; Size tileSize = layer.TileSize; Size amntOfTiles = layer.LayerSize; List<DestroyableTileInfo> gameObjectPositions = new List<DestroyableTileInfo>(); for (int x = 0; x < amntOfTiles.Width; x++) { for (int y = 0; y < amntOfTiles.Height; y++) { Location tileLocation = new Location(x, y); Tile thisTile = tileArray[tileLocation]; if (thisTile != null) { DestroyableTileInfo newInfo = new DestroyableTileInfo(); newInfo.ID = thisTile.Properties["id"]; newInfo.Position = new Point(x * tileSize.Width, y * tileSize.Height); newInfo.TileName = tileName; gameObjectPositions.Add(newInfo); } } } return gameObjectPositions; }
public LayerPropertiesDialog(Layer layer, bool isNewLayer) { InitializeComponent(); m_layer = layer; m_isNewLayer = isNewLayer; }
public TileAnimationCommand(Layer layer, Location tileLocation, AnimatedTile animatedTile) { m_layer = layer; m_tileLocation = tileLocation; m_animatedTile = animatedTile; m_oldTile = null; m_description = "Set animated tile at " + tileLocation; }
public LayerDeleteCommand(Map map, Layer layer, MapTreeView mapTreeView) { m_map = map; m_layer = layer; m_layerIndex = map.Layers.IndexOf(layer); m_mapTreeView = mapTreeView; m_description = "Delete layer \"" + layer.Id + "\""; }
public ToolsEraseTileCommand(Layer layer, Location tileLocation) { m_layer = layer; m_tileLocation = tileLocation; m_description = "Erase tile at " + m_tileLocation + " in layer \"" + m_layer.Id + "\""; }
public Actor1(Texture2D texture, Point position, Microsoft.Xna.Framework.Rectangle collisionBox, Map map) { this.map = map; collisiona = map.Layers[3]; Position = position; Texture = texture; Collisionbox = collisionBox; }
public LayerOrderCommand(Layer layer, LayerOrderCommandType layerOrderCommandType) { m_layer = layer; m_layerOrderCommandType = layerOrderCommandType; m_description = layerOrderCommandType == LayerOrderCommandType.BringForward ? "Bring layer \"" + layer.Id + "\" forward" : "Send layer \"" + layer.Id + "\" backward"; }
public TileAnimationDialog(Map map, Layer layer, Location tileLocation) { InitializeComponent(); m_map = map; m_layer = layer; m_tileLocation = tileLocation; }
public LayerVisibilityCommand(Layer layer, bool newVisibility) { m_layer = layer; m_oldVisibility = layer.Visible; m_newVisibility = newVisibility; m_description = "Make layer \"" + m_layer.Id + "\" " + (m_newVisibility ? "visible" : "invisibile"); }
public EditDeleteCommand(Layer layer, TileSelection tileSelection) { m_layer = layer; m_selectionLocation = tileSelection.Bounds.Location; m_tileSelection = tileSelection; m_tileBrush = null; m_description = "Erase selection from layer \"" + m_layer.Id + "\""; }
public EditCutCommand(Layer layer, TileSelection tileSelection) { m_layer = layer; m_selectionLocation = tileSelection.Bounds.Location; m_tileSelection = tileSelection; m_oldTiles = null; m_description = "Cut selection from layer \"" + m_layer.Id + "\""; }
public bool IsIntersectingExplosion(Layer layer, MazeActor actor) { /* if (layer.Tiles[0, 0] == null) { // no tile here } */ return false; }
/// <summary> /// Constructs a new animated tile for the given layer, using the /// given tile frames and frame interval /// </summary> /// <param name="layer">Layer to assign the tile to</param> /// <param name="tileFrames">Array of StaticTile instances</param> /// <param name="frameInterval">Frame interval in milliseconds</param> public AnimatedTile(Layer layer, StaticTile[] tileFrames, long frameInterval) : base(layer) { if (frameInterval <= 0) throw new Exception("Frame interval must be strictly positive"); m_tileFrames = new StaticTile[tileFrames.Length]; tileFrames.CopyTo(m_tileFrames, 0); m_frameInterval = frameInterval; m_animationInterval = frameInterval * tileFrames.Length; }
public List<GameObject> GetGameObjects(Game game, Map map) { _layer = map.GetLayer(_layerName); if (_layer != null) { return CreateGameObjects(ExtractGameObjectPositions(_layer), game); } else { return new List<GameObject>(); } }
xTile.Dimensions.Rectangle _viewport; //camera #endregion Fields #region Constructors public Level(int levelNumber) { //set camera size based on screen size _viewport = new xTile.Dimensions.Rectangle( new xTile.Dimensions.Size( Game1.SCREEN_WIDTH, Game1.SCREEN_HEIGHT)); //load the map for the specified level _tileMap = Content.Load<Map>("Maps\\" + levelNumber); //load tile sheet _tileMap.LoadTileSheets(MapDisplayDevice); _collisionLayer = _tileMap.Layers[0]; }
public ToolsSelectCommand(Layer layer, TileSelection currentTileSelection, TileSelection newTileSelection, bool replace) { m_layer = layer; m_currentTileSelection = currentTileSelection; m_oldTileSelection = new TileSelection(currentTileSelection); m_newTileSelection = new TileSelection(newTileSelection); m_replace = replace; if (m_replace) m_description = newTileSelection.IsEmpty() ? "Clear selection" : "Select tiles"; else m_description = "Select more tiles"; }
/// <summary> /// Constructs a static tile for the given layer, tile sheet, blend /// mode and tile index /// </summary> /// <param name="layer">Layer to assign the tile to</param> /// <param name="tileSheet">Tile sheet associated with the tile</param> /// <param name="blendMode">Tile blend mode</param> /// <param name="tileIndex">Index of the tile in the given tile sheet</param> public StaticTile(Layer layer, TileSheet tileSheet, BlendMode blendMode, int tileIndex) : base(layer) { if (!layer.Map.TileSheets.Contains(tileSheet)) throw new Exception("The specified TileSheet is not in the parent map"); m_blendMode = blendMode; m_tileSheet = tileSheet; if (tileIndex < 0 || tileIndex >= tileSheet.TileCount) throw new Exception("The specified Tile Index is out of range"); m_tileIndex = tileIndex; }
public EditPasteCommand(Layer layer, TileBrush tileBrush, Location brushLocation, TileSelection tileSelection, bool fromClipboard) { m_layer = layer; m_tileBrush = tileBrush; m_brushLocation = brushLocation; m_tileSelection = tileSelection; m_fromClipboard = fromClipboard; m_oldTiles = null; m_description = fromClipboard ? "Paste copied tiles" : "Paste tile brush \"" + tileBrush.Id + "\""; m_description += " at " + m_brushLocation + " in layer \"" + m_layer.Id + "\""; }
public InLevel(int levelNumber, ContentManager content) { //general purpose hit detection rectangle _hitRect = new Rectangle(0, 0, 0, 0); _sprite = new Sprite(content.Load<Texture2D>("character"), 48, 48, 2, 2, TimeSpan.FromSeconds(0.2), 4); _sprite.SetLocation(60, Game1.SCREEN_HEIGHT - 2 * Tile.TILE_WIDTH); _tileMap = content.Load<Map>("Maps/level1"); _tileMap.LoadTileSheets(MapDisplayDevice); _viewport = new xTile.Dimensions.Rectangle( new xTile.Dimensions.Size( Game1.SCREEN_WIDTH, Game1.SCREEN_HEIGHT)); _collisionLayer = _tileMap.Layers[0]; }
public ToolsTileBlockCommand(Layer layer, TileSheet tileSheet, int tileIndex, Location blockLocation, Size blockSize) { m_layer = layer; m_tileSheet = tileSheet; m_tileIndex = tileIndex; m_blockLocation = blockLocation; m_oldTiles = new Tile[blockSize.Width, blockSize.Height]; m_oldFringeAssignments = new Dictionary<Location, Tile>(); m_description = "Draw a block of tiles \"" + m_tileSheet.Id + ":" + m_tileIndex + "\" at " + m_blockLocation + " of size " + blockSize + " in layer \"" + m_layer.Id + "\""; }
public LayerOffsetCommand(Layer layer, Location offset, bool wrapHorizontally, bool wrapVertically) { m_layer = layer; m_offset = offset; m_wrapHorizontally = wrapHorizontally; m_wrapVertically = wrapVertically; m_tiles = null; m_description = "Offset layer \"" + m_layer.Id + "\" by " + m_offset + " tiles "; if (m_wrapHorizontally && m_wrapVertically) m_description += "with horizontal and vertical wrapping"; else if (m_wrapHorizontally) m_description += "with horizontal wrapping only"; else if (m_wrapVertically) m_description += "with vertical wrapping only"; else m_description += "without wrapping"; }
public Dictionary<Location, Tile> DetermineTileAssignments(Layer layer, Location tileLocation, StaticTile staticTile) { Dictionary<Location, Tile> allAssignments = new Dictionary<Location, Tile>(); foreach (AutoTile autoTile in m_autoTiles) { if (autoTile.TileSheet != staticTile.TileSheet) continue; Dictionary<Location, Tile> assignments = autoTile.DetermineTileAssignments(layer, tileLocation, staticTile.TileIndex); foreach (Location location in assignments.Keys) allAssignments[location] = assignments[location]; } if (m_autoTiles.Count == 0) allAssignments[tileLocation] = staticTile.Clone(layer); return allAssignments; }
public Character(Texture2D texture, int currentFrame, int spriteWidth, int spriteHeight, Map map) { this.spriteTexture = texture; this.currentFrame = currentFrame; this.spriteWidth = spriteWidth; this.spriteHeight = spriteHeight; this._map = map; if (!(_map == null)) { Console.WriteLine("_map != null"); } this.collision = map.GetLayer("Colision"); //this.collision = _map.Layers[3]; m_vecLeafPositions = new Vector2[20]; m_vecLeafVelocities = new Vector2[m_vecLeafPositions.Length]; }
public ToolsPlaceTileCommand(Layer layer, Tile newTile, Location tileLocation) { m_layer = layer; if (newTile is StaticTile) { m_newAssignments = AutoTileManager.Instance.DetermineTileAssignments( m_layer, tileLocation, (StaticTile) newTile); } else { m_newAssignments = new Dictionary<Location, Tile>(); m_newAssignments[tileLocation] = newTile; } m_oldAssignments = new Dictionary<Location, Tile>(); foreach (Location assignedLocation in m_newAssignments.Keys) m_oldAssignments[assignedLocation] = layer.Tiles[assignedLocation]; m_description = "Place tile \"" + newTile.TileSheet.Id + ":" + newTile.TileIndex + "\" at " + tileLocation + " in layer \"" + m_layer.Id + "\""; }
public EditChangeSelectionCommand(Layer layer, TileSelection currentTileSelection, ChangeSelectionType changeSelectionType) { m_layer = layer; m_currentTileSelection = currentTileSelection; m_oldTileSelection = new TileSelection(currentTileSelection); m_changeSelectionType = changeSelectionType; switch (m_changeSelectionType) { case ChangeSelectionType.SelectAll: m_description = "Select all tiles"; break; case ChangeSelectionType.Clear: m_description = "Clear tile selection"; break; case ChangeSelectionType.Invert: m_description = "Invert tile selection"; break; } }
internal TileBrush(string id, Layer layer, TileSelection tileSelection) { m_id = id; xTile.Dimensions.Rectangle selectionBounds = tileSelection.Bounds; m_brushSize = selectionBounds.Size; m_tileSize = layer.TileSize; m_displaySize = new xTile.Dimensions.Size( m_brushSize.Width * m_tileSize.Width, m_brushSize.Height * m_tileSize.Height); m_tileBrushElements = new List<TileBrushElement>(); foreach (Location location in tileSelection.Locations) { if (!layer.IsValidTileLocation(location)) continue; Tile tile = layer.Tiles[location]; Tile tileClone = tile == null ? null : tile.Clone(layer); TileBrushElement tileBrushElement = new TileBrushElement( tileClone, location - selectionBounds.Location); m_tileBrushElements.Add(tileBrushElement); } }
protected List<Vector2> ExtractGameObjectPositions(Layer layer) { TileArray tileArray = layer.Tiles; Size tileSize = layer.TileSize; Size amntOfTiles = layer.LayerSize; List<Vector2> gameObjectPositions = new List<Vector2>(); for (int x = 0; x < amntOfTiles.Width; x++) { for (int y = 0; y < amntOfTiles.Height; y++) { Location tileLocation = new Location(x, y); Tile thisTile = tileArray[tileLocation]; if (thisTile != null) { Vector2 position = new Vector2(x * tileSize.Width, y * tileSize.Height); gameObjectPositions.Add(position); } } } return gameObjectPositions; }
public Map Load(Stream stream) { ReadHeader(stream); MphdRecord mphdRecord = null; string[] authorLines = null; Color[] colourMap = null; BlockRecord[] blockRecords = null; AnimationRecord[] animationRecords = null; Image imageSource = null; short[][] layers = new short[8][]; Dictionary<string, Chunk> chunks = MapChunks(stream); if (!chunks.ContainsKey("MPHD")) throw new Exception("Header chunk MPHD missing"); Chunk mphdChunk = chunks["MPHD"]; mphdRecord = ReadChunkMPHD(stream, mphdChunk); if (mphdRecord.BlockDepth == 8) { if (!chunks.ContainsKey("CMAP")) throw new Exception("Colour map chuck CMAP is required for 8bit graphics blocks"); Chunk cmapChunk = chunks["CMAP"]; colourMap = ReadChunkCMAP(stream, cmapChunk); } if (chunks.ContainsKey("ATHR")) authorLines = ReadChunkATHR(stream, chunks["ATHR"]); if (!chunks.ContainsKey("BKDT")) throw new Exception("Block data chunk BKDT missing"); Chunk bkdtChunk = chunks["BKDT"]; blockRecords = ReadChunkBKDT(stream, bkdtChunk, mphdRecord); // optional ? if (chunks.ContainsKey("ANDT")) { Chunk andtChunk = chunks["ANDT"]; animationRecords = ReadChunkANDT(stream, andtChunk, mphdRecord); } if (!chunks.ContainsKey("BGFX")) throw new Exception("Block graphics chunk BGFX missing"); Chunk bgfxChunk = chunks["BGFX"]; imageSource = ReadChunkBGFX(stream, bgfxChunk, mphdRecord, colourMap); if (!chunks.ContainsKey("BODY")) throw new Exception("Body chunk BODY missing"); Chunk bodyChunk = chunks["BODY"]; layers[0] = ReadChunkLayer(stream, bodyChunk, mphdRecord); // additional layers for (int layer = 1; layer <= 7; layer++) { string chunkId = "LYR" + layer; if (chunks.ContainsKey(chunkId)) { Chunk layerChuck = chunks[chunkId]; layers[layer] = ReadChunkLayer(stream, layerChuck, mphdRecord); } } // new map Map map = new Map(); // attach ATHR lines as description if (authorLines != null) { StringBuilder stringBuilder = new StringBuilder(); foreach (string authorLine in authorLines) stringBuilder.AppendLine(authorLine); map.Description = stringBuilder.ToString(); } // prompt user to save tilesheet image source SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = "Portable Network Geaphics (*.png)|*.png"; saveFileDialog.OverwritePrompt = true; saveFileDialog.Title = "Save tile sheet image source as"; saveFileDialog.ValidateNames = true; if (saveFileDialog.ShowDialog() == DialogResult.Cancel) throw new Exception("Mappy FMAP file import aborted"); string tileSheetImageSource = saveFileDialog.FileName; imageSource.Save(tileSheetImageSource, ImageFormat.Png); // determine global tile size xTile.Dimensions.Size tileSize = new xTile.Dimensions.Size(mphdRecord.BlockWidth, mphdRecord.BlockHeight); // add tilesheet TileSheet tileSheet = new TileSheet("BGFX", map, tileSheetImageSource, new xTile.Dimensions.Size(1, mphdRecord.NumBlockGfx), tileSize); map.AddTileSheet(tileSheet); // determine global map size xTile.Dimensions.Size mapSize = new xTile.Dimensions.Size(mphdRecord.MapWidth, mphdRecord.MapHeight); // create layers for (int layerIndex = 0; layerIndex < 8; layerIndex++) { if (layers[layerIndex] == null) continue; string layerId = layerIndex == 0 ? "BODY" : "LYR" + layerIndex; Layer layer = new Layer(layerId, map, mapSize, tileSize); map.AddLayer(layer); for (int tileY = 0; tileY < mapSize.Height; tileY++) { for (int tileX = 0; tileX < mapSize.Width; tileX++) { int layerOffset = tileY * mapSize.Width + tileX; int tileIndex = layers[layerIndex][layerOffset]; if (tileIndex >= 0) { layer.Tiles[tileX, tileY] = new StaticTile(layer, tileSheet, BlendMode.Alpha, tileIndex); } else { AnimationRecord animationRecord = animationRecords[-tileIndex - 1]; StaticTile[] tileFrames = new StaticTile[animationRecord.Frames.Length]; for (int frameIndex = 0; frameIndex < animationRecord.Frames.Length; frameIndex++) tileFrames[frameIndex] = new StaticTile(layer, tileSheet, BlendMode.Alpha, animationRecord.Frames[frameIndex]); // process loop types switch (animationRecord.Type) { case 2: // LOOPR: loop backward Array.Reverse(tileFrames); break; case 5: // PPFF -+ case 6: // PPRR | - different states for ping-pong animation case 7: // PPRF | - treat all the same case 8: // PPFR -+ StaticTile[] pingPongFrames = new StaticTile[tileFrames.Length * 2 - 1]; Array.Copy(tileFrames, pingPongFrames, tileFrames.Length); Array.Copy(tileFrames, 0, pingPongFrames, tileFrames.Length, tileFrames.Length - 1); Array.Reverse(pingPongFrames, tileFrames.Length, tileFrames.Length - 1); tileFrames = pingPongFrames; break; default: // treat all other cases as LOOPF // 0 = NONE // 1 = LOOPF: loop forward // 3 = ONCE, 4 = ONCEH: one-off animations // 9 = ONCES: one-off animations break; } AnimatedTile animatedTile = new AnimatedTile(layer, tileFrames, (long)animationRecord.Delay * 20); layer.Tiles[tileX, tileY] = animatedTile; } } } } return map; }
private void WriteChunkLayer(Stream stream, Layer layer, string chunkId, AnimatedTile[] animatedTiles) { // BODY or LYR1 .. LYR7 WriteSequence(stream, chunkId); // size is array of shorts int layerWidth = layer.LayerWidth; int layerHeight = layer.LayerHeight; WriteMsb(stream, (long)(layerWidth * layerHeight * 2)); for (int tileY = 0; tileY < layerHeight; tileY++) { for (int tileX = 0; tileX < layerWidth; tileX++) { Tile tile = layer.Tiles[tileX, tileY]; if (tile == null) WriteLsb(stream, (short)0); else if (tile is StaticTile) WriteLsb(stream, (short)(tile.TileIndex * 32)); else if (tile is AnimatedTile) { if (animatedTiles == null) WriteLsb(stream, (short)0); else { AnimatedTile animatedTile = (AnimatedTile)tile; int animationIndex = -1; for (int listIndex = 0; listIndex < animatedTiles.Length; listIndex++) { if (AnimationsMatch(animatedTile, animatedTiles[listIndex])) { animationIndex = listIndex; break; } } if (animationIndex < 0) WriteLsb(stream, (short)0); else { short animationOffset = (short)((animationIndex - animatedTiles.Length) * AnimationRecord.SIZE); WriteLsb(stream, animationOffset); } } } else throw new Exception("Unknown tile type: " + tile.GetType()); } } }