/** * Clean up memory. */ public void destroy() { Object = null; if(next != null) next.destroy(); next = null; }
public FlxTilemap() : base() { auto = OFF; widthInTiles = 0; heightInTiles = 0; totalTiles = 0; tileGraphic = null; _rects = null; _tiles = null; _tileObjectsForDrawing = new List<FlxTile>(); _tileObjects = null; _tileWidth = 0; _tileHeight = 0; Immovable = true; _block = new FlxObject(); _block.Width = _block.Height = 0; _block.Immovable = true; _startingIndex = 0; collideIndex = 1; AllowCollisions = Any; ID = 3; }
override public void create () { FlxG.Framerate = 50; //FlxG.flashFramerate = 50; // Creates a new tilemap with no arguments collisionMap = new FlxTilemap (); /* * FlxTilemaps are created using strings of comma seperated values (csv) * This string ends up looking something like this: * * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,0,0,0,0, * 0,0,0,0,0,0,1,1,1,0, * 0,0,1,1,1,0,0,0,0,0, * ... * * Each '0' stands for an empty tile, and each '1' stands for * a solid tile * * When using the auto map generation, the '1's are converted into the corresponding frame * in the tileset. */ // Initializes the map using the generated string, the tile images, and the tile size collisionMap.loadMapFile (default_auto, auto_tiles, (int)TILE_WIDTH, (int)TILE_HEIGHT, FlxTilemap.AUTO); add (collisionMap); highlightBox = new FlxObject (0, 0, TILE_WIDTH, TILE_HEIGHT); setupPlayer (); // When switching between modes here, the map is reloaded with it's own data, so the positions of tiles are kept the same // Notice that different tilesets are used when the auto mode is switched autoAltBtn = new FlxButton (4, FlxG.height - 24, "AUTO", altButtonFunc); add (autoAltBtn); resetBtn = new FlxButton (8 + autoAltBtn.Width, FlxG.height - 24, "Reset", resetButtonFunc); add (resetBtn); quitBtn = new FlxButton (FlxG.width - resetBtn.Width - 4, FlxG.height - 24, "Quit", onQuit); add (quitBtn); helperTxt = new FlxText (5, 5, 150, "Click to place tiles. Shift-Click to remove tiles\nArrow keys to move"); add (helperTxt); // Show mouse pointer FlxG.mouse.show (); }
/// <summary> /// The Y-axis component of the object separation process. /// </summary> /// <param name="objectOne">Any <code>FlxObject</code>.</param> /// <param name="objectTwo">Any other <code>FlxObject</code>.</param> /// <returns></returns> public static bool separateY(FlxObject objectOne, FlxObject objectTwo) { //can't separate two immovable objects bool obj1immovable = objectOne.Immovable; bool obj2immovable = objectTwo.Immovable; if(obj1immovable && obj2immovable) return false; ////If one of the objects is a tilemap, just pass it off. if (objectOne is FlxTilemap) return (objectOne as FlxTilemap).overlapsWithCallback(objectTwo, separateY); if (objectTwo is FlxTilemap) return (objectTwo as FlxTilemap).overlapsWithCallback(objectOne, separateY, true); //First, get the two object deltas float overlap = 0; float obj1delta = objectOne.Y - objectOne.Last.Y; float obj2delta = objectTwo.Y - objectTwo.Last.Y; if(obj1delta != obj2delta) { //Check if the Y hulls actually overlap float obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta; float obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta; FlxRect obj1rect = new FlxRect(objectOne.X,objectOne.Y-((obj1delta > 0)?obj1delta:0),objectOne.Width,objectOne.Height+obj1deltaAbs); FlxRect obj2rect = new FlxRect(objectTwo.X,objectTwo.Y-((obj2delta > 0)?obj2delta:0),objectTwo.Width,objectTwo.Height+obj2deltaAbs); if((obj1rect.X + obj1rect.Width > obj2rect.X) && (obj1rect.X < obj2rect.X + obj2rect.Width) && (obj1rect.Y + obj1rect.Height > obj2rect.Y) && (obj1rect.Y < obj2rect.Y + obj2rect.Height)) { float maxOverlap = obj1deltaAbs + obj2deltaAbs + OverlapBias; //If they did overlap (and can), figure out by how much and flip the corresponding flags if(obj1delta > obj2delta) { overlap = objectOne.Y + objectOne.Height - objectTwo.Y; if((overlap > maxOverlap) || !Convert.ToBoolean(objectOne.AllowCollisions & Down) || !Convert.ToBoolean(objectTwo.AllowCollisions & Up)) overlap = 0; else { objectOne.Touching |= Down; objectTwo.Touching |= Up; } } else if(obj1delta < obj2delta) { overlap = objectOne.Y - objectTwo.Height - objectTwo.Y; if((-overlap > maxOverlap) || !Convert.ToBoolean(objectOne.AllowCollisions & Up) || !Convert.ToBoolean(objectTwo.AllowCollisions & Down)) overlap = 0; else { objectOne.Touching |= Up; objectTwo.Touching |= Down; } } } } //Then adjust their positions and velocities accordingly (if there was any overlap) if(overlap != 0) { float obj1v = objectOne.Velocity.Y; float obj2v = objectTwo.Velocity.Y; if(!obj1immovable && !obj2immovable) { overlap *= 0.5f; objectOne.Y = objectOne.Y - overlap; objectTwo.Y += overlap; float obj1velocity = (float)Math.Sqrt((obj2v * obj2v * objectTwo.Mass) / objectOne.Mass) * ((obj2v > 0) ? 1f : -1f); float obj2velocity = (float)Math.Sqrt((obj1v * obj1v * objectOne.Mass) / objectTwo.Mass) * ((obj1v > 0) ? 1f : -1f); float average = (obj1velocity + obj2velocity) * 0.5f; obj1velocity -= average; obj2velocity -= average; objectOne.Velocity.Y = average + obj1velocity * objectOne.Elasticity; objectTwo.Velocity.Y = average + obj2velocity * objectTwo.Elasticity; } else if(!obj1immovable) { objectOne.Y = objectOne.Y - overlap; objectOne.Velocity.Y = obj2v - obj1v*objectOne.Elasticity; //This is special case code that handles cases like horizontal moving platforms you can ride if(objectTwo.Active && objectTwo.Moves && (obj1delta > obj2delta)) objectOne.X += objectTwo.X - objectTwo.Last.X; } else if(!obj2immovable) { objectTwo.Y += overlap; objectTwo.Velocity.Y = obj1v - obj2v*objectTwo.Elasticity; //This is special case code that handles cases like horizontal moving platforms you can ride if(objectOne.Active && objectOne.Moves && (obj1delta < obj2delta)) objectTwo.X += objectOne.X - objectOne.Last.X; } return true; } else return false; }
/// <summary> /// The X-axis component of the object separation process. /// </summary> /// <param name="objectOne">Any <code>FlxObject</code>.</param> /// <param name="objectTwo">Any other <code>FlxObject</code>.</param> /// <returns></returns> public static bool separateX(FlxObject objectOne, FlxObject objectTwo) { // can't separate two immovable objects bool obj1immovable = objectOne.Immovable; bool obj2immovable = objectTwo.Immovable; if(obj1immovable && obj2immovable) return false; // If one of the objects is a tilemap, just pass it off. if (objectOne is FlxTilemap) return (objectOne as FlxTilemap).overlapsWithCallback(objectTwo, separateX); if (objectTwo is FlxTilemap) return (objectTwo as FlxTilemap).overlapsWithCallback(objectOne, separateX, true); // First, get the two object deltas float overlap = 0; float obj1delta = objectOne.X - objectOne.Last.X; float obj2delta = objectTwo.X - objectTwo.Last.X; if(obj1delta != obj2delta) { //Check if the X hulls actually overlap float obj1deltaAbs = (obj1delta > 0) ? obj1delta : -obj1delta; float obj2deltaAbs = (obj2delta > 0) ? obj2delta : -obj2delta; FlxRect obj1rect = new FlxRect(objectOne.X-((obj1delta > 0)?obj1delta:0),objectOne.Last.Y,objectOne.Width+((obj1delta > 0)?obj1delta:-obj1delta),objectOne.Height); FlxRect obj2rect = new FlxRect(objectTwo.X-((obj2delta > 0)?obj2delta:0),objectTwo.Last.Y,objectTwo.Width+((obj2delta > 0)?obj2delta:-obj2delta),objectTwo.Height); if((obj1rect.X + obj1rect.Width > obj2rect.X) && (obj1rect.X < obj2rect.X + obj2rect.Width) && (obj1rect.Y + obj1rect.Height > obj2rect.Y) && (obj1rect.Y < obj2rect.Y + obj2rect.Height)) { float maxOverlap = obj1deltaAbs + obj2deltaAbs + OverlapBias; //If they did overlap (and can), figure out by how much and flip the corresponding flags if(obj1delta > obj2delta) { overlap = objectOne.X + objectOne.Width - objectTwo.X; if((overlap > maxOverlap) || !Convert.ToBoolean(objectOne.AllowCollisions & Right) || !Convert.ToBoolean(objectTwo.AllowCollisions & Left)) overlap = 0; else { objectOne.Touching |= Right; objectTwo.Touching |= Left; } } else if(obj1delta < obj2delta) { overlap = objectOne.X - objectTwo.Width - objectTwo.X; if((-overlap > maxOverlap) || !Convert.ToBoolean(objectOne.AllowCollisions & Left) || !Convert.ToBoolean(objectTwo.AllowCollisions & Right)) overlap = 0; else { objectOne.Touching |= Left; objectTwo.Touching |= Right; } } } } //Then adjust their positions and velocities accordingly (if there was any overlap) if(overlap != 0) { float obj1v = objectOne.Velocity.X; float obj2v = objectTwo.Velocity.X; if(!obj1immovable && !obj2immovable) { overlap *= 0.5f; objectOne.X = objectOne.X - overlap; objectTwo.X += overlap; float obj1velocity = (float)Math.Sqrt((obj2v * obj2v * objectTwo.Mass) / objectOne.Mass) * ((obj2v > 0) ? 1f : -1f); float obj2velocity = (float)Math.Sqrt((obj1v * obj1v * objectOne.Mass) / objectTwo.Mass) * ((obj1v > 0) ? 1f : -1f); float average = (obj1velocity + obj2velocity) * 0.5f; obj1velocity -= average; obj2velocity -= average; objectOne.Velocity.X = average + obj1velocity * objectOne.Elasticity; objectTwo.Velocity.X = average + obj2velocity * objectTwo.Elasticity; } else if(!obj1immovable) { objectOne.X = objectOne.X - overlap; objectOne.Velocity.X = obj2v - obj1v*objectOne.Elasticity; } else if(!obj2immovable) { objectTwo.X += overlap; objectTwo.Velocity.X = obj1v - obj2v*objectTwo.Elasticity; } return true; } else return false; }
/// <summary> /// The main collision resolution function in flixel. /// </summary> /// <param name="objectOne">Any <code>FlxObject</code>.</param> /// <param name="objectTwo">Any other <code>FlxObject</code>.</param> /// <returns>Whether the objects in fact touched and were separated.</returns> public static bool separate(FlxObject objectOne, FlxObject objectTwo) { bool separatedX = separateX(objectOne, objectTwo); bool separatedY = separateY(objectOne, objectTwo); return separatedX || separatedY; }
//This is an overlap callback function, triggered by the calls to FlxU.overlap(). protected bool overlapped(FlxObject object1,FlxObject object2) { if((object1 is EnemyBullet) || (object1 is Bullet)) object1.kill(); object2.hurt(1); return true; }
/** * Call this function to add an object to the root of the tree. This * function will recursively add all group members, but not the groups * themselves. * * @param ObjectOrGroup FlxObjects are just added, FlxGroups are recursed * and their applicable members added accordingly. * @param List A <code>int</code> flag indicating the list to which you want * to add the objects. Options are <code>A_LIST</code> and * <code>B_LIST</code>. */ public void add(FlxBasic ObjectOrGroup, uint List) { _list = List; if (ObjectOrGroup is FlxGroup) { int i = 0; FlxBasic basic; List<FlxBasic> members = ((FlxGroup)ObjectOrGroup).Members; int l = (int)((FlxGroup)(ObjectOrGroup)).length; while (i < l) { basic = members.ElementAt (i++); if ((basic != null) && basic.Exists) { if (basic is FlxGroup) add (basic, List); else if (basic is FlxObject) { _object = (FlxObject)basic; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject (); } } } } } else { _object = (FlxObject)ObjectOrGroup; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject (); } } }
/** * <code>FlxQuadTree</code>'s other main function. Call this after adding * objects using <code>FlxQuadTree.Load()</code> to compare the objects that * you loaded. * * @return Whether or not any overlaps were found. */ public Boolean execute() { Boolean overlapProcessed = false; FlxList iterator; if (_headA.Object != null) { iterator = _headA; while (iterator != null) { _object = iterator.Object; if (_useBothLists) _iterator = _headB; else _iterator = iterator.next; if (_object.Exists && (_object.AllowCollisions > 0) && (_iterator != null) && (_iterator.Object != null) && _iterator.Object.Exists && overlapNode ()) { overlapProcessed = true; } iterator = iterator.next; } } // Advance through the tree by calling overlap on each child if ((_northWestTree != null) && _northWestTree.execute ()) overlapProcessed = true; if ((_northEastTree != null) && _northEastTree.execute ()) overlapProcessed = true; if ((_southEastTree != null) && _southEastTree.execute ()) overlapProcessed = true; if ((_southWestTree != null) && _southWestTree.execute ()) overlapProcessed = true; return overlapProcessed; }
public FlxSpriteCollisionEvent(FlxObject Attacker, FlxObject Target) { _s1 = Attacker; _s2 = Target; }
/** * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>. */ public FlxList() { Object = null; next = null; }
/// <summary> /// Call this function to see if one <code>FlxObject</code> overlaps another. /// Can be called with one object and one group, or two groups, or two objects, /// whatever floats your boat! For maximum performance try bundling a lot of objects /// together using a <code>FlxGroup</code> (or even bundling groups together!). /// /// <p>NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.</p> /// </summary> /// <param name="ObjectOrGroup1">The first object or group you want to check.</param> /// <param name="ObjectOrGroup2">The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group.</param> /// <param name="NotifyCallback">A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject)</code> - that is called if those two objects overlap.</param> /// <param name="ProcessCallback">A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject)</code> - that is called if those two objects overlap. If a ProcessCallback is provided, then NotifyCallback will only be called if ProcessCallback returns true for those objects!</param> /// <returns></returns> public static Boolean overlap(FlxObject ObjectOrGroup1 = null, FlxObject ObjectOrGroup2 = null, Func<FlxObject, FlxObject, Boolean> NotifyCallback = null, Func<FlxObject, FlxObject, Boolean> ProcessCallback = null) { if (ObjectOrGroup1 == null) { ObjectOrGroup1 = FlxG.State; } if (ObjectOrGroup2 == ObjectOrGroup1) { ObjectOrGroup2 = null; } FlxQuadTree.divisions = FlxG.worldDivisions; FlxQuadTree quadTree = new FlxQuadTree(FlxG.worldBounds.X, FlxG.worldBounds.Y, FlxG.worldBounds.Width, FlxG.worldBounds.Height); quadTree.load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, ProcessCallback); Boolean result = quadTree.execute(); quadTree.destroy(); return result; }
/// <summary> /// Call this function to see if one <code>FlxObject</code> collides with another. /// Can be called with one object and one group, or two groups, or two objects, /// whatever floats your boat! For maximum performance try bundling a lot of objects /// together using a <code>FlxGroup</code> (or even bundling groups together!). /// /// <p>This function just calls FlxG.overlap and presets the ProcessCallback parameter to FlxObject.separate. /// To create your own collision logic, write your own ProcessCallback and use FlxG.overlap to set it up.</p> /// /// <p>NOTE: does NOT take objects' scrollfactor into account, all overlaps are checked in world space.</p> /// </summary> /// <param name="objectOrGroup1">The first object or group you want to check.</param> /// <param name="objectOrGroup2">The second object or group you want to check. If it is the same as the first, flixel knows to just do a comparison within that group.</param> /// <param name="notifyCallback">A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject)</code> - that is called if those two objects overlap.</param> /// <returns>Whether any objects were successfully collided/separated.</returns> public static Boolean collide(FlxObject objectOrGroup1 = null, FlxObject objectOrGroup2 = null, Func<FlxObject, FlxObject, Boolean> notifyCallback = null) { return overlap(objectOrGroup1, objectOrGroup2, notifyCallback, FlxObject.separate); }
/// <summary> /// Tells this camera object what <code>FlxObject</code> to track. /// </summary> /// <param name="target">The object you want the camera to track. Set to null to not follow anything.</param> /// <param name="style">Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling <code>follow()</code>.</param> public void follow(FlxObject target, uint style = StyleLockon) { Target = target; float helper; switch (style) { case StylePlatformer: float w = Width / 8; float h = Height / 3; Deadzone = new FlxRect((Width - w) / 2, (Height - h) / 2 - h * 0.25f, w, h); break; case StyleTopdown: helper = FlxU.max(Width, Height) / 4; Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper); break; case StyleTopdownTight: helper = FlxU.max(Width, Height) / 8; Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper); break; case StyleLockon: break; case StyleLoose: Deadzone = new FlxRect(0, 0, Width, Height); break; default: Deadzone = null; break; } }
/// <summary> /// Clean up memory. /// </summary> public override void destroy() { screen.destroy(); screen = null; Target = null; Scroll = null; Deadzone = null; Bounds = null; Buffer = null; //_flashBitmap = null; //_flashRect = null; //_flashPoint = null; fxFlashComplete = null; fxFadeComplete = null; fxShakeComplete = null; fxShakeOffset = null; //_fill = null; base.destroy(); }
/// <summary> /// Copy the bounds, focus object, and deadzone info from an existing camera. /// </summary> /// <param name="camera">The camera you want to copy from.</param> /// <returns>A reference to this <code>FlxCamera</code> object.</returns> public FlxCamera copyFrom(FlxCamera camera) { if (camera.Bounds == null) { this.Bounds = null; } else { if (this.Bounds == null) { this.Bounds = new FlxRect(); } this.Bounds.copyFrom(camera.Bounds); } this.Target = camera.Target; if (this.Target != null) { if (camera.Deadzone == null) { this.Deadzone = null; } else { if (this.Deadzone == null) { this.Deadzone = new FlxRect(); } this.Deadzone.copyFrom(camera.Deadzone); } } return this; }
/// <summary> /// Instantiates a new camera at the specified location, with the specified size and zoom level. /// </summary> /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param> /// <param name="width">The width of the camera display in pixels.</param> /// <param name="height">The height of the camera display in pixels.</param> /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param> public FlxCamera(float x, float y, int width, int height, float zoom = 0) : base() { X = x; Y = y; Width = width; Height = height; Target = null; Deadzone = null; Scroll = new FlxPoint(); _point = new FlxPoint(); Bounds = null; screen = new FlxSprite(); screen.makeGraphic((uint) width, (uint) height, new Color(0, 0, 0, 0)); screen.setOriginToCorner(); //Buffer = (RenderTarget2D)screen.Pixels; BgColor = FlxG.bgColor; _color = Color.White; /* _flashBitmap = new Bitmap(buffer); _flashBitmap.x = -width*0.5; _flashBitmap.y = -height*0.5; _flashSprite = new Sprite(); */ zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values /* _flashOffsetX = width*0.5*zoom; _flashOffsetY = height*0.5*zoom; _flashSprite.x = x + _flashOffsetX; _flashSprite.y = y + _flashOffsetY; _flashSprite.addChild(_flashBitmap); _flashRect = new Rectangle(0,0,width,height); _flashPoint = new Point(); */ fxFlashColor = Color.Black; fxFlashDuration = 0.0f; fxFlashComplete = null; fxFlashAlpha = 0.0f; fxFadeColor = Color.Black; fxFadeDuration = 0.0f; fxFadeComplete = null; fxFadeAlpha = 0.0f; fxShakeIntensity = 0.0f; fxShakeDuration = 0.0f; fxShakeComplete = null; fxShakeOffset = new FlxPoint(); fxShakeDirection = 0; //_fill = new BitmapData(width,height,true,0); // flx# //DefaultZoom = 1.0f; rotating = 0.0f; Zoom = zoom; FlashSprite = new FlxObject(); //BgColor = Color.Black; _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fxHelperTexture.SetData(new[] { Color.White }); _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); _fillTexture.SetData(new[] { Color.White }); UpdateHelpers(); }
//Called whenever the player touches a coin public Boolean getCoin (FlxObject Coin, FlxObject Player) { Coin.kill (); score.text = "SCORE: " + (coins.CountDead () * 100); if (coins.CountLiving () == 0) { status.text = "Find the exit."; exit.Exists = true; } return true; }
//Called whenever the player touches the exit public Boolean win (FlxObject Exit, FlxObject Player) { status.text = "Yay, you won!"; score.text = "SCORE: 5000"; Player.kill (); return true; }
/// <summary> /// Call this function if you want this sound's volume to change /// based on distance from a particular FlxCore object. /// </summary> /// <param name="x">The X position of the sound.</param> /// <param name="y">The Y position of the sound.</param> /// <param name="target">The object you want to track.</param> /// <param name="radius">The maximum distance this sound can travel.</param> /// <param name="pan">Whether the sound should pan in addition to the volume changes (default: true).</param> /// <returns>This FlxSound instance (nice for chaining stuff together, if you're into that).</returns> public FlxSound proximity(float x, float y, FlxObject target, float radius, bool pan = true) { this.x = x; this.y = y; _target = target; _radius = radius; _pan = pan; return this; }
private void wrap (FlxObject obj) { obj.X = (obj.X + obj.Width / 2 + FlxG.width) % FlxG.width - obj.Width / 2; obj.Y = (obj.Y + obj.Height / 2) % FlxG.height - obj.Height / 2; }
/** * Clean up memory. */ public void destroy() { if (_headA != null) _headA.destroy (); _headA = null; // if(_tailA != null) // _tailA.destroy(); _tailA = null; if (_headB != null) _headB.destroy (); _headB = null; // if(_tailB != null) // _tailB.destroy(); _tailB = null; if (_northWestTree != null) _northWestTree.destroy (); _northWestTree = null; if (_northEastTree != null) _northEastTree.destroy (); _northEastTree = null; if (_southEastTree != null) _southEastTree.destroy (); _southEastTree = null; if (_southWestTree != null) _southWestTree.destroy (); _southWestTree = null; _object = null; _processingCallback = null; _notifyCallback = null; //_pool.free(this); }
/// <summary> /// Clean up memory. /// </summary> public override void destroy() { kill(); if (_sound != null) { _sound.Dispose(); } _sound = null; _target = null; name = null; artist = null; base.destroy(); }
// overlapsWithCallBack public Boolean overlapsWithCallback(FlxObject Object, Func<FlxObject, FlxObject, Boolean> Callback=null, Boolean FlipCallbackParams=false, FlxPoint Position=null) { Boolean results = false; float X = base.X; float Y = base.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; }
/// <summary> /// An internal function for clearing all the variables used by sounds. /// </summary> protected void createSound() { destroy(); x = 0; y = 0; _sound = null; _position = 0; _volume = 1.0f; _volumeAdjust = 1.0f; _looped = false; _target = null; _radius = 0; _pan = false; _fadeOutTimer = 0; _fadeOutTotal = 0; _pauseOnFadeOut = false; _fadeInTimer = 0; _fadeInTotal = 0; Exists = false; Active = false; Visible = false; name = null; artist = null; amplitude = 0; amplitudeLeft = 0; amplitudeRight = 0; autoDestroy = false; }
/// <summary> /// Change the emitter's midpoint to match the midpoint of a <code>FlxObject</code>. /// </summary> /// <param name="flxObject">The <code>FlxObject</code> that you want to sync up with.</param> public void at(FlxObject flxObject) { flxObject.getMidpoint(_point); X = _point.X - (Convert.ToInt32(Width)>>1); Y = _point.Y - (Convert.ToInt32(Height)>>1); }