/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); map = Content.Load <Map>(@"Levels\Level1"); mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice); map.LoadTileSheets(mapDisplayDevice); xTile.Layers.Layer layer = map.GetLayer("Foreground"); World.viewport = new xTile.Dimensions.Rectangle(new xTile.Dimensions.Size(800, 600)); particleManager = new ParticleManager(map); particleManager.LoadContent(Content); mario = Content.Load <Texture2D>("tiles"); player = new Player(this.Content, new Vector2(350, this.Window.ClientBounds.Height - (48 * 2) - 48), Vector2.Zero, map, particleManager); xTile.Layers.Layer elayer = map.GetLayer("Enemy"); elayer.Visible = false; for (int x = 0; x < elayer.LayerWidth; x++) { for (int y = 0; y < elayer.LayerHeight; y++) { xTile.Tiles.Tile tile = elayer.Tiles[x, y]; if (tile != null) { if (tile.Properties.Keys.Contains("type")) { Vector2 vel = Vector2.Zero; if (tile.Properties.Keys.Contains("velocity")) { vel = new Vector2(90 * tile.Properties["velocity"], 0); } int x_left = -1, x_right = -1; if (tile.Properties.Keys.Contains("x_left")) { x_left = tile.Properties["x_left"]; } if (tile.Properties.Keys.Contains("x_right")) { x_right = tile.Properties["x_right"]; } if (tile.Properties.Keys.Contains("type") && tile.Properties["type"] == "goomba") { enemies.Add(new Enemy(this.Content, new Vector2(x * 48, y * 48), vel, x_left, x_right, map)); } } } } } }
public static void deleteTileIfIndex(xTile.Layers.Layer layer, int x, int y, int index) { if (layer.Tiles[x, y] != null && layer.Tiles[x, y].TileIndex == index) { layer.Tiles[x, y] = null; } }
public static void buildShippingCrate(Map map) { TileSheet sheet = null; foreach (TileSheet tSheet in map.TileSheets) { if (tSheet.ImageSource.Contains("outdoorsTileSheet")) { sheet = tSheet; break; } } if (sheet == null) { sheet = map.TileSheets[0]; Logger.Log("Could not find outdoor tilesheet! Defaulting to the first available tilesheet, '" + sheet.Id + "'..."); } xTile.Layers.Layer buildings = map.GetLayer("Buildings"); xTile.Layers.Layer front = map.GetLayer("Front"); buildings.Tiles[(int)shippingCrateLocation.X, (int)shippingCrateLocation.Y] = new StaticTile(buildings, sheet, BlendMode.Alpha, 387); buildings.Tiles[(int)shippingCrateLocation.X + 1, (int)shippingCrateLocation.Y] = new StaticTile(buildings, sheet, BlendMode.Alpha, 388); front.Tiles[(int)shippingCrateLocation.X, (int)shippingCrateLocation.Y - 1] = new StaticTile(front, sheet, BlendMode.Alpha, 362); front.Tiles[(int)shippingCrateLocation.X + 1, (int)shippingCrateLocation.Y - 1] = new StaticTile(front, sheet, BlendMode.Alpha, 363); }
public static void buildMailBox(Map map) { TileSheet sheet = null; foreach (TileSheet tSheet in map.TileSheets) { if (tSheet.ImageSource.Contains("outdoorsTileSheet")) { sheet = tSheet; break; } } if (sheet == null) { sheet = map.TileSheets[0]; Logger.Log("Could not find outdoor tilesheet! Defaulting to the first available tilesheet, '" + sheet.Id + "'..."); } xTile.Layers.Layer buildings = map.GetLayer("Buildings"); xTile.Layers.Layer front = map.GetLayer("Front"); buildings.Tiles[(int)mailBoxLocation.X, (int)mailBoxLocation.Y] = new StaticTile(buildings, sheet, BlendMode.Alpha, 1955); buildings.Tiles[(int)mailBoxLocation.X, (int)mailBoxLocation.Y].Properties["Action"] = "Mailbox"; front.Tiles[(int)mailBoxLocation.X, (int)mailBoxLocation.Y - 1] = new StaticTile(front, sheet, BlendMode.Alpha, 1930); }
private void openFileDialog_FileOk(object sender, CancelEventArgs e) { currentMap = openFileDialog.SafeFileName.Split('.')[0]; Editor.CurrentMap = Editor.Content.Load <Map>(@"maps/" + currentMap); Editor.CurrentMap.LoadTileSheets(Editor.DisplayDevice); int editorLayerInt = Editor.CurrentMap.Properties["PlayerLayer"]; xTile.Layers.Layer editorLayer = Editor.CurrentMap.Layers[editorLayerInt]; TileMap.TileHeight = Editor.CurrentMap.Properties["TileSize"]; TileMap.TileWidth = Editor.CurrentMap.Properties["TileSize"]; TileMap.MapHeight = editorLayer.TileHeight / TileMap.TileHeight * editorLayer.LayerHeight; TileMap.MapWidth = editorLayer.TileWidth / TileMap.TileWidth * editorLayer.LayerWidth; Camera.UpdateWorldRectangle(); try { TileMap.LoadMap(new FileStream(mapPath + @"/" + currentMap + ".map", FileMode.Open), true); } catch { TileMap.ClearMap(); } gameUpdate.Start(); }
public static void removeVanillaMailboxTiles(Map map) { xTile.Layers.Layer buildings = map.GetLayer("Buildings"); xTile.Layers.Layer front = map.GetLayer("Front"); deleteTileIfIndex(buildings, 68, 16, 1955); deleteTileIfIndex(front, 68, 15, 1930); }
public static Map makeMapCopy(FarmHouse house, string mapPath) { Map sourceMap = loader.Load <Map>(mapPath, ContentSource.GameContent); Map newMap = new Map(); foreach (xTile.Tiles.TileSheet sheet in sourceMap.TileSheets) { xTile.Tiles.TileSheet newSheet = new xTile.Tiles.TileSheet(newMap, sheet.ImageSource, sheet.SheetSize, sheet.TileSize); newSheet.Id = sheet.Id; newMap.AddTileSheet(newSheet); Logger.Log("Adding tilesheet " + newSheet.Id + " (" + newSheet.ImageSource + ")"); } foreach (xTile.Layers.Layer layer in sourceMap.Layers) { xTile.Layers.Layer newLayer = new xTile.Layers.Layer(layer.Id, newMap, layer.LayerSize, layer.TileSize); xTile.Tiles.TileArray tiles = layer.Tiles; for (int x = 0; x < layer.LayerWidth; x++) { for (int y = 0; y < layer.LayerHeight; y++) { if (tiles[x, y] != null) { xTile.Tiles.Tile tile = tiles[x, y]; if (tile is xTile.Tiles.StaticTile) { Logger.Log("Searching for sheet '" + tile.TileSheet.Id + "'..."); newLayer.Tiles[x, y] = new xTile.Tiles.StaticTile(newLayer, newMap.GetTileSheet(tile.TileSheet.Id), tile.BlendMode, tile.TileIndex); } else { xTile.Tiles.AnimatedTile animTile = (tile as xTile.Tiles.AnimatedTile); xTile.Tiles.StaticTile[] frames = new xTile.Tiles.StaticTile[animTile.TileFrames.Length]; for (int frame = 0; frame < animTile.TileFrames.Length; frame++) { frames[frame] = new xTile.Tiles.StaticTile(newLayer, newMap.GetTileSheet(animTile.TileSheet.Id), animTile.BlendMode, animTile.TileFrames[frame].TileIndex); } newLayer.Tiles[x, y] = new xTile.Tiles.AnimatedTile(newLayer, frames, animTile.FrameInterval); } foreach (string key in tile.Properties.Keys) { newLayer.Tiles[x, y].Properties[key] = tile.Properties[key]; } } } } foreach (string key in layer.Properties.Keys) { newLayer.Properties[key] = layer.Properties[key]; } newMap.AddLayer(newLayer); } foreach (string key in sourceMap.Properties.Keys) { newMap.Properties[key] = sourceMap.Properties[key]; } return(newMap); }
public static void removeVanillaShippingCrateTiles(Map map) { xTile.Layers.Layer buildings = map.GetLayer("Buildings"); xTile.Layers.Layer front = map.GetLayer("Front"); deleteTileIfIndex(buildings, 71, 14, 387); deleteTileIfIndex(buildings, 72, 14, 388); deleteTileIfIndex(front, 71, 13, 362); deleteTileIfIndex(front, 72, 13, 363); }
/// <summary> /// Identifies the level of the best cooking station within the player's use range. /// A cooking station's level influences the number of ingredients slots available to the player. /// </summary> /// <returns>Level of the best cooking station in range, defaults to 0.</returns> public static int GetNearbyCookingStationLevel() { int radius = int.Parse(ModEntry.ItemDefinitions["CookingUseRange"][0]); int cookingStationLevel = 0; if (Game1.currentLocation.IsOutdoors) { // If outdoors, use the player's tool level for ingredients slots cookingStationLevel = Utils.GetFarmersMaxUsableIngredients(); Log.D($"Cooking station: {Game1.currentLocation.Name}: Outdoors (level {cookingStationLevel})", ModEntry.Config.DebugMode); } else { // If indoors, use the farmhouse or cabin level as a base for ingredients slots xTile.Layers.Layer layer = Game1.currentLocation.Map.GetLayer("Buildings"); int xLimit = Game1.player.getTileX() + radius; int yLimit = Game1.player.getTileY() + radius; for (int x = Game1.player.getTileX() - radius; x < xLimit && cookingStationLevel == 0; ++x) { for (int y = Game1.player.getTileY() - radius; y < yLimit && cookingStationLevel == 0; ++y) { xTile.Tiles.Tile tile = layer.Tiles[x, y]; if (tile == null || (Game1.currentLocation.doesTileHaveProperty(x, y, "Action", "Buildings") != "kitchen" && !ModEntry.IndoorsTileIndexesThatActAsCookingStations.Contains(tile.TileIndex))) { continue; } switch (Game1.currentLocation) { case FarmHouse farmHouse: // FarmHouses use their upgrade level as a baseline after Robin installs a kitchen cookingStationLevel = Utils.GetFarmhouseKitchenLevel(farmHouse); break; default: // NPC kitchens (other than the Saloon) use the Farmer's ingredients limits only cookingStationLevel = Utils.GetFarmersMaxUsableIngredients(); break; } Log.D($"Cooking station: {Game1.currentLocation.Name}: Kitchen (level {cookingStationLevel})", ModEntry.Config.DebugMode); } } } return(cookingStationLevel); }
public static void drawLayer(xTile.Layers.Layer layer, xTile.Display.IDisplayDevice displayDevice, xTile.Dimensions.Rectangle mapViewport, xTile.Dimensions.Location displayOffset, bool wrap, int pixelZoom) { pixelZoom = (int)Game1.options.zoomLevel; int tileWidth = pixelZoom * 16; int tileHeight = pixelZoom * 16; Location tileInternalOffset = new Location(mapViewport.X * tileWidth, mapViewport.Y * tileHeight); int tileXMin = (mapViewport.X >= 0) ? (mapViewport.X / tileWidth) : ((mapViewport.X - tileWidth + 1) / tileWidth); int tileYMin = (mapViewport.Y >= 0) ? (mapViewport.Y / tileHeight) : ((mapViewport.Y - tileHeight + 1) / tileHeight); if (tileXMin < 0) { displayOffset.X -= tileXMin * tileWidth; tileXMin = 0; } if (tileYMin < 0) { displayOffset.Y -= tileYMin * tileHeight; tileYMin = 0; } int tileColumns = 1 + (mapViewport.Size.Width - 1) / tileWidth; int tileRows = 1 + (mapViewport.Size.Height - 1) / tileHeight; if (tileInternalOffset.X != 0) { tileColumns++; } if (tileInternalOffset.Y != 0) { tileRows++; } int tileXMax = Math.Min(tileXMin + tileColumns, layer.LayerSize.Width); int tileYMax = Math.Min(tileYMin + tileRows, layer.LayerSize.Height); Location tileLocation = displayOffset - tileInternalOffset; int offset = layer.Id.Equals("Front") ? (16 * pixelZoom) : 0; for (int tileY = tileYMin; tileY < tileYMax; tileY++) { tileLocation.X = displayOffset.X - tileInternalOffset.X; for (int tileX = tileXMin; tileX < tileXMax; tileX++) { Tile tile = layer.Tiles[tileX, tileY]; if (tile != null) { displayDevice.DrawTile(tile, tileLocation, (float)(tileY * (16 * pixelZoom) + 16 * pixelZoom + offset) / 10000f); } tileLocation.X += tileWidth; } tileLocation.Y += tileHeight; } }
public MazeActor( Vector2 location, Texture2D texture, Rectangle initialFrame, Vector2 velocity, xTile.Layers.Layer map) : base(location, texture, initialFrame, velocity) { direction = Direction.RIGHT; target = location; this.map = map; UpdateDirection(); }
public static void LoadLevel(string levelName) { CurrentLevel = levelName; CurrentMap = MapProvider.GetMap(levelName); int editorLayerInt = CurrentMap.Properties["PlayerLayer"]; xTile.Layers.Layer editorLayer = CurrentMap.Layers[editorLayerInt]; TileMap.TileHeight = CurrentMap.Properties["TileSize"]; TileMap.TileWidth = CurrentMap.Properties["TileSize"]; TileMap.MapHeight = editorLayer.TileHeight / TileMap.TileHeight * editorLayer.LayerHeight; TileMap.MapWidth = editorLayer.TileWidth / TileMap.TileWidth * editorLayer.LayerWidth; TileMap.LoadMap(new FileStream(Application.StartupPath + @"\Content\maps\" + levelName + ".map", FileMode.Open), true); Camera.UpdateWorldRectangle(); if (OnLevelLoad != null) { OnLevelLoad(); } }
public TimeSpan GetDuration() { if (Duration != null) { return((TimeSpan)Duration); } int maxFill = 0; foreach (Location location in Locations) { GameLocation gameLocation = Game1.getLocationFromName(location.LocationName); xTile.Layers.Layer layer = gameLocation.Map.GetLayer("Back"); int area = layer.LayerHeight * layer.LayerWidth; int fillTime = Math.Max(Math.Min(area / PixelFillRate, 59), 15); if (fillTime > maxFill) { maxFill = fillTime; } } return(new TimeSpan(0, 0, seconds: maxFill)); }
public static bool PreventMapDraw(xTile.Layers.Layer __instance) { return(!removeMapLayers); }
private void OnTilePanelMouseUp(object sender, MouseEventArgs mouseEventArgs) { if (m_tileSheet == null) { return; } if (mouseEventArgs.Button != MouseButtons.Left) { return; } m_leftMouseDown = false; if (m_brushEnd == m_brushStart) { // single tile selected m_selectedTileIndex = GetTileIndex(mouseEventArgs.Location); if (m_selectedTileIndex >= 0) { if (m_orderMode == OrderMode.MRU) { m_selectedTileIndex = m_indexToMru[m_selectedTileIndex]; } UpdateMru(m_selectedTileIndex); if (m_orderMode == OrderMode.MRU) { m_focusOnTile = true; } if (TileSelected != null) { TileSelected(this, new TilePickerEventArgs(m_tileSheet, m_selectedTileIndex)); } m_tilePanel.Invalidate(); } } else { if (TileBrushSelected != null) { // tile brush selected int tileCount = m_tileSheet.TileCount; int tilesAcross = Math.Max(1, m_requiredSize.Width / (m_tileSheet.TileWidth + 1)); int tilesDown = 1 + (tileCount - 1) / tilesAcross; xTile.Layers.Layer dummyLayer = new xTile.Layers.Layer( "", m_tileSheet.Map, new xTile.Dimensions.Size(1, 1), m_tileSheet.TileSize); List <TileBrushElement> tileBrushElements = new List <TileBrushElement>(); for (int tileY = m_brushStart.Y; tileY <= m_brushEnd.Y; tileY++) { for (int tileX = m_brushStart.X; tileX <= m_brushEnd.X; tileX++) { int tileIndex = tileY * tilesAcross + tileX; if (tileIndex >= tileCount) { continue; } if (m_orderMode == OrderMode.MRU) { tileIndex = m_indexToMru[tileIndex]; } tileBrushElements.Add(new TileBrushElement( new StaticTile(dummyLayer, m_tileSheet, BlendMode.Alpha, tileIndex), new xTile.Dimensions.Location(tileX - m_brushStart.X, tileY - m_brushStart.Y))); } } TileBrush tileBrush = new TileBrush("TilePickerBrush", tileBrushElements); TileBrushSelected(this, new TilePickerEventArgs(tileBrush)); } } }
private void ParseTiles(xTile.Layers.Layer platformLayer, AggregateTileHandler func) { List <TileAggregate> aggregates = new List <TileAggregate>(); Dictionary <Point, TileAggregate> pointToAggregate = new Dictionary <Point, TileAggregate>(); var width = platformLayer.LayerWidth; var height = platformLayer.LayerHeight; var tiles = platformLayer.Tiles; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (tiles[x, y] != null) { string type = ""; string color = ""; Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (var property in tiles[x, y].TileSheet.Properties) { switch (property.Key) { case "Type": type = property.Value; break; case "Color": color = property.Value; break; default: properties[property.Key] = property.Value; break; } } TileAggregate aggregate; if (x > 0 && pointToAggregate.TryGetValue(new Point(x - 1, y), out aggregate) && aggregate.type == type && (aggregate.dir == TileDirection.HORIZONTAL || aggregate.dir == TileDirection.UNDEFINED) && aggregate.color == color) { aggregate.dir = TileDirection.HORIZONTAL; aggregate.rect.Width++; pointToAggregate[new Point(x, y)] = aggregate; } else if (y > 0 && pointToAggregate.TryGetValue(new Point(x, y - 1), out aggregate) && aggregate.type == type && (aggregate.dir == TileDirection.VERTICAL || aggregate.dir == TileDirection.UNDEFINED) && aggregate.color == color) { aggregate.dir = TileDirection.VERTICAL; aggregate.rect.Height++; pointToAggregate[new Point(x, y)] = aggregate; } else { aggregate = new TileAggregate(); aggregate.type = type; aggregate.color = color; aggregate.dir = TileDirection.UNDEFINED; aggregate.rect = new Rectangle(x, y, 1, 1); pointToAggregate[new Point(x, y)] = aggregate; aggregates.Add(aggregate); } foreach (var keyPair in properties) { aggregate.properties[keyPair.Key] = keyPair.Value; } } } } //Combine List <TileAggregate> combinedStripsToRemove = new List <TileAggregate>(); foreach (var aggregate in aggregates) { TileAggregate aboveAggregate; if (aggregate.rect.Y > 0 && pointToAggregate.TryGetValue(new Point(aggregate.rect.X, aggregate.rect.Y - 1), out aboveAggregate) && aboveAggregate.type == aggregate.type && (aboveAggregate.dir == TileDirection.HORIZONTAL || aboveAggregate.dir == TileDirection.COMBINED) && aboveAggregate.color == aggregate.color && aboveAggregate.rect.X == aggregate.rect.X && aboveAggregate.rect.Width == aggregate.rect.Width) { combinedStripsToRemove.Add(aggregate); aboveAggregate.dir = TileDirection.COMBINED; aboveAggregate.rect.Height++; pointToAggregate[new Point(aggregate.rect.X, aggregate.rect.Y)] = aboveAggregate; foreach (var keyPair in aggregate.properties) { aboveAggregate.properties[keyPair.Key] = keyPair.Value; } } } foreach (var aggregate in combinedStripsToRemove) { aggregates.Remove(aggregate); } func(aggregates, pointToAggregate); }
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); }
private void ParseMap(ref Map map, World world, ContentManager content, out Vector2 unoPos, out ExitPortal exit) { var layerCount = map.Layers.Count; Vector2 tempUnoPos = new Vector2(); ExitPortal tmpExitPortal = null; xTile.Layers.Layer platformLayer = map.Layers.First((x) => x.Id == "Platform Layer"); xTile.Layers.Layer moveablePlatformLayer = map.Layers.First((x) => x.Id == "Movable Platform Layer"); xTile.Layers.Layer zoneLayer = map.Layers.First((x) => x.Id == "Zones Layer"); xTile.Layers.Layer zone2Layer = map.Layers.FirstOrDefault((x) => x.Id == "Zones2 Layer"); xTile.Layers.Layer startLayer = map.Layers.First((x) => x.Id == "Start Position Layer"); xTile.Layers.Layer balloonLayer = map.Layers.First((x) => x.Id == "Balloon Layer"); xTile.Layers.Layer speedLayer = map.Layers.First((x) => x.Id == "Speed Modifier Layer"); xTile.Layers.Layer timeLayer = map.Layers.FirstOrDefault((x) => x.Id == "Time Modifier Layer"); xTile.Layers.Layer triggerLayer = map.Layers.First((x) => x.Id == "Trigger Groups"); xTile.Layers.Layer portalLayer = map.Layers.FirstOrDefault((x) => x.Id == "Portal Layer"); ParseTiles(platformLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var aggregate in aggregates) { if (aggregate.type == "Wall" || aggregate.type == "Magnetic Wall") { Rectangle rect = aggregate.rect; walls.Add(new Walls(aggregate.color, world, (uint)rect.Width, (uint)rect.Height, new Point(rect.X, rect.Y), true)); } } }); ParseTiles(startLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var aggregate in aggregates) { if (aggregate.type == "Uno") { float tileSize = GameManager.TILE_SIZE; Rectangle rect = aggregate.rect; tempUnoPos = new Vector2(rect.X * tileSize, rect.Y * tileSize); } } }); Dictionary <Point, TileAggregate> pointToZoneAggregate = null; ParseTiles(zoneLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { pointToZoneAggregate = pointToAggregate; }); if (zone2Layer != null) { ParseTiles(zone2Layer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var keyPair in pointToAggregate) { pointToZoneAggregate[keyPair.Key] = keyPair.Value; } }); } Dictionary <Point, TileAggregate> pointToSpeedAggregate = null; ParseTiles(speedLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { pointToSpeedAggregate = pointToAggregate; }); Dictionary <Point, TileAggregate> pointToTimeAggregate = null; if (timeLayer != null) { ParseTiles(timeLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { pointToTimeAggregate = pointToAggregate; }); } else { pointToTimeAggregate = new Dictionary <Point, TileAggregate>(); } Dictionary <string, List <IActivateable> > activators = new Dictionary <string, List <IActivateable> >(); Dictionary <Point, TileAggregate> pointToTriggerAggregate = null; ParseTiles(triggerLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { pointToTriggerAggregate = pointToAggregate; }); ParseTiles(moveablePlatformLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var aggregate in aggregates) { if (aggregate.type == "Wall" || aggregate.type == "Magnetic Wall") { Rectangle rect = aggregate.rect; Point origin = rect.Location; Point destination = origin; TileAggregate zone; if (pointToZoneAggregate.TryGetValue(origin, out zone)) { bool zoneIsWide = zone.rect.Width > zone.rect.Height; if (zone.rect.Location == origin) { if (zoneIsWide) { origin = new Point(zone.rect.Right - rect.Width, rect.Y); } else { origin = new Point(rect.X, zone.rect.Bottom - rect.Height); } } else { if (zoneIsWide) { origin = new Point(zone.rect.X, rect.Y); } else { origin = new Point(rect.X, zone.rect.Y); } } } TileAggregate speedAggregate; string speedName; float speed = WALL_SPEEDS[0]; if (pointToSpeedAggregate.TryGetValue(new Point(rect.X, rect.Y), out speedAggregate) && speedAggregate.type == "Speed Modifier" && speedAggregate.properties.TryGetValue("Speed", out speedName)) { switch (speedName) { default: case "Slow": speed = WALL_SPEEDS[0]; break; case "Med": speed = WALL_SPEEDS[1]; break; case "Fast": speed = WALL_SPEEDS[2]; break; } } TileAggregate timeAggregate; string timeName; float time = WALL_TIMES[1]; if (pointToTimeAggregate.TryGetValue(new Point(rect.X, rect.Y), out timeAggregate) && timeAggregate.type == "Time Modifier" && timeAggregate.properties.TryGetValue("Time", out timeName)) { switch (timeName) { case "Short": time = WALL_TIMES[0]; break; default: case "Med": time = WALL_TIMES[1]; break; case "Long": time = WALL_TIMES[2]; break; } } MovableWall wall = new MovableWall(aggregate.color, world, (uint)rect.Width, (uint)rect.Height, origin, time, destination, speed, content); walls.Add(wall); TileAggregate trigger; if (pointToTriggerAggregate.TryGetValue(rect.Location, out trigger)) { string triggerNumber = trigger.properties["Number"]; if (!activators.ContainsKey(triggerNumber)) { activators[triggerNumber] = new List <IActivateable>(); } activators[triggerNumber].Add(wall); } } } }); ParseTiles(balloonLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var aggregate in aggregates) { if (aggregate.type == "Balloon") { Rectangle rect = aggregate.rect; float speed = 0f; int range = 0; Balloon balloon; switch (aggregate.color) { case "g": { GreenBalloon greenBalloon = new GreenBalloon(new Point(rect.X, rect.Y), content); List <IActivateable> activatables; TileAggregate trigger; if (pointToTriggerAggregate.TryGetValue(rect.Location, out trigger) && activators.TryGetValue(trigger.properties["Number"], out activatables)) { foreach (var a in activatables) { greenBalloon.AddToActivatable(a); } } balloon = greenBalloon; } break; case "b": { BlueBalloon blueBalloon = new BlueBalloon(new Point(rect.X, rect.Y), world, content, 3f); balloon = blueBalloon; } break; case "y": { speed = 1f; TileAggregate speedAggregate; string speedName; if (pointToSpeedAggregate.TryGetValue(new Point(rect.X, rect.Y), out speedAggregate) && speedAggregate.type == "Speed Modifier" && speedAggregate.properties.TryGetValue("Speed", out speedName)) { switch (speedName) { default: case "Slow": speed = BALLOON_SPEEDS[0]; break; case "Med": speed = BALLOON_SPEEDS[1]; break; case "Fast": speed = BALLOON_SPEEDS[2]; break; } } TileAggregate zone; if (pointToZoneAggregate.TryGetValue(new Point(rect.X, rect.Y), out zone) && zone.color == "r") { //Start at left side rect.X = zone.rect.X; rect.Y = zone.rect.Y; //Go for horizontal width of zone range = zone.rect.Width; } } goto default; default: balloon = new Balloon(new Point(rect.X, rect.Y), content, aggregate.color, speed, range); break; } GameManager.getInstance().AddBalloon(balloon); } } }); if (portalLayer != null) { ParseTiles(portalLayer, delegate(List <TileAggregate> aggregates, Dictionary <Point, TileAggregate> pointToAggregate) { foreach (var aggregate in aggregates) { if (aggregate.type == "Exit") { float tileSize = GameManager.TILE_SIZE; Rectangle rect = aggregate.rect; tmpExitPortal = new ExitPortal(rect.Location); } } }); } //Remove Non Static Layers if (portalLayer != null) { map.RemoveLayer(portalLayer); } map.RemoveLayer(triggerLayer); if (timeLayer != null) { map.RemoveLayer(timeLayer); } map.RemoveLayer(speedLayer); map.RemoveLayer(balloonLayer); map.RemoveLayer(startLayer); map.RemoveLayer(moveablePlatformLayer); if (zone2Layer != null) { map.RemoveLayer(zone2Layer); } map.RemoveLayer(zoneLayer); unoPos = tempUnoPos; exit = tmpExitPortal; }
private void Setup() { // Handle patches specific to other mods var registry = this.Helper.Data.ReadJsonFile <Dictionary <string, string> >("assets/TownPatches/registry.json"); string patchVersion = "Vanilla"; foreach (var pair in registry) { if (!this.Helper.ModRegistry.IsLoaded(pair.Key)) { continue; } patchVersion = pair.Value; break; } // Setup for patching var town = Game1.getLocationFromName("Town"); var patch = this.Helper.Content.Load <xTile.Map>("assets/TownPatches/" + patchVersion + ".tbin"); var layers = town.map.Layers.Where(a => patch.GetLayer(a.Id) != null).Select(a => a.Id); // Perform patching foreach (string layer in layers) { xTile.Layers.Layer toLayer = town.map.GetLayer(layer), fromLayer = patch.GetLayer(layer); // First patch area: The road for (int x = 96; x < 120; x++) { for (int y = 53; y < 61; y++) { var tile = fromLayer.Tiles[x, y]; if (tile == null) { toLayer.Tiles[x, y] = null; } else { toLayer.Tiles[x, y] = new xTile.Tiles.StaticTile(toLayer, town.map.GetTileSheet(tile.TileSheet.Id), xTile.Tiles.BlendMode.Additive, tile.TileIndex); } var vect = new Microsoft.Xna.Framework.Vector2(x, y); town.largeTerrainFeatures.Filter(a => a.tilePosition.Value != vect); } } // Second patch area: replacing the pink tree for (int x = 110; x < 116; x++) { for (int y = 46; y < 53; y++) { var tile = fromLayer.Tiles[x, y]; if (tile == null) { toLayer.Tiles[x, y] = null; } else { toLayer.Tiles[x, y] = new xTile.Tiles.StaticTile(toLayer, town.map.GetTileSheet(tile.TileSheet.Id), xTile.Tiles.BlendMode.Additive, tile.TileIndex); } } } } // Setup warps to sundrop [TEMP: Will become warps to SundropBusStop map in the future] town.warps.Add(new Warp(120, 55, "SundropPromenade", 1, 29, false)); town.warps.Add(new Warp(120, 56, "SundropPromenade", 1, 30, false)); town.warps.Add(new Warp(120, 57, "SundropPromenade", 1, 31, false)); town.warps.Add(new Warp(120, 58, "SundropPromenade", 1, 32, false)); // Add new locations foreach (string map in this.Maps) { this.Monitor.Log("Adding sundrop location: " + Path.GetFileNameWithoutExtension(map), LogLevel.Trace); Game1.locations.Add(new SundropLocation(this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "Maps", map)), Path.GetFileNameWithoutExtension(map))); } // Add warp back to Pelican [TEMP: Will be removed once proper travel is implemented] Game1.getLocationFromName("SundropPromenade").setTileProperty(3, 37, "Buildings", "Action", "Warp 119 56 Town"); }
public void _draw(Game1 tthis, GameTime gameTime, RenderTarget2D target_screen) { Game1.showingHealthBar = false; Color bgColor = Color.Black; { if (target_screen != null) { tthis.GraphicsDevice.SetRenderTarget(target_screen); } { tthis.GraphicsDevice.Clear(bgColor); if (Game1.gameMode == (byte)11) { Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3685"), new Vector2(16f, 16f), Microsoft.Xna.Framework.Color.HotPink); Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Microsoft.Xna.Framework.Color(0, (int)byte.MaxValue, 0)); Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Microsoft.Xna.Framework.Color.White); Game1.spriteBatch.End(); } else if (Game1.gameMode == (byte)6 || Game1.gameMode == (byte)3 && Game1.currentLocation == null) { Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); string str1 = ""; for (int index = 0; (double)index < gameTime.TotalGameTime.TotalMilliseconds % 999.0 / 333.0; ++index) { str1 += "."; } string str2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3688"); string s = str2 + str1; string str3 = str2 + "... "; int widthOfString = SpriteText.getWidthOfString(str3, 999999); int height = 64; int x = 64; int y = Game1.graphics.GraphicsDevice.Viewport.GetTitleSafeArea().Bottom - height; SpriteText.drawString(Game1.spriteBatch, s, x, y, 999999, widthOfString, height, 1f, 0.88f, false, 0, str3, -1, SpriteText.ScrollTextAlignment.Left); Game1.spriteBatch.End(); if (target_screen != null) { tthis.GraphicsDevice.SetRenderTarget((RenderTarget2D)null); tthis.GraphicsDevice.Clear(bgColor); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); Game1.spriteBatch.Draw((Texture2D)target_screen, Vector2.Zero, new Microsoft.Xna.Framework.Rectangle?(target_screen.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, Game1.options.zoomLevel, SpriteEffects.None, 1f); Game1.spriteBatch.End(); } if (Game1.overlayMenu != null) { Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); Game1.overlayMenu.draw(Game1.spriteBatch); Game1.spriteBatch.End(); } } else { Microsoft.Xna.Framework.Rectangle rectangle; Viewport viewport; if (Game1.gameMode == (byte)0) { Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); } else { if (Game1.drawLighting) { tthis.GraphicsDevice.SetRenderTarget(Game1.lightmap); tthis.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White * 0.0f); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); Microsoft.Xna.Framework.Color color = !Game1.currentLocation.Name.StartsWith("UndergroundMine") || !(Game1.currentLocation is MineShaft) ? (Game1.ambientLight.Equals(Microsoft.Xna.Framework.Color.White) || Game1.isRaining && (bool)(NetFieldBase <bool, NetBool>)Game1.currentLocation.isOutdoors ? Game1.outdoorLight : Game1.ambientLight) : (Game1.currentLocation as MineShaft).getLightingColor(gameTime); Game1.spriteBatch.Draw(Game1.staminaRect, Game1.lightmap.Bounds, color); foreach (LightSource currentLightSource in Game1.currentLightSources) { if (!Game1.isRaining && !Game1.isDarkOut() || currentLightSource.lightContext.Value != LightSource.LightContext.WindowLight) { if (currentLightSource.PlayerID != 0L && currentLightSource.PlayerID != Game1.player.UniqueMultiplayerID) { Farmer farmerMaybeOffline = Game1.getFarmerMaybeOffline(currentLightSource.PlayerID); if (farmerMaybeOffline == null || farmerMaybeOffline.currentLocation != null && farmerMaybeOffline.currentLocation.Name != Game1.currentLocation.Name || (bool)(NetFieldBase <bool, NetBool>)farmerMaybeOffline.hidden) { continue; } } if (Utility.isOnScreen((Vector2)(NetFieldBase <Vector2, NetVector2>)currentLightSource.position, (int)((double)(float)(NetFieldBase <float, NetFloat>)currentLightSource.radius * 64.0 * 4.0))) { Game1.spriteBatch.Draw(currentLightSource.lightTexture, Game1.GlobalToLocal(Game1.viewport, (Vector2)(NetFieldBase <Vector2, NetVector2>)currentLightSource.position) / (float)(Game1.options.lightingQuality / 2), new Microsoft.Xna.Framework.Rectangle?(currentLightSource.lightTexture.Bounds), (Microsoft.Xna.Framework.Color)(NetFieldBase <Microsoft.Xna.Framework.Color, NetColor>) currentLightSource.color, 0.0f, new Vector2((float)currentLightSource.lightTexture.Bounds.Center.X, (float)currentLightSource.lightTexture.Bounds.Center.Y), (float)(NetFieldBase <float, NetFloat>)currentLightSource.radius / (float)(Game1.options.lightingQuality / 2), SpriteEffects.None, 0.9f); } } } Game1.spriteBatch.End(); tthis.GraphicsDevice.SetRenderTarget(target_screen); } //if (Game1.bloomDay && Game1.bloom != null) // Game1.bloom.BeginDraw(); tthis.GraphicsDevice.Clear(bgColor); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (Game1.background != null) { Game1.background.draw(Game1.spriteBatch); } Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); Game1.currentLocation.Map.GetLayer("Back").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4); Game1.currentLocation.drawWater(Game1.spriteBatch); if (!Game1.currentLocation.shouldHideCharacters()) { if (Game1.CurrentEvent == null) { foreach (NPC character in Game1.currentLocation.characters) { if (!(bool)(NetFieldBase <bool, NetBool>)character.swimming && !character.HideShadow && (!character.IsInvisible && !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(character.getTileLocation()))) { Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, character.Position + new Vector2((float)(character.Sprite.SpriteWidth * 4) / 2f, (float)(character.GetBoundingBox().Height + (character.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)character.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)character.scale, SpriteEffects.None, Math.Max(0.0f, (float)character.getStandingY() / 10000f) - 1E-06f); } } } else { foreach (NPC actor in Game1.CurrentEvent.actors) { if (!(bool)(NetFieldBase <bool, NetBool>)actor.swimming && !actor.HideShadow && !Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(actor.getTileLocation())) { Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : (actor.Sprite.SpriteHeight <= 16 ? -4 : 12))))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)actor.scale, SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f); } } } } xTile.Layers.Layer layer1 = Game1.currentLocation.Map.GetLayer("Buildings"); layer1.Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4); Game1.mapDisplayDevice.EndScene(); Game1.spriteBatch.End(); Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (!Game1.currentLocation.shouldHideCharacters()) { if (Game1.CurrentEvent == null) { foreach (NPC character in Game1.currentLocation.characters) { if (!(bool)(NetFieldBase <bool, NetBool>)character.swimming && !character.HideShadow && (!(bool)(NetFieldBase <bool, NetBool>)character.isInvisible && Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(character.getTileLocation()))) { Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, character.Position + new Vector2((float)(character.Sprite.SpriteWidth * 4) / 2f, (float)(character.GetBoundingBox().Height + (character.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)character.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)character.scale, SpriteEffects.None, Math.Max(0.0f, (float)character.getStandingY() / 10000f) - 1E-06f); } } } else { foreach (NPC actor in Game1.CurrentEvent.actors) { if (!(bool)(NetFieldBase <bool, NetBool>)actor.swimming && !actor.HideShadow && Game1.currentLocation.shouldShadowBeDrawnAboveBuildingsLayer(actor.getTileLocation())) { Game1.spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, actor.Position + new Vector2((float)(actor.Sprite.SpriteWidth * 4) / 2f, (float)(actor.GetBoundingBox().Height + (actor.IsMonster ? 0 : 12)))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), (float)(4.0 + (double)actor.yJumpOffset / 40.0) * (float)(NetFieldBase <float, NetFloat>)actor.scale, SpriteEffects.None, Math.Max(0.0f, (float)actor.getStandingY() / 10000f) - 1E-06f); } } } } if ((Game1.eventUp || Game1.killScreen) && (!Game1.killScreen && Game1.currentLocation.currentEvent != null)) { Game1.currentLocation.currentEvent.draw(Game1.spriteBatch); } if (Game1.player.currentUpgrade != null && Game1.player.currentUpgrade.daysLeftTillUpgradeDone <= 3 && Game1.currentLocation.Name.Equals("Farm")) { Game1.spriteBatch.Draw(Game1.player.currentUpgrade.workerTexture, Game1.GlobalToLocal(Game1.viewport, Game1.player.currentUpgrade.positionOfCarpenter), new Microsoft.Xna.Framework.Rectangle?(Game1.player.currentUpgrade.getSourceRectangle()), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, (float)(((double)Game1.player.currentUpgrade.positionOfCarpenter.Y + 48.0) / 10000.0)); } Game1.currentLocation.draw(Game1.spriteBatch); foreach (Vector2 key in Game1.crabPotOverlayTiles.Keys) { xTile.Tiles.Tile tile = layer1.Tiles[(int)key.X, (int)key.Y]; if (tile != null) { Vector2 local = Game1.GlobalToLocal(Game1.viewport, key * 64f); xTile.Dimensions.Location location = new xTile.Dimensions.Location((int)local.X, (int)local.Y); Game1.mapDisplayDevice.DrawTile(tile, location, (float)(((double)key.Y * 64.0 - 1.0) / 10000.0)); } } if (Game1.eventUp && Game1.currentLocation.currentEvent != null) { string messageToScreen = Game1.currentLocation.currentEvent.messageToScreen; } if (Game1.currentLocation.Name.Equals("Farm")) { if (Game1.player.CoopUpgradeLevel > 0) { Game1.spriteBatch.Draw(Game1.currentCoopTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(1280f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentCoopTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f)); } switch (Game1.player.BarnUpgradeLevel) { case 1: Game1.spriteBatch.Draw(Game1.currentBarnTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(768f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentBarnTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f)); break; case 2: Game1.spriteBatch.Draw(Game1.currentBarnTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(640f, 256f)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentBarnTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f)); break; } if (Game1.player.hasGreenhouse) { Game1.spriteBatch.Draw(Game1.greenhouseTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(64f, 320f)), new Microsoft.Xna.Framework.Rectangle?(Game1.greenhouseTexture.Bounds), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, Math.Max(0.0f, 0.0576f)); } } Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); Game1.currentLocation.Map.GetLayer("Front").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4); Game1.mapDisplayDevice.EndScene(); Game1.currentLocation.drawAboveFrontLayer(Game1.spriteBatch); Game1.spriteBatch.End(); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (Game1.displayFarmer && Game1.player.ActiveObject != null && ((bool)(NetFieldBase <bool, NetBool>)Game1.player.ActiveObject.bigCraftable && tthis.checkBigCraftableBoundariesForFrontLayer()) && Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), Game1.player.getStandingY()), Game1.viewport.Size) == null) { Game1.drawPlayerHeldObject(Game1.player); } else if (Game1.displayFarmer && Game1.player.ActiveObject != null) { if (Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location((int)Game1.player.Position.X, (int)Game1.player.Position.Y - 38), Game1.viewport.Size) == null || Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location((int)Game1.player.Position.X, (int)Game1.player.Position.Y - 38), Game1.viewport.Size).TileIndexProperties.ContainsKey("FrontAlways")) { xTile.Layers.Layer layer2 = Game1.currentLocation.Map.GetLayer("Front"); rectangle = Game1.player.GetBoundingBox(); xTile.Dimensions.Location mapDisplayLocation1 = new xTile.Dimensions.Location(rectangle.Right, (int)Game1.player.Position.Y - 38); xTile.Dimensions.Size size1 = Game1.viewport.Size; if (layer2.PickTile(mapDisplayLocation1, size1) != null) { xTile.Layers.Layer layer3 = Game1.currentLocation.Map.GetLayer("Front"); rectangle = Game1.player.GetBoundingBox(); xTile.Dimensions.Location mapDisplayLocation2 = new xTile.Dimensions.Location(rectangle.Right, (int)Game1.player.Position.Y - 38); xTile.Dimensions.Size size2 = Game1.viewport.Size; if (layer3.PickTile(mapDisplayLocation2, size2).TileIndexProperties.ContainsKey("FrontAlways")) { goto label_139; } } else { goto label_139; } } Game1.drawPlayerHeldObject(Game1.player); } label_139: if ((Game1.player.UsingTool || Game1.pickingTool) && Game1.player.CurrentTool != null && ((!Game1.player.CurrentTool.Name.Equals("Seeds") || Game1.pickingTool) && (Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), (int)Game1.player.Position.Y - 38), Game1.viewport.Size) != null && Game1.currentLocation.Map.GetLayer("Front").PickTile(new xTile.Dimensions.Location(Game1.player.getStandingX(), Game1.player.getStandingY()), Game1.viewport.Size) == null))) { Game1.drawTool(Game1.player); } if (Game1.currentLocation.Map.GetLayer("AlwaysFront") != null) { Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); Game1.currentLocation.Map.GetLayer("AlwaysFront").Draw(Game1.mapDisplayDevice, Game1.viewport, xTile.Dimensions.Location.Origin, false, 4); Game1.mapDisplayDevice.EndScene(); } if ((double)Game1.toolHold > 400.0 && Game1.player.CurrentTool.UpgradeLevel >= 1 && Game1.player.canReleaseTool) { Microsoft.Xna.Framework.Color color = Microsoft.Xna.Framework.Color.White; switch ((int)((double)Game1.toolHold / 600.0) + 2) { case 1: color = Tool.copperColor; break; case 2: color = Tool.steelColor; break; case 3: color = Tool.goldColor; break; case 4: color = Tool.iridiumColor; break; } Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X - 2, (int)Game1.player.getLocalPosition(Game1.viewport).Y - (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : 64) - 2, (int)((double)Game1.toolHold % 600.0 * 0.0799999982118607) + 4, 12), Microsoft.Xna.Framework.Color.Black); Game1.spriteBatch.Draw(Game1.littleEffect, new Microsoft.Xna.Framework.Rectangle((int)Game1.player.getLocalPosition(Game1.viewport).X, (int)Game1.player.getLocalPosition(Game1.viewport).Y - (Game1.player.CurrentTool.Name.Equals("Watering Can") ? 0 : 64), (int)((double)Game1.toolHold % 600.0 * 0.0799999982118607), 8), color); } if ((double)Game1.currentLocation.LightLevel > 0.0 && Game1.timeOfDay < 2000) { Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Microsoft.Xna.Framework.Color.Black * Game1.currentLocation.LightLevel); } if (Game1.screenGlow) { Game1.spriteBatch.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Game1.screenGlowColor * Game1.screenGlowAlpha); } Game1.currentLocation.drawAboveAlwaysFrontLayer(Game1.spriteBatch); Game1.spriteBatch.End(); Game1.spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (Game1.eventUp && Game1.currentLocation.currentEvent != null) { foreach (NPC actor in Game1.currentLocation.currentEvent.actors) { if (actor.isEmoting) { Vector2 localPosition = actor.getLocalPosition(Game1.viewport); localPosition.Y -= 140f; if (actor.Age == 2) { localPosition.Y += 32f; } else if (actor.Gender == 1) { localPosition.Y += 10f; } Game1.spriteBatch.Draw(Game1.emoteSpriteSheet, localPosition, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(actor.CurrentEmoteIndex * 16 % Game1.emoteSpriteSheet.Width, actor.CurrentEmoteIndex * 16 / Game1.emoteSpriteSheet.Width * 16, 16, 16)), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)actor.getStandingY() / 10000f); } } } Game1.spriteBatch.End(); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (Game1.drawGrid) { int num1 = -Game1.viewport.X % 64; float num2 = (float)(-Game1.viewport.Y % 64); int num3 = num1; while (true) { int num4 = num3; viewport = Game1.graphics.GraphicsDevice.Viewport; int width = viewport.Width; if (num4 < width) { SpriteBatch spriteBatch = Game1.spriteBatch; Texture2D staminaRect = Game1.staminaRect; int x = num3; int y = (int)num2; viewport = Game1.graphics.GraphicsDevice.Viewport; int height = viewport.Height; Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, 1, height); Microsoft.Xna.Framework.Color color = Microsoft.Xna.Framework.Color.Red * 0.5f; spriteBatch.Draw(staminaRect, destinationRectangle, color); num3 += 64; } else { break; } } float num5 = num2; while (true) { double num4 = (double)num5; viewport = Game1.graphics.GraphicsDevice.Viewport; double height = (double)viewport.Height; if (num4 < height) { SpriteBatch spriteBatch = Game1.spriteBatch; Texture2D staminaRect = Game1.staminaRect; int x = num1; int y = (int)num5; viewport = Game1.graphics.GraphicsDevice.Viewport; int width = viewport.Width; Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, width, 1); Microsoft.Xna.Framework.Color color = Microsoft.Xna.Framework.Color.Red * 0.5f; spriteBatch.Draw(staminaRect, destinationRectangle, color); num5 += 64f; } else { break; } } } } Game1.spriteBatch.End(); tthis.CallAction("renderScreenBuffer", target_screen); } } } }
private void OnTilePanelMouseUp(object sender, MouseEventArgs mouseEventArgs) { if (m_tileSheet == null) return; if (mouseEventArgs.Button != MouseButtons.Left) return; m_leftMouseDown = false; if (m_brushEnd == m_brushStart) { // single tile selected m_selectedTileIndex = GetTileIndex(mouseEventArgs.Location); if (m_selectedTileIndex >= 0) { if (m_orderMode == OrderMode.MRU) m_selectedTileIndex = m_indexToMru[m_selectedTileIndex]; UpdateMru(m_selectedTileIndex); if (m_orderMode == OrderMode.MRU) m_focusOnTile = true; if (TileSelected != null) TileSelected(this, new TilePickerEventArgs(m_tileSheet, m_selectedTileIndex)); m_tilePanel.Invalidate(); } } else { if (TileBrushSelected != null) { // tile brush selected int tileCount = m_tileSheet.TileCount; int tilesAcross = Math.Max(1, m_requiredSize.Width / (m_tileSheet.TileWidth + 1)); int tilesDown = 1 + (tileCount - 1) / tilesAcross; xTile.Layers.Layer dummyLayer = new xTile.Layers.Layer( "", m_tileSheet.Map, new xTile.Dimensions.Size(1, 1), m_tileSheet.TileSize); List<TileBrushElement> tileBrushElements = new List<TileBrushElement>(); for (int tileY = m_brushStart.Y; tileY <= m_brushEnd.Y; tileY++) { for (int tileX = m_brushStart.X; tileX <= m_brushEnd.X; tileX++) { int tileIndex = tileY * tilesAcross + tileX; if (tileIndex >= tileCount) continue; if (m_orderMode == OrderMode.MRU) tileIndex = m_indexToMru[tileIndex]; tileBrushElements.Add(new TileBrushElement( new StaticTile(dummyLayer, m_tileSheet, BlendMode.Alpha, tileIndex), new xTile.Dimensions.Location(tileX - m_brushStart.X, tileY - m_brushStart.Y))); } } TileBrush tileBrush = new TileBrush("TilePickerBrush", tileBrushElements); TileBrushSelected(this, new TilePickerEventArgs(tileBrush)); } } }
private void commitTerrain() { // Remove old layers var layersToRemove = new List <xTile.Layers.Layer>(); foreach (var check in Game1.currentLocation.Map.Layers) { if (check.Id.Contains("Terraform")) { layersToRemove.Add(check); } } foreach (var remove in layersToRemove) { Game1.currentLocation.Map.RemoveLayer(remove); } // Remove old tilesheets var sheetsToRemove = new List <xTile.Tiles.TileSheet>(); foreach (var check in Game1.currentLocation.Map.TileSheets) { if (check.Id.Contains("Terraform")) { sheetsToRemove.Add(check); } } foreach (var remove in sheetsToRemove) { Game1.currentLocation.Map.RemoveTileSheet(remove); } // Collect tile types var types = new List <TileType>(); types.Add(TileType.DarkDirt); types.Add(TileType.LightGrass); types.Add(TileType.MediumGrass); types.Add(TileType.DarkGrass); // Add tile sheets var typesTs = new Dictionary <TileType, xTile.Tiles.TileSheet>(); char tsCounter = '0'; foreach (var type in types) { var ts = new xTile.Tiles.TileSheet(Game1.currentLocation.Map, Mod.instance.Helper.Content.GetActualAssetKey($"assets/vanilla/{type}.png"), new xTile.Dimensions.Size(4, 4), new xTile.Dimensions.Size(16, 16)); ts.Id = "\u03a9" + ts.Id + "Terraform" + (tsCounter++) + type.ToString(); Game1.currentLocation.Map.AddTileSheet(ts); typesTs.Add(type, ts); } Game1.currentLocation.Map.LoadTileSheets(Game1.mapDisplayDevice); int[] tileIndexLookup = new[] { 12, 8, 13, 1, 0, 14, 3, 5, 15, 9, 4, 10, 11, 7, 2, 6 }; // Add our tiles, by layer foreach (var type in types) { var layer = new xTile.Layers.Layer("BackTerraform_" + type, Game1.currentLocation.Map, Game1.currentLocation.Map.Layers[0].LayerSize, new xTile.Dimensions.Size(Game1.tileSize, Game1.tileSize)); var ts = typesTs[type]; for (int ix = 0; ix < terrainWidth; ++ix) { for (int iy = 0; iy < terrainHeight; ++iy) { Func <int, int, bool> getTile = (x, y) => { if (x < 0 || y < 0 || x > terrainWidth || y > terrainHeight) { return(false); } return(terrainData[x, y] == type); }; int cornerFlags = 0; if (getTile(ix + 1, iy + 0)) { cornerFlags |= 1; } if (getTile(ix + 1, iy + 1)) { cornerFlags |= 2; } if (getTile(ix + 0, iy + 1)) { cornerFlags |= 4; } if (getTile(ix + 0, iy + 0)) { cornerFlags |= 8; } if (cornerFlags == 0) { continue; } layer.Tiles[ix, iy] = new xTile.Tiles.StaticTile(layer, ts, xTile.Tiles.BlendMode.Alpha, tileIndexLookup[cornerFlags]); } } Game1.currentLocation.Map.AddLayer(layer); } // Water tile effects if (Game1.currentLocation.waterTiles == null) { Game1.currentLocation.waterTiles = new bool[terrainWidth, terrainHeight]; } for (int i = 0; i < Game1.currentLocation.waterTiles.Length; ++i) { int ix = i % terrainWidth, iy = i / terrainWidth; var tile = terrainData[ix, iy]; Game1.currentLocation.waterTiles[ix, iy] = (tile == TileType.Water || tile == TileType.DeepWater); } }