예제 #1
0
 protected override void OnRemoved(ComponentStateEventArgs registrationArgs)
 {
     physics.Body.BroadphaseTag &= ~(int)BodyTags.Projectile;
     physics.Synchronized -= syncHandler;
     physics.World.Events.BodiesBeginCollide -= collideHandler;
     base.OnRemoved(registrationArgs);
 }
예제 #2
0
 /// <summary>
 /// Occurs when the component is dettached from an entity.
 /// </summary>
 protected virtual void OnRemoved(ComponentStateEventArgs registrationArgs)
 {
     if (Removed != null)
     {
         Removed(this, registrationArgs);
     }
 }
예제 #3
0
 protected override void OnAdded(ComponentStateEventArgs registrationArgs)
 {
     base.OnAdded(registrationArgs);
     physics.Body.Material.Restitution = 0f;
     physics.Body.Material.KineticFriction = 0.5f;
     physics.Body.Material.StaticFriction = 0.5f;
     physics.Body.SetMassProperties(JMatrix.Zero, 1.0f, true);
 }
예제 #4
0
 protected override void OnAdded(ComponentStateEventArgs registrationArgs)
 {
     base.OnAdded(registrationArgs);
     if (physics.Body.Shape is Multishape) throw new NotSupportedException("Multishapes not supported!");
     physics.Body.BroadphaseTag |= (int)BodyTags.Projectile;
     physics.Body.SetMassProperties(JMatrix.Identity, 0.1f, false);
     physics.Synchronized += syncHandler;
 }
예제 #5
0
		protected override void OnAdded(ComponentStateEventArgs registrationArgs)
		{
			base.OnAdded(registrationArgs);
			if (physics.Body.Shape is Multishape) throw new NotSupportedException("Multishapes not supported!");
			physics.Body.IsStatic = true;
			physics.Body.BroadphaseTag |= (int)BodyTags.Ghost;
			physics.Synchronized += syncHandler;
		}
예제 #6
0
 protected override void OnAdded(ComponentStateEventArgs registrationArgs) {
     base.OnAdded(registrationArgs);
     /*
     Layer =
         _sprite.Layer - 1;
     */
     Size = new Size(
         _sprite.Size.Width + TextureSourceRectangle.Width,
         _sprite.Size.Height + TextureSourceRectangle.Height);
 }
예제 #7
0
		private void Synchronized(object sender, ComponentStateEventArgs componentStateEventArgs)
		{
			if (IsOutOfSync)
			{
				physics.World.Events.PostStep -= postStepHandler;
			}
			else
			{
				physics.World.Events.PostStep += postStepHandler;
			}
		}
예제 #8
0
	    protected override void OnAdded(ComponentStateEventArgs registrationArgs)
        {
            base.OnAdded(registrationArgs);
			Body.Tag = Record.Name;
            var offset = Body.Position;
            var rot = JMatrix.CreateFromQuaternion(transform.Rotation.ToQuaternion());
            JVector.Transform(ref offset, ref rot, out offset);
            Offset = offset.ToVector3();
            Body.Orientation = Body.Orientation * rot;
            Body.Position = offset + transform.Translation.ToJVector();
			baseTransform = new Transform(JQuaternion.CreateFromMatrix(Body.Orientation).ToQuaternion(),
										 Body.Position.ToVector3()).Invert() * new Transform(transform.Rotation, transform.Translation);
            storedScale = transform.Scale;
            transform.Bind(GetTransform, SetTransform);
        }
예제 #9
0
 protected override void OnAdded(ComponentStateEventArgs registrationArgs)
 {
     base.OnAdded(registrationArgs);
     physics.Body.Material.Restitution = 0f;
     physics.Body.Material.KineticFriction = 0.5f;
     physics.Body.Material.StaticFriction = 0.5f;
     physics.Body.Mass = 1000f;
     physics.Body.SetMassProperties(JMatrix.Zero, 1/physics.Body.Mass, true);
     constraint = new TargetConstraint(physics.Body) {Velocity = 3.0f};
     Activate();
     physics.Synchronized += (sender, args) =>
                                 {
                                     if (!IsOutOfSync)
                                         physics.World.AddConstraint(constraint);
                                     else
                                         physics.World.RemoveConstraint(constraint);
                                 };
 }
