예제 #1
0
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            Projectile proj = sender.Entity.Tag as Projectile;

            if (proj != null)
            {
                var otherEntityInformation = other as EntityCollidable;
                if (otherEntityInformation != null)
                {
                    Player p = otherEntityInformation.Entity.Tag as Player;
                    if (p != null)
                    {
                        if (p.Id == proj.FiredByPlayerID || p.IsDodging)
                        {
                            return;
                        }
                        Player shooter = game.PlayerManager.GetPlayer(proj.FiredByPlayerID);
                        float  damage  = 0;
                        if (shooter.EquippedWeapons != null)
                        {
                            damage = shooter.RangePower + shooter.EquippedWeapons[shooter.ActiveWeaponIndex].WeaponDamage;
                        }
                        float reduction = (damage * ((float)p.Defense / 100f));
                        p.Health -= (long)(damage - reduction);
                        p.LastHit = shooter.Id;
                    }
                }
                proj.RemoveFromSpace = true;
            }
        }
예제 #2
0
 protected void onRobotDamaged(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     active     = true;
     r1.CanSeek = r2.CanSeek = true;
     r1.PhysicsObject.CollisionInformation.Events.InitialCollisionDetected -= onRobotDamaged;
     r2.PhysicsObject.CollisionInformation.Events.InitialCollisionDetected -= onRobotDamaged;
 }
예제 #3
0
 protected override void OnCollisionEnded(Collider other, CollidablePairHandler handler)
 {
     if (other.Owner.Name == "Ground" || other.Owner.Name == "Box")
     {
         Grounded = false;
     }
 }
예제 #4
0
 void Events_ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
 {
     if (TheRegion.GlobalTickTimeLocal - lastSoundTime < soundmaxrate)
     {
         return;
     }
     lastSoundTime = TheRegion.GlobalTickTimeLocal;
     if (other is FullChunkObject)
     {
         ((ConvexFCOPairHandler)pair).ContactInfo(/*contact.Id*/ 0, out ContactInformation info);
         float vellen = (float)(Math.Abs(info.RelativeVelocity.X) + Math.Abs(info.RelativeVelocity.Y) + Math.Abs(info.RelativeVelocity.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         Location      block = new Location(contact.Position - contact.Normal * 0.01f);
         BlockInternal bi    = TheRegion.GetBlockInternal(block);
         MaterialSound sound = ((Material)bi.BlockMaterial).Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound, mod, 0.5f * mod);
         }
         MaterialSound sound2 = Mat.Sound();
         if (sound2 != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound2, mod, 0.5f * mod);
         }
     }
     else if (other is EntityCollidable)
     {
         BEPUphysics.Entities.Entity e        = ((EntityCollidable)other).Entity;
         BEPUutilities.Vector3       velocity = BEPUutilities.Vector3.Zero;
         if (e != null)
         {
             velocity = e.LinearVelocity;
         }
         BEPUutilities.Vector3 relvel = Body.LinearVelocity - velocity;
         float vellen = (float)(Math.Abs(relvel.X) + Math.Abs(relvel.Y) + Math.Abs(relvel.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         MaterialSound sound = Mat.Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(new Location(contact.Position), sound, mod, 0.5f * mod);
         }
     }
 }
예제 #5
0
        private void ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
        {
            Box weapon = sender.Entity as Box;

            if (weapon != null)
            {
                var otherEntityInformation = other as EntityCollidable;
                if (otherEntityInformation != null)
                {
                    Player p = otherEntityInformation.Entity.Tag as Player;
                    if (p != null)
                    {
                        Weapon tempo = pickupWeapon(Convert.ToInt64(weapon.Tag));
                        if (tempo != null)
                        {
                            p.addWeapon(tempo);
                        }
                        AIPlayer p2 = p as AIPlayer;
                        if (p2 != null)
                        {
                            p2.gotWeapon = true;
                        }
                    }
                }
            }
        }
예제 #6
0
 protected override void OnInitialCollisionDetected(Collider other, CollidablePairHandler handler)
 {
     if (other.Owner.Name == "Ground" || other.Owner.Name == "Box")
     {
         Grounded = true;
     }
 }
 ///<summary>
 /// Initializes the constraint.
 ///</summary>
 ///<param name="a">First entity of the pair.</param>
 ///<param name="b">Second entity of the pair.</param>
 ///<param name="newPair">Pair owning this constraint.</param>
 public virtual void Initialize(Entity a, Entity b, CollidablePairHandler newPair)
 {
     //This should only be called before the constraint has been added to the solver.
     entityA = a;
     entityB = b;
     pair    = newPair;
     OnInvolvedEntitiesChanged();
 }
예제 #8
0
 protected override void OnContactCreated(Collider other, CollidablePairHandler handler, ContactData contact)
 {
     if (other.Owner.Name == "Player")
     {
         HoBGameScene.ComesFromMenu = false;
         GameEngine.Instance.InitializeScene <HoBGameScene>();
     }
 }
