Advertisement
Enjl

PlayerSheetMirror.cs

Sep 28th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. // Name: PlayerSheetMirror
  2. // Submenu: SMBX
  3. // Author: Enjl
  4. // Title: PlayerSheetMirror
  5. // Version: 1.0
  6. // Desc: Mirrors the right half of a player sprite sheet onto the left half.
  7. // Keywords:
  8. // URL:
  9. // Help:
  10. void Render(Surface dst, Surface src, Rectangle rect)
  11. {
  12.     // Delete any of these lines you don't need
  13.     Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
  14.     int CenterX = ((selection.Right - selection.Left) / 2) + selection.Left;
  15.     int CenterY = ((selection.Bottom - selection.Top) / 2) + selection.Top;
  16.     ColorBgra PrimaryColor = EnvironmentParameters.PrimaryColor;
  17.     ColorBgra SecondaryColor = EnvironmentParameters.SecondaryColor;
  18.     int BrushWidth = (int)EnvironmentParameters.BrushWidth;
  19.    
  20.     int w = src.Width;
  21.     int h = src.Height;
  22.     double cX = w * 0.5;
  23.    
  24.     int cellWidth = (int) (w * 0.1);
  25.     int cellHeight = (int) (h * 0.1);
  26.    
  27.     int rightBound = (int) Math.Min(cX, rect.Right);
  28.  
  29.     ColorBgra CurrentPixel;
  30.     for (int y = rect.Top; y < rect.Bottom; y++)
  31.     {
  32.         if (IsCancelRequested) return;
  33.         for (int x = rect.Left; x < rect.Right; x++)
  34.         {
  35.             int currentCellX = (int) Math.Floor((double) (x / cellWidth));
  36.             int currentCellY = (int) Math.Floor((double) (y / cellHeight));
  37.             int frame = currentCellX * 10 + currentCellY + 2 - 50;
  38.             if (frame <= 0) {
  39.                 int xOffset = x - currentCellX * cellWidth;
  40.                 int yOffset = y - currentCellY * cellHeight;
  41.                
  42.                 int targetCellX = (int) (Math.Floor((-frame) * 0.1d) * cellWidth) + cellWidth;
  43.                 int targetCellY = (int) ((((-frame) % 10)) * cellHeight);
  44.                 int newX = (int) (cX - 1 + targetCellX - xOffset);
  45.                 int newY = (int) (targetCellY + yOffset);
  46.                
  47.                 newX = Math.Min(Math.Max(newX, 0), w - 1);
  48.                 newY = Math.Min(Math.Max(newY, 0), h - 1);
  49.                
  50.                 CurrentPixel = src[newX,newY];
  51.                 dst[x,y] = CurrentPixel;
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement