User prompt
can you adjust the hud
User prompt
can we put the current level in the center of the top of the screen
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'BALL_COST is not defined' in or related to this line: 'var normalCostText = new Text2(BALL_COST.toString(), {' Line Number: 71
User prompt
Please fix the bug: 'GAME_WIDTH is not defined' in or related to this line: 'levelTxt.x = GAME_WIDTH / 2 - levelTxt.width / 2;' Line Number: 54
Code edit (1 edits merged)
Please save this source code
User prompt
Fix level 2 not loading and showing game over
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 473
Code edit (8 edits merged)
Please save this source code
User prompt
remove power ups from game
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 475
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'undefined')' in or related to this line: 'var gridSize = levelConfig[level].gridSize || 200; // Define grid size per level, default to 200 if not specified' Line Number: 96
User prompt
theregrid size will be different per level
User prompt
Lets make level config a little more specific, and allow player to define groups of blocks for each level, and also set how many hitpoins those blocks will have
User prompt
Please fix the bug: 'gridSize is not defined' in or related to this line: 'var gridX = Math.floor(brick.x / gridSize);' Line Number: 170
User prompt
can ou optimize it more. feels like the problems is with the bricks
User prompt
game is getting stuck when there are many bricks and balls. can we optimize the code to allow many balls and bricks in the screen at the same time
User prompt
create a config file were we can say home may bricks each level will have
User prompt
Imptove game perfoomance to handel many balls simultaneously
User prompt
add levels to the game. once all bricks are destroyed, move to next level. show current level on screen in the top
User prompt
add a level sctructurue, level two should have more bricks and some should have 2 hitpints
User prompt
sometimes balls bounce close to a brick butu do not touch it and nor destroy it, can you fix that
User prompt
Make sure bricks can be touched in any part of their surface
User prompt
Please fix the bug: 'Graphics is not a constructor' in or related to this line: 'var hitbox = new Graphics();' Line Number: 47
/**** * Classes ****/ // Ball class representing the ball that breaks bricks var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; self.direction = { x: 1, y: -1 }; self.update = function () { var _ref = levelConfig[level] || { gridSize: 200 }, gridSize = _ref.gridSize; var stepSize = self.speed; var dx = self.direction.x * stepSize; var dy = self.direction.y * stepSize; self.x += dx; self.y += dy; // Bounce off walls if (self.x <= BALL_RADIUS || self.x >= GAME_WIDTH - BALL_RADIUS) { self.direction.x *= -1; self.x = Math.max(BALL_RADIUS, Math.min(GAME_WIDTH - BALL_RADIUS, self.x)); } if (self.y <= BALL_RADIUS || self.y >= GAME_HEIGHT - BALL_RADIUS) { self.direction.y *= -1; self.y = Math.max(BALL_RADIUS, Math.min(GAME_HEIGHT - BALL_RADIUS, self.y)); } // Only check collisions near actual bricks (performance optimization) if (!isNearBricks(self.x, self.y)) { return; } // Check collisions with bricks using grid-based collision detection var gridXMin = Math.floor((self.x - BALL_RADIUS) / gridSize); var gridXMax = Math.floor((self.x + BALL_RADIUS) / gridSize); var gridYMin = Math.floor((self.y - BALL_RADIUS) / gridSize); var gridYMax = Math.floor((self.y + BALL_RADIUS) / gridSize); var hasCollided = false; for (var gx = gridXMin; gx <= gridXMax && !hasCollided; gx++) { for (var gy = gridYMin; gy <= gridYMax && !hasCollided; gy++) { var gridKey = "".concat(gx, ",").concat(gy); var cellBricks = brickGrid[gridKey]; if (!cellBricks || cellBricks.length === 0) { continue; } for (var j = cellBricks.length - 1; j >= 0; j--) { var brick = cellBricks[j]; if (!brick || brick.health <= 0 || !self.intersects(brick)) { continue; } // Handle collision handleBallBrickCollision(self, brick); brick.hit(); // Remove brick from grid if destroyed if (brick.health <= 0) { cellBricks.splice(j, 1); } hasCollided = true; break; } } } }; }); // Brick class representing the bricks to be broken var Brick = Container.expand(function () { var self = Container.call(this); var brickGraphics = self.attachAsset('brick', { anchorX: 0.5, anchorY: 0.5 }); self.health = 1; self.maxHealth = 1; self.healthText = new Text2(self.health.toString(), { size: 30, fill: 0xFFFFFF }); self.healthText.anchor.set(0.5, 0.5); self.addChild(self.healthText); self.updateTint = function () { var healthPercent = self.health / self.maxHealth; // Use different color based on health percentage var colorIndex = Math.min(Math.floor((1 - healthPercent) * LEVEL_COLORS.length), LEVEL_COLORS.length - 1); brickGraphics.tint = LEVEL_COLORS[colorIndex]; }; self.hit = function () { self.health -= 1; if (self.health <= 0) { // Award points - more points for higher health bricks score += Math.max(1, Math.floor(self.maxHealth * 0.5)); scoreTxt.setText(score.toString()); // Remove from active bricks array var brickIndex = bricks.indexOf(self); if (brickIndex !== -1) { bricks.splice(brickIndex, 1); } // Destroy the brick self.destroy(); } else { // Update display self.healthText.setText(self.health.toString()); self.updateTint(); } }; }); /**** * Initialize Game ****/ /**** * Helper Functions ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ /**** * Constants ****/ /**** * Game Configuration ****/ var GAME_WIDTH = 2048; var GAME_HEIGHT = 2632; var BALL_RADIUS = 50; var BRICK_WIDTH = 150; var BRICK_HEIGHT = 50; var BALL_COST = 50; var LEVEL_COLORS = [0xff00ff, // Neon magenta 0x00ffcc, // Neon cyan 0xccff00, // Neon lime 0xff6600, // Neon orange 0x66ffff, // Light blue 0xff3366, // Pink 0xffcc00, // Gold 0x9966ff, // Purple 0x33cc33, // Green 0xff0000 // Red ]; /**** * Helper Functions ****/ function handleBallBrickCollision(ball, brick) { // Calculate relative position for better physics var relativeX = (ball.x - brick.x) / (brick.width / 2); var relativeY = (ball.y - brick.y) / (brick.height / 2); // Determine collision side and apply proper bounce if (Math.abs(relativeX) > Math.abs(relativeY)) { // Horizontal collision ball.direction.x = -ball.direction.x; // Push ball out of brick horizontally ball.x = brick.x + (relativeX > 0 ? brick.width / 2 + BALL_RADIUS : -brick.width / 2 - BALL_RADIUS); } else { // Vertical collision ball.direction.y = -ball.direction.y; // Push ball out vertically ball.y = brick.y + (relativeY > 0 ? brick.height / 2 + BALL_RADIUS : -brick.height / 2 - BALL_RADIUS); } // Add slight randomness to prevent looping patterns ball.direction.x += (Math.random() - 0.5) * 0.1; // Normalize vector to maintain consistent speed var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y); ball.direction.x /= magnitude; ball.direction.y /= magnitude; } function isNearBricks(x, y) { if (!brickGridBounds) { return true; } // Add a buffer around the brick area var buffer = BALL_RADIUS * 2; return x >= brickGridBounds.minX - buffer && x <= brickGridBounds.maxX + buffer && y >= brickGridBounds.minY - buffer && y <= brickGridBounds.maxY + buffer; } var levelConfig = { 1: { totalBricks: 50, hitpoints: 1, gridSize: 200, pattern: 'standard' }, 2: { totalBricks: 100, hitpoints: 2, gridSize: 180, pattern: 'standard' }, 3: { totalBricks: 120, hitpoints: 3, gridSize: 170, pattern: 'gradient' }, 4: { totalBricks: 150, hitpoints: 4, gridSize: 160, pattern: 'standard' }, 5: { totalBricks: 180, hitpoints: 5, gridSize: 150, pattern: 'gradient' }, 6: { totalBricks: 200, hitpoints: 6, gridSize: 140, pattern: 'zigzag' }, 7: { totalBricks: 220, hitpoints: 7, gridSize: 130, pattern: 'gradient' }, 8: { totalBricks: 240, hitpoints: 8, gridSize: 120, pattern: 'zigzag' }, 9: { totalBricks: 260, hitpoints: 9, gridSize: 110, pattern: 'alternating' }, 10: { totalBricks: 280, hitpoints: 10, gridSize: 100, pattern: 'fortress' } }; /**** * Game Variables ****/ var balls = []; var bricks = []; var brickGrid = {}; var score = 100; var level = 1; var brickGridBounds = null; /**** * HUD Setup ****/ var hud = new Container(); LK.gui.topRight.addChild(hud); // Score display var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); hud.addChild(scoreTxt); scoreTxt.setText(score.toString()); // Level display var levelTxt = new Text2('Level: ' + level, { size: 100, fill: 0xFFFFFF }); levelTxt.anchor.set(1, 0); levelTxt.y = 120; hud.addChild(levelTxt); // Buy ball button var buyBallButton = LK.getAsset('BuyBall50', { size: 80, fill: 0xFFFFFF, anchorX: 0.5, anchorY: 0, y: 0, x: -300 }); var costText = new Text2(BALL_COST.toString(), { size: 50, fill: 0xFFFFFF }); costText.anchor.set(0.5, 0); costText.y = 100; buyBallButton.addChild(costText); var ballIcon = buyBallButton.attachAsset('ball', { anchorX: 0.5, anchorY: -0.5, scaleX: 0.5, scaleY: 0.5 }); buyBallButton.down = function () { if (score >= BALL_COST) { score -= BALL_COST; scoreTxt.setText(score.toString()); createBall(); } }; hud.addChild(buyBallButton); /**** * Game Functions ****/ // Create and position bricks with different patterns based on level function createBricks() { var _ref2 = levelConfig[level] || {}, _ref2$totalBricks = _ref2.totalBricks, totalBricks = _ref2$totalBricks === void 0 ? 50 : _ref2$totalBricks, _ref2$hitpoints = _ref2.hitpoints, hitpoints = _ref2$hitpoints === void 0 ? 1 : _ref2$hitpoints, _ref2$gridSize = _ref2.gridSize, gridSize = _ref2$gridSize === void 0 ? 200 : _ref2$gridSize, _ref2$pattern = _ref2.pattern, pattern = _ref2$pattern === void 0 ? 'standard' : _ref2$pattern; var spacingX = 2; var spacingY = 2; var cols = 10; var rows = Math.ceil(totalBricks / cols); var totalWidth = cols * BRICK_WIDTH + (cols - 1) * spacingX; var totalHeight = rows * BRICK_HEIGHT + (rows - 1) * spacingY; var startX = (GAME_WIDTH - totalWidth) / 2 + BRICK_WIDTH / 2; var startY = (GAME_HEIGHT - totalHeight) / 3 + BRICK_HEIGHT / 2; // Clear existing brick grid brickGrid = {}; bricks = []; var brickCount = 0; for (var i = 0; i < rows && brickCount < totalBricks; i++) { for (var j = 0; j < cols && brickCount < totalBricks; j++) { // Skip some bricks based on pattern var shouldSkip = false; var brickHitpoints = hitpoints; switch (pattern) { case 'zigzag': // Skip every other brick in alternating rows shouldSkip = i % 2 === 0 && j % 2 === 1 || i % 2 === 1 && j % 2 === 0; break; case 'gradient': // Higher hitpoints at the top, lower at the bottom brickHitpoints = Math.max(1, Math.ceil(hitpoints * (1 - i / rows))); break; case 'alternating': // Alternating hitpoints patterns brickHitpoints = i % 2 === 0 ? hitpoints : Math.max(1, Math.ceil(hitpoints / 2)); break; case 'fortress': // Stronger bricks in the middle var distFromCenter = Math.sqrt(Math.pow((j - cols / 2) / (cols / 2), 2) + Math.pow((i - rows / 2) / (rows / 2), 2)); brickHitpoints = Math.max(1, Math.ceil(hitpoints * (1 - distFromCenter))); // Skip some outer bricks shouldSkip = distFromCenter > 0.8 && Math.random() > 0.7; break; } if (shouldSkip) { continue; } var brick = new Brick(); brick.x = startX + j * (BRICK_WIDTH + spacingX); brick.y = startY + i * (BRICK_HEIGHT + spacingY); brick.health = brickHitpoints; brick.maxHealth = brickHitpoints; brick.healthText.setText(brick.health.toString()); brick.updateTint(); bricks.push(brick); game.addChild(brick); brickCount++; // Add to spatial grid for optimized collision detection var gridX = Math.floor(brick.x / gridSize); var gridY = Math.floor(brick.y / gridSize); var gridKey = "".concat(gridX, ",").concat(gridY); if (!brickGrid[gridKey]) { brickGrid[gridKey] = []; } brickGrid[gridKey].push(brick); } } // Store boundaries for optimization brickGridBounds = { minX: startX - BRICK_WIDTH / 2, maxX: startX + totalWidth - BRICK_WIDTH / 2, minY: startY - BRICK_HEIGHT / 2, maxY: startY + totalHeight - BRICK_HEIGHT / 2 }; } // Create a new ball with improved positioning function createBall() { var ball = new Ball(); // Position ball safely var gridBottom = brickGridBounds ? brickGridBounds.maxY + 150 : GAME_HEIGHT * 0.7; ball.x = GAME_WIDTH / 2 + (Math.random() * 200 - 100); // Slight randomization ball.y = Math.min(gridBottom + 100, GAME_HEIGHT - BALL_RADIUS * 2); // Random direction within a cone pointing upward var angle = (Math.random() * 0.5 + 0.25) * Math.PI; ball.direction.x = Math.cos(angle); ball.direction.y = -Math.sin(angle); // Normalize direction vector var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y); ball.direction.x /= magnitude; ball.direction.y /= magnitude; // Adjust speed based on level for gradual difficulty increase ball.speed = 6 + level * 0.3; // Small speed increase per level balls.push(ball); game.addChild(ball); } // Handle game completion function handleLevelComplete() { // Clean up existing objects clearLevel(); if (level === Object.keys(levelConfig).length) { // Game completed var gameOverText = new Text2('Game Completed!', { size: 150, fill: 0xFFFFFF }); gameOverText.anchor.set(0.5, 0.5); gameOverText.x = GAME_WIDTH / 2; gameOverText.y = GAME_HEIGHT / 2; game.addChild(gameOverText); var finalScoreText = new Text2('Final Score: ' + score, { size: 100, fill: 0xFFFFFF }); finalScoreText.anchor.set(0.5, 0.5); finalScoreText.x = GAME_WIDTH / 2; finalScoreText.y = GAME_HEIGHT / 2 + 150; game.addChild(finalScoreText); setTimeout(function () { LK.showGameOver(); }, 3000); } else { // Next level level += 1; levelTxt.setText('Level: ' + level); // Level transition effect/message var levelText = new Text2('Level ' + level, { size: 150, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0.5); levelText.x = GAME_WIDTH / 2; levelText.y = GAME_HEIGHT / 2; game.addChild(levelText); // Display pattern type var patternName = levelConfig[level].pattern.charAt(0).toUpperCase() + levelConfig[level].pattern.slice(1); var patternText = new Text2(patternName + ' Pattern', { size: 80, fill: 0xFFFFFF }); patternText.anchor.set(0.5, 0.5); patternText.x = GAME_WIDTH / 2; patternText.y = GAME_HEIGHT / 2 + 150; game.addChild(patternText); // Remove level text after 2 seconds and start new level setTimeout(function () { levelText.destroy(); patternText.destroy(); createBricks(); createBall(); }, 2000); } } // Clear level objects function clearLevel() { // Remove all balls for (var i = balls.length - 1; i >= 0; i--) { balls[i].destroy(); } balls = []; // Remove any remaining bricks for (var i = bricks.length - 1; i >= 0; i--) { bricks[i].destroy(); } bricks = []; brickGrid = {}; } /**** * Game Update Loop ****/ game.update = function () { // Update all balls for (var i = balls.length - 1; i >= 0; i--) { var ball = balls[i]; ball.update(); // Remove balls that fall below the screen if (ball.y > GAME_HEIGHT + BALL_RADIUS) { ball.destroy(); balls.splice(i, 1); } } // Level completion check if (bricks.length === 0) { handleLevelComplete(); } // Auto-create ball if all balls are lost if (balls.length === 0) { if (score >= BALL_COST) { score -= Math.min(score, BALL_COST); scoreTxt.setText(score.toString()); createBall(); } else { // Game over clearLevel(); LK.showGameOver(); } } }; /**** * Input Handling ****/ game.down = function (x, y, obj) { // Manually hit bricks on click if (!bricks || !Array.isArray(bricks)) { return; } x = Number(x); y = Number(y); // Check if player clicked near the launch area to control ball direction var controlAreaY = GAME_HEIGHT * 0.8; if (y > controlAreaY) { // Direct balls toward click point for (var i = 0; i < balls.length; i++) { var ball = balls[i]; // Only redirect balls below a certain Y position if (ball.y > controlAreaY) { // Calculate direction to click point var dx = x - ball.x; var dy = y - ball.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { ball.direction.x = dx / dist; ball.direction.y = dy / dist; // Force upward direction if (ball.direction.y > 0) { ball.direction.y *= -1; // Re-normalize var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y); ball.direction.x /= magnitude; ball.direction.y /= magnitude; } } } } return; } // Check for brick hits (cheat/debug feature) for (var i = 0; i < bricks.length; i++) { var brick = bricks[i]; if (!brick.x || !brick.y || !brick.width || !brick.height) { continue; } // Simple AABB collision check if (x >= brick.x - brick.width / 2 && x <= brick.x + brick.width / 2 && y >= brick.y - brick.height / 2 && y <= brick.y + brick.height / 2) { brick.hit(); return; } } }; // Initialize game elements createBricks(); createBall();
===================================================================
--- original.js
+++ change.js
@@ -83,16 +83,17 @@
});
self.healthText.anchor.set(0.5, 0.5);
self.addChild(self.healthText);
self.updateTint = function () {
- var healthRatio = self.health / self.maxHealth;
- var colorIndex = Math.min(Math.floor((1 - healthRatio) * LEVEL_COLORS.length), LEVEL_COLORS.length - 1);
+ var healthPercent = self.health / self.maxHealth;
+ // Use different color based on health percentage
+ var colorIndex = Math.min(Math.floor((1 - healthPercent) * LEVEL_COLORS.length), LEVEL_COLORS.length - 1);
brickGraphics.tint = LEVEL_COLORS[colorIndex];
};
self.hit = function () {
self.health -= 1;
if (self.health <= 0) {
- // Award points
+ // Award points - more points for higher health bricks
score += Math.max(1, Math.floor(self.maxHealth * 0.5));
scoreTxt.setText(score.toString());
// Remove from active bricks array
var brickIndex = bricks.indexOf(self);
@@ -137,9 +138,23 @@
var LEVEL_COLORS = [0xff00ff,
// Neon magenta
0x00ffcc,
// Neon cyan
-0xccff00 // Neon lime
+0xccff00,
+// Neon lime
+0xff6600,
+// Neon orange
+0x66ffff,
+// Light blue
+0xff3366,
+// Pink
+0xffcc00,
+// Gold
+0x9966ff,
+// Purple
+0x33cc33,
+// Green
+0xff0000 // Red
];
/****
* Helper Functions
****/
@@ -177,29 +192,64 @@
var levelConfig = {
1: {
totalBricks: 50,
hitpoints: 1,
- gridSize: 200
+ gridSize: 200,
+ pattern: 'standard'
},
2: {
totalBricks: 100,
hitpoints: 2,
- gridSize: 180
+ gridSize: 180,
+ pattern: 'standard'
},
3: {
- totalBricks: 150,
+ totalBricks: 120,
hitpoints: 3,
- gridSize: 160
+ gridSize: 170,
+ pattern: 'gradient'
},
4: {
- totalBricks: 200,
+ totalBricks: 150,
hitpoints: 4,
- gridSize: 140
+ gridSize: 160,
+ pattern: 'standard'
},
5: {
- totalBricks: 250,
+ totalBricks: 180,
hitpoints: 5,
- gridSize: 120
+ gridSize: 150,
+ pattern: 'gradient'
+ },
+ 6: {
+ totalBricks: 200,
+ hitpoints: 6,
+ gridSize: 140,
+ pattern: 'zigzag'
+ },
+ 7: {
+ totalBricks: 220,
+ hitpoints: 7,
+ gridSize: 130,
+ pattern: 'gradient'
+ },
+ 8: {
+ totalBricks: 240,
+ hitpoints: 8,
+ gridSize: 120,
+ pattern: 'zigzag'
+ },
+ 9: {
+ totalBricks: 260,
+ hitpoints: 9,
+ gridSize: 110,
+ pattern: 'alternating'
+ },
+ 10: {
+ totalBricks: 280,
+ hitpoints: 10,
+ gridSize: 100,
+ pattern: 'fortress'
}
};
/****
* Game Variables
@@ -263,39 +313,70 @@
hud.addChild(buyBallButton);
/****
* Game Functions
****/
-// Create and position bricks
+// Create and position bricks with different patterns based on level
function createBricks() {
var _ref2 = levelConfig[level] || {},
_ref2$totalBricks = _ref2.totalBricks,
totalBricks = _ref2$totalBricks === void 0 ? 50 : _ref2$totalBricks,
_ref2$hitpoints = _ref2.hitpoints,
hitpoints = _ref2$hitpoints === void 0 ? 1 : _ref2$hitpoints,
_ref2$gridSize = _ref2.gridSize,
- gridSize = _ref2$gridSize === void 0 ? 200 : _ref2$gridSize;
+ gridSize = _ref2$gridSize === void 0 ? 200 : _ref2$gridSize,
+ _ref2$pattern = _ref2.pattern,
+ pattern = _ref2$pattern === void 0 ? 'standard' : _ref2$pattern;
var spacingX = 2;
var spacingY = 2;
var cols = 10;
var rows = Math.ceil(totalBricks / cols);
var totalWidth = cols * BRICK_WIDTH + (cols - 1) * spacingX;
var totalHeight = rows * BRICK_HEIGHT + (rows - 1) * spacingY;
var startX = (GAME_WIDTH - totalWidth) / 2 + BRICK_WIDTH / 2;
- var startY = (GAME_HEIGHT - totalHeight) / 3 + BRICK_HEIGHT / 2; // Move bricks higher
+ var startY = (GAME_HEIGHT - totalHeight) / 3 + BRICK_HEIGHT / 2;
// Clear existing brick grid
brickGrid = {};
bricks = [];
- for (var i = 0; i < rows; i++) {
- for (var j = 0; j < cols && i * cols + j < totalBricks; j++) {
+ var brickCount = 0;
+ for (var i = 0; i < rows && brickCount < totalBricks; i++) {
+ for (var j = 0; j < cols && brickCount < totalBricks; j++) {
+ // Skip some bricks based on pattern
+ var shouldSkip = false;
+ var brickHitpoints = hitpoints;
+ switch (pattern) {
+ case 'zigzag':
+ // Skip every other brick in alternating rows
+ shouldSkip = i % 2 === 0 && j % 2 === 1 || i % 2 === 1 && j % 2 === 0;
+ break;
+ case 'gradient':
+ // Higher hitpoints at the top, lower at the bottom
+ brickHitpoints = Math.max(1, Math.ceil(hitpoints * (1 - i / rows)));
+ break;
+ case 'alternating':
+ // Alternating hitpoints patterns
+ brickHitpoints = i % 2 === 0 ? hitpoints : Math.max(1, Math.ceil(hitpoints / 2));
+ break;
+ case 'fortress':
+ // Stronger bricks in the middle
+ var distFromCenter = Math.sqrt(Math.pow((j - cols / 2) / (cols / 2), 2) + Math.pow((i - rows / 2) / (rows / 2), 2));
+ brickHitpoints = Math.max(1, Math.ceil(hitpoints * (1 - distFromCenter)));
+ // Skip some outer bricks
+ shouldSkip = distFromCenter > 0.8 && Math.random() > 0.7;
+ break;
+ }
+ if (shouldSkip) {
+ continue;
+ }
var brick = new Brick();
brick.x = startX + j * (BRICK_WIDTH + spacingX);
brick.y = startY + i * (BRICK_HEIGHT + spacingY);
- brick.health = hitpoints;
- brick.maxHealth = hitpoints;
+ brick.health = brickHitpoints;
+ brick.maxHealth = brickHitpoints;
brick.healthText.setText(brick.health.toString());
brick.updateTint();
bricks.push(brick);
game.addChild(brick);
+ brickCount++;
// Add to spatial grid for optimized collision detection
var gridX = Math.floor(brick.x / gridSize);
var gridY = Math.floor(brick.y / gridSize);
var gridKey = "".concat(gridX, ",").concat(gridY);
@@ -327,8 +408,10 @@
// Normalize direction vector
var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y);
ball.direction.x /= magnitude;
ball.direction.y /= magnitude;
+ // Adjust speed based on level for gradual difficulty increase
+ ball.speed = 6 + level * 0.3; // Small speed increase per level
balls.push(ball);
game.addChild(ball);
}
// Handle game completion
@@ -352,9 +435,9 @@
finalScoreText.anchor.set(0.5, 0.5);
finalScoreText.x = GAME_WIDTH / 2;
finalScoreText.y = GAME_HEIGHT / 2 + 150;
game.addChild(finalScoreText);
- LK.setTimeout(function () {
+ setTimeout(function () {
LK.showGameOver();
}, 3000);
} else {
// Next level
@@ -368,11 +451,22 @@
levelText.anchor.set(0.5, 0.5);
levelText.x = GAME_WIDTH / 2;
levelText.y = GAME_HEIGHT / 2;
game.addChild(levelText);
+ // Display pattern type
+ var patternName = levelConfig[level].pattern.charAt(0).toUpperCase() + levelConfig[level].pattern.slice(1);
+ var patternText = new Text2(patternName + ' Pattern', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ patternText.anchor.set(0.5, 0.5);
+ patternText.x = GAME_WIDTH / 2;
+ patternText.y = GAME_HEIGHT / 2 + 150;
+ game.addChild(patternText);
// Remove level text after 2 seconds and start new level
- LK.setTimeout(function () {
+ setTimeout(function () {
levelText.destroy();
+ patternText.destroy();
createBricks();
createBall();
}, 2000);
}