Example #1
0
 /// <summary>
 /// Helper function, just copies the values from this rectangle to the specified rectangle.
 /// </summary>
 /// <param name="rect">Any <code>FlxRect</code>.</param>
 /// <returns>A reference to the altered rectangle parameter.</returns>
 public FlxRect copyTo(FlxRect rect)
 {
     rect.X      = X;
     rect.Y      = Y;
     rect.Width  = Width;
     rect.Height = Height;
     return(this);
 }
Example #2
0
 /// <summary>
 /// Helper function, just copies the values from the specified rectangle.
 /// </summary>
 /// <param name="rect">Any <code>FlxRect</code>.</param>
 /// <returns>A reference to itself.</returns>
 public FlxRect copyFrom(FlxRect rect)
 {
     X      = rect.X;
     Y      = rect.Y;
     Width  = rect.Width;
     Height = rect.Height;
     return(this);
 }
Example #3
0
        /// <summary>
        /// Specify the boundaries of the level or where the camera is allowed to move.
        /// </summary>
        /// <param name="x">The smallest X value of your level (usually 0).</param>
        /// <param name="y">The smallest Y value of your level (usually 0).</param>
        /// <param name="width">The largest X value of your level (usually the level width).</param>
        /// <param name="height">The largest Y value of your level (usually the level height).</param>
        /// <param name="updateWorld">Whether the global quad-tree's dimensions should be updated to match (default: false).</param>
        public void setBounds(float x = 0, float y = 0, float width = 0, float height = 0, Boolean updateWorld = false)
        {
            if (Bounds == null)
            {
                Bounds = new FlxRect();
            }

            Bounds.make(x, y, width, height);

            if (updateWorld)
            {
                FlxG.worldBounds.copyFrom(Bounds);
            }

            update();
        }
Example #4
0
        public override void destroy()
        {
            // flx# - can animations in _animations be null?

            /*
             * if(_animations != null)
             *          {
             *                  FlxAnim a;
             *                  int i = 0;
             *                  int l = _animations.Count;
             *                  while(i < l)
             *                  {
             *                          a = _animations[i++];
             *                          if(a != null)
             *                                  a.destroy();
             *                  }
             *                  _animations = null;
             *          }
             */

            if (_animations != null)
            {
                foreach (FlxAnim animation in _animations)
                {
                    animation.destroy();
                }
            }

            _flashPoint     = null;
            _flashRect      = null;
            _flashRect2     = null;
            _flashPointZero = null;

            Offset = null;
            Origin = null;
            Scale  = null;

            _curAnim = null;
            //_matrix = null; // flx# - matrix is a struct
            _callback = null;
            //_framePixels = null; // flx# - unused
        }
Example #5
0
        /// <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();
        }
Example #6
0
        /// <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;
            }
        }
Example #7
0
        /// <summary>
        /// Creates a white 8x8 square <code>FlxSprite</code> at the specified position.
        /// Optionally can load a simple, one-frame graphic instead.
        /// </summary>
        /// <param name="x">The initial X position of the sprite.</param>
        /// <param name="y">The initial Y position of the sprite.</param>
        /// <param name="graphic">The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).</param>
        public FlxSprite(float x = 0, float y = 0, string graphic = null)
            : base(x, y)
        {
            Health = 1;

            _flashPoint     = new FlxPoint();
            _flashRect      = new FlxRect();
            _flashRect2     = new FlxRect();
            _flashPointZero = new FlxPoint(0, 0);
            Offset          = new FlxPoint();
            Origin          = new FlxPoint();

            Scale        = new FlxPoint(1, 1);
            Alpha        = 1;
            Color        = Color.White;
            Blend        = null;
            AntiAliasing = false;
            Cameras      = null;

            Finished    = false;
            _facing     = Right;
            _animations = new List <FlxAnim>();
            _flipped    = 0;
            _curAnim    = null;
            _curFrame   = 0;
            _curIndex   = 0;
            _frameTimer = 0;

            _matrix   = new Matrix();
            _callback = null;

            if (graphic == null)
            {
                graphic = ImgDefault;
            }

            loadGraphic(graphic);

            // flx# stuff
            Angle  = 0f;
            camX   = camY = 0;
            oX     = x;
            oY     = y;
            moving = false;

            /*
             * Scale = new FlxPoint(1.0f, 1.0f);
             * Offset = new FlxPoint();
             * Origin = new FlxPoint();
             * alpha = 1.0f;
             * _color = Color.White * alpha;
             *
             * _animations = new List<FlxAnim>();
             * _animated = false;
             *
             * Finished = false;
             * _facing = Right;
             * _flipped = 0;
             * _curAnim = null;
             * _curFrame = 0;
             * _curIndex = 0;
             * _frameTimer = 0;
             *
             * _callback = null;
             * _matrix = new Matrix();
             *
             * if (graphic == null)
             *  graphic = ImgDefault;
             * loadGraphic(graphic);
             *
             * Angle = 0f;
             *
             * camX = camY = 0;
             * oX = x;
             * oY = y;
             *
             * moving = false;
             */
        }