예제 #10
0
        protected override void OnRemoved(ComponentStateEventArgs registrationArgs) {
            base.OnRemoved(registrationArgs);

            for (int i = 0; i < _sprites.Length; i++) {
                Sprite sprite = _sprites[i];

                if (sprite == null) {
                    continue;
                }

                if (sprite.Record != null) {
                    sprite.Record.Drop();
                }

                if (SpriteBatch != null) {
                    SpriteBatch.Remove(sprite);
                }

                _sprites[i] = null;
            }
        }
예제 #11
0
 protected override void OnAdded(ComponentStateEventArgs e)
 {
     base.OnAdded(e);
 }
        /// <summary>
        /// Occurs when the component is dettached from an entity. All managed dependencies are null'ed.
        /// </summary>
        /// <remarks>
        /// If you don't want the dependencies to get lost, then override this method and don't call base.
        /// </remarks>
        protected override void OnRemoved(ComponentStateEventArgs registrationArgs)
        {
            base.OnRemoved(registrationArgs);

            ClearDependencies();
        }
        /// <summary>
        /// Occurs when the component is attached to an entity. All dependencies are injected.
        /// </summary>
        protected override void OnAdded(ComponentStateEventArgs registrationArgs)
        {
            base.OnAdded(registrationArgs);

            InjectDependencies();
        }
예제 #14
0
 protected override void OnAdded(ComponentStateEventArgs e)
 {
     base.OnAdded(e);
     phys.Body.Material.KineticFriction = 0f;
     phys.Body.Material.StaticFriction = 0f;
     phys.Body.Material.Restitution = 0f;
     var invInertia = phys.Body.InverseInertia;
     invInertia.M11 = 0;
     invInertia.M22 = 0;
     invInertia.M33 = 0;
     phys.Body.SetMassProperties(invInertia, 1f, true);
     phys.Synchronized += OnSynchronized;
 }
예제 #15
0
 void OnSpriteRemoved(object sender, ComponentStateEventArgs e) {
     Remove(sender as Sprite);
 }
예제 #16
0
 private void Synchronized(object sender, ComponentStateEventArgs componentStateEventArgs)
 {
     if (IsOutOfSync) return;
     physics.World.Events.BodiesBeginCollide += collideHandler;
 }
예제 #17
0
 protected override void OnRemoved(ComponentStateEventArgs e)
 {
     if (controller != null) phys.World.RemoveConstraint(controller);
     base.OnRemoved(e);
 }
예제 #18
0
 private void OnSynchronized(object sender, ComponentStateEventArgs e)
 {
     if (!IsOutOfSync)
     {
         controller = new CharacterController(phys.World, phys.Body);
         controller.StateChanged += OnStateChanged;
         phys.World.AddConstraint(controller);
         var ground = Entity.FindAllWithComponent<TerrainComponent>().FirstOrDefault();
         terrain = ground.GetComponent<TerrainComponent>();
         terrainPhys = ground.GetComponent<PhysicsComponent>();
     }
 }
예제 #19
0
 protected override void OnRemoved(ComponentStateEventArgs e)
 {
     base.OnRemoved(e);
     localParent.RemoveChild(localRoot);
 }
예제 #20
0
        protected override void OnAdded(ComponentStateEventArgs registrationArgs) {
            base.OnAdded(registrationArgs);

            Reset();
        }
예제 #21
0
        protected override void OnAdded(ComponentStateEventArgs registrationArgs) {
            base.OnAdded(registrationArgs);

            _walls.Left += OnLeftBoundaries;
        }
예제 #22
0
		protected override void OnRemoved(ComponentStateEventArgs registrationArgs)
		{
			base.OnRemoved(registrationArgs);
			physics.Body.BroadphaseTag ^= (int)BodyTags.Ghost;
			physics.Synchronized -= syncHandler;
		}
예제 #23
0
        /// <summary>
        /// Occurs when the component is attached to an entity. All dependencies are injected.
        /// </summary>
        protected override void OnAdded(ComponentStateEventArgs registrationArgs)
        {
            base.OnAdded(registrationArgs);

            InjectDependencies();
        }
예제 #24
0
        /// <summary>
        /// Occurs when the component is dettached from an entity. All managed dependencies are null'ed.
        /// </summary>
        /// <remarks>
        /// > If you don't want the dependencies to get lost, then override this method and don't base.
        /// </remarks>
        protected override void OnRemoved(ComponentStateEventArgs registrationArgs)
        {
            base.OnRemoved(registrationArgs);

            ClearDependencies();
        }