Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// Check and see if this object is currently on screen.
        /// Differs from <code>FlxObject</code>'s implementation
        /// in that it takes the actual graphic into account,
        /// not just the hitbox or bounding box or whatever.
        /// </summary>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns>Whether the object is on screen or not.</returns>
        override public bool onScreen(FlxCamera camera = null)
        {
            if (camera == null)
            {
                camera = FlxG.camera;
            }

            getScreenXY(_tagPoint, camera);
            _tagPoint.X = _tagPoint.X - Offset.X;
            _tagPoint.Y = _tagPoint.Y - Offset.Y;

            /*
             * if (((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1))
             *  return ((_point.x + frameWidth > 0) && (_point.x < Camera.width) && (_point.y + frameHeight > 0) && (_point.y < Camera.height));
             */

            float halfWidth  = FrameWidth / 2;
            float halfHeight = FrameHeight / 2;
            float absScaleX  = (Scale.X > 0) ? Scale.X : -Scale.X;
            float absScaleY  = (Scale.Y > 0) ? Scale.Y : -Scale.Y;
            float radius     = (float)Math.Sqrt((halfWidth * halfWidth) + (halfHeight * halfHeight)) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY);

            _tagPoint.X = _tagPoint.X + halfWidth;
            _tagPoint.Y = _tagPoint.Y + halfHeight;
            return((_tagPoint.X + radius > 0) && (_tagPoint.X - radius < camera.Width) && (_tagPoint.Y + radius > 0) && (_tagPoint.Y - radius < camera.Height));
        }
Beispiel #3
0
 public void follow(FlxCamera Camera = null, int Border = 0, Boolean UpdateWorld = false)
 {
     if (Camera == null)
     {
         Camera = FlxG.camera;
     }
     Camera.setBounds(X + Border * tileSize, Y + Border * tileSize, Width - Border * tileSize * 2, Height - Border * tileSize * 2, UpdateWorld);
 }
Beispiel #4
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);
             */
        }
Beispiel #5
0
        /**
         * Similar to <code>FlxObject</code>'s <code>drawDebug()</code>
         * functionality, this function calls <code>drawDebug()</code> on each
         * <code>FlxPath</code> for the specified camera. Very helpful for
         * debugging!
         *
         * @param Camera Which <code>FlxCamera</code> object to draw the debug data
         *        to.
         */
        public override void drawDebug(FlxCamera Camera = null)
        {
            if (Camera == null)
            {
                Camera = FlxG.camera;
            }

            int     i = _paths.Count() - 1;
            FlxPath path;

            while (i >= 0)
            {
                path = _paths.ElementAt(i--);
                if ((path != null) && !path.IgnoreDrawDebug)
                {
                    path.drawDebug(Camera);
                }
            }
        }
