Exemplo n.º 1
0
		public void shoot(FlxPoint Location, int Aim)
		{
			_sfxShoot.play(true);
			base.reset(Location.X-Width/2,Location.Y-Height/2);
			Solid = true;
			switch((uint)Aim)
			{
				case Up:
					play("up");
					Velocity.Y = -speed;
					break;
				case Down:
					play("down");
					Velocity.Y = speed;
					break;
				case Left:
					play("left");
					Velocity.X = -speed;
					break;
				case Right:
					play("right");
					Velocity.X = speed;
					break;
				default:
					break;
			}
		}
Exemplo n.º 2
0
        /**
         * Pathfinding helper function, strips out even more points by raycasting from one point to the next and dropping unnecessary points.
         *
         * @param	Points		An array of <code>FlxPoint</code> nodes.
         */
        protected void raySimplifyPath(List <FlxPoint> Points)
        {
            FlxPoint source    = Points[0];
            int      lastIndex = -1;
            FlxPoint node;
            int      i = 1;
            int      l = Points.Count;

            while (i < l)
            {
                node = Points[i++];
                if (node == null)
                {
                    continue;
                }
                if (ray(source, node, _tagPoint))
                {
                    if (lastIndex >= 0)
                    {
                        Points[lastIndex] = null;
                    }
                }
                else
                {
                    source = Points[lastIndex];
                }
                lastIndex = i - 1;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new <code>FlxEmitter</code> object at a specific position.
        /// Does NOT automatically generate or attach particles!
        /// </summary>
        /// <param name="X">The X position of the emitter.</param>
        /// <param name="Y">The Y position of the emitter.</param>
        /// <param name="size">Optional, specifies a maximum capacity for this emitter.</param>
        public FlxEmitter(float X = 0, float Y = 0, uint size = 0) : base(size)
        {
            ((FlxObject)this).X = X;
            ((FlxObject)this).Y = Y;

            Width  = 0;
            Height = 0;

            minParticleSpeed = new FlxPoint(-100, -100);
            maxParticleSpeed = new FlxPoint(100, 100);

            minRotation = -360;
            maxRotation = 360;

            gravity       = 0;
            particleClass = null;
            particleDrag  = new FlxPoint();

            frequency = 0.1f;
            lifespan  = 3;
            bounce    = 0;

            _quantity = 0;
            _counter  = 0;
            _explode  = true;
            on        = false;
            _point    = new FlxPoint();
        }
Exemplo n.º 4
0
        /**
         * Find a path through the tilemap.  Any tile with any collision flags set is treated as impassable.
         * If no path is discovered then a null reference is returned.
         *
         * @param	Start		The start point in world coordinates.
         * @param	End			The end point in world coordinates.
         * @param	Simplify	Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line.  Default value is true.
         * @param	RaySimplify	Whether to run an extra raycasting simplification algorithm over the remaining path data.  This can result in some close corners being cut, and should be used with care if at all (yet).  Default value is false.
         *
         * @return	A <code>FlxPath</code> from the start to the end.  If no path could be found, then a null reference is returned.
         */
        public FlxPath findPath(FlxPoint Start, FlxPoint End, bool Simplify = true, bool RaySimplify = false)
        {
            //figure out what tile we are starting and ending on.
            int startIndex = (int)((Start.Y - Y) / _tileHeight) * widthInTiles + (int)((Start.X - X) / _tileWidth);
            int endIndex   = (int)((End.Y - Y) / _tileHeight) * widthInTiles + (int)((End.X - X) / _tileWidth);

            //check that the start and end are clear.
            if (((_tileObjects[_data[startIndex]] as FlxTile).AllowCollisions > 0) ||
                ((_tileObjects[_data[endIndex]] as FlxTile).AllowCollisions > 0))
            {
                return(null);
            }

            //figure out how far each of the tiles is from the starting tile
            List <int> distances = computePathDistance(startIndex, endIndex);

            if (distances == null)
            {
                return(null);
            }

            //then count backward to find the shortest path.
            List <FlxPoint> points = new List <FlxPoint>();

            walkPath(distances, endIndex, points);

            //reset the start and end points to be exact
            FlxPoint node;

            node   = points[points.Count - 1] as FlxPoint;
            node.X = Start.X;
            node.Y = Start.Y;
            node   = points[0] as FlxPoint;
            node.X = End.X;
            node.Y = End.Y;

            //some simple path cleanup options
            if (Simplify)
            {
                simplifyPath(points);
            }
            if (RaySimplify)
            {
                raySimplifyPath(points);
            }

            //finally load the remaining points into a new path object and return it
            FlxPath path = new FlxPath();
            int     i    = points.Count - 1;

            while (i >= 0)
            {
                node = points[i--] as FlxPoint;
                if (node != null)
                {
                    path.AddPoint(node, true);
                }
            }
            return(path);
        }
Exemplo n.º 5
0
        /**
         * Pathfinding helper function, strips out extra points on the same line.
         *
         * @param	Points		An array of <code>FlxPoint</code> nodes.
         */
        protected void simplifyPath(List <FlxPoint> Points)
        {
            float    deltaPrevious;
            float    deltaNext;
            FlxPoint last = Points[0];
            FlxPoint node;
            int      i = 1;
            int      l = Points.Count - 1;

            while (i < l)
            {
                node          = Points[i];
                deltaPrevious = (node.X - last.X) / (node.Y - last.Y);
                deltaNext     = (node.X - Points[i + 1].X) / (node.Y - Points[i + 1].Y);
                if ((last.X == Points[i + 1].X) || (last.Y == Points[i + 1].Y) || (deltaPrevious == deltaNext))
                {
                    Points[i] = null;
                }
                else
                {
                    last = node;
                }
                i++;
            }
        }
Exemplo n.º 6
0
		//This is the constructor for the enemy class.  Because we are
		//recycling enemies, we don't want our constructor to have any
		//required parameters.
		public Enemy() : base()
		{
			loadRotatedGraphic(ImgBot,64,0,false,true);

			//We want the enemy's "hit box" or actual size to be
			//smaller than the enemy graphic itself, just by a few pixels.
			Width = 12;
			Height = 12;
			centerOffsets();

			//Here we are setting up the jet particles
			// that shoot out the back of the ship.
			_jets = new FlxEmitter();
			_jets.setRotation();
			//_jets.MakeParticles(ImgJet,15,0,false,0);

			//These parameters help control the ship's
			//speed and direction during the update() loop.
			MaxAngular = 120;
			AngularDrag = 400;
			Drag.X = 35;
			_thrust = 0;
			_playerMidpoint = new FlxPoint();

			_sfxExplode = new FlxSound().loadEmbedded(SndExplode, false, false);
			_sfxHit = new FlxSound().loadEmbedded(SndHit, false, false);
			_sfxJet = new FlxSound().loadEmbedded(SndJet, false, false);
		}
Exemplo n.º 7
0
        /// <summary>
        /// Calculate the distance between two points.
        /// </summary>
        /// <param name="point1">A <code>FlxPoint</code> object referring to the first location.</param>
        /// <param name="point2">A <code>FlxPoint</code> object referring to the second location.</param>
        /// <returns>The distance between the two points as a floating point <code>Number</code> object.</returns>
        internal static float getDistance(FlxPoint point1, FlxPoint point2)
        {
            float dx = point1.X - point2.X;
            float dy = point1.Y - point2.Y;

            return((float)Math.Sqrt(dx * dx + dy * dy));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sometimes its easier or faster to just pass a point object instead of separate X and Y coordinates.
        /// This also gives you the option of not creating a new node but actually adding that specific
        /// <code>FlxPoint</code> object to the path.  This allows you to do neat things, like dynamic paths.
        /// </summary>
        /// <param name="node">The point in world coordinates you want to add to the path.</param>
        /// <param name="index">Where within the list of path nodes to insert this new point.</param>
        /// <param name="asReference">Whether to add the point as a reference, or to create a new point with the specified values.</param>
        public void AddPointAt(FlxPoint node, int index, bool asReference = false)
        {
            if (index > Nodes.Count)
            {
                index = Nodes.Count;
            }

            Nodes.Insert(index, asReference ? node : new FlxPoint(node.X, node.Y));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Remove a node from the path.
        /// NOTE: only works with points added by reference or with references from <code>nodes</code> itself!
        /// </summary>
        /// <param name="node">The point object you want to remove from the path.</param>
        /// <returns>The node that was excised. Returns null if the node was not found.</returns>
        public FlxPoint Remove(FlxPoint node)
        {
            if (Nodes.Remove(node))
            {
                return(node);
            }

            return(null);
        }
Exemplo n.º 10
0
		public void shoot(FlxPoint Location, float Angle)
		{
			_sfxShoot.play(true);
			base.reset(Location.X-Width/2,Location.Y-Height/2);
			FlxU.rotatePoint(0,(int) speed,0,0,Angle,_tagPoint);
			Velocity.X = _tagPoint.X;
			Velocity.Y = _tagPoint.Y;
			Solid = (true);
			play("idle");
		}
Exemplo n.º 11
0
        /// <summary>
        /// Clean up memory.
        /// </summary>
        override public void destroy()
        {
            minParticleSpeed = null;
            maxParticleSpeed = null;
            particleDrag     = null;
            particleClass    = null;
            _point           = null;

            base.destroy();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Instantiate the basic flixel object.
        /// </summary>
        public FlxBasic()
        {
            ID              = -1;
            Exists          = true;
            Active          = true;
            Visible         = true;
            Alive           = true;
            IgnoreDrawDebug = false;

            Position = new FlxPoint();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Instantiate the basic flixel object.
        /// </summary>
        public FlxBasic()
        {
            ID = -1;
            Exists = true;
            Active = true;
            Visible = true;
            Alive = true;
            IgnoreDrawDebug = false;

            Position = new FlxPoint ();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Checks to see if a point in 2D world space overlaps this <code>FlxSprite</code> object's current displayed pixels.
        /// This check is ALWAYS made in screen space, and always takes scroll factors into account.
        /// </summary>
        /// <param name="point">The point in world space you want to check.</param>
        /// <param name="mask">Used in the pixel hit test to determine what counts as solid.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns></returns>
        public bool pixelOverlapPoint(FlxPoint point, uint mask = 0xFF, FlxCamera camera = null)
        {
            throw new NotImplementedException();

            /*
             *          if(Camera == null)
             *                  Camera = FlxG.camera;
             *          getScreenXY(_point,Camera);
             *          _point.x = _point.x - offset.x;
             *          _point.y = _point.y - offset.y;
             *          _flashPoint.x = (Point.x - Camera.scroll.x) - _point.x;
             *          _flashPoint.y = (Point.y - Camera.scroll.y) - _point.y;
             *          return framePixels.hitTest(_flashPointZero,Mask,_flashPoint);
             */
        }
Exemplo n.º 15
0
        /// <summary>
        /// Instantiate a new path object.
        /// </summary>
        /// <param name="nodes">Optional, can specify all the points for the path up front if you want.</param>
        public FlxPath(IEnumerable<FlxPoint> nodes = null)
        {
            Nodes = (nodes == null) ? new List<FlxPoint>() : nodes.ToList();

            _point = new FlxPoint();
            DebugColor = Color.White;
            DebugScrollFactor = new FlxPoint(1, 1);
            IgnoreDrawDebug = false;

            // @TODO
            /*
            var debugPathDisplay:DebugPathDisplay = manager;
            if(debugPathDisplay != null)
                debugPathDisplay.add(this);
            */
        }
Exemplo n.º 16
0
        // overlapsPoint
        override public Boolean overlapsPoint(FlxPoint point, Boolean inScreenSpace = false, FlxCamera camera = null)
        {
            if (!inScreenSpace)
            {
                return((_tileObjects[_data[(int)(((point.Y - Y) / _tileHeight) * widthInTiles + (point.X - X) / _tileWidth)]] as FlxTile).AllowCollisions > 0);
            }

            if (camera == null)
            {
                camera = FlxG.camera;
            }
            point.X = point.X - camera.Scroll.X;
            point.Y = point.Y - camera.Scroll.Y;
            getScreenXY(_tagPoint, camera);
            return((_tileObjects[_data[(int)(((point.Y - _tagPoint.Y) / _tileHeight) * widthInTiles + (point.X - _tagPoint.X) / _tileWidth)]] as FlxTile).AllowCollisions > 0);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Instantiate a new path object.
        /// </summary>
        /// <param name="nodes">Optional, can specify all the points for the path up front if you want.</param>
        public FlxPath(IEnumerable <FlxPoint> nodes = null)
        {
            Nodes = (nodes == null) ? new List <FlxPoint>() : nodes.ToList();

            _point            = new FlxPoint();
            DebugColor        = Color.White;
            DebugScrollFactor = new FlxPoint(1, 1);
            IgnoreDrawDebug   = false;

            // @TODO

            /*
             *          var debugPathDisplay:DebugPathDisplay = manager;
             *          if(debugPathDisplay != null)
             *                  debugPathDisplay.add(this);
             */
        }
Exemplo n.º 18
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
        }
Exemplo n.º 19
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();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Remove a node from the path using the specified position in the list of path nodes.
        /// </summary>
        /// <param name="index">Where within the list of path nodes you want to remove a node.</param>
        /// <returns>The node that was excised. Returns null if there were no nodes in the path.</returns>
        public FlxPoint RemoveAt(int index)
        {
            if (!Nodes.Any())
            {
                return(null);
            }

            // @TODO: if called with wrong arguments this should crash

            /*
             * if (index >= Nodes.Count)
             * {
             *  index = Nodes.Count - 1;
             * }
             */

            FlxPoint removedNode = Nodes[index];

            Nodes.RemoveAt(index);
            return(removedNode);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Calculates the angle between two points. 0 degrees points straight up.
        /// </summary>
        /// <param name="point1">The X coordinate of the point.</param>
        /// <param name="point2">The Y coordinate of the point.</param>
        /// <returns>The angle in degrees, between -180 and 180.</returns>
        internal static float getAngle(FlxPoint point1, FlxPoint point2)
        {
            float x = point2.X - point1.X;
            float y = point2.Y - point1.Y;

            if ((x == 0) && (y == 0))
            {
                return(0);
            }

            float c1    = 3.14159265f * 0.25f;
            float c2    = 3 * c1;
            float ay    = (y < 0) ? -y : y;
            float angle = 0;

            if (x >= 0)
            {
                angle = c1 - c1 * ((x - ay) / (x + ay));
            }
            else
            {
                angle = c2 - c1 * ((x + ay) / (ay - x));
            }

            angle = ((y < 0) ? -angle : angle) * 57.2957796f;

            if (angle > 90)
            {
                angle = angle - 270;
            }
            else
            {
                angle += 90;
            }

            return(angle);
        }
Exemplo n.º 22
0
 public void destroy()
 {
     DebugScrollFactor = null;
     _point            = null;
     Nodes             = null;
 }
Exemplo n.º 23
0
        /**
         * Shoots a ray from the start point to the end point.
         * If/when it passes through a tile, it stores that point and returns false.
         *
         * @param	Start		The world coordinates of the start of the ray.
         * @param	End			The world coordinates of the end of the ray.
         * @param	Result		A <code>Point</code> object containing the first wall impact.
         * @param	Resolution	Defaults to 1, meaning check every tile or so.  Higher means more checks!
         * @return	Returns true if the ray made it from Start to End without hitting anything.  Returns false and fills Result if a tile was hit.
         */
        public bool ray(FlxPoint Start, FlxPoint End, FlxPoint Result = null, float Resolution = 1f)
        {
            float step = _tileWidth;

            if (_tileHeight < _tileWidth)
            {
                step = _tileHeight;
            }
            step /= Resolution;
            float deltaX   = End.X - Start.X;
            float deltaY   = End.Y - Start.Y;
            float distance = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
            int   steps    = (int)FlxU.ceil(distance / step);
            float stepX    = deltaX / steps;
            float stepY    = deltaY / steps;
            float curX     = Start.X - stepX - X;
            float curY     = Start.Y - stepY - Y;
            int   tileX;
            int   tileY;
            int   i = 0;

            while (i < steps)
            {
                curX += stepX;
                curY += stepY;

                if ((curX < 0) || (curX > Width) || (curY < 0) || (curY > Height))
                {
                    i++;
                    continue;
                }

                tileX = (int)curX / _tileWidth;
                tileY = (int)curY / _tileHeight;
                if (Convert.ToBoolean((_tileObjects[_data[tileY * widthInTiles + tileX]] as FlxTile).AllowCollisions))
                {
                    //Some basic helper stuff
                    tileX *= _tileWidth;
                    tileY *= _tileHeight;
                    float rx = 0;
                    float ry = 0;
                    float q;
                    float lx = curX - stepX;
                    float ly = curY - stepY;

                    //Figure out if it crosses the X boundary
                    q = tileX;
                    if (deltaX < 0)
                    {
                        q += _tileWidth;
                    }
                    rx = q;
                    ry = ly + stepY * ((q - lx) / stepX);
                    if ((ry > tileY) && (ry < tileY + _tileHeight))
                    {
                        if (Result == null)
                        {
                            Result = new FlxPoint();
                        }
                        Result.X = rx;
                        Result.Y = ry;
                        return(false);
                    }

                    //Else, figure out if it crosses the Y boundary
                    q = tileY;
                    if (deltaY < 0)
                    {
                        q += _tileHeight;
                    }
                    rx = lx + stepX * ((q - ly) / stepY);
                    ry = q;
                    if ((rx > tileX) && (rx < tileX + _tileWidth))
                    {
                        if (Result == null)
                        {
                            Result = new FlxPoint();
                        }
                        Result.X = rx;
                        Result.Y = ry;
                        return(false);
                    }
                    return(true);
                }
                i++;
            }
            return(true);
        }
Exemplo n.º 24
0
 public void destroy()
 {
     DebugScrollFactor = null;
     _point = null;
     Nodes = null;
 }
Exemplo n.º 25
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
        }
Exemplo n.º 26
0
        /// <summary>
        /// Calculates the angle between two points. 0 degrees points straight up.
        /// </summary>
        /// <param name="point1">The X coordinate of the point.</param>
        /// <param name="point2">The Y coordinate of the point.</param>
        /// <returns>The angle in degrees, between -180 and 180.</returns>
        internal static float getAngle(FlxPoint point1, FlxPoint point2)
        {
            float x = point2.X - point1.X;
            float y = point2.Y - point1.Y;

            if ((x == 0) && (y == 0))
            {
                return 0;
            }

            float c1 = 3.14159265f * 0.25f;
            float c2 = 3 * c1;
            float ay = (y < 0) ? -y : y;
            float angle = 0;

            if (x >= 0)
            {
                angle = c1 - c1 * ((x - ay) / (x + ay));
            }
            else
            {
                angle = c2 - c1 * ((x + ay) / (ay - x));
            }

            angle = ((y < 0) ? -angle : angle) * 57.2957796f;

            if (angle > 90)
            {
                angle = angle - 270;
            }
            else
            {
                angle += 90;
            }

            return angle;
        }
Exemplo n.º 27
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();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Checks to see if a point in 2D world space overlaps this <code>FlxSprite</code> object's current displayed pixels.
        /// This check is ALWAYS made in screen space, and always takes scroll factors into account.
        /// </summary>
        /// <param name="point">The point in world space you want to check.</param>
        /// <param name="mask">Used in the pixel hit test to determine what counts as solid.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns></returns>
        public bool pixelOverlapPoint(FlxPoint point, uint mask = 0xFF, FlxCamera camera = null)
        {
            throw new NotImplementedException();

            /*
            if(Camera == null)
                Camera = FlxG.camera;
            getScreenXY(_point,Camera);
            _point.x = _point.x - offset.x;
            _point.y = _point.y - offset.y;
            _flashPoint.x = (Point.x - Camera.scroll.x) - _point.x;
            _flashPoint.y = (Point.y - Camera.scroll.y) - _point.y;
            return framePixels.hitTest(_flashPointZero,Mask,_flashPoint);
            */
        }
Exemplo n.º 29
0
 /// <summary>
 /// Move the camera focus to this location instantly.
 /// </summary>
 /// <param name="point">Where you want the camera to focus.</param>
 public void focusOn(FlxPoint point)
 {
     point.X += (point.X > 0) ? 0.0000001f : -0.0000001f;
     point.Y += (point.Y > 0) ? 0.0000001f : -0.0000001f;
     Scroll.make(point.X - Width * 0.5f, point.Y - Height * 0.5f);
 }
Exemplo n.º 30
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();
        }
Exemplo n.º 31
0
        /**
         * Basic button update logic
         */
        protected void UpdateButton()
        {
            if(Status == Pressed)
                Status = Normal;

            // Figure out if the button is Highlighted or Pressed or what
            // (ignore checkbox behavior for now).

            if(FlxG.mouse.cursor.Visible)
            {
                if(Cameras == null)
                    Cameras = FlxG.cameras;
                FlxCamera Camera;
                int i = 0;
                int l = Cameras.Count;
                int pointerId = 0;
                //int totalPointers = FlxG.mouse.ActivePointers + 1;
                int totalPointers = 2;
                Boolean offAll = true;
                while(i < l)
                {
                    Camera = Cameras[i++];
                    while(pointerId < totalPointers)
                    {
                        FlxPoint p = new FlxPoint(FlxG.mouse.cursor.X, FlxG.mouse.cursor.Y);
                        if(overlapsPoint(p, true, Camera))
                        {
                            offAll = false;
                            if(FlxG.mouse.pressed())
                            {
                                Status = Pressed;
                                //if(FlxG.mouse.justPressed(pointerId))
                                if(FlxG.mouse.justPressed())
                                {
                                    /*
                                    if(OnDown != null)
                                    {
                                        OnDown.Callback();
                                    }
                                    if(SoundDown != null)
                                        SoundDown.Play(true);
                                    */
                                }
                            }

                            if(Status == Normal)
                            {
                                Status = Highlight;
                                /*
                                if(OnOver != null)
                                    OnOver.Callback();
                                if(SoundOver != null)
                                    SoundOver.Play(true);
                                */

                            }
                        }
                        ++pointerId;
                    }
                }
                if(offAll)
                {
                    if(Status != Normal)
                    {
                        /*
                        if(OnOut != null)
                            OnOut.Callback();

                        if(SoundOut != null)
                            SoundOut.Play(true);
                        */

                    }
                    Status = Normal;
                }
            }

            // Then if the Label and/or the Label offset exist,
            // position them to match the button.
            if(Label != null)
            {
                Label.X = X;
                Label.Y = Y;
            }
            if(LabelOffset != null)
            {
                Label.X += LabelOffset.X;
                Label.Y += LabelOffset.Y;
            }

            // Then pick the appropriate frame of animation
            if((Status == Highlight) && (_onToggle /*|| FlxG.mobile*/))
                Frame = Normal;
            else
                Frame = Status;
        }
Exemplo n.º 32
0
        /**
         * Creates a new <code>FlxButton</code> object with a gray background and a
         * callback function on the UI thread.
         *
         * @param X The X position of the button.
         * @param Y The Y position of the button.
         * @param Label The text that you want to appear on the button.
         * @param OnClick The function to call whenever the button is clicked.
         */
        public FlxButton(float x = 0, float y = 0, String label = null, FlxButtonEvent Callback = null)
            : base(x, y)
        {
            if(label != null)
            {
                Label = new FlxText(x-1, y+3, 80, label);
                Label.setFormat(null, 8, new Color(0x33,0x33,0x33), "center", Color.Transparent);
                LabelOffset = new FlxPoint(-1, 3);
            }
            loadGraphic(ImgDefaultButton, true, false, 80, 20);
            _callback = Callback;
            /*
            onUp = OnClick;

            onDown = null;
            onOut = null;
            onOver = null;
            */
            SoundOver = null;
            SoundOut = null;
            SoundDown = null;
            SoundUp = null;

            Status = Normal;
            _onToggle = false;
            _pressed = false;
            _initialized = false;
        }
Exemplo n.º 33
0
        // 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;
        }
Exemplo n.º 34
0
        // overlapsPoint
        public override Boolean overlapsPoint(FlxPoint point, Boolean inScreenSpace = false, FlxCamera camera = null)
        {
            if (!inScreenSpace)
                return (_tileObjects[_data[(int)(((point.Y - Y) / _tileHeight) * widthInTiles + (point.X - X) / _tileWidth)]] as FlxTile).AllowCollisions > 0;

            if (camera == null)
                camera = FlxG.camera;
            point.X = point.X - camera.Scroll.X;
            point.Y = point.Y - camera.Scroll.Y;
            getScreenXY(_tagPoint, camera);
            return (_tileObjects[_data[(int)(((point.Y - _tagPoint.Y) / _tileHeight) * widthInTiles + (point.X - _tagPoint.X) / _tileWidth)]] as FlxTile).AllowCollisions > 0;
        }
Exemplo n.º 35
0
        /**
         * Find a path through the tilemap.  Any tile with any collision flags set is treated as impassable.
         * If no path is discovered then a null reference is returned.
         *
         * @param	Start		The start point in world coordinates.
         * @param	End			The end point in world coordinates.
         * @param	Simplify	Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line.  Default value is true.
         * @param	RaySimplify	Whether to run an extra raycasting simplification algorithm over the remaining path data.  This can result in some close corners being cut, and should be used with care if at all (yet).  Default value is false.
         *
         * @return	A <code>FlxPath</code> from the start to the end.  If no path could be found, then a null reference is returned.
         */
        public FlxPath findPath(FlxPoint Start, FlxPoint End, bool Simplify=true, bool RaySimplify=false)
        {
            //figure out what tile we are starting and ending on.
            int startIndex = (int)((Start.Y-Y)/_tileHeight) * widthInTiles + (int)((Start.X-X)/_tileWidth);
            int endIndex = (int)((End.Y-Y)/_tileHeight) * widthInTiles + (int)((End.X-X)/_tileWidth);

            //check that the start and end are clear.
            if( ((_tileObjects[_data[startIndex]] as FlxTile).AllowCollisions > 0) ||
                ((_tileObjects[_data[endIndex]] as FlxTile).AllowCollisions > 0) )
                return null;

            //figure out how far each of the tiles is from the starting tile
            List<int> distances = computePathDistance(startIndex,endIndex);
            if(distances == null)
                return null;

            //then count backward to find the shortest path.
            List<FlxPoint> points = new List<FlxPoint>();
            walkPath(distances,endIndex,points);

            //reset the start and end points to be exact
            FlxPoint node;
            node = points[points.Count-1] as FlxPoint;
            node.X = Start.X;
            node.Y = Start.Y;
            node = points[0] as FlxPoint;
            node.X = End.X;
            node.Y = End.Y;

            //some simple path cleanup options
            if(Simplify)
                simplifyPath(points);
            if(RaySimplify)
                raySimplifyPath(points);

            //finally load the remaining points into a new path object and return it
            FlxPath path = new FlxPath();
            int i = points.Count - 1;
            while(i >= 0)
            {
                node = points[i--] as FlxPoint;
                if(node != null)
                    path.AddPoint(node,true);
            }
            return path;
        }
Exemplo n.º 36
0
 /// <summary>
 /// Helper function, just copies the values from the specified point.
 /// </summary>
 /// <param name="point">Any <code>FlxPoint</code>.</param>
 /// <returns>A reference to itself.</returns>
 public FlxPoint copyFrom(FlxPoint point)
 {
     X = point.X;
     Y = point.Y;
     return(this);
 }
Exemplo n.º 37
0
        /// <summary>
        /// Checks to see if a point in 2D world space overlaps this <code>FlxObject</code> object.
        /// </summary>
        /// <param name="point">The point in world space you want to check.</param>
        /// <param name="inScreenSpace">Whether to take scroll factors into account when checking for overlap.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera. flx# - currently only one exists</param>
        /// <returns></returns>
        public virtual bool overlapsPoint(FlxPoint point, bool inScreenSpace = false, FlxCamera camera = null)
        {
            if (!inScreenSpace)
            {
                return (point.X > this.X) && (point.X < this.X + Width) && (point.Y > this.Y) && (point.Y < this.Y + Height);
            }

            if (camera == null)
            {
                camera = FlxG.camera;
            }

            float x = point.X - camera.Scroll.X;
            float y = point.Y - camera.Scroll.Y;
            getScreenXY(_tagPoint, camera);
            return (x > _tagPoint.X) && (x < _tagPoint.X + Width) && (y > _tagPoint.Y) && (y < _tagPoint.Y + Height);
        }
Exemplo n.º 38
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;
             */
        }
Exemplo n.º 39
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;
        }
Exemplo n.º 40
0
        /// <summary>
        /// Remove a node from the path.
        /// NOTE: only works with points added by reference or with references from <code>nodes</code> itself!
        /// </summary>
        /// <param name="node">The point object you want to remove from the path.</param>
        /// <returns>The node that was excised. Returns null if the node was not found.</returns>
        public FlxPoint Remove(FlxPoint node)
        {
            if (Nodes.Remove(node))
            {
                return node;
            }

            return null;
        }
Exemplo n.º 41
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();
        }
Exemplo n.º 42
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;
            */
        }
Exemplo n.º 43
0
        /// <summary>
        /// Retrieve the midpoint of this object in world coordinates.
        /// </summary>
        /// <param name="point">Allows you to pass in an existing <code>FlxPoint</code> object if you're so inclined. Otherwise a new one is created.</param>
        /// <returns>A <code>FlxPoint</code> object containing the midpoint of this object in world coordinates.</returns>
        public FlxPoint getMidpoint(FlxPoint point = null)
        {
            if (point == null)
            {
                point = new FlxPoint();
            }

            // flx# - wtf we dont bitshift here but anywhere else?
            point.X = X + (Width / 2);
            point.Y = Y + (Height / 2);
            return point;
        }
Exemplo n.º 44
0
        //*** NOTE: THESE LAST THREE FUNCTIONS REQUIRE FLXPOINT ***//
        /// <summary>
        /// Rotates a point in 2D space around another point by the given angle.
        /// </summary>
        /// <param name="x">The X coordinate of the point you want to rotate.</param>
        /// <param name="y">The Y coordinate of the point you want to rotate.</param>
        /// <param name="pivotX">The X coordinate of the point you want to rotate around.</param>
        /// <param name="pivotY">The Y coordinate of the point you want to rotate around.</param>
        /// <param name="angle">Rotate the point by this many degrees.</param>
        /// <param name="point">Optional <code>FlxPoint</code> to store the results in.</param>
        /// <returns>A <code>FlxPoint</code> containing the coordinates of the rotated point.</returns>
        public static FlxPoint rotatePoint(float x, float y, float pivotX, float pivotY, float angle, FlxPoint point = null)
        {
            float sin = 0;
            float cos = 0;
            float radians = angle * -0.017453293f;

            while (radians < -3.14159265)
            {
                radians += 6.28318531f;
            }

            while (radians > 3.14159265)
            {
                radians = radians - 6.28318531f;
            }

            if (radians < 0)
            {
                sin = 1.27323954f * radians + .405284735f * radians * radians;

                if (sin < 0)
                {
                    sin = .225f * (sin * -sin - sin) + sin;
                }
                else
                {
                    sin = .225f * (sin * sin - sin) + sin;
                }
            }
            else
            {
                sin = 1.27323954f * radians - 0.405284735f * radians * radians;

                if (sin < 0)
                {
                    sin = .225f * (sin * -sin - sin) + sin;
                }
                else
                {
                    sin = .225f * (sin * sin - sin) + sin;
                }
            }

            radians += 1.57079632f;
            if (radians > 3.14159265)
            {
                radians = radians - 6.28318531f;
            }

            if (radians < 0)
            {
                cos = 1.27323954f * radians + 0.405284735f * radians * radians;

                if (cos < 0)
                {
                    cos = .225f * (cos * -cos - cos) + cos;
                }
                else
                {
                    cos = .225f * (cos * cos - cos) + cos;
                }
            }
            else
            {
                cos = 1.27323954f * radians - 0.405284735f * radians * radians;

                if (cos < 0)
                {
                    cos = .225f * (cos * -cos - cos) + cos;
                }
                else
                {
                    cos = .225f * (cos * cos - cos) + cos;
                }
            }

            float dx = x - pivotX;
            float dy = pivotY + y; // Y axis is inverted in flash, normally this would be a subtract operation // flx# - Hmmmmm...
            if (point == null)
            {
                point = new FlxPoint();
            }
            point.X = pivotX + cos * dx - sin * dy;
            point.Y = pivotY - sin * dx - cos * dy;
            return point;
        }
Exemplo n.º 45
0
        /// <summary>
        /// Call this function to figure out the on-screen position of the object.
        /// </summary>
        /// <param name="point">Takes a <code>FlxPoint</code> object and assigns the post-scrolled X and Y values of this object to it.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns></returns>
        public FlxPoint getScreenXY(FlxPoint point = null, FlxCamera camera = null)
        {
            if (point == null)
            {
                point = new FlxPoint();
            }

            if (camera == null)
            {
                camera = FlxG.camera;
            }

            point.X = X - (camera.Scroll.X * ScrollFactor.X);
            point.Y = Y - (camera.Scroll.Y * ScrollFactor.Y);
            point.X += (point.X > 0) ? 0.0000001f : -0.0000001f;
            point.Y += (point.Y > 0) ? 0.0000001f : -0.0000001f;
            return point;
        }
Exemplo n.º 46
0
 /// <summary>
 /// Calculate the distance between two points.
 /// </summary>
 /// <param name="point1">A <code>FlxPoint</code> object referring to the first location.</param>
 /// <param name="point2">A <code>FlxPoint</code> object referring to the second location.</param>
 /// <returns>The distance between the two points as a floating point <code>Number</code> object.</returns>
 internal static float getDistance(FlxPoint point1, FlxPoint point2)
 {
     float dx = point1.X - point2.X;
     float dy = point1.Y - point2.Y;
     return (float) Math.Sqrt(dx * dx + dy * dy);
 }
Exemplo n.º 47
0
 /// <summary>
 /// Override this function to null out variables or manually call
 /// <code>destroy()</code> on class members if necessary.
 /// Don't forget to call <code>super.destroy()</code>!
 /// </summary>
 public virtual void destroy()
 {
     Position = null;
 }
Exemplo n.º 48
0
        // 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);
        }
