Exemplo n.º 1
0
	    /// Initialize the proxy using the given shape. The shape
	    /// must remain in scope while the proxy is in use.
	    public void Set(Shape shape, int index)
        {
            switch (shape.ShapeType)
	        {
	        case ShapeType.Circle:
		        {
			        CircleShape circle = (CircleShape)shape;
                    _vertices[0] = circle._p;
			        _count = 1;
			        _radius = circle._radius;
		        }
		        break;

            case ShapeType.Polygon:
		        {
			        PolygonShape polygon = (PolygonShape)shape;
			        _vertices = polygon._vertices;
			        _count = polygon._vertexCount;
			        _radius = polygon._radius;
		        }
		        break;

	        case ShapeType.Loop:
	            {
		            LoopShape loop = (LoopShape)shape;
		            Debug.Assert(0 <= index && index < loop._count);

		            _buffer[0] = loop._vertices[index];
		            if (index + 1 < loop._count)
		            {
			            _buffer[1] = loop._vertices[index + 1];
		            }
		            else
		            {
			            _buffer[1] = loop._vertices[0];
		            }

                    _vertices[0] = _buffer[0];
                    _vertices[1] = _buffer[1];
		            _count = 2;
		            _radius = loop._radius;
	            }
	            break;

	        case ShapeType.Edge:
	            {
		            EdgeShape edge = (EdgeShape)shape;
                    _vertices[0] = edge._vertex1;
                    _vertices[1] = edge._vertex2;
		            _count = 2;
		            _radius = edge._radius;
                }
                break;

	        default:
		        Debug.Assert(false);
                break;
	        }

        }
        public Soldier(Shape shape, Vector2 position, GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            idle = new Animation(gameContent.idle[(int)shape], 20f, false);
            walk = new Animation(gameContent.walk[(int)shape], 0.15f, true);
            animationPlayer.PlayAnimation(idle);

            MaxHealth = 10; health = gameContent.random.Next(2, 10);
            MaxReloadTime = gameContent.random.Next(50); reloadTime = 0;

            CircleShape cShape = new CircleShape();
            cShape._radius = (Size + 2) / 2 / gameContent.b2Scale;

            BodyDef bd = new BodyDef();
            bd.fixedRotation = true;
            bd.type = BodyType.Dynamic;
            bd.position = position / gameContent.b2Scale;
            body = world.CreateBody(bd);
            //body.SetLinearDamping(10);

            FixtureDef fd = new FixtureDef();
            fd.shape = cShape;
            fd.restitution = 0.5f;
            fd.friction = .1f;
            fd.density = .1f;

            body.CreateFixture(fd);
            body.SetUserData(this);
        }
        public static bool TestOverlap(Shape shapeA, Shape shapeB, ref Transform xfA, ref Transform xfB)
        {
            DistanceInput input = new DistanceInput();
            input.proxyA.Set(shapeA);
            input.proxyB.Set(shapeB);
            input.transformA = xfA;
            input.transformB = xfB;
            input.useRadii = true;

            SimplexCache cache;
            DistanceOutput output;
            Distance.ComputeDistance(out output, out cache, ref input);

            return output.distance < 10.0f * Settings.b2_epsilon;
        }
 public Bazooka(Shape shape, Vector2 position, GameContent gameContent, World world)
     : base(shape, position, gameContent, world)
 {
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates one part of the motorcycle or driver
        /// </summary>
        /// <param name="shape">The shape of the part</param>
        /// <param name="name">The Content name of the texture that belongs to this part</param>
        /// <param name="pos">The position of the part</param>
        /// <param name="angle">The rotation angle of the part</param>
        /// <param name="density">The density of the part</param>
        /// <param name="friction">The friction of the part</param>
        /// <param name="restitution">The restitution of the part</param>
        /// <returns></returns>
        private Body CreatePart(Shape shape, String name, Vector2 pos, float angle, float density,
                                float friction, float restitution)
        {
            Body body = CreateBody(name, pos, angle);

            FixtureDef fixtureDef = new FixtureDef();
            fixtureDef.shape = shape;
            fixtureDef.density = density;
            fixtureDef.friction = friction;
            fixtureDef.restitution = restitution;

            body.CreateFixture(fixtureDef);

            parts.Add(body);
            return body;
        }
        /// <summary>
        /// Initialize the proxy using the given shape. The shape
        /// must remain in scope while the proxy is in use.
        /// </summary>
        /// <param name="shape"></param>
        public void Set(Shape shape)
        {
            switch (shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        CircleShape circle = (CircleShape)shape;
                        _vertices[0] = circle._p;
                        _count = 1;
                        _radius = circle._radius;
                    }
                    break;

                case ShapeType.Polygon:
                    {
                        PolygonShape polygon = (PolygonShape)shape;
                        _vertices = polygon._vertices;
                        _count = polygon._vertexCount;
                        _radius = polygon._radius;
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a fixture from a shape and attach it to this body.
        /// This is a convenience function. Use FixtureDef if you need to set parameters
        /// like friction, restitution, user data, or filtering.
        /// If the density is non-zero, this function automatically updates the mass of the body.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="shape">the shape to be cloned.</param>
        /// <param name="density">the shape density (set to zero for static bodies).</param>
        /// <returns></returns>
        public Fixture CreateFixture(Shape shape, float density)
        {
            FixtureDef def = new FixtureDef();
            def.shape = shape;
            def.density = density;

            return CreateFixture(def);
        }
 public AirBombs(Shape shape, Vector2 position, GameContent gameContent, World world)
     : base(shape, position, gameContent, world)
 {
 }
 internal Fixture()
 {
     _userData = null;
     _body = null;
     _next = null;
     _proxyId = BroadPhase.NullProxy;
     _shape = null;
 }
Exemplo n.º 10
0
 /// <summary>
 /// The constructor sets the default fixture definition values.
 /// </summary>
 public FixtureDef()
 {
     shape = null;
     userData = null;
     friction = 0.2f;
     restitution = 0.0f;
     density = 0.0f;
     filter.categoryBits = 0x0001;
     filter.maskBits = 0xFFFF;
     filter.groupIndex = 0;
     isSensor = false;
 }
Exemplo n.º 11
0
        internal void Destroy()
        {
            // The proxy must be destroyed before calling this.
            Debug.Assert(_proxyId == BroadPhase.NullProxy);

            _shape = null;
        }
Exemplo n.º 12
0
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        internal void Create(Body body, FixtureDef def)
        {
            _userData = def.userData;
            _friction = def.friction;
            _restitution = def.restitution;

            _body = body;
            _next = null;

            _filter = def.filter;

            _isSensor = def.isSensor;

            _shape = def.shape.Clone();

            _density = def.density;
        }