public Tile(BitArray tileType = null, Sprite sprite = null) { if (tileType == null) { tileType = TileInfo.CreateTileType(); tileType.Set((int)TileInfo.TileFlag.Empty, true); } this.tileType = tileType; this.sprite = sprite; }
public static Map CreateTestMap(ContentManager Content) { Map map = new Map(); map.backdrop = new FixedBackdrop("bkBlue", Content); TileUnit numRows = 15; TileUnit numCols = 20; map.tiles = new List <List <Tile> >(); for (int i = 0; i < numRows; i++) { map.backgroundTiles.Add(new List <Sprite>()); map.tiles.Add(new List <Tile>()); for (int j = 0; j < numCols; j++) { map.backgroundTiles[i].Add(null); map.tiles[i].Add(new Tile()); } } Sprite sprite = new Sprite(Content, "Stage/PrtCave", Units.TileToPixel(1), 0, Units.TileToPixel(1), Units.TileToPixel(1)); BitArray tmp = TileInfo.CreateTileType(); tmp.Set((int)TileInfo.TileFlag.Wall, true); Tile tile = new Tile(tmp, sprite); TileUnit row = 11; for (TileUnit col = 0; col < numCols; col++) { map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col)] = tile; } map.tiles[10][5] = tile; map.tiles[9][4] = tile; map.tiles[8][3] = tile; map.tiles[7][2] = tile; map.tiles[10][3] = tile; Sprite chainTop = new Sprite(Content, "Stage/PrtCave", Units.TileToPixel(11), Units.TileToPixel(2), Units.TileToPixel(1), Units.TileToPixel(1)); Sprite chainMiddle = new Sprite(Content, "Stage/PrtCave", Units.TileToPixel(12), Units.TileToPixel(2), Units.TileToPixel(1), Units.TileToPixel(1)); Sprite chainBottom = new Sprite(Content, "Stage/PrtCave", Units.TileToPixel(13), Units.TileToPixel(2), Units.TileToPixel(1), Units.TileToPixel(1)); map.backgroundTiles[8][2] = chainTop; map.backgroundTiles[9][2] = chainMiddle; map.backgroundTiles[10][2] = chainBottom; return(map); }
public float GetSlope(BitArray tileType) { BitArray rightTop = TileInfo.CreateTileType(); rightTop.Set((int)TileInfo.TileFlag.RightSlope, true); rightTop.Set((int)TileInfo.TileFlag.TopSlope, true); BitArray leftBottom = TileInfo.CreateTileType(); leftBottom.Set((int)TileInfo.TileFlag.LeftSlope, true); leftBottom.Set((int)TileInfo.TileFlag.BottomSlope, true); bool isPositive = ((rightTop.And(tileType).IsEqual(rightTop)) || (leftBottom.And(tileType).IsEqual(leftBottom))); return(isPositive ? 0.5f : -0.5f); }
CollisionInfo?TestMapStickyCollision(Map map, Rectangle rectangle, TileInfo.SideType direction, BitArray maybeGroundTile) { List <CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction); for (int i = 0; i < tiles.Count; i++) { TileInfo.SideType side = TileInfo.OppositeSide(direction); GameUnit perpendicularPosition; if (TileInfo.Vertical(side)) { perpendicularPosition = rectangle.Center.X; } else { perpendicularPosition = rectangle.Center.Y; } GameUnit leadingPosition = rectangle.Side(direction); bool shouldTestSlopes = TileInfo.Vertical(side); TestCollisionInfo testInfo = tiles[i].TestCollision(side, perpendicularPosition, leadingPosition, shouldTestSlopes); if (testInfo.isColliding) { CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType); return(info); } else if (maybeGroundTile != null && direction == TileInfo.SideType.BottomSide) { BitArray tallSlope = TileInfo.CreateTileType(); tallSlope.Set((int)TileInfo.TileFlag.Slope, true); tallSlope.Set((int)TileInfo.TileFlag.TallSlope, true); if ((maybeGroundTile[(int)TileInfo.TileFlag.Slope] && tiles[i].TileType[(int)TileInfo.TileFlag.Slope]) || (maybeGroundTile[(int)TileInfo.TileFlag.Wall] && (tallSlope.And(tiles[i].TileType).Equals(tallSlope)))) { CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType); return(info); } } } return(null); }
public GameUnit GetOffset(BitArray tileType) { BitArray leftTopTall = TileInfo.CreateTileType(); leftTopTall.Set((int)TileInfo.TileFlag.LeftSlope, true); leftTopTall.Set((int)TileInfo.TileFlag.TopSlope, true); leftTopTall.Set((int)TileInfo.TileFlag.TallSlope, true); BitArray rightBottomShort = TileInfo.CreateTileType(); rightBottomShort.Set((int)TileInfo.TileFlag.RightSlope, true); rightBottomShort.Set((int)TileInfo.TileFlag.BottomSlope, true); rightBottomShort.Set((int)TileInfo.TileFlag.ShortSlope, true); if ((leftTopTall.And(tileType).IsEqual(leftTopTall)) || (rightBottomShort.And(tileType).IsEqual(rightBottomShort))) { return(Units.TileToGame(1)); } BitArray leftBottomTall = TileInfo.CreateTileType(); leftBottomTall.Set((int)TileInfo.TileFlag.LeftSlope, true); leftBottomTall.Set((int)TileInfo.TileFlag.BottomSlope, true); leftBottomTall.Set((int)TileInfo.TileFlag.TallSlope, true); BitArray rightTopShort = TileInfo.CreateTileType(); rightTopShort.Set((int)TileInfo.TileFlag.RightSlope, true); rightTopShort.Set((int)TileInfo.TileFlag.TopSlope, true); rightTopShort.Set((int)TileInfo.TileFlag.ShortSlope, true); if (leftBottomTall.And(tileType).IsEqual(leftBottomTall) || rightTopShort.And(tileType).IsEqual(rightTopShort)) { return(0.0f); } return(Units.HalfTile); }
public static Map CreateSlopeTestMap(ContentManager Content) { Map map = new Map(); map.backdrop = new FixedBackdrop("bkBlue", Content); TileUnit numRows = 15; TileUnit numCols = 20; map.tiles = new List <List <Tile> >(); for (int i = 0; i < numRows; i++) { map.backgroundTiles.Add(new List <Sprite>()); map.tiles.Add(new List <Tile>()); for (int j = 0; j < numCols; j++) { map.backgroundTiles[i].Add(null); map.tiles[i].Add(new Tile()); } } BitArray tmp = TileInfo.CreateTileType(); tmp.Set((int)TileInfo.TileFlag.Wall, true); Tile wallTile = new Tile(tmp, new Sprite(Content, "Stage/PrtCave", Units.TileToPixel(1), 0, Units.TileToPixel(1), Units.TileToPixel(1))); Tile[] slopeTiles = new Tile[(int)SlopeTiles.NumSlopes]; for (int i = 0; i < (int)SlopeTiles.NumSlopes; i++) { BitArray a = TileInfo.CreateTileType(); a.Set((int)TileInfo.TileFlag.Slope, true); a.Set(i / 2 % 2 == 0 ? (int)TileInfo.TileFlag.LeftSlope : (int)TileInfo.TileFlag.RightSlope, true); a.Set(i / 4 == 0 ? (int)TileInfo.TileFlag.TopSlope : (int)TileInfo.TileFlag.BottomSlope, true); a.Set((i + 1) / 2 % 2 == 0 ? (int)TileInfo.TileFlag.TallSlope : (int)TileInfo.TileFlag.ShortSlope, true); slopeTiles[i] = new Tile(a, new Sprite(Content, "Stage/PrtCave", Units.TileToPixel((uint)(2 + i % 4)), Units.TileToPixel((uint)(i / 4)), Units.TileToPixel(1), Units.TileToPixel(1))); } TileUnit row = 11; TileUnit col; for (col = 0; col < numCols; col++) { map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col)] = wallTile; } row--; col = 0; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LBT]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBT]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LBS]; col++; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBS]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBT]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LBT]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LBS]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBS]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBT]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBS]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBT]; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col++)] = wallTile; col++; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RBS]; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; col = 0; row -= 3; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LTT]; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.LTS]; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RTS]; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = slopeTiles[(int)SlopeTiles.RTT]; map.tiles[Convert.ToInt32(row - 1)][Convert.ToInt32(col)] = wallTile; map.tiles[Convert.ToInt32(row)][Convert.ToInt32(col++)] = wallTile; return(map); }