/// <summary> /// Internal function used by FlxEmitter to create the particles /// </summary> /// <param name="Graphic"></param> /// <param name="Rotation"></param> /// <param name="Width"></param> /// <param name="Height"></param> /// <returns></returns> public FlxSprite loadParticleGraphic(Texture2D Graphic, float Rotation, float Width = 0, float Height = 0) { rotateBy = Rotation * 0.0174532925f; texture = Graphic; int numFrames = (int)FlxU.floor(texture.Width / texture.Height); if (Width == 0 || Height == 0) { Width = texture.Height; Height = Width; } frameWidth = width = Width; frameHeight = height = Height; List <FlxRect> _draws = new List <FlxRect>(); for (int i = 0; i < numFrames; i++) { FlxRect textureArea = new FlxRect(i * height, 0, width, height); _draws.Add(textureArea); } int di;// = (int)Math.Round(FlxU.randomBetween(0, numFrames)); Random r = new Random(); di = r.Next(numFrames); particleRect = _draws[di]; //FlxRect t = _draws[di]; sourceRect = new FlxRect(particleRect.x, particleRect.y, particleRect.width, particleRect.height); return(this); }
// overlapsWithCallBack public Boolean overlapsWithCallback(FlxObject Object, Func <FlxObject, FlxObject, Boolean> Callback = null, Boolean FlipCallbackParams = false, FlxPoint Position = null) { Boolean results = false; float X = x; float Y = y; if (Position != null) { X = Position.x; Y = Position.x; } //Figure out what tiles we need to check against int selectionX = (int)FlxU.floor((Object.x - X) / _tileWidth); int selectionY = (int)FlxU.floor((Object.y - Y) / _tileHeight); uint selectionWidth = (uint)(selectionX + (FlxU.ceil((int)Object.width / _tileWidth)) + 2); uint selectionHeight = (uint)(selectionY + (FlxU.ceil((int)Object.height / _tileHeight)) + 2); //Then bound these coordinates by the map edges if (selectionX < 0) { selectionX = 0; } if (selectionY < 0) { selectionY = 0; } if (selectionWidth > widthInTiles) { selectionWidth = (uint)widthInTiles; } if (selectionHeight > heightInTiles) { selectionHeight = (uint)heightInTiles; } //Then loop through this selection of tiles and call FlxObject.separate() accordingly uint rowStart = (uint)selectionY * (uint)widthInTiles; uint row = (uint)selectionY; uint column; FlxTile tile; Boolean overlapFound; float deltaX = X - last.x; float deltaY = Y - last.y; while (row < selectionHeight) { column = (uint)selectionX; while (column < selectionWidth) { overlapFound = false; tile = _tileObjects[(int)_data[(int)(rowStart + column)]] as FlxTile; if (Convert.ToBoolean(tile.allowCollisions)) { tile.x = X + (int)column * _tileWidth; tile.y = Y + (int)row * _tileHeight; tile.last.x = tile.x - deltaX; tile.last.y = tile.y - deltaY; if (Callback != null) { if (FlipCallbackParams) { overlapFound = Callback(Object, tile); } else { overlapFound = Callback(tile, Object); } } else { overlapFound = (Object.x + Object.width > tile.x) && (Object.x < tile.x + tile.width) && (Object.y + Object.height > tile.y) && (Object.y < tile.y + tile.height); } if (overlapFound) { if ((tile.callback != null)) { tile.mapIndex = (uint)rowStart + column; tile.callback(tile, Object); } results = true; } } else if ((tile.callback != null)) { tile.mapIndex = (uint)rowStart + (uint)column; tile.callback(tile, Object); } column++; } rowStart += (uint)widthInTiles; row++; } return(results); }