Пример #1
0
 public Wall(Vector2 dimensions, Vector2 position, VelcroPhysics.Dynamics.World world)
 {
     textureDimensions = dimensions;
     label             = "wall";
     origin            = textureDimensions / 1.85f;
     physicsBody       = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(dimensions.X), ConvertUnits.ToSimUnits(dimensions.Y), 10, ConvertUnits.ToSimUnits(position), 0, BodyType.Static, null);
 }
Пример #2
0
 public World(int areaWidth, int areaHeight)
 {
     physicsWorld = new VelcroPhysics.Dynamics.World(Vector2.Zero);
     p1           = new Player(new Vector2(200, 200), physicsWorld);
     entities     = new List <Entity>();
     entities.Add(p1);
     wall  = new Wall(new Vector2(200, 200), new Vector2(300, 700), physicsWorld);
     wall2 = new Wall(new Vector2(200, 200), new Vector2(600, 300), physicsWorld);
     entities.Add(wall);
     entities.Add(wall2);
 }
Пример #3
0
        public Player(Vector2 pos, VelcroPhysics.Dynamics.World world)
        {
            physicsBody = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(100f), 1f, ConvertUnits.ToSimUnits(pos), BodyType.Dynamic);
            physicsBody.LinearDamping = 10f;

            label                  = "player";
            textureDimensions      = new Vector2(100, 100);
            origin                 = textureDimensions / 2;
            damageBox              = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(30f), ConvertUnits.ToSimUnits(90f), 2f, new Vector2(0, ConvertUnits.ToSimUnits(100f)), physicsBody, null);
            damageBox.OnCollision += new VelcroPhysics.Collision.Handlers.OnCollisionHandler(this.Dealdamage);
        }
Пример #4
0
 public override void EndPrimaryAttack(VelcroPhysics.Dynamics.World world)
 {
     throw new NotImplementedException();
 }
Пример #5
0
 protected void DrawBox2DJointsGizmos(VelcroPhysics.Dynamics.World b2World)
 {
 }
Пример #6
0
    protected void DrawBox2DBodyGizmos(VelcroPhysics.Dynamics.World b2World)
    {
        for (int ib = 0, count = b2World.BodyList.Count; ib < count; ++ib)
        {
            VelcroPhysics.Dynamics.Body body = b2World.BodyList[ib];
            if (null == body)
            {
                continue;
            }

            Color fixtureColor;
            if (body.IsStatic)
            {
                fixtureColor = new Color(1, 0, 1);
            }
            else
            {
                if (body.BodyType == VelcroPhysics.Dynamics.BodyType.Kinematic)
                {
                    fixtureColor = Color.yellow;
                }
                else
                {
                    fixtureColor = Color.green;
                }

                if ((body._flags & VelcroPhysics.Dynamics.BodyFlags.AwakeFlag) == 0)
                {
                    fixtureColor = Color.gray * 0.5f + fixtureColor * 0.5f;
                }
            }

            Microsoft.Xna.Framework.Vector2 center = body.WorldCenter;
            for (int ifix = 0, countFix = body.FixtureList.Count; ifix < countFix; ++ifix)
            {
                VelcroPhysics.Dynamics.Fixture fixture = body.FixtureList[ifix];
                if (fixture.Friction > 5f)
                {
                    fixtureColor.b = 1.0f;
                }
                if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Circle)
                {
                    float   radius   = fixture.Shape.Radius * GlobalVarFun.DisplayToPhysicUnitRatio;
                    Vector3 v3Center = GlobalVarFun.GetDisplayPosition(center.X, center.Y);

                    Gizmos.color = fixtureColor;
                    Gizmos.DrawWireSphere(v3Center, radius);
                }
                else if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Polygon)
                {
                    var shape       = fixture.Shape as VelcroPhysics.Collision.Shapes.PolygonShape;
                    int vertexCount = shape.Vertices.Count;
                    for (int iv = 0; iv < vertexCount; ++iv)
                    {
                        Microsoft.Xna.Framework.Vector2 src = (shape.Vertices[(iv) % vertexCount]);
                        Microsoft.Xna.Framework.Vector2 des = (shape.Vertices[(iv + 1) % vertexCount]);
                        src = ChangeRotation(body, src);
                        des = ChangeRotation(body, des);
                        Vector3 v3Src = GlobalVarFun.GetDisplayPosition(src.X, src.Y);
                        Vector3 v3Des = GlobalVarFun.GetDisplayPosition(des.X, des.Y);

                        v3Src.z = 0;
                        v3Des.z = 0;

                        Gizmos.color = fixtureColor;
                        Gizmos.DrawLine(v3Src, v3Des);
                    }
                }
                else if (fixture.Shape.ShapeType == VelcroPhysics.Collision.Shapes.ShapeType.Edge)
                {
                    var shape = fixture.Shape as VelcroPhysics.Collision.Shapes.EdgeShape;
                    Microsoft.Xna.Framework.Vector2 startPos = shape._vertex1;
                    Microsoft.Xna.Framework.Vector2 endPos   = shape._vertex2;

                    Microsoft.Xna.Framework.Vector2 src = startPos;
                    Microsoft.Xna.Framework.Vector2 des = endPos;
                    src = ChangeRotation(body, src);
                    des = ChangeRotation(body, des);
                    Vector3 v3Src = GlobalVarFun.GetDisplayPosition(src.X, src.Y);
                    Vector3 v3Des = GlobalVarFun.GetDisplayPosition(des.X, des.Y);

                    v3Src.z = 0;
                    v3Des.z = 0;

                    Gizmos.color = fixtureColor;
                    Gizmos.DrawLine(v3Src, v3Des);
                }
            }
        }
    }
Пример #7
0
 public abstract void EndPrimaryAttack(VelcroPhysics.Dynamics.World world);
Пример #8
0
 public override void EndPrimaryAttack(VelcroPhysics.Dynamics.World world)
 {
     damageBox.IsSensor = false;
 }
Пример #9
0
 public override void PrimaryAttack(VelcroPhysics.Dynamics.World world)
 {
     //damageBox.IsSensor = true;
 }