Beispiel #6
0
        /**
         * Called by <code>FlxG.drawPlugins()</code> after the game state has been
         * drawn. Cycles through cameras and calls <code>drawDebug()</code> on each
         * one.
         */

        public override void draw()
        {
            //FlxCamera camera = FlxG.getActiveCamera();
            FlxCamera camera = FlxG.camera;

            if (Cameras == null)
            {
                Cameras = FlxG.cameras;
            }

            if (!Cameras.Contains(camera))
            {
                return;
            }

            if (FlxG.visualDebug && !IgnoreDrawDebug)
            {
                drawDebug(camera);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Checks to see if some <code>FlxObject</code> overlaps this <code>FlxObject</code> or <code>FlxGroup</code>.
        /// If the group has a LOT of things in it, it might be faster to use <code>FlxG.overlaps()</code>.
        /// WARNING: Currently tilemaps do NOT support screen space overlap checks!
        /// </summary>
        /// <param name="objectOrGroup">The object or group being tested.</param>
        /// <param name="inScreenSpace">Whether to take scroll factors into account when checking for overlap.  Default is false, or "only compare in world space."</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 overlaps(FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = null)
        {
            if(objectOrGroup is FlxGroup)
            {
                bool results = false;
                var group = objectOrGroup as FlxGroup;
                foreach (FlxBasic member in group.Members)
                {
                    if (overlaps(member, inScreenSpace, camera))
                    {
                        results = true;
                        // flx# - we could break here, if overlaps does not trigger anything on the remaining members
                    }
                }

                /*
                int i = 0;
                List<FlxBasic> members = new List<FlxBasic>();
                members = (objectOrGroup as FlxGroup).members;
                //uint l = (uint)(ObjectOrGroup as FlxGroup).length;
                uint length = (uint)members.Count;
                while(i < length)
                {
                    if(overlaps(members[i++],inScreenSpace,camera))
                        results = true;
                }
                */

                return results;
            }

            if (objectOrGroup is FlxTilemap)
            {
                // Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
                // we redirect the call to the tilemap overlap here.
                return (objectOrGroup as FlxTilemap).overlaps(this, inScreenSpace, camera);
            }

            var flxObject = objectOrGroup as FlxObject;

            if(!inScreenSpace)
            {
                return (flxObject.X + flxObject.Width > X) && (flxObject.X < X + Width) &&
                       (flxObject.Y + flxObject.Height > Y) && (flxObject.Y < Y + Height);
            }

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

            FlxPoint objectScreenPos = flxObject.getScreenXY(null, camera);
            getScreenXY(_tagPoint, camera);
            return (objectScreenPos.X + flxObject.Width > _tagPoint.X) && (objectScreenPos.X < _tagPoint.X + Width) &&
                   (objectScreenPos.Y + flxObject.Height > _tagPoint.Y) && (objectScreenPos.Y < _tagPoint.Y + Height);
        }
Beispiel #8
0
        /// <summary>
        /// Check and see if this object is currently on screen.
        /// </summary>
        /// <param name="camera">Specify which game camera you want. If null getScreenXY() will just grab the first global camera.</param>
        /// <returns>bool</returns>
        public virtual bool onScreen(FlxCamera camera = null)
        {
            if (camera == null)
            {
                camera = FlxG.camera;
            }

            getScreenXY(_tagPoint,camera);
            return (_tagPoint.X + Width > 0) && (_tagPoint.X < camera.Width) && (_tagPoint.Y + Height > 0) && (_tagPoint.Y < camera.Height);
        }
Beispiel #9
0
        /// <summary>
        /// Add a new camera object to the game.
        /// Handy for PiP, split-screen, etc.
        /// </summary>
        /// <param name="newCamera">The camera you want to add.</param>
        /// <returns>This <code>FlxCamera</code> instance.</returns>
        public static FlxCamera addCamera(FlxCamera newCamera)
        {
            FlxG.cameras.Add(newCamera);

            var newViewport = new Viewport((int)newCamera.X, (int)newCamera.Y, (int)newCamera.Width, (int)newCamera.Height);
            FlxS.Viewports.Add(newViewport);

            //FlxG.log("camera is at x: " + newCamera.X + " y: " + newCamera.Y + " width: " + newCamera.Width + " height " + newCamera.Height);
            //FlxG.log("camera count: " + FlxG.cameras.Count);

            return newCamera;

            /*
            FlxG._game.addChildAt(NewCamera._flashSprite,FlxG._game.getChildIndex(FlxG._game._mouse));
            FlxG.cameras.push(NewCamera);
            return NewCamera;
            */
        }
Beispiel #10
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);
        }
Beispiel #11
0
 protected void drawTilemap(FlxCamera Camera)
 {
     //no need because draw() actually renders the tilemap
 }
Beispiel #12
0
        /// <summary>
        /// Check and see if this object is currently on screen.
        /// Differs from <code>FlxObject</code>'s implementation
        /// in that it takes the actual graphic into account,
        /// not just the hitbox or bounding box or whatever.
        /// </summary>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns>Whether the object is on screen or not.</returns>
        public override bool onScreen(FlxCamera camera = null)
        {
            if (camera == null)
            {
                camera = FlxG.camera;
            }

            getScreenXY(_tagPoint, camera);
            _tagPoint.X = _tagPoint.X - Offset.X;
            _tagPoint.Y = _tagPoint.Y - Offset.Y;

            /*
            if (((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1))
                return ((_point.x + frameWidth > 0) && (_point.x < Camera.width) && (_point.y + frameHeight > 0) && (_point.y < Camera.height));
            */

            float halfWidth = FrameWidth / 2;
            float halfHeight = FrameHeight / 2;
            float absScaleX = (Scale.X > 0) ? Scale.X : -Scale.X;
            float absScaleY = (Scale.Y > 0) ? Scale.Y : -Scale.Y;
            float radius = (float)Math.Sqrt((halfWidth * halfWidth) + (halfHeight * halfHeight)) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY);
            _tagPoint.X = _tagPoint.X + halfWidth;
            _tagPoint.Y = _tagPoint.Y + halfHeight;
            return ((_tagPoint.X + radius > 0) && (_tagPoint.X - radius < camera.Width) && (_tagPoint.Y + radius > 0) && (_tagPoint.Y - radius < camera.Height));
        }
