private void SetLightTextureOffset() { Vector2 textOffset = textureOffset; if (FlippedX) { textOffset.X = -textOffset.X; } if (FlippedY) { textOffset.Y = -textOffset.Y; } foreach (LightSource light in Lights) { Vector2 bgOffset = new Vector2( MathUtils.PositiveModulo((int)-textOffset.X, light.texture.Width), MathUtils.PositiveModulo((int)-textOffset.Y, light.texture.Height)); light.LightTextureOffset = bgOffset; } }
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) { if (prefab.sprite == null) { return; } if (editing) { if (!HasBody && !ShowStructures) { return; } if (HasBody && !ShowWalls) { return; } } Color color = IsHighlighted ? Color.Orange : spriteColor; if (IsSelected && editing) { //color = Color.Lerp(color, Color.Gold, 0.5f); color = spriteColor; Vector2 rectSize = rect.Size.ToVector2(); if (BodyWidth > 0.0f) { rectSize.X = BodyWidth; } if (BodyHeight > 0.0f) { rectSize.Y = BodyHeight; } Vector2 bodyPos = WorldPosition + BodyOffset; GUI.DrawRectangle(spriteBatch, new Vector2(bodyPos.X, -bodyPos.Y), rectSize.X, rectSize.Y, BodyRotation, Color.White, thickness: Math.Max(1, (int)(2 / Screen.Selected.Cam.Zoom))); } Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; float depth = SpriteDepthOverrideIsSet ? SpriteOverrideDepth : prefab.sprite.Depth; depth -= (ID % 255) * 0.000001f; Vector2 textureOffset = this.textureOffset; if (FlippedX) { textureOffset.X = -textureOffset.X; } if (FlippedY) { textureOffset.Y = -textureOffset.Y; } if (back && damageEffect == null) { if (Prefab.BackgroundSprite != null) { Vector2 dropShadowOffset = Vector2.Zero; if (UseDropShadow) { dropShadowOffset = DropShadowOffset; if (dropShadowOffset == Vector2.Zero) { if (Submarine == null) { dropShadowOffset = Vector2.UnitY * 10.0f; } else { dropShadowOffset = IsHorizontal ? new Vector2(0.0f, Math.Sign(Submarine.HiddenSubPosition.Y - Position.Y) * 10.0f) : new Vector2(Math.Sign(Submarine.HiddenSubPosition.X - Position.X) * 10.0f, 0.0f); } } dropShadowOffset.Y = -dropShadowOffset.Y; } SpriteEffects oldEffects = Prefab.BackgroundSprite.effects; Prefab.BackgroundSprite.effects ^= SpriteEffects; Point backGroundOffset = new Point( MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height)); Prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), color: color, textureScale: TextureScale * Scale, startOffset: backGroundOffset, depth: Math.Max(Prefab.BackgroundSprite.Depth, depth + 0.000001f)); if (UseDropShadow) { Prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)) + dropShadowOffset, new Vector2(rect.Width, rect.Height), color: Color.Black * 0.5f, textureScale: TextureScale * Scale, startOffset: backGroundOffset, depth: (depth + Prefab.BackgroundSprite.Depth) / 2.0f); } Prefab.BackgroundSprite.effects = oldEffects; } } if (back == depth > 0.5f) { SpriteEffects oldEffects = prefab.sprite.effects; prefab.sprite.effects ^= SpriteEffects; for (int i = 0; i < Sections.Length; i++) { if (damageEffect != null) { float newCutoff = MathHelper.Lerp(0.0f, 0.65f, Sections[i].damage / Prefab.Health); if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor) { damageEffect.Parameters["aCutoff"].SetValue(newCutoff); damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f); damageEffect.Parameters["inColor"].SetValue(color.ToVector4()); damageEffect.CurrentTechnique.Passes[0].Apply(); Submarine.DamageEffectCutoff = newCutoff; Submarine.DamageEffectColor = color; } } Point sectionOffset = new Point( Math.Abs(rect.Location.X - Sections[i].rect.Location.X), Math.Abs(rect.Location.Y - Sections[i].rect.Location.Y)); if (FlippedX && IsHorizontal) { sectionOffset.X = Sections[i].rect.Right - rect.Right; } if (FlippedY && !IsHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (Sections[i].rect.Y - Sections[i].rect.Height); } sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); prefab.sprite.DrawTiled( spriteBatch, new Vector2(Sections[i].rect.X + drawOffset.X, -(Sections[i].rect.Y + drawOffset.Y)), new Vector2(Sections[i].rect.Width, Sections[i].rect.Height), color: color, startOffset: sectionOffset, depth: depth, textureScale: TextureScale * Scale); } prefab.sprite.effects = oldEffects; } if (GameMain.DebugDraw) { if (Bodies != null) { for (int i = 0; i < Bodies.Count; i++) { Vector2 pos = FarseerPhysics.ConvertUnits.ToDisplayUnits(Bodies[i].Position); if (Submarine != null) { pos += Submarine.Position; } pos.Y = -pos.Y; GUI.DrawRectangle(spriteBatch, pos, FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].X), FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].Y), -Bodies[i].Rotation, Color.White); } } if (SectionCount > 0 && HasBody) { for (int i = 0; i < SectionCount; i++) { if (GetSection(i).damage > 0) { var textPos = SectionPosition(i, true); textPos.Y = -textPos.Y; GUI.DrawString(spriteBatch, textPos, "Damage: " + (int)((GetSection(i).damage / Health) * 100f) + "%", Color.Yellow); } } } AiTarget?.Draw(spriteBatch); } }
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) { if (prefab.sprite == null) { return; } if (editing) { if (!HasBody && !ShowStructures) { return; } if (HasBody && !ShowWalls) { return; } } else if (HiddenInGame) { return; } Color color = IsIncludedInSelection && editing ? GUI.Style.Blue : IsHighlighted?GUI.Style.Orange *Math.Max(spriteColor.A / (float)byte.MaxValue, 0.1f) : spriteColor; if (IsSelected && editing) { //color = Color.Lerp(color, Color.Gold, 0.5f); color = spriteColor; Vector2 rectSize = rect.Size.ToVector2(); if (BodyWidth > 0.0f) { rectSize.X = BodyWidth; } if (BodyHeight > 0.0f) { rectSize.Y = BodyHeight; } Vector2 bodyPos = WorldPosition + BodyOffset; GUI.DrawRectangle(spriteBatch, new Vector2(bodyPos.X, -bodyPos.Y), rectSize.X, rectSize.Y, BodyRotation, Color.White, thickness: Math.Max(1, (int)(2 / Screen.Selected.Cam.Zoom))); } bool isWiringMode = editing && SubEditorScreen.TransparentWiringMode && SubEditorScreen.IsWiringMode(); if (isWiringMode) { color *= 0.15f; } Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; float depth = GetDrawDepth(); Vector2 textureOffset = this.textureOffset; if (FlippedX) { textureOffset.X = -textureOffset.X; } if (FlippedY) { textureOffset.Y = -textureOffset.Y; } if (back && damageEffect == null && !isWiringMode) { if (Prefab.BackgroundSprite != null) { Vector2 dropShadowOffset = Vector2.Zero; if (UseDropShadow) { dropShadowOffset = DropShadowOffset; if (dropShadowOffset == Vector2.Zero) { if (Submarine == null) { dropShadowOffset = Vector2.UnitY * 10.0f; } else { dropShadowOffset = IsHorizontal ? new Vector2(0.0f, Math.Sign(Submarine.HiddenSubPosition.Y - Position.Y) * 10.0f) : new Vector2(Math.Sign(Submarine.HiddenSubPosition.X - Position.X) * 10.0f, 0.0f); } } dropShadowOffset.Y = -dropShadowOffset.Y; } SpriteEffects oldEffects = Prefab.BackgroundSprite.effects; Prefab.BackgroundSprite.effects ^= SpriteEffects; Vector2 backGroundOffset = new Vector2( MathUtils.PositiveModulo((int)-textureOffset.X, Prefab.BackgroundSprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, Prefab.BackgroundSprite.SourceRect.Height)); Prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), color: Prefab.BackgroundSpriteColor, textureScale: TextureScale * Scale, startOffset: backGroundOffset, depth: Math.Max(GetDrawDepth(Prefab.BackgroundSprite.Depth, Prefab.BackgroundSprite), depth + 0.000001f)); if (UseDropShadow) { Prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)) + dropShadowOffset, new Vector2(rect.Width, rect.Height), color: Color.Black * 0.5f, textureScale: TextureScale * Scale, startOffset: backGroundOffset, depth: (depth + Prefab.BackgroundSprite.Depth) / 2.0f); } Prefab.BackgroundSprite.effects = oldEffects; } } if (back == GetRealDepth() > 0.5f) { SpriteEffects oldEffects = prefab.sprite.effects; prefab.sprite.effects ^= SpriteEffects; for (int i = 0; i < Sections.Length; i++) { Rectangle drawSection = Sections[i].rect; if (damageEffect != null) { float newCutoff = MathHelper.Lerp(0.0f, 0.65f, Sections[i].damage / MaxHealth); if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor) { damageEffect.Parameters["aCutoff"].SetValue(newCutoff); damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f); damageEffect.Parameters["inColor"].SetValue(color.ToVector4()); damageEffect.CurrentTechnique.Passes[0].Apply(); Submarine.DamageEffectCutoff = newCutoff; Submarine.DamageEffectColor = color; } } if (!HasDamage && i == 0) { drawSection = new Rectangle( drawSection.X, drawSection.Y, Sections[Sections.Length - 1].rect.Right - drawSection.X, drawSection.Y - (Sections[Sections.Length - 1].rect.Y - Sections[Sections.Length - 1].rect.Height)); i = Sections.Length; } Vector2 sectionOffset = new Vector2( Math.Abs(rect.Location.X - drawSection.Location.X), Math.Abs(rect.Location.Y - drawSection.Location.Y)); if (FlippedX && IsHorizontal) { sectionOffset.X = drawSection.Right - rect.Right; } if (FlippedY && !IsHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (drawSection.Y - drawSection.Height); } sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); prefab.sprite.DrawTiled( spriteBatch, new Vector2(drawSection.X + drawOffset.X, -(drawSection.Y + drawOffset.Y)), new Vector2(drawSection.Width, drawSection.Height), color: color, startOffset: sectionOffset, depth: depth, textureScale: TextureScale * Scale); } foreach (var decorativeSprite in Prefab.DecorativeSprites) { if (!spriteAnimState[decorativeSprite].IsActive) { continue; } float rotation = decorativeSprite.GetRotation(ref spriteAnimState[decorativeSprite].RotationState, spriteAnimState[decorativeSprite].RandomRotationFactor); Vector2 offset = decorativeSprite.GetOffset(ref spriteAnimState[decorativeSprite].OffsetState, spriteAnimState[decorativeSprite].RandomOffsetMultiplier) * Scale; decorativeSprite.Sprite.Draw(spriteBatch, new Vector2(DrawPosition.X + offset.X, -(DrawPosition.Y + offset.Y)), color, rotation, decorativeSprite.GetScale(spriteAnimState[decorativeSprite].RandomScaleFactor) * Scale, prefab.sprite.effects, depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - prefab.sprite.Depth), 0.999f)); } prefab.sprite.effects = oldEffects; } if (GameMain.DebugDraw && Screen.Selected.Cam.Zoom > 0.5f) { if (Bodies != null) { for (int i = 0; i < Bodies.Count; i++) { Vector2 pos = FarseerPhysics.ConvertUnits.ToDisplayUnits(Bodies[i].Position); if (Submarine != null) { pos += Submarine.Position; } pos.Y = -pos.Y; GUI.DrawRectangle(spriteBatch, pos, FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].X), FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].Y), -Bodies[i].Rotation, Color.White); } } if (SectionCount > 0 && HasBody) { for (int i = 0; i < SectionCount; i++) { if (GetSection(i).damage > 0) { var textPos = SectionPosition(i, true); textPos.Y = -textPos.Y; GUI.DrawString(spriteBatch, textPos, "Damage: " + (int)((GetSection(i).damage / MaxHealth) * 100f) + "%", Color.Yellow); } } } } }
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) { if (prefab.sprite == null) { return; } Color color = (isHighlighted) ? Color.Orange : spriteColor; if (IsSelected && editing) { color = Color.Red; GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, -rect.Y, rect.Width, rect.Height), color); } Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; float depth = prefab.sprite.Depth; depth -= (ID % 255) * 0.000001f; Vector2 textureOffset = this.textureOffset; if (flippedX) { textureOffset.X = -textureOffset.X; } if (flippedY) { textureOffset.Y = -textureOffset.Y; } if (back && damageEffect == null) { if (prefab.BackgroundSprite != null) { SpriteEffects oldEffects = prefab.BackgroundSprite.effects; prefab.BackgroundSprite.effects ^= SpriteEffects; Point backGroundOffset = new Point( MathUtils.PositiveModulo((int)-textureOffset.X, prefab.BackgroundSprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.BackgroundSprite.SourceRect.Height)); prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), color: color, textureScale: TextureScale, startOffset: backGroundOffset); prefab.BackgroundSprite.effects = oldEffects; } } if (back == prefab.sprite.Depth > 0.5f || editing) { SpriteEffects oldEffects = prefab.sprite.effects; prefab.sprite.effects ^= SpriteEffects; for (int i = 0; i < sections.Length; i++) { if (damageEffect != null) { float newCutoff = sections[i].damage > 0 ? MathHelper.Lerp(0.2f, 0.65f, sections[i].damage / prefab.Health) : 0.0f; if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor) { damageEffect.Parameters["aCutoff"].SetValue(newCutoff); damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f); damageEffect.Parameters["inColor"].SetValue(color.ToVector4()); damageEffect.CurrentTechnique.Passes[0].Apply(); Submarine.DamageEffectCutoff = newCutoff; Submarine.DamageEffectColor = color; } } Point sectionOffset = new Point( Math.Abs(rect.Location.X - sections[i].rect.Location.X), Math.Abs(rect.Location.Y - sections[i].rect.Location.Y)); if (flippedX && isHorizontal) { sectionOffset.X = sections[i].rect.Right - rect.Right; } if (flippedY && !isHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (sections[i].rect.Y - sections[i].rect.Height); } sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); prefab.sprite.DrawTiled( spriteBatch, new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)), new Vector2(sections[i].rect.Width, sections[i].rect.Height), color: spriteColor, startOffset: sectionOffset, depth: depth, textureScale: TextureScale); } prefab.sprite.effects = oldEffects; } }
private void BakeMapEntity(XElement element) { string identifier = element.GetAttributeString("identifier", ""); if (string.IsNullOrEmpty(identifier)) { return; } Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); if (rect.Equals(Rectangle.Empty)) { return; } float depth = element.GetAttributeFloat("spritedepth", 1f); bool flippedX = element.GetAttributeBool("flippedx", false); bool flippedY = element.GetAttributeBool("flippedy", false); float scale = element.GetAttributeFloat("scale", 1f); Color color = element.GetAttributeColor("spritecolor", Color.White); float rotation = element.GetAttributeFloat("rotation", 0f); MapEntityPrefab prefab = MapEntityPrefab.List.FirstOrDefault(p => p.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase)); if (prefab == null) { return; } var texture = prefab.sprite.Texture; var srcRect = prefab.sprite.SourceRect; SpriteEffects spriteEffects = SpriteEffects.None; if (flippedX) { spriteEffects |= SpriteEffects.FlipHorizontally; } if (flippedY) { spriteEffects |= SpriteEffects.FlipVertically; } var prevEffects = prefab.sprite.effects; prefab.sprite.effects ^= spriteEffects; bool overrideSprite = false; ItemPrefab itemPrefab = prefab as ItemPrefab; StructurePrefab structurePrefab = prefab as StructurePrefab; if (itemPrefab != null) { BakeItemComponents(itemPrefab, rect, color, scale, rotation, depth, out overrideSprite); } if (!overrideSprite) { if (structurePrefab != null) { ParseUpgrades(structurePrefab.ConfigElement, ref scale); if (!prefab.ResizeVertical) { rect.Height = (int)(rect.Height * scale / prefab.Scale); } if (!prefab.ResizeHorizontal) { rect.Width = (int)(rect.Width * scale / prefab.Scale); } var textureScale = element.GetAttributeVector2("texturescale", Vector2.One); Vector2 backGroundOffset = Vector2.Zero; Vector2 textureOffset = element.GetAttributeVector2("textureoffset", Vector2.Zero); if (flippedX) { textureOffset.X = -textureOffset.X; } if (flippedY) { textureOffset.Y = -textureOffset.Y; } backGroundOffset = new Vector2( MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height)); prefab.sprite.DrawTiled( spriteRecorder, rect.Location.ToVector2() * new Vector2(1f, -1f), rect.Size.ToVector2(), color: color, startOffset: backGroundOffset, textureScale: textureScale * scale, depth: depth); } else if (itemPrefab != null) { bool usePrefabValues = element.GetAttributeBool("isoverride", false) != itemPrefab.IsOverride; if (usePrefabValues) { scale = itemPrefab.ConfigElement.GetAttributeFloat(scale, "scale", "Scale"); } ParseUpgrades(itemPrefab.ConfigElement, ref scale); if (prefab.ResizeVertical || prefab.ResizeHorizontal) { if (!prefab.ResizeHorizontal) { rect.Width = (int)(prefab.sprite.size.X * scale); } if (!prefab.ResizeVertical) { rect.Height = (int)(prefab.sprite.size.Y * scale); } var spritePos = rect.Center.ToVector2(); //spritePos.Y = rect.Height - spritePos.Y; prefab.sprite.DrawTiled( spriteRecorder, rect.Location.ToVector2() * new Vector2(1f, -1f), rect.Size.ToVector2(), color: color, textureScale: Vector2.One * scale, depth: depth); foreach (var decorativeSprite in itemPrefab.DecorativeSprites) { float offsetState = 0f; Vector2 offset = decorativeSprite.GetOffset(ref offsetState, Vector2.Zero) * scale; if (flippedX && itemPrefab.CanSpriteFlipX) { offset.X = -offset.X; } if (flippedY && itemPrefab.CanSpriteFlipY) { offset.Y = -offset.Y; } decorativeSprite.Sprite.DrawTiled(spriteRecorder, new Vector2(spritePos.X + offset.X - rect.Width / 2, -(spritePos.Y + offset.Y + rect.Height / 2)), rect.Size.ToVector2(), color: color, textureScale: Vector2.One * scale, depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - prefab.sprite.Depth), 0.999f)); } } else { rect.Width = (int)(rect.Width * scale / prefab.Scale); rect.Height = (int)(rect.Height * scale / prefab.Scale); var spritePos = rect.Center.ToVector2(); spritePos.Y -= rect.Height; //spritePos.Y = rect.Height - spritePos.Y; prefab.sprite.Draw( spriteRecorder, spritePos * new Vector2(1f, -1f), color, prefab.sprite.Origin, rotation, scale, prefab.sprite.effects, depth); foreach (var decorativeSprite in itemPrefab.DecorativeSprites) { float rotationState = 0f; float offsetState = 0f; float rot = decorativeSprite.GetRotation(ref rotationState, 0f); Vector2 offset = decorativeSprite.GetOffset(ref offsetState, Vector2.Zero) * scale; if (flippedX && itemPrefab.CanSpriteFlipX) { offset.X = -offset.X; } if (flippedY && itemPrefab.CanSpriteFlipY) { offset.Y = -offset.Y; } decorativeSprite.Sprite.Draw(spriteRecorder, new Vector2(spritePos.X + offset.X, -(spritePos.Y + offset.Y)), color, MathHelper.ToRadians(rotation) + rot, decorativeSprite.GetScale(0f) * scale, prefab.sprite.effects, depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - prefab.sprite.Depth), 0.999f)); } } } } prefab.sprite.effects = prevEffects; }
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) { if (prefab.sprite == null) { return; } if (editing) { if (!HasBody && !ShowStructures) { return; } if (HasBody && !ShowWalls) { return; } } Color color = (isHighlighted) ? Color.Orange : spriteColor; if (IsSelected && editing) { color = Color.Lerp(color, Color.Gold, 0.5f); GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, -rect.Y, rect.Width, rect.Height), color); } Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; float depth = SpriteDepthOverrideIsSet ? SpriteOverrideDepth : prefab.sprite.Depth; depth -= (ID % 255) * 0.000001f; Vector2 textureOffset = this.textureOffset; if (FlippedX) { textureOffset.X = -textureOffset.X; } if (FlippedY) { textureOffset.Y = -textureOffset.Y; } if (back && damageEffect == null) { if (prefab.BackgroundSprite != null) { SpriteEffects oldEffects = prefab.BackgroundSprite.effects; prefab.BackgroundSprite.effects ^= SpriteEffects; Point backGroundOffset = new Point( MathUtils.PositiveModulo((int)-textureOffset.X, prefab.BackgroundSprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.BackgroundSprite.SourceRect.Height)); prefab.BackgroundSprite.DrawTiled( spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), color: color, textureScale: TextureScale, startOffset: backGroundOffset, scaleMultiplier: Scale); prefab.BackgroundSprite.effects = oldEffects; } } if (back == depth > 0.5f || editing) { SpriteEffects oldEffects = prefab.sprite.effects; prefab.sprite.effects ^= SpriteEffects; for (int i = 0; i < Sections.Length; i++) { if (damageEffect != null) { float newCutoff = Sections[i].damage > 0 ? MathHelper.Lerp(0.2f, 0.65f, Sections[i].damage / prefab.Health) : 0.0f; if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor) { damageEffect.Parameters["aCutoff"].SetValue(newCutoff); damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f); damageEffect.Parameters["inColor"].SetValue(color.ToVector4()); damageEffect.CurrentTechnique.Passes[0].Apply(); Submarine.DamageEffectCutoff = newCutoff; Submarine.DamageEffectColor = color; } } Point sectionOffset = new Point( Math.Abs(rect.Location.X - Sections[i].rect.Location.X), Math.Abs(rect.Location.Y - Sections[i].rect.Location.Y)); if (FlippedX && IsHorizontal) { sectionOffset.X = Sections[i].rect.Right - rect.Right; } if (FlippedY && !IsHorizontal) { sectionOffset.Y = (rect.Y - rect.Height) - (Sections[i].rect.Y - Sections[i].rect.Height); } sectionOffset.X += MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width); sectionOffset.Y += MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height); prefab.sprite.DrawTiled( spriteBatch, new Vector2(Sections[i].rect.X + drawOffset.X, -(Sections[i].rect.Y + drawOffset.Y)), new Vector2(Sections[i].rect.Width, Sections[i].rect.Height), color: color, startOffset: sectionOffset, depth: depth, textureScale: TextureScale, scaleMultiplier: Scale); } prefab.sprite.effects = oldEffects; } if (GameMain.DebugDraw) { if (Bodies != null && prefab.BodyRotation != 0.0f) { for (int i = 0; i < Bodies.Count; i++) { Vector2 pos = FarseerPhysics.ConvertUnits.ToDisplayUnits(Bodies[i].Position); if (Submarine != null) { pos += Submarine.Position; } pos.Y = -pos.Y; GUI.DrawRectangle(spriteBatch, pos, FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].X), FarseerPhysics.ConvertUnits.ToDisplayUnits(bodyDebugDimensions[i].Y), -Bodies[i].Rotation, Color.White); } } } }