protected void drawBounds(SpriteBatch spriteBatch, int X, int Y) { spriteBatch.Draw(FlxG.XnaSheet, new Rectangle((int)(FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)), (int)(FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)), (int)width, (int)height), new Rectangle(1, 1, 1, 1), getBoundingColor()); }
/// <summary> /// Call this function to figure out the on-screen position of the object. /// /// Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it. /// </summary> /// <returns>The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.</returns> override public Vector2 getScreenXY() { Vector2 Point = Vector2.Zero; Point.X = FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X) - offset.X; Point.Y = FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y) - offset.Y; return(Point); }
/** * Call this function to figure out the on-screen position of the object. * * @param P Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it. * * @return The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object. */ virtual public Vector2 getScreenXY() { Vector2 Point = Vector2.Zero; Point.X = FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X); Point.Y = FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y); return(Point); }
protected void drawPivot(SpriteBatch spriteBatch, int X, int Y, Color col) { spriteBatch.Draw(FlxG.XnaSheet, new Rectangle((int)(FlxU.floor(X + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)), (int)(FlxU.floor(Y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)), 1, 1), new Rectangle(1, 1, 1, 1), col); }
/// <summary> /// Checks for overlaps between the provided object and any tiles above the collision index. /// </summary> /// <param name="Core">The <code>FlxObject</code> you want to check against.</param> /// <returns>True if overlap occurs, otherwise False</returns> override public bool overlaps(FlxObject Core) { int d; int dd; List <BlockPoint> blocks = new List <BlockPoint>(); //First make a list of all the blocks we'll use for collision int ix = (int)FlxU.floor((Core.x - x) / _tileWidth); int iy = (int)FlxU.floor((Core.y - y) / _tileHeight); int iw = (int)FlxU.ceil((float)Core.width / (float)_tileWidth) + 1; int ih = (int)FlxU.ceil((float)Core.height / (float)_tileHeight) + 1; int r = 0; int c; while (r < ih) { if (r >= heightInTiles) { break; } d = (iy + r) * widthInTiles + ix; c = 0; while (c < iw) { if (c >= widthInTiles) { break; } dd = _data[d + c]; if (dd >= collideMin && dd >= collideMax) { blocks.Add(new BlockPoint((int)(x + (ix + c) * _tileWidth), (int)(y + (iy + r) * _tileHeight), dd)); } c++; } r++; } //Then check for overlaps int bl = blocks.Count; int i = 0; while (i < bl) { _block.x = blocks[i].x; _block.y = blocks[i++].y; if (_block.overlaps(Core)) { return(true); } } return(false); }
virtual public bool overlapsPoint(float X, float Y, bool PerPixel) { X = X + FlxU.floor(FlxG.scroll.X); Y = Y + FlxU.floor(FlxG.scroll.Y); _point = getScreenXY(); if ((X <= _point.X) || (X >= _point.X + width) || (Y <= _point.Y) || (Y >= _point.Y + height)) { return(false); } return(true); }
/// <summary> /// <code>FlxU.collide()</code> (and thus <code>FlxObject.collide()</code>) call /// this function each time two objects are compared to see if they collide. /// It doesn't necessarily mean these objects WILL collide, however. /// </summary> /// <param name="Object">The <code>FlxObject</code> you're about to run into.</param> override public void preCollide(FlxObject Object) { //Collision fix, in case updateMotion() is called colHullX.x = 0; colHullX.y = 0; colHullY.x = 0; colHullY.y = 0; int r; int c; int rs; int ix = (int)FlxU.floor((Object.x - x) / _tileWidth); int iy = (int)FlxU.floor((Object.y - y) / _tileHeight); int iw = ix + (int)FlxU.ceil((float)Object.width / (float)_tileWidth) + 1; int ih = iy + (int)FlxU.ceil((float)Object.height / (float)_tileHeight) + 1; if (ix < 0) { ix = 0; } if (iy < 0) { iy = 0; } if (iw > widthInTiles) { iw = widthInTiles; } if (ih > heightInTiles) { ih = heightInTiles; } rs = iy * widthInTiles; r = iy; colOffsets.Clear(); while (r < ih) { c = ix; while (c < iw) { if (_data[rs + c] >= collideMin && _data[rs + c] <= collideMax) { colOffsets.Add(new Vector2(x + c * _tileWidth, y + r * _tileHeight)); } c++; } rs += widthInTiles; r++; } }
//public void setAngleBasedOnVelocity() //{ // double rot = Math.Atan2((float)velocity.Y, (float)velocity.X); // double degrees = rot * 180 / Math.PI; // angle = (float)degrees; //} /// <summary> /// Draws bounds /// </summary> /// <param name="spriteBatch">Sprite Batch</param> /// <param name="X">X</param> /// <param name="Y">Y</param> protected void drawBounds(SpriteBatch spriteBatch, int X, int Y) { spriteBatch.Draw(FlxG.XnaSheet, new Rectangle((int)(FlxU.floor(x + FlxU.roundingError) + FlxU.floor(FlxG.scroll.X * scrollFactor.X)), (int)(FlxU.floor(y + FlxU.roundingError) + FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)), (int)width, (int)height), new Rectangle(1, 1, 1, 1), getBoundingColor()); if (path != null) { //int count = 0; // Draw a square for each node in a path //foreach (var item in path.nodes) //{ // spriteBatch.Draw(FlxG.XnaSheet, // new Rectangle((int)item.X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)), // (int)item.Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y)), // 4, // 4), // new Rectangle(1, 1, 1, 1), // Color.DarkOrange); //} // Draw a line for each node for (int i = 0; i < path.nodes.Count - 1; i++) { #if !__ANDROID__ spriteBatch.DrawLine(new Vector2((int)path.nodes[i].X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)), (int)path.nodes[i].Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y))), new Vector2((int)path.nodes[i + 1].X - 2 + (int)(FlxU.floor(FlxG.scroll.X * scrollFactor.X)), (int)path.nodes[i + 1].Y - 2 + (int)(FlxU.floor(FlxG.scroll.Y * scrollFactor.Y))), Color.DarkOrange, 1.0f); #endif } } }
/// <summary> /// Checks to see if a point in 2D space overlaps this FlxCore object. /// </summary> /// <param name="X">The X coordinate of the point.</param> /// <param name="Y">The Y coordinate of the point.</param> /// <param name="PerPixel">Whether or not to use per pixel collision checking.</param> /// <returns>Whether or not the point overlaps this object.</returns> override public bool overlapsPoint(float X, float Y, bool PerPixel) { X = X + FlxU.floor(FlxG.scroll.X); Y = Y + FlxU.floor(FlxG.scroll.Y); _point = getScreenXY(); //if(PerPixel) // return _framePixels.hitTest(new Point(0,0),0xFF,new Point(X-_point.x,Y-_point.y)); //else if (_stretchToFit == false) { if ((X <= _point.X) || (X >= _point.X + frameWidth) || (Y <= _point.Y) || (Y >= _point.Y + frameHeight)) { return(false); } } else { if ((X <= _point.X) || (X >= _point.X + width) || (Y <= _point.Y) || (Y >= _point.Y + height)) { return(false); } } return(true); }