예제 #1
0
        public MovingPlatform(Shape aPlatform, Vector2D start, Vector2D end, float aSpeed, float dampen)
        {
            point1 = start;
            point2 = end;

            destSpeed = aSpeed;

            Vector2D displacement = point2 - point1;

            direction    = displacement.Normalised();
            timeToTravel = displacement.Length() / destSpeed;
            timeSoFar    = 0.0f;

            currentSpeed = 0;

            //if the dampen time is longer than half the total travel time then cut it down to half the travel time
            if (dampen * 2.0f > timeToTravel)
            {
                dampen = timeToTravel / 2.0f;
            }
            dampenTime = dampen;


            acceleration = SuvatEquations.AfromUTV(0, dampenTime, destSpeed);


            platform                = new RigidBody();
            platform.Shape          = aPlatform;
            platform.LinearVelocity = direction * currentSpeed;
            platform.moveable       = true;
            platform.obeysGravity   = false;
            platform.reactToForce   = false;
            platform.SetPosition(point1);
        }
예제 #2
0
        //initialise a net centred on the provided location, with the initial velocity
        private void CreateNet(Vector2D initalLocation, Vector2D initalVelocity)
        {
            float cubeSize   = 5.0f;
            int   width      = 5;
            int   height     = 5;
            float restLength = 15;

            RigidBody tempSquare;


            //loop through the width and height of the net
            for (int i = 0; i < height; ++i)
            {
                for (int j = 0; j < width; ++j)
                {
                    //create the next box and add it to the list of boxes
                    tempSquare              = new RigidBody();
                    tempSquare.Shape        = new Box(cubeSize, cubeSize);
                    tempSquare.Shape.mColor = System.Drawing.Color.LightSteelBlue;
                    tempSquare.type         = RBTypes.PLAYER_NET;
                    tempSquare.SetPosition(initalLocation + new Vector2D((j - 2) * cubeSize, (i - 2) * cubeSize));
                    tempSquare.LinearVelocity = initalVelocity;
                    tempSquare.SetDynamic();
                    tempSquare.Mass = 20;
                    netEdges.Add(tempSquare);


                    //add the spring to the block on the left
                    if (j > 0)
                    {
                        netRopes.Add(new SpringJoint(netEdges[i * width + j], netEdges[i * width + j - 1]));
                        netRopes[netRopes.Count - 1].RestLength = restLength;
                        netRopes[netRopes.Count - 1].Stiffness  = 1000;
                    }

                    //add a spring to the block above
                    if (i > 0)
                    {
                        netRopes.Add(new SpringJoint(netEdges[i * width + j], netEdges[(i - 1) * width + j]));
                        netRopes[netRopes.Count - 1].RestLength = restLength;
                        netRopes[netRopes.Count - 1].Stiffness  = 1000;
                    }
                }
            }
        }