Beispiel #13
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;
        }
Beispiel #14
0
 protected void drawTilemap(FlxCamera Camera)
 {
     //no need because draw() actually renders the tilemap
 }
Beispiel #15
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;
        }
Beispiel #16
0
 // findPath
 // simplifyPath
 // raySimplifyPath
 // computePathDistance
 // walkPath
 public override Boolean overlaps(FlxBasic objectOrGroup, Boolean inScreenSpace = false, FlxCamera camera = null)
 {
     if (objectOrGroup is FlxGroup)
     {
         Boolean results = false;
         FlxBasic basic;
         int i = 0;
         List<FlxBasic> members = new List<FlxBasic>();
         members = (objectOrGroup as FlxGroup).Members;
         while (i < members.Count)
         {
             basic = members[i++] as FlxBasic;
             if (basic is FlxObject)
             {
                 if (overlapsWithCallback(basic as FlxObject))
                     results = true;
             }
             else
             {
                 if (overlaps(basic, inScreenSpace, camera))
                     results = true;
             }
         }
         return results;
     }
     else if (objectOrGroup is FlxObject)
     {
         return overlapsWithCallback(objectOrGroup as FlxObject);
     }
     return false;
 }
Beispiel #17
0
 public void follow(FlxCamera Camera = null, int Border = 0, Boolean UpdateWorld = false)
 {
     if (Camera == null)
         Camera = FlxG.camera;
     Camera.setBounds(X + Border * tileSize, Y + Border * tileSize, Width - Border * tileSize * 2, Height - Border * tileSize * 2, UpdateWorld);
 }
Beispiel #18
0
        /// <summary>
        /// Dumps all the current cameras and resets to just one camera.
        /// Handy for doing split-screen especially.
        /// </summary>
        /// <param name="newCamera">Optional; specify a specific camera object to be the new main camera.</param>
        public static void resetCameras(FlxCamera newCamera = null)
        {
            foreach (FlxCamera flxCam in cameras)
            {
                flxCam.destroy();
            }

            cameras.Clear();

            FlxS.Viewports.Clear ();

            if (newCamera == null)
            {
                newCamera = new FlxCamera(0, 0, FlxG.width, FlxG.height);
            }

            FlxG.addCamera(newCamera);
            FlxG.camera = newCamera;
        }
Beispiel #19
0
        /// <summary>
        /// Remove a camera from the game.
        /// </summary>
        /// <param name="camera">The camera you want to remove.</param>
        /// <param name="destroy">Whether to call destroy() on the camera, default value is true.</param>
        public static void removeCamera(FlxCamera camera, bool destroy = true)
        {
            throw new NotImplementedException();

            /*
            try
            {
                FlxG._game.removeChild(Camera._flashSprite);
            }
            catch(E:Error)
            {
                FlxG.log("Error removing camera, not part of game.");
            }
            if(Destroy)
                Camera.destroy();
            */
        }
