XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/DeathMod

修正领域背景铺满与视差移动

7430f68
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

1 个文件 +42 -40
Modified Common/DeathDomainVisualSystem.cs +42 -40
@@ -191,7 +191,6 @@ internal class DeathDomainVisualSystem : ModSystem
191 191 coreNoiseTime,
192 192 coreNoiseSeed,
193 193 coreNoiseAmplitude,
194 time,
195 194 mastery,
196 195 reveal);
197 196 DrawFilledNoiseDisc(
@@ -220,7 +219,6 @@ internal class DeathDomainVisualSystem : ModSystem
220 219 float noiseTime,
221 220 float noiseSeed,
222 221 float noiseAmplitude,
223 float time,
224 222 float mastery,
225 223 float reveal)
226 224 {
@@ -245,12 +243,8 @@ internal class DeathDomainVisualSystem : ModSystem
245 243 for (int layer = 0; layer < 3; layer++)
246 244 {
247 245 float parallax = layer switch { 0 => 0.07f, 1 => 0.18f, _ => 0.34f };
248 Vector2 drift = layer switch
249 {
250 0 => new Vector2(5.5f, -1.5f),
251 1 => new Vector2(-11f, 2.5f),
252 _ => new Vector2(17f, -3.5f)
253 } * time;
246 float horizontalViewFraction = layer switch { 0 => 0.96f, 1 => 0.9f, _ => 0.84f };
247 float verticalViewFraction = layer switch { 0 => 0.96f, 1 => 0.9f, _ => 0.86f };
254 248 float opacity = layer switch
255 249 {
256 250 0 => MathHelper.Lerp(0.88f, 1f, mastery) * reveal,
@@ -258,6 +252,10 @@ internal class DeathDomainVisualSystem : ModSystem
258 252 _ => MathHelper.Lerp(0.78f, 0.96f, mastery) * reveal
259 253 };
260 254 Texture2D texture = DeathDomainBackdropTextureSystem.GetLayer(layer);
255 float viewWidth = texture.Width * horizontalViewFraction;
256 float viewHeight = texture.Height * verticalViewFraction;
257 float sourceOffsetX = PingPong(worldCenter.X * parallax, texture.Width - viewWidth);
258 float sourceOffsetY = PingPong(worldCenter.Y * parallax, texture.Height - viewHeight);
261 259
262 260 for (int index = 0; index < bands; index++)
263 261 {
@@ -280,14 +278,20 @@ internal class DeathDomainVisualSystem : ModSystem
280 278 if (left >= right)
281 279 continue;
282 280
281 float normalizedLeft = MathHelper.Clamp((left + extent) / (extent * 2f), 0f, 1f);
282 float normalizedRight = MathHelper.Clamp((right + extent) / (extent * 2f), 0f, 1f);
283 float normalizedTop = MathHelper.Clamp((scanY - bandHeight * 0.5f + extent) / (extent * 2f), 0f, 1f);
284 float normalizedBottom = MathHelper.Clamp((scanY + bandHeight * 0.5f + extent) / (extent * 2f), 0f, 1f);
283 285 DrawBackdropBand(
284 286 batch,
285 287 texture,
286 288 new Vector2(center.X + left, center.Y + scanY - bandHeight * 0.5f),
287 289 right - left,
288 290 bandHeight,
289 worldCenter * parallax + new Vector2(left, scanY),
290 drift,
291 sourceOffsetX + normalizedLeft * viewWidth,
292 sourceOffsetY + normalizedTop * viewHeight,
293 Math.Max(0.5f, (normalizedRight - normalizedLeft) * viewWidth),
294 Math.Max(0.5f, (normalizedBottom - normalizedTop) * viewHeight),
291 295 opacity);
292 296 }
293 297 }
@@ -299,41 +303,39 @@ internal class DeathDomainVisualSystem : ModSystem
299 303 Vector2 destination,
300 304 float destinationWidth,
301 305 float destinationHeight,
302 Vector2 sampleOrigin,
303 Vector2 drift,
306 float sourceX,
307 float sourceY,
308 float sourceWidth,
309 float sourceHeight,
304 310 float opacity)
305 311 {
306 312 if (destinationWidth <= 0.05f || destinationHeight <= 0.05f || opacity <= 0.001f)
307 313 return;
308 314
309 int sourceHeight = Math.Clamp((int)Math.Ceiling(destinationHeight), 1, texture.Height);
310 int sourceY = (int)PositiveModulo(sampleOrigin.Y + drift.Y, texture.Height);
311 sourceY = Math.Min(sourceY, texture.Height - sourceHeight);
312 float sourceX = PositiveModulo(sampleOrigin.X + drift.X, texture.Width);
313 float remaining = destinationWidth;
314 float destinationX = destination.X;
315 while (remaining > 0.01f)
316 {
317 int sourceStart = Math.Clamp((int)sourceX, 0, texture.Width - 1);
318 float available = texture.Width - sourceStart;
319 float drawWidth = Math.Min(remaining, available);
320 int sourceWidth = Math.Clamp((int)Math.Ceiling(drawWidth), 1, texture.Width - sourceStart);
321 Rectangle source = new(sourceStart, sourceY, sourceWidth, sourceHeight);
322 batch.Draw(
323 texture,
324 new Vector2(destinationX, destination.Y),
325 source,
326 Color.White * opacity,
327 0f,
328 Vector2.Zero,
329 new Vector2(drawWidth / sourceWidth, destinationHeight / sourceHeight),
330 SpriteEffects.None,
331 0f);
332
333 remaining -= drawWidth;
334 destinationX += drawWidth;
335 sourceX = 0f;
336 }
315 int sourceLeft = Math.Clamp((int)Math.Floor(sourceX), 0, texture.Width - 1);
316 int sourceTop = Math.Clamp((int)Math.Floor(sourceY), 0, texture.Height - 1);
317 int sourceRight = Math.Clamp((int)Math.Ceiling(sourceX + sourceWidth), sourceLeft + 1, texture.Width);
318 int sourceBottom = Math.Clamp((int)Math.Ceiling(sourceY + sourceHeight), sourceTop + 1, texture.Height);
319 Rectangle source = new(sourceLeft, sourceTop, sourceRight - sourceLeft, sourceBottom - sourceTop);
320 batch.Draw(
321 texture,
322 destination,
323 source,
324 Color.White * opacity,
325 0f,
326 Vector2.Zero,
327 new Vector2(destinationWidth / source.Width, destinationHeight / source.Height),
328 SpriteEffects.None,
329 0f);
330 }
331
332 private static float PingPong(float value, float length)
333 {
334 if (length <= 0.001f)
335 return 0f;
336
337 float wrapped = PositiveModulo(value, length * 2f);
338 return length - Math.Abs(wrapped - length);
337 339 }
338 340
339 341 private static void DrawSovereignSeal(SpriteBatch batch, Texture2D pixel, Vector2 center, int mastery, float animation)