Code edit (8 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
make the background bigger and put the score text under the level text and finally add background to the texts
User prompt
Create another pointEffect asset and when we destroy each block, a random one of these assets will appear ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Score texts like +10 +250 are coming, these should not come ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Look, when we combine the blocks and they disappear, they only produce a big effect, that is, not all of them and no text or anything like that. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The arrow we pulled should not be visible, instead when the block is destroyed, an asset should suddenly appear with the effect, then move up a little at medium speed and disappear with the effect. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
When we throw the arrow to one or two blocks, it disappears immediately.
User prompt
Ok, just check the things we wrote and destroy them so that they don't get worse! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The arrow should disappear when we select at least 3 blocks. We draw the arrow and it goes straight. It selects and destroys blocks that are not close to each other. Fix this error and Let's use the arrow to connect the blocks to each other, so that the arrow stays on the blocks and destroys them if appropriate. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
You removed the arrow logic, I said the blocks that will join with the arrow will disappear if it is suitable, you added back the block logic that disappears when touched. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
did you delete the arrow? bring it back! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the arrow extend symmetrically, that is, go straight like this and not get lost, let the blocks be combined and if appropriate, let them disappear. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
By the way, when we draw an arrow, it will be longer and white, that is, it will create a separate asset. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
You misunderstood what I said arrow. Let's say there are 3 blocks next to each other. Let's click on the first block and shoot a long arrow. When they touch each other, they won't be destroyed. In other words, if it's suitable, our arrow will be destroyed. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Look, instead of clicking on the appropriate colored blocks, let's hold them and pull them together so that they can disappear if appropriate. Also, there should be at least 3 same colored blocks so that we can combine them. Also, remove the moves logic from the game. Add white color asset as background ↪💡 Consider importing and using the following plugins: @upit/tween.v1 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
Initial prompt
Block Blast Puzzle
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Arrow = Container.expand(function (colorType) { var self = Container.call(this); self.colorType = colorType; self.directionX = 0; self.directionY = 0; self.speed = 800; self.isDestroyed = false; // Create arrow graphics - long white arrow var arrowGraphics = self.attachAsset('arrow', { anchorX: 0.5, anchorY: 0.5 }); self.setDirection = function (targetX, targetY) { // Calculate normalized direction vector var dx = targetX - self.x; var dy = targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.directionX = dx / distance; self.directionY = dy / distance; arrowGraphics.rotation = Math.atan2(dy, dx); } }; self.update = function () { if (self.isDestroyed) return; // Move in straight line using direction vector self.x += self.directionX * self.speed * (1 / 60); self.y += self.directionY * self.speed * (1 / 60); // Check collision with blocks self.checkBlockCollision(); // Remove arrow if it goes off screen if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) { self.destroyArrow(); } }; self.checkBlockCollision = function () { var gridX = Math.floor((self.x - GRID_START_X) / BLOCK_SIZE); var gridY = Math.floor((self.y - GRID_START_Y) / BLOCK_SIZE); if (gridX >= 0 && gridX < GRID_WIDTH && gridY >= 0 && gridY < GRID_HEIGHT) { var hitBlock = grid[gridX][gridY]; if (hitBlock && hitBlock.colorType === self.colorType) { // Get connected blocks of same color var connectedBlocks = getConnectedBlocks(gridX, gridY, self.colorType); if (connectedBlocks.length >= 3) { // Clear and blast connected blocks clearSelection(); selectedBlocks = connectedBlocks; blastSelectedBlocks(); } self.destroyArrow(); } } }; self.destroyArrow = function () { if (!self.isDestroyed) { self.isDestroyed = true; removeArrow(self); } }; return self; }); var Block = Container.expand(function (colorType) { var self = Container.call(this); self.colorType = colorType; self.gridX = 0; self.gridY = 0; self.isSelected = false; self.isDragging = false; self.originalX = 0; self.originalY = 0; var blockAssets = ['blockRed', 'blockBlue', 'blockGreen', 'blockYellow', 'blockPurple']; var blockGraphics = self.attachAsset(blockAssets[colorType], { anchorX: 0.5, anchorY: 0.5 }); self.setSelected = function (selected) { self.isSelected = selected; if (selected) { blockGraphics.alpha = 0.8; blockGraphics.scaleX = 1.05; blockGraphics.scaleY = 1.05; tween(blockGraphics, { tint: 0xFFFFAA }, { duration: 200 }); } else { blockGraphics.alpha = 1.0; blockGraphics.scaleX = 1.0; blockGraphics.scaleY = 1.0; tween(blockGraphics, { tint: 0xFFFFFF }, { duration: 200 }); } }; self.blast = function () { tween(blockGraphics, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var GRID_WIDTH = 8; var GRID_HEIGHT = 10; var BLOCK_SIZE = 200; var GRID_START_X = (2048 - GRID_WIDTH * BLOCK_SIZE) / 2; var GRID_START_Y = 400; var grid = []; var selectedBlocks = []; var currentLevel = 1; var currentScore = 0; var targetScore = 1000; var gameActive = true; var activeArrows = []; var shootingBlock = null; // Initialize grid array for (var x = 0; x < GRID_WIDTH; x++) { grid[x] = []; for (var y = 0; y < GRID_HEIGHT; y++) { grid[x][y] = null; } } // Add white background var background = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // UI Elements var scoreText = new Text2('Score: 0', { size: 80, fill: 0x000000 }); scoreText.anchor.set(0, 0); scoreText.x = 50; scoreText.y = 100; game.addChild(scoreText); var targetText = new Text2('Target: 1000', { size: 80, fill: 0x0066CC }); targetText.anchor.set(0.5, 0); targetText.x = 1024; targetText.y = 200; game.addChild(targetText); var levelText = new Text2('Level 1', { size: 100, fill: 0x000000 }); levelText.anchor.set(0.5, 0); levelText.x = 1024; levelText.y = 50; game.addChild(levelText); function createBlock(x, y) { var colorType = Math.floor(Math.random() * 5); var block = new Block(colorType); block.gridX = x; block.gridY = y; block.x = GRID_START_X + x * BLOCK_SIZE + BLOCK_SIZE / 2; block.y = GRID_START_Y + y * BLOCK_SIZE + BLOCK_SIZE / 2; grid[x][y] = block; game.addChild(block); return block; } function initializeGrid() { for (var x = 0; x < GRID_WIDTH; x++) { for (var y = 0; y < GRID_HEIGHT; y++) { createBlock(x, y); } } } function getConnectedBlocks(startX, startY, colorType, visited) { if (!visited) visited = []; var key = startX + ',' + startY; if (visited.indexOf(key) !== -1) return []; if (startX < 0 || startX >= GRID_WIDTH || startY < 0 || startY >= GRID_HEIGHT) return []; if (!grid[startX][startY] || grid[startX][startY].colorType !== colorType) return []; visited.push(key); var connected = [grid[startX][startY]]; // Check adjacent blocks (up, down, left, right) var directions = [[0, -1], [0, 1], [-1, 0], [1, 0]]; for (var i = 0; i < directions.length; i++) { var newX = startX + directions[i][0]; var newY = startY + directions[i][1]; var adjacentBlocks = getConnectedBlocks(newX, newY, colorType, visited); connected = connected.concat(adjacentBlocks); } return connected; } function clearSelection() { for (var i = 0; i < selectedBlocks.length; i++) { selectedBlocks[i].setSelected(false); } selectedBlocks = []; } function selectBlockGroup(block) { clearSelection(); selectedBlocks = getConnectedBlocks(block.gridX, block.gridY, block.colorType); if (selectedBlocks.length >= 3) { for (var i = 0; i < selectedBlocks.length; i++) { selectedBlocks[i].setSelected(true); } return true; } else { selectedBlocks = []; return false; } } function blastSelectedBlocks() { if (selectedBlocks.length < 3 || !gameActive) return; var points = calculateScore(selectedBlocks.length); currentScore += points; LK.getSound('blockBlast').play(); LK.effects.flashScreen(0xffffff, 200); // Remove blocks from grid and blast them for (var i = 0; i < selectedBlocks.length; i++) { var block = selectedBlocks[i]; grid[block.gridX][block.gridY] = null; block.blast(); } selectedBlocks = []; // Apply gravity after a short delay LK.setTimeout(function () { applyGravity(); updateUI(); checkGameState(); }, 400); } function calculateScore(blockCount) { return blockCount * blockCount * 10; } function applyGravity() { for (var x = 0; x < GRID_WIDTH; x++) { var writeY = GRID_HEIGHT - 1; // Move existing blocks down for (var y = GRID_HEIGHT - 1; y >= 0; y--) { if (grid[x][y] !== null) { if (writeY !== y) { grid[x][writeY] = grid[x][y]; grid[x][y] = null; grid[x][writeY].gridY = writeY; // Animate block falling var targetY = GRID_START_Y + writeY * BLOCK_SIZE + BLOCK_SIZE / 2; tween(grid[x][writeY], { y: targetY }, { duration: 300, easing: tween.easeOut }); } writeY--; } } // Fill empty spaces at top with new blocks for (var y = writeY; y >= 0; y--) { var newBlock = createBlock(x, y); newBlock.y = GRID_START_Y - (writeY - y + 1) * BLOCK_SIZE + BLOCK_SIZE / 2; var targetY = GRID_START_Y + y * BLOCK_SIZE + BLOCK_SIZE / 2; tween(newBlock, { y: targetY }, { duration: 500, easing: tween.bounceOut }); } } } function updateUI() { scoreText.setText('Score: ' + currentScore); LK.setScore(currentScore); } function checkGameState() { if (currentScore >= targetScore) { gameActive = false; LK.getSound('levelComplete').play(); LK.setTimeout(function () { nextLevel(); }, 1000); } } function removeArrow(arrow) { var index = activeArrows.indexOf(arrow); if (index !== -1) { activeArrows.splice(index, 1); } arrow.destroy(); } function nextLevel() { currentLevel++; targetScore = currentScore + 500 * currentLevel; gameActive = true; levelText.setText('Level ' + currentLevel); targetText.setText('Target: ' + targetScore); updateUI(); if (currentLevel >= 10) { LK.showYouWin(); } } game.down = function (x, y, obj) { if (!gameActive) return; var gridX = Math.floor((x - GRID_START_X) / BLOCK_SIZE); var gridY = Math.floor((y - GRID_START_Y) / BLOCK_SIZE); if (gridX >= 0 && gridX < GRID_WIDTH && gridY >= 0 && gridY < GRID_HEIGHT) { var block = grid[gridX][gridY]; if (block) { shootingBlock = block; selectBlockGroup(block); } else { clearSelection(); } } else { clearSelection(); } }; game.move = function (x, y, obj) { // No dragging mechanics needed for arrow shooting }; game.up = function (x, y, obj) { if (!gameActive || !shootingBlock) return; // Shoot arrow in direction of target var arrow = new Arrow(shootingBlock.colorType); arrow.x = shootingBlock.x; arrow.y = shootingBlock.y; arrow.setDirection(x, y); activeArrows.push(arrow); game.addChild(arrow); // Clear shooting state shootingBlock = null; clearSelection(); }; game.update = function () { // Update all active arrows for (var i = activeArrows.length - 1; i >= 0; i--) { var arrow = activeArrows[i]; if (arrow.update) { arrow.update(); } } }; // Initialize the game initializeGrid(); updateUI();
===================================================================
--- original.js
+++ change.js
@@ -8,44 +8,64 @@
****/
var Arrow = Container.expand(function (colorType) {
var self = Container.call(this);
self.colorType = colorType;
- self.targetX = 0;
- self.targetY = 0;
+ self.directionX = 0;
+ self.directionY = 0;
self.speed = 800;
- self.hasReached = false;
+ self.isDestroyed = false;
// Create arrow graphics - long white arrow
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5
});
- self.setTarget = function (targetX, targetY) {
- self.targetX = targetX;
- self.targetY = targetY;
- // Calculate rotation to point towards target
+ self.setDirection = function (targetX, targetY) {
+ // Calculate normalized direction vector
var dx = targetX - self.x;
var dy = targetY - self.y;
- arrowGraphics.rotation = Math.atan2(dy, dx);
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ self.directionX = dx / distance;
+ self.directionY = dy / distance;
+ arrowGraphics.rotation = Math.atan2(dy, dx);
+ }
};
self.update = function () {
- if (self.hasReached) return;
- // Move towards target
- var dx = self.targetX - self.x;
- var dy = self.targetY - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < 20) {
- self.hasReached = true;
- self.onReachTarget();
- return;
+ if (self.isDestroyed) return;
+ // Move in straight line using direction vector
+ self.x += self.directionX * self.speed * (1 / 60);
+ self.y += self.directionY * self.speed * (1 / 60);
+ // Check collision with blocks
+ self.checkBlockCollision();
+ // Remove arrow if it goes off screen
+ if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) {
+ self.destroyArrow();
}
- var moveX = dx / distance * self.speed * (1 / 60);
- var moveY = dy / distance * self.speed * (1 / 60);
- self.x += moveX;
- self.y += moveY;
};
- self.onReachTarget = function () {
- // This will be called when arrow reaches target
+ self.checkBlockCollision = function () {
+ var gridX = Math.floor((self.x - GRID_START_X) / BLOCK_SIZE);
+ var gridY = Math.floor((self.y - GRID_START_Y) / BLOCK_SIZE);
+ if (gridX >= 0 && gridX < GRID_WIDTH && gridY >= 0 && gridY < GRID_HEIGHT) {
+ var hitBlock = grid[gridX][gridY];
+ if (hitBlock && hitBlock.colorType === self.colorType) {
+ // Get connected blocks of same color
+ var connectedBlocks = getConnectedBlocks(gridX, gridY, self.colorType);
+ if (connectedBlocks.length >= 3) {
+ // Clear and blast connected blocks
+ clearSelection();
+ selectedBlocks = connectedBlocks;
+ blastSelectedBlocks();
+ }
+ self.destroyArrow();
+ }
+ }
};
+ self.destroyArrow = function () {
+ if (!self.isDestroyed) {
+ self.isDestroyed = true;
+ removeArrow(self);
+ }
+ };
return self;
});
var Block = Container.expand(function (colorType) {
var self = Container.call(this);
@@ -287,27 +307,8 @@
nextLevel();
}, 1000);
}
}
-function checkArrowHit(arrow, targetX, targetY) {
- // Find which block the arrow hit
- var gridX = Math.floor((targetX - GRID_START_X) / BLOCK_SIZE);
- var gridY = Math.floor((targetY - GRID_START_Y) / BLOCK_SIZE);
- if (gridX >= 0 && gridX < GRID_WIDTH && gridY >= 0 && gridY < GRID_HEIGHT) {
- var hitBlock = grid[gridX][gridY];
- if (hitBlock && hitBlock.colorType === arrow.colorType) {
- // Get connected blocks of same color
- var connectedBlocks = getConnectedBlocks(gridX, gridY, arrow.colorType);
- if (connectedBlocks.length >= 3) {
- // Destroy connected blocks and arrow
- selectedBlocks = connectedBlocks;
- blastSelectedBlocks();
- }
- }
- }
- // Remove arrow
- removeArrow(arrow);
-}
function removeArrow(arrow) {
var index = activeArrows.indexOf(arrow);
if (index !== -1) {
activeArrows.splice(index, 1);
@@ -345,16 +346,13 @@
// No dragging mechanics needed for arrow shooting
};
game.up = function (x, y, obj) {
if (!gameActive || !shootingBlock) return;
- // Shoot arrow to target position
+ // Shoot arrow in direction of target
var arrow = new Arrow(shootingBlock.colorType);
arrow.x = shootingBlock.x;
arrow.y = shootingBlock.y;
- arrow.setTarget(x, y);
- arrow.onReachTarget = function () {
- checkArrowHit(arrow, x, y);
- };
+ arrow.setDirection(x, y);
activeArrows.push(arrow);
game.addChild(arrow);
// Clear shooting state
shootingBlock = null;