Beispiel #20
0
        /// <summary>
        /// Checks to see if this <code>FlxObject</code> were located at the given position, would it overlap the <code>FlxObject</code> or <code>FlxGroup</code>?
        /// This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size into account.
        /// WARNING: Currently tilemaps do NOT support screen space overlap checks!
        /// </summary>
        /// <param name="x">The X position you want to check. Pretends this object (the caller, not the parameter) is located here.</param>
        /// <param name="y">The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.</param>
        /// <param name="objectOrGroup">The object or group being tested.</param>
        /// <param name="inScreenSpace">Whether to take scroll factors into account when checking for overlap.  Default is false, or "only compare in world space."</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 overlapsAt(float x, float y, FlxBasic objectOrGroup, bool inScreenSpace = false, FlxCamera camera = null)
        {
            if (objectOrGroup is FlxGroup)
            {
                bool results = false;
                var group = objectOrGroup as FlxGroup;
                foreach (FlxBasic member in group.Members)
                {
                    if (overlapsAt(x, y, member, inScreenSpace, camera))
                    {
                        results = true;
                        // flx# - we could break here, if overlaps does not trigger anything on the remaining members
                    }
                }

                /*
                int i = 0;List<FlxBasic> members = new List<FlxBasic>();
                members = (objectOrGroup as FlxGroup).members;
                uint length = (uint)members.Count;
                while (i < length)
                {
                        if (overlapsAt(x, y, members[i++], inScreenSpace, camera))
                            results = true;
                }
                */
                return results;
            }

            if (objectOrGroup is FlxTilemap)
            {
                var tilemap = objectOrGroup as FlxTilemap;
                return tilemap.overlapsAt(tilemap.X - (x - this.X), tilemap.Y - (y - this.Y), this, inScreenSpace, camera);
            }

            var flxObject = objectOrGroup as FlxObject;

            if(!inScreenSpace)
            {
                return (flxObject.X + flxObject.Width > x) && (flxObject.X < x + Width) &&
                       (flxObject.Y + flxObject.Height > y) && (flxObject.Y < y + Height);
            }

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

            FlxPoint objectScreenPos = flxObject.getScreenXY(null, camera);
            _tagPoint.X = x - camera.Scroll.X * ScrollFactor.X; //copied from getScreenXY()
            _tagPoint.Y = y - camera.Scroll.Y * ScrollFactor.Y;
            _tagPoint.X += (_tagPoint.X > 0) ? 0.0000001f : -0.0000001f;
            _tagPoint.Y += (_tagPoint.Y > 0) ? 0.0000001f : -0.0000001f;

            return (objectScreenPos.X + flxObject.Width > _tagPoint.X) && (objectScreenPos.X < _tagPoint.X + Width) &&
                   (objectScreenPos.Y + flxObject.Height > _tagPoint.Y) && (objectScreenPos.Y < _tagPoint.Y + Height);
        }
Beispiel #21
0
 /// <summary>
 /// Override this function to draw custom "debug mode" graphics to the
 /// specified camera while the debugger's visual mode is toggled on.
 /// </summary>
 /// <param name="camera">Which camera to draw the debug visuals to.</param>
 public virtual void drawDebug(FlxCamera camera = null)
 {
 }
Beispiel #22
0
        /**
         * Similar to <code>FlxObject</code>'s <code>drawDebug()</code>
         * functionality, this function calls <code>drawDebug()</code> on each
         * <code>FlxPath</code> for the specified camera. Very helpful for
         * debugging!
         *
         * @param Camera Which <code>FlxCamera</code> object to draw the debug data
         *        to.
         */
        public override void drawDebug(FlxCamera Camera = null)
        {
            if(Camera == null)
                Camera = FlxG.camera;

            int i = _paths.Count() - 1;
            FlxPath path;
            while(i >= 0)
            {
                path = _paths.ElementAt(i--);
                if((path != null) && !path.IgnoreDrawDebug)
                    path.drawDebug(Camera);
            }
        }
