User prompt
function updateScoreDisplay() { if (!scoreTxt) { return; } // Remove the old scoreTxt game.removeChild(scoreTxt); // Create a new one with the updated score scoreTxt = createScoreText(score); scoreTxt.scaleX = 1.0; scoreTxt.scaleY = 1.0; game.addChild(scoreTxt); }
User prompt
// Comment out the tween for testing: // tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { ... });
User prompt
mainText.text = String(score); shadowText.text = String(score); if (typeof mainText.refresh === 'function') { mainText.refresh(); } if (typeof shadowText.refresh === 'function') { shadowText.refresh(); }
User prompt
force refresh text2 after every destroyed enemy
User prompt
Move the scoreboard to a very different location
User prompt
Comment out the entire scoreTxt creation (or set scoreTxt.visible = false;).
User prompt
Verify that the scoreTxt has the right children and that updating .text actually changes the displayed number.
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Shape is not defined' in or related to this line: 'var hitbox = new Shape({' Line Number: 440
Code edit (2 edits merged)
Please save this source code
User prompt
do it
User prompt
attach attackcol to player
User prompt
similar to jumpcol, attach attackcol
User prompt
attackcol stays on the ground when player jumps, it should follow
User prompt
attack col doesn't follow the sprite
User prompt
attack col should follow if player is jumping
Code edit (1 edits merged)
Please save this source code
User prompt
Modify spawnEnemy() like this: function spawnEnemy() { var e = new Container(); var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); // Manually define hit area to match the enemy visual e.hitArea = { x: -gfx.width / 2, y: -gfx.height / 2, width: gfx.width, height: gfx.height }; // Random spawn from left or right 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 animation var baseY = e.y; function bounce() { tween(e, { y: baseY - 50 }, { duration: 500, easing: tween.bounceInOut, onFinish: function () { tween(e, { y: baseY }, { duration: 500, easing: tween.bounceInOut, onFinish: bounce }); } }); } bounce(); enemies.push(e); game.addChild(e); } ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a shape to the enemy container to define its bounds
User prompt
give enemys a hitbox
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: scoreTxt.getChildByName is not a function' in or related to this line: 'scoreTxt.getChildByName('main').text = String(score);' Line Number: 37
User prompt
Please fix the bug: 'ReferenceError: updateScoreDisplay is not defined' in or related to this line: 'updateScoreDisplay();' Line Number: 464
User prompt
Please fix the bug: 'ReferenceError: incrementScore is not defined' in or related to this line: 'incrementScore();' Line Number: 461
Code edit (2 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Initialize Game ****/ // Init Game var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ /**** * Score Setup ****/ // 1) Make the score variable var score = 0; // 2) We'll store the score text container here var scoreTxt; // This function updates the visible text (shadow + main) // whenever the score changes: function updateScoreDisplay() { // If no scoreTxt container, do nothing if (!scoreTxt) { return; } // Attempt to find the text objects var mainText = scoreTxt.findChildByName('main'); var shadowText = scoreTxt.findChildByName('shadow'); if (mainText && shadowText) { // Convert current score to string mainText.text = String(score); shadowText.text = String(score); // Optional tween effect (makes the text pulse briefly) tween(scoreTxt, { scaleX: 1.5, scaleY: 1.5 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreTxt, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); } else { console.warn('⚠️ Could not find "main"/"shadow" text in scoreTxt.'); } } // Call this each time you want to add to the score: function incrementScore() { score++; updateScoreDisplay(); } // A helper to build the text container once at startup: function createScoreText(value) { var shadow = new Text2(String(value), { size: 300, fill: 0x000000, fontFamily: "Arial" }); shadow.name = "shadow"; shadow.anchor.set(0.5, 0); shadow.x = 4; shadow.y = 4; var main = new Text2(String(value), { size: 300, fill: 0xFF69B4, fontFamily: "Arial" }); main.name = "main"; main.anchor.set(0.5, 0); // container to hold both texts var container = new Container(); container.name = "scoreTxt"; container.x = 1024; container.y = 50; // add shadow + main text container.addChild(shadow); container.addChild(main); return container; } // Create the score text container once, at the start: scoreTxt = createScoreText(score); scoreTxt.scaleX = 1.0; scoreTxt.scaleY = 1.0; // Play background music LK.playMusic('bgm', { loop: true }); /**** * Add Background ****/ var bg01 = LK.getAsset('bg01', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); game.addChild(bg01); // Add the score text after the background, so it's on top: game.addChild(scoreTxt); // Petals var petals = []; for (var i = 0; i < 50; i++) { var petal = new Container(); var petalSprite = petal.attachAsset('petals', { anchorX: 0.5, anchorY: 0.5, rotation: Math.random() * Math.PI * 2 }); petal.x = Math.random() * 2048; petal.y = Math.random() * 2732; petal.speedY = Math.random() * 2 + 1; petal.speedX = Math.random() * 2 - 1; // The standard update for drifting petals petal.update = function () { this.y += this.speedY; this.x += this.speedX; if (this.y > 2732) { this.y = -50; this.x = Math.random() * 2048; } }; petals.push(petal); game.addChild(petal); } // Player container var player = new Container(); var visualContainer = new Container(); visualContainer.name = 'visual'; // Attach the 'idle' player sprite by default var playerSprite = visualContainer.attachAsset('player_idle', { anchorX: 0.5, anchorY: 0.5 }); player.addChild(visualContainer); // Position the player player.x = 1024; player.y = 2732 - 250; game.addChild(player); /**** * Idle animations (breathing + tilt) ****/ 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 }); } }); } 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 }); } }); } }); } // Start them once at the beginning: startBreathingAnimation(); startTiltAnimation(); // Sequence control var isSequenceRunning = false; var isJumping = false; var playerState = 'idle'; // Attack collider var attackCol = LK.getAsset('attackcol', { anchorX: 0.5, anchorY: 0.5, alpha: 1 }); game.addChild(attackCol); attackCol.visible = false; // hidden until attacking /**** * Swap the player's visual sprite ****/ function swapPlayerVisual(newVisualId, x, y) { var flip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; var onDone = arguments.length > 4 ? arguments[4] : undefined; var visualContainer = player.findChildByName('visual'); if (!visualContainer) { visualContainer = new Container(); visualContainer.name = 'visual'; player.addChild(visualContainer); } else { // remove old sprite visualContainer.removeChildAt(0); } // attach new sprite playerSprite = visualContainer.attachAsset(newVisualId, { anchorX: 0.5, anchorY: 0.5 }); visualContainer.scaleX = flip; // update position player.x = x; player.y = y; // special case: jump includes jump collider if (newVisualId === 'player_jump') { var jumpCol = LK.getAsset('jumpcol', { anchorX: 0.5, anchorY: 0.5, x: x, y: y + player.height / 2, alpha: 1 }); game.addChild(jumpCol); tween(jumpCol, { y: jumpCol.y - 600 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(jumpCol, { y: 2732 - 250 + player.height / 2 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { jumpCol.destroy(); } }); } }); // Ensure attack collider follows player during jump attackCol.y = jumpCol.y; } if (typeof onDone === 'function') { if (newVisualId === 'player_idle') { startBreathingAnimation(); startTiltAnimation(); } onDone(); } } /**** * Main input (touch) logic ****/ game.down = function (x, y) { if (isSequenceRunning) { return; } // Jump if tapped in top 2/3 if (y < 2732 * 2 / 3 && !isJumping) { isJumping = true; LK.getSound('hup').play(); swapPlayerVisual('player_jump', player.x, player.y); // dust particles on jump for (var i = 0; i < 10; i++) { var 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: function onFinish() { p.destroy(); } }); } 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() { // landing dust for (var i = 0; i < 10; i++) { var 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: function onFinish() { p.destroy(); } }); } isJumping = false; swapPlayerVisual('player_idle', 1024, 2732 - 250, 1, function () { startBreathingAnimation(); startTiltAnimation(); }); // small "squash" effect after landing var visual = player.findChildByName('visual'); if (visual) { var direction = visual.scaleX < 0 ? -1 : 1; tween(visual, { scaleX: direction * 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { tween(visual, { scaleX: direction * 1.0, scaleY: 1.0 }, { duration: 100 }); } }); } } }); } }); return; } // Attack if tapped in bottom 1/3 isSequenceRunning = true; var flip = x < 1024 ? -1 : 1; // Attack phase 1 swapPlayerVisual('player_attackf01', 1024, 2732 - 250, flip); LK.getSound('retroslash').play(); // small "stretch" effect var vis = player.findChildByName('visual'); if (vis) { tween(vis, { scaleX: flip * 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { tween(vis, { scaleX: flip * 1.0, scaleY: 1.0 }, { duration: 100 }); } }); } LK.setTimeout(function () { // Attack phase 2 swapPlayerVisual('player_attackf02', 1024, 2732 - 250, flip); // collider attackCol.x = flip === -1 ? 874 : 1174; attackCol.y = 2732 - 250; attackCol.scaleX = flip; attackCol.visible = true; // revert to idle LK.setTimeout(function () { if (attackCol) { attackCol.visible = false; } swapPlayerVisual('player_idle', 1024, 2732 - 250, 1, function () { startBreathingAnimation(); startTiltAnimation(); }); isSequenceRunning = false; playerState = 'idle'; }, 250); }, 250); }; /**** * Enemies array + spawn ****/ var enemies = []; function spawnEnemy() { var e = new Container(); // attach the enemy sprite var gfx = e.attachAsset('enemy01', { anchorX: 0.5, anchorY: 0.5 }); // define its hit area so intersects() works as intended e.hitArea = { x: -gfx.width / 2, y: -gfx.height / 2, width: gfx.width, height: gfx.height }; // spawn from left or right 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); // flip the sprite if from right side gfx.scaleX = fromLeft ? 1 : -1; // simple bounce 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(); enemies.push(e); game.addChild(e); } // spawn enemies on an interval LK.setInterval(spawnEnemy, Math.random() * 1500 + 1000); // Main update loop game.update = function () { for (var i = enemies.length - 1; i >= 0; i--) { var e = enemies[i]; e.x += e.speedX; // remove if offscreen if (e.x < -300 || e.x > 2048 + 300) { var index = enemies.indexOf(e); if (index !== -1) { enemies.splice(index, 1); } e.destroy(); continue; } // check for collisions if (attackCol.visible && e.intersects(attackCol)) { handleEnemyHit(e, i); } } }; /**** * Enemy hit logic ****/ function handleEnemyHit(enemy, index) { // Double-check the array if (!enemies.includes(enemy)) { return; } LK.getSound('slimedeath').play(); // cancel bounce if any if (enemy.bounceTween && typeof enemy.bounceTween.cancel === 'function') { enemy.bounceTween.cancel(); } // Red + slight scale up tween(enemy, { tint: 0xFF0000 }, { duration: 0, onFinish: function onFinish() { tween(enemy, { scaleX: 1.3, scaleY: 1.3 }, { duration: 50, onFinish: function onFinish() { // shrink away + fade tween(enemy, { scaleX: 0.5, scaleY: 0.5, alpha: 0 }, { duration: 100, onFinish: function onFinish() { // remove from array if still present if (enemies.includes(enemy)) { enemies.splice(index, 1); enemy.destroy(); incrementScore(); } } }); } }); } }); } /**** * "findChildByName" helper ****/ Container.prototype.findChildByName = function (name) { for (var i = 0; i < this.children.length; i++) { if (this.children[i].name === name) { return this.children[i]; } } return null; };
===================================================================
--- original.js
+++ change.js
@@ -13,22 +13,56 @@
/****
* Game Code
****/
-function updateScoreDisplay() {
- // Update the score text with the current score
- scoreTxt.findChildByName('main').text = String(score);
- scoreTxt.findChildByName('shadow').text = String(score);
-}
/****
* Score Setup
****/
+// 1) Make the score variable
var score = 0;
-var scoreTxt; // Declare it first
+// 2) We'll store the score text container here
+var scoreTxt;
+// This function updates the visible text (shadow + main)
+// whenever the score changes:
+function updateScoreDisplay() {
+ // If no scoreTxt container, do nothing
+ if (!scoreTxt) {
+ return;
+ }
+ // Attempt to find the text objects
+ var mainText = scoreTxt.findChildByName('main');
+ var shadowText = scoreTxt.findChildByName('shadow');
+ if (mainText && shadowText) {
+ // Convert current score to string
+ mainText.text = String(score);
+ shadowText.text = String(score);
+ // Optional tween effect (makes the text pulse briefly)
+ tween(scoreTxt, {
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(scoreTxt, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
+ }
+ });
+ } else {
+ console.warn('⚠️ Could not find "main"/"shadow" text in scoreTxt.');
+ }
+}
+// Call this each time you want to add to the score:
function incrementScore() {
- score += 1;
+ score++;
updateScoreDisplay();
}
+// A helper to build the text container once at startup:
function createScoreText(value) {
var shadow = new Text2(String(value), {
size: 300,
fill: 0x000000,
@@ -37,40 +71,45 @@
shadow.name = "shadow";
shadow.anchor.set(0.5, 0);
shadow.x = 4;
shadow.y = 4;
- var text = new Text2(String(value), {
+ var main = new Text2(String(value), {
size: 300,
fill: 0xFF69B4,
fontFamily: "Arial"
});
- text.name = "main";
- text.anchor.set(0.5, 0);
+ main.name = "main";
+ main.anchor.set(0.5, 0);
+ // container to hold both texts
var container = new Container();
container.name = "scoreTxt";
container.x = 1024;
container.y = 50;
+ // add shadow + main text
container.addChild(shadow);
- container.addChild(text);
+ container.addChild(main);
return container;
}
-// After defining the function, then create the text object
+// Create the score text container once, at the start:
scoreTxt = createScoreText(score);
scoreTxt.scaleX = 1.0;
scoreTxt.scaleY = 1.0;
-// Assets
+// Play background music
LK.playMusic('bgm', {
loop: true
});
+/****
+* Add Background
+****/
var bg01 = LK.getAsset('bg01', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
game.addChild(bg01);
-game.addChild(scoreTxt); // Add score text on top of background
-// Add to GUI, not to main game layer
+// Add the score text after the background, so it's on top:
+game.addChild(scoreTxt);
// Petals
var petals = [];
for (var i = 0; i < 50; i++) {
var petal = new Container();
@@ -82,8 +121,9 @@
petal.x = Math.random() * 2048;
petal.y = Math.random() * 2732;
petal.speedY = Math.random() * 2 + 1;
petal.speedX = Math.random() * 2 - 1;
+ // The standard update for drifting petals
petal.update = function () {
this.y += this.speedY;
this.x += this.speedX;
if (this.y > 2732) {
@@ -93,20 +133,25 @@
};
petals.push(petal);
game.addChild(petal);
}
-// Player setup
+// Player container
var player = new Container();
-var visualContainer = new Container(); // Inner container
+var visualContainer = new Container();
+visualContainer.name = 'visual';
+// Attach the 'idle' player sprite by default
var playerSprite = visualContainer.attachAsset('player_idle', {
anchorX: 0.5,
anchorY: 0.5
});
-visualContainer.name = 'visual'; // so we can find it later
player.addChild(visualContainer);
+// Position the player
player.x = 1024;
player.y = 2732 - 250;
game.addChild(player);
+/****
+* Idle animations (breathing + tilt)
+****/
function startBreathingAnimation() {
tween(player, {
scaleX: 1.05,
scaleY: 1.05
@@ -149,43 +194,48 @@
});
}
});
}
+// Start them once at the beginning:
startBreathingAnimation();
startTiltAnimation();
+// Sequence control
var isSequenceRunning = false;
var isJumping = false;
var playerState = 'idle';
+// Attack collider
var attackCol = LK.getAsset('attackcol', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1
});
game.addChild(attackCol);
-attackCol.visible = false; // hide initially
+attackCol.visible = false; // hidden until attacking
+/****
+* Swap the player's visual sprite
+****/
function swapPlayerVisual(newVisualId, x, y) {
var flip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var onDone = arguments.length > 4 ? arguments[4] : undefined;
- // Find existing visual container
var visualContainer = player.findChildByName('visual');
- if (visualContainer) {
- // Remove old visual sprite
- visualContainer.removeChildAt(0);
- } else {
- // Create new visual container if it doesn't exist
+ if (!visualContainer) {
visualContainer = new Container();
visualContainer.name = 'visual';
player.addChild(visualContainer);
+ } else {
+ // remove old sprite
+ visualContainer.removeChildAt(0);
}
- // Attach new visual sprite
+ // attach new sprite
playerSprite = visualContainer.attachAsset(newVisualId, {
anchorX: 0.5,
anchorY: 0.5
});
visualContainer.scaleX = flip;
+ // update position
player.x = x;
player.y = y;
- // Special case: jump visual includes a jump collider
+ // special case: jump includes jump collider
if (newVisualId === 'player_jump') {
var jumpCol = LK.getAsset('jumpcol', {
anchorX: 0.5,
anchorY: 0.5,
@@ -205,49 +255,53 @@
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
- return jumpCol.destroy();
+ jumpCol.destroy();
}
});
}
});
+ // Ensure attack collider follows player during jump
+ attackCol.y = jumpCol.y;
}
- if (onDone) {
+ if (typeof onDone === 'function') {
if (newVisualId === 'player_idle') {
startBreathingAnimation();
startTiltAnimation();
}
onDone();
}
}
-// Main input handler
+/****
+* Main input (touch) logic
+****/
game.down = function (x, y) {
if (isSequenceRunning) {
return;
}
- // 🦘 Jump input (upper 2/3 screen)
+ // Jump if tapped in top 2/3
if (y < 2732 * 2 / 3 && !isJumping) {
isJumping = true;
LK.getSound('hup').play();
swapPlayerVisual('player_jump', player.x, player.y);
- // 💨 Create dust particles on jump
+ // dust particles on jump
for (var i = 0; i < 10; i++) {
var p = LK.getAsset('dust', {
anchorX: 0.5,
anchorY: 0.5,
- x: player.x + Math.random() * 100 - 50,
- y: player.y + Math.random() * 100 - 50
+ 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,
+ x: p.x + (Math.random() * 200 - 100),
y: p.y - Math.random() * 200
}, {
duration: 500,
onFinish: function onFinish() {
- return p.destroy();
+ p.destroy();
}
});
}
tween(player, {
@@ -261,38 +315,37 @@
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
- // 💨 Landing dust
+ // landing dust
for (var i = 0; i < 10; i++) {
var p = LK.getAsset('dust', {
anchorX: 0.5,
anchorY: 0.5,
- x: player.x + Math.random() * 100 - 50,
- y: player.y + Math.random() * 100 - 50
+ 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,
+ x: p.x + (Math.random() * 200 - 100),
y: p.y + Math.random() * 200
}, {
duration: 500,
onFinish: function onFinish() {
- return p.destroy();
+ p.destroy();
}
});
}
isJumping = false;
swapPlayerVisual('player_idle', 1024, 2732 - 250, 1, function () {
startBreathingAnimation();
startTiltAnimation();
});
+ // small "squash" effect after landing
var visual = player.findChildByName('visual');
if (visual) {
- // Get current direction (1 or -1)
var direction = visual.scaleX < 0 ? -1 : 1;
- // Apply stretch relative to facing direction
tween(visual, {
scaleX: direction * 1.3,
scaleY: 1.3
}, {
@@ -312,24 +365,24 @@
}
});
return;
}
- // ⚔️ Attack input (bottom 1/3)
+ // Attack if tapped in bottom 1/3
isSequenceRunning = true;
var flip = x < 1024 ? -1 : 1;
- // Phase 1: player_attackf01
+ // Attack phase 1
swapPlayerVisual('player_attackf01', 1024, 2732 - 250, flip);
LK.getSound('retroslash').play();
- // 🌟 Apply stretch
- var visual = player.findChildByName('visual');
- if (visual) {
- tween(visual, {
+ // small "stretch" effect
+ var vis = player.findChildByName('visual');
+ if (vis) {
+ tween(vis, {
scaleX: flip * 1.3,
scaleY: 1.3
}, {
duration: 50,
onFinish: function onFinish() {
- tween(visual, {
+ tween(vis, {
scaleX: flip * 1.0,
scaleY: 1.0
}, {
duration: 100
@@ -337,16 +390,16 @@
}
});
}
LK.setTimeout(function () {
- // Phase 2: player_attackf02
+ // Attack phase 2
swapPlayerVisual('player_attackf02', 1024, 2732 - 250, flip);
- // Create slash collider
+ // collider
attackCol.x = flip === -1 ? 874 : 1174;
attackCol.y = 2732 - 250;
attackCol.scaleX = flip;
attackCol.visible = true;
- // End attack
+ // revert to idle
LK.setTimeout(function () {
if (attackCol) {
attackCol.visible = false;
}
@@ -358,30 +411,34 @@
playerState = 'idle';
}, 250);
}, 250);
};
-// ✅ Enemies array
+/****
+* Enemies array + spawn
+****/
var enemies = [];
function spawnEnemy() {
var e = new Container();
+ // attach the enemy sprite
var gfx = e.attachAsset('enemy01', {
anchorX: 0.5,
anchorY: 0.5
});
- // Manually define hit area to match the enemy visual
+ // define its hit area so intersects() works as intended
e.hitArea = {
x: -gfx.width / 2,
y: -gfx.height / 2,
width: gfx.width,
height: gfx.height
};
- // Random spawn from left or right
+ // spawn from left or right
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);
+ // flip the sprite if from right side
gfx.scaleX = fromLeft ? 1 : -1;
- // Bounce animation
+ // simple bounce
var baseY = e.y;
function bounce() {
tween(e, {
y: baseY - 50
@@ -402,37 +459,44 @@
bounce();
enemies.push(e);
game.addChild(e);
}
-LK.setInterval(spawnEnemy, Math.random() * 1500 + 1000); // Random interval
-// ✅ Game loop
+// spawn enemies on an interval
+LK.setInterval(spawnEnemy, Math.random() * 1500 + 1000);
+// Main update loop
game.update = function () {
for (var i = enemies.length - 1; i >= 0; i--) {
var e = enemies[i];
e.x += e.speedX;
- // Remove if offscreen
+ // remove if offscreen
if (e.x < -300 || e.x > 2048 + 300) {
var index = enemies.indexOf(e);
if (index !== -1) {
enemies.splice(index, 1);
}
e.destroy();
continue;
}
- // Check for attack hit
+ // check for collisions
if (attackCol.visible && e.intersects(attackCol)) {
handleEnemyHit(e, i);
}
}
};
+/****
+* Enemy hit logic
+****/
function handleEnemyHit(enemy, index) {
+ // Double-check the array
if (!enemies.includes(enemy)) {
return;
}
LK.getSound('slimedeath').play();
+ // cancel bounce if any
if (enemy.bounceTween && typeof enemy.bounceTween.cancel === 'function') {
enemy.bounceTween.cancel();
}
+ // Red + slight scale up
tween(enemy, {
tint: 0xFF0000
}, {
duration: 0,
@@ -442,28 +506,32 @@
scaleY: 1.3
}, {
duration: 50,
onFinish: function onFinish() {
+ // shrink away + fade
tween(enemy, {
scaleX: 0.5,
scaleY: 0.5,
alpha: 0
}, {
duration: 100,
onFinish: function onFinish() {
+ // remove from array if still present
if (enemies.includes(enemy)) {
enemies.splice(index, 1);
enemy.destroy();
incrementScore();
- updateScoreDisplay();
}
}
});
}
});
}
});
}
+/****
+* "findChildByName" helper
+****/
Container.prototype.findChildByName = function (name) {
for (var i = 0; i < this.children.length; i++) {
if (this.children[i].name === name) {
return this.children[i];
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
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
picture of a cute enemy slime monster inspired by dragon quest and ragnarok online. In-Game asset. 2d. High contrast. No shadows
picture of a cute fat and large enemy slime monster inspired by dragon quest and ragnarok online. In-Game asset. 2d. High contrast. No shadows
picture of a cute enemy slime monster wearing a shield infront of its face inspired by dragon quest and ragnarok online. In-Game asset. 2d. High contrast. No shadows