/****
* 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
});
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
});
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) {
LK.showGameOver();
} else {
score += 1;
scoreTxt.setText(score);
}
}
// 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 accepting papers
game.down = function (x, y, obj) {
var localPos = game.toLocal(obj.global);
papers.forEach(function (paper) {
if (paper.containsPoint(localPos)) {
acceptPaper(paper);
}
});
};
// Event listener for rejecting papers
game.up = function (x, y, obj) {
var localPos = game.toLocal(obj.global);
papers.forEach(function (paper) {
if (paper.containsPoint(localPos)) {
rejectPaper(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
}
});
}; ===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,21 @@
/****
* 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
+ });
+ 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', {
@@ -54,10 +68,14 @@
// Function to handle paper acceptance
function acceptPaper(paper) {
paper.destroy();
papers.splice(papers.indexOf(paper), 1);
- score += 1;
- scoreTxt.setText(score);
+ if (paper instanceof BadPaper) {
+ LK.showGameOver();
+ } else {
+ score += 1;
+ scoreTxt.setText(score);
+ }
}
// Function to handle paper rejection
function rejectPaper(paper) {
paper.destroy();
@@ -66,9 +84,15 @@
scoreTxt.setText(score);
}
// Function to create a new paper
function createPaper() {
- var newPaper = new Paper();
+ 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);