Skip to content

Commit 66d8459

Browse files
authored
Merge pull request #47 from vitellaryjr/respawnblock-additions
add 'texture' and 'delayRespawn' options
2 parents b37b67b + 738f370 commit 66d8459

3 files changed

Lines changed: 85 additions & 11 deletions

File tree

Code/Entities/BubbleWrapBlock.cs

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Loenn/entities/bubble_wrap_block.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ bubbleWrapBlock.placements = {
1919
width = 16,
2020
height = 16,
2121
canDash = true,
22-
respawnTime = 3.0
22+
respawnTime = 3.0,
23+
texture = "objects/VortexHelper/bubbleWrapBlock",
24+
delayRespawn = false,
2325
}
2426
}
2527
}
2628

27-
local frame = "objects/VortexHelper/bubbleWrapBlock/bubbleBlock"
2829
local nine_patch_options = {
2930
mode = "fill",
3031
borderMode = "repeat",
@@ -35,7 +36,7 @@ function bubbleWrapBlock.sprite(room, entity)
3536
local x, y = entity.x or 0, entity.y or 0
3637
local width, height = entity.width or 16, entity.height or 16
3738

38-
local ninePatch = drawableNinePatch.fromTexture(frame, nine_patch_options, x, y, width, height)
39+
local ninePatch = drawableNinePatch.fromTexture((entity.texture or "objects/VortexHelper/bubbleWrapBlock").."/bubbleBlock", nine_patch_options, x, y, width, height)
3940

4041
return ninePatch:getDrawableSprite()
4142
end

Loenn/lang/en_gb.lang

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ entities.VortexHelper/BowlPuffer.attributes.description.explodeTimer=The time, i
2525
# Bubble Wrap Block
2626
entities.VortexHelper/BubbleWrapBlock.placements.name.bubble_wrap_block=Respawning Dash Block
2727
entities.VortexHelper/BubbleWrapBlock.attributes.description.canDash=Whether the player is able to break this block by dashing into it.
28-
entities.VortexHelper/BubbleWrapBlock.attributes.description.respawnTime=The time in seconds that this block takes to respawn after breaking.
28+
entities.VortexHelper/BubbleWrapBlock.attributes.description.respawnTime=The time in seconds that this block takes to respawn after breaking.
29+
entities.VortexHelper/BubbleWrapBlock.attributes.description.texture=The folder containing the block textures.\nMust contain two 24x24 textures, named "bubbleBlock" and "bubbleOutline", and optionally a "debris" texture.
30+
entities.VortexHelper/BubbleWrapBlock.attributes.description.delayRespawn=Whether the attached objects should respawn slightly later than the block's collision, similar to Core Blocks.
2931

3032
# Color Switch
3133
entities.VortexHelper/ColorSwitch.placements.name.all_cycle=Color Switch (All, Cycle)

0 commit comments

Comments
 (0)