Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
take score to foreground
User prompt
Move paper creation to the foreground but lower than guard
User prompt
Move guard to the foreground Move paper creation to the background
User prompt
take guard in foreground
User prompt
take papers to foreground
User prompt
add image to background
Code edit (1 edits merged)
Please save this source code
User prompt
all game objects must be in foreground
User prompt
take background to background
User prompt
background must be object
User prompt
create background with white color
Code edit (3 edits merged)
Please save this source code
User prompt
when player click on complected papers score mustn't increase
User prompt
Please fix the bug: 'Uncaught TypeError: LK.setColor is not a function' in or related to this line: 'LK.setColor(paper, 'green');' Line Number: 102
User prompt
Please fix the bug: 'Uncaught TypeError: LK.setColot is not a function' in or related to this line: 'LK.setColot(paper, 'green');' Line Number: 102
User prompt
create disappearing effect for complected papers
Code edit (1 edits merged)
Please save this source code
User prompt
when player accept paper change paper's asset to another and destroy it after 1 second disappearing
User prompt
instead destroy change paper to complected paper when player accept paper
User prompt
don't destroy paper after accept
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Define the BadPaper class var BadPaper = Container.expand(function () { var self = Container.call(this); var paperGraphics = self.attachAsset('badPaper', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.update = function () { // BadPaper specific update logic }; self.containsPoint = function (point) { return point.x >= self.x && point.x <= self.x + self.width && point.y >= self.y && point.y <= self.y + self.height; }; }); // Define the Guard class var Guard = Container.expand(function () { var self = Container.call(this); var guardGraphics = self.attachAsset('guard', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Guard specific update logic }; }); //<Assets used in the game will automatically appear here> // Define the Paper class var Paper = Container.expand(function () { var self = Container.call(this); var paperGraphics = self.attachAsset('paper', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.update = function () { // Paper specific update logic }; self.containsPoint = function (point) { return point.x >= self.x && point.x <= self.x + self.width && point.y >= self.y && point.y <= self.y + self.height; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var papers = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create the guard and position it var guard = new Guard(); guard.x = 2048 / 2; guard.y = 2732 - 200; game.addChild(guard); // Function to handle paper acceptance function acceptPaper(paper) { if (paper instanceof complectedPaper) { return; } else { paperGraphics = paper.attachAsset('completedPaper', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); LK.setTimeout(function () { paper.destroy(); papers.splice(papers.indexOf(paper), 1); }, 500); if (paper instanceof BadPaper) { score -= 1; scoreTxt.setText(score); LK.setScore(LK.getScore() - 1); } else { score += 1; scoreTxt.setText(score); LK.setScore(LK.getScore() + 1); paperGraphics = paper.attachAsset('completedPaper', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); } } } // Function to handle paper rejection function rejectPaper(paper) { paper.destroy(); papers.splice(papers.indexOf(paper), 1); if (paper instanceof BadPaper == true) { score += 1; } score -= 1; scoreTxt.setText(score); } // Function to create a new paper function createPaper() { var newPaper; if (Math.random() < 0.3) { // 10% chance to create a bad paper newPaper = new BadPaper(); } else { newPaper = new Paper(); } newPaper.x = Math.random() * 2048; newPaper.y = 0; papers.push(newPaper); game.addChildAt(newPaper, 0); } // Event listener for moving the guard game.move = function (x, y, obj) { guard.x = x; guard.y = y; }; // Event listener for rejecting papers game.down = function (x, y, obj) { var localPos = game.toLocal(obj.global); papers.forEach(function (paper) { if (paper.containsPoint({ x: localPos.x, y: localPos.y })) { if (paper instanceof BadPaper) { LK.showGameOver(); } else { acceptPaper(paper); } } }); }; // Update function to handle game logic game.update = function () { // Create a new paper every 60 ticks if (LK.ticks % 60 == 0) { createPaper(); } // Update all papers papers.forEach(function (paper) { paper.y += 5; // Move paper downwards if (paper.y > 2732) { rejectPaper(paper); // Reject paper if it goes off screen } }); // Stop the game if the score is less than 0 if (score < 0) { LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -71,32 +71,36 @@
guard.y = 2732 - 200;
game.addChild(guard);
// Function to handle paper acceptance
function acceptPaper(paper) {
- paperGraphics = paper.attachAsset('completedPaper', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2,
- scaleY: 2
- });
- LK.setTimeout(function () {
- paper.destroy();
- papers.splice(papers.indexOf(paper), 1);
- }, 500);
- if (paper instanceof BadPaper) {
- score -= 1;
- scoreTxt.setText(score);
- LK.setScore(LK.getScore() - 1);
+ if (paper instanceof complectedPaper) {
+ return;
} else {
- score += 1;
- scoreTxt.setText(score);
- LK.setScore(LK.getScore() + 1);
paperGraphics = paper.attachAsset('completedPaper', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
+ LK.setTimeout(function () {
+ paper.destroy();
+ papers.splice(papers.indexOf(paper), 1);
+ }, 500);
+ if (paper instanceof BadPaper) {
+ score -= 1;
+ scoreTxt.setText(score);
+ LK.setScore(LK.getScore() - 1);
+ } else {
+ score += 1;
+ scoreTxt.setText(score);
+ LK.setScore(LK.getScore() + 1);
+ paperGraphics = paper.attachAsset('completedPaper', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 2
+ });
+ }
}
}
// Function to handle paper rejection
function rejectPaper(paper) {
@@ -136,9 +140,9 @@
y: localPos.y
})) {
if (paper instanceof BadPaper) {
LK.showGameOver();
- } else if (!(paperGraphics.assetId === 'completedPaper')) {
+ } else {
acceptPaper(paper);
}
}
});