/// <summary> /// Transitions the camera to the given target. /// </summary> /// <param name="target">The object we want the camera to view.</param> /// <param name="transitionTime">The amount of time it will take to transition /// to the target object. </param> public void MoveToTarget(T2DSceneObject target, float transitionTime) { if(camera.IsMounted) camera.Dismount(); camera.AnimatePosition((target.Position + mountOffset), transitionTime); camera.Mount(target, String.Empty, camera.AnimatePositionTarget, 0.0f, true); }
/// <summary> /// Turns the object invisible (if it isn't already) and disables all collision. /// </summary> /// <param name="puzzleObject">The object to make disappear.</param> public override void Execute(T2DSceneObject puzzleObject) { T2DStaticSprite sprite = puzzleObject as T2DStaticSprite; if (sprite != null) { newColor = new Color(255, 0, 0, 0); SimpleMaterial material = TorqueObjectDatabase.Instance.FindObject<SimpleMaterial>(sprite.Material.Name); if (material == null) return; Texture2D tex = material.Texture.Instance as Texture2D; SurfaceFormat format = tex.Format; int numPixels = tex.Width * tex.Height; Color[] data = new Color[numPixels]; if (tex.GraphicsDevice.Textures[0] == tex) tex.GraphicsDevice.Textures[0] = null; tex.GetData<Color>(data); for (int i = 0; i < numPixels; ++i) { Color c = data[i]; c = newColor; data[i] = c; } tex.SetData<Color>(data); } active = false; }
/// <summary> /// Returns the camera back to the player. Only to be used after all camera /// transitioning is done /// </summary> /// <param name="player">The player.</param> /// <param name="transitionTime">The amount of time it will to take to transition /// to the player</param> public void ReturnToPlayer(T2DSceneObject player, float transitionTime) { camera.AnimatePosition((player.Position + new Vector2(0, -1)), transitionTime); camera.Mount(player, String.Empty, new Vector2(0, -1), 0.0f, true); camera.UseMountForce = true; camera.MountForce = 15; }
public override void Execute(T2DSceneObject puzzleObject) { if (sfxName != "") SoundManager.Instance.PlaySound("sounds", sfxName); active = false; }
public override void Execute(GarageGames.Torque.T2D.T2DSceneObject puzzleObject) { this.puzzleObject = puzzleObject; ProcessList.Instance.AddTickCallback(puzzleObject, this); active = false; degrees = 0; }
public static void ResolveCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, ref T2DCollisionInfo info, T2DCollisionMaterial material, bool handleBoth) { theirObject.Physics.Velocity = Vector2.Zero; ourObject.Physics.Velocity = Vector2.Zero; ourObject.MarkForDelete = true; }
protected override bool _confirmPickup(T2DSceneObject ourObject, T2DSceneObject theirObject, ActorComponent actor) { base._confirmPickup(ourObject, theirObject, actor); if(actor is PlayerActorComponent) { if(ourObject.TestObjectType(PlatformerData.SpawnedObjectType)) { CheckpointSystemSpawnedObjectComponent spawnedComp = ourObject.Components.FindComponent<CheckpointSystemSpawnedObjectComponent>(); if(spawnedComp != null) spawnedComp.Recover = false; } // Play sound effect here! SoundManager.Instance.PlaySound("sounds", "checkpoint"); CheckpointManager.Instance.CheckpointReached(); // set the new respawn position of the actor if (SceneObject != null) actor.RespawnPosition = SceneObject.Position; else actor.RespawnPosition = actor.Actor.Position; //GUICanvas.Instance.SetContentControl(new Checkpoint_GUI(SceneObject.Position + new Vector2(0, -5))); effect.Spawn(SceneObject.Position); // true = yes, i was picked up. delete me! return true; } // false = no, this guy didn't pick me up. return false; }
/// <summary> /// _confirmDamage callback. Optionally override this in a child class to only deal damage to specific actors. Returns true by default /// (i.e. deals damage to any Actor). /// </summary> /// <param name="ourObject">The scene object this HazardComponent is on.</param> /// <param name="theirObject">The scene object the ActorComponent is on.</param> /// <param name="actor">The ActorComponent on the scene object that entered the trigger.</param> /// <returns>True if the HazardComponent should deal damage to the Actor.</returns> protected virtual bool _confirmDamage(T2DSceneObject ourObject, T2DSceneObject theirObject, ActorComponent actor) { // this should be overridden by derived classes // a return value of false will result in the damage not being applied // a return value of true will result in the damage being applied return true; }
/// <summary> /// Turns the object invisible (if it isn't already) and disables all collision. /// </summary> /// <param name="puzzleObject">The object to make disappear.</param> public override void Execute(T2DSceneObject puzzleObject) { obj = puzzleObject; puzzleObject.CollisionsEnabled = false; //puzzleObject.Visible = false; active = false; ProcessList.Instance.AddTickCallback(puzzleObject, this); }
/// <summary> /// Adds the object and an associated scrolling magnitude the pool /// of parallax objects to update. /// </summary> /// <param name="obj">The scene object to include in parallax scrolling.</param> /// <param name="magnitude">The scrolling magnitude of the object.</param> public void AddParallaxObj(T2DSceneObject obj, float magnitude) { ParallaxObject pObj; pObj.ObjectPtr = obj; pObj.Magnitude = magnitude; parallaxObjects.Add(pObj); }
public static void EtherealCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, ref T2DCollisionInfo info, T2DCollisionMaterial material, bool handleBoth) { // Start player's flashing animation to indicate she was hit. PlayerActorComponent actor = theirObject.Components.FindComponent<PlayerActorComponent>(); if (actor != null && !actor.IsInvincible) actor.ApplyDamageEffects(); }
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>(); if (actor == null) return; actor.Kill(Owner as T2DSceneObject); }
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { TrapComponent trapComponent = trapObject.Components.FindComponent<TrapComponent>(); trapComponent.Activate(); ourObject.CollisionsEnabled = false; ourObject.MarkForDelete = true; }
/// <summary> /// Mounts the particle to the given scene object. /// </summary> /// <param name="mounter">The object to mount the particle to.</param> public void MountTo(T2DSceneObject mounter) { mountedParticle = particleTemplate.Clone() as T2DParticleEffect; if (mountedParticle != null) { TorqueObjectDatabase.Instance.Register(mountedParticle); mountedParticle.Mount(mounter, linkPoint, true); } }
public override void Execute(T2DSceneObject puzzleObject) { this.puzzleObject = puzzleObject; origPosition = this.puzzleObject.Position; this.puzzleObject.Physics.VelocityX = xSpeed * (xDistance / Math.Abs(xDistance)); this.puzzleObject.Physics.VelocityY = ySpeed * (yDistance / Math.Abs(yDistance)); ProcessList.Instance.AddTickCallback(puzzleObject, this); active = false; }
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>(); if (actor == null) return; if (_confirmDamage(ourObject, theirObject, actor)) actor.TakeDamage(_damage, ourObject); }
/// <summary> /// Decides whether or not the Actor should be allowed to pick this collectible up. Override this /// in derived classes. Default always returns true. /// </summary> /// <param name="ourObject">The scene object this CollectibleComponent is on.</param> /// <param name="theirObject">The scene object the ActorComponent is on.</param> /// <param name="actor">The ActorComponent that's trying to pick up this collectible.</param> /// <returns>True if the Actor should be allowed to pick up the collectible.</returns> protected virtual bool _confirmPickup(T2DSceneObject ourObject, T2DSceneObject theirObject, ActorComponent actor) { if(theirObject.TestObjectType(PlatformerData.PlayerObjectType)) if(effect != null) effect.Spawn(SceneObject.Position); // this should be overridden by derived classes // a return value of false will result in the collectible remaining in the scene // a return value of true will result in the collectible being removed from the scene return true; }
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { PlayerActorComponent player = theirObject.Components.FindComponent<PlayerActorComponent>(); if (player == null) return; else player.SwitchToFallDeath(); base._onEnter(ourObject, theirObject, info); }
public void OnLeaveLadder(T2DSceneObject ourObject, T2DSceneObject theirObject) { // notify the actor they are no longer in the ladder ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>(); if (actor != null) actor.LadderObject = null; // disable the trigger when all actors leave if (_objectList.Count == 0 && _ladder.Collision != null) Enabled = false; }
protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { BairneActorComponent actor = theirObject.Components.FindComponent<BairneActorComponent>(); if (actor != null) { actor.OnLeft = onLeft; actor.ReachedBound = true; actor.HorizontalStop(); } else ;//log error }
/// <summary> /// The routine run when the player collides with the object. /// </summary> /// <param name="ourObject">The trigger object.</param> /// <param name="theirObject">The player that collided with the trigger.</param> /// <param name="info">Some sort of info...</param> protected override void _onEnter(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info) { if (!flipped) { switchedOn = !switchedOn; if (behaviors != null) foreach (ISwitchBehavior behavior in behaviors) behavior.Execute(ourObject, switchedOn); flipped = true; } }
public void OnStayLadder(T2DSceneObject ourObject, T2DSceneObject theirObject) { // make sure the object is an actor type if (!theirObject.TestObjectType(PlatformerData.ActorObjectType)) return; // grab the actor component ActorComponent actor = theirObject.Components.FindComponent<ActorComponent>(); // notify the actor that they are in a ladder and give them a reference if (actor != null && !actor.InLadder) actor.LadderObject = _ladder; }
/// <summary> /// Accelerated version of CheckSceneObjectBins for T2D. /// </summary> /// <param name="obj">Object to check.</param> public void CheckSceneObjectBinsT2D(T2DSceneObject obj) { // Check everything is fine! Assert.Fatal(obj != null, "Invalid Object"); // Get the object's SceneContainerData SceneContainerData scd = obj.SceneContainerData; // Find which bins we cover. uint minBinX, minBinY, maxBinX, maxBinY; _GetBins(obj.WorldClipRectangle, out minBinX, out minBinY, out maxBinX, out maxBinY); _CheckSceneObjectBins(obj, scd, minBinX, minBinY, maxBinX, maxBinY); }
///<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 Vector2 ConvertLinkPointToWorld(T2DSceneObject gameObject, string linkPointName) { Vector2 linkPosition; float rotation; if (gameObject.LinkPoints.HasLinkPoint(linkPointName)) { gameObject.LinkPoints.GetLinkPoint(linkPointName, out linkPosition, out rotation); float x = (gameObject.WorldClipRectangle.Width / 2) * linkPosition.X; float y = (gameObject.WorldClipRectangle.Height / 2) * linkPosition.Y; return new Vector2(x, y); } return Vector2.Zero; }
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; }
public override bool TakeDamage(float damage, T2DSceneObject sourceObject) { if(!Alive) return false; float startHealth = _health; _health -= damage; _health = MathHelper.Clamp(_health, 0, _maxHealth); if (_health == 0) _die(startHealth - _health, sourceObject); else _tookDamage(startHealth - _health, sourceObject); return true; }
protected override bool _OnRegister(TorqueObject owner) { if (!base._OnRegister(owner)) return false; _sceneObject = owner as T2DSceneObject; if (_sceneObject.Collision == null) Assert.Fatal(false, "TriggerComponent requires a T2DCollisionComponent. Please add these components to your trigger.\n\nTrigger position: " + _sceneObject.Position.ToString()); // make sure the collision component has at least one image if (_sceneObject.Collision.Images.Count == 0) _sceneObject.Collision.InstallImage(new T2DPolyImage()); // make sure the collision and physics settigns are correct _sceneObject.Collision.OnCollision = OnCollision; _sceneObject.Collision.CollidesWith = TorqueObjectType.NoObjects; _sceneObject.Collision.SolveOverlap = false; _sceneObject.CollisionsEnabled = true; return 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; }