Пример #1
0
 public override void hitBottom(FlxObject Contact, float Velocity)
 {
     if(velocity.Y > 50)
         FlxG.play(SndLand);
     onFloor = true;
     base.hitBottom(Contact,Velocity);
 }
Пример #2
0
 public FlxObject add(FlxObject Object, bool ShareScroll)
 {
     if (members.IndexOf(Object) < 0)
         members.Add(Object);
         //members[members.Count] = Object;
     if(ShareScroll)
         Object.scrollFactor = scrollFactor;
     return Object;
 }
Пример #3
0
 /**
  * Call this function to see if one <code>FlxObject</code> collides with another.
  * Can be called with one object and one group, or two groups, or two objects,
  * whatever floats your boat!  It will put everything into a quad tree and then
  * check for collisions.  For maximum performance try bundling a lot of objects
  * together using a <code>FlxGroup</code> (even bundling groups together!)
  * NOTE: does NOT take objects' scrollfactor into account.
  *
  * @param	Object1		The first object or group you want to check.
  * @param	Object2		The second object or group you want to check.  If it is the same as the first, flixel knows to just do a comparison within that group.
  */
 public static bool collide(FlxObject Object1, FlxObject Object2)
 {
     if( (Object1 == null) || !Object1.exists ||
         (Object2 == null) || !Object2.exists )
         return false;
     quadTree = new FlxQuadTree(FlxQuadTree.bounds.x,FlxQuadTree.bounds.y,FlxQuadTree.bounds.width,FlxQuadTree.bounds.height,null);
     quadTree.add(Object1,FlxQuadTree.A_LIST);
     bool match = Object1 == Object2;
     if(!match)
         quadTree.add(Object2,FlxQuadTree.B_LIST);
     bool cx = quadTree.overlap(!match,solveXCollision);
     bool cy = quadTree.overlap(!match,solveYCollision);
     return cx || cy;
 }
Пример #4
0
 public override void hitBottom(FlxObject Contact, float Velocity)
 {
     onFloor = true;
     if(((velocity.Y > 0)?velocity.Y:-velocity.Y) > _bounce*100)
     {
         velocity.Y = -velocity.Y * _bounce;
         if(angularVelocity != 0)
             angularVelocity *= -_bounce;
     }
     else
     {
         angularVelocity = 0;
         base.hitBottom(Contact,Velocity);
     }
     velocity.X *= _bounce;
 }
Пример #5
0
 //@desc		Adds a new FlxCore subclass (FlxSprite, FlxBlock, etc) to the game loop
 //@param	Core	The object you want to add to the game loop
 public virtual FlxObject add(FlxObject Core)
 {
     return defaultGroup.add(Core);
 }
Пример #6
0
 /// <summary>
 /// Called when the sprite hits something on its side, either left or right.
 /// </summary>
 /// <param name="Contact"></param>
 /// <param name="Velocity"></param>
 public override void hitSide(FlxObject Contact, float Velocity)
 {
     base.hitSide(Contact, Velocity);
 }
Пример #7
0
        /**
         * <code>FlxU.collide()</code> (and thus <code>FlxObject.collide()</code>) call
         * this function each time two objects are compared to see if they collide.
         * It doesn't necessarily mean these objects WILL collide, however.
         *
         * @param	Object	The <code>FlxObject</code> you're about to run into.
         */
        public override void preCollide(FlxObject Object)
        {
            //Collision fix, in case updateMotion() is called
            colHullX.x = 0;
            colHullX.y = 0;
            colHullY.x = 0;
            colHullY.y = 0;

            int r;
            int c;
            int rs;
            int ix = (int)FlxU.floor((Object.x - x)/_tileWidth);
            int iy = (int)FlxU.floor((Object.y - y)/_tileHeight);
            int iw = ix + (int)FlxU.ceil((float)Object.width / (float)_tileWidth) + 1;
            int ih = iy + (int)FlxU.ceil((float)Object.height / (float)_tileHeight) + 1;
            if(ix < 0)
                ix = 0;
            if(iy < 0)
                iy = 0;
            if(iw > widthInTiles)
                iw = widthInTiles;
            if(ih > heightInTiles)
                ih = heightInTiles;
            rs = iy*widthInTiles;
            r = iy;
            colOffsets.Clear();
            while(r < ih)
            {
                c = ix;
                while(c < iw)
                {
                    if (_data[rs + c] >= collideIndex)
                    {
                        colOffsets.Add(new Vector2(x + c * _tileWidth, y + r * _tileHeight));
                    }
                    c++;
                }
                rs += widthInTiles;
                r++;
            }
        }
