/**** * Classes ****/ // SplitSquare: A square that can be split into two, then each half can be split again var SplitSquare = Container.expand(function () { var self = Container.call(this); // State: 0 = whole, 1 = split in 2, 2 = split in 4 self.splitState = 0; // Store child pieces for later reference self.pieces = []; // Add the initial whole square var whole = self.attachAsset('splitSquare1', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); self.pieces.push(whole); // Helper to clear all pieces self.clearPieces = function () { for (var i = 0; i < self.pieces.length; i++) { if (self.pieces[i] && self.pieces[i].parent) { self.pieces[i].parent.removeChild(self.pieces[i]); } } self.pieces = []; }; // Split into 2 pieces (horizontal split, üstlü altlı) self.splitInTwo = function () { self.clearPieces(); // Use the actual height of the splitSquare2 asset for perfect alignment var pieceH = LK.getAsset('splitSquare2', { anchorX: 0.5, anchorY: 0.5 }).height; var top = self.attachAsset('splitSquare2', { anchorX: 0.5, // center horizontally anchorY: 1, // bottom edge x: 0, y: 0 }); var bottom = self.attachAsset('splitSquare2', { anchorX: 0.5, // center horizontally anchorY: 0, // top edge x: 0, y: 0 }); self.pieces.push(top, bottom); self.splitState = 1; }; // Split into 4 pieces (each half split horizontally) self.splitInFour = function () { self.clearPieces(); // Use the actual width/height of the splitSquare3/4 assets for perfect alignment var pieceW = LK.getAsset('splitSquare3', { anchorX: 0.5, anchorY: 0.5 }).width; var pieceH = LK.getAsset('splitSquare3', { anchorX: 0.5, anchorY: 0.5 }).height; // Add a small margin between pieces var margin = 24; // Top-left var tl = self.attachAsset('splitSquare3', { anchorX: 1, anchorY: 1, x: -margin / 2, y: -margin / 2 }); // Bottom-left var bl = self.attachAsset('splitSquare4', { anchorX: 1, anchorY: 0, x: -margin / 2, y: margin / 2 }); // Top-right var tr = self.attachAsset('splitSquare3', { anchorX: 0, anchorY: 1, x: margin / 2, y: -margin / 2 }); // Bottom-right var br = self.attachAsset('splitSquare4', { anchorX: 0, anchorY: 0, x: margin / 2, y: margin / 2 }); self.pieces.push(tl, bl, tr, br); self.splitState = 2; }; // Handle click/tap to split self.down = function (x, y, obj) { if (self.splitState === 0) { self.splitInTwo(); } else if (self.splitState === 1) { self.splitInFour(); } }; return self; }); /**** * Initialize Game ****/ // Add a SplitSquare to the center of the game var game = new LK.Game({ backgroundColor: 0xffffff }); /**** * Game Code ****/ // Dilim sayısı state var sliceCount = 1; // Add 'Replay' button to the top right, small size var restartButton = new Text2('Replay', { size: 60, fill: 0x8e24aa, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); restartButton.anchor.set(1, 0); // right edge, top edge restartButton.x = 0; // will be positioned by gui.topRight restartButton.y = 0; LK.gui.topRight.addChild(restartButton); restartButton.down = function () { // Reset game state splitSquare.splitState = 0; splitSquare.clearPieces(); var whole = splitSquare.attachAsset('splitSquare1', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); splitSquare.pieces.push(whole); sliceCount = 1; updateSliceCountText(); }; // Add label above slice count to show Tam/Yarım/Çeyrek var sliceLabelText = new Text2('Tam', { size: 140, fill: 0x8e24aa, // mor renk font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); sliceLabelText.anchor.set(0.5, 1); // center horizontally, bottom edge sliceLabelText.y = -180; // move label further down LK.gui.bottom.addChild(sliceLabelText); // Add 'Dilim Sayısı' text at the bottom center var sliceCountText = new Text2('Dilim Sayısı: 1', { size: 100, fill: 0xD83318, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); sliceCountText.anchor.set(0.5, 1); // center horizontally, bottom edge sliceCountText.y = -40; // move slice count further down LK.gui.bottom.addChild(sliceCountText); // Helper to update slice count text function updateSliceCountText() { sliceCountText.setText('Dilim Sayısı: ' + sliceCount); if (sliceCount === 1) { sliceLabelText.setText('Tam'); } else if (sliceCount === 2) { sliceLabelText.setText('Yarım'); } else if (sliceCount === 4) { sliceLabelText.setText('Çeyrek'); } } // Title var titleText = new Text2('Pasta Bölmece', { size: 120, fill: 0xD83318, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); titleText.anchor.set(0.5, 0); // center horizontally, top edge // Place title below the top bar, leaving 40px margin from the top (and not in the top left 100x100) titleText.y = 40; LK.gui.top.addChild(titleText); // Add a SplitSquare to the center of the game var splitSquare = new SplitSquare(); splitSquare.x = 2048 / 2; splitSquare.y = 2732 / 2; game.addChild(splitSquare); // Add 'Pastayı Böl' text below the cake, bigger and further down var splitLabel = new Text2('Pastayı Böl', { size: 90, fill: 0xD83318, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); splitLabel.anchor.set(0.5, 0); // Position further below the splitSquare (using its height) var cakeAsset = LK.getAsset('splitSquare1', { anchorX: 0.5, anchorY: 0.5 }); splitLabel.x = splitSquare.x; splitLabel.y = splitSquare.y + cakeAsset.height / 2 + 80; game.addChild(splitLabel); // Patch SplitSquare to update sliceCount and text on split var origDown = splitSquare.down; splitSquare.down = function (x, y, obj) { if (splitSquare.splitState === 0) { sliceCount = 2; updateSliceCountText(); } else if (splitSquare.splitState === 1) { sliceCount = 4; updateSliceCountText(); } origDown.call(splitSquare, x, y, obj); }; updateSliceCountText(); ;
/****
* Classes
****/
// SplitSquare: A square that can be split into two, then each half can be split again
var SplitSquare = Container.expand(function () {
var self = Container.call(this);
// State: 0 = whole, 1 = split in 2, 2 = split in 4
self.splitState = 0;
// Store child pieces for later reference
self.pieces = [];
// Add the initial whole square
var whole = self.attachAsset('splitSquare1', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
self.pieces.push(whole);
// Helper to clear all pieces
self.clearPieces = function () {
for (var i = 0; i < self.pieces.length; i++) {
if (self.pieces[i] && self.pieces[i].parent) {
self.pieces[i].parent.removeChild(self.pieces[i]);
}
}
self.pieces = [];
};
// Split into 2 pieces (horizontal split, üstlü altlı)
self.splitInTwo = function () {
self.clearPieces();
// Use the actual height of the splitSquare2 asset for perfect alignment
var pieceH = LK.getAsset('splitSquare2', {
anchorX: 0.5,
anchorY: 0.5
}).height;
var top = self.attachAsset('splitSquare2', {
anchorX: 0.5,
// center horizontally
anchorY: 1,
// bottom edge
x: 0,
y: 0
});
var bottom = self.attachAsset('splitSquare2', {
anchorX: 0.5,
// center horizontally
anchorY: 0,
// top edge
x: 0,
y: 0
});
self.pieces.push(top, bottom);
self.splitState = 1;
};
// Split into 4 pieces (each half split horizontally)
self.splitInFour = function () {
self.clearPieces();
// Use the actual width/height of the splitSquare3/4 assets for perfect alignment
var pieceW = LK.getAsset('splitSquare3', {
anchorX: 0.5,
anchorY: 0.5
}).width;
var pieceH = LK.getAsset('splitSquare3', {
anchorX: 0.5,
anchorY: 0.5
}).height;
// Add a small margin between pieces
var margin = 24;
// Top-left
var tl = self.attachAsset('splitSquare3', {
anchorX: 1,
anchorY: 1,
x: -margin / 2,
y: -margin / 2
});
// Bottom-left
var bl = self.attachAsset('splitSquare4', {
anchorX: 1,
anchorY: 0,
x: -margin / 2,
y: margin / 2
});
// Top-right
var tr = self.attachAsset('splitSquare3', {
anchorX: 0,
anchorY: 1,
x: margin / 2,
y: -margin / 2
});
// Bottom-right
var br = self.attachAsset('splitSquare4', {
anchorX: 0,
anchorY: 0,
x: margin / 2,
y: margin / 2
});
self.pieces.push(tl, bl, tr, br);
self.splitState = 2;
};
// Handle click/tap to split
self.down = function (x, y, obj) {
if (self.splitState === 0) {
self.splitInTwo();
} else if (self.splitState === 1) {
self.splitInFour();
}
};
return self;
});
/****
* Initialize Game
****/
// Add a SplitSquare to the center of the game
var game = new LK.Game({
backgroundColor: 0xffffff
});
/****
* Game Code
****/
// Dilim sayısı state
var sliceCount = 1;
// Add 'Replay' button to the top right, small size
var restartButton = new Text2('Replay', {
size: 60,
fill: 0x8e24aa,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
restartButton.anchor.set(1, 0); // right edge, top edge
restartButton.x = 0; // will be positioned by gui.topRight
restartButton.y = 0;
LK.gui.topRight.addChild(restartButton);
restartButton.down = function () {
// Reset game state
splitSquare.splitState = 0;
splitSquare.clearPieces();
var whole = splitSquare.attachAsset('splitSquare1', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
splitSquare.pieces.push(whole);
sliceCount = 1;
updateSliceCountText();
};
// Add label above slice count to show Tam/Yarım/Çeyrek
var sliceLabelText = new Text2('Tam', {
size: 140,
fill: 0x8e24aa,
// mor renk
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
sliceLabelText.anchor.set(0.5, 1); // center horizontally, bottom edge
sliceLabelText.y = -180; // move label further down
LK.gui.bottom.addChild(sliceLabelText);
// Add 'Dilim Sayısı' text at the bottom center
var sliceCountText = new Text2('Dilim Sayısı: 1', {
size: 100,
fill: 0xD83318,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
sliceCountText.anchor.set(0.5, 1); // center horizontally, bottom edge
sliceCountText.y = -40; // move slice count further down
LK.gui.bottom.addChild(sliceCountText);
// Helper to update slice count text
function updateSliceCountText() {
sliceCountText.setText('Dilim Sayısı: ' + sliceCount);
if (sliceCount === 1) {
sliceLabelText.setText('Tam');
} else if (sliceCount === 2) {
sliceLabelText.setText('Yarım');
} else if (sliceCount === 4) {
sliceLabelText.setText('Çeyrek');
}
}
// Title
var titleText = new Text2('Pasta Bölmece', {
size: 120,
fill: 0xD83318,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
titleText.anchor.set(0.5, 0); // center horizontally, top edge
// Place title below the top bar, leaving 40px margin from the top (and not in the top left 100x100)
titleText.y = 40;
LK.gui.top.addChild(titleText);
// Add a SplitSquare to the center of the game
var splitSquare = new SplitSquare();
splitSquare.x = 2048 / 2;
splitSquare.y = 2732 / 2;
game.addChild(splitSquare);
// Add 'Pastayı Böl' text below the cake, bigger and further down
var splitLabel = new Text2('Pastayı Böl', {
size: 90,
fill: 0xD83318,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
splitLabel.anchor.set(0.5, 0);
// Position further below the splitSquare (using its height)
var cakeAsset = LK.getAsset('splitSquare1', {
anchorX: 0.5,
anchorY: 0.5
});
splitLabel.x = splitSquare.x;
splitLabel.y = splitSquare.y + cakeAsset.height / 2 + 80;
game.addChild(splitLabel);
// Patch SplitSquare to update sliceCount and text on split
var origDown = splitSquare.down;
splitSquare.down = function (x, y, obj) {
if (splitSquare.splitState === 0) {
sliceCount = 2;
updateSliceCountText();
} else if (splitSquare.splitState === 1) {
sliceCount = 4;
updateSliceCountText();
}
origDown.call(splitSquare, x, y, obj);
};
updateSliceCountText();
;