public void Update(float deltaTime) { UpdateProjSpecific(deltaTime); if (LinearVelocity.X > 500.0f) { //DebugConsole.ThrowError("CHARACTER EXPLODED"); body.ResetDynamics(); body.SetTransform(character.SimPosition, 0.0f); } if (inWater) { body.ApplyWaterForces(); } if (isSevered) { severedFadeOutTimer += deltaTime; if (severedFadeOutTimer > SeveredFadeOutTime) { body.Enabled = false; } } if (character.IsDead) { return; } SoundTimer -= deltaTime; }
public LevelTrigger(XElement element, Vector2 position, float rotation, float scale = 1.0f) { physicsBody = new PhysicsBody(element, scale); physicsBody.CollisionCategories = Physics.CollisionLevel; physicsBody.CollidesWith = Physics.CollisionCharacter | Physics.CollisionItem | Physics.CollisionProjectile | Physics.CollisionWall; physicsBody.FarseerBody.OnCollision += PhysicsBody_OnCollision; physicsBody.FarseerBody.OnSeparation += PhysicsBody_OnSeparation; physicsBody.FarseerBody.IsSensor = true; physicsBody.FarseerBody.IsStatic = true; physicsBody.FarseerBody.IsKinematic = true; physicsBody.SetTransform(ConvertUnits.ToSimUnits(position), rotation); cameraShake = element.GetAttributeFloat("camerashake", 0.0f); force = element.GetAttributeVector2("force", Vector2.Zero); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "statuseffect": statusEffects.Add(StatusEffect.Load(subElement)); break; case "attack": case "damage": attacks.Add(new Attack(subElement)); break; } } }
public void Update(float deltaTime) { if (LightSource != null) { LightSource.ParentSub = body.Submarine; } if (!character.IsDead) { damage = Math.Max(0.0f, damage - deltaTime * 0.1f); } if (burnt > 0.0f) { Burnt -= deltaTime; } if (LinearVelocity.X > 500.0f) { //DebugConsole.ThrowError("CHARACTER EXPLODED"); body.ResetDynamics(); body.SetTransform(character.SimPosition, 0.0f); } if (inWater) { body.ApplyWaterForces(); } if (character.IsDead) { return; } soundTimer -= deltaTime; //if (MathUtils.RandomFloat(0.0f, 1000.0f) < Bleeding) //{ // Game1.particleManager.CreateParticle( // !inWater ? "blood" : "waterblood", // SimPosition, Vector2.Zero); //} }
public void SetPosition(Vector2 position) { Body.SetTransform(ConvertUnits.ToSimUnits(position), 0.0f); }
public LevelTrigger(XElement element, Vector2 position, float rotation, float scale = 1.0f, string parentDebugName = "") { TriggererPosition = new Dictionary <Entity, Vector2>(); worldPosition = position; if (element.Attributes("radius").Any() || element.Attributes("width").Any() || element.Attributes("height").Any()) { physicsBody = new PhysicsBody(element, scale) { CollisionCategories = Physics.CollisionLevel, CollidesWith = Physics.CollisionCharacter | Physics.CollisionItem | Physics.CollisionProjectile | Physics.CollisionWall }; physicsBody.FarseerBody.OnCollision += PhysicsBody_OnCollision; physicsBody.FarseerBody.OnSeparation += PhysicsBody_OnSeparation; physicsBody.FarseerBody.IsSensor = true; physicsBody.FarseerBody.IsStatic = true; physicsBody.FarseerBody.IsKinematic = true; ColliderRadius = ConvertUnits.ToDisplayUnits(Math.Max(Math.Max(PhysicsBody.radius, PhysicsBody.width / 2.0f), PhysicsBody.height / 2.0f)); physicsBody.SetTransform(ConvertUnits.ToSimUnits(position), rotation); } cameraShake = element.GetAttributeFloat("camerashake", 0.0f); stayTriggeredDelay = element.GetAttributeFloat("staytriggereddelay", 0.0f); randomTriggerInterval = element.GetAttributeFloat("randomtriggerinterval", 0.0f); randomTriggerProbability = element.GetAttributeFloat("randomtriggerprobability", 0.0f); UseNetworkSyncing = element.GetAttributeBool("networksyncing", false); unrotatedForce = element.Attribute("force") != null && element.Attribute("force").Value.Contains(',') ? element.GetAttributeVector2("force", Vector2.Zero) : new Vector2(element.GetAttributeFloat("force", 0.0f), 0.0f); ForceFluctuationInterval = element.GetAttributeFloat("forcefluctuationinterval", 0.01f); ForceFluctuationStrength = Math.Max(element.GetAttributeFloat("forcefluctuationstrength", 0.0f), 0.0f); ForceFalloff = element.GetAttributeBool("forcefalloff", true); ForceVelocityLimit = ConvertUnits.ToSimUnits(element.GetAttributeFloat("forcevelocitylimit", float.MaxValue)); string forceModeStr = element.GetAttributeString("forcemode", "Force"); if (!Enum.TryParse(forceModeStr, out forceMode)) { DebugConsole.ThrowError("Error in LevelTrigger config: \"" + forceModeStr + "\" is not a valid force mode."); } CalculateDirectionalForce(); string triggeredByStr = element.GetAttributeString("triggeredby", "Character"); if (!Enum.TryParse(triggeredByStr, out triggeredBy)) { DebugConsole.ThrowError("Error in LevelTrigger config: \"" + triggeredByStr + "\" is not a valid triggerer type."); } UpdateCollisionCategories(); triggerOthersDistance = element.GetAttributeFloat("triggerothersdistance", 0.0f); var tagsArray = element.GetAttributeStringArray("tags", new string[0]); foreach (string tag in tagsArray) { tags.Add(tag.ToLower()); } if (triggeredBy.HasFlag(TriggererType.OtherTrigger)) { var otherTagsArray = element.GetAttributeStringArray("allowedothertriggertags", new string[0]); foreach (string tag in otherTagsArray) { allowedOtherTriggerTags.Add(tag.ToLower()); } } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "statuseffect": statusEffects.Add(StatusEffect.Load(subElement, string.IsNullOrEmpty(parentDebugName) ? "LevelTrigger" : "LevelTrigger in " + parentDebugName)); break; case "attack": case "damage": var attack = new Attack(subElement, string.IsNullOrEmpty(parentDebugName) ? "LevelTrigger" : "LevelTrigger in " + parentDebugName); var multipliedAfflictions = attack.GetMultipliedAfflictions((float)Timing.Step); attack.Afflictions.Clear(); foreach (Affliction affliction in multipliedAfflictions) { attack.Afflictions.Add(affliction, null); } attacks.Add(attack); break; } } forceFluctuationTimer = Rand.Range(0.0f, ForceFluctuationInterval); randomTriggerTimer = Rand.Range(0.0f, randomTriggerInterval); }
private void AttachToBody(PhysicsBody collider, Limb attachLimb, Body targetBody, Vector2 attachPos) { //already attached to something if (attachJoints.Count > 0) { //already attached to the target body, no need to do anything if (attachJoints[0].BodyB == targetBody) { return; } DeattachFromBody(); } jointDir = attachLimb.Dir; Vector2 transformedLocalAttachPos = localAttachPos * attachLimb.character.AnimController.RagdollParams.LimbScale; if (jointDir < 0.0f) { transformedLocalAttachPos.X = -transformedLocalAttachPos.X; } //transformedLocalAttachPos = Vector2.Transform(transformedLocalAttachPos, Matrix.CreateRotationZ(attachLimb.Rotation)); float angle = MathUtils.VectorToAngle(-attachSurfaceNormal) - MathHelper.PiOver2 + attachLimbRotation * attachLimb.Dir; attachLimb.body.SetTransform(attachPos + attachSurfaceNormal * transformedLocalAttachPos.Length(), angle); var limbJoint = new WeldJoint(attachLimb.body.FarseerBody, targetBody, transformedLocalAttachPos, targetBody.GetLocalPoint(attachPos), false) { FrequencyHz = 10.0f, DampingRatio = 0.5f, KinematicBodyB = true, CollideConnected = false, }; GameMain.World.AddJoint(limbJoint); attachJoints.Add(limbJoint); // Limb scale is already taken into account when creating the collider. Vector2 colliderFront = collider.GetLocalFront(); if (jointDir < 0.0f) { colliderFront.X = -colliderFront.X; } collider.SetTransform(attachPos + attachSurfaceNormal * colliderFront.Length(), MathUtils.VectorToAngle(-attachSurfaceNormal) - MathHelper.PiOver2); var colliderJoint = new WeldJoint(collider.FarseerBody, targetBody, colliderFront, targetBody.GetLocalPoint(attachPos), false) { FrequencyHz = 10.0f, DampingRatio = 0.5f, KinematicBodyB = true, CollideConnected = false, //Length = 0.1f }; GameMain.World.AddJoint(colliderJoint); attachJoints.Add(colliderJoint); }