Esempio n. 1
0
        private void testPlayerBlocking()
        {
            Player p     = ((GameWorld)owner).player;
            Rect2d prect = p.GetPosition();

            if (prect.IsTouching(pipeUnder))
            {
                lastUpdate = 0;
            }
        }
Esempio n. 2
0
        /// <returns> Wether an illegal pushback happened</returns>
        public bool DoCollisions(bool ignoreIllegalPushback = false)
        {
            if (!alive)
            {
                return(false);
            }

            bool result = false;

            // Collide with Entities

            Rect2d nocollnewpos = new Rect2d(
                new Vec2d(
                    position.X - DETECTION_TOLERANCE,
                    position.Y - DETECTION_TOLERANCE),
                width + DETECTION_TOLERANCE * 2,
                height + DETECTION_TOLERANCE * 2);
            Rect2d currPosition = GetPosition();

            foreach (DynamicEntity e in owner.GetSurroundingEntityList(GetCollisionMapPosition()))
            {
                if (nocollnewpos.IsColldingWith(e.GetPosition()) && e != this)
                {
                    bool isColl  = currPosition.IsColldingWith(e.GetPosition());
                    bool isTouch = currPosition.IsTouching(e.GetPosition());
                    bool isBlock = Entity.TestBlocking(e, this);

                    if (e.alive)
                    {
                        //e.onCollide(this, false, isBlock, isColl, isTouch);
                        this.onCollide(e, true, isBlock, isColl, isTouch);
                    }

                    if (isBlock && isColl)
                    {
                        result = true;

                        if (!ignoreIllegalPushback)
                        {
                            OnIllegalIntersection(e);
                        }
                    }
                }
            }

            // Collide with Blocks

            int left   = (int)((position.X - BLOCK_DETECTION_RANGE * Block.BLOCK_WIDTH) / Block.BLOCK_WIDTH);
            int bottom = (int)((position.Y - BLOCK_DETECTION_RANGE * Block.BLOCK_HEIGHT) / Block.BLOCK_HEIGHT);
            int right  = (int)Math.Ceiling((position.X + width + BLOCK_DETECTION_RANGE * Block.BLOCK_WIDTH) / Block.BLOCK_WIDTH);
            int top    = (int)Math.Ceiling((position.Y + height + BLOCK_DETECTION_RANGE * Block.BLOCK_HEIGHT) / Block.BLOCK_HEIGHT);

            for (int x = left; x < right; x++)
            {
                for (int y = bottom; y < top; y++)
                {
                    Block b = owner.GetBlock(x, y);
                    if (b != null && nocollnewpos.IsColldingWith(b.GetPosition()))
                    {
                        bool isColl  = currPosition.IsColldingWith(b.GetPosition());
                        bool isTouch = currPosition.IsTouching(b.GetPosition());
                        bool isBlock = Entity.TestBlocking(b, this);

                        b.onCollide(this, false, isBlock, isColl, isTouch);
                        this.onCollide(b, true, isBlock, isColl, isTouch);

                        if (isBlock && isColl)
                        {
                            result = true;

                            if (!ignoreIllegalPushback)
                            {
                                OnIllegalIntersection(b);
                            }
                        }
                    }
                }
            }

            // Collide with TriggerZones

            for (int x = left; x < right; x++)
            {
                for (int y = bottom; y < top; y++)
                {
                    List <Trigger> tlist = owner.getTriggerList(x, y);

                    if (tlist != null)
                    {
                        foreach (Trigger t in tlist)
                        {
                            bool isColl = currPosition.IsColldingWith(t.GetPosition());

                            if (isColl)
                            {
                                t.OnCollide(this);
                            }
                        }
                    }
                }
            }

            return(result);
        }