Exemplo n.º 1
0
 /// <summary>
 /// Constructor for deserialization.
 /// </summary>
 /// <param name="info">info is the serialization info to deserialize with</param>
 /// <param name="context">context is the context in which to deserialize...?</param>
 protected TriggerEntity_cl(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     mPhysicsType = (PhysicsComponent_cl.PhysicsObjectType)info.GetValue("PhysicsType", typeof(PhysicsComponent_cl.PhysicsObjectType));
     mDisableAfterTrigger = info.GetBoolean("Disable");
     mCooldownTime = info.GetSingle("Cooldown");
 }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shape"></param>
        public void SetShape(PhysicsComponent_cl.PhysicsObjectType shape)
        {
            if (shape == mPhysicsType)
            {
                return;
            }

            /************************************************************************
             * HACK:
             * All shapes should be supported
             *
             * Jay Sternfield	-	2011/12/03
             ************************************************************************/
            if (shape != PhysicsComponent_cl.PhysicsObjectType.RECTANGLE && shape != PhysicsComponent_cl.PhysicsObjectType.CIRCLE)
            {
                throw new Exception("Trigger shape must be Rectangle or Circle.");
            }

            Vector2 size = ((RenderableComponent_cl)GetComponentOfType(typeof(RenderableComponent_cl))).Sprite.Size;

            mPhysicsBody = BodyFactory.CreateBody(PhysicsManager_cl.Instance.PhysicsWorld);

            switch (shape)
            {
                case PhysicsComponent_cl.PhysicsObjectType.RECTANGLE:
                    mPhysicsFixture = FixtureFactory.AttachRectangle(size.X, size.Y, 0f, Vector2.Zero, mPhysicsBody);
                    break;
                case PhysicsComponent_cl.PhysicsObjectType.CIRCLE:
                    mPhysicsFixture = FixtureFactory.AttachCircle(size.X, 0f, mPhysicsBody);
                    break;
                default:
                    throw new Exception("Invalid trigger shape.");
            }

            mPhysicsType = shape;
            mPhysicsBody.BodyType = BodyType.Static;
            mPhysicsBody.IsSensor = true;
            mPhysicsBody.CollisionGroup = 100;
            mPhysicsBody.OnCollision += OnCollision;
        }