///<summary> ///Callback for when the microbe collides with another object. ///</summary> ///<param name="ourObject">The microbe.</param> ///<param name="theirObject">The other object.</param> ///<param name="info">Information about the collision point.</param> ///<param name="resolve">Not used.</param> ///<param name="physicsMaterial"> ///The physics properties of the objects. ///</param> public void OnCollision( T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { if (!ourObject.MarkForDelete && theirObject.TestObjectType(_collidesWith)) { //handle microbe collision with another microbe if (theirObject.TestObjectType( TorqueObjectDatabase.Instance.GetObjectType("microbe"))) { T2DPhysicsComponent.BounceCollision.Invoke( ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.ClampCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.KillCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.RigidCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.StickyCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); } else if (theirObject.TestObjectType( TorqueObjectDatabase.Instance.GetObjectType("projectile"))) { //T2DPhysicsComponent.BounceCollision.Invoke( // ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.ClampCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); T2DPhysicsComponent.KillCollision.Invoke( ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.RigidCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); //T2DPhysicsComponent.StickyCollision.Invoke( //ourObject, theirObject, ref info, physicsMaterial, false); } //TODO: add handling for other object types } }
/// <summary> /// T2DOnCollision delegate to handle damage between the melee scene object and enemies /// </summary> /// <param name="myObject">The melee scene object mounted on the player</param> /// <param name="theirObject">The enemy scene object</param> /// <param name="info">Collision information</param> /// <param name="resolve">How the collision will be resolved</param> /// <param name="physicsMaterial">The type of material that would affect the physics</param> public static void MeleeCollision(T2DSceneObject myObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { int damage = myObject.Components.FindComponent<AttackCollisionComponent>().Damage; if (theirObject.TestObjectType(PlatformerData.PlayerObjectType)) { PlayerActorComponent actor = theirObject.Components.FindComponent<PlayerActorComponent>(); // Deal damage to the enemy if (actor != null) actor.TakeDamage(damage, myObject, true, true); } myObject.MarkForDelete = true; }
public static void ProjCollision(T2DSceneObject projectile, T2DSceneObject targetObject, T2DCollisionInfo into, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial material) { int damage = projectile.Components.FindComponent<ProjectileComponent>().Damage; if (targetObject.TestObjectType(PlatformerData.ActorObjectType)) { PlayerActorComponent actor = targetObject.Components.FindComponent<PlayerActorComponent>(); // Deal damage to the enemy if (actor != null) actor.TakeDamage(damage, projectile, true, true); } projectile.CollisionsEnabled = false; projectile.MarkForDelete = true; }
/// <summary> /// T2DOnCollision delegate to handle damage between the kushling and the player /// </summary> /// <param name="myObject">The kushling</param> /// <param name="theirObject">The collided object.</param> /// <param name="info">Collision information</param> /// <param name="resolve">How the collision will be resolved</param> /// <param name="physicsMaterial">The type of material that would affect the physics</param> public static void KushCollision(T2DSceneObject myObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { int damage = myObject.Components.FindComponent<KushlingActorComponent>().Damage; if (theirObject.TestObjectType(PlatformerData.ActorObjectType)) { PlayerActorComponent actor = theirObject.Components.FindComponent<PlayerActorComponent>(); // Deal damage to the enemy if (actor != null && !actor.IsInvincible) actor.TakeDamage(damage, myObject, true, true); } else if (theirObject.TestObjectType(PlatformerData.EnemyObjectType)) { resolve = T2DPhysicsComponent.ClampCollision; } else resolve = null; }
/// <summary> /// Callback for when the projectile collides with another object. /// </summary> /// <param name="ourObject">The projectile.</param> /// <param name="theirObject">The other object.</param> /// <param name="info">Information about the collision point.</param> /// <param name="resolve">Not used.</param> /// <param name="physicsMaterial">The physics properties of the objects.</param> public void OnCollision( T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { if (!ourObject.MarkForDelete && theirObject.TestObjectType(_collidesWith)) { // If we hit a player object then activate its game pad vibration T2DStaticSprite psprite = theirObject as T2DStaticSprite; if (psprite != null) { GamepadVibrationComponent vib = psprite.Components.FindComponent<GamepadVibrationComponent>(); if (vib != null) { vib.SetLowSpeedVibration(0.1f, 0.8f); } } if (theirObject.TestObjectType(TorqueObjectDatabase.Instance.GetObjectType("tank"))) { Explode(info, true); } else { Explode(info, false); } } }
/// <summary> /// T2DOnCollision delegate to handle damage between the melee scene object and enemies /// </summary> /// <param name="myObject">The melee scene object mounted on the player</param> /// <param name="theirObject">The enemy scene object</param> /// <param name="info">Collision information</param> /// <param name="resolve">How the collision will be resolved</param> /// <param name="physicsMaterial">The type of material that would affect the physics</param> public static void MeleeCollision(T2DSceneObject myObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>(); int damage = myObject.Components.FindComponent<AttackCollisionComponent>().Damage; // Deal damage to the enemy if(actor != null) actor.TakeDamage(damage, myObject, true, true); myObject.MarkForDelete = true; }
public virtual void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { // call our custom collision resolve // (this is almost exactly the same as clamp, but takes *both* objects' velocity into account) if (theirObject.TestObjectType(PlatformerData.PlatformObjectType)) resolve = ResolveActorCollision; else resolve = null; // if we hit a ladder, enable it if (theirObject.TestObjectType(PlatformerData.LadderObjectType)) { // find the ladder component LadderComponent ladder = theirObject.Components.FindComponent<LadderComponent>(); // enable it if (ladder != null) ladder.Enabled = true; } }
public void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { // call our local trigger OnEnter method _onEnter(ourObject, theirObject, info); }
public override void Dispose() { _IsDisposed = true; if (_collisionImages != null) _collisionImages.Clear(); _collisionImages = null; if (_collisionMaterial != null) _collisionMaterial.Dispose(); _collisionMaterial = null; _onCollision = null; _ResetRefs(); _resolveCollisionDelegate = null; _testEarlyOut = null; base.Dispose(); }
public override void Dispose() { _IsDisposed = true; _onWorldLimit = null; _worldLimitResolveCollision = null; base.Dispose(); }
///<summary> ///Callback for when the tank collides with another object. ///</summary> ///<param name="ourObject">The tank.</param> ///<param name="theirObject">The other object.</param> ///<param name="info">Information about the collision point.</param> ///<param name="resolve">Not used.</param> ///<param name="physicsMaterial"> ///The physics properties of the objects. ///</param> public void OnCollision( T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { if (ourObject.MarkForDelete || !theirObject.TestObjectType(_collidesWith)) return; //Set up gamepad vibration if this is a player object //also set up maxVelocity GamepadVibrationComponent vib = ourObject.Components.FindComponent<GamepadVibrationComponent>(); TankMovementComponent mac = ourObject.Components.FindComponent<TankMovementComponent>(); float maxSpeed = 0.1f; //avoid possible divide by zero below if (null != mac) { maxSpeed = mac.MaxForwardSpeed; } //Calculate Impact Velocity. Vector2 deltaImpactVelocity = _CalculateImpactVelocity(ourObject, theirObject, info); float impact = deltaImpactVelocity.Length(); float vibration = MathHelper.Clamp((impact / (maxSpeed * 2.0f)), 0.0f, 1.0f); //Perform sound (on all objects) and vibration (players only) if (vibration < 0.3) { //High speed vibration for the small collisions if (vib != null) { vib.SetHighSpeedVibration(0.2f, (vibration / 0.3f) * 0.8f); } if (vibration >= 0.1 && TorqueEngineComponent.Instance.TorqueTime >= _nextSoftSoundPlayTime) { Program.SoundBank.PlayCue("softCollision"); _nextSoftSoundPlayTime = TorqueEngineComponent.Instance.TorqueTime + SOUND_TIME_STEP + TorqueUtil.GetFastRandomFloat(SOUND_TIME_STEP_VARIANCE); } } else { //Low speed vibration for the big collisions if (vib != null) { vib.SetLowSpeedVibration( 0.2f, ((vibration - 0.3f) / 0.7f) * 0.9f + 0.1f); } if (TorqueEngineComponent.Instance.TorqueTime >= _nextHardSoundPlayTime) { Program.SoundBank.PlayCue("hardCollision"); _nextHardSoundPlayTime = TorqueEngineComponent.Instance.TorqueTime + SOUND_TIME_STEP + TorqueUtil.GetFastRandomFloat(SOUND_TIME_STEP_VARIANCE); } } }
private static void PlayerCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { if (theirObject is T2DAnimatedSprite) { var player = (T2DAnimatedSprite) TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("Player1"); var aiPlayer = (T2DAnimatedSprite) TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("Player2"); if (player.AnimationData.Name.Contains("SpecialMove")) { Game.Instance.AiHealth -= 2.5; } else if (aiPlayer.AnimationData.Name.Contains("SpecialMove")) { Game.Instance.PlayerHealth -= 2.5; } } }
/// <summary> /// T2DOnCollision delegate to handle damage between the melee scene object and enemies /// </summary> /// <param name="myObject">The melee scene object mounted on the player</param> /// <param name="theirObject">The enemy scene object</param> /// <param name="info">Collision information</param> /// <param name="resolve">How the collision will be resolved</param> /// <param name="physicsMaterial">The type of material that would affect the physics</param> public static void MeleeCollision(T2DSceneObject myObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial) { //theirObject.Collision.Images[0]. int damage = myObject.Components.FindComponent<AttackCollisionComponent>().Damage; if(theirObject.TestObjectType(PlatformerData.ActorObjectType)) { EnemyActorComponent actor = theirObject.Components.FindComponent<EnemyActorComponent>(); // Deal damage to the enemy if (actor != null) actor.TakeDamage(damage, theirObject); } else { WeakSpotComponent weakSpot = theirObject.Components.FindComponent<WeakSpotComponent>(); if(weakSpot != null) weakSpot.TakeDamage(damage, true); } myObject.MarkForDelete = true; }