Skip to content
This repository was archived by the owner on Oct 18, 2025. It is now read-only.

Commit cd234fd

Browse files
tankman bg fix
1 parent 99e4c7d commit cd234fd

File tree

1 file changed

+69
-30
lines changed

1 file changed

+69
-30
lines changed

assets/stages/tank.hx

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ function onCreate()
4646
watchTower = createSprite('watchTower', 100, 50, 1, 0.5, true, [['idle', 'watchtower gradient color']]);
4747
}
4848

49+
tank = createSprite('tank', 0, 0, 1, 0.5, true, [['idle', 'BG tank w lighting']], true);
50+
4951
runningTankmans = new FlxTypedGroup<FlxSprite>();
5052
add(runningTankmans);
5153

52-
tank = createSprite('tank', 0, 0, 1, 0.5, true, [['idle', 'BG tank w lighting']], true);
53-
5454
ground = createSprite('ground', -420, -150, 1.15);
5555
}
5656

@@ -144,6 +144,8 @@ function onNoteHit(note:Note)
144144
getCharacter('extra', 0).animation.play('shoot' + (note.data % 2 == 0 ? FlxG.random.int(1, 2) : FlxG.random.int(3, 4)), true);
145145
}
146146

147+
var tankPool:Array<FlxSprite> = [];
148+
147149
var spawnTimes:Array<Array<Float>> = [];
148150

149151
function createRunningTankmans()
@@ -161,39 +163,76 @@ function updateTankmans()
161163

162164
function createTankman(noFlipX:Bool):FlxSprite
163165
{
164-
var sprite:FlxSprite = new FlxSprite(noFlipX ? 1700 : -800, 200 + FlxG.random.int(50, 100));
165-
sprite.frames = Paths.getSparrowAtlas('stages/tank/killedTankman');
166-
sprite.animation.addByPrefix('run', 'tankman running', 24, true);
166+
var sprite:FlxSprite;
167+
168+
if (tankPool.length > 0)
169+
{
170+
sprite = tankPool.pop();
171+
resetTankman(sprite, noFlipX);
172+
} else {
173+
sprite = new FlxSprite();
174+
sprite.frames = Paths.getSparrowAtlas('stages/tank/killedTankman');
175+
sprite.animation.addByPrefix('run', 'tankman running', 24, true);
176+
sprite.scale.set(0.8, 0.8);
177+
sprite.updateHitbox();
178+
sprite.antialiasing = ClientPrefs.data.antialiasing;
179+
180+
sprite.animation.onFinish.add(
181+
(name:String) -> {
182+
if (name == 'shot')
183+
{
184+
runningTankmans.remove(sprite);
185+
186+
tankPool.push(sprite);
187+
}
188+
}
189+
);
190+
191+
sprite.animation.onFrameChange.add(
192+
(name:String) -> {
193+
if (name == 'shot')
194+
{
195+
if (sprite.flipX)
196+
{
197+
sprite.offset.x = 300;
198+
sprite.offset.y = 200;
199+
}
200+
201+
sprite.velocity.x = 0;
202+
}
203+
}
204+
);
205+
206+
resetTankman(sprite, noFlipX);
207+
}
208+
209+
if (sprite != null)
210+
runningTankmans.add(sprite);
211+
}
212+
213+
function resetTankman(sprite:FlxSprite, noFlipX:Bool)
214+
{
215+
FlxTween.cancelTweensOf(sprite);
216+
167217
sprite.animation.addByPrefix('shot', 'John Shot ' + FlxG.random.int(1, 2), 24, false);
168-
sprite.animation.play('run', true);
169-
sprite.animation.curAnim.curFrame = FlxG.random.int(0, sprite.animation.curAnim.frames.length - 1);
170-
sprite.scale.set(0.8, 0.8);
171-
sprite.updateHitbox();
172-
runningTankmans.add(sprite);
173-
sprite.antialiasing = ClientPrefs.data.antialiasing;
218+
219+
sprite.x = noFlipX ? 1600 : -800;
220+
sprite.y = 200 + FlxG.random.int(50, 100);
221+
222+
sprite.offset.x = 0;
223+
sprite.offset.y = 0;
224+
174225
sprite.flipX = !noFlipX;
175-
sprite.velocity.x = (750 * FlxG.random.float(0.6, 1)) * (noFlipX ? -1 : 1);
226+
227+
sprite.animation.play('run', true);
176228

177-
sprite.animation.onFinish.add(
178-
(name:String) -> {
179-
if (name == 'shot')
180-
runningTankmans.remove(sprite, true);
181-
}
182-
);
229+
sprite.animation.curAnim.curFrame = FlxG.random.int(0, sprite.animation.curAnim.frames.length - 1);
183230

184-
FlxTimer.wait(1, () ->
231+
FlxTween.tween(sprite, {x: sprite.x + (400 + FlxG.random.float(0.6, 1) * 300) * (noFlipX ? -1 : 1)}, 1,
185232
{
186-
sprite.animation.play('shot', true);
187-
188-
if (sprite.flipX)
189-
{
190-
sprite.offset.x = 300;
191-
sprite.offset.y = 200;
233+
onComplete: (_) -> {
234+
sprite.animation.play('shot', true);
192235
}
193-
194-
sprite.velocity.x = 0;
195-
}
236+
}
196237
);
197-
198-
return sprite;
199238
}

0 commit comments

Comments
 (0)