/**** 
* Classes
****/ 
var Block = Container.expand(function (board) {
	var self = Container.call(this);
	var hsvToRgb = function hsvToRgb(h, s, v) {
		var r, g, b;
		var i = Math.floor(h * 6);
		var f = h * 6 - i;
		var p = v * (1 - s);
		var q = v * (1 - f * s);
		var t = v * (1 - (1 - f) * s);
		switch (i % 6) {
			case 0:
				r = v, g = t, b = p;
				break;
			case 1:
				r = q, g = v, b = p;
				break;
			case 2:
				r = p, g = v, b = t;
				break;
			case 3:
				r = p, g = q, b = v;
				break;
			case 4:
				r = t, g = p, b = v;
				break;
			case 5:
				r = v, g = p, b = q;
				break;
		}
		return (Math.round(r * 255) << 16) + (Math.round(g * 255) << 8) + Math.round(b * 255);
	};
	var ShapeTypes = {
		SINGLE: [[1]],
		TRI: [[1, 1, 1]],
		QUAD: [[1, 1, 1, 1]],
		LSHAPE: [[1, 0, 0], [1, 0, 0], [1, 1, 1]],
		BLOCK: [[1, 1], [1, 1]],
		SMALLLSHAPE: [[1, 0], [1, 1]]
	};
	var shapes = Object.values(ShapeTypes);
	var offset = Math.floor(Math.random() * shapes.length);
	self.offset = offset;
	self.shape = shapes[offset];
	var hue = offset % shapes.length / shapes.length;
	self.color = hsvToRgb(hue, 0.6, 1);
	self.rotateShapeRandomly = function () {
		var rotations = Math.floor(Math.random() * 4);
		for (var r = 0; r < rotations; r++) {
			self.shape = self.shape[0].map(function (val, index) {
				return self.shape.map(function (row) {
					return row[index];
				}).reverse();
			});
		}
	};
	self.rotateShapeRandomly();
	self.blocks = [];
	var background = self.attachAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	background.alpha = 0;
	var blockSize = 160;
	background.width = 4 * blockSize;
	background.height = 4 * blockSize;
	self.addChild(background);
	self.offsetX = 0;
	self.offsetY = 0;
	var blockOffsetX = (background.width / 2 - self.shape[0].length * blockSize) / 2 - blockSize / 2;
	var blockOffsetY = (background.height / 2 - self.shape.length * blockSize) / 2 - blockSize / 2;
	for (var i = 0; i < self.shape.length; i++) {
		for (var j = 0; j < self.shape[i].length; j++) {
			if (self.shape[i][j] === 1) {
				var block = self.createAsset('block_' + offset, {
					anchorX: 0.5,
					anchorY: 0.5
				});
				block.x = j * blockSize + blockOffsetX;
				block.y = i * blockSize + blockOffsetY;
				self.blocks.push(block);
				self.addChild(block);
			}
		}
	}
	self.startX = 0;
	self.startY = 0;
	self.moveTowardsHomePosition = function () {
		var dx = self.startX - self.x;
		var dy = self.startY - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > 1) {
			self.x += dx * 0.3;
			self.y += dy * 0.3;
		} else {
			self.x = self.startX;
			self.y = self.startY;
		}
	};
	var currentX = 0;
	var currentY = 0;
	self.moveToDragTarget = function () {
		var ox = -this.targetX;
		var oy = (LK.is.mobile ? 400 : 0) - this.targetY;
		this.targetX += ox / 5;
		this.targetY += oy / 5;
		this.x = currentX - this.targetX;
		this.y = currentY - this.targetY;
	};
	self._move_migrated = function (x, y) {
		currentX = x;
		currentY = y;
		self.x = x - this.targetX;
		self.y = y - this.targetY;
	};
	self.setStartPosition = function (x, y) {
		self.startX = x;
		self.startY = y;
	};
	self.getOverlappingCells = function () {
		var cells = [];
		var boardPos = {
			x: -board.x + self.x + 160 * 4 + blockOffsetX + 160,
			y: -board.y + self.y + 160 * 4 + blockOffsetY + 160
		};
		var startX = Math.floor(boardPos.x / 160);
		var startY = Math.floor(boardPos.y / 160);
		for (var i = 0; i < self.shape.length; i++) {
			for (var j = 0; j < self.shape[i].length; j++) {
				if (self.shape[i][j] === 1) {
					var cell = board.grid && board.grid[startY + i] && board.grid[startY + i][startX + j];
					if (cell && !cell.filled) {
						cells.push(cell);
					} else {
						return null;
					}
				}
			}
		}
		return cells;
	};
	self.showOverlap = function () {
		var cells = self.getOverlappingCells();
		if (cells) {
			for (var a = 0; a < cells.length; a++) {
				var cell = cells[a];
				cell.setTint(self.color);
			}
		}
	};
	self.rotateShapeRandomly = function () {
		var rotations = Math.floor(Math.random() * 4);
		for (var r = 0; r < rotations; r++) {
			self.shape = self.shape[0].map(function (val, index) {
				return self.shape.map(function (row) {
					return row[index];
				}).reverse();
			});
		}
	};
});
var Board = Container.expand(function () {
	var self = Container.call(this);
	self.particles = [];
	Board.prototype.spawnParticles = function (x, y, tint) {
		for (var i = 0; i < 10; i++) {
			var particle = new Particle(tint);
			particle.x = x;
			particle.y = y;
			this.particles.push(particle);
			this.addChild(particle);
		}
	};
	self.grid = new Array(10).fill(null).map(function () {
		return new Array(10).fill(null);
	});
	var size = 158;
	var totalWidth = 10 * size;
	var totalHeight = 10 * size;
	for (var i = 0; i < 10; i++) {
		for (var j = 0; j < 10; j++) {
			var cell = new Cell();
			cell.x = i * size - totalWidth / 2 + size / 2;
			cell.y = j * size - totalHeight / 2 + size / 2;
			self.grid[j][i] = cell;
			self.addChild(cell);
		}
	}
	self.removeTint = function () {
		for (var i = 0; i < 10; i++) {
			for (var j = 0; j < 10; j++) {
				if (!self.grid[i][j].filled) {
					self.grid[i][j].setTint(0xffffff);
				}
			}
		}
	};
	self.checkLines = function () {
		var rowsRemoved = 0;
		for (var i = 0; i < 10; i++) {
			var rowFilled = true;
			var colFilled = true;
			for (var j = 0; j < 10; j++) {
				if (!self.grid[i][j].filled) {
					rowFilled = false;
				}
				if (!self.grid[j][i].filled) {
					colFilled = false;
				}
			}
			if (rowFilled || colFilled) {
				rowsRemoved += (rowFilled ? 1 : 0) + (colFilled ? 1 : 0);
				for (var j = 0; j < 10; j++) {
					if (rowFilled) {
						self.grid[i][j].setFill(false);
						self.spawnParticles(self.grid[i][j].x, self.grid[i][j].y, self.grid[i][j].getTint());
					}
					if (colFilled) {
						self.grid[j][i].setFill(false);
						self.spawnParticles(self.grid[j][i].x, self.grid[j][i].y, self.grid[j][i].getTint());
					}
				}
			}
		}
		return rowsRemoved;
	};
	self.tick = function () {
		for (var i = self.particles.length - 1; i >= 0; i--) {
			var particle = self.particles[i];
			if (particle) {
				particle.tick();
				if (particle.alpha <= 0) {
					self.particles.splice(i, 1);
				}
			}
		}
		for (var i = 0; i < 10; i++) {
			for (var j = 0; j < 10; j++) {
				self.grid[i][j].tick(i, j);
			}
		}
	};
	self.placeBlock = function () {};
});
var Cell = Container.expand(function () {
	var self = Container.call(this);
	self.filled = false;
	var yOffsetArray = [-25, -10, -20, -25, -25, -20];
	var empty = self.attachAsset('cell', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	empty.alpa = .8;
	var filled;
	var currentOffset;
	empty.y = 2;
	self.currentTint = 0xffffff;
	self.setFill = function (isFilled, asset, offset) {
		self.filled = isFilled;
		empty.visible = !self.filled;
		if (isFilled) {
			if (asset) {
				asset.x = 0;
				asset.y = yOffsetArray[offset] || -15;
				currentOffset = offset;
				self.addChild(asset);
				filled = asset;
			}
		} else {
			if (filled) {
				filled.destroy();
				filled = null;
			}
		}
	};
	self.tick = function (i, j) {
		if (filled) {
			var offset = Math.cos(((i + j) * 3 + LK.ticks / 2) / 6) / 20;
			var ty = yOffsetArray[currentOffset] || -15;
			filled.y = ty + Math.abs(offset * 200) - 5;
			filled.rotation = offset;
		}
	};
	self.getTint = function () {
		return self.currentTint;
	};
	self.setTint = function (tint) {
		self.currentTint = tint;
		empty.tint = tint;
	};
	self.setFill(false);
});
var Particle = Container.expand(function (tint) {
	var self = Container.call(this);
	self.tint = tint;
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	particleGraphics.rotation = Math.random() * Math.PI * 2;
	particleGraphics.tint = self.tint;
	self.vx = Math.random() * 4 - 2;
	self.vy = Math.random() * 4 - 2;
	self.alpha = 1;
	self.lifetime = 60;
	self.tick = function () {
		self.x += self.vx;
		self.y += self.vy;
		self.alpha -= 1 / self.lifetime;
		if (self.alpha <= 0) {
			self.destroy();
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Main menu overlay
var mainMenuOverlay = new Container();
mainMenuOverlay.zIndex = 10000; // ensure on top
// Semi-transparent background
var menuBg = LK.getAsset('tileBackground', {
	anchorX: 0.5,
	anchorY: 0.5
});
// Make sure the background fully covers the screen
menuBg.width = 2048;
menuBg.height = 2732;
menuBg.x = 2048 / 2;
menuBg.y = 2732 / 2;
menuBg.alpha = 0.85;
mainMenuOverlay.addChild(menuBg);
// Title text (mobile-optimized)
var titleText = new Text2('Denoş Blok Oyunu', {
	size: 140,
	fill: 0xD83318,
	font: 'Impact',
	stroke: '#fff',
	strokeThickness: 14
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 500;
mainMenuOverlay.addChild(titleText);
// Play button (mobile-optimized)
var playBtnBg = LK.getAsset('background', {
	anchorX: 0.5,
	anchorY: 0.5
});
playBtnBg.width = 700;
playBtnBg.height = 220;
playBtnBg.tint = 0x83de44;
playBtnBg.alpha = 0.5;
playBtnBg.x = 2048 / 2;
playBtnBg.y = 1100;
mainMenuOverlay.addChild(playBtnBg);
var playBtnText = new Text2('Oyna', {
	size: 300,
	fill: "#fff",
	font: 'Impact',
	stroke: '#2a636e',
	strokeThickness: 10
});
playBtnText.anchor.set(0.5, 0.5);
playBtnText.x = 2048 / 2;
playBtnText.y = 1100;
mainMenuOverlay.addChild(playBtnText);
// Close (oyunu kapat) button (mobile-optimized)
var closeBtnBg = LK.getAsset('background', {
	anchorX: 0.5,
	anchorY: 0.5
});
closeBtnBg.width = 700;
closeBtnBg.height = 220;
closeBtnBg.tint = 0xd83318;
closeBtnBg.x = 2048 / 2;
closeBtnBg.y = 1400;
mainMenuOverlay.addChild(closeBtnBg);
var closeBtnText = new Text2('Oyunu Kapat', {
	size: 100,
	fill: "#fff",
	font: 'Impact',
	stroke: '#2a636e',
	strokeThickness: 10
});
closeBtnText.anchor.set(0.5, 0.5);
closeBtnText.x = 2048 / 2;
closeBtnText.y = 1400;
mainMenuOverlay.addChild(closeBtnText);
// Make close button interactive for finger/touch
closeBtnBg.interactive = true;
closeBtnBg.buttonMode = true;
closeBtnBg.on('down', function () {
	// Start game when close button is clicked
	startGame();
	// Create a function to randomly place blocks until game over
	function placeRandomBlocks() {
		if (!blocks.some(function (block) {
			return block;
		})) {
			return; // No blocks available to place
		}
		// Try to place a random block at random position
		var blockIndex = -1;
		for (var i = 0; i < blocks.length; i++) {
			if (blocks[i]) {
				blockIndex = i;
				break;
			}
		}
		if (blockIndex >= 0) {
			var block = blocks[blockIndex];
			// Find all possible positions
			var validPositions = [];
			for (var i = 0; i < 10; i++) {
				for (var j = 0; j < 10; j++) {
					var canPlace = true;
					if (board.grid[i][j].filled) {
						continue;
					}
					for (var k = 0; k < block.shape.length && canPlace; k++) {
						for (var l = 0; l < block.shape[k].length; l++) {
							if (block.shape[k][l] === 1) {
								if (i + k >= 10 || j + l >= 10 || board.grid[i + k][j + l].filled) {
									canPlace = false;
									break;
								}
							}
						}
					}
					if (canPlace) {
						validPositions.push({
							i: i,
							j: j
						});
					}
				}
			}
			// If there are valid positions, place at random one
			if (validPositions.length > 0) {
				var pos = validPositions[Math.floor(Math.random() * validPositions.length)];
				// Place the block
				var cells = [];
				for (var k = 0; k < block.shape.length; k++) {
					for (var l = 0; l < block.shape[k].length; l++) {
						if (block.shape[k][l] === 1) {
							cells.push(board.grid[pos.i + k][pos.j + l]);
						}
					}
				}
				for (var a = 0; a < cells.length; a++) {
					cells[a].setFill(true, block.blocks[a], block.offset);
					cells[a].setTint(block.color);
				}
				// Remove the used block
				blocks[blockIndex] = undefined;
				block.destroy();
				// Check for completed lines
				var pointsToAdd = board.checkLines();
				if (pointsToAdd) {
					var newScore = LK.getScore() + Math.pow(pointsToAdd, 2) * 10;
					LK.setScore(newScore);
					scoreTxt.setText(String(LK.getScore()));
				}
				// If all blocks used, create new blocks
				if (!blocks.some(function (block) {
					return block;
				})) {
					game.createBlocks();
				}
				// Continue placing blocks with a small delay
				LK.setTimeout(placeRandomBlocks, 100);
			} else {
				// No valid positions, show game over
				LK.effects.flashScreen(0xffffff, 1000);
				LK.showGameOver();
			}
		}
	}
	// Start the auto placement
	LK.setTimeout(placeRandomBlocks, 500);
});
closeBtnText.interactive = true;
closeBtnText.buttonMode = true;
closeBtnText.on('down', function () {
	closeBtnBg.emit('down');
});
// Block gameplay until play is pressed
var gameStarted = false;
game.addChild(mainMenuOverlay);
function startGame() {
	if (gameStarted) {
		return;
	}
	gameStarted = true;
	mainMenuOverlay.visible = false;
	// --- original game setup code below ---
	gameBackground = game.attachAsset('gameBackground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	gameBackground.x = 2048 / 2;
	gameBackground.y = 2732 / 2 + 65;
	blocks = [];
	dragTarget = undefined;
	board = game.addChild(new Board());
	board.x = 2048 / 2;
	board.y = 2732 / 2 - 250 + 30;
	targetOffset = undefined;
	game.createBlock = function (index) {
		var block = new Block(board);
		block.x = 2048 / 2 + (index - 1) * (block.width + 30);
		block.y = 2732 + block.height;
		block.setStartPosition(block.x, 2732 - block.height / 2 - 30);
		blocks.push(block);
		game.addChild(block);
		block.on('down', function (x, y, obj) {
			dragTarget = this;
			var pos = this.toLocal(obj.global);
			var targetPos = game.toLocal(obj.global);
			this.targetX = pos.x;
			this.targetY = pos.y;
			dragTarget._move_migrated(targetPos.x, targetPos.y);
		});
	};
	game.on('move', function (x, y, obj) {
		if (dragTarget) {
			board.removeTint();
			var pos = game.toLocal(obj.global);
			dragTarget._move_migrated(pos.x, pos.y);
			dragTarget.showOverlap();
		}
	});
	game.on('up', function (x, y, obj) {
		if (dragTarget) {
			var cells = dragTarget.getOverlappingCells();
			if (cells) {
				for (var a = 0; a < cells.length; a++) {
					cells[a].setFill(true, dragTarget.blocks[a], dragTarget.offset);
					cells[a].setTint(dragTarget.color);
				}
				blocks[blocks.indexOf(dragTarget)] = undefined;
				dragTarget.destroy();
				if (!blocks.some(function (block) {
					return block;
				})) {
					game.createBlocks();
				}
				var pointsToAdd = board.checkLines();
				if (pointsToAdd) {
					var newScore = LK.getScore() + Math.pow(pointsToAdd, 2) * 10;
					LK.setScore(newScore);
					scoreTxt.setText(String(LK.getScore()));
				}
			}
			board.removeTint();
			dragTarget = undefined;
		}
	});
	game.createBlocks = function () {
		for (var i = 0; i < 3; i++) {
			game.createBlock(i);
		}
	};
	score = 0;
	LK.setScore(0);
	game.createBlocks();
	// --- Add In-Game Score Bar ---
	var scoreTxt = new Text2(String(LK.getScore()), {
		size: 120,
		fill: 0x008080,
		font: 'Impact',
		stroke: '#fff',
		strokeThickness: 10
	});
	scoreTxt.anchor.set(0.5, 0);
	scoreTxt.x = 2048 / 2;
	scoreTxt.y = 100;
	scoreTxt.zIndex = 10001;
	LK.gui.top.addChild(scoreTxt);
	// Show score bar only when game is started
	LK.on('tick', function () {
		if (typeof scoreTxt !== "undefined") {
			scoreTxt.visible = !!gameStarted;
		}
	});
	// --- Add Back Button ---
	var backBtnBg = LK.getAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	backBtnBg.width = 400;
	backBtnBg.height = 140;
	backBtnBg.tint = 0xd83318;
	// Move button further from top left for mobile, and not in the 0-100px area
	backBtnBg.x = 2048 - 320;
	backBtnBg.y = 180;
	backBtnBg.zIndex = 10001;
	var backBtnText = new Text2('Geri', {
		size: 90,
		fill: "#fff",
		font: 'Impact',
		stroke: '#2a636e',
		strokeThickness: 10
	});
	backBtnText.anchor.set(0.5, 0.5);
	backBtnText.x = backBtnBg.x;
	backBtnText.y = backBtnBg.y;
	backBtnText.zIndex = 10002;
	// Add "Glaud" text in upper right corner
	var glaudText = new Text2('Glaud', {
		size: 40,
		fill: 0x000000
	});
	glaudText.anchor.set(1, 0);
	glaudText.x = 2048 - 20;
	glaudText.y = 20;
	glaudText.zIndex = 10003;
	LK.gui.topRight.addChild(glaudText);
	// Make back button interactive for finger/touch
	backBtnBg.interactive = true;
	backBtnBg.buttonMode = true;
	backBtnBg.on('down', function (x, y, obj) {
		// Hide game UI and show main menu
		mainMenuOverlay.visible = true;
		gameStarted = false;
		// Remove all blocks and board from game
		if (typeof board !== "undefined" && board) {
			board.destroy();
			board = undefined;
		}
		if (typeof blocks !== "undefined" && blocks) {
			for (var i = 0; i < blocks.length; i++) {
				if (blocks[i]) {
					blocks[i].destroy();
				}
			}
			blocks = [];
		}
		if (typeof gameBackground !== "undefined" && gameBackground) {
			gameBackground.destroy();
			gameBackground = undefined;
		}
		if (typeof scoreTxt !== "undefined" && scoreTxt) {
			scoreTxt.setText(String(LK.getScore()));
		}
		// Hide back button
		backBtnBg.visible = false;
		backBtnText.visible = false;
	});
	backBtnText.interactive = true;
	backBtnText.buttonMode = true;
	backBtnText.on('down', function (x, y, obj) {
		backBtnBg.emit('down', x, y, obj);
	});
	// Add to GUI overlay so it stays on top
	LK.gui.top.addChild(backBtnBg);
	LK.gui.top.addChild(backBtnText);
	// Show back button only when game is started
	LK.on('tick', function () {
		if (typeof backBtnBg !== "undefined") {
			backBtnBg.visible = !!gameStarted;
		}
		if (typeof backBtnText !== "undefined") {
			backBtnText.visible = !!gameStarted;
		}
	});
	// --- Add In-Game Menu Button ---
	var menuBtnBg = LK.getAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	menuBtnBg.width = 400;
	menuBtnBg.height = 140;
	menuBtnBg.tint = 0x008080;
	menuBtnBg.x = 320;
	menuBtnBg.y = 180;
	menuBtnBg.zIndex = 10001;
	var menuBtnText = new Text2('Menü', {
		size: 90,
		fill: "#fff",
		font: 'Impact',
		stroke: '#2a636e',
		strokeThickness: 10
	});
	menuBtnText.anchor.set(0.5, 0.5);
	menuBtnText.x = menuBtnBg.x;
	menuBtnText.y = menuBtnBg.y;
	menuBtnText.zIndex = 10002;
	menuBtnBg.interactive = true;
	menuBtnBg.buttonMode = true;
	menuBtnBg.on('down', function (x, y, obj) {
		// Hide game UI and show main menu
		mainMenuOverlay.visible = true;
		gameStarted = false;
		// Remove all blocks and board from game
		if (typeof board !== "undefined" && board) {
			board.destroy();
			board = undefined;
		}
		if (typeof blocks !== "undefined" && blocks) {
			for (var i = 0; i < blocks.length; i++) {
				if (blocks[i]) {
					blocks[i].destroy();
				}
			}
			blocks = [];
		}
		if (typeof gameBackground !== "undefined" && gameBackground) {
			gameBackground.destroy();
			gameBackground = undefined;
		}
		if (typeof scoreTxt !== "undefined" && scoreTxt) {
			scoreTxt.setText(String(LK.getScore()));
		}
		// Hide menu button
		menuBtnBg.visible = false;
		menuBtnText.visible = false;
	});
	menuBtnText.interactive = true;
	menuBtnText.buttonMode = true;
	menuBtnText.on('down', function (x, y, obj) {
		menuBtnBg.emit('down', x, y, obj);
	});
	LK.gui.top.addChild(menuBtnBg);
	LK.gui.top.addChild(menuBtnText);
	// Show menu button only when game is started
	LK.on('tick', function () {
		if (typeof menuBtnBg !== "undefined") {
			menuBtnBg.visible = !!gameStarted;
		}
		if (typeof menuBtnText !== "undefined") {
			menuBtnText.visible = !!gameStarted;
		}
	});
	game.isMovePossible = function () {
		for (var a = 0; a < blocks.length; a++) {
			if (blocks[a]) {
				for (var i = 0; i < 10; i++) {
					for (var j = 0; j < 10; j++) {
						if (board.grid[i][j].filled) {
							continue;
						}
						var canPlace = true;
						for (var k = 0; k < blocks[a].shape.length; k++) {
							for (var l = 0; l < blocks[a].shape[k].length; l++) {
								if (blocks[a].shape[k][l] === 1) {
									if (i + k < 0 || i + k >= 10 || j + l < 0 || j + l >= 10 || board.grid[i + k][j + l].filled) {
										canPlace = false;
										break;
									}
								}
							}
							if (!canPlace) {
								break;
							}
						}
						if (canPlace) {
							return true;
						}
					}
				}
			}
		}
		return false;
	};
	var isGameOver = false;
	LK.on('tick', function () {
		if (typeof board !== "undefined" && board && typeof board.tick === "function") {
			board.tick();
		}
		if (!mainMenuOverlay.visible && (isGameOver || !game.isMovePossible())) {
			LK.effects.flashScreen(0xffffff, 1000);
			LK.showGameOver();
			isGameOver = true;
		}
		for (var a = blocks.length - 1; a >= 0; a--) {
			if (blocks[a]) {
				if (blocks[a] != dragTarget) {
					blocks[a].moveTowardsHomePosition();
				} else {
					blocks[a].moveToDragTarget();
				}
			}
		}
	});
}
// Play button interaction
playBtnBg.interactive = true;
playBtnBg.buttonMode = true;
playBtnBg.on('down', function () {
	startGame();
});
playBtnText.interactive = true;
playBtnText.buttonMode = true;
playBtnText.on('down', function () {
	startGame();
}); /**** 
* Classes
****/ 
var Block = Container.expand(function (board) {
	var self = Container.call(this);
	var hsvToRgb = function hsvToRgb(h, s, v) {
		var r, g, b;
		var i = Math.floor(h * 6);
		var f = h * 6 - i;
		var p = v * (1 - s);
		var q = v * (1 - f * s);
		var t = v * (1 - (1 - f) * s);
		switch (i % 6) {
			case 0:
				r = v, g = t, b = p;
				break;
			case 1:
				r = q, g = v, b = p;
				break;
			case 2:
				r = p, g = v, b = t;
				break;
			case 3:
				r = p, g = q, b = v;
				break;
			case 4:
				r = t, g = p, b = v;
				break;
			case 5:
				r = v, g = p, b = q;
				break;
		}
		return (Math.round(r * 255) << 16) + (Math.round(g * 255) << 8) + Math.round(b * 255);
	};
	var ShapeTypes = {
		SINGLE: [[1]],
		TRI: [[1, 1, 1]],
		QUAD: [[1, 1, 1, 1]],
		LSHAPE: [[1, 0, 0], [1, 0, 0], [1, 1, 1]],
		BLOCK: [[1, 1], [1, 1]],
		SMALLLSHAPE: [[1, 0], [1, 1]]
	};
	var shapes = Object.values(ShapeTypes);
	var offset = Math.floor(Math.random() * shapes.length);
	self.offset = offset;
	self.shape = shapes[offset];
	var hue = offset % shapes.length / shapes.length;
	self.color = hsvToRgb(hue, 0.6, 1);
	self.rotateShapeRandomly = function () {
		var rotations = Math.floor(Math.random() * 4);
		for (var r = 0; r < rotations; r++) {
			self.shape = self.shape[0].map(function (val, index) {
				return self.shape.map(function (row) {
					return row[index];
				}).reverse();
			});
		}
	};
	self.rotateShapeRandomly();
	self.blocks = [];
	var background = self.attachAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	background.alpha = 0;
	var blockSize = 160;
	background.width = 4 * blockSize;
	background.height = 4 * blockSize;
	self.addChild(background);
	self.offsetX = 0;
	self.offsetY = 0;
	var blockOffsetX = (background.width / 2 - self.shape[0].length * blockSize) / 2 - blockSize / 2;
	var blockOffsetY = (background.height / 2 - self.shape.length * blockSize) / 2 - blockSize / 2;
	for (var i = 0; i < self.shape.length; i++) {
		for (var j = 0; j < self.shape[i].length; j++) {
			if (self.shape[i][j] === 1) {
				var block = self.createAsset('block_' + offset, {
					anchorX: 0.5,
					anchorY: 0.5
				});
				block.x = j * blockSize + blockOffsetX;
				block.y = i * blockSize + blockOffsetY;
				self.blocks.push(block);
				self.addChild(block);
			}
		}
	}
	self.startX = 0;
	self.startY = 0;
	self.moveTowardsHomePosition = function () {
		var dx = self.startX - self.x;
		var dy = self.startY - self.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > 1) {
			self.x += dx * 0.3;
			self.y += dy * 0.3;
		} else {
			self.x = self.startX;
			self.y = self.startY;
		}
	};
	var currentX = 0;
	var currentY = 0;
	self.moveToDragTarget = function () {
		var ox = -this.targetX;
		var oy = (LK.is.mobile ? 400 : 0) - this.targetY;
		this.targetX += ox / 5;
		this.targetY += oy / 5;
		this.x = currentX - this.targetX;
		this.y = currentY - this.targetY;
	};
	self._move_migrated = function (x, y) {
		currentX = x;
		currentY = y;
		self.x = x - this.targetX;
		self.y = y - this.targetY;
	};
	self.setStartPosition = function (x, y) {
		self.startX = x;
		self.startY = y;
	};
	self.getOverlappingCells = function () {
		var cells = [];
		var boardPos = {
			x: -board.x + self.x + 160 * 4 + blockOffsetX + 160,
			y: -board.y + self.y + 160 * 4 + blockOffsetY + 160
		};
		var startX = Math.floor(boardPos.x / 160);
		var startY = Math.floor(boardPos.y / 160);
		for (var i = 0; i < self.shape.length; i++) {
			for (var j = 0; j < self.shape[i].length; j++) {
				if (self.shape[i][j] === 1) {
					var cell = board.grid && board.grid[startY + i] && board.grid[startY + i][startX + j];
					if (cell && !cell.filled) {
						cells.push(cell);
					} else {
						return null;
					}
				}
			}
		}
		return cells;
	};
	self.showOverlap = function () {
		var cells = self.getOverlappingCells();
		if (cells) {
			for (var a = 0; a < cells.length; a++) {
				var cell = cells[a];
				cell.setTint(self.color);
			}
		}
	};
	self.rotateShapeRandomly = function () {
		var rotations = Math.floor(Math.random() * 4);
		for (var r = 0; r < rotations; r++) {
			self.shape = self.shape[0].map(function (val, index) {
				return self.shape.map(function (row) {
					return row[index];
				}).reverse();
			});
		}
	};
});
var Board = Container.expand(function () {
	var self = Container.call(this);
	self.particles = [];
	Board.prototype.spawnParticles = function (x, y, tint) {
		for (var i = 0; i < 10; i++) {
			var particle = new Particle(tint);
			particle.x = x;
			particle.y = y;
			this.particles.push(particle);
			this.addChild(particle);
		}
	};
	self.grid = new Array(10).fill(null).map(function () {
		return new Array(10).fill(null);
	});
	var size = 158;
	var totalWidth = 10 * size;
	var totalHeight = 10 * size;
	for (var i = 0; i < 10; i++) {
		for (var j = 0; j < 10; j++) {
			var cell = new Cell();
			cell.x = i * size - totalWidth / 2 + size / 2;
			cell.y = j * size - totalHeight / 2 + size / 2;
			self.grid[j][i] = cell;
			self.addChild(cell);
		}
	}
	self.removeTint = function () {
		for (var i = 0; i < 10; i++) {
			for (var j = 0; j < 10; j++) {
				if (!self.grid[i][j].filled) {
					self.grid[i][j].setTint(0xffffff);
				}
			}
		}
	};
	self.checkLines = function () {
		var rowsRemoved = 0;
		for (var i = 0; i < 10; i++) {
			var rowFilled = true;
			var colFilled = true;
			for (var j = 0; j < 10; j++) {
				if (!self.grid[i][j].filled) {
					rowFilled = false;
				}
				if (!self.grid[j][i].filled) {
					colFilled = false;
				}
			}
			if (rowFilled || colFilled) {
				rowsRemoved += (rowFilled ? 1 : 0) + (colFilled ? 1 : 0);
				for (var j = 0; j < 10; j++) {
					if (rowFilled) {
						self.grid[i][j].setFill(false);
						self.spawnParticles(self.grid[i][j].x, self.grid[i][j].y, self.grid[i][j].getTint());
					}
					if (colFilled) {
						self.grid[j][i].setFill(false);
						self.spawnParticles(self.grid[j][i].x, self.grid[j][i].y, self.grid[j][i].getTint());
					}
				}
			}
		}
		return rowsRemoved;
	};
	self.tick = function () {
		for (var i = self.particles.length - 1; i >= 0; i--) {
			var particle = self.particles[i];
			if (particle) {
				particle.tick();
				if (particle.alpha <= 0) {
					self.particles.splice(i, 1);
				}
			}
		}
		for (var i = 0; i < 10; i++) {
			for (var j = 0; j < 10; j++) {
				self.grid[i][j].tick(i, j);
			}
		}
	};
	self.placeBlock = function () {};
});
var Cell = Container.expand(function () {
	var self = Container.call(this);
	self.filled = false;
	var yOffsetArray = [-25, -10, -20, -25, -25, -20];
	var empty = self.attachAsset('cell', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	empty.alpa = .8;
	var filled;
	var currentOffset;
	empty.y = 2;
	self.currentTint = 0xffffff;
	self.setFill = function (isFilled, asset, offset) {
		self.filled = isFilled;
		empty.visible = !self.filled;
		if (isFilled) {
			if (asset) {
				asset.x = 0;
				asset.y = yOffsetArray[offset] || -15;
				currentOffset = offset;
				self.addChild(asset);
				filled = asset;
			}
		} else {
			if (filled) {
				filled.destroy();
				filled = null;
			}
		}
	};
	self.tick = function (i, j) {
		if (filled) {
			var offset = Math.cos(((i + j) * 3 + LK.ticks / 2) / 6) / 20;
			var ty = yOffsetArray[currentOffset] || -15;
			filled.y = ty + Math.abs(offset * 200) - 5;
			filled.rotation = offset;
		}
	};
	self.getTint = function () {
		return self.currentTint;
	};
	self.setTint = function (tint) {
		self.currentTint = tint;
		empty.tint = tint;
	};
	self.setFill(false);
});
var Particle = Container.expand(function (tint) {
	var self = Container.call(this);
	self.tint = tint;
	var particleGraphics = self.attachAsset('particle', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	particleGraphics.rotation = Math.random() * Math.PI * 2;
	particleGraphics.tint = self.tint;
	self.vx = Math.random() * 4 - 2;
	self.vy = Math.random() * 4 - 2;
	self.alpha = 1;
	self.lifetime = 60;
	self.tick = function () {
		self.x += self.vx;
		self.y += self.vy;
		self.alpha -= 1 / self.lifetime;
		if (self.alpha <= 0) {
			self.destroy();
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Main menu overlay
var mainMenuOverlay = new Container();
mainMenuOverlay.zIndex = 10000; // ensure on top
// Semi-transparent background
var menuBg = LK.getAsset('tileBackground', {
	anchorX: 0.5,
	anchorY: 0.5
});
// Make sure the background fully covers the screen
menuBg.width = 2048;
menuBg.height = 2732;
menuBg.x = 2048 / 2;
menuBg.y = 2732 / 2;
menuBg.alpha = 0.85;
mainMenuOverlay.addChild(menuBg);
// Title text (mobile-optimized)
var titleText = new Text2('Denoş Blok Oyunu', {
	size: 140,
	fill: 0xD83318,
	font: 'Impact',
	stroke: '#fff',
	strokeThickness: 14
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 500;
mainMenuOverlay.addChild(titleText);
// Play button (mobile-optimized)
var playBtnBg = LK.getAsset('background', {
	anchorX: 0.5,
	anchorY: 0.5
});
playBtnBg.width = 700;
playBtnBg.height = 220;
playBtnBg.tint = 0x83de44;
playBtnBg.alpha = 0.5;
playBtnBg.x = 2048 / 2;
playBtnBg.y = 1100;
mainMenuOverlay.addChild(playBtnBg);
var playBtnText = new Text2('Oyna', {
	size: 300,
	fill: "#fff",
	font: 'Impact',
	stroke: '#2a636e',
	strokeThickness: 10
});
playBtnText.anchor.set(0.5, 0.5);
playBtnText.x = 2048 / 2;
playBtnText.y = 1100;
mainMenuOverlay.addChild(playBtnText);
// Close (oyunu kapat) button (mobile-optimized)
var closeBtnBg = LK.getAsset('background', {
	anchorX: 0.5,
	anchorY: 0.5
});
closeBtnBg.width = 700;
closeBtnBg.height = 220;
closeBtnBg.tint = 0xd83318;
closeBtnBg.x = 2048 / 2;
closeBtnBg.y = 1400;
mainMenuOverlay.addChild(closeBtnBg);
var closeBtnText = new Text2('Oyunu Kapat', {
	size: 100,
	fill: "#fff",
	font: 'Impact',
	stroke: '#2a636e',
	strokeThickness: 10
});
closeBtnText.anchor.set(0.5, 0.5);
closeBtnText.x = 2048 / 2;
closeBtnText.y = 1400;
mainMenuOverlay.addChild(closeBtnText);
// Make close button interactive for finger/touch
closeBtnBg.interactive = true;
closeBtnBg.buttonMode = true;
closeBtnBg.on('down', function () {
	// Start game when close button is clicked
	startGame();
	// Create a function to randomly place blocks until game over
	function placeRandomBlocks() {
		if (!blocks.some(function (block) {
			return block;
		})) {
			return; // No blocks available to place
		}
		// Try to place a random block at random position
		var blockIndex = -1;
		for (var i = 0; i < blocks.length; i++) {
			if (blocks[i]) {
				blockIndex = i;
				break;
			}
		}
		if (blockIndex >= 0) {
			var block = blocks[blockIndex];
			// Find all possible positions
			var validPositions = [];
			for (var i = 0; i < 10; i++) {
				for (var j = 0; j < 10; j++) {
					var canPlace = true;
					if (board.grid[i][j].filled) {
						continue;
					}
					for (var k = 0; k < block.shape.length && canPlace; k++) {
						for (var l = 0; l < block.shape[k].length; l++) {
							if (block.shape[k][l] === 1) {
								if (i + k >= 10 || j + l >= 10 || board.grid[i + k][j + l].filled) {
									canPlace = false;
									break;
								}
							}
						}
					}
					if (canPlace) {
						validPositions.push({
							i: i,
							j: j
						});
					}
				}
			}
			// If there are valid positions, place at random one
			if (validPositions.length > 0) {
				var pos = validPositions[Math.floor(Math.random() * validPositions.length)];
				// Place the block
				var cells = [];
				for (var k = 0; k < block.shape.length; k++) {
					for (var l = 0; l < block.shape[k].length; l++) {
						if (block.shape[k][l] === 1) {
							cells.push(board.grid[pos.i + k][pos.j + l]);
						}
					}
				}
				for (var a = 0; a < cells.length; a++) {
					cells[a].setFill(true, block.blocks[a], block.offset);
					cells[a].setTint(block.color);
				}
				// Remove the used block
				blocks[blockIndex] = undefined;
				block.destroy();
				// Check for completed lines
				var pointsToAdd = board.checkLines();
				if (pointsToAdd) {
					var newScore = LK.getScore() + Math.pow(pointsToAdd, 2) * 10;
					LK.setScore(newScore);
					scoreTxt.setText(String(LK.getScore()));
				}
				// If all blocks used, create new blocks
				if (!blocks.some(function (block) {
					return block;
				})) {
					game.createBlocks();
				}
				// Continue placing blocks with a small delay
				LK.setTimeout(placeRandomBlocks, 100);
			} else {
				// No valid positions, show game over
				LK.effects.flashScreen(0xffffff, 1000);
				LK.showGameOver();
			}
		}
	}
	// Start the auto placement
	LK.setTimeout(placeRandomBlocks, 500);
});
closeBtnText.interactive = true;
closeBtnText.buttonMode = true;
closeBtnText.on('down', function () {
	closeBtnBg.emit('down');
});
// Block gameplay until play is pressed
var gameStarted = false;
game.addChild(mainMenuOverlay);
function startGame() {
	if (gameStarted) {
		return;
	}
	gameStarted = true;
	mainMenuOverlay.visible = false;
	// --- original game setup code below ---
	gameBackground = game.attachAsset('gameBackground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	gameBackground.x = 2048 / 2;
	gameBackground.y = 2732 / 2 + 65;
	blocks = [];
	dragTarget = undefined;
	board = game.addChild(new Board());
	board.x = 2048 / 2;
	board.y = 2732 / 2 - 250 + 30;
	targetOffset = undefined;
	game.createBlock = function (index) {
		var block = new Block(board);
		block.x = 2048 / 2 + (index - 1) * (block.width + 30);
		block.y = 2732 + block.height;
		block.setStartPosition(block.x, 2732 - block.height / 2 - 30);
		blocks.push(block);
		game.addChild(block);
		block.on('down', function (x, y, obj) {
			dragTarget = this;
			var pos = this.toLocal(obj.global);
			var targetPos = game.toLocal(obj.global);
			this.targetX = pos.x;
			this.targetY = pos.y;
			dragTarget._move_migrated(targetPos.x, targetPos.y);
		});
	};
	game.on('move', function (x, y, obj) {
		if (dragTarget) {
			board.removeTint();
			var pos = game.toLocal(obj.global);
			dragTarget._move_migrated(pos.x, pos.y);
			dragTarget.showOverlap();
		}
	});
	game.on('up', function (x, y, obj) {
		if (dragTarget) {
			var cells = dragTarget.getOverlappingCells();
			if (cells) {
				for (var a = 0; a < cells.length; a++) {
					cells[a].setFill(true, dragTarget.blocks[a], dragTarget.offset);
					cells[a].setTint(dragTarget.color);
				}
				blocks[blocks.indexOf(dragTarget)] = undefined;
				dragTarget.destroy();
				if (!blocks.some(function (block) {
					return block;
				})) {
					game.createBlocks();
				}
				var pointsToAdd = board.checkLines();
				if (pointsToAdd) {
					var newScore = LK.getScore() + Math.pow(pointsToAdd, 2) * 10;
					LK.setScore(newScore);
					scoreTxt.setText(String(LK.getScore()));
				}
			}
			board.removeTint();
			dragTarget = undefined;
		}
	});
	game.createBlocks = function () {
		for (var i = 0; i < 3; i++) {
			game.createBlock(i);
		}
	};
	score = 0;
	LK.setScore(0);
	game.createBlocks();
	// --- Add In-Game Score Bar ---
	var scoreTxt = new Text2(String(LK.getScore()), {
		size: 120,
		fill: 0x008080,
		font: 'Impact',
		stroke: '#fff',
		strokeThickness: 10
	});
	scoreTxt.anchor.set(0.5, 0);
	scoreTxt.x = 2048 / 2;
	scoreTxt.y = 100;
	scoreTxt.zIndex = 10001;
	LK.gui.top.addChild(scoreTxt);
	// Show score bar only when game is started
	LK.on('tick', function () {
		if (typeof scoreTxt !== "undefined") {
			scoreTxt.visible = !!gameStarted;
		}
	});
	// --- Add Back Button ---
	var backBtnBg = LK.getAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	backBtnBg.width = 400;
	backBtnBg.height = 140;
	backBtnBg.tint = 0xd83318;
	// Move button further from top left for mobile, and not in the 0-100px area
	backBtnBg.x = 2048 - 320;
	backBtnBg.y = 180;
	backBtnBg.zIndex = 10001;
	var backBtnText = new Text2('Geri', {
		size: 90,
		fill: "#fff",
		font: 'Impact',
		stroke: '#2a636e',
		strokeThickness: 10
	});
	backBtnText.anchor.set(0.5, 0.5);
	backBtnText.x = backBtnBg.x;
	backBtnText.y = backBtnBg.y;
	backBtnText.zIndex = 10002;
	// Add "Glaud" text in upper right corner
	var glaudText = new Text2('Glaud', {
		size: 40,
		fill: 0x000000
	});
	glaudText.anchor.set(1, 0);
	glaudText.x = 2048 - 20;
	glaudText.y = 20;
	glaudText.zIndex = 10003;
	LK.gui.topRight.addChild(glaudText);
	// Make back button interactive for finger/touch
	backBtnBg.interactive = true;
	backBtnBg.buttonMode = true;
	backBtnBg.on('down', function (x, y, obj) {
		// Hide game UI and show main menu
		mainMenuOverlay.visible = true;
		gameStarted = false;
		// Remove all blocks and board from game
		if (typeof board !== "undefined" && board) {
			board.destroy();
			board = undefined;
		}
		if (typeof blocks !== "undefined" && blocks) {
			for (var i = 0; i < blocks.length; i++) {
				if (blocks[i]) {
					blocks[i].destroy();
				}
			}
			blocks = [];
		}
		if (typeof gameBackground !== "undefined" && gameBackground) {
			gameBackground.destroy();
			gameBackground = undefined;
		}
		if (typeof scoreTxt !== "undefined" && scoreTxt) {
			scoreTxt.setText(String(LK.getScore()));
		}
		// Hide back button
		backBtnBg.visible = false;
		backBtnText.visible = false;
	});
	backBtnText.interactive = true;
	backBtnText.buttonMode = true;
	backBtnText.on('down', function (x, y, obj) {
		backBtnBg.emit('down', x, y, obj);
	});
	// Add to GUI overlay so it stays on top
	LK.gui.top.addChild(backBtnBg);
	LK.gui.top.addChild(backBtnText);
	// Show back button only when game is started
	LK.on('tick', function () {
		if (typeof backBtnBg !== "undefined") {
			backBtnBg.visible = !!gameStarted;
		}
		if (typeof backBtnText !== "undefined") {
			backBtnText.visible = !!gameStarted;
		}
	});
	// --- Add In-Game Menu Button ---
	var menuBtnBg = LK.getAsset('background', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	menuBtnBg.width = 400;
	menuBtnBg.height = 140;
	menuBtnBg.tint = 0x008080;
	menuBtnBg.x = 320;
	menuBtnBg.y = 180;
	menuBtnBg.zIndex = 10001;
	var menuBtnText = new Text2('Menü', {
		size: 90,
		fill: "#fff",
		font: 'Impact',
		stroke: '#2a636e',
		strokeThickness: 10
	});
	menuBtnText.anchor.set(0.5, 0.5);
	menuBtnText.x = menuBtnBg.x;
	menuBtnText.y = menuBtnBg.y;
	menuBtnText.zIndex = 10002;
	menuBtnBg.interactive = true;
	menuBtnBg.buttonMode = true;
	menuBtnBg.on('down', function (x, y, obj) {
		// Hide game UI and show main menu
		mainMenuOverlay.visible = true;
		gameStarted = false;
		// Remove all blocks and board from game
		if (typeof board !== "undefined" && board) {
			board.destroy();
			board = undefined;
		}
		if (typeof blocks !== "undefined" && blocks) {
			for (var i = 0; i < blocks.length; i++) {
				if (blocks[i]) {
					blocks[i].destroy();
				}
			}
			blocks = [];
		}
		if (typeof gameBackground !== "undefined" && gameBackground) {
			gameBackground.destroy();
			gameBackground = undefined;
		}
		if (typeof scoreTxt !== "undefined" && scoreTxt) {
			scoreTxt.setText(String(LK.getScore()));
		}
		// Hide menu button
		menuBtnBg.visible = false;
		menuBtnText.visible = false;
	});
	menuBtnText.interactive = true;
	menuBtnText.buttonMode = true;
	menuBtnText.on('down', function (x, y, obj) {
		menuBtnBg.emit('down', x, y, obj);
	});
	LK.gui.top.addChild(menuBtnBg);
	LK.gui.top.addChild(menuBtnText);
	// Show menu button only when game is started
	LK.on('tick', function () {
		if (typeof menuBtnBg !== "undefined") {
			menuBtnBg.visible = !!gameStarted;
		}
		if (typeof menuBtnText !== "undefined") {
			menuBtnText.visible = !!gameStarted;
		}
	});
	game.isMovePossible = function () {
		for (var a = 0; a < blocks.length; a++) {
			if (blocks[a]) {
				for (var i = 0; i < 10; i++) {
					for (var j = 0; j < 10; j++) {
						if (board.grid[i][j].filled) {
							continue;
						}
						var canPlace = true;
						for (var k = 0; k < blocks[a].shape.length; k++) {
							for (var l = 0; l < blocks[a].shape[k].length; l++) {
								if (blocks[a].shape[k][l] === 1) {
									if (i + k < 0 || i + k >= 10 || j + l < 0 || j + l >= 10 || board.grid[i + k][j + l].filled) {
										canPlace = false;
										break;
									}
								}
							}
							if (!canPlace) {
								break;
							}
						}
						if (canPlace) {
							return true;
						}
					}
				}
			}
		}
		return false;
	};
	var isGameOver = false;
	LK.on('tick', function () {
		if (typeof board !== "undefined" && board && typeof board.tick === "function") {
			board.tick();
		}
		if (!mainMenuOverlay.visible && (isGameOver || !game.isMovePossible())) {
			LK.effects.flashScreen(0xffffff, 1000);
			LK.showGameOver();
			isGameOver = true;
		}
		for (var a = blocks.length - 1; a >= 0; a--) {
			if (blocks[a]) {
				if (blocks[a] != dragTarget) {
					blocks[a].moveTowardsHomePosition();
				} else {
					blocks[a].moveToDragTarget();
				}
			}
		}
	});
}
// Play button interaction
playBtnBg.interactive = true;
playBtnBg.buttonMode = true;
playBtnBg.on('down', function () {
	startGame();
});
playBtnText.interactive = true;
playBtnText.buttonMode = true;
playBtnText.on('down', function () {
	startGame();
});
 White square with tight round corners, flat shaded, hyper casual game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Background for hyper casual puzzle game. Pastel colors, flat shaded, vector art. Circular flowers. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Background for relaxing puzzle game. Pastel colors, flat shaded, vector art. Flowers. Blocks. Relaxing. Clouds Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 White particle cloud. Cartoon. Bright outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Perfectly square red Christmas decoration. Cartoon. Cute art style
 Perfectly square yellow Christmas decoration. Cartoon style. Cute art style. Simple vector style.
 Perfectly square bright blue Christmas decoration with cute happyy face. Cartoon style. Cute art style. Simple vector style.
 Perfectly square bright purple Christmas decoration with cute happyy face. Cartoon style. Cute art style. Simple vector style.
 Perfectly square bright green Christmas decoration with cute happyy face. Cartoon style. Cute art style. Simple vector style. No Shadows
 Perfectly square bright cobalt blue Christmas decoration with cute happyy face. Cartoon style. Cute art style. Simple vector style. No Shadows Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 back button. In-Game asset. 2d. High contrast. No shadows