コード例 #1
0
        //Contructor to load from an xml file.
        public StaticBody(Game game, XmlReader reader, GraphicsDevice graphics) : base(game)
        {
            this.id = PhysicsOverlord.GetInstance().GetID();
            Color colour = new Color();

            //node is now on colour
            colour.PackedValue = Convert.ToUInt32(reader.GetAttribute("Color"));
            reader.ReadToDescendant("VertexList");
            //move node up one to VertexList
            int count = int.Parse(reader.GetAttribute("Count"));

            sourceVertices = new Vector2[count];
            reader.ReadToDescendant("Vertex");
            for (int i = 0; i < count; i++)
            {
                Vector2 newVertex = new Vector2();
                newVertex.X       = float.Parse(reader.GetAttribute("X"));
                newVertex.Y       = float.Parse(reader.GetAttribute("Y"));
                sourceVertices[i] = newVertex;
                reader.ReadToNextSibling("Vertex"); //</Vertex>
            }
            reader.ReadEndElement();                //</VertexList>
            reader.ReadEndElement();                //</StaticBody>
            BoundingBox   = new BoundingRectangle(sourceVertices);
            this.graphics = graphics;
            this.colour   = colour;
            this.type     = PhysicsObjectType.potStaticBody;
            Init();
            TriangulatePoly();
            centre = new Vector2(BoundingBox.l + ((BoundingBox.r - BoundingBox.l) / 2), BoundingBox.t + ((BoundingBox.b - BoundingBox.t) / 2));
        }
コード例 #2
0
        public void addParticles(int num)
        {
            for (int i = 0; i < num; i++)
            {
                Random RandomGenerator = new Random();

                float   randomXVelocity = 5;
                Vector2 mousePos        = camera.MouseToWorld();
                float   xPos            = mousePos.X;
                float   yPos            = mousePos.Y;

                if (xPos < drawingOffset)
                {
                    xPos = drawingOffset + 1;
                }
                else if (xPos > 800 - drawingOffset)
                {
                    xPos = 800 - drawingOffset - 1;
                }

                if (yPos < 0)
                {
                    yPos = 1;
                }
                else if (yPos > 500)
                {
                    yPos = 499;
                }

                BlobParticle theParticle = new BlobParticle(Game, new Vector2(xPos, yPos), theSprite, PhysicsOverlord.GetInstance().GetID(), particleRadius);
                theParticle.colour   = Color.Red;
                theParticle.velocity = new Vector2(5, 5);

                theParticles.Add(theParticle);
                SpatialGrid.GetInstance().AddObject(theParticle);

                particleCount++;
                currentNumParticles--;
            }
        }
コード例 #3
0
        public override void NewBody(Color colour, params Vector2[] vertices)
        {
            RigidBody rb = new RigidBody(Game, PhysicsOverlord.GetInstance().GetID(), GraphicsDevice, colour, vertices);

            NewBody(rb);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new Static Body
        /// </summary>
        /// <param name="colour">The Colour of the Static Body</param>
        /// <param name="vertices">The vertices that make up the shape</param>
        public virtual void NewBody(Color colour, params Vector2[] vertices)
        {
            StaticBody sb = new StaticBody(Game, PhysicsOverlord.GetInstance().GetID(), GraphicsDevice, colour, vertices);

            NewBody(sb);
        }
コード例 #5
0
        public void CreateParasite(int numParts)
        {
            // Create the Tail
            tail                 = new ParasiteTail(Game, PhysicsOverlord.GetInstance().GetID(), theSprite, 1.0f);
            tail.Position        = new Vector2(50 * numParts, 100);
            tail.relativeGravity = gravity;

            // Create Body Parts
            for (int i = 0; i < numParts; i++)
            {
                ParasiteBodyPart bodyPart = new ParasiteBodyPart(Game, PhysicsOverlord.GetInstance().GetID(), theSprite, 1f);
                bodyPart.Position = new Vector2(50 * i, 100);
                bodyparts.Add(bodyPart);
                bodyPart.relativeGravity = gravity;
            }

            // Create the Head
            head                 = new ParasiteHead(Game, PhysicsOverlord.GetInstance().GetID(), theSprite, 1);
            head.Position        = new Vector2(100, 100);
            head.relativeGravity = gravity;

            // IKPoints

            theParasite.Add(head);

            IKMember headIK = new IKMember(head, 10);
            IKMember lastIK = headIK;

            head.AddIKPoint(headIK);

            for (int i = 0; i < bodyparts.Count; i++)
            {
                ParasiteBodyPart bodyPart = bodyparts[i];

                theParasite.Add(bodyPart);

                IKMember ik = new IKMember(bodyPart, 10);

                if (i != 0)
                {
                    ik.addNeighbour(lastIK);
                }

                lastIK.addNeighbour(ik);

                bodyPart.AddIKPoint(ik);

                lastIK = ik;
            }

            // Uncomment for Rad Wiggle Motion!
            // currentIK = new IKMember(tail, 1);

            //currentIK = new IKMember(tail, 10);
            theParasite.Add(tail);

            IKMember tailIK = new IKMember(tail, 10);

            tailIK.addNeighbour(lastIK);
            lastIK.addNeighbour(tailIK);

            tail.AddIKPoint(tailIK);

            tail.initTail();
        }