public StaticTileSprite(TileSheet tile_sheet, int OpenGL_texture_id, Rectangle rect) { _tile_sheet = tile_sheet; _texture = OpenGL_texture_id; _rect = rect; this.ID = ObjectRegistrar.Sprites.register_obj_as(this, typeof(ITileSprite) ); }
////////////////////////////////////////////////////////////////////// // Constructor methods: public TileSprite(TileSheet tile_sheet, int obj_ID, params int[] frame_index_args) { // This form of the constructor is more convenient to call when // the frames are specified via a single index. // When specified by [x,y] within the TileSheet, the other form is needful. // // TODO: Some means to specify an arg list of (tile_sheet, [x1,y1], [x2,y2], ...) // If possible, it would be a nicety... if (tile_sheet == null) { throw new ArgumentException("Got null tile_sheet"); } if (frame_index_args == null || frame_index_args.Length == 0) { throw new ArgumentException("Got null or empty frame_indexes array"); } this.sheet = tile_sheet; this.frame_indexes = new int[frame_index_args.Length]; // Causes this.num_frames to be initialized this.bitmap = new Bitmap[this.num_frames]; this.rect = new Rectangle[this.num_frames]; this.texture = new int[this.num_frames]; for (int ii = 0; ii < this.num_frames; ii++) { int index_on_sheet = frame_index_args[ii]; int which_sheet = GridUtility3D.ZforIWH(index_on_sheet, tile_sheet.width_tiles, tile_sheet.height_tiles); this.frame_indexes[ii] = index_on_sheet; this.bitmap[ii] = this.sheet.bitmaps[which_sheet]; this.rect[ii] = this.sheet.rect_for_tile(index_on_sheet); this.texture[ii] = Load_OpenGL_texture_for_tile(this.bitmap[ii], this.rect[ii]); } this.ID = ObjectRegistrar.Sprites.register_object_as(this, typeof(ITileSprite), obj_ID); }
void Awake() { if (tileHandler != null) { GameObject.Destroy(tileHandler); } else { tileHandler = this; } TileSheetData = new TileSheet(tileSheet, resolution); tiles = new Tile[TileSheet.totalTiles]; tilePixels = new Color[TileSheet.totalTiles][]; for (int i = 0; i < tiles.Length; ++i) { tiles[i] = new Tile(i, tileCollisionType[i]); tilePixels[i] = TileSheetData[i]; } EmptyTile = tiles.Length - 1; }
void Awake() { m_noise = new Noise (2); m_tileSheet = new TileSheet (m_width, m_height); m_tileRules = new TileChoise[8]; m_tileRules [0] = new TileChoise (TileShape.DownRight, TileCriteria.No, TileCriteria.Yes, TileCriteria.No, TileCriteria.Yes); m_tileRules [1] = new TileChoise (TileShape.DownLeft, TileCriteria.No, TileCriteria.Yes, TileCriteria.Yes, TileCriteria.No); m_tileRules [2] = new TileChoise (TileShape.UpRight, TileCriteria.Yes, TileCriteria.No, TileCriteria.No, TileCriteria.Yes); m_tileRules [3] = new TileChoise (TileShape.UpLeft, TileCriteria.Yes, TileCriteria.No, TileCriteria.Yes, TileCriteria.No); m_tileRules [4] = new TileChoise (TileShape.Down, TileCriteria.Yes, TileCriteria.No, TileCriteria.DontCare, TileCriteria.DontCare); m_tileRules [5] = new TileChoise (TileShape.Up, TileCriteria.No, TileCriteria.DontCare, TileCriteria.DontCare, TileCriteria.DontCare); m_tileRules [6] = new TileChoise (TileShape.Left, TileCriteria.DontCare, TileCriteria.DontCare, TileCriteria.No, TileCriteria.Yes); m_tileRules [7] = new TileChoise (TileShape.Right, TileCriteria.DontCare, TileCriteria.DontCare, TileCriteria.Yes, TileCriteria.No); int textureSize = 2048; m_texture = new Texture2D (textureSize, textureSize); for (int x = 0; x < textureSize; x++) for (int y = 0; y < textureSize; y++) m_texture.SetPixel (x, y, new Color (1, 1, 1, 0)); //(float)x/(float)textureSize, (float)y/(float)textureSize, (float)(x-y)/(float)textureSize)); m_texture.Apply (); SpriteRenderer renderer = GetComponent<SpriteRenderer>(); Sprite sprite = new Sprite (); sprite = Sprite.Create (m_texture,new Rect(0, 0, textureSize, textureSize), new Vector2 (0,0), 1f); renderer.sprite = sprite; renderer.sortingLayerName = "Level base"; m_platformManager = new PlatformManager (); GenerateLevel (); }
public AnimTileSprite(TileSheet tile_sheet, params StaticTileSprite[] anim_frames) { if (anim_frames == null || anim_frames.Length == 0) { throw new ArgumentException("Got null or empty anim_frames array"); } _tile_sheet = tile_sheet; frame_sequence = anim_frames; num_frames = frame_sequence.Length; this.ID = ObjectRegistrar.Sprites.register_obj_as(this, typeof(ITileSprite) ); }
public static void CreatePuzzle(Vector2 spot, MineShaft shaft) { monitor.Log($"adding an offering puzzle"); int idx = 0; if (shaft.mineLevel > 40 && shaft.mineLevel < 80) { idx = Game1.random.Next(0, 2); } else if (shaft.mineLevel > 80 && shaft.mineLevel < 120) { idx = Game1.random.Next(0, 3); } else if (shaft.mineLevel > 120) { idx = Game1.random.Next(0, 4); } Layer buildings = shaft.map.GetLayer("Buildings"); Layer front = shaft.map.GetLayer("Front"); if (shaft.map.TileSheets.FirstOrDefault(s => s.Id == ModEntry.tileSheetId) == null) { shaft.map.AddTileSheet(new TileSheet(ModEntry.tileSheetId, shaft.map, ModEntry.tileSheetPath, new Size(16, 18), new Size(16, 16))); } TileSheet tilesheet = shaft.map.GetTileSheet(ModEntry.tileSheetId); bool which = Game1.random.NextDouble() < 0.5f; int full = which ? 1 : -1; // full front.Tiles[(int)spot.X + full, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 245); front.Tiles[(int)spot.X + full, (int)spot.Y] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 260); buildings.Tiles[(int)spot.X + full, (int)spot.Y + 1] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: offerIdx + 1 + idx); // empty front.Tiles[(int)spot.X - full, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 244); front.Tiles[(int)spot.X - full, (int)spot.Y] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 260); buildings.Tiles[(int)spot.X - full, (int)spot.Y + 1] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: offerIdx); shaft.setTileProperty((int)spot.X - full, (int)spot.Y + 1, "Buildings", "Action", $"offerPuzzle_{idx}_{spot.X}_{spot.Y}"); shaft.setTileProperty((int)spot.X + full, (int)spot.Y + 1, "Buildings", "Action", $"offerPuzzleSteal_{spot.X}_{spot.Y}"); }
PropertyValue ILocationHelper.GetTilesheetProperty(LocationReference location, string sheet, string key) { GameLocation loc = location; TileSheet s = loc.map.GetTileSheet(sheet); if (s == null) { return(null); } if (s.Properties.ContainsKey(key)) { return(s.Properties[key]); } return(null); }
private void OnTileDragDrop(object sender, DragEventArgs dragEventArgs) { if (m_draggedTileSheet.TileSize != m_layer.TileSize) { m_tileSizeMessageBox.Show(); return; } AddTileFrame(m_draggedTileSheet, m_draggedTileIndex); m_draggedTileSheet = null; m_draggedTileIndex = -1; Cursor = Cursors.Default; MarkAsModified(); }
/// <summary> /// Tests if the layer contains at least one tile that references /// the given tile sheet /// </summary> /// <param name="tileSheet">Tile sheet to test</param> /// <returns>True if the layer depends on the given tile sheet, false otherwise</returns> public bool DependsOnTileSheet(TileSheet tileSheet) { for (int y = 0; y < m_layerSize.Height; y++) { for (int x = 0; x < m_layerSize.Width; x++) { Tile tile = m_tiles[x, y]; if (tile != null && tile.DependsOnTileSheet(tileSheet)) { return(true); } } } return(false); }
/// <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); var tileSheetTexture = Content.Load <Texture2D>("tilesheet"); var tileSheet = new TileSheet(tileSheetTexture); levelRenderer = new LevelRenderer(graphics, tileSheet); using (var importer = new LevelImporter("Content/levels.txt")) { levelCollection = importer.LoadLevels(); } sceneStateManager = new SceneStateManager(levelCollection, levelRenderer); }
public void Refresh(TileSheet tileSheet) { //try //{ System.Drawing.Bitmap tileSheetBitmap = null; // copy bitmap in memory, otherwise Clone() method forces // a reload of the image on every call! using (var tileSheetBitmapDisk = new System.Drawing.Bitmap(tileSheet.ImageSource)) { tileSheetBitmap = new System.Drawing.Bitmap(tileSheetBitmapDisk); } int tileCount = tileSheet.TileCount; System.Drawing.Bitmap[] tileBitmaps = new System.Drawing.Bitmap[tileCount]; Size tileSize = tileSheet.TileSize; System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(0, 0, tileSize.Width, tileSize.Height); System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(destRect.Location, destRect.Size); for (int tileIndex = 0; tileIndex < tileCount; tileIndex++) { Rectangle tileRectangle = tileSheet.GetTileImageBounds(tileIndex); srcRect.X = tileRectangle.Location.X; srcRect.Y = tileRectangle.Location.Y; srcRect.Width = tileRectangle.Size.Width; srcRect.Height = tileRectangle.Size.Height; System.Drawing.Bitmap tileBitmap = tileSheetBitmap.Clone( srcRect, tileSheetBitmap.PixelFormat); tileBitmaps[tileIndex] = tileBitmap; } m_bitmapCache[tileSheet] = tileBitmaps; //} //catch (Exception innerException) //{ // Exception exception = new Exception( // "Unable to load tile sheet '" + tileSheet.Id + "' with image source '" + tileSheet.ImageSource + "'", // innerException); // throw exception; //} }
/// <summary>Find a map tilesheet by ID.</summary> /// <param name="map">The map whose tilesheets to search.</param> /// <param name="id">The tilesheet ID to match.</param> /// <param name="index">The matched tilesheet index, if any.</param> /// <param name="tilesheet">The matched tilesheet, if any.</param> private bool TryFindTilesheet(Map map, string id, out int index, out TileSheet tilesheet) { for (int i = 0; i < map.TileSheets.Count; i++) { if (map.TileSheets[i].Id == id) { index = i; tilesheet = map.TileSheets[i]; return(true); } } index = -1; tilesheet = null; return(false); }
private void setCustomTiles() { foreach (TileSheet t in CommunityCenter.map.TileSheets) { Monitor.Log($"{t.Id}-{t.Description}", LogLevel.Debug); } CommunityCenter.map.LoadTileSheets(Game1.mapDisplayDevice); TileSheet sheet = CommunityCenter.map.GetTileSheet("indoors"); int DonationsX = (int)CCDonation1.X; int DonationsY = (int)CCDonation1.Y; Layer DonationsLayer = CommunityCenter.map.GetLayer("Front"); //DonationsLayer.Tiles[DonationsX, DonationsY] = new StaticTile(DonationsLayer, sheet, BlendMode.Alpha, 1); DonationsLayer.Tiles[DonationsX, DonationsY] = new StaticTile(DonationsLayer, sheet, BlendMode.Alpha, 1206); }
private static AnimatedTile CreateAnimatedTile(GameLocation location, TileSheet sheet, int first) { return(new AnimatedTile(location.map.GetLayer("Buildings"), new StaticTile[] { new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 1), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 2), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 3), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 3), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 4), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 5), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first + 6), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first), new StaticTile(location.map.GetLayer("Buildings"), sheet, BlendMode.Alpha, first), }, 250)); }
public static void CreatePuzzle(Vector2 spot, MineShaft shaft) { Layer front = shaft.map.GetLayer("Front"); Layer buildings = shaft.map.GetLayer("Buildings"); if (shaft.map.TileSheets.FirstOrDefault(s => s.Id == ModEntry.tileSheetId) == null) { shaft.map.AddTileSheet(new TileSheet(ModEntry.tileSheetId, shaft.map, ModEntry.tileSheetPath, new Size(16, 18), new Size(16, 16))); } TileSheet tilesheet = shaft.map.GetTileSheet(ModEntry.tileSheetId); front.Tiles[(int)spot.X, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: litEyes); buildings.Tiles[(int)spot.X, (int)spot.Y] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: litEyes + 32); shaft.setTileProperty((int)spot.X, (int)spot.Y, "Buildings", "Action", $"undergroundRiddles"); }
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 static TileSheet loadTilesheet(ref Map map, string name, bool isFloor) { string ts = "zCWF" + (isFloor ? ".Floors." : ".Walls.") + name; TileSheet tilesheet = map.GetTileSheet(ts); if (tilesheet == null) { string path = isFloor ? Path.Combine(name, "floors") : Path.Combine(name, "walls"); Texture2D texture = isFloor ? Floors[name] : Walls[name]; tilesheet = new TileSheet(ts, map, path, new xTile.Dimensions.Size(texture.Width / 16, texture.Height / 16), new xTile.Dimensions.Size(16, 16)); map.AddTileSheet(tilesheet); map.LoadTileSheets(Game1.mapDisplayDevice); } return(tilesheet); }
private void LoadTileSheet(Stream stream, Map map) { string id = LoadString(stream); string description = LoadString(stream); string imageSource = LoadString(stream); Size sheetSize = LoadSize(stream); Size tileSize = LoadSize(stream); Size margin = LoadSize(stream); Size spacing = LoadSize(stream); TileSheet tileSheet = new TileSheet(id, map, imageSource, sheetSize, tileSize); tileSheet.Margin = margin; tileSheet.Spacing = spacing; LoadProperties(stream, tileSheet); map.AddTileSheet(tileSheet); }
public void setAnimatedTile(int tileX, int tileY, Layer mapLayer, TileSheet mapSheet) { mapLayer.Tiles[tileX, tileY] = new AnimatedTile(mapLayer, new StaticTile[] { new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 0), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 1), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 2), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 3), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 4), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 3), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 2), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 1), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 0), new StaticTile(mapLayer, mapSheet, BlendMode.Alpha, 5) }, 250); }
internal static void Start(MineShaft shaft, ref List <Vector2> superClearCenters, ref List <Vector2> clearCenters, ref List <Vector2> clearSpots) { if (Game1.random.NextDouble() >= config.AltarBaseChance * Math.Pow(shaft.mineLevel, config.PuzzleChanceIncreaseRate) || superClearCenters.Count == 0) { return; } monitor.Log($"adding an altar"); Vector2 spot = superClearCenters[Game1.random.Next(0, superClearCenters.Count)]; Layer front = shaft.map.GetLayer("Front"); Layer buildings = shaft.map.GetLayer("Buildings"); if (shaft.map.TileSheets.FirstOrDefault(s => s.Id == ModEntry.tileSheetId) == null) { shaft.map.AddTileSheet(new TileSheet(ModEntry.tileSheetId, shaft.map, ModEntry.tileSheetPath, new Size(16, 18), new Size(16, 16))); } TileSheet tilesheet = shaft.map.GetTileSheet(ModEntry.tileSheetId); int type = Game1.random.Next(0, 3); front.Tiles[(int)spot.X - 1, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 128 + type * 3); front.Tiles[(int)spot.X, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 129 + type * 3); front.Tiles[(int)spot.X + 1, (int)spot.Y - 1] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 130 + type * 3); front.Tiles[(int)spot.X - 1, (int)spot.Y] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 144 + type * 3); front.Tiles[(int)spot.X, (int)spot.Y] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 145 + type * 3); front.Tiles[(int)spot.X + 1, (int)spot.Y] = new StaticTile(front, tilesheet, BlendMode.Alpha, tileIndex: 146 + type * 3); buildings.Tiles[(int)spot.X - 1, (int)spot.Y + 1] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: 160 + type * 3); buildings.Tiles[(int)spot.X, (int)spot.Y + 1] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: 161 + type * 3); buildings.Tiles[(int)spot.X + 1, (int)spot.Y + 1] = new StaticTile(buildings, tilesheet, BlendMode.Alpha, tileIndex: 162 + type * 3); shaft.setTileProperty((int)spot.X, (int)spot.Y + 1, "Buildings", "Action", $"undergroundAltar_{type}_{spot.X}_{spot.Y + 1}"); foreach (Vector2 v in Utils.GetSurroundingTiles(spot, 4)) { superClearCenters.Remove(v); if (Math.Abs(v.X - spot.X) < 3 && Math.Abs(v.Y - spot.Y) < 3) { clearCenters.Remove(v); if (Math.Abs(v.X - spot.X) < 2 && Math.Abs(v.Y - spot.Y) < 2) { clearSpots.Remove(v); } } } }
public void LoadAllAssets(IModHelper modHelper) { GameLocation town = Game1.getLocationFromName("Town"); string candidateBoxPath = modHelper.Content.GetActualAssetKey("assets/Candidate_Box.png", ContentSource.ModFolder); candidateBoxTile = new TileSheet( id: "z-candidate-box", // a unique ID for the tilesheet map: town.map, imageSource: candidateBoxPath, sheetSize: new Size(16, 16), // the tile size of your tilesheet image. tileSize: new Size(16, 16) ); electionIcon = modHelper.Content.Load <Texture2D>("assets/Election_Icon.png", ContentSource.ModFolder); }
/// <summary>Validate that an asset loaded by a mod is valid and won't cause issues.</summary> /// <typeparam name="T">The asset type.</typeparam> /// <param name="info">The basic asset metadata.</param> /// <param name="data">The loaded asset data.</param> /// <param name="mod">The mod which loaded the asset.</param> private bool TryValidateLoadedAsset <T>(IAssetInfo info, T data, IModMetadata mod) { // can't load a null asset if (data == null) { mod.LogAsMod($"SMAPI blocked asset replacement for '{info.AssetName}': mod incorrectly set asset to a null value.", LogLevel.Error); return(false); } // when replacing a map, the vanilla tilesheets must have the same order and IDs if (data is Map loadedMap && this.Coordinator.TryLoadVanillaAsset(info.AssetName, out Map vanillaMap)) { for (int i = 0; i < vanillaMap.TileSheets.Count; i++) { // check for match TileSheet vanillaSheet = vanillaMap.TileSheets[i]; bool found = this.TryFindTilesheet(loadedMap, vanillaSheet.Id, out int loadedIndex, out TileSheet loadedSheet); if (found && loadedIndex == i) { continue; } // handle mismatch { // only show warning if not farm map // This is temporary: mods shouldn't do this for any vanilla map, but these are the ones we know will crash. Showing a warning for others instead gives modders time to update their mods, while still simplifying troubleshooting. bool isFarmMap = info.AssetNameEquals("Maps/Farm") || info.AssetNameEquals("Maps/Farm_Combat") || info.AssetNameEquals("Maps/Farm_Fishing") || info.AssetNameEquals("Maps/Farm_Foraging") || info.AssetNameEquals("Maps/Farm_FourCorners") || info.AssetNameEquals("Maps/Farm_Island") || info.AssetNameEquals("Maps/Farm_Mining"); string reason = found ? $"mod reordered the original tilesheets, which {(isFarmMap ? "would cause a crash" : "often causes crashes")}.\n\nTechnical details for mod author:\nExpected order [{string.Join(", ", vanillaMap.TileSheets.Select(p => $"'{p.ImageSource}' (id: {p.Id})"))}], but found tilesheet '{vanillaSheet.Id}' at index {loadedIndex} instead of {i}. Make sure custom tilesheet IDs are prefixed with 'z_' to avoid reordering tilesheets." : $"mod has no tilesheet with ID '{vanillaSheet.Id}'. Map replacements must keep the original tilesheets to avoid errors or crashes."; SCore.DeprecationManager.PlaceholderWarn("3.8.2", DeprecationLevel.PendingRemoval); if (isFarmMap) { mod.LogAsMod($"SMAPI blocked asset replacement for '{info.AssetName}': {reason}", LogLevel.Error); return(false); } mod.LogAsMod($"SMAPI detected a potential issue with asset replacement for '{info.AssetName}' map: {reason}", LogLevel.Warn); } } } return(true); }
private StaticTile LoadStaticTile(XmlHelper xmlHelper, Layer layer, TileSheet tileSheet) { int tileIndex = xmlHelper.GetIntAttribute("Index"); BlendMode blendMode = xmlHelper.GetAttribute("BlendMode") == BlendMode.Alpha.ToString() ? BlendMode.Alpha : BlendMode.Additive; StaticTile staticTile = new StaticTile(layer, tileSheet, blendMode, tileIndex); if (!xmlHelper.XmlReader.IsEmptyElement) { LoadProperties(xmlHelper, staticTile); xmlHelper.AdvanceEndElement("Static"); } return(staticTile); }
private void OnEnable() { m_tileMap = (TileMapBehaviour)target; m_tileSheet = m_tileMap.TileSheet; var meshSettings = m_tileMap.MeshSettings; if (meshSettings != null) { m_tilesX = meshSettings.TilesX; m_tilesY = meshSettings.TilesY; m_tileResolution = meshSettings.TileResolution; m_tileSize = meshSettings.TileSize; m_meshMode = meshSettings.MeshMode; m_textureFormat = meshSettings.TextureFormat; } m_activeInEditMode = m_tileMap.ActiveInEditMode; }
/// <summary> /// Tests if the given TileSheet is used by this Map by testing /// if the Layers contain and dependent tiles /// </summary> /// <param name="tileSheet">TileSheet to test</param> /// <returns>True if dependent, False otherwise</returns> public bool DependsOnTileSheet(TileSheet tileSheet) { if (tileSheet.Map != this) { return(false); } foreach (Layer layer in m_layers) { if (layer.DependsOnTileSheet(tileSheet)) { return(true); } } return(false); }
/// <summary> /// Removes the given TileSheet from this Map, subject to /// dependencies /// </summary> /// <param name="tileSheet">TileSheet to remove</param> public void RemoveTileSheet(TileSheet tileSheet) { if (!m_tileSheets.Contains(tileSheet)) { throw new Exception("The specified TileSheet is not contained in this map"); } foreach (Layer layer in m_layers) { if (layer.DependsOnTileSheet(tileSheet)) { throw new Exception("Cannot remove TileSheet as it is in use by Layer " + layer.Id); } } m_tileSheets.Remove(tileSheet); }
internal static void DumpObject(string sName, TileSheet oTile) { LogTrace("TileSheet " + sName, ""); if (oTile == null) { LogTrace("", "TileSheet is null"); } else { LogTrace("", "{"); DumpObject(" Description", oTile.Description); DumpObject(" Map", oTile.Map); DumpObject(" TileCount", oTile.TileCount); DumpObject("Properties", oTile.Properties); LogTrace("", "}"); } }
public void ApplyTreehouseIfNecessary() { if (((Game1.farmEvent != null && Game1.farmEvent is WorldChangeEvent && (int)(Game1.farmEvent as WorldChangeEvent).whichEvent == 14) || Game1.MasterPlayer.mailReceived.Contains("leoMoved") || Game1.MasterPlayer.mailReceived.Contains("leoMoved%&NL&%")) && !treehouseBuilt) { TileSheet tilesheet = map.GetTileSheet("untitled tile sheet2"); map.GetLayer("Buildings").Tiles[16, 6] = new StaticTile(map.GetLayer("Buildings"), tilesheet, BlendMode.Alpha, 197); map.GetLayer("Buildings").Tiles[16, 7] = new StaticTile(map.GetLayer("Buildings"), tilesheet, BlendMode.Alpha, 213); map.GetLayer("Back").Tiles[16, 8] = new StaticTile(map.GetLayer("Back"), tilesheet, BlendMode.Alpha, 229); map.GetLayer("Buildings").Tiles[16, 7].Properties["Action"] = new PropertyValue("LockedDoorWarp 3 8 LeoTreeHouse 600 2300"); treehouseBuilt = true; if (Game1.IsMasterGame) { updateDoors(); treehouseDoorDirty = true; } } }
private void LoadTileSheet(GameLocation location) { // Add the tilesheet. TileSheet tileSheet = new TileSheet( id: "z_portal-spritesheet", // a unique ID for the tilesheet map: location.map, imageSource: TileSheetPath, sheetSize: new xTile.Dimensions.Size(800, 16), // the pixel size of your tilesheet image. tileSize: new xTile.Dimensions.Size(16, 16) // should always be 16x16 for maps ); if (location != null && location.map != null && tileSheet != null) { location.map.AddTileSheet(tileSheet); location.map.LoadTileSheets(Game1.mapDisplayDevice); } }
private void PlacePortalSprite(PortalPosition portalPosition) { // remove the existing sprite from the map try { Game1.getLocationFromName(portalPosition.LocationName).removeTile( portalPosition.X, portalPosition.Y, "Buildings"); } catch (IndexOutOfRangeException) { } // Add the sprite to the map Layer layer = Game1.getLocationFromName(portalPosition.LocationName).map.GetLayer("Buildings"); TileSheet tileSheet = Game1.getLocationFromName(portalPosition.LocationName).map.GetTileSheet("z_portal-spritesheet"); layer.Tiles[portalPosition.X, portalPosition.Y] = new StaticTile( layer, tileSheet, BlendMode.Additive, GetPortalSpriteIndex(portalPosition)); }
internal Tile LoadTile(Layer layer, int gid) { if (gid == 0) { return(null); } TileSheet selectedTileSheet = null; int tileIndex = -1; foreach (TileSheet tileSheet in layer.Map.TileSheets) { int property1 = tileSheet.Properties["@FirstGid"]; int property2 = tileSheet.Properties["@LastGid"]; if (gid >= property1 && gid <= property2) { selectedTileSheet = tileSheet; tileIndex = gid - property1; break; } } if (selectedTileSheet == null) { throw new Exception(string.Format("Invalid tile gid: {0}", gid)); } TiledTileSet tiledTileSet; if ((tiledTileSet = TiledMap.TileSets.FirstOrDefault(tileSheet => tileSheet.SheetName == selectedTileSheet.Id)) == null) { return(new StaticTile(layer, selectedTileSheet, BlendMode.Alpha, tileIndex)); } TiledTile tiledTile1 = tiledTileSet.Tiles.FirstOrDefault(tiledTile => { if (tiledTile.TileId == tileIndex) { return(tiledTile.Animation != null); } return(false); }); if (tiledTile1 == null || tiledTile1.Animation.Count <= 0) { return(new StaticTile(layer, selectedTileSheet, BlendMode.Alpha, tileIndex)); } StaticTile[] array = tiledTile1.Animation.Select(frame => new StaticTile(layer, selectedTileSheet, BlendMode.Alpha, frame.TileId)).ToArray(); return(new AnimatedTile(layer, array, tiledTile1.Animation[0].Duration)); }
public static bool TrySetTile(this GameLocation self, int x, int y, string layer, int index, string sheet = null) { TileSheet _sheet = sheet == null ? self.map.TileSheets[0] : self.map.GetTileSheet(sheet); if (_sheet == null || _sheet.TileCount < index || index < 0) { return(false); } Layer _layer = self.map.GetLayer(layer); if (_layer == null || _layer.LayerWidth < x || x < 0 || _layer.LayerHeight < y || y < 0) { return(false); } _layer.Tiles[x, y] = new StaticTile(_layer, _sheet, BlendMode.Alpha, index); return(true); }
/// <inheritdoc /> public void Edit <T>(IAssetData asset) { // add altar if (asset.AssetNameEquals($"Maps/{this.Config.AltarLocation}")) { (int altarX, int altarY) = this.GetAltarPosition(); Map altar = this.Content.Load <Map>("assets/altar.tmx"); asset.AsMap().PatchMap(altar, targetArea: new Rectangle(altarX, altarY, 3, 3)); } // add radio to Wizard's tower else if (asset.AssetNameEquals($"Maps/{this.Config.RadioLocation}")) { Map map = asset.AsMap().Data; // get buildings layer Layer buildingsLayer = map.GetLayer("Buildings"); if (buildingsLayer == null) { Log.Warn("Can't add radio to Wizard's tower: 'Buildings' layer not found."); return; } // get front layer Layer frontLayer = map.GetLayer("Front"); if (frontLayer == null) { Log.Warn("Can't add radio to Wizard's tower: 'Front' layer not found."); return; } // get tilesheet TileSheet tilesheet = map.GetTileSheet("untitled tile sheet"); if (tilesheet == null) { Log.Warn("Can't add radio to Wizard's tower: main tilesheet not found."); return; } // add radio (int radioX, int radioY) = this.GetRadioPosition(); frontLayer.Tiles[radioX, radioY] = new StaticTile(frontLayer, tilesheet, BlendMode.Alpha, 512); (buildingsLayer.Tiles[radioX, radioY] ?? frontLayer.Tiles[radioX, radioY]).Properties["Action"] = "MagicRadio"; } }
public virtual void Draw(SpriteBatch spriteBatch) { if (!Visible) { return; } spriteBatch.End(); float scale = GraphicsManager.WindowZoom; Matrix zoomMatrix = Matrix.CreateScale(new Vector3(scale, scale, 1)); Matrix orthMatrix = zoomMatrix * Matrix.CreateOrthographicOffCenter(0, GraphicsManager.GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsManager.GraphicsDevice.PresentationParameters.BackBufferHeight, 0, 0, 1); alphaTest.Projection = orthMatrix; spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, s1, null, alphaTest); TileSheet menuBack = GraphicsManager.MenuBG; TileSheet menuBorder = GraphicsManager.MenuBorder; int addTrans = Transparent ? 3 : 0; DrawMenuPiece(spriteBatch, menuBack, Color.White, 0, addTrans); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, s2, null, null, zoomMatrix); //draw Texts foreach (IMenuElement element in GetElements()) { element.Draw(spriteBatch, new Loc()); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, null, null, null, zoomMatrix); int addX = 3 * BorderStyle; int addY = 3 * BorderFlash; DrawMenuPiece(spriteBatch, menuBorder, Color.White, addX, addY); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, zoomMatrix); }
public TextureBuilder(MapData map) { this.map = map; tileHandler = TileHandler.tileHandler; this.tiles = tileHandler.TileSheetData; int textureWidth = map.Width * tileHandler.resolution; int textureHeight = map.Height * tileHandler.resolution; Texture = new Texture2D(textureWidth, textureHeight); BuildTexture(); Texture.filterMode = FilterMode.Point; Texture.wrapMode = TextureWrapMode.Clamp; Apply(); }
void OnShown(object sender, EventArgs ee) { // Note: Events are fired in the order (Load, Activated, Shown), // It is said that using a MessageBox() can perturb the order of these events, // causing Shown to occur before Load. // http://stackoverflow.com/questions/3070163/order-of-form-load-form-shown-and-form-activated-events // It is also said that "depending on the order of events fired" is undesirable / bad style; // so perhaps once I understand what the idiomatic alternative would be, // this should be changed. // // To call any GL methods (such as setting the GL Viewport, or loading textures) // the OpenGL system must be initialized, which occurs upon the 'Load' event // firing for a Form which contains a GLControl. // http://www.opentk.com/doc/chapter/2/glcontrol // See also, regarding OpenTK.Graphics.GraphicsContext: // http://www.opentk.com/book/export/html/140 // // For this reason, the GL setup, and GL texture loading (via TileSheet constructor calls) // code has been moved here, in a method we set up to be called upon the 'Shown' event // (which is fired upon the first display of this Form). ts = new TileSheet(16, 16, NEW_OBJID, @"media/tiles/U4.B_enhanced-32x32.png"); f1234 = new TileSheet(4, 9, 32, 32, 1, 1, 1, 1, NEW_OBJID, @"media/tiles/example_all_facings.4_frames.intra_1.png"); f1234_stack = new TileSheet(1, 9, 32, 32, 1, 1, 1, 1, NEW_OBJID, @"media/tiles/example_all_facings.stacked/example_all_facings.intra_1.frame_1.png", @"media/tiles/example_all_facings.stacked/example_all_facings.intra_1.frame_2.png", @"media/tiles/example_all_facings.stacked/example_all_facings.intra_1.frame_3.png", @"media/tiles/example_all_facings.stacked/example_all_facings.intra_1.frame_4.png"); wp_ts = new TileSheet(4, 1, NEW_OBJID, @"media/tiles/whirlpool_bright.png"); wp_stack_ts = new TileSheet(1, 1, NEW_OBJID, @"media/tiles/whirlpool.stacked/whirlpool_1.png", @"media/tiles/whirlpool.stacked/whirlpool_2.png", @"media/tiles/whirlpool.stacked/whirlpool_3.png", @"media/tiles/whirlpool.stacked/whirlpool_4.png"); creatures_stack = new TileSheet(4, 7, NEW_OBJID, @"media/tiles/creatures.stacked/creatures.frame_1.png", @"media/tiles/creatures.stacked/creatures.frame_2.png", @"media/tiles/creatures.stacked/creatures.frame_3.png", @"media/tiles/creatures.stacked/creatures.frame_4.png"); //string[] empty_file_names_list = { }; //TileSheet null_filenames_ts = new TileSheet(4, 4, NEW_OBJID, null ); // Will throw an exception //TileSheet empty_filenames_list_ts = new TileSheet(4, 4, NEW_OBJID, empty_file_names_list); // Will throw an exception TileSprite anim_blue_wiz = new TileSprite(ts, NEW_OBJID, 32, 33); TileSprite anim_red_wiz = new TileSprite(ts, NEW_OBJID, 224, 225, 226, 227); // Counters for 3 frames (A,B,C) and for 4 frames (1,2,3,4) // This illustrates why the master frame cycle need be the Least Common Multiple of (3,4) // (or whatever other set of ITileSprite.num_frames values). TileSprite count_ABC = new TileSprite(ts, NEW_OBJID, 96, 97, 98); //ts[0, 6], ts[1, 6], ts[2, 6]); TileSprite count_1234 = new TileSprite(f1234_stack, NEW_OBJID, 0, 9 + 0, 18 + 0, 27 + 0); // Same as count_1234, but frames from 4 files // TileSprite whirlpool = new TileSprite(wp_ts, NEW_OBJID, 0, 1, 2, 3); TileSprite whirlpool = new TileSprite(wp_stack_ts, NEW_OBJID, 0, 1, 2, 3); // Save as from wp_ts, but using 4 image files in a stack TileSprite bat = new TileSprite(creatures_stack, NEW_OBJID, (0 * 28) + 1, (1 * 28) + 1, (2 * 28) + 1, (3 * 28) + 1); TileSprite skel_mage = new TileSprite(creatures_stack, NEW_OBJID, (0 * 28) + 21, (1 * 28) + 21, (2 * 28) + 21, (3 * 28) + 21); LF = new TileSheet(8, 1, NEW_OBJID, @"media/tiles/lava.wave_down.speed_4.frames_8.png"); // LF == LavaFlow TileSprite lava_flow = new TileSprite(LF, NEW_OBJID, 0, 1, 2, 3, 4, 5, 6, 7); // TODO: Support some manner of ITileSprite for "wave" sprites // TileSheet TW = new TileSheet(1, 9, NEW_OBJID, @"media/tiles/example_wave_test.intra_1.png"); // Will need WaveTileSprite to support this... TileSprite grass = new TileSprite(ts, NEW_OBJID, 4); TileSprite trees = new TileSprite(ts, NEW_OBJID, 6); TileSprite boulder = new TileSprite(ts, NEW_OBJID, 57); int[] path_rect_5x4 = new int[] { // 5 = grass, 7 = trees, 58 = boulder boulder.ID, grass.ID, grass.ID, trees.ID, grass.ID, grass.ID, grass.ID, grass.ID, trees.ID, trees.ID, trees.ID, trees.ID, trees.ID, trees.ID, 0, // 0 is a "hole in the map" for blitting / map composition purposes grass.ID, grass.ID, trees.ID, grass.ID, grass.ID, }; DenseGrid map_16x64 = new DenseGrid(16, 64, lava_flow.ID); // Blit a non-square grid onto the map, demonstrating the various possible rotations and flips: DenseGrid flip_none = new DenseGrid(5, 4, path_rect_5x4); DenseGrid flip_we = flip_none.Flip_WE(); DenseGrid flip_ns = flip_none.Flip_NS(); DenseGrid flip_wens = flip_we.Flip_NS(); DenseGrid.BlitFromAOntoB(flip_none, map_16x64, 1, 1); DenseGrid.BlitFromAOntoB(flip_we, map_16x64, 7, 1); DenseGrid.BlitFromAOntoB(flip_ns, map_16x64, 1, 7); DenseGrid.BlitFromAOntoB(flip_wens, map_16x64, 7, 7); DenseGrid flip_none_rot090 = flip_none.Rotate090(); DenseGrid flip_we_rot090 = flip_we.Rotate090(); DenseGrid flip_ns_rot090 = flip_ns.Rotate090(); DenseGrid flip_wens_rot090 = flip_wens.Rotate090(); DenseGrid.BlitFromAOntoB(flip_none_rot090, map_16x64, 1, 52); DenseGrid.BlitFromAOntoB(flip_we_rot090, map_16x64, 7, 52); DenseGrid.BlitFromAOntoB(flip_ns_rot090, map_16x64, 1, 58); DenseGrid.BlitFromAOntoB(flip_wens_rot090, map_16x64, 7, 58); map = new SimpleMapV1(16, 64); map.AddTerrainRegion(map_16x64, 0, 0); tvpc.scroll_constraint = ScrollConstraint.CenterTile; tvpc.set_center(map, 2, 2); // Add some elements to the Beings layer of the Map: // BUG: (in demo data) // The below are bare integers which do not correspond // to a constructed TileSprite; those display wrongly (confusion between object ID and OpenGL texture ID or somesuch?) // The fix is merely to create TileSprite objects and use their .ID // (This fossil is due to the TileSheet + TileSprite refactor; // the sprites are no longer implicitly created and stored within the TileSheet) /* map.layers[MapLayers.Beings].set_contents_at_XY( 8, 7, 256+21); // Horse map.layers[MapLayers.Beings].set_contents_at_XY( 4, 15, 256+21); // Horse map.layers[MapLayers.Beings].set_contents_at_XY( 8, 20, 33); // Wizard map.layers[MapLayers.Beings].set_contents_at_XY( 3, 25, 70); // Force field map.layers[MapLayers.Beings].set_contents_at_XY(10, 30, 29); // Stair down map.layers[MapLayers.Beings].set_contents_at_XY( 9, 35, 30); // Ruin map.layers[MapLayers.Beings].set_contents_at_XY( 6, 40, 45); // Archer map.layers[MapLayers.Beings].set_contents_at_XY(12, 45, 23); // Purple tiles map.layers[MapLayers.Beings].set_contents_at_XY( 5, 50, 19); // Ship */ map.layers[MapLayers.Beings].set_contents_at_XY(2, 1, anim_blue_wiz.ID); // Blue Wizard, animated (2 frames) map.layers[MapLayers.Beings].set_contents_at_XY(3, 3, anim_red_wiz.ID); // Red Wizard, animated (4 frames) map.layers[MapLayers.Beings].set_contents_at_XY(4, 1, count_ABC.ID); // 3 frames (A,B,C) map.layers[MapLayers.Beings].set_contents_at_XY(5, 1, count_1234.ID); // 4 frames (1,2,3,4) map.layers[MapLayers.Beings].set_contents_at_XY(6, 6, bat.ID); map.layers[MapLayers.Beings].set_contents_at_XY(4, 7, skel_mage.ID); map.layers[MapLayers.Beings].set_contents_at_XY(0, 0, whirlpool.ID); // Add some elements to the UI_elements layer of the TileViewPort: // Over-sized cursor // Drawback: outside of tile bounds // is off-viewport for edge-of-viewport sides of cursor on edge-of-viewport tiles. // Also, the "quanta" animation rate for the cursor blinking is too fast, as in "pokemon epilepsy warning" too-fast. // (Blinking at "frame" rate seems OK...may want a modestly faster rate.) // // This cursor _does_ look a lot better, other than for edge-of-viewport tiles. // One possible solution to that issue would be for the "rest" state of the viewport // to have an n-pixel border along all edges, showing partial tiles. // Will need to coordinate all this with smooth-scrolling, too... ts_cursor_blink_40x40 = new TileSheet(1, 1, 40, 40, 0, 0, 0, 0, NEW_OBJID, @"media/cursors/cursor_40x40_blink.stacked/cursor_40x40.frame_1.png", @"media/cursors/cursor_40x40_blink.stacked/cursor_40x40.frame_2.png"); TileSprite large_cursor = new TileSprite(ts_cursor_blink_40x40, NEW_OBJID, 0, 1); int LC = large_cursor.ID; tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.center_x, tvpc.center_y, LC); // Center tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, 0, LC); // NW tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, 0, LC); // NE tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, tvpc.max_y, LC); // SW tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, tvpc.max_y, LC); // SE // // "Marquee" cursor // // Drawback: cursor itself is entirely within tile bounds, thus clips edge pixels of the under-cursor tile... // // //reticle_single_file_ts = new TileSheet(4, 1, NEW_OBJID, @"media/tiles/bright_marquee.frame_1234.png"); reticle_four_files_ts = new TileSheet(4, 4, NEW_OBJID, @"media/tiles/bright_marquee.frame_1.png", @"media/tiles/bright_marquee.frame_2.png", @"media/tiles/bright_marquee.frame_3.png", @"media/tiles/bright_marquee.frame_4.png"); // Also used in Form1.OnPaint() //TileSprite anim_reticle = new TileSprite(reticle_four_files_ts, 15, 31, 47, 63); // Bottom right tile in each image file //int reticle = anim_reticle.ID; //tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.center_x, tvpc.center_y, reticle); // Center //tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, 0, reticle); // NW //tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, 0, reticle); // NE //tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, tvpc.max_y, reticle); // SW //tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, tvpc.max_y, reticle); // SE // A few method calls to demonstrate that Archetype and Obj are working: Archetype aa = new Archetype("first_test_archetype", 0); aa.add_field("int_2a", FieldType.INT); aa.add_field("string_2a", FieldType.STRING); aa.add_field("decimal_2a", FieldType.DECIMAL); aa.add_field("ID_2a", FieldType.ID); aa.add_field("int_list", FieldType.LIST_INT); aa.add_field("string_list", FieldType.LIST_STRING); aa.add_field("decimal_list", FieldType.LIST_DECIMAL); aa.add_field("ID_list", FieldType.LIST_ID); Obj obj1 = new Obj(aa, "first_test_obj", 0); stdout.print("archetype.serialize()\n"); stdout.print("{0}", aa.serialize() ); stdout.print("\n"); stdout.print("obj.serialize()\n"); stdout.print("{0}", obj1.serialize() ); stdout.print("\n"); }
void processPlatform(TileSheet tileSheet, int index) { Tile startTile = tileSheet.getTile (index); Platform p = new Platform (startTile); searchSideways (p, tileSheet, startTile, true); searchSideways (p, tileSheet, startTile, false); p.m_wallLeft = tileSheet.getTile (p.m_left.x - 1, p.m_left.y) != null; p.m_wallRight = tileSheet.getTile (p.m_right.x + 1, p.m_right.y) != null; m_platforms.Add (p); }
void findPlatforms(TileSheet tileSheet) { for (int i = 0; i < tileSheet.nofTiles; i++) { Tile t = tileSheet.getTile (i); if (t != null && t.m_meta == (int)Processing.NotDone) { t.m_meta = (int)Processing.Done; if (t.isWalkable ()) processPlatform (tileSheet, i); } } }
void searchSideways(Platform p, TileSheet tileSheet, Tile startTile, bool isRightDir) { bool finding = true; Tile currentTile = startTile; int addDirNumber = isRightDir ? 1 : -1; for (int x = startTile.m_pos.x+addDirNumber; x < tileSheet.m_width && x > 0 && finding; x += addDirNumber) { finding = false; for (int y = currentTile.m_pos.y - 1; y <= currentTile.m_pos.y + 1; y++) { Tile t = tileSheet.getTile (x, y); if (t != null) { t.m_meta = (int)Processing.Done; if (t.isWalkable ()) { currentTile = t; p.addTile (t); finding = true; break; } } } } }
public TileGrid() { this.UseTilingSafeBorders = true; _layers = new List<TileLayer>(); _visibilityChanged = true; this.Scale = Vector2.One; this.TileSheet = null; }
public bool Create(TileSheet tileSheet, Sprite pfmSprite, Sprite leftDebugSprite, Sprite rightDebugSprite, Vector2 spacing) { HashSet<int> visited = new HashSet<int> (); float visitedPercentage; CreateCandidate (tileSheet, pfmSprite, leftDebugSprite, rightDebugSprite, spacing); //createDebugInfo (pfmSprite, leftDebugSprite, rightDebugSprite, spacing); breadthFirstSearchVisitable (visited, out visitedPercentage); return checkCandidate (visited, visitedPercentage, tileSheet.m_width, tileSheet.m_height); }
void OnShown(object sender, EventArgs ee) { // Note: Events are fired in the order (Load, Activated, Shown), // It is said that using a MessageBox() can perturb the order of these events, // causing Shown to occur before Load. // http://stackoverflow.com/questions/3070163/order-of-form-load-form-shown-and-form-activated-events // It is also said that "depending on the order of events fired" is undesirable / bad style; // so perhaps once I understand what the idiomatic alternative would be, // this should be changed. // // To call any GL methods (such as setting the GL Viewport, or loading textures) // the OpenGL system must be initialized, which occurs upon the 'Load' event // firing for a Form which contains a GLControl. // http://www.opentk.com/doc/chapter/2/glcontrol // See also, regarding OpenTK.Graphics.GraphicsContext: // http://www.opentk.com/book/export/html/140 // // For this reason, the GL setup, and GL texture loading (via TileSheet constructor calls) // code has been moved here, in a method we set up to be called upon the 'Shown' event // (which is fired upon the first display of this Form). ts = new TileSheet(@"Main/U4.B_enhanced-32x32.png", 16, 16); // causes GL textures to be loaded, needs some GL setup prior... f1234 = new TileSheet(@"Main/example_all_facings.4_frames.intra_1.png", 4, 9, 32, 32, 1, 1, 1, 1); ui_ts = new TileSheet(@"Main/bright_marquee.frame_1.png", 4, 4); // Sprite ID 272 is the reticle //ui_ts = new TileSheet(@"Main/bright_marquee.frame_1.alpha.png", 4, 4); // Hmmm...not quite right... //ui_ts = new TileSheet(@"Main/bright_marquee.frame_1.alpha.2.png", 4, 4); // Hmmm...not quite right... wp_ts = new TileSheet(@"Main/whirlpool_bright.png", 4, 1); // TODO: // After setting up all these AnimTileSprite instances, the utility is clear for // various constructor overloads which infer the wanted StaticTileSprite IDs... AnimTileSprite anim_blue_wiz = new AnimTileSprite(ts, ts[32], ts[33]); AnimTileSprite anim_red_wiz = new AnimTileSprite(ts, ts[0, 14], ts[1, 14], ts[2, 14], ts[3, 14]); // Counters for 3 frames (A,B,C) and for 4 frames (1,2,3,4) // This illustrates why the master frame cycle need be the Least Common Multiple of (3,4) // (or whatever other set of ITileSprite.num_frames values). AnimTileSprite count_ABC = new AnimTileSprite(ts, ts[0, 6], ts[1, 6], ts[2, 6]); AnimTileSprite count_1234 = new AnimTileSprite(f1234, f1234[0, 0], f1234[1, 0], f1234[2, 0], f1234[3, 0]); AnimTileSprite whirlpool = new AnimTileSprite(wp_ts, wp_ts[0], wp_ts[1], wp_ts[2], wp_ts[3]); LF = new TileSheet(@"Main/lava.wave_down.speed_4.frames_8.png", 8, 1); // LF == LavaFlow AnimTileSprite lava_flow = new AnimTileSprite(LF, LF[0], LF[1], LF[2], LF[3], LF[4], LF[5], LF[6], LF[7]); // TileSheet TW = new TileSheet(@"Main/example_wave_test.intra_1.png", 1, 9); // Will need WaveTileSprite to support this... int[] path_rect_5x4 = new int[] { // 5 = grass, 7 = trees, 58 = boulder 58, 5, 5, 7, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 0, 5, 5, 7, 5, 5, }; int lava_ID = ts[12, 4].ID; // Lava //DenseGrid map_16x64 = new DenseGrid(16, 64, lava_ID); // StaticTileSprite lava DenseGrid map_16x64 = new DenseGrid(16, 64, lava_flow.ID); // AnimTileSprite flowing lava DenseGrid flip_none = new DenseGrid(5, 4, path_rect_5x4); // Test with width != height, the better to see the rotations and flips DenseGrid flip_we = flip_none.Flip_WE(); DenseGrid flip_ns = flip_none.Flip_NS(); DenseGrid flip_wens = flip_we.Flip_NS(); DenseGrid.BlitFromAOntoB(flip_none, map_16x64, 1, 1); DenseGrid.BlitFromAOntoB(flip_we, map_16x64, 7, 1); DenseGrid.BlitFromAOntoB(flip_ns, map_16x64, 1, 7); DenseGrid.BlitFromAOntoB(flip_wens, map_16x64, 7, 7); DenseGrid flip_none_rot090 = flip_none.Rotate090(); DenseGrid flip_we_rot090 = flip_we.Rotate090(); DenseGrid flip_ns_rot090 = flip_ns.Rotate090(); DenseGrid flip_wens_rot090 = flip_wens.Rotate090(); DenseGrid.BlitFromAOntoB(flip_none_rot090, map_16x64, 1, 52); DenseGrid.BlitFromAOntoB(flip_we_rot090, map_16x64, 7, 52); DenseGrid.BlitFromAOntoB(flip_ns_rot090, map_16x64, 1, 58); DenseGrid.BlitFromAOntoB(flip_wens_rot090, map_16x64, 7, 58); map = new SimpleMapV1(16, 64, ts); map.AddTerrainRegion(map_16x64, 0, 0); //tvp = new TileViewPort(this.tvp_control, // 15, 15, // //ViewPortScrollingConstraint.EntireMap, // ScrollConstraint.CenterTile, // //ViewPortScrollingConstraint.EdgeCorner, // map, 0, 0); tvpc.scroll_constraint = ScrollConstraint.CenterTile; tvpc.set_center(map, 2, 2); // Add some elements to the Beings layer of the Map: // TODO: Still using hard-coded Sprite ID values here... map.layers[MapLayers.Beings].set_contents_at_XY( 8, 7, 21); // Horse map.layers[MapLayers.Beings].set_contents_at_XY( 8, 7, 21); // Horse map.layers[MapLayers.Beings].set_contents_at_XY( 4, 15, 21); // Horse map.layers[MapLayers.Beings].set_contents_at_XY( 8, 20, 33); // Wizard map.layers[MapLayers.Beings].set_contents_at_XY( 3, 25, 70); // Force field map.layers[MapLayers.Beings].set_contents_at_XY(10, 30, 29); // Stair down map.layers[MapLayers.Beings].set_contents_at_XY( 9, 35, 30); // Ruin map.layers[MapLayers.Beings].set_contents_at_XY( 6, 40, 45); // Archer map.layers[MapLayers.Beings].set_contents_at_XY(12, 45, 23); // Purple tiles map.layers[MapLayers.Beings].set_contents_at_XY( 5, 50, 19); // Ship map.layers[MapLayers.Beings].set_contents_at_XY(2, 1, anim_blue_wiz.ID); // Blue Wizard, animated (2 frames) map.layers[MapLayers.Beings].set_contents_at_XY(3, 3, anim_red_wiz.ID); // Red Wizard, animated (4 frames) map.layers[MapLayers.Beings].set_contents_at_XY(4, 1, count_ABC.ID); // 3 frames (A,B,C) map.layers[MapLayers.Beings].set_contents_at_XY(5, 1, count_1234.ID); // 4 frames (1,2,3,4) map.layers[MapLayers.Beings].set_contents_at_XY(0, 0, whirlpool.ID); // Add some elements to the UI_elements layer of the TileViewPort: int reticle = ui_ts[3, 3].ID; // avoiding hard-coding Sprite ID 272 tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.center_x, tvpc.center_y, reticle); // Center tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, 0, reticle); // NW tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, 0, reticle); // NE tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(0, tvpc.max_y, reticle); // SW tvpc.layers[ViewPortLayers.UI_Elements].set_contents_at_XY(tvpc.max_x, tvpc.max_y, reticle); // SE }
private static void WriteTileSheet(XmlNode itemNode, XmlDocument doc, TileSheet tileSheet) { itemNode.Attributes.Append(doc.CreateAttribute("materialSource")).InnerText = GetAssetSource(tileSheet.Material); itemNode.Attributes.Append(doc.CreateAttribute("materialRef")).InnerText = tileSheet.Material.Name; SerializeAsset(doc, itemNode, tileSheet); itemNode.AppendChildIfNotNull(WriteProperty("TileSize", tileSheet, doc)); itemNode.AppendChildIfNotNull(WriteProperty("EnableCollisionByDefault", tileSheet, doc)); itemNode.AppendChildIfNotNull(WriteProperty("UseTilingSafeBorders", tileSheet, doc)); XmlNode _polys = itemNode.AppendChild(doc.CreateElement("Polygons")); foreach (Polygon polygon in tileSheet.Polygons) { XmlNode _poly = _polys.AppendChild(doc.CreateElement("Polygon")); if (polygon == null) { _poly.InnerText = "n"; } else { _poly.InnerText = polygon.ToString(); } } }
private static TileSheet LoadTileSheet(XmlNode _node, SceneBase scene) { TileSheet tileSheet = new TileSheet(); tileSheet.Material = GetMaterialAssetFromNode(_node, scene); SetProperty("EnableCollisionByDefault", tileSheet, _node); SetProperty("TileSize", tileSheet, _node); SetProperty("Polygons", tileSheet, _node); tileSheet.CreateFlippedPolygons(); return tileSheet; }
public void CreateCandidate(TileSheet tileSheet, Sprite pfmSprite, Sprite leftDebugSprite, Sprite rightDebugSprite, Vector2 spacing) { if (m_baseObject != null) GameObject.Destroy (m_baseObject); m_platforms = new List<Platform> (); m_baseObject = new GameObject ("Platform debug"); for (int i = 0; i < tileSheet.nofTiles; i++) { Tile t = tileSheet.getTile (i); if (t != null) t.m_meta = (int)Processing.NotDone; } findPlatforms (tileSheet); trimPlatforms (); setupConnections (); }
public StaticTileSprite(TileSheet tile_sheet, int OpenGL_texture_id, int xx, int yy, int ww, int hh) : this(tile_sheet, OpenGL_texture_id, new Rectangle(xx, yy, ww, hh)) { // This overload has an empty method body }
// TODO: Add support for "default object/terrain", likely on a per-layer basis... public SimpleMapV1(int ww, int hh, TileSheet ts) { if ((ww < 1) || (ww > GridUtility.max_width )) { throw new ArgumentException("invalid width"); } if ((hh < 1) || (hh > GridUtility.max_height)) { throw new ArgumentException("invalid height"); } if (ts == null) { throw new ArgumentException("invalid tilesheet"); } width = ww; height = hh; sheet = ts; layers = new IGridIterable[MapLayers.COUNT]; layers[MapLayers.Terrain] = new MapCompositedLayer(width, height); layers[MapLayers.Beings] = new MapSparseGridLayer(width, height, null); }