Code edit (7 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: x is not defined' in or related to this line: 'changeToText.x = x; // x coordinate as per requirement' Line Number: 394
User prompt
add a new text block to screen saying "Change To:" with x and y variables. do not touch score text
User prompt
Fix Bug: 'Uncaught ReferenceError: topRightImage is not defined' in or related to this line: 'var topRightImageGraphics = topRightImage.attachAsset('imageId', {' Line Number: 391
User prompt
Fix Bug: 'Uncaught ReferenceError: customizableX is not defined' in or related to this line: 'changeToText.x = customizableX; // Replace 'customizableX' with the desired x coordinate' Line Number: 388
User prompt
add text to to screen saying "Change To:" with x and y coordinates that can be changed
Code edit (2 edits merged)
Please save this source code
User prompt
Add text saying "Change" 50pixels above imageID
Code edit (1 edits merged)
Please save this source code
User prompt
correct text2 code so it shows on teh screen
Code edit (5 edits merged)
Please save this source code
User prompt
change text2 hieght to be 150 from top of screen
Code edit (12 edits merged)
Please save this source code
User prompt
Add text above imageID
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture('Zbert1');' Line Number: 108
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture('Zbert1');' Line Number: 108
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture(LK.getAsset('Zbert1', {}));' Line Number: 108
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture(LK.getAsset('Zbert1', {}));' Line Number: 108
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.up, {}));' Line Number: 108
User prompt
Fix Bug: 'TypeError: self.zbertGraphics.setTexture is not a function' in or related to this line: 'self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.up, {}));' Line Number: 108
Code edit (3 edits merged)
Please save this source code
User prompt
correct code to ensure texture swap takes place when Zbert moves
User prompt
Correct issue with zbert by preloading or retrieving the necessary textures for both Zbert1 and Zbert2 and then swapping the `texture` property of the `zbertGraphics` sprite with the appropriate preloaded texture when Zbert changes direction. This would be done without calling `LK.getAsset` within the `move` method each time a direction change occurs.
Code edit (6 edits merged)
Please save this source code
/**** 
* Classes
****/
var ControlButton = Container.expand(function (assetId, x, y, rotation, controlDirection) {
	var self = Container.call(this);
	self.on('up', function (obj) {
		buttonGraphics.tint = 0xFFFFFF; // Remove tint
	});
	var buttonGraphics = self.attachAsset(assetId, {
		anchorX: 0.5,
		anchorY: 0.5,
		x: x,
		y: y,
		rotation: rotation,
		alpha: 0.5
	});
	self.controlDirection = controlDirection;
	self.on('down', function (obj) {
		buttonGraphics.tint = 0x000000; // Tint button orange
		var zbert = game.grid.children.find(function (child) {
			return child instanceof Zbert;
		});
		if (zbert) {
			zbert.move(self.controlDirection);
		}
	});
});
var BBall = Container.expand(function (gridX, gridY, width, height) {
	var self = Container.call(this);
	self.isBBallJumping = false;
	self.move = function () {
		if (self.isBBallJumping || !self.parent) {
			return;
		}
		self.isBBallJumping = true;
		var tileWidth = 250;
		var tileHeight = 270;
		var arcHeight = 150;
		var direction = Math.random() < 0.5 ? 'downLeft' : 'downRight';
		var targetX = self.x + (direction === 'downLeft' ? -tileWidth / 2 : tileWidth / 2);
		var targetY = self.y + tileHeight - 90;
		var startX = self.x;
		var startY = self.y;
		var distanceX = targetX - startX;
		var distanceY = targetY - startY;
		var startTime = Date.now();
		var travelTime = 400;
		var bballTickHandler = function bballTickHandler() {
			var currentTime = Date.now();
			var timeElapsed = currentTime - startTime;
			if (timeElapsed < travelTime) {
				var progress = timeElapsed / travelTime;
				var arcProgress = Math.sin(progress * Math.PI);
				self.x = startX + distanceX * progress;
				self.y = startY + distanceY * progress - arcHeight * arcProgress;
			} else {
				self.x = targetX;
				self.y = targetY;
				LK.off('tick', bballTickHandler);
				self.isBBallJumping = false;
				var tileBelow = game.grid.getTileAt(self.x, self.y + tileHeight / 2);
				if (!tileBelow) {
					self.parent.removeChild(self);
					// Spawn a new BBall at the top
					var newBBall = new BBall(game.grid.tileArray[0][0].x, game.grid.tileArray[0][0].y - 150, 180, 180);
					game.grid.addChild(newBBall);
					// Trigger the move of the new BBall
					newBBall.move();
				}
			}
		};
		LK.on('tick', bballTickHandler);
		LK.setTimeout(self.move, travelTime + 50);
	};
	var BBallGraphics = self.attachAsset('bouncingBall', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	BBallGraphics.width = width;
	BBallGraphics.height = height;
	self.x = gridX;
	self.y = gridY;
});
var Zbert = Container.expand(function (gridX, gridY, width, height) {
	var self = Container.call(this);
	self.isZbertJumping = false;
	self.move = function (direction) {
		if (self.isZbertJumping) {
			return;
		}
		self.isZbertJumping = true;
		var moveX = 0;
		var moveY = 0;
		var tileWidth = 250;
		var tileHeight = 270;
		var arcHeight = 130;
		var targetX = self.x;
		var targetY = self.y;
		switch (direction) {
			case 'upLeft':
				targetX -= tileWidth / 2 + 2;
				targetY -= tileHeight - 90;
				self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.up, {}));
				break;
			case 'upRight':
				targetX += tileWidth / 2;
				targetY -= tileHeight - 90;
				self.zbertGraphics.texture = zbertTextures.up;
				break;
			case 'downLeft':
				targetX -= tileWidth / 2;
				targetY += tileHeight - 90;
				self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.down, {}));
				break;
			case 'downRight':
				targetX += tileWidth / 2;
				targetY += tileHeight - 90;
				self.zbertGraphics.texture = zbertTextures.down;
				break;
		}
		var startX = self.x;
		var startY = self.y;
		var distanceX = targetX - startX;
		var distanceY = targetY - startY;
		var startTime = Date.now();
		var travelTime = 300;
		var zbertTickHandler = function zbertTickHandler() {
			var currentTime = Date.now();
			var timeElapsed = currentTime - startTime;
			if (timeElapsed < travelTime) {
				var progress = timeElapsed / travelTime;
				var arcProgress = Math.sin(progress * Math.PI);
				self.x = startX + distanceX * progress;
				self.y = startY + distanceY * progress - arcHeight * arcProgress;
			} else {
				self.x = targetX;
				self.y = targetY;
				LK.off('tick', zbertTickHandler);
				self.isZbertJumping = false;
				var tileBelow = game.grid.getTileAt(self.x, self.y + tileHeight);
				if (tileBelow) {
					tileBelow.flipColor();
					if (game.grid.checkWinCondition()) {
						game.showWin();
					}
				} else {
					self.x = game.grid.x - self.width;
					self.y = 0;
					var fallToY = game.height - self.height / 2;
					var fallDuration = 4000;
					var fallStartTime = Date.now();
					var zbertFallTickHandler = function zbertFallTickHandler() {
						var currentTime = Date.now();
						var timeElapsed = currentTime - fallStartTime;
						if (timeElapsed < fallDuration) {
							var fallProgress = timeElapsed / fallDuration;
							self.y = fallProgress * fallToY;
						} else {
							self.y = fallToY;
							LK.off('tick', zbertFallTickHandler);
							self.isZbertJumping = false;
						}
					};
					LK.on('tick', zbertFallTickHandler);
				}
			}
		};
		LK.on('tick', zbertTickHandler);
	};
	self.zbertGraphics = self.attachAsset('Zbert1', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.zbertGraphics.width = width;
	self.zbertGraphics.height = height;
	self.x = gridX;
	self.y = gridY;
});
// Grid class to manage the puzzle grid
var Grid = Container.expand(function () {
	var self = Container.call(this);
	// Method to get the tile at a specific x and y position
	self.getTileAt = function (x, y) {
		for (var i = 0; i < this.tileArray.length; i++) {
			for (var j = 0; j < this.tileArray[i].length; j++) {
				var tile = this.tileArray[i][j];
				if (x >= tile.x - tile.width / 2 && x <= tile.x + tile.width / 2 && y >= tile.y - tile.height / 2 && y <= tile.y + tile.height / 2) {
					return tile;
				}
			}
		}
		return null;
	};
	this.gridSize = 13; // Gridsize control - 13 gives 7 wide middle
	this.tileArray = []; // Array to hold the tiles
	var tileColorCounter = {
		whiteCount: 0,
		greenCount: 0
	}; // Object to keep track of tile colors
	// Initialize the grid with tiles
	self.initGrid = function () {
		var tileWidth = 250;
		var tileHeight = 270;
		for (var i = 0; i < this.gridSize; i++) {
			this.tileArray[i] = []; // Initialize the row in tileArray
			var numTilesInRow = i < 7 ? i + 1 : this.gridSize - i;
			var rowOffset = (this.gridSize - numTilesInRow) * (tileWidth / 2);
			for (var j = 0; j < numTilesInRow; j++) {
				var tile = new Tile(i, j, tileWidth, tileHeight, this.gridSize);
				tile.x = rowOffset + j * tileWidth;
				tile.y = i * (tileHeight - 90);
				this.tileArray[i][j] = tile;
				self.addChild(tile);
				if (i === this.gridSize - 1 && j === numTilesInRow - 1) {
					// Add Zbert after all tiles have been added
					var zbert = self.children.find(function (child) {
						return child instanceof Zbert;
					});
					if (!zbert) {
						zbert = new Zbert(tile.x, tile.y - 150, 180, 180);
					} else {
						zbert.x = tile.x;
						zbert.y = tile.y - 150;
						zbert.isZbertJumping = false; // Ensure Zbert can move immediately
					}
					self.addChild(zbert);
					// Spawn a gem on random tiles except the bottom row
					var spawnGem = function spawnGem() {
						var randomRow = Math.floor(Math.random() * (self.gridSize - 2));
						var randomCol = Math.floor(Math.random() * self.tileArray[randomRow].length);
						var randomTile = self.tileArray[randomRow][randomCol];
						var gem = new Gem(randomTile.x, randomTile.y - 90, 150, 150);
						self.addChild(gem);
						// Set a timer to destroy the gem after 15 seconds
						LK.setTimeout(function () {
							if (gem.parent) {
								gem.destroy();
							}
						}, 15000);
					};
					// Spawn gems at random intervals
					var spawnInterval = Math.random() * (30000 - 15000) + 15000; // Random time between 15 to 30 seconds
					LK.setInterval(spawnGem, spawnInterval);
				}
			}
		}
	};
	// Check if all tiles are the same color
	self.checkWinCondition = function () {
		var firstColor = this.tileArray[0][0].color;
		for (var i = 0; i < this.gridSize; i++) {
			for (var j = 0; j < this.tileArray[i].length; j++) {
				if (this.tileArray[i][j].color !== targetColours[targetColourIndex]) {
					return false;
				}
			}
		}
		return true;
	};
});
var Tile = Container.expand(function (gridX, gridY, width, height, gridSize) {
	var self = Container.call(this);
	self.gridSize = gridSize;
	self.color = gridX === self.gridSize - 1 && gridY === 0 ? targetColours[targetColourIndex] : 0xFFFFFF; // Set all cells to white apart from the cell Zbert is on in the bottom left corner, set this cell to green
	var tileGraphics = self.attachAsset('tile', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	tileGraphics.width = width;
	tileGraphics.height = height;
	tileGraphics.tint = self.color;
	// Function to highlight the tile
	self.highlight = function (color) {
		tileGraphics.tint = color;
		LK.setTimeout(function () {
			tileGraphics.tint = self.color;
		}, 500); // Reset tint after 500ms
	};
	// Function to flip the color of the tile
	self.flipColor = function () {
		self.color = targetColours[targetColourIndex];
		tileGraphics.tint = self.color;
		LK.setScore(LK.getScore() + 25);
		scoreDisplay.updateScore(LK.getScore());
	};
});
var LevelManager = Container.expand(function () {
	var self = Container.call(this);
	self.showWin = function () {
		LK.effects.flashScreen(0xFF0000, 1000); // Flash the screen green for 1 second
		setBackgroundByNumber(Math.floor(Math.random() * 6) + 1);
		if (game.grid.checkWinCondition()) {
			// Move to the next target colour
			if (++targetColourIndex >= targetColours.length) {
				targetColourIndex = 0;
			}
			// Reset the grid for a new level with the next target colour
			setBackgroundByNumber(Math.floor(Math.random() * 6) + 1);
			game.grid.initGrid();
			game.grid.x = (2048 - tileWidth * game.grid.gridSize) / 2 + tileWidth / 2;
			game.grid.y = (2732 - tileHeight * game.grid.gridSize) / 2 + tileHeight / 2 + 600;
		}
	};
});
var Gem = Container.expand(function (gridX, gridY, width, height) {
	var self = Container.call(this);
	var gemGraphics = self.attachAsset('gem', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	gemGraphics.width = width;
	gemGraphics.height = height;
	self.x = gridX;
	self.y = gridY;
	// Function to collect the gem
	self.collect = function () {
		// Increase score by 100 when Zbert collects a gem
		LK.setScore(LK.getScore() + 100);
		self.destroy();
	};
});
var ScoreText = Container.expand(function () {
	var self = Container.call(this);
	var scoreTxt = new Text2('0', {
		size: 100,
		weight: 800,
		fill: "#ffffff"
	});
	scoreTxt.anchor.set(0.5, 0);
	self.addChild(scoreTxt);
	self.updateScore = function (newScore) {
		scoreTxt.setText(newScore.toString());
	};
});
/**** 
* Initialize Game
****/
// Instantiate LevelManager and replace the old showWin function
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/
// Preload Zbert textures
var zbertTextures = {
	up: 'Zbert1',
	down: 'Zbert2'
};
var scoreDisplay = new ScoreText();
LK.gui.top.addChild(scoreDisplay);
// Grid class to manage the puzzle grid
// Function to select and set background by variable number
function controlBBallMovement(direction) {
	var bball = game.grid.children.find(function (child) {
		return child instanceof BBall;
	});
	if (bball) {
		bball.move(direction);
	}
}
var tileArray = [];
var targetColours = [0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0x800000, 0x808000, 0x008000, 0x800080, 0x008080, 0x000080];
var targetColourIndex = 0;
var setBackgroundByNumber = function setBackgroundByNumber() {
	var backgroundNumber = Math.floor(Math.random() * 6) + 1;
	// Remove the current background if it exists
	if (game.background) {
		game.removeChild(game.background);
	}
	// Create a new background asset based on the provided number
	game.background = game.createAsset('backgroundImage' + backgroundNumber, {});
	game.background.width = 3000;
	game.background.height = 3000;
	game.background.x = 2048 / 2 - game.background.width / 2;
	game.background.y = 2732 / 2 - game.background.height / 2;
	// Add the new background to the game
	game.addChildAt(game.background, 0);
};
// Set an initial background
setBackgroundByNumber(2);
// Add image to top right corner of screen
var topRightImage = game.addChild(new Container());
topRightImage.x = 2048 - 200 - LK.getAsset('imageId', {}).width;
topRightImage.y = 300;
var topRightImageGraphics = topRightImage.attachAsset('imageId', {
	anchorX: 0.5,
	anchorY: 0.5
});
topRightImageGraphics.tint = targetColours[targetColourIndex];
// Add Corner asset to the screen
var CCupL = game.addChild(new ControlButton('CCupL', -125, 2478, -45, 'upLeft'));
var CCupR = game.addChild(new ControlButton('CCupR', 2170, 2507, 45, 'upRight'));
var CCdownL = game.addChild(new ControlButton('CCdownR', 340, 2769, -45, 'downRight'));
var CCdownR = game.addChild(new ControlButton('CCdownL', 1690, 2805, 45, 'downLeft'));
// Add the grid to the game
game.grid = game.addChild(new Grid());
game.grid.initGrid();
var tileWidth = 250;
var tileHeight = 270;
game.grid.x = (2048 - tileWidth * game.grid.gridSize) / 2 + tileWidth / 2;
game.grid.y = (2732 - tileHeight * game.grid.gridSize) / 2 + tileHeight / 2 + 600;
// Instantiate LevelManager and replace the old showWin function
var levelManager = new LevelManager();
game.showWin = levelManager.showWin;
// Method to spawn new BBalls at random intervals between 4 to 10 seconds
function spawnBBall() {
	var spawnInterval = Math.random() * (10000 - 4000) + 4000; // Random time between 4 to 10 seconds
	LK.setTimeout(function () {
		// Only spawn a new BBall if there are less than 3 BBalls on screen
		var bballCount = game.grid.children.reduce(function (count, child) {
			return count + (child instanceof BBall ? 1 : 0);
		}, 0);
		if (bballCount < 3) {
			//limit number of balls to 3 at any one time
			var bball = new BBall(game.grid.tileArray[0][0].x, game.grid.tileArray[0][0].y - 150, 180, 180);
			game.grid.addChild(bball);
			bball.move();
		}
		spawnBBall(); // Recursively call to continue spawning
	}, spawnInterval);
}
// Start spawning BBalls
spawnBBall();
LK.on('tick', function () {
	var zbert = game.grid.children.find(function (child) {
		return child instanceof Zbert;
	});
	var bball = game.grid.children.find(function (child) {
		return child instanceof BBall;
	});
	var gem = game.grid.children.find(function (child) {
		return child instanceof Gem;
	});
	if (zbert && bball && zbert.intersects(bball)) {
		LK.effects.flashScreen(0x000000, 1000);
		LK.showGameOver();
	}
	if (zbert && gem && zbert.intersects(gem)) {
		gem.collect();
	}
	// Rest of the tick code...
}); ===================================================================
--- original.js
+++ change.js
@@ -99,9 +99,9 @@
 		switch (direction) {
 			case 'upLeft':
 				targetX -= tileWidth / 2 + 2;
 				targetY -= tileHeight - 90;
-				self.zbertGraphics.texture = zbertTextures.up;
+				self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.up, {}));
 				break;
 			case 'upRight':
 				targetX += tileWidth / 2;
 				targetY -= tileHeight - 90;
@@ -109,9 +109,9 @@
 				break;
 			case 'downLeft':
 				targetX -= tileWidth / 2;
 				targetY += tileHeight - 90;
-				self.zbertGraphics.texture = zbertTextures.down;
+				self.zbertGraphics.setTexture(LK.getAsset(zbertTextures.down, {}));
 				break;
 			case 'downRight':
 				targetX += tileWidth / 2;
 				targetY += tileHeight - 90;
@@ -345,10 +345,10 @@
 * Game Code
 ****/
 // Preload Zbert textures
 var zbertTextures = {
-	up: LK.getAsset('Zbert1', {}),
-	down: LK.getAsset('Zbert2', {})
+	up: 'Zbert1',
+	down: 'Zbert2'
 };
 var scoreDisplay = new ScoreText();
 LK.gui.top.addChild(scoreDisplay);
 // Grid class to manage the puzzle grid
 beautiful landscape. starry sky, pastel colours, high definition, alien world. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 beautiful landscape. starry sky, pastel colours, high definition, alien world.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 beautiful expansive landscape. starry sky, pastel colours, high definition, alien world.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 beautiful expansive landscape. starry sky, pastel colours, high definition, alien world.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 A little cube person. 2 legs. back to viewer. facing 45 degrees to the right. multicoloured skin, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 white circle. metallic. light bevel on edge. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 
 Round furry, cute alien ball with big eyes. vivid colours, looking at 45 degrees to the right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 bright 3d present with bow, vivd colours. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Change to be vivid multicoloured cube
 A simple Triangle, flat shaded, bevelled edges. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Speech bubble with expletive word in it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 parachute. multicoloured. cartoon style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 white circle with a single thin black border. flat shade. simple graphic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 small star shape, vivid metallic blue, varying length spikes on star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.