User prompt
Please fix the bug: 'Timeout.tick error: bounceTween is not defined' in or related to this line: 'e.bounceTween = bounceTween;' Line Number: 352
User prompt
Inside spawnEnemy(), store a reference to the bounce tween and cancel it on hit: function spawnEnemy() { var e = new Container(); var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); var fromLeft = Math.random() < 0.5; e.x = fromLeft ? -gfx.width / 2 : 2048 + gfx.width / 2; e.y = 2732 - 225; e.speedX = fromLeft ? Math.random() * 4 + 2 : -(Math.random() * 4 + 2); gfx.scaleX = fromLeft ? 1 : -1; // Bounce logic with cancel support var baseY = e.y; let bounceTween; function bounce() { bounceTween = tween(e, { y: baseY - 50 }, { duration: 500, easing: tween.bounceInOut, onFinish: () => { bounceTween = tween(e, { y: baseY }, { duration: 500, easing: tween.bounceInOut, onFinish: bounce }); } }); } bounce(); e.bounceTween = bounceTween; enemies.push(e); game.addChild(e); }
User prompt
Replace your updateScoreText() with this cleaner version: // Create and add score display once var score = 0; var scoreTxt = new Text2(String(score), { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = 1024; scoreTxt.y = 50; LK.gui.top.addChild(scoreTxt); // Update without destroying function updateScoreText(newValue) { score = newValue; scoreTxt.text = String(score); tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: () => { tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); }
User prompt
Replace this block: if (attackCol && e.intersects(attackCol)) { e.update = () => {}; LK.getSound('slimedeath').play(); tween(e, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: () => tween(e, { scaleX: 0.5, scaleY: 0.5, alpha: 0 }, { duration: 100, onFinish: () => e.destroy() }) }); enemies.splice(i, 1); LK.setScore(++score); updateScoreText(score); } With this corrected version: if (attackCol && e.intersects(attackCol)) { e.update = () => {}; LK.getSound('slimedeath').play(); enemies.splice(i, 1); // Remove immediately from array tween(e, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: () => { tween(e, { scaleX: 0.5, scaleY: 0.5, alpha: 0, tint: 0xFF0000 }, { duration: 100, onFinish: () => e.destroy() }); } }); score++; updateScoreText(score); }
User prompt
var score = 0; function updateScoreText(value) { LK.gui.top.removeChild(scoreTxt); scoreTxt = new Text2(String(value), { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = 1024; scoreTxt.y = 50; LK.gui.top.addChild(scoreTxt); tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: () => { tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); }
Code edit (3 edits merged)
Please save this source code
User prompt
// TODO: PASTE THIS BLOCK AFTER YOUR ASSET INITs AND PLUGIN IMPORTS // You already have tween, sounds, and assets defined, so this should replace the current game setup // Game Setup var game = new LK.Game({ backgroundColor: 0x000000 }); LK.playMusic('bgm', { loop: true }); var bg01 = LK.getAsset('bg01', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); game.addChild(bg01); // PLAYER SETUP var player = new Container(); var playerSprite = player.attachAsset('player_idle', { anchorX: 0.5, anchorY: 0.5 }); player.x = 1024; player.y = 2732 - 250; game.addChild(player); var isJumping = false; var isSequenceRunning = false; var playerState = 'idle'; var attackCol = null; var playerFlip = 1; function swapPlayerVisual(newVisualId, x, y, cb) { if (player && !player.destroyed) { game.removeChild(player); player.destroy(); } player = new Container(); playerSprite = player.attachAsset(newVisualId, { anchorX: 0.5, anchorY: 0.5 }); player.x = x; player.y = y; player.scaleX = playerFlip; game.addChild(player); if (newVisualId === 'player_jump') { let jumpCol = LK.getAsset('jumpcol', { anchorX: 0.5, anchorY: 0.5, x: x, y: y + player.height / 2, alpha: 0 }); game.addChild(jumpCol); tween(jumpCol, { y: jumpCol.y - 600 }, { duration: 500, easing: tween.bounceOut, onFinish: () => { tween(jumpCol, { y: 2732 - 250 + player.height / 2 }, { duration: 300, easing: tween.bounceOut, onFinish: () => jumpCol.destroy() }); } }); } if (cb) cb(); } function startBreathing() { tween(player, { scaleX: 1.05, scaleY: 1.05 }, { duration: 1000, easing: tween.easeInOut, onFinish: () => { tween(player, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: startBreathing }); } }); } function startTilting() { tween(player, { rotation: Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: () => { tween(player, { rotation: -Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: () => { tween(player, { rotation: 0 }, { duration: 500, easing: tween.easeInOut, onFinish: startTilting }); } }); } }); } startBreathing(); startTilting(); // Jump + Attack input game.down = function (x, y) { if (isSequenceRunning) return; if (y < 2732 * 2 / 3) { if (!isJumping) { isJumping = true; LK.getSound('hup').play(); playerFlip = 1; swapPlayerVisual('player_jump', player.x, player.y); for (let i = 0; i < 10; i++) { let dust = LK.getAsset('dust', { anchorX: 0.5, anchorY: 0.5, x: player.x + Math.random() * 100 - 50, y: player.y + Math.random() * 100 - 50 }); game.addChild(dust); tween(dust, { alpha: 0, x: dust.x + Math.random() * 200 - 100, y: dust.y - Math.random() * 200 }, { duration: 500, onFinish: () => dust.destroy() }); } tween(player, { y: player.y - 600 }, { duration: 500, easing: tween.easeOut, onFinish: () => { tween(player, { y: 2732 - 250 }, { duration: 300, easing: tween.bounceOut, onFinish: () => { LK.effects.flashObject(player, 0xFFFFFF, 100); for (let i = 0; i < 10; i++) { let p = LK.getAsset('dust', { anchorX: 0.5, anchorY: 0.5, x: player.x + Math.random() * 100 - 50, y: player.y + Math.random() * 100 - 50 }); game.addChild(p); tween(p, { alpha: 0, x: p.x + Math.random() * 200 - 100, y: p.y + Math.random() * 200 }, { duration: 500, onFinish: () => p.destroy() }); } isJumping = false; swapPlayerVisual('player_idle', player.x, player.y, () => { startBreathing(); startTilting(); }); } }); } }); } return; } // Attack isSequenceRunning = true; playerState = 'attacking'; playerFlip = x < 1024 ? -1 : 1; swapPlayerVisual('player_attackf01', 1024, 2732 - 250); LK.getSound('retroslash').play(); LK.setTimeout(() => { swapPlayerVisual('player_attackf02', 1024, 2732 - 250); attackCol = LK.getAsset('attackcol', { anchorX: 0.5, anchorY: 0.5, x: player.x + (playerFlip === -1 ? -150 : 150), y: player.y, alpha: 0 }); attackCol.scaleX = playerFlip; game.addChild(attackCol); LK.setTimeout(() => { if (attackCol) attackCol.destroy(); swapPlayerVisual('player_idle', 1024, 2732 - 250, () => { startBreathing(); startTilting(); isSequenceRunning = false; playerState = 'idle'; }); }, 250); }, 250); }; // Score var scoreTxt = new Text2('0', { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function updateScoreText(score) { LK.gui.top.removeChild(scoreTxt); scoreTxt = new Text2(String(score), { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: () => tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }) }); } // Enemies var enemies = []; function spawnEnemy() { var e = new Container(); var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); e.y = 2732 - 225; var fromLeft = Math.random() < 0.5; e.x = fromLeft ? -gfx.width : 2048 + gfx.width; e.speedX = fromLeft ? (Math.random() * 4 + 2) : -(Math.random() * 4 + 2); gfx.scaleX = fromLeft ? 1 : -1; enemies.push(e); game.addChild(e); let baseY = e.y; function bounce() { tween(e, { y: baseY - 50 }, { duration: 500, easing: tween.bounceInOut, onFinish: () => { tween(e, { y: baseY }, { duration: 500, easing: tween.bounceInOut, onFinish: bounce }); } }); } bounce(); } LK.setInterval(spawnEnemy, 2000); game.update = function () { for (let i = enemies.length - 1; i >= 0; i--) { let e = enemies[i]; e.x += e.speedX; if (e.x < -300 || e.x > 2348) { e.destroy(); enemies.splice(i, 1); continue; } if (attackCol && e.intersects(attackCol)) { LK.getSound('slimedeath').play(); e.update = () => {}; tween(e, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: () => { tween(e, { scaleX: 0.5, scaleY: 0.5, alpha: 0 }, { duration: 100, onFinish: () => e.destroy() }); } }); enemies.splice(i, 1); LK.setScore(LK.getScore() + 1); updateScoreText(LK.getScore()); } } };
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Maximum call stack size exceeded' in or related to this line: 'swapPlayerVisual('player_idle');' Line Number: 490
User prompt
Clean Up, anywhere there is: player.destroy(); player = LK.getAsset(...); game.addChild(player); replace it with: swapPlayerVisual('player_idle'); // or 'player_jump' or 'player_attackf01', etc.
User prompt
Use swapPlayerVisual() in the Jump and Attack jump: swapPlayerVisual('player_jump'); Idle (after landing or attack):
User prompt
Replace the Existing player Setup var player = new Container(); var playerSprite = player.attachAsset('player_idle', { anchorX: 0.5, anchorY: 0.5 }); player.x = 2048 / 2; player.y = 2732 - 250; game.addChild(player); And replace it with this updated setup, right after initializing the game // Create a player container with swappable visuals var player = new Container(); player.x = 2048 / 2; player.y = 2732 - 250; game.addChild(player); var playerSprite = null; function swapPlayerVisual(assetId) { // Destroy previous visual if it exists if (playerSprite && !playerSprite.destroyed) { player.removeChild(playerSprite); playerSprite.destroy(); } // Attach new sprite to the same container playerSprite = player.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); }
User prompt
Keep the player container alive. Replace only the attached asset (playerSprite). Ensure any tween or logic applies to player, not playerSprite.
User prompt
it doesn't work, i still see two characters...... i jump, i land and attack, the attack animation finishes and there are two characters
User prompt
if i jump and then land and right away attack, theres two characters visible, fix it
User prompt
when the playif i jump and then land and right away attack, theres two characters visible, fix it
User prompt
do not create a player idle when landing
User prompt
prevent the player from attacking while landing
User prompt
prevent the player from attacking while jumping
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of null (setting 'x')' in or related to this line: 'playerAttack.x = 2048 / 2;' Line Number: 549
User prompt
Please fix the bug: 'Uncaught ReferenceError: playerAttack is not defined' in or related to this line: 'playerAttack.scaleX = -1;' Line Number: 544
User prompt
During jump: swapPlayerVisual('player_jump'); After landing: swapPlayerVisual('player_idle'); During attack: swapPlayerVisual('player_attackf01'); After delay: swapPlayerVisual('player_attackf02'); // then after another delay, return to idle: swapPlayerVisual('player_idle'); Do not call player.destroy() unless you're destroying the entire player container—you should only be swapping the child visual.
User prompt
Please fix the bug: 'playerSprite is not defined' in or related to this line: 'if (playerSprite) {' Line Number: 126
User prompt
var playerSprite = null; Create a swapPlayerVisual() function that only changes the visual inside player: function swapPlayerVisual(visualId) { if (playerSprite) { player.removeChild(playerSprite); playerSprite.destroy(); } playerSprite = player.attachAsset(visualId, { anchorX: 0.5, anchorY: 0.5 }); } Update your player setup like this: var player = new Container(); player.x = 2048 / 2; player.y = 2732 - 250; swapPlayerVisual('player_idle'); game.addChild(player); Update all attack and jump logic to use swapPlayerVisual() instead of creating new assets directly:
User prompt
make jumpcol invisible
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ LK.playMusic('bgm', { loop: true }); var bg01 = LK.getAsset('bg01', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(bg01); var player = new Container(); var playerSprite = player.attachAsset('player_idle', { anchorX: 0.5, anchorY: 0.5 }); player.x = 2048 / 2; player.y = 2732 - 250; game.addChild(player); var isSequenceRunning = false; var playerState = 'idle'; var attackCol = null; var isJumping = false; function swapPlayerVisual(newVisualId, x, y, callback) { if (player && !player.destroyed) { game.removeChild(player); player.destroy(); } player = new Container(); playerSprite = player.attachAsset(newVisualId, { anchorX: 0.5, anchorY: 0.5 }); player.x = x; player.y = y; game.addChild(player); if (newVisualId === 'player_jump') { var jumpCol = LK.getAsset('jumpcol', { anchorX: 0.5, anchorY: 0.5, x: x, y: y + player.height / 2 }); jumpCol.alpha = 0; game.addChild(jumpCol); tween(jumpCol, { y: jumpCol.y - 600 }, { duration: 500, easing: tween.bounceOut, onFinish: function onFinish() { tween(jumpCol, { y: 2732 - 250 + player.height / 2 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { return jumpCol.destroy(); } }); } }); } if (callback) { callback(); } } function startBreathingAnimation() { tween(player, { scaleX: 1.05, scaleY: 1.05 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: startBreathingAnimation }); } }); } startBreathingAnimation(); // Idle tilt animation function startTiltAnimation() { tween(player, { rotation: Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { rotation: -Math.PI / 32 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(player, { rotation: 0 }, { duration: 500, easing: tween.easeInOut, onFinish: startTiltAnimation }); } }); } }); } startTiltAnimation(); game.down = function (x, y) { if (isSequenceRunning) { return; } if (y < 2732 * 2 / 3) { if (!isJumping) { isJumping = true; LK.getSound('hup').play(); swapPlayerVisual('player_jump', player.x, player.y); tween(player, { y: player.y - 600 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(player, { y: 2732 - 250 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { isJumping = false; swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, function () { startBreathingAnimation(); startTiltAnimation(); }); } }); } }); } return; } isSequenceRunning = true; playerState = 'attacking'; var isLeftClick = x < 2048 / 2; swapPlayerVisual('player_attackf01', 2048 / 2, 2732 - 250); if (isLeftClick) { player.scaleX = -1; } LK.getSound('retroslash').play(); LK.setTimeout(function () { swapPlayerVisual('player_attackf02', 2048 / 2, 2732 - 250); if (isLeftClick) { player.scaleX = -1; } attackCol = LK.getAsset('attackcol', { anchorX: 0.5, anchorY: 0.5, x: isLeftClick ? player.x - 150 : player.x + 150, y: player.y, alpha: 0 }); if (isLeftClick) { attackCol.scaleX = -1; } game.addChild(attackCol); LK.setTimeout(function () { if (attackCol) { attackCol.destroy(); attackCol = null; } swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, function () { startBreathingAnimation(); startTiltAnimation(); }); isSequenceRunning = false; playerState = 'idle'; }, 250); }, 250); }; var scoreTxt = new Text2('0', { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function updateScoreText(value) { LK.gui.top.removeChild(scoreTxt); scoreTxt = new Text2(String(value), { size: 300, fill: 0xFF69B4, stroke: 0x000000, strokeThickness: 5 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { return tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); } var enemies = []; function spawnEnemy() { var e = new Container(); var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); e.y = 2732 - 225; var spawnLeft = Math.random() < 0.5; e.x = spawnLeft ? -gfx.width / 2 : 2048 + gfx.width / 2; e.speedX = spawnLeft ? Math.random() * 4 + 2 : -(Math.random() * 4 + 2); gfx.scaleX = spawnLeft ? 1 : -1; enemies.push(e); game.addChild(e); var baseY = e.y; function bounce() { tween(e, { y: baseY - 50 }, { duration: 500, easing: tween.bounceInOut, onFinish: function onFinish() { tween(e, { y: baseY }, { duration: 500, easing: tween.bounceInOut, onFinish: bounce }); } }); } bounce(); } LK.setInterval(spawnEnemy, 2000); game.update = function () { for (var i = enemies.length - 1; i >= 0; i--) { var e = enemies[i]; e.x += e.speedX; if (e.x < -300 || e.x > 2048 + 300) { e.destroy(); enemies.splice(i, 1); continue; } if (attackCol && e.intersects(attackCol)) { e.update = function () {}; LK.getSound('slimedeath').play(); tween(e, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { return tween(e, { scaleX: 0.5, scaleY: 0.5, alpha: 0 }, { duration: 100, onFinish: function onFinish() { return e.destroy(); } }); } }); enemies.splice(i, 1); LK.setScore(LK.getScore() + 1); updateScoreText(LK.getScore()); } } };
===================================================================
--- original.js
+++ change.js
@@ -36,8 +36,9 @@
var attackCol = null;
var isJumping = false;
function swapPlayerVisual(newVisualId, x, y, callback) {
if (player && !player.destroyed) {
+ game.removeChild(player);
player.destroy();
}
player = new Container();
playerSprite = player.attachAsset(newVisualId, {
@@ -59,9 +60,9 @@
tween(jumpCol, {
y: jumpCol.y - 600
}, {
duration: 500,
- easing: tween.easeOut,
+ easing: tween.bounceOut,
onFinish: function onFinish() {
tween(jumpCol, {
y: 2732 - 250 + player.height / 2
}, {
@@ -97,8 +98,35 @@
}
});
}
startBreathingAnimation();
+// Idle tilt animation
+function startTiltAnimation() {
+ tween(player, {
+ rotation: Math.PI / 32
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(player, {
+ rotation: -Math.PI / 32
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(player, {
+ rotation: 0
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: startTiltAnimation
+ });
+ }
+ });
+ }
+ });
+}
+startTiltAnimation();
game.down = function (x, y) {
if (isSequenceRunning) {
return;
}
@@ -119,9 +147,12 @@
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
isJumping = false;
- swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, startBreathingAnimation);
+ swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, function () {
+ startBreathingAnimation();
+ startTiltAnimation();
+ });
}
});
}
});
@@ -130,49 +161,38 @@
}
isSequenceRunning = true;
playerState = 'attacking';
var isLeftClick = x < 2048 / 2;
- var attack01 = LK.getAsset('player_attackf01', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 - 250
- });
+ swapPlayerVisual('player_attackf01', 2048 / 2, 2732 - 250);
if (isLeftClick) {
- attack01.scaleX = -1;
+ player.scaleX = -1;
}
- game.addChild(attack01);
LK.getSound('retroslash').play();
LK.setTimeout(function () {
- attack01.destroy();
- var attack02 = LK.getAsset('player_attackf02', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 - 250
- });
+ swapPlayerVisual('player_attackf02', 2048 / 2, 2732 - 250);
if (isLeftClick) {
- attack02.scaleX = -1;
+ player.scaleX = -1;
}
attackCol = LK.getAsset('attackcol', {
anchorX: 0.5,
anchorY: 0.5,
- x: isLeftClick ? attack02.x - 150 : attack02.x + 150,
- y: attack02.y,
+ x: isLeftClick ? player.x - 150 : player.x + 150,
+ y: player.y,
alpha: 0
});
if (isLeftClick) {
attackCol.scaleX = -1;
}
game.addChild(attackCol);
- game.addChild(attack02);
LK.setTimeout(function () {
- attack02.destroy();
if (attackCol) {
attackCol.destroy();
attackCol = null;
}
- swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, startBreathingAnimation);
+ swapPlayerVisual('player_idle', 2048 / 2, 2732 - 250, function () {
+ startBreathingAnimation();
+ startTiltAnimation();
+ });
isSequenceRunning = false;
playerState = 'idle';
}, 250);
}, 250);
@@ -213,25 +233,53 @@
});
}
var enemies = [];
function spawnEnemy() {
- var enemy = LK.getAsset('enemy01', {
+ var e = new Container();
+ var gfx = e.attachAsset('enemy01', {
anchorX: 0.5,
- anchorY: 0.5,
- x: Math.random() < 0.5 ? -100 : 2048 + 100,
- y: 2732 - 225
+ anchorY: 0.5
});
- enemy.speedX = enemy.x < 0 ? 4 : -4;
- game.addChild(enemy);
- enemies.push(enemy);
+ e.y = 2732 - 225;
+ var spawnLeft = Math.random() < 0.5;
+ e.x = spawnLeft ? -gfx.width / 2 : 2048 + gfx.width / 2;
+ e.speedX = spawnLeft ? Math.random() * 4 + 2 : -(Math.random() * 4 + 2);
+ gfx.scaleX = spawnLeft ? 1 : -1;
+ enemies.push(e);
+ game.addChild(e);
+ var baseY = e.y;
+ function bounce() {
+ tween(e, {
+ y: baseY - 50
+ }, {
+ duration: 500,
+ easing: tween.bounceInOut,
+ onFinish: function onFinish() {
+ tween(e, {
+ y: baseY
+ }, {
+ duration: 500,
+ easing: tween.bounceInOut,
+ onFinish: bounce
+ });
+ }
+ });
+ }
+ bounce();
}
LK.setInterval(spawnEnemy, 2000);
game.update = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
var e = enemies[i];
e.x += e.speedX;
+ if (e.x < -300 || e.x > 2048 + 300) {
+ e.destroy();
+ enemies.splice(i, 1);
+ continue;
+ }
if (attackCol && e.intersects(attackCol)) {
e.update = function () {};
+ LK.getSound('slimedeath').play();
tween(e, {
scaleX: 1.3,
scaleY: 1.3
}, {
@@ -252,9 +300,6 @@
enemies.splice(i, 1);
LK.setScore(LK.getScore() + 1);
updateScoreText(LK.getScore());
}
- if (e.destroyed) {
- enemies.splice(i, 1);
- }
}
};
\ No newline at end of file
high definition super nintendo background of a japanese sakura tree forest Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
2d snes dust particle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
silver coin, $ sign on it, snes art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gold coin, $ sign on it, snes art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
snes white feather. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
add a wooden shield
white 3d questionmark with a shadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
caligraphy paper front facing flat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
the letters 'Ready' in 3d with a japanese cartoon cherry blossom flair. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
add eyebrows