Пример #8
0
        /**
         * The tilemap constructor just initializes some basic variables.
         */
        public FlxTilemap()
        {
            if (ImgAuto == null || ImgAutoAlt == null)
            {
                ImgAuto = FlxG.Content.Load<Texture2D>("flixel/autotiles");
                ImgAutoAlt = FlxG.Content.Load<Texture2D>("flixel/autotiles_alt");
            }

            auto = OFF;
            collideIndex = 1;
            startingIndex = 0;
            drawIndex = 1;
            widthInTiles = 0;
            heightInTiles = 0;
            totalTiles = 0;
            _flashRect2 = new Rectangle();
            _flashRect = _flashRect2;
            _data = null;
            _tileWidth = 0;
            _tileHeight = 0;
            _rects = null;
            _block = new FlxObject();
            _block.width = _block.height = 0;
            _block.@fixed = true;
            //_callbacks = new Array();
            @fixed = true;
            moves = false;
        }
Пример #9
0
        //@desc		Tells the camera subsystem what FlxCore object to follow
        //@param	Target		The object to follow
        //@param	Lerp		How much lag the camera should have (can help smooth out the camera movement)
        public static void follow(FlxObject Target, float Lerp)
        {
            followTarget = Target;
            followLerp = Lerp;

            if (Target == null)
                return;

            scroll.X = _scrollTarget.X = (width >> 1) - followTarget.x - ((int)followTarget.width >> 1);
            scroll.Y = _scrollTarget.Y = (height >> 1) - followTarget.y - ((int)followTarget.height >> 1);
        }
Пример #10
0
 /**
  * Replaces an existing <code>FlxObject</code> with a new one.
  *
  * @param	OldObject	The object you want to replace.
  * @param	NewObject	The new object you want to use instead.
  *
  * @return	The new object.
  */
 public FlxObject replace(FlxObject OldObject, FlxObject NewObject)
 {
     int index = members.IndexOf(OldObject);
     if((index < 0) || (index >= members.Count))
         return null;
     members[index] = NewObject;
     return NewObject;
 }
Пример #11
0
        /// <summary>
        /// Called when the sprite hits something on its left side.
        /// </summary>
        /// <param name="Contact">The Object that it collided with.</param>
        /// <param name="Velocity"></param>
        public override void hitLeft(FlxObject Contact, float Velocity)
        {
            Console.WriteLine("HITLEFT - Score: " + FlxG.score.ToString() + " " + Velocity);

            if (y <= Globals.diveHeight - height / 2)
            {
                play("exitWater");
                mode = "exitWater";

                acceleration.X = 0;
                acceleration.Y = 0;
                velocity.X = 0;
                velocity.Y = 0;
                setDrags(25, 25);
            }
            else
            {
                x += 3;

                acceleration.X = 0;
                acceleration.Y = 0;
                velocity.X = 0;
                velocity.Y = 0;
                setDrags(25, 25);

                mode = "deadFloat";
                play("hitFloor");

                Globals.addScore(-1000000, "Hit head on side");
            }

            dead = true;

            base.hitLeft(Contact, Velocity);
        }
Пример #12
0
 /**
  * Called when this object's right side collides with another <code>FlxObject</code>'s left.
  * NOTE: by default this function just calls <code>hitSide()</code>.
  *
  * @param	Contact		The <code>FlxObject</code> you just ran into.
  * @param	Velocity	The suggested new velocity for this object.
  */
 public virtual void hitRight(FlxObject Contact, float Velocity)
 {
     hitSide(Contact,Velocity);
 }
Пример #13
0
 /**
  * Called when this object's bottom edge collides with the top of another <code>FlxObject</code>.
  *
  * @param	Contact		The <code>FlxObject</code> you just ran into.
  * @param	Velocity	The suggested new velocity for this object.
  */
 public virtual void hitBottom(FlxObject Contact, float Velocity)
 {
     onFloor = true;
     if(!@fixed || (Contact.@fixed && ((velocity.Y != 0) || (velocity.X != 0))))
         velocity.Y = Velocity;
 }
