User prompt
over a time of 0.01 sec change the sprites in loop 1 - 5.
User prompt
fix the code of spawning a collactable such that, if the obstacle group is spawned on the lower path then spawn the collactible on the upper path, and vise versa, Make sure the spawn rate and speed is same as the obstacles.
User prompt
Fix the problem with coin spawning logic
User prompt
increase the spawn rate of sprite.
User prompt
Destroy the previous sprite before sapwning next sprite.
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
Loop the ninja sprite in order 1 - 5 over 0.1 sec.
User prompt
Remove the popup code.
User prompt
fix the issue.
User prompt
Now i have five sprites for different poses of the ninja for running, make running animation using those assets.
User prompt
Add the one more text GUI for testing on the bottom centre of the screen.
User prompt
fix the issues.
User prompt
when lives are finished pause the game and show the popup message, at the middle of the screen.
User prompt
Do not game over .
User prompt
Find the cause and fix the issue.
User prompt
no popup is shown when lives are finished.
User prompt
Now whenever player get's out of lives give a popup showing that you can buy three lives using 5000 coins, and show the number of coins collected by the player. and if the player buys live with coin then continue the game, else if the player doesn't have coin to buy then show 3 sec time on the popup and then game over.
User prompt
display the collected coins on the screen.
User prompt
Now add an event in coins that checks the intersection of ninja with coin, and whenever ninja intersect with coin ( single coin ) increase the value of coin in player inventory by 1.
Code edit (1 edits merged)
Please save this source code
User prompt
increase the space between the coins.
User prompt
E Now there are three type of collactibles, add a logic for below specifications: - Coins ( which are spawned in the cluster of more that one coin - cluster size [ 5, 7, 9, 10, 12, 14] ) - Spawn probabilty 95% - Sheild ( Which is spawned single ) - Spawn probability 4 % - Life ( Which is spawned single ) - Spawn Probabiltiy 1 %
User prompt
add a code to spawn a collactable such that, if the obstacle group is spawned on the lower path then spawn the collactible on the upper path, and vise versa, Make sure the spawn rate and speed is same as the obstacles.
User prompt
add a code to spawn a collactable such that, if the obstacle group is spawned on the lower path then spawn the collactible on the upper path, and vise versa
User prompt
Write the code in optimal way.
/****
* 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 -= 5;
if (self.x < -self.width) {
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', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
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) {
LK.showGameOver();
}
// 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
****/
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 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
var coinTxt = new Text2('Coins: 0', {
resolution: 2,
size: 100,
fill: "#ffffff",
font: "lexend"
});
coinTxt.anchor.set(1, 0); // Set anchor to the top right corner
coinTxt.x = 2048 - 20; // Position on the right side of the screen with a small margin
coinTxt.y = 0; // Position at the top of the screen with a small margin
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) {
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