User prompt
Curlinstones cannot cover other curlinstones in display order but they collision with each other.
User prompt
Add second stone to the map
User prompt
Ensure player has one movement with curlinstone and change turn to ai
User prompt
Change turn from player to computer when player pushed her curlingstone
User prompt
Change player to computer
User prompt
Ensure centerline cannot cover the texts in display order
User prompt
Ensure centerline is under the texts in the display order
User prompt
Ensure gamemodeasset is above centerline in display order
User prompt
Play crawl sound when the selected curling stone is moving
User prompt
Please fix the bug: 'ReferenceError: otherStone is not defined' in or related to this line: 'self.lastWasIntersecting = self.intersects(otherStone); // Update lastWasIntersecting after collision detection' Line Number: 55
User prompt
Add click event to the mobile phone by handling touch events
User prompt
Why cannot moving the stone? Repair this bug!
User prompt
Please fix the bug: 'ReferenceError: otherStone is not defined' in or related to this line: 'self.lastWasIntersecting = self.intersects(otherStone); // Update lastWasIntersecting after collision detection' Line Number: 55
User prompt
Hey! The stone is stopped moving! Fix this bug!
User prompt
Please fix the bug: 'ReferenceError: otherStone is not defined' in or related to this line: 'self.lastWasIntersecting = self.intersects(otherStone); // Update lastWasIntersecting after collision detection' Line Number: 55
User prompt
ADD COLLISION EVENT TO THE CURLING STONES
User prompt
Avoid removement of the selected curlingstone
User prompt
add computer controlled opponent to the map when the player selected stone stopped
User prompt
Please fix the bug: 'ReferenceError: otherStone is not defined' in or related to this line: 'self.lastWasIntersecting = self.intersects(otherStone); // Update lastWasIntersecting after collision detection' Line Number: 55
User prompt
Migrate the latest LK Engine
User prompt
remove the player start text from the map if the player has shot his stone
User prompt
update game logic
User prompt
remove the player start text from the map
User prompt
A player can only move his stone once in a turn. Next comes the opponent.
User prompt
The players turn is off when the her curling is stopped.
/**** 
* Classes
****/ 
// The assets will be automatically created and loaded by the LK engine
// Create a class for the curling stone
var CurlingStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneBlue', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x + Math.cos(self.direction) * self.speed; // Update lastX before position change
	self.lastY = self.y + Math.sin(self.direction) * self.speed; // Update lastY before position change
	self.canMove = true; // Initialize canMove property to allow movement initially
	self.lastWasIntersecting = false; // Initialize lastWasIntersecting for collision detection
	self.touched = false; // Track if the stone has been touched
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		// Play crawl sound when the stone is moving
		if (self.speed > 0 && !self.crawlSoundPlaying) {
			LK.getSound('Crawl').play();
			self.crawlSoundPlaying = true;
		} else if (self.speed <= 0 && self.crawlSoundPlaying) {
			LK.getSound('Crawl').stop();
			self.crawlSoundPlaying = false;
		}
		// Check if the stone has crossed the red line
		if (self.lastY <= 2732 * 0.75 + 300 && self.y > 2732 * 0.75 + 300) {
			self.canMove = false; // Disable further movement
			// Check for intersections with other stones
			stones.forEach(function (otherStone) {
				if (otherStone !== self && self.lastWasIntersecting === false && self.intersects(otherStone)) {
					// Calculate the angle of collision
					var angle = Math.atan2(self.y - otherStone.y, self.x - otherStone.x);
					// Calculate new direction for both stones
					var selfNewDirection = angle + Math.PI;
					var otherStoneNewDirection = angle;
					// Swap speeds for a simple elastic collision effect
					var tempSpeed = self.speed;
					self.speed = otherStone.speed;
					otherStone.speed = tempSpeed;
					// Set new directions
					self.direction = selfNewDirection;
					otherStone.direction = otherStoneNewDirection;
				}
				self.lastWasIntersecting = self.intersects(otherStone); // Update lastWasIntersecting after collision detection
			});
		}
		self.lastX = self.x; // Update lastX after position change
		// Define VALUE and VALUE2 for X and Y coordinate checks
		var VALUE = 2048 / 2; // Center of the screen for X coordinate check
		var VALUE2 = 2732 * 0.25; // Target line for Y coordinate check
		// Check if we reached the X position (VALUE) right now as we were not there before
		if (self.lastX <= VALUE && self.x > VALUE) {
			console.log("Reached the center X position!");
			// Additional logic for when the stone reaches the center X position
		}
		self.lastY = self.y; // Update lastY after position change
		// Check if we reached the X (VALUE2) and Y (VALUE) position right at this frame, and not the frame before
		if (self.lastY <= VALUE && self.y > VALUE && self.x <= VALUE2 && self.x > VALUE2) {
			console.log("Reached the target X and Y position!");
			// Additional logic for when the stone reaches the target X and Y position
		}
		// Check if we reached the Y position (VALUE) right at this frame now as we were not there before (last update tick)
		if (self.lastY <= VALUE && self.y > VALUE) {
			console.log("Reached the target line!");
			// Additional logic for when the stone reaches the target line
		}
		// Check for intersections with other stones
		stones.forEach(function (otherStone) {
			if (otherStone !== self && self.lastWasIntersecting === false && self.intersects(otherStone)) {
				// Calculate the angle of collision
				var angle = Math.atan2(self.y - otherStone.y, self.x - otherStone.x);
				// Calculate new direction for both stones
				var selfNewDirection = angle + Math.PI;
				var otherStoneNewDirection = angle;
				// Swap speeds for a simple elastic collision effect
				var tempSpeed = self.speed;
				self.speed = otherStone.speed;
				otherStone.speed = tempSpeed;
				// Set new directions
				self.direction = selfNewDirection;
				otherStone.direction = otherStoneNewDirection;
			}
		});
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
			if (self.touched) {
				if (gameMode === 'playerVsAI') {
					isPlayerTurn = !isPlayerTurn; // Toggle turn
					if (!isPlayerTurn) {
						aiTakeTurn(); // Trigger AI's turn
					}
				} else if (gameMode === 'playerVsPlayer') {
					isPlayerTurn = !isPlayerTurn; // Toggle turn
					currentPlayer = isPlayerTurn ? 1 : 2; // Switch between player 1 and player 2
				}
				self.touched = false; // Reset touched state after turn ends
			}
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
// Create a class for the game mode selection pop-up
var GameModePopup = Container.expand(function () {
	var self = Container.call(this);
	// Create background for the pop-up
	// Removed the duplicated whiteCenter asset from the map
	// Create text for the pop-up
	var text = new Text2('Choose Game Mode', {
		size: 150,
		fill: 0x000000
	});
	text.anchor.set(0.5, 0.5);
	text.x = 2048 / 2;
	text.y = 2732 / 2;
	self.addChild(text);
	// Create text for choosing curling stone
	var chooseStoneText = new Text2('Choose Curling Stone', {
		size: 120,
		fill: 0x000000
	});
	chooseStoneText.anchor.set(0.5, 0.5);
	chooseStoneText.x = 2048 / 2;
	chooseStoneText.y = 2732 / 2 + 600;
	self.addChild(chooseStoneText);
});
var GreenStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneGreen', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var NeonStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneNeon', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var OrangeStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneOrange', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var PinkStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stonePink', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var PurpleStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stonePurple', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var RedStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneRed', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
var YellowStone = Container.expand(function () {
	var self = Container.call(this);
	var stoneGraphics = self.attachAsset('stoneYellow', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lastX = self.x; // Initialize lastX for tracking previous X position
	self.lastY = self.y; // Initialize lastY for tracking previous Y position
	self.speed = 0;
	self.direction = 0;
	self.update = function () {
		self.x += Math.cos(self.direction) * self.speed;
		self.y += Math.sin(self.direction) * self.speed;
		self.lastX = self.x; // Update lastX after position change
		self.lastY = self.y; // Update lastY after position change
		self.speed *= 0.99; // friction
		if (self.speed < 0.1) {
			self.speed = 0;
		}
	};
	self["throw"] = function (speed, direction) {
		self.speed = speed;
		self.direction = direction;
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0xFFFFFF // Init game with white background
});
/**** 
* Game Code
****/ 
function aiTakeTurn() {
	// AI selects a stone of a different color
	var stones = [stone, stoneRed, stoneYellow, stoneGreen, stoneOrange, stonePink, stonePurple, stoneNeon];
	var aiSelectedStone = null;
	do {
		aiSelectedStone = stones[Math.floor(Math.random() * stones.length)];
	} while (aiSelectedStone === selectedStone || aiSelectedStone.touched || aiSelectedStone.speed > 0 || aiSelectedStone === null);
	// AI throws the stone with a random speed and direction
	if (aiSelectedStone) {
		var speed = Math.random() * 5 + 1; // Random speed between 1 and 6
		var direction = Math.random() * Math.PI * 2; // Random direction
		aiSelectedStone["throw"](speed, direction);
		aiSelectedStone.touched = true; // Mark the stone as touched
		// Add AI's stone to the map
		if (!aiSelectedStone.parent) {
			game.addChild(aiSelectedStone);
		}
	}
	// Toggle back to player's turn
	isPlayerTurn = true; // Switch back to player's turn after AI's turn
}
function isExactlyOneStoneBelowRedLine() {
	var stones = [stone, stoneRed, stoneYellow, stoneGreen, stoneOrange, stonePink, stonePurple, stoneNeon];
	var count = 0;
	stones.forEach(function (stone) {
		if (stone.y > 2732 * 0.75 + 300) {
			// Removed game over condition when stone intersects target
			if (!startButton) {
				// Check if startButton is null, indicating it has disappeared
				// Logic to start the match
				console.log("Match has started!");
			}
			count++;
		}
	});
	return count === 1;
}
// Initialize stones array to track all stones
var stones = [new CurlingStone(), new RedStone(), new YellowStone(), new GreenStone(), new OrangeStone(), new PinkStone(), new PurpleStone(), new NeonStone()];
stones.forEach(function (stone) {
	stone.lastWasIntersecting = false; // Initialize lastWasIntersecting for each stone
});
var anotherObject = whiteCenter; // Define anotherObject for intersection checks
// Initialize startButton variable
var startButton = null;
// Function to check the visibility of the start button
function checkStartButtonVisibility() {
	if (gameMode !== null && selectedStone !== null && selectedStone.y > 2732 * 0.75 + 300 && (selectAsset.visible || selectGreenAsset.visible)) {
		// Logic to display the start button
		startButton = LK.getAsset('startButton', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: 2048 / 2,
			y: 2732 * 0.25
		});
		startButton.visible = true;
		startButton.interactive = true;
		startButton.on('down', startButtonClickHandler);
		game.addChild(startButton);
	} else {
		if (startButton) {
			startButton.visible = false;
		}
	}
}
// Initialize playerStartText variable
var playerStartText = null;
// Initialize game mode variable
var gameMode = null;
var selectedStone = null; // Track selected stone
// Display the game mode selection pop-up
var gameModePopup = new GameModePopup();
game.addChild(gameModePopup);
// Add first game mode asset to the map
var gameModeAsset1 = LK.getAsset('gameModeAsset', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2
});
game.addChild(gameModeAsset1);
// Add second game mode asset to the map
var gameModeAsset2 = LK.getAsset('gameModeAsset', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2 + 600 // Adjusted position for the second asset
});
game.addChild(gameModeAsset2);
// Add left button to the center of the map
var leftButton = LK.getAsset('leftButton', {
	anchorX: 1.0,
	// Align right edge
	anchorY: 0.0,
	x: 2048 / 2,
	y: gameModeAsset1.y + gameModeAsset1.height / 2
});
leftButton.interactive = true;
leftButton.on('down', function () {
	selectPlayerVsPlayerMode();
	isPlayerTurn = true; // Set to player 1's turn
	gameMode = 'playerVsPlayer'; // Ensure game mode is set to player vs player
});
game.addChild(leftButton);
// Add playervsplayer asset to the map
var playervsplayerAsset = LK.getAsset('playervsplayer', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: leftButton.x - leftButton.width / 2,
	y: leftButton.y + leftButton.height / 2
});
game.addChild(playervsplayerAsset);
// Add select asset to indicate selection
var selectAsset = LK.getAsset('select', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: leftButton.x - leftButton.width / 2,
	y: leftButton.y + leftButton.height / 2
});
selectAsset.visible = false; // Initially hidden
game.addChild(selectAsset);
// Add right button to the center of the map
var rightButton = LK.getAsset('rightButton', {
	anchorX: 0.0,
	// Align left edge
	anchorY: 0.0,
	x: 2048 / 2,
	y: gameModeAsset1.y + gameModeAsset1.height / 2
});
rightButton.interactive = true;
rightButton.on('down', function () {
	selectPlayerVsAIMode();
	isPlayerTurn = false; // Set opponent to computer
	gameMode = 'playerVsAI'; // Ensure game mode is set to player vs AI
});
game.addChild(rightButton);
// Add selectgreen asset to the map
var selectGreenAsset = LK.getAsset('selectgreen', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: rightButton.x + rightButton.width / 2,
	y: rightButton.y + rightButton.height / 2
});
selectGreenAsset.visible = false; // Initially hidden
game.addChild(selectGreenAsset);
// Function to handle player vs ai mode selection
function selectPlayerVsAIMode() {
	gameMode = 'playerVsAI';
	isPlayerTurn = false; // Set opponent to computer
	selectGreenAsset.visible = !selectGreenAsset.visible;
	if (selectGreenAsset.visible) {
		selectAsset.visible = false;
	}
	selectGreenAsset.x = rightButton.x + rightButton.width / 2;
	selectGreenAsset.y = rightButton.y + rightButton.height / 2;
	checkStartButtonVisibility();
}
// Function to handle player vs player mode selection
function selectPlayerVsPlayerMode() {
	gameMode = 'playerVsPlayer';
	selectAsset.visible = !selectAsset.visible;
	if (selectAsset.visible) {
		selectGreenAsset.visible = false;
	}
	selectAsset.x = leftButton.x - leftButton.width / 2;
	selectAsset.y = leftButton.y + leftButton.height / 2;
	checkStartButtonVisibility();
}
// Add interaction to playervsplayerAsset
playervsplayerAsset.interactive = true;
playervsplayerAsset.on('down', selectPlayerVsPlayerMode);
// Add playervsai asset to the map
var playervsaiAsset = LK.getAsset('playervsai', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: rightButton.x + rightButton.width / 2,
	y: rightButton.y + rightButton.height / 2
});
playervsaiAsset.interactive = true;
playervsaiAsset.on('down', selectPlayerVsAIMode);
game.addChild(playervsaiAsset);
// Add center line to the game
var centerLine = LK.getAsset('centerLine', {
	anchorX: 0.5,
	anchorY: 0.0,
	x: 2048 / 2,
	y: 0
});
// Add left lane to the game
var leftLane = LK.getAsset('leftLane', {
	anchorX: 0.5,
	anchorY: 0.0,
	x: 50,
	y: 0
});
game.addChild(leftLane);
// Add right lane to the game
var rightLane = LK.getAsset('rightLane', {
	anchorX: 0.5,
	anchorY: 0.0,
	x: 2048 - 50,
	y: 0
});
game.addChild(rightLane);
// Add red horizontal line to the lower quarter of the map
var redLine = LK.getAsset('redLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 * 0.75 + 300
});
// Add grey horizontal target line to the upper quadrant of the map
var targetLine = LK.getAsset('targetLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 * 0.25
});
var whiteRing = LK.getAsset('whiteRing', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 * 0.25
});
var redRing = LK.getAsset('redRing', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 * 0.25
});
var blueRing = LK.getAsset('blueRing', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 * 0.25
});
game.addChild(blueRing);
game.addChild(whiteRing);
game.addChild(redRing);
// Add whiteCenter to the center of the redRing
var whiteCenter = LK.getAsset('whiteCenter', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: redRing.x,
	y: redRing.y
});
game.addChild(whiteCenter);
game.addChild(gameModeAsset1);
game.addChild(gameModeAsset2);
game.addChild(centerLine);
game.addChild(redLine);
game.addChild(targetLine);
var stoneSpacing = 200;
var totalStones = 8;
var startX = 2048 / 2 - stoneSpacing * (totalStones - 1) / 2;
var stone = game.addChild(new CurlingStone());
stone.x = startX;
stone.y = 2732 * 0.75 + 500 - 350;
stone.interactive = true;
stone.on('down', function () {
	if (selectedStone && selectedStone !== stone) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
		selectedStone.touched = false; // Reset touched state
	}
	if (startButton && startButton.visible === false) {
		stone.y = stone.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	} else {
		stone.y = stone.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500; // Allow movement above redline
	}
	selectedStone = stone;
	checkStartButtonVisibility();
});
stone.on('select', function () {
	// Logic for when stoneBlue is selected
	console.log("stoneBlue selected");
});
var stoneRed = game.addChild(new RedStone());
stoneRed.x = startX + stoneSpacing;
stoneRed.y = 2732 * 0.75 + 500 - 350;
stoneRed.interactive = true;
stoneRed.on('down', function () {
	if (selectedStone && selectedStone !== stoneRed) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stoneRed.y = stoneRed.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stoneRed;
	checkStartButtonVisibility();
});
var stoneYellow = game.addChild(new YellowStone());
stoneYellow.x = startX + stoneSpacing * 2;
stoneYellow.y = 2732 * 0.75 + 500 - 350;
stoneYellow.interactive = true;
stoneYellow.on('down', function () {
	if (selectedStone && selectedStone !== stoneYellow) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stoneYellow.y = stoneYellow.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stoneYellow;
	checkStartButtonVisibility();
});
var stoneGreen = game.addChild(new GreenStone());
stoneGreen.x = startX + stoneSpacing * 3;
stoneGreen.y = 2732 * 0.75 + 500 - 350;
stoneGreen.interactive = true;
stoneGreen.on('down', function () {
	if (selectedStone && selectedStone !== stoneGreen) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stoneGreen.y = stoneGreen.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stoneGreen;
	checkStartButtonVisibility();
});
var stoneOrange = game.addChild(new OrangeStone());
stoneOrange.x = startX + stoneSpacing * 4;
stoneOrange.y = 2732 * 0.75 + 500 - 350;
stoneOrange.interactive = true;
stoneOrange.on('down', function () {
	if (selectedStone && selectedStone !== stoneOrange) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stoneOrange.y = stoneOrange.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stoneOrange;
	checkStartButtonVisibility();
});
var stonePink = game.addChild(new PinkStone());
stonePink.x = startX + stoneSpacing * 5;
stonePink.y = 2732 * 0.75 + 500 - 350;
stonePink.interactive = true;
stonePink.on('down', function () {
	if (selectedStone && selectedStone !== stonePink) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stonePink.y = stonePink.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stonePink;
	checkStartButtonVisibility();
});
var stonePurple = game.addChild(new PurpleStone());
stonePurple.x = startX + stoneSpacing * 6;
stonePurple.y = 2732 * 0.75 + 500 - 350;
stonePurple.interactive = true;
stonePurple.on('down', function () {
	if (selectedStone && selectedStone !== stonePurple) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stonePurple.y = stonePurple.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stonePurple;
	checkStartButtonVisibility();
});
var stoneNeon = game.addChild(new NeonStone());
stoneNeon.x = startX + stoneSpacing * 7;
stoneNeon.y = 2732 * 0.75 + 500 - 350;
stoneNeon.interactive = true;
stoneNeon.on('down', function () {
	if (selectedStone && selectedStone !== stoneNeon) {
		selectedStone.y = 2732 * 0.75 + 500 - 350; // Reset previous stone position
	}
	stoneNeon.y = stoneNeon.y === 2732 * 0.75 + 500 ? 2732 * 0.75 + 500 - 350 : 2732 * 0.75 + 500;
	selectedStone = stoneNeon;
	checkStartButtonVisibility();
});
// Initialize the game state
var throwing = false;
var throwStart = null;
var isPlayerTurn = true; // Track whose turn it is, starting with player 1
var currentPlayer = 1; // Track the current player (1 or 2) in player vs player mode
var player1Stones = [];
var player2Stones = [];
// Handle touch events
game.down = function (x, y, obj) {
	if (selectedStone) {
		// Hide 'PLAYER START' text if it exists
		if (playerStartText) {
			playerStartText.visible = false;
		}
		// Hide 'PLAYER START' text if it exists
		if (playerStartText) {
			playerStartText.visible = false;
		}
		if (selectedStone.canMove && !selectedStone.touched && y > 2732 * 0.75 + 300 && y < 2732 && selectedStone.lastY <= 2732 * 0.75 + 300 && selectedStone.y <= 2732 * 0.75 + 300) {
			selectedStone.touched = true; // Mark the stone as touched
			selectedStone.lastX = selectedStone.x; // Update lastX before position change
			selectedStone.lastY = selectedStone.y; // Update lastY before position change
			selectedStone.x = x;
			selectedStone.y = y;
			selectedStone.interactive = false; // Disable interaction for dragging
			if (gameMode === 'playerVsPlayer' && isPlayerTurn) {
				// Switch to the second player's stone
				var secondPlayerStone = stones.find(function (stone) {
					return !stone.touched && stone.speed === 0;
				});
				if (secondPlayerStone) {
					selectedStone = secondPlayerStone;
				}
			} else if (gameMode === 'playerVsPlayer' && !isPlayerTurn) {}
			// Switch to the first player's stone
			var firstPlayerStone = stones.find(function (stone) {
				return stone.touched && stone.speed === 0;
			});
			if (firstPlayerStone) {
				selectedStone = firstPlayerStone;
			}
		}
		throwing = true;
	}
	throwStart = {
		x: x,
		y: y
	};
};
game.up = function (x, y, obj) {
	if (throwing && selectedStone) {
		// Hide 'PLAYER START' text if it exists
		if (playerStartText) {
			playerStartText.visible = false;
			playerStartText.destroy(); // Remove the text from the game
			playerStartText = null; // Clear the reference
		}
		var dx = x - throwStart.x; // Calculate the difference in x
		var dy = y - throwStart.y; // Calculate the difference in y
		var speed = Math.sqrt(dx * dx + dy * dy) / 50; // Adjust speed calculation for push
		var direction = Math.atan2(dy, dx); // Calculate direction
		selectedStone["throw"](speed, direction); // Apply throw with calculated speed and direction
		throwing = false;
		// Toggle turns between player and AI
		if (gameMode === 'playerVsPlayer') {
			isPlayerTurn = !isPlayerTurn;
			currentPlayer = isPlayerTurn ? 1 : 2; // Switch between player 1 and player 2
			if (isPlayerTurn) {
				// Load the second player's stone
				var secondPlayerStone = stones.find(function (stone) {
					return !stone.touched && stone.speed === 0;
				});
				if (secondPlayerStone) {
					secondPlayerStone.touched = true;
					game.addChild(secondPlayerStone);
				}
			} else {
				// Load the first player's stone
				var firstPlayerStone = stones.find(function (stone) {
					return stone.touched && stone.speed === 0;
				});
				if (firstPlayerStone) {
					firstPlayerStone.touched = true;
					game.addChild(firstPlayerStone);
				}
			}
			if (!isPlayerTurn) {
				// Load the second player's stone
				var secondPlayerStone = stones.find(function (stone) {
					return !stone.touched && stone.speed === 0;
				});
				if (secondPlayerStone) {
					secondPlayerStone.touched = true;
					game.addChild(secondPlayerStone);
				}
			}
		} else if (gameMode === 'playerVsAI' && isPlayerTurn) {
			isPlayerTurn = false; // Switch to AI's turn
			aiTakeTurn(); // Trigger AI's turn
		}
		if (!isPlayerTurn && !selectedStone.touched) {
			if (gameMode === 'playerVsAI') {
				aiTakeTurn();
			} else if (gameMode === 'playerVsPlayer') {
				// Switch to the next player's turn
				isPlayerTurn = true;
			}
		}
	}
};
// Update the game state
game.update = function () {
	// Removed game over condition when stone intersects target
	if (selectedStone) {
		if (gameMode === 'playerVsPlayer') {
			if (isPlayerTurn && currentPlayer === 1) {
				player1Stones.push(selectedStone);
			} else if (!isPlayerTurn && currentPlayer === 2) {
				player2Stones.push(selectedStone);
			}
		}
		// I care about the exact frame when I intersect, so check I was not intersecting / colliding before
		if (selectedStone.lastWasIntersecting === false && selectedStone.intersects(anotherObject)) {
			console.log("Intersection with the target!");
			// Additional logic for when the stone intersects with the target
		}
		selectedStone.lastWasIntersecting = selectedStone.intersects(anotherObject);
		selectedStone.update();
		if (selectedStone.lastX !== selectedStone.x || selectedStone.lastY !== selectedStone.y) {
			selectedStone.lastX = selectedStone.x; // Update lastX before position change
			selectedStone.lastY = selectedStone.y; // Update lastY before position change
		}
		// Check if the stone has reached the target line
		if (selectedStone.lastY <= 2732 * 0.25 && selectedStone.y > 2732 * 0.25) {
			console.log("Stone reached the target line!");
			// Additional logic for when the stone reaches the target line
		}
	}
};
function startButtonClickHandler() {
	// Move the selected stone to the center line bottom under the red line center
	if (selectedStone) {
		selectedStone.x = 2048 / 2; // Center horizontally
		selectedStone.y = 2732 * 0.75 + 400; // Position between the red line and the center bottom
		selectedStone.interactive = false; // Disable interaction for dragging
	}
	// AI selects a stone of a different color
	var stones = [stone, stoneRed, stoneYellow, stoneGreen, stoneOrange, stonePink, stonePurple, stoneNeon];
	var aiSelectedStone = null;
	do {
		aiSelectedStone = stones[Math.floor(Math.random() * stones.length)];
	} while (aiSelectedStone === selectedStone);
	// Move AI selected stone to a different position
	if (aiSelectedStone) {
		aiSelectedStone.x = 2048 / 2 + 100; // Slightly offset from the player's stone
		aiSelectedStone.y = 2732 * 0.75 + 400;
		aiSelectedStone.touched = true; // Mark the AI stone as touched
		if (!aiSelectedStone.parent) {
			game.addChild(aiSelectedStone); // Add AI's stone to the game
		}
	}
	// Hide non-selected stones
	var stones = [stone, stoneRed, stoneYellow, stoneGreen, stoneOrange, stonePink, stonePurple, stoneNeon];
	stones.forEach(function (stone) {
		if (stone !== selectedStone) {
			stone.visible = false;
		}
		stone.interactive = false; // Disable interaction for all stones
	});
	// Hide other specified assets
	gameModeAsset1.visible = false;
	gameModeAsset2.visible = false;
	leftButton.visible = false;
	playervsaiAsset.visible = false;
	playervsplayerAsset.visible = false;
	rightButton.visible = false;
	selectAsset.visible = false;
	selectGreenAsset.visible = false;
	if (startButton && startButton.visible) {
		// Add 'PLAYER START' text to the top center of the map
		var playerStartText = new Text2('PLAYER START', {
			size: 75,
			fill: 0x000000
		});
		playerStartText.anchor.set(0.5, 0.5);
		playerStartText.x = 2048 / 2 - 20;
		playerStartText.y = 75; // Position at the top center, moved up by 25 units 
		game.addChild(playerStartText);
		startButton.destroy(); // Destroy the startButton to ensure it disappears completely
		startButton = null; // Set startButton to null to remove reference
	}
	// Remove texts from the map
	gameModePopup.visible = false;
} ===================================================================
--- original.js
+++ change.js
@@ -338,9 +338,9 @@
 			game.addChild(aiSelectedStone);
 		}
 	}
 	// Toggle back to player's turn