Пример #14
0
 /**
  * If you don't want to call <code>FlxU.collide()</code> you can use this instead.
  * Just calls <code>FlxU.collide(this,Object);</code>.  Will collide against itself
  * if Object==null.
  *
  * @param	Object		The <FlxObject> you want to collide with.
  */
 public virtual bool collide(FlxObject Object)
 {
     return FlxU.collide(this,((Object==null)?this:Object));
 }
Пример #15
0
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</null>.
  */
 public FlxList()
 {
     @object = null;
     next = null;
 }
Пример #16
0
        /**
         * <code>FlxQuadTree</code>'s other main function.  Call this after adding objects
         * using <code>FlxQuadTree.add()</code> to compare the objects that you loaded.
         *
         * @param	BothLists	Whether you are doing an A-B list comparison, or comparing A against itself.
         * @param	Callback	A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject);</code>  If no function is provided, <code>FlxQuadTree</code> will call <code>kill()</code> on both objects.
         *
         * @return	Whether or not any overlaps were found.
         */
        public bool overlap(bool BothLists, SpriteCollisionEvent Callback)
        {
            _oc = Callback;
            bool c = false;
            FlxList itr;
            if(BothLists)
            {
                //An A-B list comparison
                _oa = B_LIST;
                if(_headA.@object != null)
                {
                    itr = _headA;
                    while(itr != null)
                    {
                        _o = itr.@object;
                        if(_o.exists && _o.solid && overlapNode())
                            c = true;
                        itr = itr.next;
                    }
                }
                _oa = A_LIST;
                if(_headB.@object != null)
                {
                    itr = _headB;
                    while(itr != null)
                    {
                        _o = itr.@object;
                        if(_o.exists && _o.solid)
                        {
                            if((_nw != null) && _nw.overlapNode())
                                c = true;
                            if((_ne != null) && _ne.overlapNode())
                                c = true;
                            if((_se != null) && _se.overlapNode())
                                c = true;
                            if((_sw != null) && _sw.overlapNode())
                                c = true;
                        }
                        itr = itr.next;
                    }
                }
            }
            else
            {
                //Just checking the A list against itself
                if(_headA.@object != null)
                {
                    itr = _headA;
                    while(itr != null)
                    {
                        _o = itr.@object;
                        if(_o.exists && _o.solid && overlapNode(itr.next))
                            c = true;
                        itr = itr.next;
                    }
                }
            }

            //Advance through the tree by calling overlap on each child
            if((_nw != null) && _nw.overlap(BothLists,_oc))
                c = true;
            if((_ne != null) && _ne.overlap(BothLists,_oc))
                c = true;
            if((_se != null) && _se.overlap(BothLists,_oc))
                c = true;
            if((_sw != null) && _sw.overlap(BothLists,_oc))
                c = true;

            return c;
        }
Пример #17
0
 /**
  * Call this function to add an object to the root of the tree.
  * This function will recursively add all group members, but
  * not the groups themselves.
  *
  * @param	Object		The <code>FlxObject</code> you want to add.  <code>FlxGroup</code> objects will be recursed and their applicable members added automatically.
  * @param	List		A <code>uint</code> flag indicating the list to which you want to add the objects.  Options are <code>A_LIST</code> and <code>B_LIST</code>.
  */
 public void add(FlxObject Object, uint List)
 {
     _oa = List;
     if(Object._group)
     {
         int i = 0;
         FlxObject m;
         List<FlxObject> members = (Object as FlxGroup).members;
         int l = members.Count;
         while(i < l)
         {
             m = members[i++] as FlxObject;
             if((m != null) && m.exists)
             {
                 if(m._group)
                     add(m,List);
                 else if(m.solid)
                 {
                     _o = m;
                     _ol = _o.x;
                     _ot = _o.y;
                     _or = _o.x + _o.width;
                     _ob = _o.y + _o.height;
                     addObject();
                 }
             }
         }
     }
     if(Object.solid)
     {
         _o = Object;
         _ol = _o.x;
         _ot = _o.y;
         _or = _o.x + _o.width;
         _ob = _o.y + _o.height;
         addObject();
     }
 }
