public Punk(String inEntityType, int inTotalLife, Nez.Tiled.TiledMap inMap, bool enemyHasGun, int ntargetPositionRange) : base(inEntityType, inTotalLife, inMap, enemyHasGun, ntargetPositionRange) { EntityType = inEntityType; TileMap = inMap; TotalLife = inTotalLife; CurrentLife = TotalLife; CollisionLayer = TileMap.getLayer <TiledTileLayer>("collisionLayer"); WeightedGraph = new WeightedGridGraph(CollisionLayer); Start = new Point(1, 1); End = new Point(10, 10); WeightedSearchPath = WeightedGraph.search(Start, End); EnemyCanShootGun = enemyHasGun; TargetPositionRange = ntargetPositionRange; }
/// <summary> /// note that the origin is the top left so this position will represent that /// </summary> /// <returns>The world position.</returns> /// <param name="tilemap">Tilemap.</param> public Vector2 getWorldPosition(TiledMap tilemap) { return(new Vector2(x * tilemap.tileWidth, y * tilemap.tileHeight)); }
/// <summary> /// Rectangle that encompases this tile with origin on the top left /// </summary> /// <returns>The tile rectangle.</returns> /// <param name="tilemap">Tilemap.</param> public Rectangle getTileRectangle(TiledMap tilemap) { return(new Rectangle(x * tilemap.tileWidth, y * tilemap.tileHeight, tilemap.tileWidth, tilemap.tileHeight)); }
public TiledIsometricTiledLayer(TiledMap map, string name, int width, int height) : this(map, name, width, height, new TiledTile[width * height]) { }
public TiledIsometricTiledLayer(TiledMap map, string name, int width, int height, TiledTile[] tiles) : base(map, name, width, height, tiles) { }
public TiledMapMover(TiledTileLayer collisionLayer) { this.collisionLayer = collisionLayer; tiledMap = collisionLayer.tiledMap; Assert.isNotNull(collisionLayer, nameof(collisionLayer) + " is required"); }
public TiledTilesetTile(int id, TiledMap tiledMap) { Id = id; TiledMap = tiledMap; }
public TiledTilesetTile(int id, TiledMap tiledMap) { this.id = id; this.tiledMap = tiledMap; }
/// <summary> /// returns the bounds Rectangle of the passed in tile /// </summary> /// <returns>The bounds for tile.</returns> /// <param name="tile">Tile.</param> /// <param name="tilemap">Tilemap.</param> public static Rectangle getBoundsForTile(TiledTile tile, TiledMap tilemap) { return(new Rectangle(tile.x * tilemap.tileWidth, tile.y * tilemap.tileHeight, tilemap.tileWidth, tilemap.tileHeight)); }
public TiledMapMover(TiledTileLayer collisionLayer) { Insist.IsNotNull(collisionLayer, nameof(collisionLayer) + " is required"); this.CollisionLayer = collisionLayer; TiledMap = collisionLayer.TiledMap; }
/// <summary> /// note that the origin is the top left so this position will represent that /// </summary> /// <returns>The world position.</returns> /// <param name="tilemap">Tilemap.</param> public Vector2 GetWorldPosition(TiledMap tilemap) { return(new Vector2(X * tilemap.TileWidth, Y * tilemap.TileHeight)); }
/// <summary> /// Rectangle that encompases this tile with origin on the top left /// </summary> /// <returns>The tile rectangle.</returns> /// <param name="tilemap">Tilemap.</param> public Rectangle GetTileRectangle(TiledMap tilemap) { return(new Rectangle(X * tilemap.TileWidth, Y * tilemap.TileHeight, tilemap.TileWidth, tilemap.TileHeight)); }
public void DrawTile(Batcher batcher, Vector2 position, float layerDepth, int x, int y, float scale) { var tile = GetTile(x, y); if (tile == null) { return; } var t = TiledMap.IsometricTileToWorldPosition(x, y); var tileRegion = tile.TextureRegion; // for the y position, we need to take into account if the tile is larger than the tileHeight and shift. Tiled uses // a bottom-left coordinate system and MonoGame a top-left var rotation = 0f; var spriteEffects = SpriteEffects.None; if (tile.FlippedHorizonally) { spriteEffects |= SpriteEffects.FlipHorizontally; } if (tile.FlippedVertically) { spriteEffects |= SpriteEffects.FlipVertically; } if (tile.FlippedDiagonally) { if (tile.FlippedHorizonally && tile.FlippedVertically) { spriteEffects ^= SpriteEffects.FlipVertically; rotation = MathHelper.PiOver2; t.X += TiledMap.TileHeight + (tileRegion.SourceRect.Height - TiledMap.TileHeight); t.Y -= (tileRegion.SourceRect.Width - TiledMap.TileWidth); } else if (tile.FlippedHorizonally) { spriteEffects ^= SpriteEffects.FlipVertically; rotation = -MathHelper.PiOver2; t.Y += TiledMap.TileHeight; } else if (tile.FlippedVertically) { spriteEffects ^= SpriteEffects.FlipHorizontally; rotation = MathHelper.PiOver2; t.X += TiledMap.TileWidth + (tileRegion.SourceRect.Height - TiledMap.TileHeight); t.Y += (TiledMap.TileWidth - tileRegion.SourceRect.Width); } else { spriteEffects ^= SpriteEffects.FlipHorizontally; rotation = -MathHelper.PiOver2; t.Y += TiledMap.TileHeight; } } // if we had no rotations (diagonal flipping) shift our y-coord to account for any non-tileSized tiles to account for // Tiled being bottom-left origin if (rotation == 0) { t.Y += (TiledMap.TileHeight - tileRegion.SourceRect.Height); } // Scale the tile's relative position, but not the origin t = t * new Vector2(scale) + position; batcher.Draw(tileRegion.Texture2D, t, tileRegion.SourceRect, Color, rotation, Vector2.Zero, scale, spriteEffects, layerDepth); }
/// <summary> /// casts a line from start to end returning the first solid tile it intersects. Note that start and end and clamped to the tilemap /// bounds so make sure you pass in valid positions else you may get odd results! /// </summary> /// <param name="start">Start.</param> /// <param name="end">End.</param> public new TiledTile Linecast(Vector2 start, Vector2 end) { var direction = end - start; // worldToTilePosition clamps to the tilemaps bounds so no need to worry about overlow var startCell = TiledMap.IsometricWorldToTilePosition(start); var endCell = TiledMap.IsometricWorldToTilePosition(end); start.X /= TiledMap.TileWidth; start.Y /= TiledMap.TileHeight; // what tile are we on var intX = startCell.X; var intY = startCell.Y; // ensure our start cell exists if (intX < 0 || intX >= TiledMap.Width || intY < 0 || intY >= TiledMap.Height) { return(null); } // which way we go var stepX = Math.Sign(direction.X); var stepY = Math.Sign(direction.Y); // Calculate cell boundaries. when the step is positive, the next cell is after this one meaning we add 1. // If negative, cell is before this one in which case dont add to boundary var boundaryX = intX + (stepX > 0 ? 1 : 0); var boundaryY = intY + (stepY > 0 ? 1 : 0); // determine the value of t at which the ray crosses the first vertical tile boundary. same for y/horizontal. // The minimum of these two values will indicate how much we can travel along the ray and still remain in the current tile // may be infinite for near vertical/horizontal rays var tMaxX = (boundaryX - start.X) / direction.X; var tMaxY = (boundaryY - start.Y) / direction.Y; if (direction.X == 0f) { tMaxX = float.PositiveInfinity; } if (direction.Y == 0f) { tMaxY = float.PositiveInfinity; } // how far do we have to walk before crossing a cell from a cell boundary. may be infinite for near vertical/horizontal rays var tDeltaX = stepX / direction.X; var tDeltaY = stepY / direction.Y; // start walking and returning the intersecting tiles var tile = Tiles[intX + intY * Width]; if (tile != null) { return(tile); } while (intX != endCell.X || intY != endCell.Y) { if (tMaxX < tMaxY) { intX += stepX; tMaxX += tDeltaX; } else { intY += stepY; tMaxY += tDeltaY; } tile = Tiles[intX + intY * Width]; if (tile != null) { return(tile); } } return(null); }
/// <summary> /// note that world position assumes that the Vector2 was normalized to be in the tilemaps coordinates. i.e. if the tilemap /// is not at 0,0 then the world position should be moved so that it takes into consideration the tilemap offset from 0,0. /// Example: if the tilemap is at 300,300 then the passed in value should be worldPos - (300,300) /// </summary> /// <returns>The tile at world position.</returns> /// <param name="pos">Position.</param> public new TiledTile GetTileAtWorldPosition(Vector2 pos) { var tilePos = TiledMap.IsometricWorldToTilePosition(pos); return(GetTile(tilePos.X, tilePos.Y)); }