示例#1
0
        private void SetupColliders()
        {
            float delta     = 0.03f;
            float space     = 0.01f;
            float distance2 = space / 2;
            float size      = delta - space;
            int   i         = 0;

            for (float x = -0.9f; x < 0.9f; x += delta)
            {
                for (float y = -0.9f; y < 0.9f; y += delta)
                {
                    var collider = new Collider(x, y, size, size)
                    {
                        Velocity = RandomVectors.Velocity()
                    };
                    colliders.Add(collider);
                    ++i;
                }
            }
            float scale = 2f;

            collisionGrid       = new CollisionGrid(windowBorders, size * scale, size * scale);
            collisionGridCenter = new CollisionGridCenter(windowBorders, size * scale, size * scale);
        }
示例#2
0
        private void HandleNarrowPhaseCollision(Collider collider1, Collider collider2)
        {
            var box1 = collider1.Box;
            var box2 = collider2.Box;

            if (box1.Intersects(box2))
            {
                //undo movement
                collider1.RestoreSavedBox();
                collider2.RestoreSavedBox();
                ////set random velocity
                collider1.Velocity = RandomVectors.Velocity();
                collider2.Velocity = RandomVectors.Velocity();
            }
        }