Example #8
0
        /// <summary>
        /// Override this function to null out variables or
        /// manually call destroy() on class members if necessary.
        /// Don't forget to call super.destroy()!
        /// </summary>
        public override void destroy()
        {
            Velocity = null;
            Acceleration = null;
            Drag = null;
            MaxVelocity = null;
            ScrollFactor = null;
            _tagPoint = null;
            _tagRect = null;
            Last = null;

            // flx# - ?
            //cameras = null;

            if (Path != null)
            {
                Path.destroy();
                Path = null;
            }

            base.destroy();
        }
Example #9
0
        /// <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;
        }
Example #10
0
        /// <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;
        }
Example #11
0
 /// <summary>
 /// Checks to see if some <code>FlxRect</code> object overlaps this <code>FlxRect</code> object.
 /// </summary>
 /// <param name="rect">The rectangle being tested.</param>
 /// <returns>Whether or not the two rectangles overlap.</returns>
 public Boolean overlaps(FlxRect rect)
 {
     return((rect.X + rect.Width > X) && (rect.X < X + Width) && (rect.Y + rect.Height > Y) && (rect.Y < Y + Height));
 }
Example #12
0
 /// <summary>
 /// Helper function, just copies the values from this rectangle to the specified rectangle.
 /// </summary>
 /// <param name="rect">Any <code>FlxRect</code>.</param>
 /// <returns>A reference to the altered rectangle parameter.</returns>
 public FlxRect copyTo(FlxRect rect)
 {
     rect.X = X;
     rect.Y = Y;
     rect.Width = Width;
     rect.Height = Height;
     return this;
 }
Example #13
0
        /// <summary>
        /// This function creates a flat colored square image dynamically.
        /// </summary>
        /// <param name="width">The width of the sprite you want to generate.</param>
        /// <param name="height">The height of the sprite you want to generate.</param>
        /// <param name="color">Specifies the color of the generated block.</param>
        /// <param name="unique">Whether the graphic should be a unique instance in the graphics cache. Default is false.</param>
        /// <param name="key">Optional parameter - specify a string key to identify this graphic in the cache. Trumps Unique flag.</param>
        /// <returns></returns>
        public FlxSprite makeGraphic(uint width, uint height, Color color, bool unique = false, string key = null)
        {
            /*
            if (unique || !string.IsNullOrEmpty(key))
            {
                throw new NotSupportedException();
            }
            */
            _bakedRotation = 0;
            _pixels = FlxG.createBitmap(width, height, color, unique, key);

            Width = width;
            FrameWidth = width;
            Height = height;
            FrameHeight = height;

            resetHelpers();

            // flx# stuff
            drawSourceRect = new Rectangle(0, 0, (int)width, (int)height);

            texture = _pixels;
            sourceRect = new FlxRect(0, 0, width, height);

            return this;
        }
Example #14
0
        public override void destroy()
        {
            // flx# - can animations in _animations be null?
            /*
            if(_animations != null)
            {
                FlxAnim a;
                int i = 0;
                int l = _animations.Count;
                while(i < l)
                {
                    a = _animations[i++];
                    if(a != null)
                        a.destroy();
                }
                _animations = null;
            }
            */

            if (_animations != null)
            {
                foreach (FlxAnim animation in _animations)
                {
                    animation.destroy();
                }
            }

            _flashPoint = null;
            _flashRect = null;
            _flashRect2 = null;
            _flashPointZero = null;

            Offset = null;
            Origin = null;
            Scale = null;

            _curAnim = null;
            //_matrix = null; // flx# - matrix is a struct
            _callback = null;
            //_framePixels = null; // flx# - unused
        }
