/**** * 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(); /**** * Game Code ****/ var background = game.addChildAt(LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0 }), 0); background.zIndex = -1; // 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) { 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 += 3; } score -= 3; 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, 1); } // 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 % 30 == 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(); } };
/****
* 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();
/****
* Game Code
****/
var background = game.addChildAt(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0
}), 0);
background.zIndex = -1;
// 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) {
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 += 3;
}
score -= 3;
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, 1);
}
// 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 % 30 == 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();
}
};