Beispiel #23
0
        /// <summary>
        /// While this doesn't override <code>FlxBasic.DrawDebug()</code>, the behavior is very similar.
        /// Based on this path data, it draws a simple lines-and-boxes representation of the path
        /// if the visual debug mode was toggled in the debugger overlay. You can use <code>DebugColor</code>
        /// and <code>DebugScrollFactor</code> to control the path's appearance.
        /// </summary>
        /// <param name="camera">The camera object the path will draw to.</param>
        public void drawDebug(FlxCamera camera)
        {
            throw new NotImplementedException();

            /*
            if(nodes.length <= 0)
                return;
            if(Camera == null)
                Camera = FlxG.camera;

            //Set up our global flash graphics object to draw out the path
            var gfx:Graphics = FlxG.flashGfx;
            gfx.clear();

            //Then fill up the object with node and path graphics
            var node:FlxPoint;
            var nextNode:FlxPoint;
            var i:uint = 0;
            var l:uint = nodes.length;
            while(i < l)
            {
                //get a reference to the current node
                node = nodes[i] as FlxPoint;

                //find the screen position of the node on this camera
                _point.x = node.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
                _point.y = node.y - int(Camera.scroll.y*debugScrollFactor.y);
                _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
                _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));

                //decide what color this node should be
                var nodeSize:uint = 2;
                if((i == 0) || (i == l-1))
                    nodeSize *= 2;
                var nodeColor:uint = debugColor;
                if(l > 1)
                {
                    if(i == 0)
                        nodeColor = FlxG.GREEN;
                    else if(i == l-1)
                        nodeColor = FlxG.RED;
                }

                //draw a box for the node
                gfx.beginFill(nodeColor,0.5);
                gfx.lineStyle();
                gfx.drawRect(_point.x-nodeSize*0.5,_point.y-nodeSize*0.5,nodeSize,nodeSize);
                gfx.endFill();

                //then find the next node in the path
                var linealpha:Number = 0.3;
                if(i < l-1)
                    nextNode = nodes[i+1];
                else
                {
                    nextNode = nodes[0];
                    linealpha = 0.15;
                }

                //then draw a line to the next node
                gfx.moveTo(_point.x,_point.y);
                gfx.lineStyle(1,debugColor,linealpha);
                _point.x = nextNode.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
                _point.y = nextNode.y - int(Camera.scroll.y*debugScrollFactor.y);
                _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
                _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
                gfx.lineTo(_point.x,_point.y);

                i++;
            }

            //then stamp the path down onto the game buffer
            Camera.buffer.draw(FlxG.flashGfxSprite);
            */
        }
		//Just plops down a spawner and some blocks - haphazard and crappy atm but functional!
		protected void buildRoom(int RX,int RY,bool Spawners)
		{
			//first place the spawn point (if necessary)
			int rw = 20;
			int sx = 0;
			int sy = 0;
			if(Spawners)
			{
				sx = (int) (2+FlxG.random()*(rw-7));
				sy = (int) (2+FlxG.random()*(rw-7));
			}

			//then place a bunch of blocks
			int numBlocks = (int) (3+FlxG.random()*4);
			if(!Spawners) numBlocks++;
			int maxW = 10;
			int minW = 2;
			int maxH = 8;
			int minH = 1;
			int bx;
			int by;
			int bw;
			int bh;
			bool check;
			for(int i = 0; i < numBlocks; i++)
			{
				do
				{
					//keep generating different specs if they overlap the spawner
					bw = (int) (minW + FlxG.random()*(maxW-minW));
					bh = (int) (minH + FlxG.random()*(maxH-minH));
					bx = (int) (-1 + FlxG.random()*(rw+1-bw));
					by = (int) (-1 + FlxG.random()*(rw+1-bh));
					if(Spawners)
						check = ((sx>bx+bw) || (sx+3<bx) || (sy>by+bh) || (sy+3<by));
					else
						check = true;
				} while(!check);

				FlxTileblock b;
				b = new FlxTileblock(RX+bx*8,RY+by*8,bw*8,bh*8);
				b.loadTiles(ImgTech);
				_blocks.add(b);

				//If the block has room, add some non-colliding "dirt" graphics for variety
				if((bw >= 4) && (bh >= 5))
				{
					b = new FlxTileblock(RX+bx*8+8,RY+by*8,bw*8-16,8);
					b.loadTiles(ImgDirtTop);
					_decorations.add(b);

					b = new FlxTileblock(RX+bx*8+8,RY+by*8+8,bw*8-16,bh*8-24);
					b.loadTiles(ImgDirt);
					_decorations.add(b);
				}
			}

			if(Spawners)
			{
				//Finally actually add the spawner
				Spawner sp = new Spawner(RX+sx*8,RY+sy*8,_bigGibs,_enemies,_enemyBullets,_littleGibs,_player); 
				_spawners.add(sp);

				//Then create a dedicated camera to watch the spawner
				_hud.add(new FlxSprite(3 + (_spawners.length-1)*16, 3, ImgMiniFrame));
				FlxCamera camera = new FlxCamera(10 + (_spawners.length-1)*32,10,24,24,1);
				camera.follow(sp);
				FlxG.addCamera(camera);
			}
		}