Example #15
0
        /// <summary>
        /// Load an image from an embedded graphic file.
        /// </summary>
        /// <param name="graphic">The image you want to use.</param>
        /// <param name="animated">Whether the Graphic parameter is a single sprite or a row of sprites.</param>
        /// <param name="reverse">Whether you need this class to generate horizontally flipped versions of the animation frames.</param>
        /// <param name="width">Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param>
        /// <param name="height">Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param>
        /// <param name="unique">Optional, whether the graphic should be a unique instance in the graphics cache.  Default is false.</param>
        /// <returns></returns>
        public FlxSprite loadGraphic(string graphicFile, Boolean animated = false, Boolean reverse = false, float width = 0, float height = 0, bool unique = false)
        {
            Texture2D graphic = FlxS.ContentManager.Load <Texture2D> (graphicFile);

            /*
             * if (unique || reverse)
             * {
             * throw new NotSupportedException();
             * }
             */
            _bakedRotation = 0;

            // flx# - if reversed, addBitmap doubles the texture width and draws
            // a flipped image beside the original one. thus all these * 2 / 2
            // calculations below
            //_pixels = FlxG.addBitmap(graphic, reverse, unique);

            _pixels = graphic;

            if (reverse)
            {
                _flipped = (uint)_pixels.Width >> 1;
            }
            else
            {
                _flipped = 0;
            }

            if (width == 0)
            {
                if (animated)
                {
                    width = _pixels.Width;
                }
                else if (_flipped > 0)
                {
                    width = _pixels.Width * 0.5f;
                }
                else
                {
                    width = _pixels.Width;
                }
            }

            Width      = width;
            FrameWidth = width;

            if (height == 0)
            {
                if (animated)
                {
                    height = width;
                }
                else
                {
                    height = _pixels.Height;
                }
            }

            Height      = height;
            FrameHeight = height;

            resetHelpers();

            // flx# stuff
            drawSourceRect = new Rectangle(0, 0, (int)Width, (int)Height);

            _animated  = animated;
            texture    = graphic;
            sourceRect = new FlxRect(0, 0, width, height);

            return(this);
        }
Example #16
0
        /// <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();
        }
Example #17
0
        /// <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;
        }
Example #18
0
        /// <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();
        }
Example #19
0
        /// <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();
        }
Example #20
0
        /// <summary>
        /// Creates a white 8x8 square <code>FlxSprite</code> at the specified position.
        /// Optionally can load a simple, one-frame graphic instead.
        /// </summary>
        /// <param name="x">The initial X position of the sprite.</param>
        /// <param name="y">The initial Y position of the sprite.</param>
        /// <param name="graphic">The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).</param>
        public FlxSprite(float x = 0, float y = 0, string graphic = null)
            : base(x, y)
        {
            Health = 1;

            _flashPoint = new FlxPoint();
            _flashRect = new FlxRect();
            _flashRect2 = new FlxRect();
            _flashPointZero = new FlxPoint(0, 0);
            Offset = new FlxPoint();
            Origin = new FlxPoint();

            Scale = new FlxPoint(1, 1);
            Alpha = 1;
            Color = Color.White;
            Blend = null;
            AntiAliasing = false;
            Cameras = null;

            Finished = false;
            _facing = Right;
            _animations = new List<FlxAnim>();
            _flipped = 0;
            _curAnim = null;
            _curFrame = 0;
            _curIndex = 0;
            _frameTimer = 0;

            _matrix = new Matrix();
            _callback = null;

            if (graphic == null)
            {
                graphic = ImgDefault;
            }

            loadGraphic(graphic);

            // flx# stuff
            Angle = 0f;
            camX = camY = 0;
            oX = x;
            oY = y;
            moving = false;

            /*
            Scale = new FlxPoint(1.0f, 1.0f);
            Offset = new FlxPoint();
            Origin = new FlxPoint();
            alpha = 1.0f;
            _color = Color.White * alpha;

            _animations = new List<FlxAnim>();
            _animated = false;

            Finished = false;
            _facing = Right;
            _flipped = 0;
            _curAnim = null;
            _curFrame = 0;
            _curIndex = 0;
            _frameTimer = 0;

            _callback = null;
            _matrix = new Matrix();

            if (graphic == null)
                graphic = ImgDefault;
            loadGraphic(graphic);

            Angle = 0f;

            camX = camY = 0;
            oX = x;
            oY = y;

            moving = false;
            */
        }
