Code edit (4 edits merged)
Please save this source code
User prompt
bad papers doesn't less score when go out from screen
User prompt
bad papers must less score
User prompt
fix it
User prompt
papers must be bigger
User prompt
when player click on paper paper must accept
User prompt
papers must increase score
User prompt
guard move follow cursor
User prompt
player move follow cursor
User prompt
guard move with WASD buttons
User prompt
guard must move
User prompt
delete dot
Code edit (1 edits merged)
Please save this source code
User prompt
if player score become in less than 0 game must stop
User prompt
dot doesn't move fix it
User prompt
dot move on WASD buttons
User prompt
dot must move when player click on mouse botton
User prompt
dot must move like mouse
User prompt
the circle must follow for the cursor
User prompt
create a dot which pursues for maus
User prompt
game must stop, when player click on bad paper
User prompt
create a baf papers? accept which game over and their color is red
User prompt
Please fix the bug: 'Uncaught TypeError: paper.containsPoint is not a function' in or related to this line: 'if (paper.containsPoint(localPos)) {' Line Number: 83
Initial prompt
Papers
/**** * 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 = game.addChild(new Guard()); guard.x = 2048 / 2; guard.y = 2732 - 200; // Function to handle paper acceptance function acceptPaper(paper) { paper.destroy(); papers.splice(papers.indexOf(paper), 1); 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); } } // Function to handle paper rejection function rejectPaper(paper) { paper.destroy(); papers.splice(papers.indexOf(paper), 1); score -= 1; scoreTxt.setText(score); } // Function to create a new paper function createPaper() { var newPaper; if (Math.random() < 0.1) { // 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.addChild(newPaper); } // 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 })) { 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) { if (paper instanceof paper) { rejectPaper(paper); } } }); // Stop the game if the score is less than 0 if (score < 0) { LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -130,14 +130,11 @@
// Update all papers
papers.forEach(function (paper) {
paper.y += 5; // Move paper downwards
if (paper.y > 2732) {
- if (paper instanceof BadPaper) {
- score -= 1;
- scoreTxt.setText(score);
- LK.setScore(LK.getScore() - 1);
+ if (paper instanceof paper) {
+ rejectPaper(paper);
}
- rejectPaper(paper); // Reject paper if it goes off screen
}
});
// Stop the game if the score is less than 0
if (score < 0) {