User prompt
Herhangi oyuncu 5 gol attığı an oyun dursun
User prompt
Herhangi oyuncu 5 gol attıktan sonra oyun dursun ve bitsin
User prompt
5 gol atıldıktan sonra oyun bitsin
User prompt
Topu 2.5 kat hızlandır
User prompt
Topu 1.3 kat hızlı yap
User prompt
Topu 1.5 kat hızlandr
User prompt
Paddle i kontrol edmiyorum kontrol edilebilir yap
User prompt
Kaledeki şeyleri kontrol edemiyom düzelt
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'tween.to(winnerText, 500, {' Line Number: 158 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Oyun sonunda kazanan oyuncunun kazandığını yazsın
User prompt
Kale görünüşünü sil
User prompt
Önceki gibi yap
User prompt
Futbol kalesini üstten görünüş yap 2d gibi
User prompt
Topu 2 kat yavaşlat
User prompt
Topu 3 kat hızlandır
User prompt
Kale çizgisi arkada olsun
User prompt
Kalede olan kontrol ede bildiğimiz çizgi daha önde olsun kale çizgisi arkada olsun
User prompt
Kaledeki çizgiler biraz daha önde olsun çok değil
User prompt
Topun hızını 2 kat artır
User prompt
2 kişilik futbol oyununa benzer oyun yap top duvarlardan falan seksin kalede kontrol edebildiğimiz dörtgen şey olsun top ondanda seksin 5 gol atan kazansın
User prompt
Patlama efektleri yok ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Sweet Match Quest
Initial prompt
Candy crush benzeri oyun yap
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); self.velocityX = 8; self.velocityY = 4; self.speed = 10; var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.x += self.velocityX; self.y += self.velocityY; // Bounce off top and bottom walls if (self.y <= 30 || self.y >= FIELD_HEIGHT - 30) { self.velocityY = -self.velocityY; LK.getSound('bounce').play(); } // Check goal boundaries if (self.x <= 0) { // Player 2 scores player2Score++; resetBall(); LK.getSound('goal').play(); } else if (self.x >= FIELD_WIDTH) { // Player 1 scores player1Score++; resetBall(); LK.getSound('goal').play(); } }; return self; }); var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = self.attachAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); self.targetY = self.y; self.update = function () { // Smooth movement towards target var diff = self.targetY - self.y; self.y += diff * 0.1; // Keep paddle within field bounds if (self.y < 150) self.y = 150; if (self.y > FIELD_HEIGHT - 150) self.y = FIELD_HEIGHT - 150; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x006400 }); /**** * Game Code ****/ var FIELD_WIDTH = 2048; var FIELD_HEIGHT = 1500; var PADDLE_SPEED = 8; var GOAL_WIDTH = 40; var GOAL_HEIGHT = 300; // Game state var player1Score = 0; var player2Score = 0; var isGameActive = true; var WINNING_SCORE = 5; // Create field background var field = game.addChild(LK.getAsset('field', { anchorX: 0.5, anchorY: 0.5 })); field.x = FIELD_WIDTH / 2; field.y = FIELD_HEIGHT / 2 + 100; // Create goals var leftGoal = game.addChild(LK.getAsset('goal', { anchorX: 0.5, anchorY: 0.5 })); leftGoal.x = 20; leftGoal.y = FIELD_HEIGHT / 2 + 100; var rightGoal = game.addChild(LK.getAsset('goal', { anchorX: 0.5, anchorY: 0.5 })); rightGoal.x = FIELD_WIDTH - 20; rightGoal.y = FIELD_HEIGHT / 2 + 100; // Create paddles var leftPaddle = game.addChild(new Paddle()); leftPaddle.x = 100; leftPaddle.y = FIELD_HEIGHT / 2 + 100; var rightPaddle = game.addChild(new Paddle()); rightPaddle.x = FIELD_WIDTH - 100; rightPaddle.y = FIELD_HEIGHT / 2 + 100; // Create ball var ball = game.addChild(new Ball()); // UI Elements var player1ScoreText = new Text2('Player 1: 0', { size: 80, fill: 0xFFFFFF }); player1ScoreText.anchor.set(0, 0); player1ScoreText.x = 20; player1ScoreText.y = 20; LK.gui.topLeft.addChild(player1ScoreText); var player2ScoreText = new Text2('Player 2: 0', { size: 80, fill: 0xFFFFFF }); player2ScoreText.anchor.set(1, 0); player2ScoreText.x = -20; player2ScoreText.y = 20; LK.gui.topRight.addChild(player2ScoreText); function resetBall() { ball.x = FIELD_WIDTH / 2; ball.y = FIELD_HEIGHT / 2 + 100; ball.velocityX = Math.random() > 0.5 ? 8 : -8; ball.velocityY = (Math.random() - 0.5) * 8; updateUI(); checkGameState(); } function updateUI() { player1ScoreText.setText('Player 1: ' + player1Score); player2ScoreText.setText('Player 2: ' + player2Score); } function checkGameState() { if (player1Score >= WINNING_SCORE) { isGameActive = false; LK.showYouWin(); } else if (player2Score >= WINNING_SCORE) { isGameActive = false; LK.showGameOver(); } } // Touch controls game.move = function (x, y, obj) { if (!isGameActive) return; // Left side controls left paddle if (x < FIELD_WIDTH / 2) { leftPaddle.targetY = y; } else { // Right side controls right paddle rightPaddle.targetY = y; } }; game.update = function () { if (!isGameActive) return; // Check ball-paddle collisions if (ball.intersects(leftPaddle)) { if (ball.velocityX < 0) { ball.velocityX = -ball.velocityX; var relativeIntersectY = ball.y - leftPaddle.y; ball.velocityY = relativeIntersectY * 0.1; LK.getSound('bounce').play(); } } if (ball.intersects(rightPaddle)) { if (ball.velocityX > 0) { ball.velocityX = -ball.velocityX; var relativeIntersectY = ball.y - rightPaddle.y; ball.velocityY = relativeIntersectY * 0.1; LK.getSound('bounce').play(); } } }; // Initialize game resetBall(); updateUI();
===================================================================
--- original.js
+++ change.js
@@ -5,538 +5,175 @@
/****
* Classes
****/
-var Candy = Container.expand(function (type) {
+var Ball = Container.expand(function () {
var self = Container.call(this);
- self.type = type;
- self.gridX = 0;
- self.gridY = 0;
- self.isAnimating = false;
- var candyGraphics = self.attachAsset('candy' + type, {
+ self.velocityX = 8;
+ self.velocityY = 4;
+ self.speed = 10;
+ var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
- self.setGridPosition = function (gridX, gridY) {
- self.gridX = gridX;
- self.gridY = gridY;
- self.x = GRID_START_X + gridX * CELL_SIZE;
- self.y = GRID_START_Y + gridY * CELL_SIZE;
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Bounce off top and bottom walls
+ if (self.y <= 30 || self.y >= FIELD_HEIGHT - 30) {
+ self.velocityY = -self.velocityY;
+ LK.getSound('bounce').play();
+ }
+ // Check goal boundaries
+ if (self.x <= 0) {
+ // Player 2 scores
+ player2Score++;
+ resetBall();
+ LK.getSound('goal').play();
+ } else if (self.x >= FIELD_WIDTH) {
+ // Player 1 scores
+ player1Score++;
+ resetBall();
+ LK.getSound('goal').play();
+ }
};
- self.animateToPosition = function (newX, newY, callback) {
- self.isAnimating = true;
- tween(self, {
- x: newX,
- y: newY
- }, {
- duration: 200,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- self.isAnimating = false;
- if (callback) callback();
- }
- });
+ return self;
+});
+var Paddle = Container.expand(function () {
+ var self = Container.call(this);
+ var paddleGraphics = self.attachAsset('paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.targetY = self.y;
+ self.update = function () {
+ // Smooth movement towards target
+ var diff = self.targetY - self.y;
+ self.y += diff * 0.1;
+ // Keep paddle within field bounds
+ if (self.y < 150) self.y = 150;
+ if (self.y > FIELD_HEIGHT - 150) self.y = FIELD_HEIGHT - 150;
};
- self.down = function (x, y, obj) {
- if (self.isAnimating) return;
- handleCandySelection(self);
- };
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x1a1a2e
+ backgroundColor: 0x006400
});
/****
* Game Code
****/
-var GRID_SIZE = 8;
-var CELL_SIZE = 200;
-var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
-var GRID_START_Y = 400;
-var CANDY_TYPES = 6;
-var grid = [];
-var selectedCandy = null;
-var isProcessing = false;
-var movesLeft = 30;
-var targetScore = 5000;
+var FIELD_WIDTH = 2048;
+var FIELD_HEIGHT = 1500;
+var PADDLE_SPEED = 8;
+var GOAL_WIDTH = 40;
+var GOAL_HEIGHT = 300;
+// Game state
+var player1Score = 0;
+var player2Score = 0;
var isGameActive = true;
-// Initialize UI
-var scoreText = new Text2('Score: 0', {
+var WINNING_SCORE = 5;
+// Create field background
+var field = game.addChild(LK.getAsset('field', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+field.x = FIELD_WIDTH / 2;
+field.y = FIELD_HEIGHT / 2 + 100;
+// Create goals
+var leftGoal = game.addChild(LK.getAsset('goal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+leftGoal.x = 20;
+leftGoal.y = FIELD_HEIGHT / 2 + 100;
+var rightGoal = game.addChild(LK.getAsset('goal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+rightGoal.x = FIELD_WIDTH - 20;
+rightGoal.y = FIELD_HEIGHT / 2 + 100;
+// Create paddles
+var leftPaddle = game.addChild(new Paddle());
+leftPaddle.x = 100;
+leftPaddle.y = FIELD_HEIGHT / 2 + 100;
+var rightPaddle = game.addChild(new Paddle());
+rightPaddle.x = FIELD_WIDTH - 100;
+rightPaddle.y = FIELD_HEIGHT / 2 + 100;
+// Create ball
+var ball = game.addChild(new Ball());
+// UI Elements
+var player1ScoreText = new Text2('Player 1: 0', {
size: 80,
fill: 0xFFFFFF
});
-scoreText.anchor.set(0.5, 0);
-LK.gui.top.addChild(scoreText);
-var movesText = new Text2('Moves: ' + movesLeft, {
- size: 60,
+player1ScoreText.anchor.set(0, 0);
+player1ScoreText.x = 20;
+player1ScoreText.y = 20;
+LK.gui.topLeft.addChild(player1ScoreText);
+var player2ScoreText = new Text2('Player 2: 0', {
+ size: 80,
fill: 0xFFFFFF
});
-movesText.anchor.set(1, 0);
-movesText.x = -20;
-movesText.y = 20;
-LK.gui.topRight.addChild(movesText);
-var targetText = new Text2('Target: ' + targetScore, {
- size: 60,
- fill: 0xFFFF00
-});
-targetText.anchor.set(0, 0);
-targetText.x = 20;
-targetText.y = 20;
-LK.gui.topLeft.addChild(targetText);
-// Create grid background
-for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE; j++) {
- var bg = game.addChild(LK.getAsset('gridBg', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.3
- }));
- bg.x = GRID_START_X + i * CELL_SIZE;
- bg.y = GRID_START_Y + j * CELL_SIZE;
- }
+player2ScoreText.anchor.set(1, 0);
+player2ScoreText.x = -20;
+player2ScoreText.y = 20;
+LK.gui.topRight.addChild(player2ScoreText);
+function resetBall() {
+ ball.x = FIELD_WIDTH / 2;
+ ball.y = FIELD_HEIGHT / 2 + 100;
+ ball.velocityX = Math.random() > 0.5 ? 8 : -8;
+ ball.velocityY = (Math.random() - 0.5) * 8;
+ updateUI();
+ checkGameState();
}
-function initializeGrid() {
- grid = [];
- for (var i = 0; i < GRID_SIZE; i++) {
- grid[i] = [];
- for (var j = 0; j < GRID_SIZE; j++) {
- var candyType = Math.floor(Math.random() * CANDY_TYPES) + 1;
- var candy = new Candy(candyType);
- candy.setGridPosition(i, j);
- grid[i][j] = candy;
- game.addChild(candy);
- }
- }
- // Remove initial matches
- removeInitialMatches();
-}
-function removeInitialMatches() {
- var hasMatches = true;
- var attempts = 0;
- while (hasMatches && attempts < 50) {
- hasMatches = false;
- attempts++;
- for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE; j++) {
- if (grid[i][j]) {
- // Check horizontal matches
- if (i < GRID_SIZE - 2 && grid[i][j].type === grid[i + 1][j].type && grid[i][j].type === grid[i + 2][j].type) {
- grid[i][j].type = Math.floor(Math.random() * CANDY_TYPES) + 1;
- hasMatches = true;
- }
- // Check vertical matches
- if (j < GRID_SIZE - 2 && grid[i][j].type === grid[i][j + 1].type && grid[i][j].type === grid[i][j + 2].type) {
- grid[i][j].type = Math.floor(Math.random() * CANDY_TYPES) + 1;
- hasMatches = true;
- }
- }
- }
- }
- }
-}
-function handleCandySelection(candy) {
- if (!isGameActive || isProcessing) return;
- if (!selectedCandy) {
- selectedCandy = candy;
- tween(candy, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 100
- });
- } else {
- if (selectedCandy === candy) {
- // Deselect
- tween(selectedCandy, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
- selectedCandy = null;
- } else if (areAdjacent(selectedCandy, candy)) {
- // Attempt swap
- attemptSwap(selectedCandy, candy);
- } else {
- // Select new candy
- tween(selectedCandy, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
- selectedCandy = candy;
- tween(candy, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 100
- });
- }
- }
-}
-function areAdjacent(candy1, candy2) {
- var dx = Math.abs(candy1.gridX - candy2.gridX);
- var dy = Math.abs(candy1.gridY - candy2.gridY);
- return dx === 1 && dy === 0 || dx === 0 && dy === 1;
-}
-function attemptSwap(candy1, candy2) {
- isProcessing = true;
- // Swap positions in grid
- var tempX = candy1.gridX;
- var tempY = candy1.gridY;
- grid[candy1.gridX][candy1.gridY] = candy2;
- grid[candy2.gridX][candy2.gridY] = candy1;
- candy1.gridX = candy2.gridX;
- candy1.gridY = candy2.gridY;
- candy2.gridX = tempX;
- candy2.gridY = tempY;
- // Animate swap
- var newX1 = GRID_START_X + candy1.gridX * CELL_SIZE;
- var newY1 = GRID_START_Y + candy1.gridY * CELL_SIZE;
- var newX2 = GRID_START_X + candy2.gridX * CELL_SIZE;
- var newY2 = GRID_START_Y + candy2.gridY * CELL_SIZE;
- var animationsCompleted = 0;
- candy1.animateToPosition(newX1, newY1, function () {
- animationsCompleted++;
- if (animationsCompleted === 2) {
- checkSwapResult(candy1, candy2);
- }
- });
- candy2.animateToPosition(newX2, newY2, function () {
- animationsCompleted++;
- if (animationsCompleted === 2) {
- checkSwapResult(candy1, candy2);
- }
- });
- LK.getSound('swap').play();
-}
-function checkSwapResult(candy1, candy2) {
- var matches = findMatches();
- if (matches.length > 0) {
- // Valid move
- movesLeft--;
- updateUI();
- tween(selectedCandy, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
- selectedCandy = null;
- processMatches(matches);
- } else {
- // Invalid move - swap back
- var tempX = candy1.gridX;
- var tempY = candy1.gridY;
- grid[candy1.gridX][candy1.gridY] = candy2;
- grid[candy2.gridX][candy2.gridY] = candy1;
- candy1.gridX = candy2.gridX;
- candy1.gridY = candy2.gridY;
- candy2.gridX = tempX;
- candy2.gridY = tempY;
- var newX1 = GRID_START_X + candy1.gridX * CELL_SIZE;
- var newY1 = GRID_START_Y + candy1.gridY * CELL_SIZE;
- var newX2 = GRID_START_X + candy2.gridX * CELL_SIZE;
- var newY2 = GRID_START_Y + candy2.gridY * CELL_SIZE;
- var revertAnimations = 0;
- candy1.animateToPosition(newX1, newY1, function () {
- revertAnimations++;
- if (revertAnimations === 2) {
- tween(selectedCandy, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
- selectedCandy = null;
- isProcessing = false;
- }
- });
- candy2.animateToPosition(newX2, newY2, function () {
- revertAnimations++;
- if (revertAnimations === 2) {
- tween(selectedCandy, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
- selectedCandy = null;
- isProcessing = false;
- }
- });
- }
-}
-function findMatches() {
- var matches = [];
- var processed = [];
- // Initialize processed array
- for (var i = 0; i < GRID_SIZE; i++) {
- processed[i] = [];
- for (var j = 0; j < GRID_SIZE; j++) {
- processed[i][j] = false;
- }
- }
- // Find horizontal matches
- for (var j = 0; j < GRID_SIZE; j++) {
- for (var i = 0; i < GRID_SIZE - 2; i++) {
- if (grid[i][j] && grid[i + 1][j] && grid[i + 2][j] && grid[i][j].type === grid[i + 1][j].type && grid[i][j].type === grid[i + 2][j].type) {
- var matchGroup = [];
- var type = grid[i][j].type;
- var k = i;
- while (k < GRID_SIZE && grid[k][j] && grid[k][j].type === type) {
- if (!processed[k][j]) {
- matchGroup.push({
- x: k,
- y: j
- });
- processed[k][j] = true;
- }
- k++;
- }
- if (matchGroup.length >= 3) {
- matches.push(matchGroup);
- }
- }
- }
- }
- // Find vertical matches
- for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE - 2; j++) {
- if (grid[i][j] && grid[i][j + 1] && grid[i][j + 2] && grid[i][j].type === grid[i][j + 1].type && grid[i][j].type === grid[i][j + 2].type) {
- var matchGroup = [];
- var type = grid[i][j].type;
- var k = j;
- while (k < GRID_SIZE && grid[i][k] && grid[i][k].type === type) {
- if (!processed[i][k]) {
- matchGroup.push({
- x: i,
- y: k
- });
- processed[i][k] = true;
- }
- k++;
- }
- if (matchGroup.length >= 3) {
- matches.push(matchGroup);
- }
- }
- }
- }
- return matches;
-}
-function processMatches(matches) {
- if (matches.length === 0) {
- isProcessing = false;
- checkGameState();
- return;
- }
- var totalMatched = 0;
- var candiesToExplode = [];
- // Collect candies to explode
- for (var i = 0; i < matches.length; i++) {
- var matchGroup = matches[i];
- for (var j = 0; j < matchGroup.length; j++) {
- var pos = matchGroup[j];
- if (grid[pos.x][pos.y]) {
- candiesToExplode.push(grid[pos.x][pos.y]);
- totalMatched++;
- }
- }
- }
- // Start explosion animations
- var explosionsCompleted = 0;
- for (var k = 0; k < candiesToExplode.length; k++) {
- var candy = candiesToExplode[k];
- // Explosion effect: scale up and fade out
- tween(candy, {
- scaleX: 1.5,
- scaleY: 1.5,
- alpha: 0
- }, {
- duration: 250,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- explosionsCompleted++;
- if (explosionsCompleted === candiesToExplode.length) {
- // All explosions complete, now remove candies
- for (var m = 0; m < candiesToExplode.length; m++) {
- var explodedCandy = candiesToExplode[m];
- for (var x = 0; x < GRID_SIZE; x++) {
- for (var y = 0; y < GRID_SIZE; y++) {
- if (grid[x][y] === explodedCandy) {
- grid[x][y].destroy();
- grid[x][y] = null;
- }
- }
- }
- }
- // Calculate score
- var baseScore = totalMatched * 100;
- var bonus = Math.max(0, (totalMatched - 3) * 50);
- var scoreGained = baseScore + bonus;
- LK.setScore(LK.getScore() + scoreGained);
- updateUI();
- // Drop candies and fill gaps
- LK.setTimeout(function () {
- dropCandies();
- }, 50);
- }
- }
- });
- }
- LK.getSound('match').play();
-}
-function dropCandies() {
- var hasDropped = false;
- // Drop existing candies
- for (var i = 0; i < GRID_SIZE; i++) {
- var writePos = GRID_SIZE - 1;
- for (var j = GRID_SIZE - 1; j >= 0; j--) {
- if (grid[i][j]) {
- if (j !== writePos) {
- grid[i][writePos] = grid[i][j];
- grid[i][j] = null;
- grid[i][writePos].gridY = writePos;
- hasDropped = true;
- }
- writePos--;
- }
- }
- }
- // Animate drops
- if (hasDropped) {
- for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE; j++) {
- if (grid[i][j]) {
- var newY = GRID_START_Y + j * CELL_SIZE;
- if (grid[i][j].y !== newY) {
- grid[i][j].animateToPosition(grid[i][j].x, newY);
- }
- }
- }
- }
- }
- // Fill empty spaces
- LK.setTimeout(function () {
- fillEmptySpaces();
- }, 250);
-}
-function fillEmptySpaces() {
- for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE; j++) {
- if (!grid[i][j]) {
- var candyType = Math.floor(Math.random() * CANDY_TYPES) + 1;
- var candy = new Candy(candyType);
- candy.setGridPosition(i, j);
- candy.y = GRID_START_Y - CELL_SIZE;
- grid[i][j] = candy;
- game.addChild(candy);
- candy.animateToPosition(candy.x, GRID_START_Y + j * CELL_SIZE);
- }
- }
- }
- // Check for new matches after fill
- LK.setTimeout(function () {
- var newMatches = findMatches();
- if (newMatches.length > 0) {
- processMatches(newMatches);
- } else {
- isProcessing = false;
- checkGameState();
- }
- }, 300);
-}
function updateUI() {
- scoreText.setText('Score: ' + LK.getScore());
- movesText.setText('Moves: ' + movesLeft);
+ player1ScoreText.setText('Player 1: ' + player1Score);
+ player2ScoreText.setText('Player 2: ' + player2Score);
}
function checkGameState() {
- if (!isGameActive) return;
- if (LK.getScore() >= targetScore) {
+ if (player1Score >= WINNING_SCORE) {
isGameActive = false;
LK.showYouWin();
- return;
- }
- if (movesLeft <= 0) {
+ } else if (player2Score >= WINNING_SCORE) {
isGameActive = false;
LK.showGameOver();
- return;
}
- // Check if there are valid moves available
- if (!hasValidMoves()) {
- isGameActive = false;
- LK.showGameOver();
- }
}
-function hasValidMoves() {
- for (var i = 0; i < GRID_SIZE; i++) {
- for (var j = 0; j < GRID_SIZE; j++) {
- if (grid[i][j]) {
- // Check horizontal swap
- if (i < GRID_SIZE - 1 && grid[i + 1][j]) {
- if (wouldCreateMatch(i, j, i + 1, j)) {
- return true;
- }
- }
- // Check vertical swap
- if (j < GRID_SIZE - 1 && grid[i][j + 1]) {
- if (wouldCreateMatch(i, j, i, j + 1)) {
- return true;
- }
- }
- }
+// Touch controls
+game.move = function (x, y, obj) {
+ if (!isGameActive) return;
+ // Left side controls left paddle
+ if (x < FIELD_WIDTH / 2) {
+ leftPaddle.targetY = y;
+ } else {
+ // Right side controls right paddle
+ rightPaddle.targetY = y;
+ }
+};
+game.update = function () {
+ if (!isGameActive) return;
+ // Check ball-paddle collisions
+ if (ball.intersects(leftPaddle)) {
+ if (ball.velocityX < 0) {
+ ball.velocityX = -ball.velocityX;
+ var relativeIntersectY = ball.y - leftPaddle.y;
+ ball.velocityY = relativeIntersectY * 0.1;
+ LK.getSound('bounce').play();
}
}
- return false;
-}
-function wouldCreateMatch(x1, y1, x2, y2) {
- // Temporarily swap
- var temp = grid[x1][y1].type;
- grid[x1][y1].type = grid[x2][y2].type;
- grid[x2][y2].type = temp;
- var hasMatch = checkPositionForMatch(x1, y1) || checkPositionForMatch(x2, y2);
- // Swap back
- temp = grid[x1][y1].type;
- grid[x1][y1].type = grid[x2][y2].type;
- grid[x2][y2].type = temp;
- return hasMatch;
-}
-function checkPositionForMatch(x, y) {
- var type = grid[x][y].type;
- // Check horizontal
- var count = 1;
- var i = x - 1;
- while (i >= 0 && grid[i][y] && grid[i][y].type === type) {
- count++;
- i--;
+ if (ball.intersects(rightPaddle)) {
+ if (ball.velocityX > 0) {
+ ball.velocityX = -ball.velocityX;
+ var relativeIntersectY = ball.y - rightPaddle.y;
+ ball.velocityY = relativeIntersectY * 0.1;
+ LK.getSound('bounce').play();
+ }
}
- i = x + 1;
- while (i < GRID_SIZE && grid[i][y] && grid[i][y].type === type) {
- count++;
- i++;
- }
- if (count >= 3) return true;
- // Check vertical
- count = 1;
- var j = y - 1;
- while (j >= 0 && grid[x][j] && grid[x][j].type === type) {
- count++;
- j--;
- }
- j = y + 1;
- while (j < GRID_SIZE && grid[x][j] && grid[x][j].type === type) {
- count++;
- j++;
- }
- if (count >= 3) return true;
- return false;
-}
-// Initialize the game
-initializeGrid();
+};
+// Initialize game
+resetBall();
updateUI();
\ No newline at end of file