Example #21
0
        /// <summary>
        /// Specify the boundaries of the level or where the camera is allowed to move.
        /// </summary>
        /// <param name="x">The smallest X value of your level (usually 0).</param>
        /// <param name="y">The smallest Y value of your level (usually 0).</param>
        /// <param name="width">The largest X value of your level (usually the level width).</param>
        /// <param name="height">The largest Y value of your level (usually the level height).</param>
        /// <param name="updateWorld">Whether the global quad-tree's dimensions should be updated to match (default: false).</param>
        public void setBounds(float x = 0, float y = 0, float width = 0, float height = 0, Boolean updateWorld = false)
        {
            if (Bounds == null)
            {
                Bounds = new FlxRect();
            }

            Bounds.make(x, y, width, height);

            if (updateWorld)
            {
                FlxG.worldBounds.copyFrom(Bounds);
            }

            update();
        }
Example #22
0
        /// <summary>
        /// Load an image from an embedded graphic file.
        /// </summary>
        /// <param name="graphic">The image you want to use.</param>
        /// <param name="animated">Whether the Graphic parameter is a single sprite or a row of sprites.</param>
        /// <param name="reverse">Whether you need this class to generate horizontally flipped versions of the animation frames.</param>
        /// <param name="width">Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param>
        /// <param name="height">Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).</param>
        /// <param name="unique">Optional, whether the graphic should be a unique instance in the graphics cache.  Default is false.</param>
        /// <returns></returns>
        public FlxSprite loadGraphic(string graphicFile, Boolean animated = false, Boolean reverse = false, float width = 0, float height = 0, bool unique = false)
        {
            Texture2D graphic = FlxS.ContentManager.Load<Texture2D> (graphicFile);
            /*
            if (unique || reverse)
            {
                throw new NotSupportedException();
            }
            */
            _bakedRotation = 0;

            // flx# - if reversed, addBitmap doubles the texture width and draws
            // a flipped image beside the original one. thus all these * 2 / 2
            // calculations below
            //_pixels = FlxG.addBitmap(graphic, reverse, unique);

            _pixels = graphic;

            if (reverse)
            {
                _flipped = (uint)_pixels.Width >> 1;
            }
            else
            {
                _flipped = 0;
            }

            if (width == 0)
            {
                if (animated)
                {
                    width = _pixels.Width;
                }
                else if (_flipped > 0)
                {
                    width = _pixels.Width * 0.5f;
                }
                else
                {
                    width = _pixels.Width;
                }
            }

            Width = width;
            FrameWidth = width;

            if (height == 0)
            {
                if (animated)
                {
                    height = width;
                }
                else
                {
                    height = _pixels.Height;
                }
            }

            Height = height;
            FrameHeight = height;

            resetHelpers();

            // flx# stuff
            drawSourceRect = new Rectangle(0, 0, (int)Width, (int)Height);

            _animated = animated;
            texture = graphic;
            sourceRect = new FlxRect(0, 0, width, height);

            return this;
        }
Example #23
0
        /// <summary>
        /// Called by <code>FlxGame</code> to set up <code>FlxG</code> during <code>FlxGame</code>'s constructor.
        /// </summary>
        internal static void init(FlxGame game, int width, int height, float zoom)
        {
            FlxG._game = game;
            FlxG.width = width;
            FlxG.height = height;

            FlxG.mute = false;
            FlxG.volume = 1.0f;
            FlxG.sounds = new FlxGroup();
            FlxG.volumeHandler = delegate { };

            //FlxG.clearBitmapCache();

            //if(flashGfxSprite == null)
            //{
            //    flashGfxSprite = new Sprite();
            //    flashGfx = flashGfxSprite.graphics;
            //}

            FlxCamera.DefaultZoom = zoom;
            //FlxG._cameraRect = new Rectangle();
            FlxG.cameras = new List<FlxCamera>();
            //FlxG.UseBufferLocking = false;

            FlxG.plugins = new List<FlxBasic>();
            //addPlugin(new DebugPathDisplay());
            //addPlugin(new TimerManager());

            FlxG.mouse = new FlxMouse();
            FlxG.keys = new FlxKeyboard();
            //FlxG.mobile = false;

            FlxG.levels = null;
            FlxG.scores = null;
            FlxG.visualDebug = false;

            // flx# stuff

            FlxG.cameras = new List<FlxCamera>();

            //FlxG.width = FlxG.graphics.PreferredBackBufferWidth;
            //FlxG.height = FlxG.graphics.PreferredBackBufferHeight;
            FlxG.bgColor = Color.Black;
            FlxG.mute = false;
            FlxG.sounds = new FlxGroup();
            FlxG.worldBounds = new FlxRect();
            FlxG.defaultFont = FlxS.ContentManager.Load<SpriteFont>("deffont");
            //FlxG.zoom = 1f;
            FlxG.pad1 = new FlxGamepad(PlayerIndex.One);
            FlxG.pad2 = new FlxGamepad(PlayerIndex.Two);
            FlxG.pad3 = new FlxGamepad(PlayerIndex.Three);
            FlxG.pad4 = new FlxGamepad(PlayerIndex.Four);
            FlxG.keys = new FlxKeyboard();
            FlxG.mouse = new FlxMouse();
            FlxCamera defaultCam = new FlxCamera(0, 0, FlxG.width, FlxG.height, FlxG.zoom);
            FlxG.addCamera(defaultCam);

            //Thread tCreate = new Thread(FlxG.state.create);
            //tCreate.Start();

            //create state last
            //FlxG.State.create();
        }