Пример #18
0
 public FlxSpriteCollisionEvent(FlxObject Attacker, FlxObject Target)
 {
     _s1 = Attacker;
     _s2 = Target;
 }
Пример #19
0
        /// <summary>
        /// Called when the sprite hit something on its bottom edge.
        /// </summary>
        /// <param name="Contact">The Object that it collided with.</param>
        /// <param name="Velocity">The Velocity that is will now have???</param>
        public override void hitBottom(FlxObject Contact, float Velocity)
        {
            if (mode == "swan" || mode == "dive" || mode == "enterWater" || mode == "swim")
            {
                play("hitFloor");
                mode = "dead";
                Globals.addScore(-1000000, "Hit head");
                dead = true;
            }

            base.hitBottom(Contact, Velocity);
        }
Пример #20
0
 /**
  * Call this function to see if one <code>FlxObject</code> overlaps another.
  * Can be called with one object and one group, or two groups, or two objects,
  * whatever floats your boat!  It will put everything into a quad tree and then
  * check for overlaps.  For maximum performance try bundling a lot of objects
  * together using a <code>FlxGroup</code> (even bundling groups together!)
  * NOTE: does NOT take objects' scrollfactor into account.
  *
  * @param	Object1		The first object or group you want to check.
  * @param	Object2		The second object or group you want to check.  If it is the same as the first, flixel knows to just do a comparison within that group.
  * @param	Callback	A function with two <code>FlxObject</code> parameters - e.g. <code>myOverlapFunction(Object1:FlxObject,Object2:FlxObject);</code>  If no function is provided, <code>FlxQuadTree</code> will call <code>kill()</code> on both objects.
  */
 public static bool overlap(FlxObject Object1, FlxObject Object2, SpriteCollisionEvent Callback)
 {
     if( (Object1 == null) || !Object1.exists ||
         (Object2 == null) || !Object2.exists )
         return false;
     quadTree = new FlxQuadTree(FlxQuadTree.bounds.x,FlxQuadTree.bounds.y,FlxQuadTree.bounds.width,FlxQuadTree.bounds.height, null);
     quadTree.add(Object1,FlxQuadTree.A_LIST);
     if(Object1 == Object2)
         return quadTree.overlap(false,Callback);
     quadTree.add(Object2,FlxQuadTree.B_LIST);
     return quadTree.overlap(true,Callback);
 }
Пример #21
0
 /**
  * Called when this object's top collides with the bottom of another <code>FlxObject</code>.
  *
  * @param	Contact		The <code>FlxObject</code> you just ran into.
  * @param	Velocity	The suggested new velocity for this object.
  */
 public virtual void hitTop(FlxObject Contact, float Velocity)
 {
     if(!@fixed || (Contact.@fixed && ((velocity.Y != 0) || (velocity.X != 0))))
         velocity.Y = Velocity;
 }
Пример #22
0
 /**
  * Adds a new <code>FlxObject</code> subclass (FlxSprite, FlxBlock, etc) to the list of children
  *
  * @param	Object			The object you want to add
  * @param	ShareScroll		Whether or not this FlxObject should sync up with this layer's scrollFactor
  *
  * @return	The same <code>FlxObject</code> object that was passed in.
  */
 public FlxObject add(FlxObject Object)
 {
     return add(Object, false);
 }
Пример #23
0
 public override void hitSide(FlxObject Contact, float Velocity)
 {
     velocity.X = -velocity.X * _bounce;
     if(angularVelocity != 0)
         angularVelocity = -angularVelocity * _bounce;
 }
Пример #24
0
 /**
  * Checks to see if some <code>FlxObject</code> object overlaps this <code>FlxObject</code> object.
  *
  * @param	Object	The object being tested.
  *
  * @return	Whether or not the two objects overlap.
  */
 public virtual bool overlaps(FlxObject Object)
 {
     _point = getScreenXY();
     float tx = _point.X;
     float ty = _point.Y;
     _point = Object.getScreenXY();
     if((_point.X <= tx-Object.width) || (_point.X >= tx+width) || (_point.Y <= ty-Object.height) || (_point.Y >= ty+height))
         return false;
     return true;
 }