Exemplo n.º 49
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();
        }
Exemplo n.º 50
0
        /// <summary>
        /// Sometimes its easier or faster to just pass a point object instead of separate X and Y coordinates.
        /// This also gives you the option of not creating a new node but actually adding that specific
        /// <code>FlxPoint</code> object to the path.  This allows you to do neat things, like dynamic paths.
        /// </summary>
        /// <param name="node">The point in world coordinates you want to add to the path.</param>
        /// <param name="index">Where within the list of path nodes to insert this new point.</param>
        /// <param name="asReference">Whether to add the point as a reference, or to create a new point with the specified values.</param>
        public void AddPointAt(FlxPoint node, int index, bool asReference = false)
        {
            if (index > Nodes.Count)
            {
                index = Nodes.Count;
            }

            Nodes.Insert(index, asReference ? node : new FlxPoint(node.X, node.Y));
        }
Exemplo n.º 51
0
 /// <summary>
 /// Move the camera focus to this location instantly.
 /// </summary>
 /// <param name="point">Where you want the camera to focus.</param>
 public void focusOn(FlxPoint point)
 {
     point.X += (point.X > 0) ? 0.0000001f : -0.0000001f;
     point.Y += (point.Y > 0) ? 0.0000001f : -0.0000001f;
     Scroll.make(point.X - Width * 0.5f, point.Y - Height * 0.5f);
 }
