@@ -22,29 +22,36 @@ private enum States
2222
2323 private readonly bool canDash ;
2424 private readonly float respawnTime ;
25+ private readonly bool delayRespawn ;
2526 private float timer ;
2627 private float rectEffectInflate = 0f ;
2728
2829 private readonly SoundSource breakSfx ;
2930
3031 private readonly MTexture [ , , ] nineSlice ;
32+ private readonly MTexture debrisTexture ;
3133
3234 private Vector2 wobbleScale = Vector2 . One ;
3335 private readonly Wiggler wobble ;
3436
3537 public BubbleWrapBlock ( EntityData data , Vector2 offset )
36- : this ( data . Position + offset , data . Width , data . Height , data . Bool ( "canDash" ) , data . Float ( "respawnTime" ) ) { }
38+ : this ( data . Position + offset , data . Width , data . Height , data . Bool ( "canDash" ) , data . Float ( "respawnTime" ) , data . Attr ( "texture" , "objects/VortexHelper/bubbleWrapBlock" ) , data . Bool ( "delayRespawn" , false ) ) { }
3739
3840 public BubbleWrapBlock ( Vector2 position , int width , int height , bool canDash , float respawnTime )
41+ : this ( position , width , height , canDash , respawnTime , "objects/VortexHelper/bubbleWrapBlock" , false ) { }
42+
43+ public BubbleWrapBlock ( Vector2 position , int width , int height , bool canDash , float respawnTime , string texture , bool delayed )
3944 : base ( position , width , height , safe : true )
4045 {
4146 this . SurfaceSoundIndex = SurfaceIndex . Brick ;
4247
4348 this . canDash = canDash ;
4449 this . respawnTime = respawnTime ;
50+ this . delayRespawn = delayed ;
4551
46- MTexture block = GFX . Game [ "objects/VortexHelper/bubbleWrapBlock/bubbleBlock" ] ;
47- MTexture outline = GFX . Game [ "objects/VortexHelper/bubbleWrapBlock/bubbleOutline" ] ;
52+ MTexture block = GFX . Game [ texture + "/bubbleBlock" ] ;
53+ MTexture outline = GFX . Game [ texture + "/bubbleOutline" ] ;
54+ this . debrisTexture = GFX . Game . GetOrDefault ( texture + "/debris" , GFX . Game [ "debris/VortexHelper/bubbleWrapBlock" ] ) ;
4855
4956 this . nineSlice = new MTexture [ 3 , 3 , 2 ] ;
5057 for ( int i = 0 ; i < 3 ; i ++ )
@@ -142,7 +149,7 @@ public void Break()
142149 {
143150 Debris debris = new Debris ( ) . orig_Init ( this . Position + new Vector2 ( 4 + i * 8 , 4 + j * 8 ) , '1' ) . BlastFrom ( this . Center ) ;
144151 var debrisData = new DynData < Debris > ( debris ) ;
145- debrisData . Get < Image > ( "image" ) . Texture = GFX . Game [ "debris/VortexHelper/BubbleWrapBlock" ] ;
152+ debrisData . Get < Image > ( "image" ) . Texture = this . debrisTexture ;
146153 this . Scene . Add ( debris ) ;
147154 }
148155 }
@@ -164,24 +171,45 @@ public override void Update()
164171
165172 if ( this . timer <= 0f )
166173 if ( CheckEntitySafe ( ) )
167- Respawn ( ) ;
174+ StartRespawn ( ) ;
168175
169176 if ( this . state == States . Gone )
170177 this . rectEffectInflate = Calc . Approach ( this . rectEffectInflate , 3 , 20 * Engine . DeltaTime ) ;
171178 }
172179
173- private void Respawn ( )
180+ private void StartRespawn ( )
174181 {
175182 if ( this . Collidable )
176183 return ;
177184
185+ this . Collidable = true ;
186+
187+ if ( this . delayRespawn )
188+ {
189+ Audio . Play ( "event:/game/09_core/bounceblock_reappear" , this . Center ) ;
190+ float duration = 0.35f ;
191+ for ( int i = 0 ; i < this . Width / 8f ; i ++ )
192+ {
193+ for ( int j = 0 ; j < this . Height / 8f ; j ++ )
194+ {
195+ Vector2 pos = this . Position + new Vector2 ( 4 + i * 8 , 4 + j * 8 ) ;
196+ Scene . Add ( Engine . Pooler . Create < BubbleWrapBlock . RespawnDebris > ( ) . Init ( pos + ( pos - Center ) . SafeNormalize ( ) * 12f , pos , this . debrisTexture , duration ) ) ;
197+ }
198+ }
199+ Alarm . Set ( this , duration , Respawn , Alarm . AlarmMode . Oneshot ) ;
200+ }
201+ else
202+ Respawn ( ) ;
203+ }
204+
205+ private void Respawn ( )
206+ {
178207 this . wobble . Start ( ) ;
179208 RespawnParticles ( ) ;
180209 this . rectEffectInflate = 0f ;
181210
182211 EnableStaticMovers ( ) ;
183212 this . breakSfx . Play ( SFX . game_05_redbooster_reappear ) ;
184- this . Collidable = true ;
185213 this . state = States . Idle ;
186214 }
187215
@@ -208,4 +236,47 @@ private bool CheckEntitySafe()
208236 LifeMax = 0.8f ,
209237 DirectionRange = ( float ) Math . PI / 6f
210238 } ;
239+
240+ private class RespawnDebris : Entity
241+ {
242+ private float duration ;
243+ private Vector2 from ;
244+ private Vector2 to ;
245+
246+ private Image sprite ;
247+ private float percent ;
248+
249+ public BubbleWrapBlock . RespawnDebris Init ( Vector2 from , Vector2 to , MTexture texture , float duration )
250+ {
251+ if ( this . sprite == null )
252+ {
253+ Add ( this . sprite = new Image ( texture ) ) ;
254+ this . sprite . CenterOrigin ( ) ;
255+ }
256+ else
257+ {
258+ this . sprite . Texture = texture ;
259+ }
260+ this . sprite . Rotation = Calc . Random . NextAngle ( ) ;
261+
262+ this . from = from ;
263+ this . Position = from ;
264+ this . percent = 0f ;
265+ this . to = to ;
266+ this . duration = duration ;
267+ return this ;
268+ }
269+
270+ public override void Update ( )
271+ {
272+ if ( this . percent > 1f )
273+ {
274+ RemoveSelf ( ) ;
275+ return ;
276+ }
277+ this . percent += Engine . DeltaTime / this . duration ;
278+ this . Position = Vector2 . Lerp ( this . from , this . to , Ease . CubeIn ( this . percent ) ) ;
279+ this . sprite . Color = Color . White * this . percent ;
280+ }
281+ }
211282}
0 commit comments