예제 #9
0
        } // OnCollisionEnded

        /// <summary>
        /// When a collision is still occurring fire the proper handler in every script attached to the game object
        /// </summary>
        private void OnPairTouched(EntityCollidable entity, Collidable collidable, CollidablePairHandler pair)
        {
            foreach (var script in Owner.Scripts)
            {
                GameObject3D go = (GameObject3D)collidable.Tag;
                script.OnCollisionStay(go, pair.Contacts);
            }
        } // OnPairTouched
예제 #10
0
 protected override void OnContactCreated(Collider other, CollidablePairHandler handler, ContactData contact)
 {
     if ((other.Owner.Name == "Player" || other.Owner.Name == "Enemy") && handler.Contacts.Count == 1
         ) //Only if thats the first contact
     {
         Vector3 force = Vector3.UnitY * 5000;
         other.PhysicsCollider.ApplyLinearImpulse(ref force);
     }
 }
예제 #11
0
 protected override void OnContactCreated(Collider other, CollidablePairHandler handler, ContactData contact)
 {
     if (other.Owner.Name == "BulletPlayer")
     {
         hp--;
         Logger.Log(DebugChannel.Log, "Current Enemy HP: " + hp, 5);
         other.Owner.Destroy();
     }
 }
예제 #12
0
        /// <summary>
        /// Internal Function that is redirecting the Event but checking if the object has been woken up first
        /// </summary>
        /// <param name="other">The other game object</param>
        /// <param name="handler">The Handler Containing Collision Data</param>
        internal void onContactCreated(Collider other, CollidablePairHandler handler, ContactData contact)
        {
            if (!_awake)
            {
                Awake();
                _awake = true;
            }

            OnContactCreated(other, handler, contact);
        }
예제 #13
0
        /// <summary>
        /// Internal Function that is redirecting the Event but checking if the object has been woken up first
        /// </summary>
        /// <param name="other">The other game object</param>
        /// <param name="handler">The Handler Containing Collision Data</param>
        internal void onCollisionEnded(Collider other, CollidablePairHandler handler)
        {
            if (!_awake)
            {
                Awake();
                _awake = true;
            }

            OnCollisionEnded(other, handler);
        }
예제 #14
0
        /// <summary>
        /// Internal Function that is redirecting the Event but checking if the object has been woken up first
        /// </summary>
        /// <param name="other">The other game object</param>
        /// <param name="handler">The Handler Containing Collision Data</param>
        internal void onInitialCollisionDetected(Collider other, CollidablePairHandler handler)
        {
            if (!_awake)
            {
                Awake();
                _awake = true;
            }

            OnInitialCollisionDetected(other, handler);
        }
예제 #15
0
 void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
 {
     if (soundEffect != null)
     {
         emitter.Position  = body.Position / 5.0f;
         listener.Position = XNAGame.Instance.Camera.Position / 5.0f;
         soundEffectInstance.Apply3D(listener, emitter);
         soundEffectInstance.Play();
     }
 }
예제 #16
0
        /// <summary>
        /// Internal Function that is redirecting the Event but checking if the object has been woken up first
        /// </summary>
        /// <param name="other">The other game object</param>
        /// <param name="handler">The Handler Containing Collision Data</param>
        /// <param name="contact">The Contact point that was removed</param>
        internal void InternalOnContactRemoved(Collider other, CollidablePairHandler handler, ContactData contact)
        {
            if (!awake)
            {
                Awake();
                awake = true;
            }

            OnContactRemoved(other, handler, contact);
        }
예제 #17
0
 protected override void OnContactCreated(Collider other, CollidablePairHandler handler, ContactData contact)
 {
     if (other.Owner.Name == "BulletEnemy")
     {
         hp--;
         OnHPChange?.Invoke(hp / (float)maxHP);
         Logger.Log(DebugChannel.Log, "Current Player HP: " + hp, 5);
         other.Owner.Destroy();
     }
 }
예제 #18
0
        protected void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            GameEntity ge = other.Tag as GameEntity;

            if (ge != null && ge.Name == "punch")
            {
                Game.PunchProp();
                Entity.Dead = true;
            }
        }
예제 #19
0
        protected void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            GameEntity ge = other.Tag as GameEntity;

            if (ge != null && ge.Name == "player")
            {
                Game.DrinkBeer(physicalData.Position);
                Entity.KillEntity();
            }
        }
예제 #20
0
 public void OnPairTouching(Collidable other, CollidablePairHandler collisionPair)
 {
     if (InternalPairTouched != null)
     {
         eventStoragePairTouched.Enqueue(new EventStoragePairTouched(other, collisionPair));
     }
     if (PairTouching != null)
     {
         PairTouching(owner, other, collisionPair);
     }
 }
예제 #21
0
 public void OnInitialCollisionDetected(Collidable other, CollidablePairHandler collisionPair)
 {
     if (InternalInitialCollisionDetected != null)
     {
         eventStorageInitialCollisionDetected.Enqueue(new EventStorageInitialCollisionDetected(other, collisionPair));
     }
     if (DetectingInitialCollision != null)
     {
         DetectingInitialCollision(owner, other, collisionPair);
     }
 }
