Beispiel #1
0
        public Player(World world, Vector2 position)
        {
            // create the user data
            UserData userData = new UserData();
            userData.thing = this;

            // create the body
            body = BodyFactory.CreateBody(world, position, 0, userData);
            body.IsStatic = false;
            body.FixedRotation = true;

            // create the body fixture
            Fixture bodyFixture = body.CreateFixture(CreateBodyShape(), userData);
            bodyFixture.Friction = PlayerConstants.FRICTION;

            // create the landing fixture
            landingFixture = body.CreateFixture(CreateLandingShape(), userData);
            landingFixture.IsSensor = true;
            landingFixture.OnCollision += OnLandingCollision;

            InitializeUnbounded();
        }
Beispiel #2
0
        protected Ribbon(World world, List<Vector2> path, float start, float end)
        {
            this.points = path;
            this.start = start;
            this.end = end;

            for (int i = 0; i < points.Count; i++)
            {
                Vector2 v = points[(i + 1) % points.Count] - points[i];
                v.Normalize();
                orientations.Add(v);

                float dist = Vector2.Distance(points[i], points[(i + 1) % points.Count]);
                length += dist;
                intervals.Add(dist);
            }

            UserData userData = new UserData();
            userData.thing = this;

            body = new Body(world);
            body.UserData = userData;
            body.IsStatic = true;
        }
Beispiel #3
0
        /// <summary>
        /// Updates physical fixtures.
        /// </summary>
        protected virtual void UpdateBody()
        {
            //if not moving
            if (Math.Abs(speed) < RibbonConstants.STILLTHRESHOLD)
            {
                //if the ribbon isn't moving, we don't need so many fixtures
                while (fixtures.Count > 1)
                {
                    (fixtures.Dequeue()).Dispose();
                }
            }
            else
            {
                UserData userData = new UserData();
                userData.thing = this;

                Shape shape = GenerateShape();
                fixtures.Enqueue(body.CreateFixture(shape, userData));

                while (fixtures.Count > RibbonConstants.FIXTUREOVERLAY)
                {
                    (fixtures.Dequeue()).Dispose();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates the initial fixture for the ribbon.
        /// </summary>
        protected void InitializeRibbon()
        {
            UserData userData = new UserData();
            userData.thing = this;

            Shape shape = GenerateShape();
            fixtures.Enqueue(body.CreateFixture(shape, userData));
        }