public int Distance(ref CCPointI p) { var hside = X - p.X; var vside = Y - p.Y; return((int)Math.Sqrt(hside * hside + vside * vside)); }
public CCBoundingBoxI Transform(CCAffineTransform matrix) { var top = MinY; var left = MinX; var right = MaxX; var bottom = MaxY; var topLeft = new CCPointI(left, top); var topRight = new CCPointI(right, top); var bottomLeft = new CCPointI(left, bottom); var bottomRight = new CCPointI(right, bottom); matrix.Transform(ref topLeft.X, ref topLeft.Y); matrix.Transform(ref topRight.Y, ref topRight.Y); matrix.Transform(ref bottomLeft.X, ref bottomLeft.Y); matrix.Transform(ref bottomRight.X, ref bottomRight.Y); int minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X)); int maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X)); int minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y)); int maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y)); return(new CCBoundingBoxI(minX, minY, maxX, maxY)); }
public CCBoundingBoxI Transform(CCAffineTransform matrix) { var top = MinY; var left = MinX; var right = MaxX; var bottom = MaxY; var topLeft = new CCPointI(left, top); var topRight = new CCPointI(right, top); var bottomLeft = new CCPointI(left, bottom); var bottomRight = new CCPointI(right, bottom); matrix.Transform(ref topLeft.X, ref topLeft.Y); matrix.Transform(ref topRight.Y, ref topRight.Y); matrix.Transform(ref bottomLeft.X, ref bottomLeft.Y); matrix.Transform(ref bottomRight.X, ref bottomRight.Y); int minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X)); int maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X)); int minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y)); int maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y)); return new CCBoundingBoxI(minX, minY, maxX, maxY); }
public void ExpandToPoint(ref CCPointI point) { ExpandToPoint(point.X, point.Y); }
public void ExpandToCircle(ref CCPointI point, int radius) { ExpandToCircle(point.X, point.Y, radius); }
public bool Equals(CCPointI other) { return this == other; }
public bool Equals(ref CCPointI p) { return X == p.X && Y == p.Y; }
public int Distance(ref CCPointI p) { var hside = X - p.X; var vside = Y - p.Y; return (int)Math.Sqrt(hside * hside + vside * vside); }
public bool Equals(CCPointI other) { return(this == other); }
public bool Equals(ref CCPointI p) { return(X == p.X && Y == p.Y); }
List<character> placeEnemiesRandomly() { List<character> enemies = new List<character>(); int tileDimension = (int)TileTexelSize.Width; int numberOfColumns = (int)MapDimensions.Size.Width; int numberOfRows = (int)MapDimensions.Size.Height; CCTileMapCoordinates randomTile; CCPoint randomLocation; for (int i =0; i < (Int32.Parse(MapPropertyNamed("numEnemies"))+level); i++) { int randCol = CCRandom.GetRandomInt(0, numberOfColumns - 1); int randRow = CCRandom.GetRandomInt(0, numberOfRows - 1); randomTile = new CCTileMapCoordinates(randCol, randRow); //if you randomly chose a non-walkable tile OR another char is on that tile if (character.checkSingleTileWithProperties(randomTile, "walkable", "true") && !isTileOccupied(randomTile)) { randomLocation = LayerNamed("Map").TilePosition(randomTile); randomLocation = new CCPointI((int)randomLocation.X + tileDimension / 2, (int)randomLocation.Y + tileDimension / 2); enemies.Add(new character("enemyChar", 5, randomLocation, availableWeapons[i+1] ));//CCRandom.GetRandomInt(0,availableWeapons.Count-1)] )); } else i--; } return enemies; }
//Calls the tileHandler on EVERY map tile void loopTiles(character oldUser) { int tileDimension = (int)TileTexelSize.Width; int numberOfColumns = (int)MapDimensions.Size.Width; int numberOfRows = (int)MapDimensions.Size.Height; CCPointI world = new CCPointI(0, 0); // Tile maps can have multiple layers, so let's loop through all of them: foreach (CCTileMapLayer layer in TileLayersContainer.Children) { // Loop through the columns and rows to find all tiles for (int column = 0; column < numberOfColumns; column++) { // We're going to add tileDimension / 2 to get the position // of the center of the tile - this will help us in // positioning entities, and will eliminate the possibility // of floating point error when calculating the nearest tile: world.X = tileDimension * column + tileDimension / 2; for (int row = 0; row < numberOfRows; row++) { // See above on why we add tileDimension / 2 world.Y = tileDimension * row + tileDimension / 2; tileHandler(world, layer, oldUser, true); } } } }