Exemplo n.º 1
0
 public override void hitBottom(FlxObject Contact, float Velocity)
 {
     if(velocity.Y > 50)
         FlxG.play(SndLand);
     onFloor = true;
     base.hitBottom(Contact,Velocity);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 public FlxSpriteCollisionEvent(FlxObject Attacker, FlxObject Target)
 {
     _s1 = Attacker;
     _s2 = Target;
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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++;
            }
        }
Exemplo n.º 9
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;
            [email protected] = true;
            //_callbacks = new Array();
            @fixed = true;
            moves = false;
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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([email protected] != null)
                {
                    itr = _headA;
                    while(itr != null)
                    {
                        _o = [email protected];
                        if(_o.exists && _o.solid && overlapNode())
                            c = true;
                        itr = itr.next;
                    }
                }
                _oa = A_LIST;
                if([email protected] != null)
                {
                    itr = _headB;
                    while(itr != null)
                    {
                        _o = [email protected];
                        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([email protected] != null)
                {
                    itr = _headA;
                    while(itr != null)
                    {
                        _o = [email protected];
                        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;
        }
Exemplo n.º 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);
 }
Exemplo n.º 13
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([email protected] || ([email protected] && ((velocity.Y != 0) || (velocity.X != 0))))
         velocity.Y = Velocity;
 }
Exemplo n.º 14
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([email protected] || ([email protected] && ((velocity.Y != 0) || (velocity.X != 0))))
         velocity.Y = Velocity;
 }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
0
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</null>.
  */
 public FlxList()
 {
     @object = null;
     next = null;
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
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;
 }
Exemplo n.º 20
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();
     }
 }
Exemplo n.º 21
0
 public override void hitSide(FlxObject Contact, float Velocity)
 {
     velocity.X = -velocity.X * _bounce;
     if(angularVelocity != 0)
         angularVelocity = -angularVelocity * _bounce;
 }
Exemplo n.º 22
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.
 }
Exemplo n.º 23
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);
 }
Exemplo n.º 24
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;
 }
Exemplo n.º 25
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();
 }
Exemplo n.º 26
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;
 }
Exemplo n.º 27
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;
        }
Exemplo n.º 28
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);
 }
 /// <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);
 }
Exemplo n.º 30
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;
 }