/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Class for a single puzzle piece var PuzzlePiece = Container.expand(function () { var self = Container.call(this); // Attach a smooth curve asset var pieceGraphics = self.attachAsset('smoothCurve', { anchorX: 0.5, anchorY: 0.5 }); // Method to rotate the piece self.rotate = function () { pieceGraphics.rotation += Math.PI / 2; // Rotate 90 degrees }; // Check if the piece is correctly aligned self.isAligned = function () { // Logic to determine if the piece is aligned correctly return pieceGraphics.rotation % (2 * Math.PI) === 0; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xE0F7FA // Init game with a soothing pastel blue background }); /**** * Game Code ****/ // Array to hold all puzzle pieces var puzzlePieces = []; // Function to initialize the puzzle function initPuzzle() { var numPieces = 5; // Number of pieces in the loop var centerX = 2048 / 2; var centerY = 2732 / 2; var radius = 300; // Radius of the loop for (var i = 0; i < numPieces; i++) { var angle = i / numPieces * 2 * Math.PI; var piece = new PuzzlePiece(); piece.x = centerX + radius * Math.cos(angle); piece.y = centerY + radius * Math.sin(angle); piece.rotation = angle; puzzlePieces.push(piece); game.addChild(piece); } } // Initialize the puzzle initPuzzle(); // Event listener for rotating pieces game.down = function (x, y, obj) { var localPos = game.toLocal(obj.global); puzzlePieces.forEach(function (piece) { if (piece.getBounds().contains(localPos.x, localPos.y)) { piece.rotate(); } }); }; // Update function to check if the puzzle is solved game.update = function () { var allAligned = puzzlePieces.every(function (piece) { return piece.isAligned(); }); if (allAligned) { // Flash screen green for 1 second to indicate success LK.effects.flashScreen(0x00FF00, 1000); } };
===================================================================
--- original.js
+++ change.js
@@ -1,72 +1,72 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
// Class for a single puzzle piece
var PuzzlePiece = Container.expand(function () {
- var self = Container.call(this);
- // Attach a smooth curve asset
- var pieceGraphics = self.attachAsset('smoothCurve', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Method to rotate the piece
- self.rotate = function () {
- pieceGraphics.rotation += Math.PI / 2; // Rotate 90 degrees
- };
- // Check if the piece is correctly aligned
- self.isAligned = function () {
- // Logic to determine if the piece is aligned correctly
- return pieceGraphics.rotation % (2 * Math.PI) === 0;
- };
+ var self = Container.call(this);
+ // Attach a smooth curve asset
+ var pieceGraphics = self.attachAsset('smoothCurve', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Method to rotate the piece
+ self.rotate = function () {
+ pieceGraphics.rotation += Math.PI / 2; // Rotate 90 degrees
+ };
+ // Check if the piece is correctly aligned
+ self.isAligned = function () {
+ // Logic to determine if the piece is aligned correctly
+ return pieceGraphics.rotation % (2 * Math.PI) === 0;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0xE0F7FA // Init game with a soothing pastel blue background
+ backgroundColor: 0xE0F7FA // Init game with a soothing pastel blue background
});
-/****
+/****
* Game Code
-****/
+****/
// Array to hold all puzzle pieces
var puzzlePieces = [];
// Function to initialize the puzzle
function initPuzzle() {
- var numPieces = 5; // Number of pieces in the loop
- var centerX = 2048 / 2;
- var centerY = 2732 / 2;
- var radius = 300; // Radius of the loop
- for (var i = 0; i < numPieces; i++) {
- var angle = i / numPieces * 2 * Math.PI;
- var piece = new PuzzlePiece();
- piece.x = centerX + radius * Math.cos(angle);
- piece.y = centerY + radius * Math.sin(angle);
- piece.rotation = angle;
- puzzlePieces.push(piece);
- game.addChild(piece);
- }
+ var numPieces = 5; // Number of pieces in the loop
+ var centerX = 2048 / 2;
+ var centerY = 2732 / 2;
+ var radius = 300; // Radius of the loop
+ for (var i = 0; i < numPieces; i++) {
+ var angle = i / numPieces * 2 * Math.PI;
+ var piece = new PuzzlePiece();
+ piece.x = centerX + radius * Math.cos(angle);
+ piece.y = centerY + radius * Math.sin(angle);
+ piece.rotation = angle;
+ puzzlePieces.push(piece);
+ game.addChild(piece);
+ }
}
// Initialize the puzzle
initPuzzle();
// Event listener for rotating pieces
game.down = function (x, y, obj) {
- var localPos = game.toLocal(obj.global);
- puzzlePieces.forEach(function (piece) {
- if (piece.containsPoint(localPos)) {
- piece.rotate();
- }
- });
+ var localPos = game.toLocal(obj.global);
+ puzzlePieces.forEach(function (piece) {
+ if (piece.getBounds().contains(localPos.x, localPos.y)) {
+ piece.rotate();
+ }
+ });
};
// Update function to check if the puzzle is solved
game.update = function () {
- var allAligned = puzzlePieces.every(function (piece) {
- return piece.isAligned();
- });
- if (allAligned) {
- // Flash screen green for 1 second to indicate success
- LK.effects.flashScreen(0x00FF00, 1000);
- }
+ var allAligned = puzzlePieces.every(function (piece) {
+ return piece.isAligned();
+ });
+ if (allAligned) {
+ // Flash screen green for 1 second to indicate success
+ LK.effects.flashScreen(0x00FF00, 1000);
+ }
};
\ No newline at end of file