-	isPlayerTurn = false; // Start with AI's turn
+	isPlayerTurn = true; // Switch back to player's turn after AI's turn
 }
 function isExactlyOneStoneBelowRedLine() {
 	var stones = [stone, stoneRed, stoneYellow, stoneGreen, stoneOrange, stonePink, stonePurple, stoneNeon];
 	var count = 0;
@@ -778,18 +778,8 @@
 			}
 		} else if (gameMode === 'playerVsAI' && isPlayerTurn) {
 			isPlayerTurn = false; // Switch to AI's turn
 			aiTakeTurn(); // Trigger AI's turn
-		} else if (gameMode === 'playerVsAI' && !isPlayerTurn) {
-			isPlayerTurn = true; // Switch back to player's turn
-			// Load the player's stone
-			var playerStone = stones.find(function (stone) {
-				return stone.touched && stone.speed === 0;
-			});
-			if (playerStone) {
-				playerStone.touched = true;
-				game.addChild(playerStone);
-			}
 		}
 		if (!isPlayerTurn && !selectedStone.touched) {
 			if (gameMode === 'playerVsAI') {
 				aiTakeTurn();
:quality(85)/https://cdn.frvr.ai/671ffaa31b725d4fe7b009de.png%3F3) 
 black curling stone with pink top, top view.
:quality(85)/https://cdn.frvr.ai/671ffcb81b725d4fe7b00a19.png%3F3) 
 Black curlingstone with purple top, top view.
:quality(85)/https://cdn.frvr.ai/671ffd891b725d4fe7b00a47.png%3F3) 
 Black curlingstone with yellow top, top view.
:quality(85)/https://cdn.frvr.ai/671ffeeb1b725d4fe7b00a97.png%3F3) 
 Black curlingstone with orange top, top view.
:quality(85)/https://cdn.frvr.ai/6720068b1b725d4fe7b00b4f.png%3F3) 
 black curlingstone with neongreen top, top view.
:quality(85)/https://cdn.frvr.ai/672008901b725d4fe7b00ba3.png%3F3) 
 Black curlingstone with neonblue top, top view.
:quality(85)/https://cdn.frvr.ai/6722a290f77c0bb2345fd7cd.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6722b80af77c0bb2345fd838.png%3F3) 
 add a text to the center: "Player vs Player"
:quality(85)/https://cdn.frvr.ai/672358df0ac8f145edb50384.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67235fd60ac8f145edb503bd.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/672363490ac8f145edb503e6.png%3F3) 
 neongreen rectangle with rounded corners, transparent in the middle.
:quality(85)/https://cdn.frvr.ai/67236c550ac8f145edb50434.png%3F3) 
 Red button with white start text.
:quality(85)/https://cdn.frvr.ai/679bf1716d4a9a00c2ea7f9d.png%3F3)