Beispiel #25
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);
            */
        }
		public override void create()
		{
			FlxG.Framerate = 50;
			//FlxG.FlashFramerate = 50;

			// set the background color to white
			FlxG.bgColor = FlxColor.WHITE;

			//Setup the level (40 x 40 tiles) Addapted from Adam Atomic's EZPlatformer
			int[] levelData = {
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 1, 1, 1, 0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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

			// Create the tilemap from the levelData we just created
			level = new FlxTilemap();
			level.loadMap(FlxTilemap.arrayToCSV(levelData, 40), FlxTilemap.ImgAuto,0,0,FlxTilemap.AUTO);
			add(level);

			//Create the two players
			player1 = new FlxSprite(65, 200).makeGraphic(10,12, FlxColor.RED); //player 1 is red and starts at 65, 200
			player1.MaxVelocity.X = 80;   // Theses are pysics settings,
			player1.MaxVelocity.Y = 200;  // controling how the players behave
			player1.Acceleration.Y = 200; // in the game
			player1.Drag.X = player1.MaxVelocity.X*4;
			add(player1);

			player2 = new FlxSprite(265, 200).makeGraphic(10,12, FlxColor.BLUE); // player2 is blue and starts at 265, 200
			player2.MaxVelocity.X = 80; // Same thing than player 1
			player2.MaxVelocity.Y = 200;
			player2.Acceleration.Y = 200;
			player2.Drag.X = player2.MaxVelocity.X*4;
			add(player2);

			// Then we setup two cameras to follow each of the two players

			FlxCamera cam = new FlxCamera(0,0, FlxG.width/2, FlxG.height); // we put the first one in the top left corner
			cam.follow(player2);
			// this sets the limits of where the camera goes so that it doesn't show what's outside of the tilemap
			cam.setBounds(0,0,level.Width, level.Height);
			cam.Color = FlxColor.PINK; // add a light red tint to the camera to differentiate it from the other
			FlxG.resetCameras (cam);

			// Almost the same thing as the first camera
			cam = new FlxCamera(FlxG.width/2,0, FlxG.width/2, FlxG.height);    // and the second one in the top middle of the screen
			cam.follow(player1);
			cam.setBounds(0,0,level.Width, level.Height);
			cam.Color = FlxColor.CADETBLUE; // Add a light blue tint to the camera
			FlxG.addCamera(cam);
		}
Beispiel #27
0
        // findPath

        // simplifyPath

        // raySimplifyPath

        // computePathDistance

        // walkPath

        override public Boolean overlaps(FlxBasic objectOrGroup, Boolean inScreenSpace = false, FlxCamera camera = null)
        {
            if (objectOrGroup is FlxGroup)
            {
                Boolean         results = false;
                FlxBasic        basic;
                int             i       = 0;
                List <FlxBasic> members = new List <FlxBasic>();
                members = (objectOrGroup as FlxGroup).Members;
                while (i < members.Count)
                {
                    basic = members[i++] as FlxBasic;
                    if (basic is FlxObject)
                    {
                        if (overlapsWithCallback(basic as FlxObject))
                        {
                            results = true;
                        }
                    }
                    else
                    {
                        if (overlaps(basic, inScreenSpace, camera))
                        {
                            results = true;
                        }
                    }
                }
                return(results);
            }
            else if (objectOrGroup is FlxObject)
            {
                return(overlapsWithCallback(objectOrGroup as FlxObject));
            }
            return(false);
        }
Beispiel #28
0
        /// <summary>
        /// While this doesn't override <code>FlxBasic.DrawDebug()</code>, the behavior is very similar.
        /// Based on this path data, it draws a simple lines-and-boxes representation of the path
        /// if the visual debug mode was toggled in the debugger overlay. You can use <code>DebugColor</code>
        /// and <code>DebugScrollFactor</code> to control the path's appearance.
        /// </summary>
        /// <param name="camera">The camera object the path will draw to.</param>
        public void drawDebug(FlxCamera camera)
        {
            throw new NotImplementedException();

            /*
             *          if(nodes.length <= 0)
             *                  return;
             *          if(Camera == null)
             *                  Camera = FlxG.camera;
             *
             *          //Set up our global flash graphics object to draw out the path
             *          var gfx:Graphics = FlxG.flashGfx;
             *          gfx.clear();
             *
             *          //Then fill up the object with node and path graphics
             *          var node:FlxPoint;
             *          var nextNode:FlxPoint;
             *          var i:uint = 0;
             *          var l:uint = nodes.length;
             *          while(i < l)
             *          {
             *                  //get a reference to the current node
             *                  node = nodes[i] as FlxPoint;
             *
             *                  //find the screen position of the node on this camera
             *                  _point.x = node.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
             *                  _point.y = node.y - int(Camera.scroll.y*debugScrollFactor.y);
             *                  _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
             *                  _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
             *
             *                  //decide what color this node should be
             *                  var nodeSize:uint = 2;
             *                  if((i == 0) || (i == l-1))
             *                          nodeSize *= 2;
             *                  var nodeColor:uint = debugColor;
             *                  if(l > 1)
             *                  {
             *                          if(i == 0)
             *                                  nodeColor = FlxG.GREEN;
             *                          else if(i == l-1)
             *                                  nodeColor = FlxG.RED;
             *                  }
             *
             *                  //draw a box for the node
             *                  gfx.beginFill(nodeColor,0.5);
             *                  gfx.lineStyle();
             *                  gfx.drawRect(_point.x-nodeSize*0.5,_point.y-nodeSize*0.5,nodeSize,nodeSize);
             *                  gfx.endFill();
             *
             *                  //then find the next node in the path
             *                  var linealpha:Number = 0.3;
             *                  if(i < l-1)
             *                          nextNode = nodes[i+1];
             *                  else
             *                  {
             *                          nextNode = nodes[0];
             *                          linealpha = 0.15;
             *                  }
             *
             *                  //then draw a line to the next node
             *                  gfx.moveTo(_point.x,_point.y);
             *                  gfx.lineStyle(1,debugColor,linealpha);
             *                  _point.x = nextNode.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
             *                  _point.y = nextNode.y - int(Camera.scroll.y*debugScrollFactor.y);
             *                  _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
             *                  _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
             *                  gfx.lineTo(_point.x,_point.y);
             *
             *                  i++;
             *          }
             *
             *          //then stamp the path down onto the game buffer
             *          Camera.buffer.draw(FlxG.flashGfxSprite);
             */
        }
Beispiel #29
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);
        }