Example #24
0
 /// <summary>
 /// Helper function, just copies the values from the specified rectangle.
 /// </summary>
 /// <param name="rect">Any <code>FlxRect</code>.</param>
 /// <returns>A reference to itself.</returns>
 public FlxRect copyFrom(FlxRect rect)
 {
     X = rect.X;
     Y = rect.Y;
     Width = rect.Width;
     Height = rect.Height;
     return this;
 }
Example #25
0
        /// <summary>
        /// Called whenever the game is reset, doesn't have to do quite as much work as the basic initialization stuff.
        /// </summary>
        internal static void reset()
        {
            //FlxG.clearBitmapCache();
            FlxG.resetInput();
            FlxG.destroySounds(true);
            FlxG.levels = null;
            FlxG.scores = null;
            FlxG.level = 0;
            FlxG.score = 0;
            FlxG.paused = false;
            FlxG.timeScale = 1.0f;
            FlxG.elapsed = 0;
            FlxG.globalSeed = (float) FlxU.Random.NextDouble();
            FlxG.worldBounds = new FlxRect(-10, -10, FlxG.width + 20, FlxG.height + 20);
            FlxG.worldDivisions = 6;

            /*
            var debugPathDisplay:DebugPathDisplay = FlxG.getPlugin(DebugPathDisplay) as DebugPathDisplay;
            if(debugPathDisplay != null)
                debugPathDisplay.clear();
            */
        }
Example #26
0
 /// <summary>
 /// Checks to see if some <code>FlxRect</code> object overlaps this <code>FlxRect</code> object.
 /// </summary>
 /// <param name="rect">The rectangle being tested.</param>
 /// <returns>Whether or not the two rectangles overlap.</returns>
 public Boolean overlaps(FlxRect rect)
 {
     return (rect.X + rect.Width > X) && (rect.X < X + Width) && (rect.Y + rect.Height > Y) && (rect.Y < Y + Height);
 }
Example #27
0
        /// <summary>
        /// Instantiates a <code>FlxObject</code>.
        /// </summary>
        /// <param name="x">X-coordinate of the object in space.</param>
        /// <param name="y">y-coordinate of the object in space.</param>
        /// <param name="width">Desired width of the rectangle.</param>
        /// <param name="height">Desired height of the rectangle.</param>
        public FlxObject(float x = 0, float y = 0, float width = 0, float height = 0)
            : base()
        {
            X = x;
            Y = y;
            Last = new FlxPoint(x, y);
            Width = width;
            Height = height;
            Mass = 1.0f;
            Elasticity = 0.0f;

            Immovable = false;
            Moves = true;

            Touching = None;
            WasTouching = None;
            AllowCollisions = Any;

            Velocity = new FlxPoint();
            Acceleration = new FlxPoint();
            Drag = new FlxPoint();
            MaxVelocity = new FlxPoint(10000, 10000);

            Angle = 0;
            AngularVelocity = 0;
            AngularAcceleration = 0;
            AngularDrag = 0;
            MaxAngular = 10000;

            ScrollFactor = new FlxPoint(1, 1);
            _flicker = false;
            _flickerTimer = 0;

            _tagPoint = new FlxPoint();
            _tagRect = new FlxRect();

            Path = null;
            PathSpeed = 0;
            PathAngle = 0;

            // flx# - ?
            //Health = 1;
        }