User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'then')' in or related to this line: 'LK.getSound('backgroundMusic').play({' Line Number: 366
User prompt
can you fix the issue with background music.
User prompt
still can not here the background music.
User prompt
Still not working.
User prompt
Play background music from the game start
User prompt
i can't here again, fix the issue with background music loop.
User prompt
Find the error and fix the background music.
User prompt
Add a background music
User prompt
move the dash near to the legs of the ninja
User prompt
Sprites of ninja should always spawned on top in terms of visibility
User prompt
Reduce more
User prompt
reduce the overall opacity of dash to 0.5
User prompt
move dash 4px forward
User prompt
move dash 1px forward
User prompt
move dash slightly forward.
User prompt
Move the dash little bit forward.
User prompt
collectible lives are moving slow than the other collectibles
User prompt
Remove the transition effect.
User prompt
make it linear
User prompt
i want cubic now.
User prompt
instead of fade in use ease in out
User prompt
transition between sprites should smooth.
User prompt
Please fix the bug: 'TypeError: ninjaGraphics.setTexture is not a function' in or related to this line: 'ninjaGraphics.setTexture(self.runFrames[self.currentFrame]);' Line Number: 129
User prompt
Fix the issue.
User prompt
Over a time of 0.05 sec loop through the sprites one after other in a sequence 1 - 5, continuously.
/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
backgroundGraphics.alpha = 0.5;
var zoomDirection = 1;
self.update = function () {
if (this.scale.x >= 1.0025) {
zoomDirection = -1;
} else if (this.scale.x <= 0.9975) {
zoomDirection = 1;
}
this.scale.x += 0.000025 * zoomDirection;
this.scale.y += 0.000025 * zoomDirection;
};
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 30;
if (self.x < -self.width) {
self.destroy();
}
// Check for intersection with ninja
if (self.intersects(ninja)) {
coinCounter++;
coinTxt.setText('Coins: ' + coinCounter); // Update the coin display text
self.destroy();
}
};
});
var Dash = Container.expand(function () {
var self = Container.call(this);
var dashGraphics = self.attachAsset('dash', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.opacity = 0.4;
self.update = function () {
self.x -= self.speed;
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var DisplayLife = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('life', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x -= self.speed;
self.x += Math.sin(LK.ticks / 10) * 2.5;
if (self.x < -self.width) {
self.destroy();
}
};
});
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('life', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 5;
if (self.x < -self.width) {
self.destroy();
}
};
});
var Ninja = Container.expand(function () {
var self = Container.call(this);
var ninjaGraphics = self.attachAsset('ninja_run1', {
anchorX: 0.5,
anchorY: 0.5
});
self.runFrames = ['ninja_run1', 'ninja_run2', 'ninja_run3', 'ninja_run4', 'ninja_run5'];
self.currentFrame = 0;
self.frameInterval = 3; // Change frame every 3 ticks
self.ticks = 0;
self.speed = 5;
self.update = function () {
self.ticks++;
if (self.ticks % self.frameInterval === 0) {
self.currentFrame = (self.currentFrame + 1) % self.runFrames.length;
ninjaGraphics.setTexture(self.runFrames[self.currentFrame]);
}
if (self.currentPath === 'lower' && self.y >= path2.y - self.height && !self.dashActive) {
var dash = new Dash();
dash.x = self.x - self.width / 2;
dash.y = self.y;
game.addChildAt(dash, game.getChildIndex(ninja));
self.dashActive = true;
LK.setTimeout(function () {
dash.destroy();
self.dashActive = false;
}, 100);
} else if (self.currentPath === 'upper' && self.y <= path1.y - self.height && !self.dashActive) {
var dash = new Dash();
dash.x = self.x - self.width / 2;
dash.y = self.y;
game.addChildAt(dash, game.getChildIndex(ninja));
self.dashActive = true;
LK.setTimeout(function () {
dash.destroy();
self.dashActive = false;
}, 50);
}
if (self.currentPath === 'upper' && self.y > path1.y - self.height - 50) {
self.y -= 10;
if (self.y <= path1.y - self.height - 50) {
self.y = path1.y - self.height - 50;
}
} else if (self.currentPath === 'lower' && self.y < path2.y - self.height + 50) {
self.y += 10;
if (self.y >= path2.y - self.height + 50) {
self.y = path2.y - self.height + 50;
}
}
scoreTxt.setText(ninja.distanceTraveled + 'm'); // Update the score display
for (var i = coins.length - 1; i >= 0; i--) {
if (self.intersects(coins[i])) {
coinCounter++;
scoreMultiplier = 2;
LK.setTimeout(function () {
scoreMultiplier = 1;
}, 5000);
coins[i].destroy();
coins.splice(i, 1);
i--;
coinTxt.setText('Coins: ' + coinCounter); // Update the coin display text
}
}
for (var i = lives.length - 1; i >= 0; i--) {
if (self.intersects(lives[i])) {
self.lives++;
lives[i].destroy();
lives.splice(i, 1);
i--;
// Update the display lives
var life = game.addChild(new DisplayLife());
life.x = 100 + (self.lives - 1) * 100;
life.y = path1.y - 150;
game.setChildIndex(life, game.children.length - 1);
}
}
for (var i = shields.length - 1; i >= 0; i--) {
if (self.intersects(shields[i])) {
self.invincible = true;
ninjaGraphics.tint = 0x0000ff; // Change tint to blue
// Add shield icon and timer display
if (!self.shieldIcon) {
self.shieldIcon = new Text2('10s', {
size: 100,
fill: "#ffffff"
});
self.shieldIcon.anchor.set(0.5, 0.5);
self.shieldIcon.x = 100;
self.shieldIcon.y = 2732 / 2;
LK.gui.left.addChild(self.shieldIcon);
}
var shieldTimeLeft = 10;
self.shieldInterval = LK.setInterval(function () {
shieldTimeLeft--;
self.shieldIcon.setText(shieldTimeLeft + 's');
if (shieldTimeLeft <= 0) {
LK.clearInterval(self.shieldInterval);
self.shieldIcon.destroy();
self.shieldIcon = null;
}
}, 1000);
if (self.shieldTimeout) {
LK.clearTimeout(self.shieldTimeout);
}
self.shieldTimeout = LK.setTimeout(function () {
self.invincible = false;
ninjaGraphics.tint = 0xffffff; // Reset tint to white
self.shieldTimeout = null;
if (self.shieldIcon) {
self.shieldIcon.destroy();
self.shieldIcon = null;
}
LK.clearInterval(self.shieldInterval);
}, 10000);
shields[i].destroy();
shields.splice(i, 1);
i--;
}
}
for (var i = 0; i < game.children.length; i++) {
if (game.children[i] instanceof Obstacle && self.intersects(game.children[i])) {
if (self.invincible) {
// Destroy the obstacle and show destruction effect
LK.effects.flashObject(game.children[i], 0xff0000, 500); // Flash red before destroying
game.children[i].destroy();
continue; // Skip the rest of the loop for this obstacle
}
// Reduce the lives by one
self.lives--;
// Update the display
updateDisplayLives();
// If no lives left, game over
if (self.lives === 0) {
// Handle game over logic here if needed
}
// Make ninja invincible for 3 seconds if not already invincible
if (!self.invincible) {
self.invincible = true;
ninjaGraphics.alpha = 1;
var opacityDirection = -1;
var _opacityChange = function opacityChange() {
ninjaGraphics.alpha += 0.18 * opacityDirection;
if (ninjaGraphics.alpha <= 0.1) {
opacityDirection = 1;
} else if (ninjaGraphics.alpha >= 1) {
opacityDirection = -1;
}
if (self.invincible) {
LK.setTimeout(_opacityChange, 60);
} else {
ninjaGraphics.alpha = 1;
}
};
LK.setTimeout(_opacityChange, 60);
LK.setTimeout(function () {
self.invincible = false;
ninjaGraphics.alpha = 1; // Reset opacity to 1 when invincibility ends
}, 3000);
if (self.shieldTimeout) {
LK.clearTimeout(self.shieldTimeout);
self.shieldTimeout = null;
}
}
}
}
};
self.down = function () {
if (self.currentPath === 'lower') {
targetPath = 'upper';
self.y -= 20;
self.x += 10;
} else {
targetPath = 'lower';
self.y += 20;
self.x -= 10;
}
};
self.up = function () {
targetPath = null;
};
});
var NinjaStar = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('ninjaStar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y += self.speed;
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 30;
self.update = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.destroy();
}
};
});
var Path = Container.expand(function () {
var self = Container.call(this);
var pathGraphics = self.attachAsset('path', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 30;
self.update = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.destroy();
}
};
});
var Shield = Container.expand(function () {
var self = Container.call(this);
var shieldGraphics = self.attachAsset('shield', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 30;
if (self.x < -self.width) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Display a test text at the bottom center of the screen
var testTxt = new Text2('Test Text', {
resolution: 2,
size: 100,
fill: "#ffffff",
font: "lexend"
});
testTxt.anchor.set(0.5, 1);
testTxt.x = 2048 / 2;
testTxt.y = 2732 - 50; // Position 50 pixels from the bottom
LK.gui.bottom.addChild(testTxt);
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var _n = 0,
F = function F() {};
return {
s: F,
n: function n() {
return _n >= r.length ? {
done: !0
} : {
done: !1,
value: r[_n++]
};
},
e: function e(r) {
throw r;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o,
a = !0,
u = !1;
return {
s: function s() {
t = t.call(r);
},
n: function n() {
var r = t.next();
return a = r.done, r;
},
e: function e(r) {
u = !0, o = r;
},
f: function f() {
try {
a || null == t["return"] || t["return"]();
} finally {
if (u) {
throw o;
}
}
}
};
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) {
return _arrayLikeToArray(r, a);
}
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) {
n[e] = r[e];
}
return n;
}
// Game Variables
var coins = [];
var lives = [];
var shields = [];
var coinCounter = 0;
var popupShown = false; // Track if the popup is already shown
var coinCounter = 0;
var coinTxt;
var coinTxt;
var scoreMultiplier = 1;
var invincible = false;
var lastSpawnedPath = 1; // Track the last path an obstacle was spawned on
var background = game.addChild(new Background());
var path1 = game.addChild(new Path());
path1.y = 2732 / 3;
var path2 = game.addChild(new Path());
path2.y = 2732 * 2 / 3;
var ninja = game.addChild(new Ninja());
ninja.x = 1024;
ninja.y = path2.y - ninja.height;
ninja.currentPath = 'lower';
ninja.lives = 3;
ninja.distanceTraveled = 0; // Initialize distance traveled to 0
var targetPath;
// Display the lives a little bit more up in y axis from the upper path
function updateDisplayLives() {
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof DisplayLife) {
game.children[i].destroy();
}
}
for (var i = 0; i < ninja.lives; i++) {
var life = game.addChild(new DisplayLife());
life.x = 100 + i * 100; // Move the lives little bit right on x axis
life.y = path1.y - 150; // Move lives a little bit more up
game.setChildIndex(life, game.children.length - 1);
}
}
updateDisplayLives();
// Display the score based on the distance traveled
var scoreTxt = new Text2('0m', {
resolution: 2,
size: 100,
fill: "#ffffff",
font: "lexend"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = path1.y - 450; // Move the score display a little bit more up, above the upper path
LK.gui.top.addChild(scoreTxt);
// Display the coin count on the same y location as the score, but on the right
coinTxt = new Text2('Coins: 0', {
resolution: 2,
size: 100,
fill: "#ffffff",
font: "lexend"
});
coinTxt.anchor.set(1, 0);
coinTxt.x = 2048 - 20;
coinTxt.y = path1.y - 450; // Align the coin text with the score text
LK.gui.top.addChild(coinTxt);
game.down = function (x, y, obj) {
if (ninja.currentPath === 'lower' && ninja.y >= path2.y - ninja.height || ninja.currentPath === 'upper' && ninja.y <= path1.y - ninja.height) {
if (ninja.currentPath === 'lower') {
targetPath = 'upper';
ninja.y -= 500; // Increase the jump speed
ninja.scale.y *= -1; // Flip vertically
// No code to insert, we are removing the timeout that destroys the dash
} else {
targetPath = 'lower';
ninja.y += 500; // Increase the jump speed
ninja.scale.y *= -1; // Flip vertically
// No code to insert, we are removing the timeout that destroys the dash
}
ninja.currentPath = targetPath;
}
};
game.update = function () {
var lastPath = 0;
if (LK.ticks % 50 == 0) {
// Determine collectible type based on probabilities
var collectibleType;
var randomValue = Math.random() * 100;
if (randomValue < 95) {
collectibleType = 'coin';
} else if (randomValue < 99) {
collectibleType = 'shield';
} else {
collectibleType = 'life';
}
// Spawn collectible on the opposite path of the last obstacle
var collectiblePath = lastSpawnedPath === 1 ? 0 : 1;
if (collectibleType === 'coin') {
var clusterSizes = [5, 7, 9, 10];
var clusterSize = clusterSizes[Math.floor(Math.random() * clusterSizes.length)];
for (var i = 0; i < clusterSize; i++) {
var newCoin = new Coin();
newCoin.x = 2048 + i * (newCoin.width + 30); // Increase spacing between coins
newCoin.y = collectiblePath === 1 ? 2732 / 3 + 80 : 2732 * 2 / 3 - 80;
game.addChild(newCoin);
}
} else if (collectibleType === 'shield') {
var newShield = new Shield();
newShield.x = 2048;
newShield.y = collectiblePath === 1 ? 2732 / 3 + 80 : 2732 * 2 / 3 - 80;
game.addChild(newShield);
} else if (collectibleType === 'life') {
var newLife = new Life();
newLife.x = 2048;
newLife.y = collectiblePath === 1 ? 2732 / 3 + 80 : 2732 * 2 / 3 - 80;
game.addChild(newLife);
}
var randomPath = Math.random() > 0.5 ? 1 : 2;
var spawnDistance = randomPath === lastPath ? 512 : 4096;
var obstacleGroupSize = Math.floor(Math.random() * 3) + 1;
for (var i = 0; i < obstacleGroupSize; i++) {
var newObstacle = new Obstacle();
newObstacle.x = spawnDistance + i * newObstacle.width;
if (randomPath === 1) {
newObstacle.y = 2732 / 3 + 80;
newObstacle.rotation = Math.PI; // Rotate 180 degrees
lastSpawnedPath = 1;
} else {
newObstacle.y = 2732 * 2 / 3 - 80;
newObstacle.rotation = 0; // No rotation
lastSpawnedPath = 0;
}
game.addChildAt(newObstacle, game.children.length);
}
lastPath = randomPath;
}
if (LK.ticks % 20 == 0) {
var newPath1 = new Path();
newPath1.x = 2048 + 100; // Increase the x-coordinate by 100 to create a gap
newPath1.y = 2732 / 3;
game.addChild(newPath1);
var newPath2 = new Path();
newPath2.x = 2048 + 100; // Increase the x-coordinate by 100 to create a gap
newPath2.y = 2732 * 2 / 3;
game.addChild(newPath2);
ninja.distanceTraveled += 100; // Increase distance traveled by 100 meters for each new path
}
};
Ninja Star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A minimalist icon depicting a ninja head silhouette in black. The silhouette should be simple and recognizable, with a headband or mask detail. The background should be transparent or a contrasting color (e.g., red or white).. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Shield. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Transparent sheild bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a series of curved, tapered lines that originate from the ninja's body and extend outward in the direction of movement. The lines should vary in length and thickness, with a sense of energy and dynamism.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
backgroundMusic
Sound effect
coinCollect
Sound effect
jumpSound
Sound effect
footstepSound1
Sound effect
footstepSound2
Sound effect
footstepSound3
Sound effect
shooterSpawn
Sound effect
destructorSpawn
Sound effect
attackerSpawn
Sound effect
shooterAttack
Sound effect
destructorAttack
Sound effect
attackerAttack
Sound effect
enemyHit
Sound effect
shieldCollect
Sound effect
shieldCollectSound
Sound effect
ninjaGrunt
Sound effect
destructorAttackSound
Sound effect