Code edit (2 edits merged)
Please save this source code
User prompt
in gem code add option to randomly select graphic displayed. graphic options are gem, NewLife and 2xBonus
Code edit (1 edits merged)
Please save this source code
User prompt
when level changes adjust alien spawn so its in front of tiles and not behind
User prompt
If gold tile below gem no longer has gem above it then flip tile to target colour if gem been collected back to start colour if gem tile not been flipped
Code edit (7 edits merged)
Please save this source code
User prompt
when zbert respawns check to see if Zbert is already at spawnpoint and if so remove duplicate
User prompt
correct code so that when Zbert falls off grid stop jump from triggering a second time
Code edit (1 edits merged)
Please save this source code
User prompt
When Zbert moves up right and has no tile below him then end game
User prompt
Fix Bug: 'TypeError: self.fall is not a function' in or related to this line: 'self.fall();' Line Number: 261
User prompt
When Zbert moves up right and goes off grid then run fall routine for zbert
Code edit (1 edits merged)
Please save this source code
User prompt
When Zbert moves up right and reaches the second to last tile if zbert moves upright again then activate the fall routine
User prompt
When Zbert moves up right when Zbert lands on last tile trigger fall action
User prompt
Fix Bug: 'Uncaught ReferenceError: tileGraphics is not defined' in or related to this line: 'tileGraphics.tint = 0x000000;' Line Number: 397
User prompt
Fix Bug: 'Uncaught TypeError: tile.tint is not a function' in or related to this line: 'tile.tint(0x000000);' Line Number: 397
User prompt
Tint the centre tile of the grid black when setting up grid
Code edit (1 edits merged)
Please save this source code
User prompt
start zebert falling animation 80 lower on y
User prompt
for detection of intersect with Zbert for Alien and ball minus 150 on Y axis to compensate for Zberts offset
User prompt
add in collision detection between the Alien and zbert
Code edit (1 edits merged)
Please save this source code
User prompt
When zbert is hit make sure balls and aliens are cleared from screen
User prompt
when zebert gets hit stop stop Ball, alien and zberts movement so only one hit is registered
/**** * Classes ****/ var ControlButton = Container.expand(function (assetId, x, y, rotation, controlDirection) { var self = Container.call(this); function reduceLife() { livesCount--; if (livesCount < 0) { LK.showGameOver(); } else { // Update lives display livesDisplay[livesCount].visible = false; } } LK.on('tick', function () { var controlButtons = game.children.filter(function (child) { return child instanceof ControlButton; }); controlButtons.forEach(function (button) { if (button.isPressed) { var zbert = game.grid.children.find(function (child) { return child instanceof Zbert; }); if (zbert && !zbert.isZbertJumping && !zbert.isHitByBall) { zbert.move(button.controlDirection); } } }); }); 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.2 }); self.controlDirection = controlDirection; self.isPressed = false; self.on('down', function (obj) { buttonGraphics.tint = 0x36369b; // Tint button orange self.isPressed = true; }); self.on('up', function (obj) { buttonGraphics.tint = 0xFFFFFF; // Remove tint self.isPressed = false; }); }); 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 = Math.max(175, 600 - 25 * levelManager.completedLevels) + bballTravelTimeAddition; 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; // Adjust shadow size based on jump arc progress self.shadowGraphics.width = width * 0.8 * (1 - arcProgress * 0.3); self.shadowGraphics.height = height * 0.4 * (1 - arcProgress * 0.3); } else { self.x = targetX; self.y = targetY; LK.off('tick', bballTickHandler); self.isBBallJumping = false; // Reset shadow size when BBall lands self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; var tileBelow = game.grid.getTileAt(self.x, self.y + tileHeight / 2); if (!tileBelow) { if (self.parent) { 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); }; self.shadowGraphics = self.attachAsset('zbertShadow', { anchorX: 0.5, anchorY: 1.0, alpha: 0.4 }); self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; self.shadowGraphics.y = height * 0.5 + 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 Alien = Container.expand(function (gridX, gridY, width, height) { var self = Container.call(this); self.isAlienJumping = false; self.moveRight = true; // Initialize moveRight to true so the alien starts moving to the right self.move = function () { if (self.isAlienJumping || !self.parent) { return; } self.isAlienJumping = true; var tileWidth = 250; var tileHeight = 270; var arcHeight = 150; var directions = ['upRight', 'upLeft', 'downRight', 'downLeft']; var randomDirectionIndex = Math.floor(Math.random() * directions.length); var direction = directions[randomDirectionIndex]; var targetX = self.x + (direction === 'upLeft' || direction === 'downLeft' ? -tileWidth / 2 : tileWidth / 2); var targetY = self.y + (direction === 'upRight' || direction === 'upLeft' ? -tileHeight + 90 : tileHeight - 90); var startX = self.x; var startY = self.y; var distanceX = targetX - startX; var distanceY = targetY - startY; var startTime = Date.now(); var travelTime = Math.max(175, 600 - 25 * levelManager.completedLevels) + bballTravelTimeAddition; var alienTickHandler = function alienTickHandler() { 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; // Adjust shadow size based on jump arc progress self.shadowGraphics.width = width * 0.8 * (1 - arcProgress * 0.3); self.shadowGraphics.height = height * 0.4 * (1 - arcProgress * 0.3); } else { self.x = targetX; self.y = targetY; LK.off('tick', alienTickHandler); self.isAlienJumping = false; self.moveRight = !self.moveRight; // Toggle moveRight to change the direction for the next move // Reset shadow size when Alien lands self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; var tileBelow = game.grid.getTileAt(self.x, self.y + tileHeight / 2); if (!tileBelow) { if (self.parent) { self.parent.removeChild(self); } // Spawn a new Alien in middle of grid var middleRow = Math.floor(game.grid.gridSize / 2); var middleTile = game.grid.tileArray[middleRow][Math.floor(game.grid.tileArray[middleRow].length / 2)]; var newAlien = new Alien(middleTile.x, middleTile.y - 150, 180, 180); game.grid.addChildAt(newAlien, game.grid.children.length); // Trigger the move of the new Alien newAlien.move(); } } }; LK.on('tick', alienTickHandler); LK.setTimeout(self.move, travelTime + 50); }; self.shadowGraphics = self.attachAsset('zbertShadow', { anchorX: 0.5, anchorY: 1.0, alpha: 0.4 }); self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; self.shadowGraphics.y = height * 0.5 + 50; var alienGraphics = self.attachAsset('Part24', { // Use a different asset for the Alien anchorX: 0.5, anchorY: 0.5 }); alienGraphics.width = width; alienGraphics.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.isHitByBall = false; self.move = function (direction) { if (self.isZbertJumping || self.isFalling || self.isHitByBall) { 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; break; case 'upRight': targetX += tileWidth / 2; targetY -= tileHeight - 90; break; case 'downLeft': targetX -= tileWidth / 2; targetY += tileHeight - 90; break; case 'downRight': targetX += tileWidth / 2; targetY += tileHeight - 90; break; } var startX = self.x; var startY = self.y; var distanceX = targetX - startX; var distanceY = targetY - startY; var startTime = Date.now(); var ZtravelTime = 350; var zbertTickHandler = function zbertTickHandler() { var currentTime = Date.now(); var timeElapsed = currentTime - startTime; if (timeElapsed < ZtravelTime) { var progress = timeElapsed / ZtravelTime; var arcProgress = Math.sin(progress * Math.PI); self.x = startX + distanceX * progress; self.y = startY + distanceY * progress - arcHeight * arcProgress; // Adjust shadow size based on jump arc progress self.shadowGraphics.width = width * 0.8 * (1 - arcProgress * 0.3); self.shadowGraphics.height = height * 0.4 * (1 - arcProgress * 0.3); } else { self.x = targetX; self.y = targetY; // Reset shadow size when Zbert lands self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; LK.off('tick', zbertTickHandler); self.isZbertJumping = false; var tileBelow = game.grid.getTileAt(self.x, self.y + tileHeight / 2); if (tileBelow) { tileBelow.flipColor(); if (game.grid.checkWinCondition()) { game.showWin(); } } else { 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 = startY + 190 + (fallToY - startY) * fallProgress; self.shadowGraphics.visible = false; // Hide shadow during fall // Attach ZbertParachute to Zbert only if it's not already attached if (!self.parachuteGraphics) { self.parachuteGraphics = self.attachAsset('ZbertParachute', { anchorX: 0.5, anchorY: 0.5, y: -self.height / 2 - 50 }); } self.isFalling = true; } else { self.y = fallToY; LK.off('tick', zbertFallTickHandler); self.isZbertJumping = false; self.isFalling = false; self.shadowGraphics.visible = true; // Show shadow again (for the new Zbert) // Remove ZbertParachute when Zbert has finished falling and reset isFalling status if (self.parachuteGraphics) { self.removeChild(self.parachuteGraphics); self.parachuteGraphics = null; self.isFalling = false; } reduceLife(); if (livesCount > 0) { self.destroy(); var bottomTile = game.grid.tileArray[game.grid.gridSize - 1][0]; // Check if Zbert is already at the spawn point var existingZbert = game.grid.children.find(function (child) { return child instanceof Zbert && child.x === bottomTile.x && child.y === bottomTile.y - 150; }); // Only create and add a new Zbert if there isn't one already at the spawn point if (!existingZbert) { var newZbert = new Zbert(bottomTile.x, bottomTile.y - 150, 180, 180); game.grid.addChild(newZbert); } } else { LK.showGameOver(); } } }; LK.on('tick', zbertFallTickHandler); } } }; LK.on('tick', zbertTickHandler); }; self.shadowGraphics = self.attachAsset('zbertShadow', { anchorX: 0.5, anchorY: 1.0, alpha: 0.4 }); self.shadowGraphics.width = width * 0.8; self.shadowGraphics.height = height * 0.4; self.shadowGraphics.y = height * 0.5 + 50; 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 // 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) { if (gem.tileBelow) { gem.tileBelow.highlight(gem.tileBelow.color); // Tint the tile with the original colour } } if (gem.tileBelow && gem.tileBelow.color === targetColours[targetColourIndex]) { gem.tileBelow.color = 0xe2e0e0; // Reset to start color if tile was flipped gem.tileBelow.highlight(gem.tileBelow.color); } 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] : 0xe2e0e0; // 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; // Removed the reset of tint to maintain the color while the gem is visible }; // Function to flip the color of the tile self.flipColor = function () { if (self.color !== targetColours[targetColourIndex]) { 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.completedLevels = 0; 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; self.completedLevels++; maxBBalls = Math.min(6, maxBBalls + 1); bballTravelTimeAddition = Math.min(600, bballTravelTimeAddition + 100); // Reset the grid for a new level with the first target colour game.grid.initGrid(); } // 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; // Reset Zbert to the bottom tile var bottomTile = game.grid.tileArray[game.grid.gridSize - 1][0]; var zbert = game.grid.children.find(function (child) { return child instanceof Zbert; }); zbert.x = bottomTile.x; zbert.y = bottomTile.y - 150; zbert.isZbertJumping = false; // Remove any BBalls and Gems from the screen game.grid.children.slice().forEach(function (child) { if (child instanceof BBall || child instanceof Gem) { child.destroy(); } }); // Set image to match new target colour topRightImageGraphics.tint = targetColours[targetColourIndex]; } }; }); 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; self.tileBelow = game.grid.getTileAt(self.x + 100, self.y + 125); if (self.tileBelow) { self.tileBelow.highlight(0xFFD700); // Tint the tile gold } // Function to collect the gem self.collect = function () { // Increase score by 100 when Zbert collects a gem LK.setScore(LK.getScore() + 175); if (self.tileBelow.color !== targetColours[targetColourIndex]) { self.tileBelow.flipColor(); // Flip to target color if not already flipped } else { self.tileBelow.color = 0xe2e0e0; // Reset to start color if tile was already flipped self.tileBelow.highlight(self.tileBelow.color); } self.destroy(); }; }); var ZbertExpletive = Container.expand(function (x, y) { var self = Container.call(this); var expletiveGraphics = self.attachAsset('ZbertExpletive', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; }); var ScoreText = Container.expand(function () { var self = Container.call(this); var scoreTxt = new Text2('0', { size: 120, fill: "#ffffff", weight: 800, dropShadow: true, dropShadowColor: '#000000', dropShadowAngle: Math.PI / 6, dropShadowDistance: 5 }); scoreTxt.anchor.set(0.5, 0); self.addChild(scoreTxt); self.updateScore = function (newScore) { scoreTxt.setText(newScore.toString()); }; }); var Life = Container.expand(function (x, y, width, height) { var self = Container.call(this); self.attachAsset('Zbert2', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }).scale.set(0.5); }); var StarDisplay = Container.expand(function (assetId, x, y, scale, rotation) { var self = Container.call(this); if (assetId === 'ZB1' || assetId === 'ZB2') { var circleGraphics = self.attachAsset('whiteCircle', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); // Ensure the circle is behind ZB1 and ZB2 by adding it before their graphics self.addChildAt(circleGraphics, 0); } var starGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); starGraphics.scale.set(scale); starGraphics.rotation = rotation; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Instantiate and display stars on the screen var starDisplay1 = game.addChild(new StarDisplay('star1', 180, 2300, 1, -0.6)); var starDisplay2 = game.addChild(new StarDisplay('star2', 340, 2550, 1, 2.6)); var starDisplay3 = game.addChild(new StarDisplay('star3', 1850, 2340, 1, 0.6)); var starDisplay4 = game.addChild(new StarDisplay('star4', 1700, 2580, 1, -2.6)); var starDisplay4 = game.addChild(new StarDisplay('ZB1', 1770, 2450, 1, 0)); var starDisplay4 = game.addChild(new StarDisplay('ZB2', 260, 2430, 1, 0)); // Function to reduce lives and handle game over function reduceLife() { livesCount--; if (livesCount < 0) { LK.showGameOver(); } else { // Update lives display livesDisplay[livesCount].visible = false; } } var livesCount = 5; var livesDisplay = []; for (var i = 0; i < livesCount; i++) { var life = new Life(2048 - 200 - i * 100, 500, 90, 70); livesDisplay.push(life); game.addChild(life); } 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 maxBBalls = 2; var levelManager = new LevelManager(); var maxAliens = levelManager.completedLevels >= 3 ? 2 : 1; var bballTravelTimeAddition = 0; var targetColours = [0x77dd77, 0x779ecb, 0xfff49c, 0xcb99c9, 0xaec6cf, 0xfdfd96, 0x836953, 0xb39eb5, 0xffb347, 0xb19cd9, 0xff6961]; 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; // Add new Text2 object for 'Change To:' label var changeToText = new Text2('CHANGE TO:', { size: 60, fill: "#ffffff", weight: 800, dropShadow: true, dropShadowColor: '#000000', dropShadowAngle: Math.PI / 6, dropShadowDistance: 5 }); changeToText.anchor.set(0.5, 0.0); changeToText.x = 2048 / 2 + 140; // Center x coordinate changeToText.y = 40; // y coordinate 150 pixels from top LK.gui.addChild(changeToText); 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 var levelManager = new LevelManager(); game.showWin = levelManager.showWin; // Method to spawn new BBalls at random intervals between 4 to 10 seconds function spawnEntities() { var spawnInterval = Math.random() * (10000 - 4000) + 4000; // Random time between 4 to 10 seconds LK.setTimeout(function () { var bballCount = game.grid.children.reduce(function (count, child) { return count + (child instanceof BBall ? 1 : 0); }, 0); var alienCount = game.grid.children.reduce(function (count, child) { return count + (child instanceof Alien ? 1 : 0); }, 0); if (bballCount < maxBBalls) { 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(); } if (alienCount < maxAliens) { var middleRow = Math.floor(game.grid.gridSize / 2); var middleTile = game.grid.tileArray[middleRow][Math.floor(game.grid.tileArray[middleRow].length / 2)]; var alien = new Alien(middleTile.x, middleTile.y - 150, 180, 180); game.grid.addChild(alien); alien.move(); } spawnEntities(); // Recursively call to continue spawning }, spawnInterval); } // Start spawning entities spawnEntities(); 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; }); var alien = game.grid.children.find(function (child) { return child instanceof Alien; }); if (zbert && (bball || alien)) { var zbertCenter = { x: zbert.x + zbert.width / 2, y: zbert.y + zbert.height / 2 - 150 }; var bballCenter = bball ? { x: bball.x + bball.width / 2, y: bball.y + bball.height / 2 } : null; var alienCenter = alien ? { x: alien.x + alien.width / 2, y: alien.y + alien.height / 2 } : null; var zbertBballCollision = bball && zbert.intersects(bball); var zbertAlienCollision = alien && zbert.intersects(alien); if ((zbertBballCollision || zbertAlienCollision) && !zbert.isFalling && !zbert.isHitByBall) { // Stop Zbert and BBall movement zbert.isHitByBall = true; // Clear all BBalls and Aliens from the screen var bballs = game.grid.children.filter(function (child) { return child instanceof BBall; }); var aliens = game.grid.children.filter(function (child) { return child instanceof Alien; }); bballs.forEach(function (b) { b.destroy(); }); aliens.forEach(function (a) { a.destroy(); }); // Display ZbertExpletive above Zbert var expletive = zbert.addChild(new ZbertExpletive(55, -zbert.height + 40)); // Pause for 2 seconds LK.setTimeout(function () { // After pause, reset Zbert to start and remove a life reduceLife(); if (livesCount <= 0) { LK.showGameOver(); } else { var bottomTile = game.grid.tileArray[game.grid.gridSize - 1][0]; zbert.x = bottomTile.x; zbert.y = bottomTile.y - 150; zbert.isZbertJumping = false; // Allow Zbert to move // Delay resetting isHitByBall flag LK.setTimeout(function () { zbert.isHitByBall = false; // Reset hit by ball status after 2 seconds bballs.forEach(function (b) { b.isBBallJumping = false; }); aliens.forEach(function (a) { a.isAlienJumping = false; }); }, 1000); expletive.destroy(); // Remove expletive // Restart spawning entities spawnEntities(); } }, 2000); } } if (gem && zbert.intersects(gem)) { gem.collect(); } // Rest of the tick code... });
===================================================================
--- original.js
+++ change.js
@@ -490,11 +490,9 @@
};
});
var Gem = Container.expand(function (gridX, gridY, width, height) {
var self = Container.call(this);
- var gemAssets = ['gem', 'NewLife', '2xbonus'];
- var randomAsset = gemAssets[Math.floor(Math.random() * gemAssets.length)];
- var gemGraphics = self.attachAsset(randomAsset, {
+ var gemGraphics = self.attachAsset('gem', {
anchorX: 0.5,
anchorY: 0.5
});
gemGraphics.width = width;
@@ -517,35 +515,8 @@
}
self.destroy();
};
});
-var NewLife = Container.expand(function (gridX, gridY, width, height) {
- var self = Container.call(this);
- var NLGraphics = self.attachAsset('gem', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- NLGraphics.width = width;
- NLGraphics.height = height;
- self.x = gridX;
- self.y = gridY;
- self.tileBelow = game.grid.getTileAt(self.x + 100, self.y + 125);
- if (self.tileBelow) {
- self.tileBelow.highlight(0xFFD700); // Tint the tile gold
- }
- // Function to collect the gem
- self.collect = function () {
- // Increase score by 100 when Zbert collects a gem
- LK.setScore(LK.getScore() + 175);
- if (self.tileBelow.color !== targetColours[targetColourIndex]) {
- self.tileBelow.flipColor(); // Flip to target color if not already flipped
- } else {
- self.tileBelow.color = 0xe2e0e0; // Reset to start color if tile was already flipped
- self.tileBelow.highlight(self.tileBelow.color);
- }
- self.destroy();
- };
-});
var ZbertExpletive = Container.expand(function (x, y) {
var self = Container.call(this);
var expletiveGraphics = self.attachAsset('ZbertExpletive', {
anchorX: 0.5,
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.