Exemplo n.º 52
0
        /**
         * Shoots a ray from the start point to the end point.
         * If/when it passes through a tile, it stores that point and returns false.
         *
         * @param	Start		The world coordinates of the start of the ray.
         * @param	End			The world coordinates of the end of the ray.
         * @param	Result		A <code>Point</code> object containing the first wall impact.
         * @param	Resolution	Defaults to 1, meaning check every tile or so.  Higher means more checks!
         * @return	Returns true if the ray made it from Start to End without hitting anything.  Returns false and fills Result if a tile was hit.
         */
        public bool ray(FlxPoint Start, FlxPoint End, FlxPoint Result=null, float Resolution=1f)
        {
            float step = _tileWidth;
            if(_tileHeight < _tileWidth)
                step = _tileHeight;
            step /= Resolution;
            float deltaX = End.X - Start.X;
            float deltaY = End.Y - Start.Y;
            float distance = (float)Math.Sqrt(deltaX*deltaX + deltaY*deltaY);
            int steps = (int)FlxU.ceil(distance/step);
            float stepX = deltaX/steps;
            float stepY = deltaY/steps;
            float curX = Start.X - stepX - X;
            float curY = Start.Y - stepY - Y;
            int tileX;
            int tileY;
            int i = 0;
            while(i < steps)
            {
                curX += stepX;
                curY += stepY;

                if((curX < 0) || (curX > Width) || (curY < 0) || (curY > Height))
                {
                    i++;
                    continue;
                }

                tileX = (int)curX/_tileWidth;
                tileY = (int)curY/_tileHeight;
                if( Convert.ToBoolean((_tileObjects[_data[tileY*widthInTiles+tileX]] as FlxTile).AllowCollisions))
                {
                    //Some basic helper stuff
                    tileX *= _tileWidth;
                    tileY *= _tileHeight;
                    float rx = 0;
                    float ry = 0;
                    float q;
                    float lx = curX-stepX;
                    float ly = curY-stepY;

                    //Figure out if it crosses the X boundary
                    q = tileX;
                    if(deltaX < 0)
                        q += _tileWidth;
                    rx = q;
                    ry = ly + stepY*((q-lx)/stepX);
                    if((ry > tileY) && (ry < tileY + _tileHeight))
                    {
                        if(Result == null)
                            Result = new FlxPoint();
                        Result.X = rx;
                        Result.Y = ry;
                        return false;
                    }

                    //Else, figure out if it crosses the Y boundary
                    q = tileY;
                    if(deltaY < 0)
                        q += _tileHeight;
                    rx = lx + stepX*((q-ly)/stepY);
                    ry = q;
                    if((rx > tileX) && (rx < tileX + _tileWidth))
                    {
                        if(Result == null)
                            Result = new FlxPoint();
                        Result.X = rx;
                        Result.Y = ry;
                        return false;
                    }
                    return true;
                }
                i++;
            }
            return true;
        }