Пример #25
0
 /**
  * <code>FlxU.collide()</code> (and thus <code>FlxObject.collide()</code>) call
  * this function each time two objects are compared to see if they collide.
  * It doesn't necessarily mean these objects WILL collide, however.
  *
  * @param	Object	The <code>FlxObject</code> you're about to run into.
  */
 public virtual void preCollide(FlxObject Object)
 {
     //Most objects don't have to do anything here.
 }
Пример #26
0
 /**
  * Call this function if you want this sound's volume to change
  * based on distance from a particular FlxCore object.
  *
  * @param	X		The X position of the sound.
  * @param	Y		The Y position of the sound.
  * @param	Core	The object you want to track.
  * @param	Radius	The maximum distance this sound can travel.
  *
  * @return	This FlxSound instance (nice for chaining stuff together, if you're into that).
  */
 public FlxSound proximity(float X, float Y, FlxObject Core, float Radius)
 {
     return proximity(X,Y,Core,Radius,true);
 }
Пример #27
0
 /**
  * Stops and resets the camera.
  */
 internal static void unfollow()
 {
     followTarget = null;
     followLead = Vector2.Zero;
     followLerp = 1;
     followMin = Point.Zero;
     followMax = Point.Zero;
     scroll = new Vector2();
     _scrollTarget = new Vector2();
 }
Пример #28
0
 public FlxSound proximity(float X, float Y, FlxObject Core, float Radius, bool Pan)
 {
     x = X;
     y = Y;
     _core = Core;
     _radius = Radius;
     _pan = Pan;
     return this;
 }
Пример #29
0
        /**
         * Checks for overlaps between the provided object and any tiles above the collision index.
         *
         * @param	Core		The <code>FlxObject</code> you want to check against.
         */
        public override bool overlaps(FlxObject Core)
        {
            int d;

            int dd;
            List<BlockPoint> blocks = new List<BlockPoint>();

            //First make a list of all the blocks we'll use for collision
            int ix = (int)FlxU.floor((Core.x - x)/_tileWidth);
            int iy = (int)FlxU.floor((Core.y - y)/_tileHeight);
            int iw = (int)FlxU.ceil((float)Core.width / (float)_tileWidth) + 1;
            int ih = (int)FlxU.ceil((float)Core.height / (float)_tileHeight) + 1;
            int r = 0;
            int c;
            while(r < ih)
            {
                if(r >= heightInTiles) break;
                d = (iy+r)*widthInTiles+ix;
                c = 0;
                while(c < iw)
                {
                    if(c >= widthInTiles) break;
                    dd = _data[d+c];
                    if(dd >= collideIndex)
                        blocks.Add(new BlockPoint((int)(x+(ix+c)*_tileWidth),(int)(y+(iy+r)*_tileHeight),dd));
                    c++;
                }
                r++;
            }

            //Then check for overlaps
            int bl = blocks.Count;
            int i = 0;
            while(i < bl)
            {
                _block.x = blocks[i].x;
                _block.y = blocks[i++].y;
                if(_block.overlaps(Core))
                    return true;
            }
            return false;
        }
Пример #30
0
 /**
  * An internal function for clearing all the variables used by sounds.
  */
 protected void init()
 {
     _sound = null;
     _position = 0;
     _volume = 1.0f;
     _volumeAdjust = 1.0f;
     _looped = false;
     _core = null;
     _radius = 0;
     _pan = false;
     _fadeOutTimer = 0;
     _fadeOutTotal = 0;
     _pauseOnFadeOut = false;
     _fadeInTimer = 0;
     _fadeInTotal = 0;
     active = false;
     visible = false;
     solid = false;
     playing = false;
 }
 /// <summary>
 /// Called when the sprite hits something on its top
 /// </summary>
 /// <param name="Contact"></param>
 /// <param name="Velocity"></param>
 public override void hitTop(FlxObject Contact, float Velocity)
 {
     base.hitTop(Contact, Velocity);
 }
Пример #32
0
 public FlxSpriteCollisionEvent(FlxObject Attacker, FlxObject Target)
 {
     _s1 = Attacker;
     _s2 = Target;
 }