@@ -21,14 +21,11 @@ private static void PixelGridAroundPlayerUpdate(PixelGrid self) {
21
21
self . Collider . Left = player . Collider . Left ;
22
22
self . Collider . Top = player . Collider . Top ;
23
23
self . width = TasHelperSettings . PixelGridWidth ;
24
- // when use self.Collider = player.Collider, and turn off Celeste TAS's ShowHitboxes,
25
- // if you demodash into wall, then player will stuck in wall
26
- // don't know why
27
24
}
28
25
}
29
26
private static void CreatePixelGridAroundPlayer ( On . Celeste . Level . orig_LoadLevel orig , Level self , Player . IntroTypes playerIntro , bool isFromLoader ) {
30
27
orig ( self , playerIntro , isFromLoader ) ;
31
- self . Add ( new PixelGrid ( ( ) => TasHelperSettings . EnablePixelGrid && player is not null , PixelGridAroundPlayerUpdate , false ) ) ;
28
+ self . Add ( new PixelGrid ( ( ) => TasHelperSettings . EnablePixelGrid && player is not null , PixelGridAroundPlayerUpdate ) ) ;
32
29
}
33
30
34
31
}
@@ -41,47 +38,23 @@ public class PixelGrid : Entity {
41
38
public Func < bool > visibleGetter ;
42
39
public int width = 0 ;
43
40
public Action < PixelGrid > UpdateBeforeRender ;
44
- public bool fadeOut = false ;
45
41
46
- public PixelGrid ( Func < bool > visibleGetter , Action < PixelGrid > UpdateBeforeRender , bool fadeOut = false ) {
42
+ private static MTexture texture ;
43
+
44
+ private const int TextureSize = 24 - 2 ;
45
+
46
+ public PixelGrid ( Func < bool > visibleGetter , Action < PixelGrid > UpdateBeforeRender ) {
47
47
Depth = 8900 ;
48
48
// lower than BackgroudTiles
49
49
Collidable = false ;
50
50
Collider = new Hitbox ( 0f , 0f ) ;
51
51
this . visibleGetter = visibleGetter ;
52
52
this . UpdateBeforeRender = UpdateBeforeRender ;
53
- this . fadeOut = fadeOut ;
54
53
}
55
54
56
- #pragma warning disable CS8509
57
- public static Color GetGridColor ( int index , float alpha = 0.5f ) {
58
- return ( Math . Abs ( index ) % 2 ) switch {
59
- 0 => color1 * alpha ,
60
- 1 => color2 * alpha ,
61
- } ;
62
- }
63
- #pragma warning restore CS8509
64
-
65
- public Color FadeOutColor ( int RelativeX , int RelativeY , float width ) {
66
- return GetGridColor ( RelativeX + RelativeY , fadeOut ? ( 1 - Distance ( RelativeX , RelativeY ) / width ) * TasHelperSettings . PixelGridOpacity * 0.1f : TasHelperSettings . PixelGridOpacity * 0.1f ) ;
67
- }
68
-
69
- public float Distance ( int RelativeX , int RelativeY ) {
70
- float DistX = 0f ;
71
- float DistY = 0f ;
72
- if ( RelativeX < Collider . Left - 1 ) {
73
- DistX = Collider . Left - 1 - RelativeX ;
74
- }
75
- else if ( RelativeX > Collider . Right ) {
76
- DistX = RelativeX - Collider . Right ;
77
- }
78
- if ( RelativeY < Collider . Top - 1 ) {
79
- DistY = Collider . Top - 1 - RelativeY ;
80
- }
81
- else if ( RelativeY > Collider . Bottom ) {
82
- DistY = RelativeY - Collider . Bottom ;
83
- }
84
- return ( float ) Math . Sqrt ( DistX * DistX + DistY * DistY ) ;
55
+ [ Initialize ]
56
+ public static void Initialize ( ) {
57
+ texture = GFX . Game [ "TASHelper/PixelGrid/grid" ] ;
85
58
}
86
59
87
60
public override void Update ( ) {
@@ -103,11 +76,46 @@ public override void DebugRender(Camera camera) {
103
76
}
104
77
105
78
public void RenderWithoutCondition ( ) {
106
- for ( int x = ( int ) ( Collider . Left - width ) ; x < Collider . Right + width ; x ++ ) {
107
- for ( int y = ( int ) ( Collider . Top - width ) ; y < Collider . Bottom + width ; y ++ ) {
108
- Draw . Point ( new Vector2 ( Position . X + x , Position . Y + y ) , FadeOutColor ( x , y , width ) ) ;
79
+ int left = ( int ) ( Collider . Left - width ) ;
80
+ int top = ( int ) ( Collider . Top - width ) ;
81
+ int w = ( int ) Collider . Width + 2 * width ;
82
+ int h = ( int ) Collider . Height + 2 * width ;
83
+ Color c1 , c2 ;
84
+ float alpha = TasHelperSettings . PixelGridOpacity * 0.1f ;
85
+ if ( ( left + top ) % 2 == 0 ) {
86
+ c1 = color1 * alpha ;
87
+ c2 = color2 * alpha ;
88
+ }
89
+ else {
90
+ c2 = color1 * alpha ;
91
+ c1 = color2 * alpha ;
92
+ }
93
+ Draw ( this . Position + new Vector2 ( left , top ) , w , h , c1 , c2 ) ;
94
+
95
+ }
96
+
97
+ private static void Draw ( Vector2 Position , int width , int height , Color color1 , Color color2 ) {
98
+ if ( width <= TextureSize && height <= TextureSize ) {
99
+ texture . Draw ( Position , Vector2 . Zero , color1 , Vector2 . One , 0f , new Rectangle ( 0 , 0 , width , height ) ) ;
100
+ texture . Draw ( Position , Vector2 . Zero , color2 , Vector2 . One , 0f , new Rectangle ( 1 , 0 , width , height ) ) ;
101
+ return ;
102
+ }
103
+ if ( height <= TextureSize ) {
104
+ while ( width > 0 ) {
105
+ int w = Math . Min ( width , TextureSize ) ;
106
+ Draw ( Position , w , height , color1 , color2 ) ;
107
+ Position += Vector2 . UnitX * w ;
108
+ width -= w ;
109
109
}
110
+ return ;
111
+ }
112
+ while ( height > 0 ) {
113
+ int h = Math . Min ( height , TextureSize ) ;
114
+ Draw ( Position , width , h , color1 , color2 ) ;
115
+ Position += Vector2 . UnitY * h ;
116
+ height -= h ;
110
117
}
118
+ return ;
111
119
}
112
120
}
113
121
0 commit comments