User prompt
yan yana yada alt alta en az 2 balon oyunun verdiği renle aynı ise tıklayınca patlayacak
User prompt
balonlar tıklanınca patlayıp kaybolmuyor
User prompt
hata var
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'colorTxt.style.fill = '#' + color.toString(16).padStart(6, '0');' Line Number: 151
Code edit (1 edits merged)
Please save this source code
User prompt
Renkli Balon Patlatmaca
Initial prompt
ekranda random balonlar olsun boşluksuz yanyana ve farklı renklerde olsun 2 renkli balon alt alta yada yanyana isepatlayabilir 2. şart balonların patlaması için oyun 3saniyede bir renk verecek oyunun verdiği renklerdeki balonlar tıklatılarak patlatılabilir
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Balloon class var Balloon = Container.expand(function () { var self = Container.call(this); // Store color for logic self.color = self.color || 0xff0000; // Default red, will be overwritten on creation // Store grid position self.gridX = 0; self.gridY = 0; // Is this balloon popped? self.popped = false; // Attach balloon asset (ellipse shape) - will be replaced in buildGrid with correct color var balloonGraphics = self.attachAsset('balloon_red', { anchorX: 0.5, anchorY: 0.5 }); // Pop animation and logic self.pop = function () { if (self.popped) return; self.popped = true; // Animate scale down and fade out tween(self, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 250, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); } }); }; // Down event (touch/click) self.down = function (x, y, obj) { if (self.popped) return; // Only allow popping if this is the current color if (self.color !== currentColor) return; // Find all connected balloons of the same color (side-by-side or vertical) var group = findConnectedBalloons(self.gridX, self.gridY, self.color); if (group.length < 2) return; // Only pop if at least 2 connected for (var i = 0; i < group.length; i++) { if (!group[i].popped) { group[i].pop(); } } // Update score LK.setScore(LK.getScore() + group.length); scoreTxt.setText(LK.getScore()); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xffffff }); /**** * Game Code ****/ // Balloon grid settings var GRID_COLS = 10; var GRID_ROWS = 12; var BALLOON_COLORS = [0xff4d4d, // red 0x4db8ff, // blue 0x4dff4d, // green 0xffe14d, // yellow 0xff4df7 // pink ]; var BALLOON_COLOR_NAMES = ['red', 'blue', 'green', 'yellow', 'pink']; // Balloon size and spacing var balloonSize = Math.floor(2048 / GRID_COLS); var balloonSpacing = 0; // No gap // Store balloons in a 2D array var balloons = []; // Store all balloon objects for easy iteration var allBalloons = []; // Current color to pop var currentColor = null; var currentColorIdx = 0; // Score text var scoreTxt = new Text2('0', { size: 120, fill: 0x222222 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Color indicator text var colorTxt = new Text2('', { size: 90, fill: 0x222222 }); colorTxt.anchor.set(0.5, 0); LK.gui.top.addChild(colorTxt); colorTxt.y = 140; // Helper: create balloon asset for each color for (var i = 0; i < BALLOON_COLORS.length; i++) {} // Helper: get color name from color value function getColorName(color) { for (var i = 0; i < BALLOON_COLORS.length; i++) { if (BALLOON_COLORS[i] === color) return BALLOON_COLOR_NAMES[i]; } return 'unknown'; } // Helper: get color display text function getColorDisplayText(color) { var idx = BALLOON_COLORS.indexOf(color); if (idx === -1) return ''; var name = BALLOON_COLOR_NAMES[idx]; var display = ''; if (name === 'red') display = 'KIRMIZI';else if (name === 'blue') display = 'MAVİ';else if (name === 'green') display = 'YEŞİL';else if (name === 'yellow') display = 'SARI';else if (name === 'pink') display = 'PEMBE'; return display; } // Helper: set color indicator function setColorIndicator(color) { colorTxt.setText('Patlat: ' + getColorDisplayText(color)); // Always use setStyle, never assign to colorTxt.style.fill directly colorTxt.setStyle({ fill: '#' + color.toString(16).padStart(6, '0') }); } // Helper: find all connected balloons of the same color (DFS, only side-by-side or vertical) function findConnectedBalloons(x, y, color) { var visited = {}; var group = []; function dfs(cx, cy) { var key = cx + ',' + cy; if (visited[key]) return; if (cx < 0 || cy < 0 || cx >= GRID_COLS || cy >= GRID_ROWS) return; var b = balloons[cx][cy]; if (!b || b.popped || b.color !== color) return; visited[key] = true; group.push(b); // Check neighbors (up, down, left, right) - no diagonal dfs(cx - 1, cy); // left dfs(cx + 1, cy); // right dfs(cx, cy - 1); // up dfs(cx, cy + 1); // down } dfs(x, y); return group; } // Helper: pick a new color (random, but must exist on board) function pickNewColor() { // Find all colors still present var present = {}; for (var i = 0; i < allBalloons.length; i++) { var b = allBalloons[i]; if (!b.popped) present[b.color] = true; } var presentColors = []; for (var i = 0; i < BALLOON_COLORS.length; i++) { if (present[BALLOON_COLORS[i]]) presentColors.push(BALLOON_COLORS[i]); } if (presentColors.length === 0) { // Win condition: all balloons popped LK.showYouWin(); return; } // Pick random color var idx = Math.floor(Math.random() * presentColors.length); currentColor = presentColors[idx]; setColorIndicator(currentColor); } // Build the balloon grid function buildGrid() { // Center grid var offsetX = Math.floor((2048 - GRID_COLS * balloonSize) / 2) + balloonSize / 2; var offsetY = Math.floor((2732 - GRID_ROWS * balloonSize) / 2) + balloonSize / 2; balloons = []; allBalloons = []; for (var x = 0; x < GRID_COLS; x++) { balloons[x] = []; for (var y = 0; y < GRID_ROWS; y++) { // Pick random color var colorIdx = Math.floor(Math.random() * BALLOON_COLORS.length); var color = BALLOON_COLORS[colorIdx]; var name = BALLOON_COLOR_NAMES[colorIdx]; var balloon = new Balloon(); balloon.color = color; balloon.gridX = x; balloon.gridY = y; // Set asset to correct color balloon.removeChildren(); balloon.attachAsset('balloon_' + name, { anchorX: 0.5, anchorY: 0.5 }); balloon.x = offsetX + x * (balloonSize + balloonSpacing); balloon.y = offsetY + y * (balloonSize + balloonSpacing); balloons[x][y] = balloon; allBalloons.push(balloon); game.addChild(balloon); } } } // Reset game state function resetGame() { LK.setScore(0); scoreTxt.setText('0'); // Remove all balloons for (var i = 0; i < allBalloons.length; i++) { allBalloons[i].destroy(); } buildGrid(); pickNewColor(); } // Timer for color change var colorTimer = null; function startColorTimer() { if (colorTimer) LK.clearInterval(colorTimer); colorTimer = LK.setInterval(function () { pickNewColor(); }, 3000); } // Start game resetGame(); startColorTimer(); // Game update (not much needed) game.update = function () { // Check win condition var remaining = 0; for (var i = 0; i < allBalloons.length; i++) { if (!allBalloons[i].popped) remaining++; } if (remaining === 0) { LK.showYouWin(); } }; // On game over or win, reset game game.onGameOver = function () { resetGame(); startColorTimer(); }; game.onYouWin = function () { resetGame(); startColorTimer(); };
===================================================================
--- original.js
+++ change.js
@@ -8,20 +8,20 @@
****/
// Balloon class
var Balloon = Container.expand(function () {
var self = Container.call(this);
- // Attach balloon asset (ellipse shape)
- var balloonGraphics = self.attachAsset('balloon_' + self.color, {
- anchorX: 0.5,
- anchorY: 0.5
- });
// Store color for logic
self.color = self.color || 0xff0000; // Default red, will be overwritten on creation
// Store grid position
self.gridX = 0;
self.gridY = 0;
// Is this balloon popped?
self.popped = false;
+ // Attach balloon asset (ellipse shape) - will be replaced in buildGrid with correct color
+ var balloonGraphics = self.attachAsset('balloon_red', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
// Pop animation and logic
self.pop = function () {
if (self.popped) return;
self.popped = true;
@@ -42,9 +42,9 @@
self.down = function (x, y, obj) {
if (self.popped) return;
// Only allow popping if this is the current color
if (self.color !== currentColor) return;
- // Find all connected balloons of the same color
+ // Find all connected balloons of the same color (side-by-side or vertical)
var group = findConnectedBalloons(self.gridX, self.gridY, self.color);
if (group.length < 2) return; // Only pop if at least 2 connected
for (var i = 0; i < group.length; i++) {
if (!group[i].popped) {
@@ -132,9 +132,9 @@
colorTxt.setStyle({
fill: '#' + color.toString(16).padStart(6, '0')
});
}
-// Helper: find all connected balloons of the same color (DFS)
+// Helper: find all connected balloons of the same color (DFS, only side-by-side or vertical)
function findConnectedBalloons(x, y, color) {
var visited = {};
var group = [];
function dfs(cx, cy) {
@@ -144,13 +144,13 @@
var b = balloons[cx][cy];
if (!b || b.popped || b.color !== color) return;
visited[key] = true;
group.push(b);
- // Check neighbors (up, down, left, right)
- dfs(cx - 1, cy);
- dfs(cx + 1, cy);
- dfs(cx, cy - 1);
- dfs(cx, cy + 1);
+ // Check neighbors (up, down, left, right) - no diagonal
+ dfs(cx - 1, cy); // left
+ dfs(cx + 1, cy); // right
+ dfs(cx, cy - 1); // up
+ dfs(cx, cy + 1); // down
}
dfs(x, y);
return group;
}