/// Apply a set of map overrides to the farm map. private void PatchMap(Farm farm, Tile[] tiles) { foreach (Tile tile in tiles) { if (tile.TileIndex < 0) { farm.removeTile(tile.X, tile.Y, farm.map.Layers[tile.LayerIndex].Id); farm.waterTiles[tile.X, tile.Y] = false; foreach (LargeTerrainFeature feature in farm.largeTerrainFeatures) { if (feature.tilePosition.X == tile.X && feature.tilePosition.Y == tile.Y) { farm.largeTerrainFeatures.Remove(feature); } } } else { Layer layer = farm.map.Layers[tile.LayerIndex]; xTile.Tiles.Tile mapTile = layer.Tiles[tile.X, tile.Y]; if (mapTile == null || mapTile.TileSheet.Id != tile.Tilesheet) { layer.Tiles[tile.X, tile.Y] = new StaticTile(layer, farm.map.GetTileSheet(tile.Tilesheet), 0, tile.TileIndex); } else { farm.setMapTileIndex(tile.X, tile.Y, tile.TileIndex, layer.Id); } } } }
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; }
/// <summary>Check if the dresser is in the location.</summary> /// <param name="pos">The tile location.</param> public bool IsDresser(Vector2 pos) { xTile.Tiles.Tile tile = Game1.currentLocation.map.GetLayer("Buildings").PickTile(new xTile.Dimensions.Location((int)pos.X * Game1.tileSize, (int)pos.Y * Game1.tileSize), Game1.viewport.Size); xTile.ObjectModel.PropertyValue propertyValue = null; tile?.Properties.TryGetValue("Action", out propertyValue); if (propertyValue?.ToString() != "Kisekae") { return(false); } return(true); }
public TilePropertiesCommand(Tile tile, string newId, BlendMode newBlendMode, PropertyCollection newProperties) { m_tile = tile; m_oldId = tile.Id; m_oldBlendMode = tile.BlendMode; m_oldProperties = new PropertyCollection(tile.Properties); m_newId = newId; m_newBlendMode = newBlendMode; m_newProperties = newProperties; m_description = "Change tile properties"; }
/********* ** Protected methods *********/ private void CheckForAction() { if (Game1.activeClickableMenu == null && !Game1.player.UsingTool && !Game1.pickingTool && !Game1.menuUp && (!Game1.eventUp || Game1.currentLocation.currentEvent.playerControlSequence) && !Game1.nameSelectUp && Game1.numberOfSelectedItems == -1 && !Game1.fadeToBlack) { this.ActionInfo = null; Vector2 grabTile = new Vector2(Game1.getOldMouseX() + Game1.viewport.X, Game1.getOldMouseY() + Game1.viewport.Y) / Game1.tileSize; if (!Utility.tileWithinRadiusOfPlayer((int)grabTile.X, (int)grabTile.Y, 1, Game1.player)) { grabTile = Game1.player.GetGrabTile(); } xTile.Tiles.Tile tile = Game1.currentLocation.map.GetLayer("Buildings").PickTile(new Location((int)grabTile.X * Game1.tileSize, (int)grabTile.Y * Game1.tileSize), Game1.viewport.Size) ?? Game1.currentLocation.map.GetLayer("Buildings").PickTile(new Location((int)grabTile.X * Game1.tileSize, (int)(grabTile.Y + 1) * Game1.tileSize), Game1.viewport.Size); if (tile != null && tile.Properties.TryGetValue("Action", out PropertyValue propertyValue) && propertyValue != null) { string[] split = ((string)propertyValue).Split(' '); string[] args = new string[split.Length - 1]; Array.Copy(split, 1, args, 0, args.Length); this.ActionInfo = new ActionInfo(Game1.player, split[0], args, grabTile); } } }
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 + "\""; }
/// <summary> /// Draws the given tile at the given location /// </summary> /// <param name="tile">Tile to draw</param> /// <param name="location">Drawing location</param> public void DrawTile(Tile tile, Location location) { if (tile == null) return; SpriteBatch spriteBatch = tile.BlendMode == BlendMode.Alpha ? m_spriteBatchAlpha : m_spriteBatchAdditive; xTile.Dimensions.Rectangle sourceRectangle = tile.TileSheet.GetTileImageBounds(tile.TileIndex); Texture2D texture2D = m_tileSheetTextures[tile.TileSheet]; m_tilePosition.X = location.X; m_tilePosition.Y = location.Y; m_sourceRectangle.X = sourceRectangle.X; m_sourceRectangle.Y = sourceRectangle.Y; m_sourceRectangle.Width = sourceRectangle.Width; m_sourceRectangle.Height = sourceRectangle.Height; spriteBatch.Draw(texture2D, m_tilePosition, m_sourceRectangle, m_modulationColour); }
public void DrawTile(Tile tile, Location location) { if (m_graphics == null) return; Bitmap tileBitmap = TileImageCache.Instance.GetTileBitmap( tile.TileSheet, tile.TileIndex); xTile.Dimensions.Size tileSize = tile.TileSheet.TileSize; System.Drawing.Rectangle destRect = new System.Drawing.Rectangle( location.X, location.Y, tileSize.Width, tileSize.Height); if (tile.BlendMode == BlendMode.Alpha) { m_graphics.DrawImage(tileBitmap, destRect, 0, 0, tileSize.Width, tileSize.Height, GraphicsUnit.Pixel, m_imageAttributes); } else { // manual additive blending using back buffer bitmap // determine clipping int minSrcX = 0; int minSrcY = 0; int maxSrcX = tileSize.Width; int maxSrcY = tileSize.Height; int minDstX = destRect.X; int minDstY = destRect.Y; int maxDstX = destRect.Right; int maxDstY = destRect.Bottom; // clip min x if (minDstX < 0) { minSrcX = -minDstX; minDstX = 0; } // clip min y if (minDstY < 0) { minSrcY = -minDstY; minDstY = 0; } // clip max x if (maxDstX > m_backBuffer.Width) { int difference = maxDstX - m_backBuffer.Width; maxSrcX -= difference; maxDstX = m_backBuffer.Width; } // clip max y if (maxDstY > m_backBuffer.Height) { int difference = maxDstY - m_backBuffer.Height; maxSrcY -= difference; maxDstY = m_backBuffer.Height; } // draw only if clipped region within buffer if (minSrcX < maxSrcX && minSrcY < maxSrcY) { int srcY = minSrcY; for (int dstY = minDstY; dstY < maxDstY; dstY++) { int srcX = minSrcX; for (int dstX = minDstX; dstX < maxDstX; dstX++) { Color backPixel = m_backBuffer.GetPixel(dstX, dstY); Color tilePixel = tileBitmap.GetPixel(srcX, srcY); Color destPixel = Color.FromArgb(backPixel.A, (byte)Math.Min(255, backPixel.R + ((int)tilePixel.R * tilePixel.A) / 255), (byte)Math.Min(255, backPixel.G + ((int)tilePixel.G * tilePixel.A) / 255), (byte)Math.Min(255, backPixel.B + ((int)tilePixel.B * tilePixel.A) / 255)); m_backBuffer.SetPixel(dstX, dstY, destPixel); ++srcX; } ++srcY; } } } }
private int GetSetIndex(Tile tile) { if (tile == null) return -1; if (!(tile is StaticTile)) return -1; if (tile.TileSheet != m_tileSheet) return -1; return GetSetIndex(tile.TileIndex); }
public MapPanelEventArgs(Tile tile, Location location) { m_tile = tile; m_location = location; }
public TileBrushElement(Tile tile, Location location) { m_tile = tile; m_location = location; }
public TilePropertiesDialog(Tile tile) { InitializeComponent(); m_tile = tile; }
public override void Update(GameTime gameTime) { KeyboardState kb = Keyboard.GetState(); gravityTimer += (float)gameTime.ElapsedGameTime.Milliseconds; if (gravityTimer > gravityTimerMax && !onGround) { this.velocity.Y += gravity; gravityTimer = 0f; } invulnerabilityTimer -= (float)gameTime.ElapsedGameTime.Milliseconds; if (invulnerabilityTimer <= 0) { invulnerabilityTimer = 0; } // Check collision below KeyValuePair <xTile.Tiles.Tile, Vector2> ctest = CollisionEdgeTest(new Vector2(this.Location.X, this.Location.Y + this.BoundingBoxRect.Height + 1), new Vector2(this.Location.X + this.BoundingBoxRect.Width, this.Location.Y + this.BoundingBoxRect.Height + 1) ); xTile.Tiles.Tile tile = ctest.Key; if (tile != null && !tile.Properties.ContainsKey("Passable")) { if (tile.Properties.Keys.Contains("causeDeath")) { if (tile.Properties["causeDeath"]) { if (!Dead) { Die(); } } } onGround = true; if (!Dead) { this.velocity.Y = 0; this.location.Y -= (this.location.Y + animations[currentAnimation].FrameHeight + 1) % 48; } } else { onGround = false; } if (!Dead) { currentAnimation = "idle" + (isBig ? "Big" : ""); if (!onGround) { currentAnimation = "jump" + (isBig ? "Big" : ""); } // Check collision above ctest = CollisionEdgeTest(new Vector2(this.Location.X, this.Location.Y), new Vector2(this.Location.X + this.BoundingBoxRect.Width, this.Location.Y)); tile = ctest.Key; if (tile != null && !tile.Properties.ContainsKey("Passable")) { if (this.velocity.Y != 0) { this.velocity.Y = 0.01f; this.location.Y = (int)(this.Center.Y / 48) * 48; xTile.Layers.Layer layer = map.GetLayer("Foreground"); if (tile.TileIndex >= 29 && tile.TileIndex <= 32) { if (isBig) { Vector2 loc = ctest.Value * 48; particleManager.SpawnParticle("block1", new Vector2(loc.X, loc.Y), new Vector2(-60, -650), 1200, 0f, true); particleManager.SpawnParticle("block2", new Vector2(loc.X + 24, loc.Y), new Vector2(60, -750), 1200, 0f, true); particleManager.SpawnParticle("block3", new Vector2(loc.X, loc.Y - 24), new Vector2(-20, -625), 1200, 0f, true); particleManager.SpawnParticle("block4", new Vector2(loc.X + 24, loc.Y - 24), new Vector2(20, -590), 1200, 0f, true); layer.Tiles[(int)ctest.Value.X, (int)ctest.Value.Y] = null; } } else if (tile.TileIndex >= 0 && tile.TileIndex <= 3) { layer.Tiles[(int)ctest.Value.X, (int)ctest.Value.Y] = new StaticTile(layer, tile.TileSheet, tile.BlendMode, 122); Vector2 loc = ctest.Value * 48; particleManager.SpawnParticle("coin", new Vector2(loc.X + 12, loc.Y - 24), new Vector2(0, -500), 600, 0f, true); } } } if (kb.IsKeyDown(Keys.Space) && onGround) { Jump(); } if (kb.IsKeyDown(Keys.Down) && onGround && isBig) { currentAnimation = "crouch"; } if (kb.IsKeyDown(Keys.Left)) { if (onGround) { currentAnimation = "run" + (isBig ? "Big" : ""); } this.FlipHorizontal = true; if (this.location.X > (World.viewport.X + WalkableArea.Left)) { this.location.X -= 5; } else if (World.viewport.X > 0) { World.viewport.X -= 5; this.location.X -= 5; } } if (kb.IsKeyDown(Keys.Right)) { if (onGround) { currentAnimation = "run" + (isBig ? "Big" : ""); } this.FlipHorizontal = false; this.location.X += 5; if (this.location.X > (World.viewport.X + WalkableArea.Right)) { World.viewport.X += 5; } } // Right collision test ctest = CollisionEdgeTest(new Vector2(this.Location.X + this.BoundingBoxRect.Width, this.Location.Y), new Vector2(this.Location.X + this.BoundingBoxRect.Width, this.Location.Y + this.BoundingBoxRect.Height - 1)); tile = ctest.Key; if (tile != null && !tile.Properties.ContainsKey("Passable")) { this.location.X -= 5; if (this.location.X >= (World.viewport.X + WalkableArea.Right)) { World.viewport.X -= 5; } } // Left collision test ctest = CollisionEdgeTest(new Vector2(this.Location.X, this.Location.Y), new Vector2(this.Location.X, this.Location.Y + this.BoundingBoxRect.Height - 1)); tile = ctest.Key; if (tile != null && !tile.Properties.ContainsKey("Passable")) { this.location.X += 5; if (this.location.X <= (World.viewport.X + WalkableArea.Left)) { World.viewport.X += 5; } //this.location.X = (int)(this.Center.X / 48) * 48; } } base.Update(gameTime); }
internal TileSheetDependency(Layer layer, Location location, Tile tile) { m_layer = layer; m_location = location; m_tile = tile; }
public override void Do() { m_oldTile = m_layer.Tiles[m_tileLocation]; m_layer.Tiles[m_tileLocation] = m_animatedTile; }
/// <summary> /// Constructs a TileArray for the given Layer and /// using the given 2d Tile array /// </summary> /// <param name="layer"></param> /// <param name="tiles"></param> public TileArray(Layer layer, Tile[,] tiles) { m_layer = layer; m_tileSheets = m_layer.Map.TileSheets; m_tiles = tiles; }
public override void Do() { m_oldTile = m_layer.Tiles[m_tileLocation]; m_layer.Tiles[m_tileLocation] = null; }