예제 #22
0
 public static bool PairIsColliding(CollidablePairHandler pair)
 {
     foreach (var contactInformation in pair.Contacts)
     {
         if (contactInformation.Contact.PenetrationDepth >= 0)
         {
             return(true);
         }
     }
     return(false);
 }
 public void CollisionEnded(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
 {
     if (other == acceptedTrigger)
     {
         //If the detector ceases to collide, get rid of the spawned box.
         movedBox.Position        = new Vector3(-4, 5, 0);
         movedBox.Orientation     = Quaternion.Identity;
         movedBox.LinearVelocity  = Vector3.Zero;
         movedBox.AngularVelocity = Vector3.Zero;
     }
 }
예제 #24
0
 public void OnCollisionEnded(Collidable other, CollidablePairHandler collisionPair)
 {
     if (InternalCollisionEnded != null)
     {
         eventStorageCollisionEnded.Enqueue(new EventStorageCollisionEnded(other, collisionPair));
     }
     if (CollisionEnding != null)
     {
         CollisionEnding(owner, other, collisionPair);
     }
 }
예제 #25
0
        protected override void OnInitialCollisionDetected(Collider other, CollidablePairHandler handler)
        {
            //if (other.Owner.Name == "Ground")
            //{

            //    Collider.PhysicsCollider.Gravity = null;
            //    RigidBodyConstraints constraints = Collider.ColliderConstraints;
            //    constraints.PositionConstraints = FreezeConstraints.Y;
            //    Collider.ColliderConstraints = constraints;
            //}
        }
        private void CollidedWith(EntityCollidable sender, Collidable other, CollidablePairHandler pair)//compares the tags of collided objects and sets the bool to be true if the target touches the dart
        {
            if (other.Tag is PhysicsComponent.GameObjectInfo)
            {
                var tag = (other.Tag as PhysicsComponent.GameObjectInfo);

                if (tag.ObjectType == typeof(MovingTarget1) || tag.ObjectType == typeof(Dart))
                {
                    wasHit = true;
                }
            }
        }
예제 #27
0
        void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            try {
                Game.Services.GetService <Space>().Remove(sender.Entity);
                Game.Components.Remove(this);

                var otherEntityInformation = other as EntityCollidable;

                if (otherEntityInformation.Tag == null)
                {
                    return;
                }

                Vector3 pos = new Vector3(physicsObject.Position.X, physicsObject.Position.Y, physicsObject.Position.Z);


                if (otherEntityInformation.Tag.GetType() == typeof(LargeAsteroid))
                {
                    Game.Services.GetService <Space>().Remove(otherEntityInformation.Entity);
                    Game.Components.Remove((LargeAsteroid)otherEntityInformation.Tag);

                    Random rnd = new Random();
                    new MediumAsteroid(game, pos, 1, new Vector3(rnd.Next(0, 10), rnd.Next(0, 10), rnd.Next(0, 10)));
                    new MediumAsteroid(game, pos, 1, new Vector3(rnd.Next(0, 10), rnd.Next(0, 10), rnd.Next(0, 10)));

                    game.totalAsteroidScore--;
                    game.boomInstance.Play();
                }

                if (otherEntityInformation.Tag.GetType() == typeof(MediumAsteroid))
                {
                    Game.Services.GetService <Space>().Remove(otherEntityInformation.Entity);
                    Game.Components.Remove((MediumAsteroid)otherEntityInformation.Tag);

                    Random rnd = new Random();
                    new SmallAsteroid(game, pos, 1, new Vector3(rnd.Next(0, 10), rnd.Next(0, 10), rnd.Next(0, 10)));

                    game.totalAsteroidScore--;
                    game.boomInstance.Play();
                }

                if (otherEntityInformation.Tag.GetType() == typeof(SmallAsteroid))
                {
                    Game.Services.GetService <Space>().Remove(otherEntityInformation.Entity);
                    Game.Components.Remove((SmallAsteroid)otherEntityInformation.Tag);

                    game.totalAsteroidScore--;
                    game.boomInstance.Play();
                }
            }
            catch (ArgumentException) {
            }
        }
        private void CollidedWith(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            if (other.Tag is PhysicsComponent.GameObjectInfo)
            {
                var tag = (other.Tag as PhysicsComponent.GameObjectInfo);

                if (tag.ObjectType == typeof(Target2) || tag.ObjectType == typeof(Dart))
                {
                    wasHit = true;
                }
            }
        }
예제 #29
0
        protected void onCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
        {
            EntityCollidable e = other as EntityCollidable;

            if (e != null)
            {
                Player player = e.Entity.Tag as Player;
                if (player != null)
                {
                    player.Damage(MathHelper.Clamp((float)random.NextDouble() * random.Next(damage - 1, damage + 2), 1, 7), this);
                }
            }
            onDeath(this);
        }
예제 #30
0
        public void CollisionEndHandler(EntityCollidable sender, Collidable other, CollidablePairHandler collisionPair)
        {
            var otherTag = other.Tag as IEntityTag;

            if (null == otherTag)
            {
                return;
            }

            if (!this.endedCollisions.Contains(otherTag.EntityID))
            {
                this.endedCollisions.Add(otherTag.EntityID);
            }
        }