{"TotalCount":35,"Files":[{"Ident":"facepunch.transposer","Path":"Assembly.cs","FileName":"Assembly.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"global using Sandbox;\r\nglobal using System;\r\nglobal using System.Collections.Generic;\r\nglobal using System.Linq;\r\n"},{"Ident":"facepunch.transposer","Path":"SpriteData.cs","FileName":"SpriteData.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// A single coloured pixel within a sprite frame.\r\n/// Stores its position relative to the sprite origin (bottom-left) and its colour.\r\n/// \u003C/summary\u003E\r\npublic struct PixelData\r\n{\r\n\tpublic PixelPoint Position;\r\n\tpublic Color32 Color;\r\n\r\n\tpublic PixelData( PixelPoint position, Color32 color )\r\n\t{\r\n\t\tPosition = position;\r\n\t\tColor = color;\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// One frame of a sprite animation.\r\n/// Contains the pixel list and the duration (in seconds) before advancing to the next frame.\r\n/// \u003C/summary\u003E\r\npublic class FrameData\r\n{\r\n\t// Sparse pixel list \u2014 only non-transparent pixels are stored.\r\n\t// Fully transparent pixels are stripped at load time (see SpriteManager.ParseFramePixels)\r\n\t// so Draw loops only touch pixels that will actually write something.\r\n\tpublic List\u003CPixelData\u003E Pixels { get; set; }\r\n\tpublic float AnimTime { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Optional per-frame hitbox override. When null, the animation-level\r\n\t/// \u003Csee cref=\u0022AnimationData.Hitbox\u0022/\u003E is used instead.\r\n\t/// \u003C/summary\u003E\r\n\tpublic PixelRect? Hitbox { get; set; }\r\n\r\n\t// Lazily-computed flipped variants. Pixel data is immutable after load,\r\n\t// so these are computed once and reused on every subsequent Draw call.\r\n\tprivate List\u003CPixelData\u003E _cachedFlipX;\r\n\tprivate List\u003CPixelData\u003E _cachedFlipY;\r\n\tprivate List\u003CPixelData\u003E _cachedFlipXY;\r\n\r\n\tpublic FrameData() { }\r\n\r\n\tpublic FrameData( List\u003CPixelData\u003E pixels, float animTime = 0f, PixelRect? hitbox = null )\r\n\t{\r\n\t\tPixels = pixels;\r\n\t\tAnimTime = animTime;\r\n\t\tHitbox = hitbox;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Return a copy of the pixel list with X coordinates mirrored within the given width.\r\n\t/// Result is cached after the first call.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CPixelData\u003E GetPixelsFlippedX( int width )\r\n\t{\r\n\t\tif ( _cachedFlipX is not null )\r\n\t\t\treturn _cachedFlipX;\r\n\r\n\t\t_cachedFlipX = new List\u003CPixelData\u003E( Pixels.Count );\r\n\t\tforeach ( PixelData p in Pixels )\r\n\t\t\t_cachedFlipX.Add( new PixelData( new PixelPoint( width - 1 - p.Position.X, p.Position.Y ), p.Color ) );\r\n\t\treturn _cachedFlipX;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Return a copy of the pixel list with Y coordinates mirrored within the given height.\r\n\t/// Result is cached after the first call.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CPixelData\u003E GetPixelsFlippedY( int height )\r\n\t{\r\n\t\tif ( _cachedFlipY is not null )\r\n\t\t\treturn _cachedFlipY;\r\n\r\n\t\t_cachedFlipY = new List\u003CPixelData\u003E( Pixels.Count );\r\n\t\tforeach ( PixelData p in Pixels )\r\n\t\t\t_cachedFlipY.Add( new PixelData( new PixelPoint( p.Position.X, height - 1 - p.Position.Y ), p.Color ) );\r\n\t\treturn _cachedFlipY;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Return a copy of the pixel list mirrored on both axes.\r\n\t/// Result is cached after the first call.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CPixelData\u003E GetPixelsFlippedXY( int width, int height )\r\n\t{\r\n\t\tif ( _cachedFlipXY is not null )\r\n\t\t\treturn _cachedFlipXY;\r\n\r\n\t\t_cachedFlipXY = new List\u003CPixelData\u003E( Pixels.Count );\r\n\t\tforeach ( PixelData p in Pixels )\r\n\t\t\t_cachedFlipXY.Add( new PixelData( new PixelPoint( width - 1 - p.Position.X, height - 1 - p.Position.Y ), p.Color ) );\r\n\t\treturn _cachedFlipXY;\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Defines a single named animation for a sprite, including all frames,\r\n/// the bounding size, optional hitbox, and loop mode.\r\n/// \u003C/summary\u003E\r\npublic class AnimationData\r\n{\r\n\tpublic string Name { get; set; }\r\n\tpublic List\u003CFrameData\u003E Frames { get; set; }\r\n\tpublic PixelPoint AnimSize { get; set; }\r\n\tpublic PixelRect Hitbox { get; set; }\r\n\tpublic LoopMode LoopMode { get; set; }\r\n\r\n\tpublic AnimationData() { }\r\n\r\n\tpublic AnimationData( string name, List\u003CFrameData\u003E frames, PixelPoint animSize, PixelRect hitbox, LoopMode loopMode )\r\n\t{\r\n\t\tName = name;\r\n\t\tFrames = frames;\r\n\t\tAnimSize = animSize;\r\n\t\tHitbox = hitbox;\r\n\t\tLoopMode = loopMode;\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// How an animation plays back after reaching the last frame.\r\n/// \u003C/summary\u003E\r\npublic enum LoopMode\r\n{\r\n\t/// \u003Csummary\u003ERestart from frame 0 after the last frame.\u003C/summary\u003E\r\n\tLoops,\r\n\t/// \u003Csummary\u003EPlay once then stop on the last frame.\u003C/summary\u003E\r\n\tPlayOnce,\r\n\t/// \u003Csummary\u003EAlternate forward and backward through the frames.\u003C/summary\u003E\r\n\tPingPong,\r\n\t/// \u003Csummary\u003EJump to a random frame each cycle.\u003C/summary\u003E\r\n\tRandomFrame\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/Coin.cs","FileName":"Coin.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Collectible coin entity. Spins in place, detects the player via pixel-colour\r\n/// collision, and smoothly relocates to a random position when collected.\r\n/// Spawns Shine sparkle particles periodically.\r\n/// \u003C/summary\u003E\r\npublic class Coin : Entity\r\n{\r\n\t// Monotonically-increasing counter shared across all Coin instances.\r\n\t// Each new coin gets a unique depth so their draw order is stable and\r\n\t// consistent even when multiple coins exist simultaneously.\r\n\tprivate static int _depthCounter;\r\n\r\n\tprivate bool _isMoving;\r\n\tprivate Vector2 _moveVector;\r\n\tprivate float _moveTimer;\r\n\tprivate const float MOVE_TIME = 0.75f;\r\n\tprivate Vector2 _originalPosition;\r\n\tprivate PixelPoint _targetPosition;\r\n\r\n\tprivate float _sparkleTimer;\r\n\tprivate const float SPARKLE_INTERVAL_IDLE   = 1f / 1.2f; // ~1.2 sparkles/s when stationary\r\n\tprivate const float SPARKLE_INTERVAL_MOVING = 1f / 12f;  // ~12 sparkles/s when moving\r\n\r\n\tprivate Queue\u003CPixelPoint\u003E _lastPositions = new();\r\n\tprivate const int NUM_LAST_POSITIONS = 4;\r\n\r\n\tpublic Coin( int x, int y, TransposerScene scene )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022coin\u0022;\r\n\t\tPlayAnimation( \u0022spin\u0022 );\r\n\t\t_layer = Globals.DEPTH_COIN;\r\n\t\t_depth = _depthCounter\u002B\u002B;\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\r\n\t\tif ( _isMoving )\r\n\t\t{\r\n\t\t\tPixelPoint oldPos = PixelPosition;\r\n\r\n\t\t\t// SineOut easing: fast start, decelerates smoothly into the target position.\r\n\t\t\tfloat moveAmount = PixelUtils.Map( _moveTimer, MOVE_TIME, 0f, 0f, 1f, EaseType.SineOut );\r\n\t\t\tExactPos = _originalPosition \u002B _moveVector * moveAmount;\r\n\r\n\t\t\tif ( PixelPosition != oldPos )\r\n\t\t\t\tAddLastPosition( oldPos );\r\n\r\n\t\t\t_moveTimer -= deltaTime;\r\n\t\t\tif ( _moveTimer \u003C= 0f )\r\n\t\t\t{\r\n\t\t\t\t_isMoving = false;\r\n\t\t\t\tPixelPosition = _targetPosition;\r\n\t\t\t\tPlayAnimation( \u0022spin\u0022 );\r\n\t\t\t\t_lastPositions.Clear();\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t// Only check for player collision while stationary \u2014 skip during relocation\r\n\t\t\t// so the coin can\u0027t be re-collected mid-flight after a swap.\r\n\t\t\tList\u003CPixelData\u003E pixelDataList = GetPixelDataList( \u0022coin\u0022, \u0022spin\u0022, _currentFrameNumber, false, false );\r\n\t\t\tif ( pixelDataList is not null )\r\n\t\t\t{\r\n\t\t\t\tforeach ( PixelData pd in pixelDataList )\r\n\t\t\t\t{\r\n\t\t\t\t\tPixelPoint pos = PixelPosition \u002B pd.Position;\r\n\t\t\t\t\tColor32 existing = Screen.GetPixel( pos.X, pos.Y );\r\n\r\n\t\t\t\t\tif ( existing.r == 200 \u0026\u0026 existing.g == 200 \u0026\u0026 existing.b == 100 \u0026\u0026 existing.a == 255 )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t((GameScene)_scene).PlayerTouchedCoin( this );\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Framerate-independent sparkle particles.\r\n\t\tfloat sparkleInterval = _isMoving ? SPARKLE_INTERVAL_MOVING : SPARKLE_INTERVAL_IDLE;\r\n\t\t_sparkleTimer -= deltaTime;\r\n\t\tif ( _sparkleTimer \u003C= 0f )\r\n\t\t{\r\n\t\t\t_sparkleTimer \u002B= sparkleInterval;\r\n\t\t\t((GameScene)_scene).CreateShine(\r\n\t\t\t\tPixelX \u002B Game.Random.Next( -1, 4 ),\r\n\t\t\t\tPixelY \u002B Game.Random.Next( -1, 4 ) );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Start a smooth relocation to a random position at least 40px away.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Relocate()\r\n\t{\r\n\t\tconst int MIN_DISTANCE = 40;\r\n\t\tint newX, newY;\r\n\r\n\t\tdo\r\n\t\t{\r\n\t\t\tnewX = Game.Random.Next( 2, Screen.PixelWidth - 12 );\r\n\t\t\tnewY = Game.Random.Next( 2, Screen.PixelHeight - 12 );\r\n\t\t}\r\n\t\twhile ( Math.Abs( newX - PixelX ) \u003C MIN_DISTANCE \u0026\u0026 Math.Abs( newY - PixelY ) \u003C MIN_DISTANCE );\r\n\r\n\t\t_isMoving = true;\r\n\t\t_moveTimer = MOVE_TIME;\r\n\t\t_sparkleTimer = 0f;\r\n\t\tPlayAnimation( \u0022moving\u0022 );\r\n\t\t_lastPositions.Clear();\r\n\r\n\t\t_originalPosition = ExactPos;\r\n\t\t_targetPosition = new PixelPoint( newX, newY );\r\n\t\t_moveVector = new Vector2( newX - ExactPos.x, newY - ExactPos.y );\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\t// Draw golden ghost trail.\r\n\t\tList\u003CPixelData\u003E trailPixels = GetPixelDataList( \u0022coin\u0022, \u0022moving\u0022, 0, false, false );\r\n\t\tif ( trailPixels is not null )\r\n\t\t{\r\n\t\t\tfloat opacity = 0.30f;\r\n\t\t\tforeach ( PixelPoint pos in _lastPositions )\r\n\t\t\t{\r\n\t\t\t\tforeach ( PixelData pd in trailPixels )\r\n\t\t\t\t{\r\n\t\t\t\t\tPixelPoint pp = pos \u002B pd.Position;\r\n\t\t\t\t\tScreen.AddPixel( pp.X, pp.Y, new Color32( 191, 191, 0, (byte)(opacity * 255f) ) );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbase.Draw();\r\n\t}\r\n\r\n\tprivate void AddLastPosition( PixelPoint pos )\r\n\t{\r\n\t\tif ( _lastPositions.Count \u003E= NUM_LAST_POSITIONS )\r\n\t\t\t_lastPositions.Dequeue();\r\n\t\t_lastPositions.Enqueue( pos );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/Shine.cs","FileName":"Shine.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Sparkle animation played near coins. Uses the \u0022shine\u0022 sprite type,\r\n/// runs at 1.5\u00D7 speed, removes self on completion.\r\n/// \u003C/summary\u003E\r\npublic class Shine : Entity\r\n{\r\n\tpublic Shine( int x, int y, TransposerScene scene )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022shine\u0022;\r\n\t\t_layer = Globals.DEPTH_SHINE;\r\n\t\tAnimTimeScale = 1.5f;\r\n\t\tPlayAnimation( \u0022shine\u0022 );\r\n\t\tSetAnimCompleteCallback( () =\u003E ((GameScene)_scene).RemoveShine( this ) );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/ScoreText.cs","FileName":"ScoreText.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Text display that renders with randomised pixel colours \u2014 the glitchy\r\n/// rainbow effect used for score/instruction text on the main menu.\r\n/// \u003C/summary\u003E\r\npublic class ScoreText : TextDisplay\r\n{\r\n\tpublic ScoreText( string text, TransposerScene scene, int x, int y, string fontName, int scale = 1 )\r\n\t\t: base( text, scene, x, y, fontName, Color.Black, scale )\r\n\t{\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\tbase.Draw();\r\n\r\n\t\tint currentX = PixelX;\r\n\t\tint currentY = PixelY;\r\n\r\n\t\tfor ( int i = 0; i \u003C _text.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tchar c = _text[i];\r\n\r\n\t\t\tif ( c == \u0027\\n\u0027 )\r\n\t\t\t{\r\n\t\t\t\tcurrentY -= _letterHeight * _scale;\r\n\t\t\t\tcurrentX = PixelX;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tif ( c == \u0027 \u0027 )\r\n\t\t\t{\r\n\t\t\t\tcurrentX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tList\u003CPixelData\u003E pixelDataList = GetPixelDataList( _fontName, c.ToString() );\r\n\t\t\tif ( pixelDataList is not null )\r\n\t\t\t\tDrawPixels( pixelDataList, currentX, currentY, _scale, randomColor: true );\r\n\r\n\t\t\tcurrentX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"MyComponent.cs","FileName":"MyComponent.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"\r\npublic sealed class MyComponent : Component\r\n{\r\n\t[Property] public string StringProperty { get; set; }\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"PixelPoint.cs","FileName":"PixelPoint.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// Integer 2D point used for pixel-space coordinates.\r\n/// Replaces float positions with exact pixel addressing.\r\n/// \u003C/summary\u003E\r\npublic struct PixelPoint : IEquatable\u003CPixelPoint\u003E\r\n{\r\n\tpublic int X;\r\n\tpublic int Y;\r\n\r\n\tpublic PixelPoint( int x, int y )\r\n\t{\r\n\t\tX = x;\r\n\t\tY = y;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Manhattan distance between two points.\r\n\t/// Cheaper than Euclidean and often sufficient for grid-based logic.\r\n\t/// \u003C/summary\u003E\r\n\tpublic int Distance( PixelPoint other )\r\n\t{\r\n\t\treturn Math.Abs( X - other.X ) \u002B Math.Abs( Y - other.Y );\r\n\t}\r\n\r\n\tpublic static PixelPoint operator \u002B( PixelPoint a, PixelPoint b ) =\u003E new( a.X \u002B b.X, a.Y \u002B b.Y );\r\n\tpublic static PixelPoint operator -( PixelPoint a, PixelPoint b ) =\u003E new( a.X - b.X, a.Y - b.Y );\r\n\tpublic static PixelPoint operator -( PixelPoint a ) =\u003E new( -a.X, -a.Y );\r\n\tpublic static PixelPoint operator *( PixelPoint a, int scale ) =\u003E new( a.X * scale, a.Y * scale );\r\n\tpublic static bool operator ==( PixelPoint a, PixelPoint b ) =\u003E a.X == b.X \u0026\u0026 a.Y == b.Y;\r\n\tpublic static bool operator !=( PixelPoint a, PixelPoint b ) =\u003E !(a == b);\r\n\r\n\tpublic static implicit operator Vector2( PixelPoint p ) =\u003E new( p.X, p.Y );\r\n\tpublic static implicit operator PixelPoint( Vector2 v ) =\u003E new( (int)v.x, (int)v.y );\r\n\r\n\tpublic static readonly PixelPoint Zero = new( 0, 0 );\r\n\r\n\tpublic bool Equals( PixelPoint other ) =\u003E X == other.X \u0026\u0026 Y == other.Y;\r\n\tpublic override bool Equals( object obj ) =\u003E obj is PixelPoint other \u0026\u0026 Equals( other );\r\n\tpublic override int GetHashCode() =\u003E HashCode.Combine( X, Y );\r\n\tpublic override string ToString() =\u003E $\u0022({X}, {Y})\u0022;\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/TextDisplay.cs","FileName":"TextDisplay.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Text renderer that uses font animation data to draw strings.\r\n/// Each character is a named animation in the font sprite type (e.g. \u0022a\u0022, \u00221\u0022, \u0022\u002B\u0022).\r\n/// Supports scale, colour override with alpha, and newlines.\r\n///\r\n/// Original font is 6\u00D79 pixels per glyph with 1px spacing.\r\n/// \u003C/summary\u003E\r\npublic class TextDisplay : Entity\r\n{\r\n\tprotected string _text;\r\n\tpublic string Text { set =\u003E _text = value; }\r\n\r\n\tprotected Color _color;\r\n\tpublic Color TextColor { set =\u003E _color = value; }\r\n\r\n\tprotected int _letterWidth;\r\n\tprotected int _letterHeight;\r\n\tprotected string _fontName;\r\n\tprotected int _spacing = 1;\r\n\tprotected int _scale;\r\n\r\n\tpublic TextDisplay( string text, TransposerScene scene, int x, int y, string fontName, Color color, int scale = 1 )\r\n\t{\r\n\t\t_text = text;\r\n\t\t_scene = scene;\r\n\t\t_fontName = fontName;\r\n\t\t_type = _fontName;\r\n\t\t_collideable = false;\r\n\r\n\t\tPixelPoint size = GetAnimSize( _type, \u0022a\u0022 );\r\n\t\t_letterWidth = size.X;\r\n\t\t_letterHeight = size.Y;\r\n\r\n\t\tPixelX = x;\r\n\t\tPixelY = y;\r\n\r\n\t\t_color = color;\r\n\t\tSetOverriddenColor( _color );\r\n\t\tSetOverrideAlpha( true );\r\n\r\n\t\t_depth = Globals.DEPTH_TEXT;\r\n\t\t_scale = scale;\r\n\t\t_hitbox = new PixelRect( 0, 0, ((_letterWidth \u002B 1) * text.Length - 1) * _scale, _letterHeight * _scale );\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\tbase.Draw();\r\n\r\n\t\tint currentX = PixelX;\r\n\t\tint currentY = PixelY;\r\n\r\n\t\tfor ( int i = 0; i \u003C _text.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tchar c = _text[i];\r\n\r\n\t\t\tif ( c == \u0027\\n\u0027 )\r\n\t\t\t{\r\n\t\t\t\tcurrentY -= _letterHeight * _scale;\r\n\t\t\t\tcurrentX = PixelX;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Space \u2014 just advance without drawing.\r\n\t\t\tif ( c == \u0027 \u0027 )\r\n\t\t\t{\r\n\t\t\t\tcurrentX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tList\u003CPixelData\u003E pixelDataList = GetPixelDataList( _fontName, c.ToString() );\r\n\t\t\tif ( pixelDataList is not null )\r\n\t\t\t\tDrawPixels( pixelDataList, currentX, currentY, _scale );\r\n\r\n\t\t\tcurrentX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/TitleText.cs","FileName":"TitleText.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Bouncing title text that floats randomly around the screen with a ghost trail.\r\n/// Used for \u0022transposer\u0022 on the main menu, rendered at 2\u00D7 scale in red.\r\n/// \u003C/summary\u003E\r\npublic class TitleText : TextDisplay\r\n{\r\n\tprivate float _moveSpeed = 30f;\r\n\tprivate Vector2 _direction;\r\n\r\n\tprivate Queue\u003CPixelPoint\u003E _lastPositions = new();\r\n\tprivate const int NUM_LAST_POSITIONS = 3;\r\n\r\n\tpublic TitleText( string text, TransposerScene scene, int x, int y, string fontName, int scale = 1 )\r\n\t\t: base( text, scene, x, y, fontName, Color.Black, scale )\r\n\t{\r\n\t\tfloat angle = Game.Random.Next( 0, 360 );\r\n\t\t_direction = GetVectorFromRotation( angle );\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\t\tMove( _direction, deltaTime );\r\n\r\n\t\t// Nudge the direction by a small random angle each frame to create\r\n\t\t// a \u0022drunk walk\u0022 \u2014 the title drifts around rather than moving in a straight line.\r\n\t\tfloat angleChange = Game.Random.Float( -7f, 7f );\r\n\t\tfloat currentAngle = GetRotationFromVector( _direction ) * (180f / MathF.PI);\r\n\t\t_direction = GetVectorFromRotation( currentAngle \u002B angleChange );\r\n\t}\r\n\r\n\tprivate void Move( Vector2 moveVector, float deltaTime )\r\n\t{\r\n\t\tVector2 newExactPos = ExactPos \u002B moveVector * _moveSpeed * deltaTime;\r\n\t\tPixelPoint newPixelPos = new( (int)MathF.Round( newExactPos.x ), (int)MathF.Round( newExactPos.y ) );\r\n\r\n\t\tif ( IsInBounds( newPixelPos.X, newPixelPos.Y, 3 ) )\r\n\t\t{\r\n\t\t\tif ( newPixelPos != PixelPosition )\r\n\t\t\t\tAddLastPosition( PixelPosition );\r\n\t\t\tExactPos = newExactPos;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tfloat angle = Game.Random.Next( 0, 360 );\r\n\t\t\t_direction = GetVectorFromRotation( angle );\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\t// Draw ghost trail at previous positions in black.\r\n\t\tfloat opacity = 0.45f;\r\n\t\tforeach ( PixelPoint pos in _lastPositions )\r\n\t\t{\r\n\t\t\tSetOverriddenColor( new Color( 0, 0, 0, opacity ) );\r\n\t\t\tint currentX = pos.X;\r\n\t\t\tint currentY = pos.Y;\r\n\r\n\t\t\tfor ( int i = 0; i \u003C _text.Length; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tchar c = _text[i];\r\n\t\t\t\tif ( c == \u0027\\n\u0027 ) { currentY -= _letterHeight * _scale; currentX = PixelX; continue; }\r\n\t\t\t\tif ( c == \u0027 \u0027 ) { currentX \u002B= (_letterWidth \u002B _spacing) * _scale; continue; }\r\n\t\t\t\tList\u003CPixelData\u003E pxList = GetPixelDataList( _fontName, c.ToString() );\r\n\t\t\t\tif ( pxList is not null ) DrawPixels( pxList, currentX, currentY, _scale );\r\n\t\t\t\tcurrentX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Draw main text in red, semi-transparent.\r\n\t\tSetOverriddenColor( new Color( 1f, 0f, 0f, 0.5f ) );\r\n\t\tint currX = PixelX;\r\n\t\tint currY = PixelY;\r\n\t\tfor ( int i = 0; i \u003C _text.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tchar c = _text[i];\r\n\t\t\tif ( c == \u0027\\n\u0027 ) { currY -= _letterHeight * _scale; currX = PixelX; continue; }\r\n\t\t\tif ( c == \u0027 \u0027 ) { currX \u002B= (_letterWidth \u002B _spacing) * _scale; continue; }\r\n\t\t\tList\u003CPixelData\u003E pxList = GetPixelDataList( _fontName, c.ToString() );\r\n\t\t\tif ( pxList is not null ) DrawPixels( pxList, currX, currY, _scale );\r\n\t\t\tcurrX \u002B= (_letterWidth \u002B _spacing) * _scale;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void AddLastPosition( PixelPoint pos )\r\n\t{\r\n\t\tif ( _lastPositions.Count \u003E= NUM_LAST_POSITIONS )\r\n\t\t\t_lastPositions.Dequeue();\r\n\t\t_lastPositions.Enqueue( pos );\r\n\t}\r\n\r\n\t// \u2500\u2500 Vector/rotation helpers (ported from Utils.cs) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t// Converts degrees to a unit direction vector.\r\n\t// Uses -sin for X so that 0\u00B0 points up (\u002BY), 90\u00B0 points right (\u002BX) \u2014 matching\r\n\t// the convention used in the original Unity port where 0\u00B0 = \u0022up\u0022 not \u0022right\u0022.\r\n\tprivate static Vector2 GetVectorFromRotation( float degrees )\r\n\t{\r\n\t\tfloat rad = degrees * (MathF.PI / 180f);\r\n\t\treturn new Vector2( MathF.Sin( -rad ), MathF.Cos( rad ) );\r\n\t}\r\n\r\n\t// Converts a direction vector back to degrees in the same convention as above.\r\n\t// Subtracts Atan2(1,0) (= 90\u00B0) to rotate the reference frame so 0\u00B0 aligns with \u002BY.\r\n\tprivate static float GetRotationFromVector( Vector2 vector )\r\n\t{\r\n\t\treturn MathF.Atan2( vector.y, vector.x ) - MathF.Atan2( 1f, 0f );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/InputManager.cs","FileName":"InputManager.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Input wrapper that provides static held/just-pressed booleans\r\n/// for the Transposer game controls.\r\n///\r\n/// Must be updated once per frame before entity updates \u2014 call\r\n/// \u003Csee cref=\u0022Update\u0022/\u003E from the game entry point component.\r\n///\r\n/// Uses the engine action system (Input.Down / Input.Pressed) for WASD\u002BSpace\r\n/// which gives proper held-state detection. Arrow keys are not bound by default\r\n/// but can be added via the Input.config action bindings.\r\n/// Analog stick (controller) input is also supported via Input.AnalogMove.\r\n/// \u003C/summary\u003E\r\npublic static class InputManager\r\n{\r\n\t// Analog stick deadzone \u2014 below this magnitude the stick is treated as neutral.\r\n\tprivate const float ANALOG_DEADZONE = 0.3f;\r\n\r\n\t// Previous-frame analog directions, used to generate JustPressed edges.\r\n\tprivate static bool _prevAnalogLeft;\r\n\tprivate static bool _prevAnalogRight;\r\n\tprivate static bool _prevAnalogUp;\r\n\tprivate static bool _prevAnalogDown;\r\n\r\n\t// \u2500\u2500 Analog speed scale (1.0 for keyboard, 0\u20131 proportional for controller) \u2500\u2500\r\n\tpublic static float MoveSpeedScale { get; private set; }\r\n\r\n\t// \u2500\u2500 Held state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tpublic static bool LeftPressed { get; private set; }\r\n\tpublic static bool RightPressed { get; private set; }\r\n\tpublic static bool UpPressed { get; private set; }\r\n\tpublic static bool DownPressed { get; private set; }\r\n\tpublic static bool SpacePressed { get; private set; }\r\n\r\n\t// \u2500\u2500 Just-pressed edge detection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tpublic static bool LeftJustPressed { get; private set; }\r\n\tpublic static bool RightJustPressed { get; private set; }\r\n\tpublic static bool UpJustPressed { get; private set; }\r\n\tpublic static bool DownJustPressed { get; private set; }\r\n\tpublic static bool SpaceJustPressed { get; private set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Poll input and update all state.\r\n\t/// Uses the action system for WASD\u002BSpace, raw keyboard for arrow keys,\r\n\t/// and Input.AnalogMove for controller left stick.\r\n\t/// Call once per frame before any game logic runs.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static void Update()\r\n\t{\r\n\t\t// Controller left stick \u2014 map to cardinal directions via deadzone.\r\n\t\tvar stick = Input.AnalogMove;\r\n\t\tbool analogLeft  = stick.y \u003E  ANALOG_DEADZONE;\r\n\t\tbool analogRight = stick.y \u003C -ANALOG_DEADZONE;\r\n\t\tbool analogUp    = stick.x \u003E  ANALOG_DEADZONE;\r\n\t\tbool analogDown  = stick.x \u003C -ANALOG_DEADZONE;\r\n\r\n\t\t// Speed scale: remap stick magnitude from [deadzone, 1] \u2192 [0, 1].\r\n\t\t// Keyboard always gives full speed; controller scales with stick pressure.\r\n\t\tbool anyAnalog = analogLeft || analogRight || analogUp || analogDown;\r\n\t\tif ( Input.UsingController \u0026\u0026 anyAnalog )\r\n\t\t{\r\n\t\t\tfloat raw = stick.Length;\r\n\t\t\tMoveSpeedScale = MathX.Clamp( (raw - ANALOG_DEADZONE) / (1f - ANALOG_DEADZONE), 0f, 1f );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tMoveSpeedScale = 1f;\r\n\t\t}\r\n\r\n\t\t// Held state: action system (WASD) \u002B raw keyboard (arrows) \u002B analog stick.\r\n\t\tLeftPressed  = Input.Down( \u0022Left\u0022 )     || Input.Keyboard.Down( \u0022LEFTARROW\u0022 )  || analogLeft;\r\n\t\tRightPressed = Input.Down( \u0022Right\u0022 )    || Input.Keyboard.Down( \u0022RIGHTARROW\u0022 ) || analogRight;\r\n\t\tUpPressed    = Input.Down( \u0022Up\u0022 )  || Input.Keyboard.Down( \u0022UPARROW\u0022 )    || analogUp;\r\n\t\tDownPressed  = Input.Down( \u0022Down\u0022 ) || Input.Keyboard.Down( \u0022DOWNARROW\u0022 )  || analogDown;\r\n\t\tSpacePressed = Input.Down( \u0022Start\u0022 );\r\n\r\n\t\t// Just-pressed: action system (WASD) \u002B raw keyboard (arrows) \u002B analog stick rising edge.\r\n\t\tLeftJustPressed  = Input.Pressed( \u0022Left\u0022 )     || Input.Keyboard.Pressed( \u0022LEFTARROW\u0022 )  || (analogLeft  \u0026\u0026 !_prevAnalogLeft);\r\n\t\tRightJustPressed = Input.Pressed( \u0022Right\u0022 )    || Input.Keyboard.Pressed( \u0022RIGHTARROW\u0022 ) || (analogRight \u0026\u0026 !_prevAnalogRight);\r\n\t\tUpJustPressed    = Input.Pressed( \u0022Up\u0022 )  || Input.Keyboard.Pressed( \u0022UPARROW\u0022 )    || (analogUp    \u0026\u0026 !_prevAnalogUp);\r\n\t\tDownJustPressed  = Input.Pressed( \u0022Down\u0022 ) || Input.Keyboard.Pressed( \u0022DOWNARROW\u0022 )  || (analogDown  \u0026\u0026 !_prevAnalogDown);\r\n\t\tSpaceJustPressed = Input.Pressed( \u0022Start\u0022 );\r\n\r\n\t\t_prevAnalogLeft  = analogLeft;\r\n\t\t_prevAnalogRight = analogRight;\r\n\t\t_prevAnalogUp    = analogUp;\r\n\t\t_prevAnalogDown  = analogDown;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"PixelFontTest.cs","FileName":"PixelFontTest.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"using Sandbox.Utility;\r\n\r\nnamespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// Interactive platformer test for the sprite, hitbox, and collision systems.\r\n///\r\n/// Controls:\r\n///   Left / Right \u2014 move horizontally\r\n///   Space \u2014 jump (when grounded)\r\n///   F \u2014 toggle FlipX on the player\r\n///   H \u2014 toggle hitbox debug overlay\r\n///\r\n/// Demonstrates:\r\n///   - Gravity, ground collision, and box collision response\r\n///   - Step-by-step axis-separated movement with test-before-commit\r\n///   - Flip-aware hitboxes on the box sprites\r\n///   - PixelCollision registry, Collide queries, and GetUnpenetration\r\n///   - DrawHitbox / DrawHitboxFilled debug visualisation\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Pixel Font Test\u0022 )]\r\n[Category( \u0022Testing\u0022 )]\r\n[Icon( \u0022text_fields\u0022 )]\r\npublic sealed class PixelFontTest : Component\r\n{\r\n\t// \u2500\u2500 Sprites \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate PixelSpriteComponent _player;\r\n\tprivate List\u003CPixelSpriteComponent\u003E _boxes = new();\r\n\r\n\t// \u2500\u2500 Collision entries \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate CollisionEntry _playerEntry;\r\n\tprivate List\u003CCollisionEntry\u003E _boxEntries = new();\r\n\r\n\t// \u2500\u2500 Positions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate float _playerX = 20f;\r\n\tprivate float _playerY = 60f;\r\n\r\n\tprivate struct BoxPlacement\r\n\t{\r\n\t\tpublic int X;\r\n\t\tpublic int Y;\r\n\t\tpublic bool FlipX;\r\n\r\n\t\tpublic BoxPlacement( int x, int y, bool flipX = false )\r\n\t\t{\r\n\t\t\tX = x;\r\n\t\t\tY = y;\r\n\t\t\tFlipX = flipX;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate readonly BoxPlacement[] _boxPlacements = new BoxPlacement[]\r\n\t{\r\n\t\t// Ground-level stepping stones (player can walk onto these from the side\r\n\t\t// since the box top = 4, well below the player\u0027s hitbox top).\r\n\t\tnew( 50, 0 ),\r\n\t\tnew( 55, 0 ),\r\n\t\tnew( 60, 0 ),\r\n\r\n\t\t// Low step \u2014 stack of 2 (top at y=8, reachable with a small jump).\r\n\t\tnew( 75, 0 ),\r\n\t\tnew( 75, 5 ),\r\n\t\tnew( 80, 0 ),\r\n\t\tnew( 80, 5 ),\r\n\r\n\t\t// Medium ledge \u2014 stack of 3 (top at y=12, near max jump from ground).\r\n\t\tnew( 95, 0 ),\r\n\t\tnew( 95, 5 ),\r\n\t\tnew( 95, 10 ),\r\n\t\tnew( 100, 0 ),\r\n\t\tnew( 100, 5 ),\r\n\t\tnew( 100, 10 ),\r\n\r\n\t\t// One flipped box to visually confirm asymmetric hitbox mirroring.\r\n\t\tnew( 105, 0, true ),\r\n\t};\r\n\r\n\t// \u2500\u2500 Physics state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate float _velocityX;\r\n\tprivate float _velocityY;\r\n\tprivate bool _grounded;\r\n\r\n\t// \u2500\u2500 State \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate bool _showHitboxes = true;\r\n\r\n\t// \u2500\u2500 Configuration \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t[Property]\r\n\tpublic Color32 BackgroundColor { get; set; } = new Color32( 30, 30, 50, 255 );\r\n\r\n\t[Property]\r\n\tpublic Color32 BodyColor { get; set; } = new Color32( 200, 200, 200, 255 );\r\n\r\n\t[Property]\r\n\tpublic float MoveSpeed { get; set; } = 30f;\r\n\r\n\t[Property]\r\n\tpublic float Gravity { get; set; } = 100f;\r\n\r\n\t[Property]\r\n\tpublic float JumpVelocity { get; set; } = 55f;\r\n\r\n\t// \u2500\u2500 Lifecycle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tSpriteManager.Reload();\r\n\t\tSpriteManager.LoadAll();\r\n\r\n\t\t// Player.\r\n\t\t_player = new PixelSpriteComponent { SpriteName = \u0022player\u0022 };\r\n\t\t_player.PlayAnimation( \u0022default\u0022 );\r\n\t\t_player.Tags.Add( \u0022player\u0022 );\r\n\t\t_playerEntry = PixelCollision.Register( _player, (int)_playerX, (int)_playerY );\r\n\r\n\t\t// Boxes.\r\n\t\tforeach ( BoxPlacement bp in _boxPlacements )\r\n\t\t{\r\n\t\t\tPixelSpriteComponent box = new() { SpriteName = \u0022box\u0022 };\r\n\t\t\tbox.PlayAnimation( \u0022idle\u0022 );\r\n\t\t\tbox.Tags.Add( \u0022solid\u0022 );\r\n\t\t\tbox.FlipX = bp.FlipX;\r\n\r\n\t\t\t_boxes.Add( box );\r\n\t\t\t_boxEntries.Add( PixelCollision.Register( box, bp.X, bp.Y ) );\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void OnDestroy()\r\n\t{\r\n\t\tPixelCollision.Clear();\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tPixelScreen screen = PixelScreen.Instance;\r\n\t\tif ( screen is null )\r\n\t\t\treturn;\r\n\r\n\t\tfloat dt = Time.Delta;\r\n\r\n\t\tHandleInput( dt );\r\n\t\tApplyPhysics( dt );\r\n\r\n\t\t// Sync collision entry.\r\n\t\t_playerEntry.X = (int)_playerX;\r\n\t\t_playerEntry.Y = (int)_playerY;\r\n\r\n\t\t// Advance animations.\r\n\t\t_player?.Update( dt );\r\n\r\n\t\t// \u2500\u2500 Draw \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t\tscreen.Clear( BackgroundColor );\r\n\r\n\t\tbool wasGui = screen.DrawInGUISpace;\r\n\t\tscreen.DrawInGUISpace = true;\r\n\r\n\t\t// Ground line.\r\n\t\tscreen.DrawLine( 0, 0, screen.PixelWidth - 1, 0, new Color32( 100, 100, 100, 255 ) );\r\n\r\n\t\t// Boxes.\r\n\t\tfor ( int i = 0; i \u003C _boxes.Count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tint bx = _boxPlacements[i].X;\r\n\t\t\tint by = _boxPlacements[i].Y;\r\n\t\t\t_boxes[i].Draw( bx, by );\r\n\r\n\t\t\tif ( _showHitboxes )\r\n\t\t\t{\r\n\t\t\t\t_boxes[i].DrawHitboxFilled( bx, by, new Color32( 50, 100, 255, 60 ) );\r\n\t\t\t\t_boxes[i].DrawHitbox( bx, by, new Color32( 80, 130, 255, 255 ) );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Player.\r\n\t\tint px = (int)_playerX;\r\n\t\tint py = (int)_playerY;\r\n\t\t_player?.Draw( px, py );\r\n\r\n\t\tif ( _showHitboxes )\r\n\t\t{\r\n\t\t\tColor32 hitboxColor = _grounded\r\n\t\t\t\t? new Color32( 50, 255, 50, 60 )\r\n\t\t\t\t: new Color32( 255, 200, 50, 60 );\r\n\r\n\t\t\t_player?.DrawHitboxFilled( px, py, hitboxColor );\r\n\t\t\t_player?.DrawHitbox( px, py, new Color32( 50, 255, 50, 255 ) );\r\n\t\t}\r\n\r\n\t\t// \u2500\u2500 HUD \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t\tint textY = screen.PixelHeight - 7;\r\n\t\tPixelText.Draw( 2, textY, \u0022left right move\u0022, BodyColor );\r\n\t\ttextY -= 7;\r\n\t\tPixelText.Draw( 2, textY, \u0022space jump\u0022, BodyColor );\r\n\t\ttextY -= 7;\r\n\t\tPixelText.Draw( 2, textY, \u0022f flip  h hitbox\u0022, BodyColor );\r\n\t\ttextY -= 9;\r\n\r\n\t\tif ( _player?.FlipX == true )\r\n\t\t{\r\n\t\t\tPixelText.Draw( 2, textY, \u0022flipped\u0022, new Color32( 255, 200, 50, 255 ) );\r\n\t\t\ttextY -= 7;\r\n\t\t}\r\n\r\n\t\tif ( _grounded )\r\n\t\t\tPixelText.Draw( 2, textY, \u0022grounded\u0022, new Color32( 50, 255, 50, 255 ) );\r\n\t\telse\r\n\t\t\tPixelText.Draw( 2, textY, \u0022airborne\u0022, new Color32( 255, 150, 50, 255 ) );\r\n\r\n\t\tscreen.DrawInGUISpace = wasGui;\r\n\t}\r\n\r\n\t// \u2500\u2500 Input \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate void HandleInput( float dt )\r\n\t{\r\n\t\t// Horizontal input \u2192 velocity.\r\n\t\t_velocityX = 0f;\r\n\t\tif ( Input.Down( \u0022Left\u0022 ) ) _velocityX -= MoveSpeed;\r\n\t\tif ( Input.Down( \u0022Right\u0022 ) ) _velocityX \u002B= MoveSpeed;\r\n\r\n\t\t// Face the direction of movement.\r\n\t\tif ( _player is not null )\r\n\t\t{\r\n\t\t\tif ( _velocityX \u003C 0f ) _player.FlipX = true;\r\n\t\t\telse if ( _velocityX \u003E 0f ) _player.FlipX = false;\r\n\t\t}\r\n\r\n\t\t// Jump.\r\n\t\tif ( Input.Pressed( \u0022Start\u0022 ) \u0026\u0026 _grounded )\r\n\t\t{\r\n\t\t\t_velocityY = JumpVelocity;\r\n\t\t\t_grounded = false;\r\n\t\t}\r\n\r\n\t\t// Toggles.\r\n\t\tif ( Input.Pressed( \u0022Flashlight\u0022 ) \u0026\u0026 _player is not null )\r\n\t\t\t_player.FlipX = !_player.FlipX;\r\n\r\n\t\tif ( Input.Keyboard.Pressed( \u0022H\u0022 ) )\r\n\t\t\t_showHitboxes = !_showHitboxes;\r\n\t}\r\n\r\n\t// \u2500\u2500 Physics \u002B collision response \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate void ApplyPhysics( float dt )\r\n\t{\r\n\t\t// Only apply gravity when airborne. This prevents velocity from\r\n\t\t// building up while standing on something and then causing a big\r\n\t\t// downward snap when sliding off an edge.\r\n\t\tif ( !_grounded )\r\n\t\t\t_velocityY -= Gravity * dt;\r\n\r\n\t\t// Clamp downward velocity to avoid tunnelling through thin platforms.\r\n\t\tconst float maxFallSpeed = -80f;\r\n\t\tif ( _velocityY \u003C maxFallSpeed )\r\n\t\t\t_velocityY = maxFallSpeed;\r\n\r\n\t\t// Compute desired movement in pixels (sub-pixel accumulation is handled\r\n\t\t// by keeping _playerX/_playerY as floats).\r\n\t\tfloat desiredX = _playerX \u002B _velocityX * dt;\r\n\t\tfloat desiredY = _playerY \u002B _velocityY * dt;\r\n\r\n\t\t// \u2500\u2500 Move X axis first, then Y. Test before commit. \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t\t// X axis.\r\n\t\tint testX = (int)desiredX;\r\n\t\tint testY = (int)_playerY;\r\n\r\n\t\tif ( PixelCollision.Collide( _player, \u0022solid\u0022, testX, testY ) is null )\r\n\t\t{\r\n\t\t\t_playerX = desiredX;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t// Blocked horizontally \u2014 zero X velocity and keep current X.\r\n\t\t\t_velocityX = 0f;\r\n\t\t}\r\n\r\n\t\t// Y axis.\r\n\t\ttestX = (int)_playerX;\r\n\t\ttestY = (int)desiredY;\r\n\r\n\t\tif ( PixelCollision.Collide( _player, \u0022solid\u0022, testX, testY ) is null )\r\n\t\t{\r\n\t\t\t_playerY = desiredY;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t// Blocked vertically \u2014 compute a Y-only correction so the player\r\n\t\t\t// sits flush against the surface. We don\u0027t use GetUnpenetration here\r\n\t\t\t// because with axis-separated movement we know the fix must be on Y,\r\n\t\t\t// but the general solver might pick X when edges are exactly aligned.\r\n\t\t\tList\u003CCollisionEntry\u003E hits = PixelCollision.CollideWithAll( _player, \u0022solid\u0022, testX, testY );\r\n\t\t\tint fixedY = testY;\r\n\r\n\t\t\tforeach ( CollisionEntry hit in hits )\r\n\t\t\t{\r\n\t\t\t\tPixelRect playerBox = _player.GetOffsetHitbox( testX, fixedY );\r\n\t\t\t\tPixelRect otherBox = hit.Sprite.GetOffsetHitbox( hit.X, hit.Y );\r\n\r\n\t\t\t\tif ( !playerBox.Overlaps( otherBox ) )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tif ( _velocityY \u003C= 0f )\r\n\t\t\t\t{\r\n\t\t\t\t\t// Falling \u2014 snap player\u0027s bottom to top of box.\r\n\t\t\t\t\tfixedY \u002B= otherBox.YMax - playerBox.YMin;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t// Rising \u2014 snap player\u0027s top to bottom of box.\r\n\t\t\t\t\tfixedY \u002B= otherBox.YMin - playerBox.YMax;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_playerY = fixedY;\r\n\r\n\t\t\t// If we were falling and got stopped, we landed.\r\n\t\t\tif ( _velocityY \u003C 0f )\r\n\t\t\t\t_grounded = true;\r\n\r\n\t\t\t_velocityY = 0f;\r\n\t\t}\r\n\r\n\t\t// Ground plane at y = 0.\r\n\t\tPixelRect groundCheck = _player.GetOffsetHitbox( (int)_playerX, (int)_playerY );\r\n\t\tif ( groundCheck.YMin \u003C 0 )\r\n\t\t{\r\n\t\t\t_playerY -= groundCheck.YMin; // push up so YMin == 0\r\n\t\t\t_velocityY = 0f;\r\n\t\t\t_grounded = true;\r\n\t\t}\r\n\r\n\t\t// Detect if we walked off an edge \u2014 check one pixel below for ground or solid.\r\n\t\tif ( _grounded \u0026\u0026 _velocityY \u003C= 0f )\r\n\t\t{\r\n\t\t\tint belowY = (int)_playerY - 1;\r\n\t\t\tPixelRect belowBox = _player.GetOffsetHitbox( (int)_playerX, belowY );\r\n\t\t\tbool onSolid = PixelCollision.Collide( _player, \u0022solid\u0022, (int)_playerX, belowY ) is not null;\r\n\t\t\tbool onGround = belowBox.YMin \u003C 0;\r\n\r\n\t\t\tif ( !onSolid \u0026\u0026 !onGround )\r\n\t\t\t{\r\n\t\t\t\t_grounded = false;\r\n\t\t\t\t// Start with a small downward nudge so the first airborne frame\r\n\t\t\t\t// actually moves the player and doesn\u0027t get stuck at the same Y.\r\n\t\t\t\t_velocityY = -Gravity * dt;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Scenes/MainMenuScene.cs","FileName":"MainMenuScene.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\n\n/// \u003Csummary\u003E\n/// Main menu scene. Shows the \u0022transposer\u0022 title bouncing around, score text,\n/// and replays the last game\u0027s grid swaps in the background progressively faster.\n/// After the player has died at least once, streams leaderboard entries upward\n/// from the bottom of the screen in a continuous loop.\n/// \u003C/summary\u003E\npublic class MainMenuScene : TransposerScene\n{\n\tprivate ScoreText _instructionsText;\n\tprivate bool _hasStartedSwitching;\n\tprivate bool _replayingSwaps;\n\tprivate int _replayIndex;\n\tprivate float _replayWaitTime;\n\tprivate float _replayTimer;\n\tprivate bool _replayStarted;\n\tprivate float _replayDelayTimer;\n\n\t// \u2500\u2500 Leaderboard scroll state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\tprivate List\u003Cstring\u003E _lbLines = new();\n\tprivate int _lbIndex;\n\tprivate float _lbSpawnTimer;\n\tprivate float _lbWaitTimer;\n\tprivate bool _lbReady;   // true once lines are populated and ready to spawn\n\tprivate bool _lbActive;  // true while this scene instance is alive; guards late async returns\n\tprivate bool _lbWaiting;\n\n\tprivate const float SPAWN_INTERVAL = 0.5f;\n\tprivate const float LOOP_WAIT      = 3f;\n\n\tpublic override void Activate()\n\t{\n\t\tbase.Activate();\n\n\t\t_hasStartedSwitching = false;\n\n\t\tAddEntity( new Background( 0, 0, this ) );\n\n\t\t// Title text at 2\u00D7 scale, centred.\n\t\tstring titleStr = \u0022transposer\u0022;\n\t\tint titleWidth = titleStr.Length * 14; // (6\u002B1)*2 = 14 per char at 2x\n\t\tTitleText title = new( titleStr, this,\n\t\t\tScreen.PixelWidth / 2 - (int)MathF.Round( titleWidth * 0.5f ),\n\t\t\tScreen.PixelHeight / 2 - 9, \u0022font\u0022, 2 );\n\t\ttitle.Depth -= 1;\n\t\tAddEntity( title );\n\n\t\tif ( !Globals.HasPlayedOnce )\n\t\t{\n\t\t\t_instructionsText = new( \u0022press space to start\u0022, this,\n\t\t\t\tScreen.PixelWidth / 2 - 70, 60, \u0022font\u0022 );\n\t\t\tAddEntity( _instructionsText );\n\t\t}\n\t\telse\n\t\t{\n\t\t\t_lbLines.Clear();\n\t\t\t_lbActive  = true;\n\t\t\t_lbReady   = false;\n\t\t\t_lbWaiting = false;\n\t\t\t_lbIndex   = 0;\n\t\t\tFetchLeaderboard();\n\t\t}\n\n\t\t// Set up swap replay (starts after 3s delay).\n\t\t_replayingSwaps = Globals.LastNumSwaps \u003E 0;\n\t\t_replayIndex = 0;\n\t\t_replayWaitTime = 1f;\n\t\t_replayTimer = 0f;\n\t\t_replayStarted = false;\n\t\t_replayDelayTimer = 3f;\n\n\t\tFadeIn( 0.25f );\n\t\tAudioManager.MusicPitch = 1f;\n\t\tAudioManager.FadeInMusic( 1f );\n\t}\n\n\tpublic override void Deactivate()\n\t{\n\t\tbase.Deactivate();\n\t\t_replayingSwaps = false;\n\t\t_lbActive = false; // prevent a late-arriving fetch result from going live\n\t}\n\n\tpublic override void UpdateScene( float deltaTime )\n\t{\n\t\tScreen.Clear( new Color32( 0, 0, 0, 255 ) );\n\n\t\tbase.UpdateScene( deltaTime );\n\n\t\t// Swap prompt text between controller and keyboard hint.\n\t\tif ( _instructionsText is not null )\n\t\t{\n\t\t\tif ( Input.UsingController )\n\t\t\t{\n\t\t\t\t_instructionsText.Text = \u0022press a to start\u0022;\n\t\t\t\t_instructionsText.PixelX = Screen.PixelWidth / 2 - 56; // 16 chars \u00D7 7px / 2\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t_instructionsText.Text = \u0022press space to start\u0022;\n\t\t\t\t_instructionsText.PixelX = Screen.PixelWidth / 2 - 70; // 20 chars \u00D7 7px / 2\n\t\t\t}\n\t\t}\n\n\t\t// Toggle mute with M.\n\t\tif ( Input.Pressed( \u0022Mute\u0022 ) )\n\t\t\tAudioManager.ToggleMute();\n\n\t\tif ( AudioManager.IsMuted )\n\t\t\tDrawMuteIcon();\n\n\t\t// Space/Z \u2192 start game, but not while the ESC screen is covering the menu.\n\t\tif ( !_switchingScene \u0026\u0026 !_hasStartedSwitching\n\t\t\t\u0026\u0026 Input.Pressed( \u0022Start\u0022 ) )\n\t\t{\n\t\t\tSetFadeToBlackCallback( () =\u003E SwitchScene( SceneType.Game ) );\n\t\t\tFadeToBlack( 0.25f );\n\t\t\t_hasStartedSwitching = true;\n\t\t}\n\n\t\t// Leaderboard scroll tick.\n\t\tif ( _lbReady )\n\t\t{\n\t\t\tif ( _lbWaiting )\n\t\t\t{\n\t\t\t\t_lbWaitTimer -= deltaTime;\n\t\t\t\tif ( _lbWaitTimer \u003C= 0f )\n\t\t\t\t{\n\t\t\t\t\t_lbWaiting = false;\n\t\t\t\t\t_lbIndex = 0;\n\t\t\t\t\t_lbSpawnTimer = 0f;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t_lbSpawnTimer -= deltaTime;\n\t\t\t\tif ( _lbSpawnTimer \u003C= 0f )\n\t\t\t\t{\n\t\t\t\t\tSpawnNextLeaderboardEntry();\n\t\t\t\t\t_lbSpawnTimer = SPAWN_INTERVAL;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Replay swaps from the last game.\n\t\tif ( _replayingSwaps )\n\t\t\tHandleSwapReplay( deltaTime );\n\n\t\tHandleTransposing( deltaTime );\n\t\tHandleFading( deltaTime );\n\t}\n\n\t// \u2500\u2500 Leaderboard \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\tprivate async void FetchLeaderboard()\n\t{\n\t\t//Log.Info( $\u0022[Transposer] FetchLeaderboard: fetching \u0027{Globals.LEADERBOARD_STAT}\u0027\u0022 );\n\n\t\tvar lb = Sandbox.Services.Leaderboards.GetFromStat( Globals.LEADERBOARD_STAT );\n\t\tlb.SetAggregationMax();\n\t\tlb.SetSortDescending();\n\t\tlb.MaxEntries = 100;\n\t\tawait lb.Refresh();\n\n\t\t//Log.Info( $\u0022[Transposer] Leaderboard refresh done. Entry count: {lb.Entries.Count()}\u0022 );\n\n\t\t_lbLines.Clear();\n\n\t\tint rank = 1;\n\t\tforeach ( var entry in lb.Entries )\n\t\t\t_lbLines.Add( FormatLine( rank\u002B\u002B, entry.DisplayName, (int)entry.Value ) );\n\n\t\t//Log.Info( $\u0022[Transposer] {_lbLines.Count} lines ready.\u0022 );\n\n\t\t// Deactivate() sets _lbReady=false; if the scene was torn down while we\n\t\t// were awaiting, discard the results \u2014 UpdateScene is no longer running.\n\t\tif ( !_lbActive )\n\t\t{\n\t\t\t_lbLines.Clear();\n\t\t\treturn;\n\t\t}\n\n\t\t_lbReady = true;\n\t\t_lbIndex = 0;\n\t\t_lbSpawnTimer = 0f;\n\t}\n\n\tprivate static string SanitizeName( string name )\n\t{\n\t\tname = name.Trim();\n\t\tvar sb = new System.Text.StringBuilder( name.Length );\n\t\tforeach ( char c in name )\n\t\t{\n\t\t\tif ( c \u003E= \u0027a\u0027 \u0026\u0026 c \u003C= \u0027z\u0027 || c \u003E= \u00270\u0027 \u0026\u0026 c \u003C= \u00279\u0027 )\n\t\t\t\tsb.Append( c );\n\t\t\telse if ( c \u003E= \u0027A\u0027 \u0026\u0026 c \u003C= \u0027Z\u0027 )\n\t\t\t\tsb.Append( (char)(c \u002B 32) );\n\t\t\telse if ( c == \u0027 \u0027 )\n\t\t\t\tsb.Append( \u0027 \u0027 );\n\t\t\telse\n\t\t\t\tsb.Append( \u0027?\u0027 );\n\t\t}\n\t\treturn sb.ToString();\n\t}\n\n\tprivate static string FormatLine( int rank, string name, int score )\n\t{\n\t\tname = SanitizeName( name );\n\t\tif ( name.Length \u003E 10 ) name = name[..10];\n\t\treturn rank \u002B \u0022: \u0022 \u002B name \u002B \u0022: \u0022 \u002B score;\n\t}\n\n\tprivate void SpawnNextLeaderboardEntry()\n\t{\n\t\tif ( _lbIndex \u003E= _lbLines.Count )\n\t\t{\n\t\t\t_lbWaiting = true;\n\t\t\t_lbWaitTimer = LOOP_WAIT;\n\t\t\treturn;\n\t\t}\n\n\t\tstring line = _lbLines[_lbIndex];\n\t\tint lineW = (line.Length * 7) - 1;\n\t\tint x = Screen.PixelWidth / 2 - lineW / 2;\n\t\tint y = -_lbLetterHeight;\n\n\t\tAddEntity( new LeaderboardScrollText( line, this, x, y, \u0022font\u0022, _lbIndex \u002B 1 ) );\n\t\t_lbIndex\u002B\u002B;\n\t}\n\n\t// Letter height of the \u0022font\u0022 sprite at scale 1 \u2014 used for spawn-below-screen offset.\n\t// Matches TextDisplay._letterHeight for \u0022font\u0022 (which is 9px).\n\tprivate const int _lbLetterHeight = 9;\n\n\t// \u2500\u2500 Swap replay \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n\t/// \u003Csummary\u003E\n\t/// Progressively replay the last game\u0027s grid swaps with decreasing delay,\n\t/// starting 3 seconds after scene activation.\n\t/// \u003C/summary\u003E\n\tprivate void HandleSwapReplay( float deltaTime )\n\t{\n\t\tif ( !_replayStarted )\n\t\t{\n\t\t\t_replayDelayTimer -= deltaTime;\n\t\t\tif ( _replayDelayTimer \u003E 0f )\n\t\t\t\treturn;\n\t\t\t_replayStarted = true;\n\t\t}\n\n\t\tif ( _replayIndex \u003E= Globals.LastNumSwaps )\n\t\t{\n\t\t\t_replayingSwaps = false;\n\t\t\treturn;\n\t\t}\n\n\t\t_replayTimer -= deltaTime;\n\t\tif ( _replayTimer \u003C= 0f )\n\t\t{\n\t\t\tSwapGridSquares();\n\t\t\t_replayIndex\u002B\u002B;\n\n\t\t\t// Decrease the wait time between each replayed swap so the replay\n\t\t\t// progressively accelerates, bottoming out at 10ms between swaps.\n\t\t\t_replayWaitTime -= 0.025f;\n\t\t\tif ( _replayWaitTime \u003C 0.01f )\n\t\t\t\t_replayWaitTime = 0.01f;\n\n\t\t\t_replayTimer = _replayWaitTime;\n\t\t}\n\t}\n}\n"},{"Ident":"facepunch.transposer","Path":"PixelScreen.cs","FileName":"PixelScreen.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"using Sandbox.Rendering;\r\n\r\nnamespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// Software-rendered pixel buffer that draws to the screen via the camera HUD.\r\n///\r\n/// Design: Every frame, game code writes into a \u003Csee cref=\u0022Color32\u0022/\u003E array through\r\n/// the drawing API (SetPixel, DrawLine, etc.). At the end of each frame the dirty\r\n/// buffer is uploaded to a GPU texture and rendered as a letterboxed quad with\r\n/// point-sampled filtering so each logical pixel maps to a crisp block on screen.\r\n///\r\n/// Ported from the Unity3D pixelshitter framework \u2014 stripped down to just the\r\n/// rendering core with no entity/scene/sprite systems.\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Pixel Screen\u0022 )]\r\n[Category( \u0022Rendering\u0022 )]\r\n[Icon( \u0022grid_on\u0022 )]\r\npublic sealed class PixelScreen : Component\r\n{\r\n\t// \u2500\u2500 Singleton convenience \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t// Lets any code reach the active pixel screen without wiring up references.\r\n\t// Set in OnEnabled / cleared in OnDisabled so it always reflects the live instance.\r\n\tpublic static PixelScreen Instance { get; private set; }\r\n\r\n\t// \u2500\u2500 Configurable properties \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Width of the pixel buffer in logical pixels.\r\n\t/// Default 160 gives an exact 16:9 ratio with the 90-high buffer.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Range( 1, 1024 )]\r\n\tpublic int PixelWidth { get; set; } = 160;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Height of the pixel buffer in logical pixels.\r\n\t/// Default 90 gives an exact 16:9 ratio with the 160-wide buffer.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Range( 1, 1024 )]\r\n\tpublic int PixelHeight { get; set; } = 90;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Camera offset applied when writing pixels.\r\n\t/// All \u003Csee cref=\u0022SetPixel\u0022/\u003E/\u003Csee cref=\u0022AddPixel\u0022/\u003E calls are shifted by this\r\n\t/// unless \u003Csee cref=\u0022DrawInGUISpace\u0022/\u003E is true.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic PixelPoint CameraPos { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// When true, pixel coordinates are treated as screen-relative (HUD mode)\r\n\t/// and the camera offset is ignored.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool DrawInGUISpace { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Screen shake intensity in pixels. Decays toward zero each frame.\r\n\t/// Set this to a positive value to trigger a shake effect.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic float ShakeAmount { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Rate at which \u003Csee cref=\u0022ShakeAmount\u0022/\u003E decays per second.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic float ShakeDecay { get; set; } = 8f;\r\n\r\n\t// \u2500\u2500 Computed properties \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How many screen pixels each logical pixel occupies.\r\n\t/// Matches the integer scale used by the letterboxed renderer to avoid sub-pixel seams.\r\n\t/// \u003C/summary\u003E\r\n\tpublic int PixelSize\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( PixelWidth \u003C= 0 || PixelHeight \u003C= 0 ) return 1;\r\n\t\t\tint scaleX = (int)(Screen.Width / PixelWidth);\r\n\t\t\tint scaleY = (int)(Screen.Height / PixelHeight);\r\n\t\t\treturn Math.Max( 1, Math.Min( scaleX, scaleY ) );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Direct read access to the backing pixel array.\r\n\t/// Length is \u003Cc\u003EPixelWidth * PixelHeight\u003C/c\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic ReadOnlySpan\u003CColor32\u003E Pixels =\u003E _pixels;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Writable access to the raw pixel buffer. Use with care \u2014\r\n\t/// callers must set \u003Csee cref=\u0022MarkDirty\u0022/\u003E after bulk writes.\r\n\t/// Needed by the grid-transposing effect which rearranges pixel regions each frame.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Color32[] GetPixelsWritable() =\u003E _pixels;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Mark the pixel buffer as dirty so it gets re-uploaded to the GPU next frame.\r\n\t/// Call this after directly modifying the array returned by \u003Csee cref=\u0022GetPixelsWritable\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void MarkDirty()\r\n\t{\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Reallocate the pixel buffer and GPU texture to match the current\r\n\t/// \u003Csee cref=\u0022PixelWidth\u0022/\u003E and \u003Csee cref=\u0022PixelHeight\u0022/\u003E.\r\n\t/// Call this after changing the resolution at runtime.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void ResizeBuffer() =\u003E InitBuffer();\r\n\r\n\t// \u2500\u2500 Internal state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate Color32[] _pixels;\r\n\tprivate Texture _texture;\r\n\tprivate bool _dirty;\r\n\r\n\t// Material using our custom point-filtered shader (nearest-neighbor sampling).\r\n\t// Built-in Material.UI.Basic hardcodes anisotropic filtering in the shader and\r\n\t// can\u0027t be overridden via render attributes, so we load our own variant.\r\n\tprivate Material _pointMaterial;\r\n\r\n\t// Cached clear colour so we can skip re-filling when the caller clears\r\n\t// to the same colour repeatedly (common pattern: clear every frame).\r\n\tprivate Color32 _lastClearColor;\r\n\tprivate bool _bufferIsUniformColor;\r\n\r\n\t// Reusable scratch buffer for ShiftPixels \u2014 avoids a per-call heap allocation.\r\n\tprivate Color32[] _shiftBuffer;\r\n\r\n\t// Cached letterbox rect \u2014 recomputed only when the screen dimensions change.\r\n\tprivate float _cachedScreenW;\r\n\tprivate float _cachedScreenH;\r\n\tprivate Rect _cachedLetterboxRect;\r\n\r\n\t// \u2500\u2500 Lifecycle \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tInstance = this;\r\n\t\tInitBuffer();\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\tif ( Instance == this )\r\n\t\t\tInstance = null;\r\n\r\n\t\t_texture?.Dispose();\r\n\t\t_texture = null;\r\n\t\t_pixels = null;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tHandleInput();\r\n\t\tApplyShake();\r\n\t\tUploadAndDraw();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// When true, enables the built-in click-to-paint demo that sets the pixel\r\n\t/// under the cursor to a random colour on left-click. Disable this when\r\n\t/// using your own input handling.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic bool EnableClickToPaint { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Built-in click-to-paint demo: left-click sets the pixel under the cursor\r\n\t/// to a random colour. Only active when \u003Csee cref=\u0022EnableClickToPaint\u0022/\u003E is true.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void HandleInput()\r\n\t{\r\n\t\tif ( !EnableClickToPaint )\r\n\t\t\treturn;\r\n\r\n\t\tif ( !Input.Down( \u0022attack1\u0022 ) )\r\n\t\t\treturn;\r\n\r\n\t\tPixelPoint px = GetMouseScreenPosition();\r\n\t\tColor32 randomColor = new Color32(\r\n\t\t\t(byte)Game.Random.Next( 0, 256 ),\r\n\t\t\t(byte)Game.Random.Next( 0, 256 ),\r\n\t\t\t(byte)Game.Random.Next( 0, 256 ),\r\n\t\t\t255\r\n\t\t);\r\n\r\n\t\t// Temporarily draw in GUI space so the screen-relative mouse\r\n\t\t// position maps directly to the pixel buffer.\r\n\t\tbool wasGui = DrawInGUISpace;\r\n\t\tDrawInGUISpace = true;\r\n\t\tSetPixel( px.X, px.Y, randomColor );\r\n\t\tDrawInGUISpace = wasGui;\r\n\t}\r\n\r\n\t// \u2500\u2500 Drawing API \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Set a single pixel to an opaque colour (no blending).\r\n\t/// \u003C/summary\u003E\r\n\tpublic void SetPixel( int x, int y, Color32 color )\r\n\t{\r\n\t\tTransformCoords( ref x, ref y );\r\n\r\n\t\tif ( !InBounds( x, y ) )\r\n\t\t\treturn;\r\n\r\n\t\t// Y is flipped because our coordinate system has Y=0 at the bottom,\r\n\t\t// but GPU textures (and the s\u0026box Texture.Update call) expect Y=0 at the top.\r\n\t\tint index = (PixelHeight - 1 - y) * PixelWidth \u002B x;\r\n\t\t_pixels[index] = color;\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Alpha-composite \u003Cparamref name=\u0022color\u0022/\u003E on top of the existing pixel (Porter-Duff over).\r\n\t/// \u003C/summary\u003E\r\n\tpublic void AddPixel( int x, int y, Color32 color )\r\n\t{\r\n\t\tTransformCoords( ref x, ref y );\r\n\r\n\t\tif ( !InBounds( x, y ) )\r\n\t\t\treturn;\r\n\r\n\t\tint index = (PixelHeight - 1 - y) * PixelWidth \u002B x;\r\n\t\t_pixels[index] = PixelUtils.AddColors( color, _pixels[index] );\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Subtractive blend: subtract \u003Cparamref name=\u0022color\u0022/\u003E RGB from the existing pixel.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void SubtractPixel( int x, int y, Color32 color )\r\n\t{\r\n\t\tTransformCoords( ref x, ref y );\r\n\r\n\t\tif ( !InBounds( x, y ) )\r\n\t\t\treturn;\r\n\r\n\t\tint index = (PixelHeight - 1 - y) * PixelWidth \u002B x;\r\n\t\t_pixels[index] = PixelUtils.SubtractColors( color, _pixels[index] );\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Fill the entire buffer with a solid colour.\r\n\t/// Optimised: skips the fill if the buffer is already this colour.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Clear( Color32 color )\r\n\t{\r\n\t\t// Most frames clear to the same colour (usually black). Skip the Array.Fill\r\n\t\t// entirely when the buffer is already uniform and the colour hasn\u0027t changed.\r\n\t\tif ( _bufferIsUniformColor \u0026\u0026 _lastClearColor.r == color.r\r\n\t\t\t\u0026\u0026 _lastClearColor.g == color.g \u0026\u0026 _lastClearColor.b == color.b\r\n\t\t\t\u0026\u0026 _lastClearColor.a == color.a )\r\n\t\t{\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tArray.Fill( _pixels, color );\r\n\t\t_lastClearColor = color;\r\n\t\t_bufferIsUniformColor = true;\r\n\t\t_dirty = true;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Additively tint every pixel in the buffer by \u003Cparamref name=\u0022color\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void AddColor( Color32 color )\r\n\t{\r\n\t\tfor ( int i = 0; i \u003C _pixels.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Color32 px = ref _pixels[i];\r\n\t\t\tpx.r = (byte)Math.Min( 255, px.r \u002B color.r );\r\n\t\t\tpx.g = (byte)Math.Min( 255, px.g \u002B color.g );\r\n\t\t\tpx.b = (byte)Math.Min( 255, px.b \u002B color.b );\r\n\t\t}\r\n\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Subtractively tint every pixel by \u003Cparamref name=\u0022color\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void SubtractColor( Color32 color )\r\n\t{\r\n\t\tfor ( int i = 0; i \u003C _pixels.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Color32 px = ref _pixels[i];\r\n\t\t\tpx.r = (byte)Math.Max( 0, px.r - color.r );\r\n\t\t\tpx.g = (byte)Math.Max( 0, px.g - color.g );\r\n\t\t\tpx.b = (byte)Math.Max( 0, px.b - color.b );\r\n\t\t}\r\n\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Alpha-composite \u003Cparamref name=\u0022color\u0022/\u003E onto every pixel.\r\n\t/// Useful for fade-in / fade-out effects.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void AddPixels( Color32 color )\r\n\t{\r\n\t\tif ( color.a == 0 )\r\n\t\t\treturn; // Nothing to blend.\r\n\r\n\t\tif ( color.a == 255 )\r\n\t\t{\r\n\t\t\t// Fully opaque overlay \u2014 equivalent to a clear.\r\n\t\t\tArray.Fill( _pixels, color );\r\n\t\t\t_lastClearColor = color;\r\n\t\t\t_bufferIsUniformColor = true;\r\n\t\t\t_dirty = true;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Precompute the source alpha factors once \u2014 they\u0027re constant across all pixels.\r\n\t\t// Calling PixelUtils.AddColors in the loop would recompute these 24,576 times.\r\n\t\tfloat srcA    = color.a / 255f;\r\n\t\tfloat srcInvA = 1f - srcA;\r\n\t\tfloat srcR    = color.r * srcA;\r\n\t\tfloat srcG    = color.g * srcA;\r\n\t\tfloat srcB    = color.b * srcA;\r\n\r\n\t\tfor ( int i = 0; i \u003C _pixels.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Color32 px = ref _pixels[i];\r\n\t\t\tfloat dstA = px.a / 255f;\r\n\t\t\tfloat outA = srcA \u002B dstA * srcInvA;\r\n\r\n\t\t\tif ( outA \u003C= 0f )\r\n\t\t\t{\r\n\t\t\t\tpx = new Color32( 0, 0, 0, 0 );\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tfloat invOutA = 1f / outA;\r\n\t\t\tpx.r = (byte)((srcR \u002B px.r * dstA * srcInvA) * invOutA);\r\n\t\t\tpx.g = (byte)((srcG \u002B px.g * dstA * srcInvA) * invOutA);\r\n\t\t\tpx.b = (byte)((srcB \u002B px.b * dstA * srcInvA) * invOutA);\r\n\t\t\tpx.a = (byte)(outA * 255f);\r\n\t\t}\r\n\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Draw a line using Bresenham\u0027s algorithm.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void DrawLine( int x0, int y0, int x1, int y1, Color32 color )\r\n\t{\r\n\t\t// Bresenham\u0027s line algorithm.\r\n\t\t// When the line is \u0022steep\u0022 (taller than wide) we transpose X\u2194Y so the\r\n\t\t// driving axis is always X, then transpose back when writing each pixel.\r\n\t\tbool steep = Math.Abs( y1 - y0 ) \u003E Math.Abs( x1 - x0 );\r\n\r\n\t\tif ( steep )\r\n\t\t{\r\n\t\t\tPixelUtils.Swap( ref x0, ref y0 );\r\n\t\t\tPixelUtils.Swap( ref x1, ref y1 );\r\n\t\t}\r\n\r\n\t\t// Ensure left-to-right iteration so the loop increments x.\r\n\t\tif ( x0 \u003E x1 )\r\n\t\t{\r\n\t\t\tPixelUtils.Swap( ref x0, ref x1 );\r\n\t\t\tPixelUtils.Swap( ref y0, ref y1 );\r\n\t\t}\r\n\r\n\t\tint dx = x1 - x0;\r\n\t\tint dy = Math.Abs( y1 - y0 );\r\n\t\tint error = dx / 2;\r\n\t\tint yStep = y0 \u003C y1 ? 1 : -1;\r\n\t\tint y = y0;\r\n\r\n\t\tfor ( int x = x0; x \u003C= x1; x\u002B\u002B )\r\n\t\t{\r\n\t\t\tif ( steep )\r\n\t\t\t\tSetPixel( y, x, color );\r\n\t\t\telse\r\n\t\t\t\tSetPixel( x, y, color );\r\n\r\n\t\t\terror -= dy;\r\n\t\t\tif ( error \u003C 0 )\r\n\t\t\t{\r\n\t\t\t\ty \u002B= yStep;\r\n\t\t\t\terror \u002B= dx;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Scroll the pixel buffer by \u003Cparamref name=\u0022offset\u0022/\u003E, wrapping pixels around the edges.\r\n\t/// Used internally for screen shake.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void ShiftPixels( PixelPoint offset )\r\n\t{\r\n\t\tif ( offset.X == 0 \u0026\u0026 offset.Y == 0 )\r\n\t\t\treturn;\r\n\r\n\t\t// Reuse a pre-allocated scratch buffer to avoid a per-call heap allocation.\r\n\t\tif ( _shiftBuffer is null || _shiftBuffer.Length != _pixels.Length )\r\n\t\t\t_shiftBuffer = new Color32[_pixels.Length];\r\n\r\n\t\tArray.Copy( _pixels, _shiftBuffer, _pixels.Length );\r\n\r\n\t\tfor ( int srcY = 0; srcY \u003C PixelHeight; srcY\u002B\u002B )\r\n\t\t{\r\n\t\t\tfor ( int srcX = 0; srcX \u003C PixelWidth; srcX\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\t// Single modulo \u002B conditional add \u2014 cheaper than the double-modulo\r\n\t\t\t\t// pattern and correct for any offset magnitude.\r\n\t\t\t\tint dstX = (srcX \u002B offset.X) % PixelWidth;\r\n\t\t\t\tif ( dstX \u003C 0 ) dstX \u002B= PixelWidth;\r\n\r\n\t\t\t\tint dstY = (srcY \u002B offset.Y) % PixelHeight;\r\n\t\t\t\tif ( dstY \u003C 0 ) dstY \u002B= PixelHeight;\r\n\r\n\t\t\t\t_pixels[dstY * PixelWidth \u002B dstX] = _shiftBuffer[srcY * PixelWidth \u002B srcX];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Read a single pixel from the buffer at the given world coordinates.\r\n\t/// Returns transparent black if the coordinates are out of bounds.\r\n\t/// Respects camera offset / GUI-space the same way write operations do.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Color32 GetPixel( int x, int y )\r\n\t{\r\n\t\tTransformCoords( ref x, ref y );\r\n\r\n\t\tif ( !InBounds( x, y ) )\r\n\t\t\treturn new Color32( 0, 0, 0, 0 );\r\n\r\n\t\tint index = (PixelHeight - 1 - y) * PixelWidth \u002B x;\r\n\t\treturn _pixels[index];\r\n\t}\r\n\r\n\t// \u2500\u2500 Input helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Convert the current mouse screen position to pixel-buffer coordinates.\r\n\t/// Returns a \u003Csee cref=\u0022PixelPoint\u0022/\u003E in the range [0, PixelWidth) x [0, PixelHeight).\r\n\t/// \u003C/summary\u003E\r\n\tpublic PixelPoint GetMouseScreenPosition()\r\n\t{\r\n\t\t// Account for the letterbox offset so pixel 0,0 maps to the\r\n\t\t// actual left/bottom edge of the rendered quad, not the screen edge.\r\n\t\tRect quad = CalculateLetterboxRect();\r\n\r\n\t\tfloat relX = (float)(Mouse.Position.x - quad.Left);\r\n\t\tfloat relY = (float)(Mouse.Position.y - quad.Top);\r\n\r\n\t\tint mx = (int)(relX / quad.Width * PixelWidth);\r\n\t\tint my = (int)(relY / quad.Height * PixelHeight);\r\n\r\n\t\t// Flip Y so 0 is at the bottom.\r\n\t\tmy = PixelHeight - 1 - my;\r\n\r\n\t\tmx = Math.Clamp( mx, 0, PixelWidth - 1 );\r\n\t\tmy = Math.Clamp( my, 0, PixelHeight - 1 );\r\n\r\n\t\treturn new PixelPoint( mx, my );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Convert mouse screen position to world pixel coordinates (adds camera offset).\r\n\t/// \u003C/summary\u003E\r\n\tpublic PixelPoint GetMouseWorldPosition()\r\n\t{\r\n\t\tPixelPoint screen = GetMouseScreenPosition();\r\n\t\treturn screen \u002B CameraPos;\r\n\t}\r\n\r\n\t// \u2500\u2500 Internals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Allocate the pixel buffer and create the GPU texture.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void InitBuffer()\r\n\t{\r\n\t\t_pixels = new Color32[PixelWidth * PixelHeight];\r\n\t\tArray.Fill( _pixels, new Color32( 0, 0, 0, 255 ) );\r\n\r\n\t\t_texture?.Dispose();\r\n\t\t_texture = Texture.Create( PixelWidth, PixelHeight )\r\n\t\t\t.WithDynamicUsage()\r\n\t\t\t.WithName( \u0022pixel_screen\u0022 )\r\n\t\t\t.Finish();\r\n\r\n\t\t_shiftBuffer = null; // Will be reallocated at the new size on next use.\r\n\t\t_cachedScreenW = 0f; // Invalidate letterbox cache.\r\n\r\n\t\t_dirty = true;\r\n\t\t_bufferIsUniformColor = true;\r\n\t\t_lastClearColor = new Color32( 0, 0, 0, 255 );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Apply camera offset to coordinates (unless drawing in GUI space).\r\n\t/// \u003C/summary\u003E\r\n\t// Converts world-space pixel coordinates to screen-space by subtracting\r\n\t// the camera offset. In GUI space the camera is ignored so HUD elements\r\n\t// are always drawn relative to the top-left of the pixel buffer.\r\n\tprivate void TransformCoords( ref int x, ref int y )\r\n\t{\r\n\t\tif ( DrawInGUISpace )\r\n\t\t\treturn;\r\n\r\n\t\tx -= CameraPos.X;\r\n\t\ty -= CameraPos.Y;\r\n\t}\r\n\r\n\tprivate bool InBounds( int x, int y )\r\n\t{\r\n\t\treturn x \u003E= 0 \u0026\u0026 x \u003C PixelWidth \u0026\u0026 y \u003E= 0 \u0026\u0026 y \u003C PixelHeight;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Decay and apply screen shake by shifting the pixel buffer randomly.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void ApplyShake()\r\n\t{\r\n\t\tif ( ShakeAmount \u003C= 0f )\r\n\t\t\treturn;\r\n\r\n\t\tint range = (int)MathF.Ceiling( ShakeAmount );\r\n\t\tint sx = Game.Random.Next( -range, range \u002B 1 );\r\n\t\tint sy = Game.Random.Next( -range, range \u002B 1 );\r\n\t\tShiftPixels( new PixelPoint( sx, sy ) );\r\n\r\n\t\tShakeAmount -= ShakeDecay * Time.Delta;\r\n\t\tif ( ShakeAmount \u003C 0f )\r\n\t\t\tShakeAmount = 0f;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Upload the pixel buffer to the GPU texture (if dirty) and draw it as a\r\n\t/// letterboxed quad with point-sampled filtering through the camera\u0027s HUD.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void UploadAndDraw()\r\n\t{\r\n\t\tif ( _texture is null || _pixels is null )\r\n\t\t\treturn;\r\n\r\n\t\t// Only re-upload when something wrote to the buffer this frame.\r\n\t\t// Skipping the GPU upload when nothing changed saves significant bandwidth\r\n\t\t// \u2014 Texture.Update copies the entire pixel array across the PCIe bus.\r\n\t\tif ( _dirty )\r\n\t\t{\r\n\t\t\t_texture.Update( _pixels.AsSpan() );\r\n\t\t\t_dirty = false;\r\n\t\t}\r\n\r\n\t\tCameraComponent camera = Scene?.Camera;\r\n\t\tif ( camera is null )\r\n\t\t\treturn;\r\n\r\n\t\t// Lazily create the point-filtered material from our custom shader.\r\n\t\t// This shader is identical to ui_basic but samples with g_sPointClamp\r\n\t\t// instead of g_sAniso, giving crisp nearest-neighbor pixel rendering.\r\n\t\t_pointMaterial ??= Material.FromShader( \u0022shaders/ui_basic_point.shader\u0022 );\r\n\r\n\t\tRect screenRect = CalculateLetterboxRect();\r\n\r\n\t\tCommandList list = camera.Hud.list;\r\n\t\tlist.Attributes.Set( \u0022Texture\u0022, _texture );\r\n\t\tlist.DrawQuad( screenRect, _pointMaterial, Color.White );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Computes a centered rectangle that fits the pixel buffer into the screen\r\n\t/// while maintaining a 1:1 pixel aspect ratio. Remaining areas are letterboxed.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Rect CalculateLetterboxRect()\r\n\t{\r\n\t\tfloat screenW = Screen.Width;\r\n\t\tfloat screenH = Screen.Height;\r\n\r\n\t\tif ( screenW == _cachedScreenW \u0026\u0026 screenH == _cachedScreenH )\r\n\t\t\treturn _cachedLetterboxRect;\r\n\r\n\t\tfloat bufferAspect = (float)PixelWidth / PixelHeight;\r\n\t\tfloat screenAspect = screenW / screenH;\r\n\r\n\t\tfloat drawW, drawH;\r\n\r\n\t\tif ( screenAspect \u003E bufferAspect )\r\n\t\t{\r\n\t\t\t// Screen is wider than buffer \u2014 pillarbox (bars on left/right).\r\n\t\t\tdrawH = screenH;\r\n\t\t\tdrawW = screenH * bufferAspect;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t// Screen is taller than buffer \u2014 letterbox (bars on top/bottom).\r\n\t\t\tdrawW = screenW;\r\n\t\t\tdrawH = screenW / bufferAspect;\r\n\t\t}\r\n\r\n\t\t// Snap to integer multiples of logical pixel size so each pixel\r\n\t\t// maps to the same number of screen pixels (no sub-pixel seams).\r\n\t\tint scale = Math.Max( 1, (int)Math.Min( drawW / PixelWidth, drawH / PixelHeight ) );\r\n\t\tdrawW = PixelWidth * scale;\r\n\t\tdrawH = PixelHeight * scale;\r\n\r\n\t\t// Floor offsets to integer screen pixels so the quad edge aligns\r\n\t\t// exactly on a screen pixel boundary \u2014 prevents sub-pixel misalignment\r\n\t\t// that causes uneven gaps at the edges of the pixel grid.\r\n\t\tint offsetX = (int)((screenW - drawW) * 0.5f);\r\n\t\tint offsetY = (int)((screenH - drawH) * 0.5f);\r\n\r\n\t\t_cachedScreenW = screenW;\r\n\t\t_cachedScreenH = screenH;\r\n\t\t_cachedLetterboxRect = new Rect( offsetX, offsetY, drawW, drawH );\r\n\t\treturn _cachedLetterboxRect;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/BloodParticle.cs","FileName":"BloodParticle.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Physics-based single red pixel that falls with gravity, bounces off X bounds,\r\n/// and converts into a \u003Csee cref=\u0022Trail\u0022/\u003E when it lands.\r\n/// Spawned constantly by the player as blood drips.\r\n/// \u003C/summary\u003E\r\npublic class BloodParticle : Entity\r\n{\r\n\tprivate Vector2 _velocity;\r\n\t// Tracks net downward displacement remaining before landing. Starts positive\r\n\t// (pixels to fall) and is decremented by downward movement each frame.\r\n\t// Upward movement (for spurts) temporarily increases it, so the particle\r\n\t// lands that many pixels below its spawn point regardless of arc height.\r\n\tprivate float _distanceToFall;\r\n\tprivate float _gravity;\r\n\tprivate float _opacity;\r\n\tprivate bool _playNoise;\r\n\r\n\tpublic BloodParticle( int x, int y, Vector2 velocity, float distanceToFall, float gravity,\r\n\t\tTransposerScene scene, bool playNoise = false )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022bloodparticle\u0022;\r\n\t\t_layer = Globals.DEPTH_BLOOD_PARTICLE;\r\n\t\t_velocity = velocity;\r\n\t\t_distanceToFall = distanceToFall;\r\n\t\t_gravity = gravity;\r\n\t\t_opacity = Game.Random.Float( 0.65f, 0.9f );\r\n\t\t_playNoise = playNoise;\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\r\n\t\tfloat yMove = _velocity.y * deltaTime;\r\n\t\tfloat newY = ExactY \u002B yMove;\r\n\r\n\t\tif ( IsInBounds( PixelY, (int)MathF.Round( newY ), 3 ) )\r\n\t\t{\r\n\t\t\tExactY = newY;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLand();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tfloat xMove = _velocity.x * deltaTime;\r\n\t\tfloat newX = ExactX \u002B xMove;\r\n\r\n\t\tif ( IsInBounds( (int)MathF.Round( newX ), PixelY, 3 ) )\r\n\t\t{\r\n\t\t\tExactX = newX;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif ( _velocity.x \u003E 0 ) PixelX--;\r\n\t\t\t_velocity = new Vector2( 0, _velocity.y );\r\n\t\t}\r\n\r\n\t\t_distanceToFall \u002B= yMove;\r\n\t\tif ( _distanceToFall \u003C= 0f )\r\n\t\t{\r\n\t\t\tif ( _playNoise )\r\n\t\t\t\tAudioManager.PlaySfx( Sfx.BloodSplat );\r\n\t\t\tLand();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Light air resistance \u2014 only applied while moving in the \u0022positive\u0022 direction\r\n\t\t// (upward for Y, rightward for X). Downward/leftward motion is not damped.\r\n\t\tif ( _velocity.y \u003E 0f )\r\n\t\t\t_velocity = new Vector2( _velocity.x, _velocity.y * 0.99f );\r\n\t\tif ( _velocity.x \u003E 0f )\r\n\t\t\t_velocity = new Vector2( _velocity.x * 0.96f, _velocity.y );\r\n\r\n\t\t_velocity = new Vector2( _velocity.x, _velocity.y \u002B _gravity );\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\tColor32 color = new( 255, 0, 0, (byte)(_opacity * 255f) );\r\n\t\tScreen.AddPixel( PixelX, PixelY, color );\r\n\t}\r\n\r\n\tprivate void Land()\r\n\t{\r\n\t\t_scene.AddEntity( new Trail( PixelX, PixelY, _opacity, _scene ) );\r\n\t\t_scene.RemoveEntity( this );\r\n\t\t((GameScene)_scene).RemoveBloodParticle( this );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/Enemy.cs","FileName":"Enemy.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Ghost-like enemy that spawns with an animation, then moves in a random\r\n/// cardinal direction, bouncing off screen edges.\r\n///\r\n/// Detects the player via pixel-colour collision: reads screen pixels at\r\n/// its \u0022up\u0022 frame positions and checks for the player\u0027s body colour\r\n/// (200, 200, 100, 255).\r\n/// \u003C/summary\u003E\r\npublic class Enemy : Entity\r\n{\r\n\tprivate const float MOVE_SPEED = 10f;\r\n\tprivate Vector2 _direction;\r\n\r\n\tprivate Queue\u003CPixelPoint\u003E _lastPositions = new();\r\n\tprivate const int NUM_LAST_POSITIONS = 2; // 2 trailing ghost positions drawn behind the enemy.\r\n\r\n\t// Cached pixel list for the \u0022up\u0022 frame \u2014 used every frame for ghost trail\r\n\t// and pixel-color collision. Computed once; the frame data never changes.\r\n\tprivate List\u003CPixelData\u003E _upFramePixels;\r\n\r\n\tprivate bool _touchedPlayer;\r\n\r\n\tpublic Enemy( int x, int y, TransposerScene scene )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022enemy\u0022;\r\n\t\tPlayAnimation( \u0022spawn\u0022 );\r\n\t\tSetAnimCompleteCallback( StartMoving );\r\n\t\t_layer = Globals.DEPTH_ENEMY;\r\n\r\n\t\t// Cache up-frame pixel list once \u2014 reused every frame in UpdateEntity and Draw.\r\n\t\t_upFramePixels = GetPixelDataList( \u0022enemy\u0022, \u0022up\u0022, 0, false, false );\r\n\t}\r\n\r\n\tprivate void StartMoving()\r\n\t{\r\n\t\tint rand = Game.Random.Next( 0, 4 );\r\n\t\t_direction = rand switch\r\n\t\t{\r\n\t\t\t0 =\u003E new Vector2( 1, 0 ),\r\n\t\t\t1 =\u003E new Vector2( -1, 0 ),\r\n\t\t\t2 =\u003E new Vector2( 0, 1 ),\r\n\t\t\t_ =\u003E new Vector2( 0, -1 )\r\n\t\t};\r\n\r\n\t\tUpdateAnim();\r\n\t\t_collideable = true;\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\r\n\t\tif ( _touchedPlayer )\r\n\t\t\treturn;\r\n\r\n\t\tMove( _direction, deltaTime );\r\n\r\n\t\t// \u2500\u2500 Pixel-colour collision: detect player body colour \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t\t// Note: uses screen-pixel reads rather than AABB because grid transposing\r\n\t\t// moves pixels visually without changing entity logical positions.\r\n\t\tif ( _collideable \u0026\u0026 !_touchedPlayer )\r\n\t\t{\r\n\t\t\tif ( _upFramePixels is null ) return;\r\n\r\n\t\t\tforeach ( PixelData pd in _upFramePixels )\r\n\t\t\t{\r\n\t\t\t\tPixelPoint pos = PixelPosition \u002B pd.Position;\r\n\t\t\t\tColor32 existing = Screen.GetPixel( pos.X, pos.Y );\r\n\r\n\t\t\t\t// Player body colour: (200, 200, 100, 255)\r\n\t\t\t\tif ( existing.r == 200 \u0026\u0026 existing.g == 200 \u0026\u0026 existing.b == 100 \u0026\u0026 existing.a == 255 )\r\n\t\t\t\t{\r\n\t\t\t\t\t((GameScene)_scene).PlayerTouchedEnemy( this );\r\n\t\t\t\t\t_touchedPlayer = true;\r\n\t\t\t\t\tPlayAnimation( \u0022killplayer\u0022 );\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void Move( Vector2 moveVector, float deltaTime )\r\n\t{\r\n\t\tVector2 newPos = ExactPos \u002B moveVector * MOVE_SPEED * deltaTime;\r\n\t\tPixelPoint newPx = new( (int)MathF.Round( newPos.x ), (int)MathF.Round( newPos.y ) );\r\n\r\n\t\tif ( IsInBounds( newPx.X, newPx.Y ) )\r\n\t\t{\r\n\t\t\tif ( newPx != PixelPosition )\r\n\t\t\t\tAddLastPosition( PixelPosition );\r\n\t\t\tExactPos = newPos;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t_direction = new Vector2( _direction.x * -1, _direction.y * -1 );\r\n\t\t\tUpdateAnim();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void UpdateAnim()\r\n\t{\r\n\t\tif ( _direction.x == -1 )\r\n\t\t{\r\n\t\t\tPlayAnimation( \u0022left\u0022 );\r\n\t\t\t_flipX = false;\r\n\t\t}\r\n\t\telse if ( _direction.x == 1 )\r\n\t\t{\r\n\t\t\t// No separate \u0022right\u0022 animation \u2014 reuse \u0022left\u0022 with horizontal flip.\r\n\t\t\tPlayAnimation( \u0022left\u0022 );\r\n\t\t\t_flipX = true;\r\n\t\t}\r\n\t\telse if ( _direction.y == 1 )\r\n\t\t{\r\n\t\t\tPlayAnimation( \u0022up\u0022 );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tPlayAnimation( \u0022down\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\t// Draw ghost trail at previous positions.\r\n\t\tif ( _upFramePixels is not null )\r\n\t\t{\r\n\t\t\tList\u003CPixelData\u003E trailPixels = _upFramePixels;\r\n\t\t\tfloat opacity = 0.5f;\r\n\t\t\tforeach ( PixelPoint pos in _lastPositions )\r\n\t\t\t{\r\n\t\t\t\tforeach ( PixelData pd in trailPixels )\r\n\t\t\t\t{\r\n\t\t\t\t\tPixelPoint pp = pos \u002B pd.Position;\r\n\t\t\t\t\tScreen.AddPixel( pp.X, pp.Y, new Color32( 0, 0, 0, (byte)(opacity * 255f) ) );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbase.Draw();\r\n\t}\r\n\r\n\tprivate void AddLastPosition( PixelPoint pos )\r\n\t{\r\n\t\tif ( _lastPositions.Count \u003E= NUM_LAST_POSITIONS )\r\n\t\t\t_lastPositions.Dequeue();\r\n\t\t_lastPositions.Enqueue( pos );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/Trail.cs","FileName":"Trail.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Blood trail left by \u003Csee cref=\u0022BloodParticle\u0022/\u003E when it lands.\r\n/// Fades out over ~4.75 seconds, with optional random spread.\r\n/// Drawn as 2px wide with chance of extra pixels to the sides/above.\r\n/// \u003C/summary\u003E\r\npublic class Trail : Entity\r\n{\r\n\tprivate float _lifetime;\r\n\tprivate const float LIFETIME_MAX = 4.75f;\r\n\r\n\tprivate bool _spreadLeft;\r\n\tprivate bool _spreadRight;\r\n\tprivate bool _spreadUp;\r\n\tprivate float _startingOpacity;\r\n\r\n\tpublic Trail( int x, int y, float startingOpacity, TransposerScene scene )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022trail\u0022;\r\n\t\t_layer = Globals.DEPTH_TRAIL;\r\n\t\t_lifetime = LIFETIME_MAX * Game.Random.Float( 0.9f, 1f );\r\n\t\t_spreadLeft = Game.Random.Next( 0, 3 ) == 0;\r\n\t\t_spreadRight = Game.Random.Next( 0, 3 ) == 0;\r\n\t\t_spreadUp = Game.Random.Next( 0, 6 ) == 0;\r\n\t\t_startingOpacity = startingOpacity;\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\r\n\t\t_lifetime -= deltaTime;\r\n\t\tif ( _lifetime \u003C= 0f )\r\n\t\t\t_scene.RemoveEntity( this );\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\tfloat opacity = PixelUtils.Map( _lifetime, LIFETIME_MAX, 0f, _startingOpacity, 0f, EaseType.SineOut );\r\n\t\tColor32 color = new( 255, 0, 0, (byte)(opacity * 255f) );\r\n\r\n\t\tScreen.AddPixel( PixelX, PixelY, color );\r\n\t\tScreen.AddPixel( PixelX \u002B 1, PixelY, color );\r\n\r\n\t\tif ( _spreadLeft ) Screen.AddPixel( PixelX - 1, PixelY, color );\r\n\t\tif ( _spreadRight ) Screen.AddPixel( PixelX \u002B 2, PixelY, color );\r\n\t\tif ( _spreadUp )\r\n\t\t{\r\n\t\t\tScreen.AddPixel( PixelX, PixelY \u002B 1, color );\r\n\t\t\tScreen.AddPixel( PixelX \u002B 1, PixelY \u002B 1, color );\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/TransposerGame.cs","FileName":"TransposerGame.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// s\u0026box Component entry point for the Transposer game.\r\n///\r\n/// Attach this to a GameObject alongside a \u003Csee cref=\u0022PixelScreen\u0022/\u003E component\r\n/// (configured to 192\u00D7128 resolution). This component initialises the sprite\r\n/// data, creates the scene manager, and drives the game loop each frame.\r\n/// \u003C/summary\u003E\r\n[Title( \u0022Transposer Game\u0022 )]\r\n[Category( \u0022Games\u0022 )]\r\n[Icon( \u0022sports_esports\u0022 )]\r\npublic sealed class TransposerGame : Component\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Reference to the PixelScreen component. Set via the editor inspector.\r\n\t/// Should be configured to 192\u00D7128 for the original Transposer resolution.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic PixelScreen PixelScreen { get; set; }\r\n\r\n\tprivate TransposerSceneManager _sceneManager;\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\t// Force the correct Transposer resolution (original game was 192\u00D7128).\r\n\t\t// Must call ResizeBuffer() to reallocate the pixel array and GPU texture\r\n\t\t// since PixelScreen.OnEnabled already ran with the default size.\r\n\t\tif ( PixelScreen is not null )\r\n\t\t{\r\n\t\t\tPixelScreen.PixelWidth = 192;\r\n\t\t\tPixelScreen.PixelHeight = 128;\r\n\t\t\tPixelScreen.ResizeBuffer();\r\n\t\t}\r\n\r\n\t\t// Load persisted high score from disk.\r\n\t\tGlobals.LoadFromDisk();\r\n\r\n\t\t// Ensure sprite data is loaded (including the transposer/ sprites).\r\n\t\tSpriteManager.Reload();\r\n\r\n\t\t_sceneManager = new TransposerSceneManager();\r\n\t\t_sceneManager.Begin();\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t// Poll input before any game logic.\r\n\t\tInputManager.Update();\r\n\r\n\t\t// Drive music fades and pitch updates.\r\n\t\tAudioManager.Tick( Time.Delta );\r\n\r\n\t\t// Tick the active scene.\r\n\t\t_sceneManager?.Update( Time.Delta );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"PixelUtils.cs","FileName":"PixelUtils.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// Easing types used by \u003Csee cref=\u0022PixelUtils.Map\u0022/\u003E.\r\n/// \u003C/summary\u003E\r\npublic enum EaseType\r\n{\r\n\tLinear,\r\n\tExpoIn,\r\n\tExpoOut,\r\n\tExpoInOut,\r\n\tCubicIn,\r\n\tCubicOut,\r\n\tCubicInOut,\r\n\tSineIn,\r\n\tSineOut,\r\n\tSineInOut\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Utility methods ported from the Unity pixelshitter framework.\r\n/// Contains alpha compositing, value remapping with easing, and coordinate helpers.\r\n/// \u003C/summary\u003E\r\npublic static class PixelUtils\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Porter-Duff \u0022source over\u0022 alpha composite.\r\n\t/// Blends \u003Cparamref name=\u0022src\u0022/\u003E on top of \u003Cparamref name=\u0022dst\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static Color32 AddColors( Color32 src, Color32 dst )\r\n\t{\r\n\t\tif ( src.a == 0 ) return dst;   // Fully transparent source \u2014 nothing to blend.\r\n\t\tif ( src.a == 255 ) return src; // Fully opaque source \u2014 covers destination entirely.\r\n\r\n\t\tfloat srcA = src.a / 255f;\r\n\t\tfloat dstA = dst.a / 255f;\r\n\r\n\t\t// Porter-Duff \u0022source over\u0022 composite:\r\n\t\t//   outA  = srcA \u002B dstA * (1 - srcA)\r\n\t\t//   outRGB = (src.rgb * srcA \u002B dst.rgb * dstA * (1 - srcA)) / outA\r\n\t\t// The (1 - srcA) term is how much of the destination shows through.\r\n\t\tfloat outA = srcA \u002B dstA * (1f - srcA);\r\n\r\n\t\tif ( outA \u003C= 0f )\r\n\t\t\treturn new Color32( 0, 0, 0, 0 );\r\n\r\n\t\tbyte r = (byte)((src.r * srcA \u002B dst.r * dstA * (1f - srcA)) / outA);\r\n\t\tbyte g = (byte)((src.g * srcA \u002B dst.g * dstA * (1f - srcA)) / outA);\r\n\t\tbyte b = (byte)((src.b * srcA \u002B dst.b * dstA * (1f - srcA)) / outA);\r\n\t\tbyte a = (byte)(outA * 255f);\r\n\r\n\t\treturn new Color32( r, g, b, a );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Subtractive blend: subtracts \u003Cparamref name=\u0022src\u0022/\u003E RGB from \u003Cparamref name=\u0022dst\u0022/\u003E.\r\n\t/// Alpha of \u003Cparamref name=\u0022src\u0022/\u003E controls blend strength.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static Color32 SubtractColors( Color32 src, Color32 dst )\r\n\t{\r\n\t\tfloat t = src.a / 255f;\r\n\t\tbyte r = (byte)Math.Max( 0, dst.r - (int)(src.r * t) );\r\n\t\tbyte g = (byte)Math.Max( 0, dst.g - (int)(src.g * t) );\r\n\t\tbyte b = (byte)Math.Max( 0, dst.b - (int)(src.b * t) );\r\n\t\treturn new Color32( r, g, b, dst.a );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Remap a value from one range to another with optional easing.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static float Map( float value, float fromMin, float fromMax, float toMin, float toMax, EaseType ease = EaseType.Linear )\r\n\t{\r\n\t\t// Normalize 0..1\r\n\t\tfloat t = (fromMax - fromMin) == 0f ? 0f : (value - fromMin) / (fromMax - fromMin);\r\n\t\tt = Math.Clamp( t, 0f, 1f );\r\n\r\n\t\tt = ease switch\r\n\t\t{\r\n\t\t\tEaseType.ExpoIn    =\u003E ExpoIn( t ),\r\n\t\t\tEaseType.ExpoOut   =\u003E ExpoOut( t ),\r\n\t\t\tEaseType.ExpoInOut =\u003E ExpoInOut( t ),\r\n\t\t\tEaseType.CubicIn   =\u003E t * t * t,                                           // t\u00B3 \u2014 slow start\r\n\t\t\tEaseType.CubicOut  =\u003E 1f - CubicOutHelper( t ),                            // 1-(1-t)\u00B3 \u2014 slow end\r\n\t\t\tEaseType.CubicInOut =\u003E t \u003C 0.5f ? 4f * t * t * t : 1f - CubicOutHelper( t ) * 0.5f, // S-curve, joins at t=0.5\r\n\t\t\tEaseType.SineIn    =\u003E 1f - MathF.Cos( t * MathF.PI / 2f ),\r\n\t\t\tEaseType.SineOut   =\u003E MathF.Sin( t * MathF.PI / 2f ),\r\n\t\t\tEaseType.SineInOut =\u003E -(MathF.Cos( MathF.PI * t ) - 1f) / 2f,\r\n\t\t\t_ =\u003E t\r\n\t\t};\r\n\r\n\t\treturn toMin \u002B (toMax - toMin) * t;\r\n\t}\r\n\r\n\tprivate static float ExpoIn( float t ) =\u003E t == 0f ? 0f : MathF.Pow( 2f, 10f * t - 10f );\r\n\tprivate static float ExpoOut( float t ) =\u003E t \u003E= 1f ? 1f : 1f - MathF.Pow( 2f, -10f * t );\r\n\tprivate static float ExpoInOut( float t )\r\n\t{\r\n\t\tif ( t == 0f ) return 0f;\r\n\t\tif ( t \u003E= 1f ) return 1f;\r\n\t\treturn t \u003C 0.5f\r\n\t\t\t? MathF.Pow( 2f, 20f * t - 10f ) / 2f\r\n\t\t\t: (2f - MathF.Pow( 2f, -20f * t \u002B 10f )) / 2f;\r\n\t}\r\n\r\n\t// Helper to avoid repeating the cubic-out pattern: (1 - t)^3\r\n\tprivate static float CubicOutHelper( float t )\r\n\t{\r\n\t\tfloat inv = 1f - t;\r\n\t\treturn inv * inv * inv;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Swap two values in place.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static void Swap\u003CT\u003E( ref T a, ref T b )\r\n\t{\r\n\t\t(a, b) = (b, a);\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Fisher-Yates shuffle on any list.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static void Shuffle\u003CT\u003E( IList\u003CT\u003E list )\r\n\t{\r\n\t\tfor ( int i = list.Count - 1; i \u003E 0; i-- )\r\n\t\t{\r\n\t\t\tint j = Game.Random.Next( i \u002B 1 );\r\n\t\t\t(list[i], list[j]) = (list[j], list[i]);\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entity.cs","FileName":"Entity.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Callback invoked when a PlayOnce animation reaches its last frame.\r\n/// \u003C/summary\u003E\r\npublic delegate void AnimationCompleteDelegate();\r\n\r\n/// \u003Csummary\u003E\r\n/// Callback for scheduled (delayed) actions.\r\n/// \u003C/summary\u003E\r\npublic delegate void ScheduledDelegate();\r\n\r\n/// \u003Csummary\u003E\r\n/// Callback invoked when a specific animation frame is entered.\r\n/// \u003C/summary\u003E\r\npublic delegate void SetFrameDelegate();\r\n\r\n/// \u003Csummary\u003E\r\n/// A delayed callback that fires after \u003Csee cref=\u0022Delay\u0022/\u003E seconds.\r\n/// \u003C/summary\u003E\r\npublic struct ScheduledDelegateData\r\n{\r\n\tpublic ScheduledDelegate Callback;\r\n\tpublic float Delay;\r\n\r\n\tpublic ScheduledDelegateData( ScheduledDelegate callback, float delay )\r\n\t{\r\n\t\tCallback = callback;\r\n\t\tDelay = delay;\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Base class for all Transposer game entities.\r\n///\r\n/// Direct port of the original Unity Entity class as a plain C# object\r\n/// (not an engine Component). Entities are managed by a \u003Csee cref=\u0022TransposerScene\u0022/\u003E\r\n/// which handles update ordering, draw sorting, and deferred add/remove.\r\n///\r\n/// Uses \u003Csee cref=\u0022SpriteManager\u0022/\u003E and the framework\u0027s \u003Csee cref=\u0022PixelSpriteComponent\u0022/\u003E\r\n/// internally for animation playback and rendering, while keeping the original\r\n/// Entity API surface intact.\r\n/// \u003C/summary\u003E\r\npublic class Entity\r\n{\r\n\t// \u2500\u2500 Position \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t// Sub-pixel float position \u2014 rounded to integer for drawing.\r\n\tprotected Vector2 _position;\r\n\r\n\tpublic Vector2 ExactPos\r\n\t{\r\n\t\tget =\u003E _position;\r\n\t\tset =\u003E _position = value;\r\n\t}\r\n\r\n\tpublic float ExactX\r\n\t{\r\n\t\tget =\u003E _position.x;\r\n\t\tset =\u003E _position = new Vector2( value, _position.y );\r\n\t}\r\n\r\n\tpublic float ExactY\r\n\t{\r\n\t\tget =\u003E _position.y;\r\n\t\tset =\u003E _position = new Vector2( _position.x, value );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Integer pixel position, using rounding (same as original).\r\n\t/// \u003C/summary\u003E\r\n\tpublic PixelPoint PixelPosition\r\n\t{\r\n\t\tget =\u003E new( (int)MathF.Round( _position.x ), (int)MathF.Round( _position.y ) );\r\n\t\tset =\u003E _position = new Vector2( value.X, value.Y );\r\n\t}\r\n\r\n\tpublic int PixelX\r\n\t{\r\n\t\tget =\u003E (int)MathF.Round( _position.x );\r\n\t\tset =\u003E _position = new Vector2( value, _position.y );\r\n\t}\r\n\r\n\tpublic int PixelY\r\n\t{\r\n\t\tget =\u003E (int)MathF.Round( _position.y );\r\n\t\tset =\u003E _position = new Vector2( _position.x, value );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Center of the entity in pixel coordinates (offset by half anim size).\r\n\t/// \u003C/summary\u003E\r\n\tpublic PixelPoint CenterPixelPos\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( _currentAnimation is not null )\r\n\t\t\t\treturn new PixelPoint(\r\n\t\t\t\t\tPixelX \u002B (int)MathF.Round( (_currentAnimation.AnimSize.X - 1) / 2f ),\r\n\t\t\t\t\tPixelY \u002B (int)MathF.Round( (_currentAnimation.AnimSize.Y - 1) / 2f ) );\r\n\t\t\treturn PixelPosition;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic Vector2 CenterExactPos\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( _currentAnimation is not null )\r\n\t\t\t\treturn new Vector2(\r\n\t\t\t\t\tExactX \u002B _currentAnimation.AnimSize.X * 0.5f,\r\n\t\t\t\t\tExactY \u002B _currentAnimation.AnimSize.Y * 0.5f );\r\n\t\t\treturn ExactPos;\r\n\t\t}\r\n\t}\r\n\r\n\t// \u2500\u2500 Sprite type \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected string _type;\r\n\tpublic string Type =\u003E _type;\r\n\r\n\t// \u2500\u2500 Depth/layer for draw sorting \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected int _depth;\r\n\tpublic int Depth { get =\u003E _depth; set =\u003E _depth = value; }\r\n\r\n\tprotected int _layer;\r\n\tpublic int Layer { get =\u003E _layer; set =\u003E _layer = value; }\r\n\r\n\t// \u2500\u2500 Hitbox / collision \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected PixelRect _hitbox;\r\n\tpublic PixelRect Hitbox =\u003E _hitbox;\r\n\r\n\t/// \u003Csummary\u003EHitbox offset by current pixel position.\u003C/summary\u003E\r\n\tpublic PixelRect OffsetHitbox =\u003E _hitbox \u002B PixelPosition;\r\n\r\n\tpublic PixelRect GetOffsetHitbox( PixelPoint position ) =\u003E _hitbox \u002B position;\r\n\tpublic PixelRect GetOffsetHitbox( int x, int y ) =\u003E _hitbox \u002B new PixelPoint( x, y );\r\n\r\n\tprotected bool _collideable;\r\n\tpublic bool Collideable =\u003E _collideable;\r\n\r\n\t// \u2500\u2500 Scene reference \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected TransposerScene _scene;\r\n\tpublic TransposerScene ContainingScene { get =\u003E _scene; set =\u003E _scene = value; }\r\n\r\n\t// \u2500\u2500 Animation state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected AnimationData _currentAnimation;\r\n\tprotected int _currentFrameNumber;\r\n\tprotected float _currentFrameTime;\r\n\tprotected FrameData _currentFrameData;\r\n\tprotected bool _pingPongForward;\r\n\tprotected float _animationTimeScale = 1.0f;\r\n\tpublic float AnimTimeScale { get =\u003E _animationTimeScale; set =\u003E _animationTimeScale = value; }\r\n\r\n\tprivate bool _overrideLoopMode;\r\n\tprivate LoopMode _overriddenLoopMode;\r\n\r\n\tprivate AnimationCompleteDelegate _animCompleteCallback;\r\n\tpublic void SetAnimCompleteCallback( AnimationCompleteDelegate callback ) =\u003E _animCompleteCallback = callback;\r\n\r\n\tprivate bool _playOnceAnimFinished;\r\n\r\n\tprivate Dictionary\u003Cint, SetFrameDelegate\u003E _setFrameDelegates = new();\r\n\tpublic void AddSetFrameCallback( int frameNumber, SetFrameDelegate callback ) =\u003E\r\n\t\t_setFrameDelegates[frameNumber] = callback;\r\n\tpublic void ClearSetFrameCallbacks() =\u003E _setFrameDelegates.Clear();\r\n\r\n\t// \u2500\u2500 Flip \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected bool _flipX;\r\n\tpublic bool FlipX { get =\u003E _flipX; set =\u003E _flipX = value; }\r\n\tprotected bool _flipY;\r\n\tpublic bool FlipY { get =\u003E _flipY; set =\u003E _flipY = value; }\r\n\r\n\t// \u2500\u2500 Color override \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprivate bool _overrideColor;\r\n\tprivate bool _overrideAlpha;\r\n\tprivate Color _overriddenColor;\r\n\r\n\tpublic void SetOverriddenColor( Color color )\r\n\t{\r\n\t\t_overrideColor = true;\r\n\t\t_overriddenColor = color;\r\n\t}\r\n\tpublic void RemoveOverriddenColor() =\u003E _overrideColor = false;\r\n\tpublic void SetOverrideAlpha( bool overrideAlpha ) =\u003E _overrideAlpha = overrideAlpha;\r\n\r\n\t// \u2500\u2500 Scheduled callbacks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprivate List\u003CScheduledDelegateData\u003E _scheduledCallbacks = new();\r\n\tpublic void AddScheduledCallback( float delay, ScheduledDelegate callback ) =\u003E\r\n\t\t_scheduledCallbacks.Add( new ScheduledDelegateData( callback, delay ) );\r\n\r\n\t// \u2500\u2500 Screen reference \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\tprotected PixelScreen Screen =\u003E PixelScreen.Instance;\r\n\r\n\t// \u2500\u2500 Update \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tpublic virtual void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tif ( _currentAnimation is not null )\r\n\t\t\tHandleAnimation( deltaTime );\r\n\r\n\t\tif ( _scheduledCallbacks.Count \u003E 0 )\r\n\t\t\tHandleScheduledCallbacks( deltaTime );\r\n\t}\r\n\r\n\tprivate void HandleScheduledCallbacks( float deltaTime )\r\n\t{\r\n\t\t// Iterate backwards so RemoveAt(i) doesn\u0027t shift unvisited entries.\r\n\t\t// Expired callbacks are fired immediately; remaining ones are re-added\r\n\t\t// at the end of the list with the updated time. The re-add is safe here\r\n\t\t// because we\u0027re iterating from the back toward the front.\r\n\t\tfor ( int i = _scheduledCallbacks.Count - 1; i \u003E= 0; i-- )\r\n\t\t{\r\n\t\t\tScheduledDelegateData data = _scheduledCallbacks[i];\r\n\t\t\tfloat newTime = data.Delay - deltaTime;\r\n\t\t\t_scheduledCallbacks.RemoveAt( i );\r\n\r\n\t\t\tif ( newTime \u003C= 0f )\r\n\t\t\t\tdata.Callback();\r\n\t\t\telse\r\n\t\t\t\t_scheduledCallbacks.Add( new ScheduledDelegateData( data.Callback, newTime ) );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void HandleAnimation( float deltaTime )\r\n\t{\r\n\t\tLoopMode loopMode = _overrideLoopMode ? _overriddenLoopMode : _currentAnimation.LoopMode;\r\n\t\tint numFrames = _currentAnimation.Frames.Count;\r\n\r\n\t\t_currentFrameTime \u002B= deltaTime * _animationTimeScale;\r\n\r\n\t\tvar animTime = _currentAnimation.Frames[_currentFrameNumber].AnimTime;\r\n\t\tif ( _currentFrameTime \u003C= animTime )\r\n\t\t\treturn;\r\n\r\n\t\tswitch ( loopMode )\r\n\t\t{\r\n\t\t\tcase LoopMode.Loops when numFrames \u003E 1:\r\n\t\t\t\tSetAnimationFrame( _currentFrameNumber == numFrames - 1 ? 0 : _currentFrameNumber \u002B 1 );\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase LoopMode.PlayOnce when !_playOnceAnimFinished:\r\n\t\t\t\t// Guard prevents re-firing the callback if PlayAnimation is called again\r\n\t\t\t\t// on the same animation while still on the last frame.\r\n\t\t\t\tif ( _currentFrameNumber \u003C numFrames - 1 )\r\n\t\t\t\t{\r\n\t\t\t\t\tSetAnimationFrame( _currentFrameNumber \u002B 1 );\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_playOnceAnimFinished = true;\r\n\t\t\t\t\tAnimationCompleteDelegate cb = _animCompleteCallback;\r\n\t\t\t\t\t_animCompleteCallback = null;\r\n\t\t\t\t\tcb?.Invoke();\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase LoopMode.PingPong when numFrames \u003E 1:\r\n\t\t\t\tif ( _pingPongForward )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( _currentFrameNumber \u003C numFrames - 1 )\r\n\t\t\t\t\t\tSetAnimationFrame( _currentFrameNumber \u002B 1 );\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tSetAnimationFrame( _currentFrameNumber - 1 );\r\n\t\t\t\t\t\t_pingPongForward = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( _currentFrameNumber \u003E 0 )\r\n\t\t\t\t\t\tSetAnimationFrame( _currentFrameNumber - 1 );\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tSetAnimationFrame( _currentFrameNumber \u002B 1 );\r\n\t\t\t\t\t\t_pingPongForward = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase LoopMode.RandomFrame when numFrames \u003E 1:\r\n\t\t\t\tint newFrame = Game.Random.Next( 0, numFrames );\r\n\t\t\t\twhile ( newFrame == _currentFrameNumber )\r\n\t\t\t\t\tnewFrame = Game.Random.Next( 0, numFrames );\r\n\t\t\t\tSetAnimationFrame( newFrame );\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\t//_currentFrameTime = 0f;\r\n\t\t_currentFrameTime -= animTime;\r\n\t}\r\n\r\n\tprivate void SetAnimationFrame( int frameNumber )\r\n\t{\r\n\t\tif ( _setFrameDelegates.TryGetValue( frameNumber, out SetFrameDelegate cb ) )\r\n\t\t\tcb?.Invoke();\r\n\r\n\t\t_currentFrameNumber = frameNumber;\r\n\t\t_currentFrameData = _currentAnimation.Frames[_currentFrameNumber];\r\n\t}\r\n\r\n\t// \u2500\u2500 Animation playback \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tpublic virtual void PlayAnimation( string animName )\r\n\t{\r\n\t\tList\u003CAnimationData\u003E anims = SpriteManager.GetAnimations( _type );\r\n\t\tif ( anims is null )\r\n\t\t{\r\n\t\t\tLog.Error( $\u0022Entity: no entity type called \u0027{_type}\u0027\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tforeach ( AnimationData anim in anims )\r\n\t\t{\r\n\t\t\tif ( anim.Name != animName )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\t_currentAnimation = anim;\r\n\t\t\t_hitbox = anim.Hitbox;\r\n\t\t\tSetAnimationFrame( 0 );\r\n\t\t\t_currentFrameTime = 0f;\r\n\t\t\t_overrideLoopMode = false;\r\n\t\t\t_playOnceAnimFinished = false;\r\n\t\t\t_pingPongForward = true; // Always start ping-pong animations going forward.\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tLog.Error( $\u0022Entity: no animation \u0027{animName}\u0027 for \u0027{_type}\u0027\u0022 );\r\n\t}\r\n\r\n\tpublic virtual void PlayAnimation( string animName, LoopMode overriddenLoopMode )\r\n\t{\r\n\t\tPlayAnimation( animName );\r\n\t\t_overrideLoopMode = true;\r\n\t\t_overriddenLoopMode = overriddenLoopMode;\r\n\t}\r\n\r\n\t// \u2500\u2500 Drawing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tpublic virtual void Draw()\r\n\t{\r\n\t\tif ( _currentAnimation is null )\r\n\t\t\treturn;\r\n\r\n\t\tif ( !IsInScreenBounds() \u0026\u0026 !Screen.DrawInGUISpace )\r\n\t\t\treturn;\r\n\r\n\t\tList\u003CPixelData\u003E pixels = GetCurrentPixels();\r\n\r\n\t\tforeach ( PixelData pixel in pixels )\r\n\t\t{\r\n\t\t\tColor32 color = ApplyColorOverride( pixel.Color );\r\n\r\n\t\t\t// Fully opaque \u2192 SetPixel (no blend math). Semi-transparent \u2192 AddPixel\r\n\t\t\t// (Porter-Duff over). Fully transparent (a == 0) \u2192 skip entirely.\r\n\t\t\tif ( color.a == 255 )\r\n\t\t\t\tScreen.SetPixel( PixelX \u002B pixel.Position.X, PixelY \u002B pixel.Position.Y, color );\r\n\t\t\telse if ( color.a \u003E 0 )\r\n\t\t\t\tScreen.AddPixel( PixelX \u002B pixel.Position.X, PixelY \u002B pixel.Position.Y, color );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Draw arbitrary pixel data at a position with optional scale and random colour.\r\n\t/// Used for text rendering and particle effects.\r\n\t/// \u003C/summary\u003E\r\n\tpublic virtual void DrawPixels( List\u003CPixelData\u003E pixelDataList, int x, int y, int scale = 1, bool randomColor = false )\r\n\t{\r\n\t\tforeach ( PixelData pixel in pixelDataList )\r\n\t\t{\r\n\t\t\tColor32 color;\r\n\t\t\tif ( randomColor )\r\n\t\t\t{\r\n\t\t\t\tcolor = new Color32(\r\n\t\t\t\t\t(byte)Game.Random.Next( 0, 100 ),\r\n\t\t\t\t\t(byte)Game.Random.Next( 0, 100 ),\r\n\t\t\t\t\t(byte)Game.Random.Next( 0, 100 ),\r\n\t\t\t\t\t(byte)Game.Random.Next( 0, 256 ) );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tcolor = ApplyColorOverride( pixel.Color );\r\n\t\t\t}\r\n\r\n\t\t\tfor ( int xOff = 0; xOff \u003C scale; xOff\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tfor ( int yOff = 0; yOff \u003C scale; yOff\u002B\u002B )\r\n\t\t\t\t{\r\n\t\t\t\t\tint px = x \u002B pixel.Position.X * scale \u002B xOff;\r\n\t\t\t\t\tint py = y \u002B pixel.Position.Y * scale \u002B yOff;\r\n\r\n\t\t\t\t\tif ( color.a == 255 )\r\n\t\t\t\t\t\tScreen.SetPixel( px, py, color );\r\n\t\t\t\t\telse if ( color.a \u003E 0 )\r\n\t\t\t\t\t\tScreen.AddPixel( px, py, color );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// \u2500\u2500 Pixel data access \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Get the current frame\u0027s pixel data, respecting flip state.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CPixelData\u003E GetPixelDataList()\r\n\t{\r\n\t\tif ( _currentAnimation is null )\r\n\t\t\treturn null;\r\n\r\n\t\treturn GetFlippedPixels( _currentAnimation.Frames[_currentFrameNumber], _currentAnimation.AnimSize );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Get pixel data for a specific type/anim/frame, optionally flipped.\r\n\t/// Used by the pixel-colour collision system to check against a known frame.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CPixelData\u003E GetPixelDataList( string type, string animName, int frameNum = 0, bool flippedX = false, bool flippedY = false )\r\n\t{\r\n\t\tAnimationData anim = SpriteManager.GetAnimation( type, animName );\r\n\t\tif ( anim is null || frameNum \u003E= anim.Frames.Count )\r\n\t\t\treturn null;\r\n\r\n\t\tFrameData frame = anim.Frames[frameNum];\r\n\t\tint w = anim.AnimSize.X;\r\n\t\tint h = anim.AnimSize.Y;\r\n\r\n\t\tif ( flippedX \u0026\u0026 flippedY ) return frame.GetPixelsFlippedXY( w, h );\r\n\t\tif ( flippedX ) return frame.GetPixelsFlippedX( w );\r\n\t\tif ( flippedY ) return frame.GetPixelsFlippedY( h );\r\n\r\n\t\treturn new List\u003CPixelData\u003E( frame.Pixels );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EGet animation size for a specific type/anim.\u003C/summary\u003E\r\n\tpublic PixelPoint GetAnimSize( string type, string animName )\r\n\t{\r\n\t\tAnimationData anim = SpriteManager.GetAnimation( type, animName );\r\n\t\treturn anim?.AnimSize ?? PixelPoint.Zero;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EGet animation hitbox for a specific type/anim.\u003C/summary\u003E\r\n\tpublic PixelRect GetAnimHitbox( string type, string animName )\r\n\t{\r\n\t\tAnimationData anim = SpriteManager.GetAnimation( type, animName );\r\n\t\treturn anim?.Hitbox ?? new PixelRect( 0, 0, 0, 0 );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EGet the AnimationData for a specific type/anim.\u003C/summary\u003E\r\n\tpublic AnimationData GetAnimationData( string type, string animName )\r\n\t{\r\n\t\treturn SpriteManager.GetAnimation( type, animName );\r\n\t}\r\n\r\n\t// \u2500\u2500 Collision (delegates to scene) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprotected Entity Collide( string type, int xPixel, int yPixel )\r\n\t{\r\n\t\treturn _scene?.Collide( this, type, xPixel, yPixel );\r\n\t}\r\n\r\n\tprotected Entity Collide( string type )\r\n\t{\r\n\t\treturn _scene?.Collide( this, type, PixelX, PixelY );\r\n\t}\r\n\r\n\tprotected List\u003CEntity\u003E CollideWithAll( string type, int xPixel, int yPixel )\r\n\t{\r\n\t\treturn _scene?.CollideWithAll( this, type, xPixel, yPixel );\r\n\t}\r\n\r\n\tprotected List\u003CEntity\u003E CollideWithAll( string type )\r\n\t{\r\n\t\treturn _scene?.CollideWithAll( this, type, PixelX, PixelY );\r\n\t}\r\n\r\n\tprotected bool IsInBounds( int xPixel, int yPixel, int padding = 0 )\r\n\t{\r\n\t\treturn _scene?.IsInBounds( this, xPixel, yPixel, padding ) ?? false;\r\n\t}\r\n\r\n\tprotected void Unpenetrate( Entity other )\r\n\t{\r\n\t\tif ( !OffsetHitbox.Overlaps( other.OffsetHitbox ) )\r\n\t\t\treturn;\r\n\r\n\t\tPixelRect myHitbox = OffsetHitbox;\r\n\t\tPixelRect otherHitbox = other.OffsetHitbox;\r\n\r\n\t\tint leftPen = myHitbox.XMax - otherHitbox.XMin \u002B 1;\r\n\t\tint rightPen = otherHitbox.XMax - myHitbox.XMin \u002B 1;\r\n\t\tint upPen = otherHitbox.YMax - myHitbox.YMin \u002B 1;\r\n\t\tint downPen = myHitbox.YMax - otherHitbox.YMin \u002B 1;\r\n\r\n\t\tDirection dir = Direction.Up;\r\n\t\tint amount = upPen;\r\n\t\tif ( downPen \u003C amount ) { dir = Direction.Down; amount = downPen; }\r\n\t\tif ( leftPen \u003C amount ) { dir = Direction.Left; amount = leftPen; }\r\n\t\tif ( rightPen \u003C amount ) { dir = Direction.Right; amount = rightPen; }\r\n\r\n\t\tswitch ( dir )\r\n\t\t{\r\n\t\t\tcase Direction.Up: PixelY \u002B= amount; break;\r\n\t\t\tcase Direction.Down: PixelY -= amount; break;\r\n\t\t\tcase Direction.Left: PixelX -= amount; break;\r\n\t\t\tcase Direction.Right: PixelX \u002B= amount; break;\r\n\t\t}\r\n\t}\r\n\r\n\t// \u2500\u2500 Bounds check \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tpublic bool IsInScreenBounds()\r\n\t{\r\n\t\tif ( _currentAnimation is null )\r\n\t\t\treturn false;\r\n\r\n\t\t// Conservative AABB cull: allows one full sprite width/height of slack\r\n\t\t// so sprites whose origin is just off-screen but whose pixels are still\r\n\t\t// visible don\u0027t get incorrectly culled.\r\n\t\tint w = _currentAnimation.AnimSize.X;\r\n\t\tint h = _currentAnimation.AnimSize.Y;\r\n\r\n\t\tif ( PixelX \u003C Screen.CameraPos.X - w ) return false;\r\n\t\tif ( PixelX \u003E Screen.PixelWidth \u002B Screen.CameraPos.X ) return false;\r\n\t\tif ( PixelY \u003C Screen.CameraPos.Y - h ) return false;\r\n\t\tif ( PixelY \u003E Screen.PixelHeight \u002B Screen.CameraPos.Y ) return false;\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\t// \u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n\tprivate List\u003CPixelData\u003E GetCurrentPixels()\r\n\t{\r\n\t\treturn GetFlippedPixels( _currentFrameData, _currentAnimation.AnimSize );\r\n\t}\r\n\r\n\tprivate List\u003CPixelData\u003E GetFlippedPixels( FrameData frame, PixelPoint animSize )\r\n\t{\r\n\t\tif ( _flipX \u0026\u0026 _flipY ) return frame.GetPixelsFlippedXY( animSize.X, animSize.Y );\r\n\t\tif ( _flipX ) return frame.GetPixelsFlippedX( animSize.X );\r\n\t\tif ( _flipY ) return frame.GetPixelsFlippedY( animSize.Y );\r\n\t\treturn frame.Pixels; // No flip \u2014 return the original list directly (no copy needed; Draw only reads it).\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Apply colour/alpha override to a pixel, matching the original Entity.Draw logic.\r\n\t/// \u003C/summary\u003E\r\n\tprivate Color32 ApplyColorOverride( Color32 color )\r\n\t{\r\n\t\tif ( !_overrideColor )\r\n\t\t\treturn color;\r\n\r\n\t\tif ( _overrideAlpha )\r\n\t\t{\r\n\t\t\tfloat colorAlpha = color.a / 255f;\r\n\t\t\tif ( color.a == 0 ) return color;\r\n\t\t\treturn new Color32(\r\n\t\t\t\t(byte)(_overriddenColor.r * 255f),\r\n\t\t\t\t(byte)(_overriddenColor.g * 255f),\r\n\t\t\t\t(byte)(_overriddenColor.b * 255f),\r\n\t\t\t\t(byte)(_overriddenColor.a * colorAlpha * 255f) );\r\n\t\t}\r\n\r\n\t\treturn new Color32(\r\n\t\t\t(byte)(_overriddenColor.r * 255f),\r\n\t\t\t(byte)(_overriddenColor.g * 255f),\r\n\t\t\t(byte)(_overriddenColor.b * 255f),\r\n\t\t\tcolor.a );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.transposer","Path":"Transposer/Entities/Background.cs","FileName":"Background.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":444361,"IsPrivate":false,"Code":"namespace Sandbox.Transposer;\r\n\r\n/// \u003Csummary\u003E\r\n/// Procedural animated background. Fills the entire screen with 2\u00D72 pixel blocks\r\n/// whose colours are computed from sine waves, position, and elapsed time.\r\n/// Draws a decorative border: outer edge is yellow-tinted noise, inner is black.\r\n///\r\n/// Three visual modes are randomly chosen per scene activation.\r\n/// \u003C/summary\u003E\r\npublic class Background : Entity\r\n{\r\n\tprivate int _width;\r\n\tprivate int _height;\r\n\tprivate float _elapsedTime;\r\n\tprivate bool _normalDirectionX;\r\n\tprivate bool _normalDirectionY;\r\n\tprivate int _visualMode;\r\n\r\n\tpublic Background( int x, int y, TransposerScene scene )\r\n\t{\r\n\t\tPixelPosition = new PixelPoint( x, y );\r\n\t\t_scene = scene;\r\n\t\t_type = \u0022tile\u0022;\r\n\t\t_layer = Globals.DEPTH_TILE;\r\n\r\n\t\t_width = Screen.PixelWidth;\r\n\t\t_height = Screen.PixelHeight;\r\n\r\n\t\t_normalDirectionX = Game.Random.Next( 0, 2 ) == 0;\r\n\t\t_normalDirectionY = Game.Random.Next( 0, 2 ) == 0;\r\n\t\t_visualMode = Game.Random.Next( 0, 3 );\r\n\t}\r\n\r\n\tpublic override void UpdateEntity( float deltaTime )\r\n\t{\r\n\t\tbase.UpdateEntity( deltaTime );\r\n\t\t_elapsedTime \u002B= deltaTime;\r\n\t}\r\n\r\n\tpublic override void Draw()\r\n\t{\r\n\t\tint xOffset = (int)MathF.Round( _elapsedTime * 10f ) % _width;\r\n\t\tint yOffset = (int)MathF.Round( _elapsedTime * 10f ) % _height;\r\n\r\n\t\tif ( !_normalDirectionX ) xOffset *= -1;\r\n\t\tif ( !_normalDirectionY ) yOffset *= -1;\r\n\r\n\t\tint px = PixelX;\r\n\t\tint py = PixelY;\r\n\r\n\t\tfor ( int x = 0; x \u003C _width; x \u002B= 2 )\r\n\t\t{\r\n\t\t\tfor ( int y = 0; y \u003C _height; y \u002B= 2 )\r\n\t\t\t{\r\n\t\t\t\t// Wrap the scrolled coordinates so the gradient tiles seamlessly.\r\n\t\t\t\tint adjX = x \u002B xOffset;\r\n\t\t\t\twhile ( adjX \u003E= _width ) adjX -= _width;\r\n\t\t\t\twhile ( adjX \u003C 0 ) adjX \u002B= _width;\r\n\r\n\t\t\t\tint adjY = y - yOffset;\r\n\t\t\t\twhile ( adjY \u003E= _height ) adjY -= _height;\r\n\t\t\t\twhile ( adjY \u003C 0 ) adjY \u002B= _height;\r\n\r\n\t\t\t\tconst float MIN = 0.20f;\r\n\t\t\t\tconst float MAX = 0.80f;\r\n\r\n\t\t\t\t// Each axis produces a sine-shaped brightness gradient that peaks at\r\n\t\t\t\t// the centre and dips at the edges \u2014 creating a soft vignette look.\r\n\t\t\t\tfloat shadeX = adjX \u003C= _width / 2\r\n\t\t\t\t\t? PixelUtils.Map( adjX, 0, _width / 2f, MIN, MAX, EaseType.SineIn )\r\n\t\t\t\t\t: PixelUtils.Map( adjX, _width / 2f \u002B 1, _width, MAX, MIN, EaseType.SineOut );\r\n\r\n\t\t\t\tfloat shadeY = adjY \u003C= _height / 2\r\n\t\t\t\t\t? PixelUtils.Map( adjY, 0, _height / 2f, MIN, MAX, EaseType.SineOut )\r\n\t\t\t\t\t: PixelUtils.Map( adjY, _height / 2f \u002B 1, _height, MAX, MIN, EaseType.SineIn );\r\n\r\n\t\t\t\t// Slow sine wave mixed in to animate the overall brightness over time.\r\n\t\t\t\tfloat offset = MathF.Sin( _elapsedTime * 0.25f ) * 0.20f;\r\n\r\n\t\t\t\t// Mode 0: pulsing blue channel \u2014 cool colour that breathes over time.\r\n\t\t\t\t// Mode 1: blue derived from avg/(x\u002Bepsilon) \u2014 varies by column position.\r\n\t\t\t\t// Mode 2: blue derived from avg/(y\u002Bepsilon) \u2014 varies by row position.\r\n\t\t\t\tColor color = _visualMode switch\r\n\t\t\t\t{\r\n\t\t\t\t\t0 =\u003E new Color( shadeX \u002B offset, shadeY - offset, 0.70f \u002B MathF.Abs( MathF.Sin( _elapsedTime * 0.5f ) ) * 0.30f ),\r\n\t\t\t\t\t1 =\u003E new Color( shadeX \u002B offset, shadeY - offset, (shadeX \u002B shadeY) * 0.5f / (shadeX \u002B 0.1f) ),\r\n\t\t\t\t\t_ =\u003E new Color( shadeX \u002B offset, shadeY - offset, (shadeX \u002B shadeY) * 0.5f / (shadeY \u002B 0.1f) )\r\n\t\t\t\t};\r\n\r\n\t\t\t\tColor32 c32 = (Color32)color;\r\n\t\t\t\tScreen.SetPixel( px \u002B x, py \u002B y, c32 );\r\n\t\t\t\tScreen.SetPixel( px \u002B x \u002B 1, py \u002B y, c32 );\r\n\t\t\t\tScreen.SetPixel( px \u002B x, py \u002B y \u002B 1, c32 );\r\n\t\t\t\tScreen.SetPixel( px \u002B x \u002B 1, py \u002B y \u002B 1, c32 );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// \u2500\u2500 Decorative border \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\t\tColor32 inner = new( 0, 0, 0, 255 );\r\n\r\n\t\tconst float MIN_SHADE = 0.20f;\r\n\t\tconst float MAX_SHADE = 0.30f;\r\n\t\tconst float MIN_OPACITY = 0.25f;\r\n\t\tconst float MAX_OPACITY = 0.50f;\r\n\r\n\t\t// Top and bottom edges.\r\n\t\tfor ( int x = 0; x \u003C _width; x\u002B\u002B )\r\n\t\t{\r\n\t\t\tColor32 outer = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( x, 0, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( x, 1, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( x, _height - 1, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( x, _height - 2, outer );\r\n\r\n\t\t\tif ( x \u003E= 2 \u0026\u0026 x \u003C= _width - 3 )\r\n\t\t\t{\r\n\t\t\t\tScreen.AddPixel( x, 2, inner );\r\n\t\t\t\tScreen.AddPixel( x, 3, inner );\r\n\t\t\t\tScreen.AddPixel( x, _height - 3, inner );\r\n\t\t\t\tScreen.AddPixel( x, _height - 4, inner );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Left and right edges.\r\n\t\tfor ( int y = 2; y \u003C _height - 2; y\u002B\u002B )\r\n\t\t{\r\n\t\t\tColor32 outer = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( 0, y, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( 1, y, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( _width - 1, y, outer );\r\n\t\t\touter = RandomBorderColor( MIN_SHADE, MAX_SHADE, MIN_OPACITY, MAX_OPACITY );\r\n\t\t\tScreen.AddPixel( _width - 2, y, outer );\r\n\r\n\t\t\tScreen.AddPixel( 2, y, inner );\r\n\t\t\tScreen.AddPixel( 3, y, inner );\r\n\t\t\tScreen.AddPixel( _width - 3, y, inner );\r\n\t\t\tScreen.AddPixel( _width - 4, y, inner );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static Color32 RandomBorderColor( float minShade, float maxShade, float minOp, float maxOp )\r\n\t{\r\n\t\tfloat shade = Game.Random.Float( minShade, maxShade );\r\n\t\tfloat op = Game.Random.Float( minOp, maxOp );\r\n\t\treturn new Color32( (byte)(shade * 255), (byte)(shade * 255), 0, (byte)(op * 255) );\r\n\t}\r\n}\r\n"}]}