Beispiel #30
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();
        }
Beispiel #31
0
        /// <summary>
        /// #flx - Not yet implemented / missing FlxG.flashGfx for direct drawing (draw on immovable debug overlay?)
        /// </summary>
        /// <param name="Camera">Which Camera - currently only one exists</param>
        public override void drawDebug(FlxCamera Camera=null)
        {
            //throw new NotImplementedException();

            if(Camera == null)
                Camera = FlxG.camera;

            //get bounding box coordinates
            float boundingBoxX = X - (int)(Camera.Scroll.X*ScrollFactor.X); //copied from getScreenXY()
            float boundingBoxY = Y - (int)(Camera.Scroll.Y*ScrollFactor.Y);
            boundingBoxX = (int)(boundingBoxX + ((boundingBoxX > 0)?0.0000001f:-0.0000001f));
            boundingBoxY = (int)(boundingBoxY + ((boundingBoxY > 0)?0.0000001f:-0.0000001f));
            int boundingBoxWidth = (int)((Width != (int)(Width)) ? Width : Width - 1f);
            int boundingBoxHeight = (int)((Height != (int)(Height)) ?Height : Height - 1f);

            ////fill static graphics object with square shape
            //var gfx:Graphics = FlxG.flashGfx;
            //gfx.clear();
            //gfx.moveTo(boundingBoxX,boundingBoxY);
            Color boundingBoxColor;
            if(Convert.ToBoolean(AllowCollisions))
            {
                if(AllowCollisions != Any)
                    boundingBoxColor = FlxColor.PINK;
                if(Immovable)
                    boundingBoxColor = FlxColor.GREEN;
                else
                    boundingBoxColor = FlxColor.RED;
            }
            else
                boundingBoxColor = FlxColor.BLUE;
            //gfx.lineStyle(1,boundingBoxColor,0.5);
            //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY);
            //gfx.lineTo(boundingBoxX+boundingBoxWidth,boundingBoxY+boundingBoxHeight);
            //gfx.lineTo(boundingBoxX,boundingBoxY+boundingBoxHeight);
            //gfx.lineTo(boundingBoxX,boundingBoxY);

            ////draw graphics shape to camera buffer
            //Camera.buffer.draw(FlxG.flashGfxSprite);
        }
Beispiel #32
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;
        }
Beispiel #33
0
 /// <summary>
 /// Override this function to draw custom "debug mode" graphics to the
 /// specified camera while the debugger's visual mode is toggled on.
 /// </summary>
 /// <param name="camera">Which camera to draw the debug visuals to.</param>
 public virtual void drawDebug(FlxCamera camera = null)
 {
 }
Beispiel #34
0
        public override void draw()
        {
            if (_flickerTimer != 0)
            {
                _flicker = !_flicker;
                if (_flicker)
                {
                    return;
                }
            }

            FlxCamera camera = FlxG.camera;            //._activeCamera;

            if (Cameras == null)
            {
                Cameras = FlxG.cameras;
            }

            if (!Cameras.Contains(camera))
            {
                return;
            }

            if (!onScreen(camera))
            {
                return;
            }

            _tagPoint.X  = X - (camera.Scroll.X * ScrollFactor.X) - Offset.X;
            _tagPoint.Y  = Y - (camera.Scroll.Y * ScrollFactor.Y) - Offset.Y;
            _tagPoint.X += (_tagPoint.X > 0) ? 0.0000001f : -0.0000001f;
            _tagPoint.Y += (_tagPoint.Y > 0) ? 0.0000001f : -0.0000001f;

            // scaling
            if (Scale.X != 1f || Scale.Y != 1f)
            {
                //_textField.getFont().setScale(Scale.X, Scale.Y);
                calcFrame();
            }

            // position
            //_textField.setPosition(_tagPoint.X, _tagPoint.Y);

            // rotation
            if (Angle != 0)
            {
                /*
                 * _matrix = FlxG.Batch.getTransformMatrix().cpy();
                 *
                 * Matrix4 rotationMatrix = FlxG.batch.getTransformMatrix();
                 * rotationMatrix.translate(_textField.getX() + (width / 2), _textField.getY() + (height / 2), 0);
                 * rotationMatrix.rotate(0, 0, 1, angle);
                 * rotationMatrix.translate(-(_textField.getX() + (width / 2)), -(_textField.getY() + (height / 2)), 0);
                 *
                 * FlxG.batch.setTransformMatrix(rotationMatrix);
                 */
            }

            /*
             * // blending
             * if(blend != null && currentBlend != blend)
             * {
             *      int[] blendFunc = BlendMode.getOpenGLBlendMode(blend);
             *      FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]);
             * }
             * else if(FlxG.batchShader == null || ignoreBatchShader)
             * {
             *      // OpenGL ES 2.0 shader render
             *      renderShader();
             *      // OpenGL ES 2.0 blend mode render
             *      renderBlend();
             * }
             */

            // distance field
            if (_distanceFieldEnabled)
            {
                drawDistanceField();
            }

            int tintColor;

            /*
             * // Render shadow behind the text
             * if(_shadow != 0)
             * {
             *      // tinting
             *      tintColor = FlxU.multiplyColors(_shadow, camera.getColor());
             *      _textField.setColors(((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, ((_shadow >> 24) & 0xFF) * _alpha
             * 0.00392f);
             *      _textField.translate(_shadowX, _shadowY);
             *      _textField.draw(FlxG.batch);
             *      _textField.translate(-_shadowX, -_shadowY);
             * }
             *
             * // tinting
             * tintColor = FlxU.multiplyColors(_color, camera.getColor());
             * _textField.setColors(((tintColor >> 16) & 0xFF) * 0.00392f, ((tintColor >> 8) & 0xFF) * 0.00392f, (tintColor & 0xFF) * 0.00392f, _alpha);
             *
             * _textField.draw(FlxG.batch);
             *
             * // turn off distance field
             * if(_distanceFieldEnabled)
             *      FlxG.batch.setShader(null);
             *
             * // rotation
             * if(Angle != 0)
             *      FlxG.batch.setTransformMatrix(_matrix);
             *
             * _VISIBLECOUNT++;
             *
             * if(FlxG.visualDebug && !ignoreDrawDebug)
             *      drawDebug(camera);
             */

            Point   point = bounds.Center;
            Vector2 pos   = new Vector2(point.X, point.Y);

            if (_alignment == "RIGHT")
            {
                pos.X += Width - textWidth;
            }

            if (_alignment == "CENTER")
            {
                pos.X += ((Width - textWidth) / 2);
            }
            pos.Y += ((Height - textHeight) / 2);

            // Render shadow behind the text
            if (_shadow != Color.Transparent)
            {
                FlxS.SpriteBatch.DrawString(LoadedFont, text, new Vector2(pos.X + _shadowX, pos.Y + _shadowY), _shadow, 0, origin, _size / _default_size, SpriteEffects.None, 0);
            }

            FlxS.SpriteBatch.DrawString(LoadedFont, text, pos, Color, 0, origin, _size / _default_size, SpriteEffects.None, 0);
        }