Exemplo n.º 53
0
 /// <summary>
 /// Helper function, just copies the values to the specified point.
 /// </summary>
 /// <param name="point">Any <code>FlxPoint</code>.</param>
 /// <returns>A reference to itself.</returns>
 public FlxPoint copyTo(FlxPoint point)
 {
     point.X = X;
     point.Y = Y;
     return(point);
 }
Exemplo n.º 54
0
 /// <summary>
 /// Override this function to null out variables or manually call
 /// <code>destroy()</code> on class members if necessary.
 /// Don't forget to call <code>super.destroy()</code>!
 /// </summary>
 public virtual void destroy()
 {
     Position = null;
 }
Exemplo n.º 55
0
        //*** NOTE: THESE LAST THREE FUNCTIONS REQUIRE FLXPOINT ***//

        /// <summary>
        /// Rotates a point in 2D space around another point by the given angle.
        /// </summary>
        /// <param name="x">The X coordinate of the point you want to rotate.</param>
        /// <param name="y">The Y coordinate of the point you want to rotate.</param>
        /// <param name="pivotX">The X coordinate of the point you want to rotate around.</param>
        /// <param name="pivotY">The Y coordinate of the point you want to rotate around.</param>
        /// <param name="angle">Rotate the point by this many degrees.</param>
        /// <param name="point">Optional <code>FlxPoint</code> to store the results in.</param>
        /// <returns>A <code>FlxPoint</code> containing the coordinates of the rotated point.</returns>
        static public FlxPoint rotatePoint(float x, float y, float pivotX, float pivotY, float angle, FlxPoint point = null)
        {
            float sin     = 0;
            float cos     = 0;
            float radians = angle * -0.017453293f;

            while (radians < -3.14159265)
            {
                radians += 6.28318531f;
            }

            while (radians > 3.14159265)
            {
                radians = radians - 6.28318531f;
            }

            if (radians < 0)
            {
                sin = 1.27323954f * radians + .405284735f * radians * radians;

                if (sin < 0)
                {
                    sin = .225f * (sin * -sin - sin) + sin;
                }
                else
                {
                    sin = .225f * (sin * sin - sin) + sin;
                }
            }
            else
            {
                sin = 1.27323954f * radians - 0.405284735f * radians * radians;

                if (sin < 0)
                {
                    sin = .225f * (sin * -sin - sin) + sin;
                }
                else
                {
                    sin = .225f * (sin * sin - sin) + sin;
                }
            }

            radians += 1.57079632f;
            if (radians > 3.14159265)
            {
                radians = radians - 6.28318531f;
            }

            if (radians < 0)
            {
                cos = 1.27323954f * radians + 0.405284735f * radians * radians;

                if (cos < 0)
                {
                    cos = .225f * (cos * -cos - cos) + cos;
                }
                else
                {
                    cos = .225f * (cos * cos - cos) + cos;
                }
            }
            else
            {
                cos = 1.27323954f * radians - 0.405284735f * radians * radians;

                if (cos < 0)
                {
                    cos = .225f * (cos * -cos - cos) + cos;
                }
                else
                {
                    cos = .225f * (cos * cos - cos) + cos;
                }
            }

            float dx = x - pivotX;
            float dy = pivotY + y; // Y axis is inverted in flash, normally this would be a subtract operation // flx# - Hmmmmm...

            if (point == null)
            {
                point = new FlxPoint();
            }
            point.X = pivotX + cos * dx - sin * dy;
            point.Y = pivotY - sin * dx - cos * dy;
            return(point);
        }
Exemplo n.º 56
0
		//Called by flixel to help clean up memory.
		 
		public override void destroy()
		{
			base.destroy();

			_player = null;
			_bullets = null;
			_gibs = null;

			_jets.destroy();
			_jets = null;

			_playerMidpoint = null;
		}
Exemplo n.º 57
0
 /// <summary>
 /// Sometimes its easier or faster to just pass a point object instead of separate X and Y coordinates.
 /// This also gives you the option of not creating a new node but actually adding that specific
 /// <code>FlxPoint</code> object to the path. This allows you to do neat things, like dynamic paths.
 /// </summary>
 /// <param name="node">The point in world coordinates you want to add to the path.</param>
 /// <param name="asReference">Whether to add the point as a reference, or to create a new point with the specified values.</param>
 public void AddPoint(FlxPoint node, bool asReference = false)
 {
     Nodes.Add(asReference ? node : new FlxPoint(node.X, node.Y));
 }