Code edit (1 edits merged)
Please save this source code
User prompt
in welcom message, paint the cash word neon green
User prompt
if welcome message is up, remove it when a power up is bought
User prompt
Please fix the bug: 'Uncaught ReferenceError: welcomeText is not defined' in or related to this line: 'if (welcomeText && welcomeText.parent) {' Line Number: 782
User prompt
also remove welcome message if a ball is bouthg
User prompt
Prevent balls from going just side ways or vertically
User prompt
sniper ball should only applyl its damage once per second
User prompt
sniper ball shoud bounceback on every touch, for half a second
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 62
User prompt
sniper reboudn should be longer
User prompt
sniper should really decrease its speed 10 times for a second after touching a bric
User prompt
sniper ball should not touch the same brick twice in a row
User prompt
Sniper should look for the next closest brick different than the one it touched last
User prompt
add this cooldown for the sniper ball: self.sniperCooldown = 0; // Add cooldown tracker self.sniperCooldownMax = 60; // Lock onto a new target every 1 second (assuming 60 FPS) self.update = function () { var gridSize = levelConfig[level] ? levelConfig[level].gridSize : 200; var stepSize = self.speed; if (self.type === 'sniper') { self.sniperCooldown--; if (self.sniperCooldown <= 0) { var nearestBrick = findNearestBrick(self.x, self.y); if (nearestBrick) { var dx = nearestBrick.x - self.x; var dy = nearestBrick.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.direction.x = dx / magnitude; self.direction.y = dy / magnitude; self.sniperCooldown = self.sniperCooldownMax; // Reset cooldown } } }
User prompt
Allow player to click on balls to change their trajectory
User prompt
initiallize sniper speed to 1
Code edit (6 edits merged)
Please save this source code
User prompt
splash damage should do the damage of the ball dived by two to adjacent cells
User prompt
Spash damage should only be to the adjacent bricks that the ball bounces of off.
User prompt
splash damage should be 100% of damage of splash ball
User prompt
spash ball should make same dagame to bricks adjacent to the last one it touches
Code edit (3 edits merged)
Please save this source code
User prompt
Spash damage should not contactenate all bricks, only the ones that are witing 200 pixels from this brick
User prompt
spash damage, if adjacent cell has more hp than the one being hit, then damage it for the amount taken to the initially hit one
Code edit (4 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -21,86 +21,24 @@
self.direction = {
x: 1,
y: -1
};
- self.sniperCooldown = 0;
- self.sniperCooldownMax = 60;
+ self.sniperCooldown = 0; // Add cooldown tracker
+ self.sniperCooldownMax = 60; // Lock onto a new target every 1 second (assuming 60 FPS)
self.interactive = true;
self.down = function (x, y, obj) {
+ // Calculate new random direction on click
var angle = Math.random() * 2 * Math.PI;
self.direction.x = Math.cos(angle);
self.direction.y = Math.sin(angle);
- normalizeDirection(self);
+ // Normalize direction
+ var magnitude = Math.sqrt(self.direction.x * self.direction.x + self.direction.y * self.direction.y);
+ self.direction.x /= magnitude;
+ self.direction.y /= magnitude;
};
self.update = function () {
var gridSize = levelConfig[level] ? levelConfig[level].gridSize : 200;
var stepSize = self.speed;
- var maxSteps = Math.ceil(stepSize / BALL_RADIUS); // Sub-step to prevent tunneling
- var stepX = self.direction.x * stepSize / maxSteps;
- var stepY = self.direction.y * stepSize / maxSteps;
- for (var step = 0; step < maxSteps; step++) {
- self.x += stepX;
- self.y += stepY;
- // Wall collisions
- 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));
- self.direction.y += (Math.random() - 0.5) * 0.1;
- LK.getSound('bounce').play();
- normalizeDirection(self);
- continue;
- }
- 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));
- self.direction.x += (Math.random() - 0.5) * 0.1;
- LK.getSound('bounce').play();
- normalizeDirection(self);
- continue;
- }
- if (!isNearBricks(self.x, self.y)) {
- continue;
- }
- 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;
- }
- handleBallBrickCollision(self, brick, stepX, stepY);
- brick.hit(self.power);
- if (self.type === 'splash' && brick.health > 0) {
- applySplashDamage(brick, gridSize);
- } else if (self.type === 'scatter') {
- scatterOnImpact(self);
- self.destroy();
- balls.splice(balls.indexOf(self), 1);
- hasCollided = true;
- break;
- }
- if (brick.health <= 0) {
- cellBricks.splice(j, 1);
- }
- hasCollided = true;
- break;
- }
- }
- }
- if (hasCollided) {
- break;
- }
- }
if (self.type === 'sniper') {
self.sniperCooldown--;
if (self.sniperCooldown <= 0) {
var nearestBrick = findNearestBrick(self.x, self.y);
@@ -109,24 +47,68 @@
var dy = nearestBrick.y - self.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
self.direction.x = dx / magnitude;
self.direction.y = dy / magnitude;
- self.sniperCooldown = self.sniperCooldownMax;
+ self.sniperCooldown = self.sniperCooldownMax; // Reset cooldown
}
}
}
+ var dx = self.direction.x * stepSize;
+ var dy = self.direction.y * stepSize;
+ self.x += dx;
+ self.y += dy;
+ 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));
+ self.direction.y += (Math.random() - 0.5) * 0.1; // Add slight randomness to y direction
+ LK.getSound('bounce').play();
+ }
+ 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));
+ self.direction.x += (Math.random() - 0.5) * 0.1; // Add slight randomness to x direction
+ LK.getSound('bounce').play();
+ }
+ if (!isNearBricks(self.x, self.y)) {
+ return;
+ }
+ 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;
+ }
+ handleBallBrickCollision(self, brick);
+ brick.hit(self.power);
+ if (self.type === 'splash' && brick.health > 0) {
+ applySplashDamage(brick, gridSize);
+ } else if (self.type === 'scatter') {
+ scatterOnImpact(self);
+ self.destroy();
+ balls.splice(balls.indexOf(self), 1);
+ hasCollided = true;
+ break;
+ }
+ if (brick.health <= 0) {
+ cellBricks.splice(j, 1);
+ }
+ hasCollided = true;
+ break;
+ }
+ }
+ }
};
- self.intersects = function (brick) {
- var ballLeft = this.x - BALL_RADIUS;
- var ballRight = this.x + BALL_RADIUS;
- var ballTop = this.y - BALL_RADIUS;
- var ballBottom = this.y + BALL_RADIUS;
- var brickLeft = brick.x - BRICK_HALF_WIDTH;
- var brickRight = brick.x + BRICK_HALF_WIDTH;
- var brickTop = brick.y - BRICK_HALF_HEIGHT;
- var brickBottom = brick.y + BRICK_HALF_HEIGHT;
- return ballLeft < brickRight && ballRight > brickLeft && ballTop < brickBottom && ballBottom > brickTop;
- };
});
var Brick = Container.expand(function () {
var self = Container.call(this);
var brickGraphics = self.attachAsset('brick', {
@@ -141,25 +123,31 @@
fontWeight: 'bold'
});
self.healthText.anchor.set(0.5, 0.5);
self.addChild(self.healthText);
+ // Helper function to convert hex color to RGB
function hexToRGB(hex) {
return {
r: hex >> 16 & 0xff,
g: hex >> 8 & 0xff,
b: hex & 0xff
};
}
+ // Helper function to convert RGB back to hex
function rgbToHex(r, g, b) {
return (Math.floor(r) << 16) + (Math.floor(g) << 8) + Math.floor(b);
}
+ // Update brick tint based on health
self.updateTint = function () {
var baseColors = LEVEL_COLORS;
- var colorCount = baseColors.length;
+ var colorCount = baseColors.length; // 10 colors
if (self.health <= colorCount) {
+ // For HP 1-10, use the direct color from LEVEL_COLORS
brickGraphics.tint = baseColors[self.health - 1];
} else {
- var lastDigit = self.health % 10;
+ // For HP > 10, use the last digit to determine the color
+ var lastDigit = self.health % 10; // Get the last digit (0-9)
+ // Map last digit 0 to index 9 (HP 10), 1 to index 0 (HP 1), etc.
var colorIndex = lastDigit === 0 ? 9 : lastDigit - 1;
brickGraphics.tint = baseColors[colorIndex];
}
};
@@ -230,9 +218,9 @@
LK.getSound('click').play();
clearLocalStorage();
playTime = 0;
storage.playTime = playTime;
- LK.showGameOver();
+ LK.showGameOver(); // Show game over when reset is pressed
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
@@ -300,9 +288,10 @@
* Game Code
****/
var welcomeText = null;
function showEndScreen() {
- game.isGameOver = true;
+ game.isGameOver = true; // Set the flag to indicate the end screen is up
+ // Hide all game elements
hud.visible = false;
powerupContainer.visible = false;
upgradeButton.visible = false;
balls.forEach(function (ball) {
@@ -318,8 +307,9 @@
congratsText.anchor.set(0.5, 0);
congratsText.x = GAME_WIDTH / 2;
congratsText.y = GAME_HEIGHT / 2 - 500 + 550;
game.addChild(congratsText);
+ // Add game title with color switching
var gameTitle = new GameTitle();
gameTitle.x = GAME_WIDTH / 2;
gameTitle.y = congratsText.y - 400;
game.addChild(gameTitle);
@@ -340,29 +330,32 @@
}
});
}
animateEndTitleColor();
+ // Add play time text
var playTimeText = new Text2('Time Played: ' + playTime + ' seconds', {
size: 80,
fill: 0xffffff
});
playTimeText.anchor.set(0.5, 0);
playTimeText.x = GAME_WIDTH / 2;
playTimeText.y = congratsText.y + 300;
game.addChild(playTimeText);
+ // Add a note below the time played
var noteText = new Text2('Start over with all your upgrades, or reset for a fresh new run! Your choice!', {
size: 50,
fill: 0xffffff
});
noteText.anchor.set(0.5, 0);
noteText.x = GAME_WIDTH / 2;
noteText.y = playTimeText.y + 400;
game.addChild(noteText);
+ // Add end game button
var endGameButton = new Container();
var buttonGraphics = endGameButton.attachAsset('endGameButton', {
anchorX: 0.5,
anchorY: 0.5,
- tint: 0x00ffff
+ tint: 0x00ffff // Match the upgrade button tint
});
var buttonText = new Text2('Restart!', {
size: 50,
fill: 0x000000,
@@ -376,34 +369,87 @@
endGameButton.down = function () {
LK.showGameOver();
};
game.addChild(endGameButton);
+ // Add reset button
var resetButton = new ResetButton();
resetButton.x = GAME_WIDTH / 2;
resetButton.y = endGameButton.y + 200;
game.addChild(resetButton);
+ // Debugging: Log to ensure animations are triggered
LK.clearInterval(playTimeInterval);
- playTimeInterval = null;
+ playTimeInterval = null; // Reset the interval variable to null
+ playTimeInterval = null; // Reset the interval variable to null
}
-function _toConsumableArray2(r) {/* Unchanged utility functions */}
-function _nonIterableSpread2() {/* Unchanged */}
-function _unsupportedIterableToArray2(r, a) {/* Unchanged */}
-function _iterableToArray2(r) {/* Unchanged */}
-function _arrayWithoutHoles2(r) {/* Unchanged */}
-function _arrayLikeToArray2(r, a) {/* Unchanged */}
-function _toConsumableArray(r) {/* Unchanged */}
-function _nonIterableSpread() {/* Unchanged */}
-function _unsupportedIterableToArray(r, a) {/* Unchanged */}
-function _iterableToArray(r) {/* Unchanged */}
-function _arrayWithoutHoles(r) {/* Unchanged */}
-function _arrayLikeToArray(r, a) {/* Unchanged */}
+function _toConsumableArray2(r) {
+ return _arrayWithoutHoles2(r) || _iterableToArray2(r) || _unsupportedIterableToArray2(r) || _nonIterableSpread2();
+}
+function _nonIterableSpread2() {
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+}
+function _unsupportedIterableToArray2(r, a) {
+ if (r) {
+ if ("string" == typeof r) {
+ return _arrayLikeToArray2(r, a);
+ }
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray2(r, a) : void 0;
+ }
+}
+function _iterableToArray2(r) {
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
+ return Array.from(r);
+ }
+}
+function _arrayWithoutHoles2(r) {
+ if (Array.isArray(r)) {
+ return _arrayLikeToArray2(r);
+ }
+}
+function _arrayLikeToArray2(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) {
+ n[e] = r[e];
+ }
+ return n;
+}
+function _toConsumableArray(r) {
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
+}
+function _nonIterableSpread() {
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+}
+function _unsupportedIterableToArray(r, a) {
+ if (r) {
+ if ("string" == typeof r) {
+ return _arrayLikeToArray(r, a);
+ }
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
+ }
+}
+function _iterableToArray(r) {
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
+ return Array.from(r);
+ }
+}
+function _arrayWithoutHoles(r) {
+ if (Array.isArray(r)) {
+ return _arrayLikeToArray(r);
+ }
+}
+function _arrayLikeToArray(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) {
+ n[e] = r[e];
+ }
+ return n;
+}
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2632;
var BALL_RADIUS = 50;
-var BRICK_WIDTH = 299;
-var BRICK_HEIGHT = 98;
-var BRICK_HALF_WIDTH = BRICK_WIDTH / 2;
-var BRICK_HALF_HEIGHT = BRICK_HEIGHT / 2;
+var BRICK_WIDTH = 300;
+var BRICK_HEIGHT = 99;
var LEVEL_COLORS = [0xff00ff, 0x00ffff, 0xffff00, 0xff0066, 0x00ff99, 0xff33cc, 0x66ff33, 0xcc00ff, 0x33ffcc, 0xff3300];
var levelConfig = {
1: {
totalBricks: 70,
@@ -508,16 +554,18 @@
sniper: false,
scatter: false
};
var playTime = storage.playTime || 0;
-var playTimeInterval = LK.setInterval(function () {
+playTimeInterval = LK.setInterval(function () {
if (!game.isGameOver) {
+ // Check if the game is not over
playTime += 1;
storage.playTime = playTime;
console.log('Time Played2:', playTime, 'seconds');
}
}, 1000);
-game.isGameOver = false;
+var playTimeInterval = null;
+game.isGameOver = false; // Initialize the flag to indicate the end screen is not up
function clearLocalStorage() {
storage.score = 0;
storage.level = 1;
storage.unlockedTiers = {
@@ -570,9 +618,9 @@
var hud = new Container();
LK.gui.top.addChild(hud);
var scoreTxt = new Text2('$0', {
size: 60,
- fill: 0x39ff14
+ fill: 0x39ff14 // Neon green color
});
scoreTxt.anchor.set(0.3, 0);
scoreTxt.x += 450;
hud.addChild(scoreTxt);
@@ -602,22 +650,24 @@
scaleX: 0.6,
scaleY: 0.6,
y: -10
});
- ballIcon.tint = type === 'splash' ? 0xff0066 : type === 'sniper' ? 0x00ff99 : type === 'scatter' ? 0xffff00 : 0xffffff;
+ // Set initial tint
+ ballIcon.tint = type === 'splash' ? 0xff0066 : type === 'sniper' ? 0x00ff99 : type === 'scatter' ? 0xffff00 : 0xffffff; // Normal ball
contentContainer.addChild(ballIcon);
var displayType = type === 'scatter' ? 'Multi' : type.charAt(0).toUpperCase() + type.slice(1);
var typeText = new Text2(displayType, {
size: 30,
fill: 0xffffff,
+ // Initial white color
fontWeight: 'bold'
});
typeText.anchor.set(0.5, 0);
typeText.y = -50;
button.addChild(typeText);
- var costText = new Text2('$' + upgrades[type + 'BallCost'], {
+ var costText = new Text2('$' + (type === 'sniper' ? 500 : type === 'splash' ? 150 : type === 'scatter' ? 2000 : upgrades[type + 'BallCost']), {
size: 40,
- fill: 0xffffff
+ fill: 0xffffff // Change to white color
});
costText.anchor.set(0.5, 0);
costText.y = 100;
button.addChild(costText);
@@ -625,8 +675,9 @@
button.down = function () {
if (score < upgrades[type + 'BallCost']) {
return;
}
+ // Remove welcome message if it exists
if (welcomeText && welcomeText.parent) {
welcomeText.parent.removeChild(welcomeText);
}
score -= upgrades[type + 'BallCost'];
@@ -644,13 +695,20 @@
}
};
button.updateState = function () {
var isEnabled = (prevTier ? unlockedTiers[prevTier] : true) && score >= upgrades[type + 'BallCost'];
- buttonGraphics.tint = isEnabled ? 0x00ffff : 0x666666;
+ buttonGraphics.tint = isEnabled ? 0x00ffff : 0x666666; // Button background tint
button.interactive = isEnabled;
- ballIcon.tint = isEnabled ? type === 'splash' ? 0xff0066 : type === 'sniper' ? 0x00ff99 : type === 'scatter' ? 0xffff00 : 0xffffff : 0x666666;
- typeText.fill = isEnabled ? 0xffffff : 0x666666;
- costText.fill = isEnabled ? 0x00ffff : 0x666666;
+ // Update ballIcon tint based on enabled state
+ if (isEnabled) {
+ ballIcon.tint = type === 'splash' ? 0xff0066 : type === 'sniper' ? 0x00ff99 : type === 'scatter' ? 0xffff00 : 0xffffff; // Restore original ball color
+ typeText.fill = 0xffffff; // White for ball name
+ costText.fill = 0x00ffff; // Cyan for price
+ } else {
+ ballIcon.tint = 0x666666; // Grey out ball icon
+ typeText.fill = 0x666666; // Grey out ball name
+ costText.fill = 0x666666; // Grey out price
+ }
};
hud.addChild(button);
ballButtons[type] = button;
}
@@ -702,9 +760,9 @@
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5,
y: 40,
- tint: iconType === 'splashBall' ? 0xff0066 : iconType === 'sniperBall' ? 0x00ff99 : iconType === 'scatterBall' ? 0xffff00 : 0xffffff
+ tint: iconType === 'splashBall' ? 0xff0066 : iconType === 'sniperBall' ? 0x00ff99 : iconType === 'scatterBall' ? 0xffff00 : iconType === 'ball' ? 0xffffff : 0x00ffff // Fallback
});
contentContainer.addChild(icon);
}
var labelText = new Text2("".concat(labelPrefix, " x").concat(upgrades[upgradeKey]), {
@@ -723,8 +781,9 @@
costText.y = 140;
contentContainer.addChild(costText);
button.interactive = true;
button.down = function () {
+ // Remove welcome message if it exists
if (welcomeText && welcomeText.parent) {
welcomeText.parent.removeChild(welcomeText);
}
var cost = baseCost * upgrades[upgradeKey];
@@ -763,12 +822,19 @@
};
button.updateState = function () {
var ballType = upgradeKey.split('Speed')[0].split('Power')[0];
var isEnabled = upgradeKey === 'clickDamage' ? score >= baseCost * upgrades[upgradeKey] : unlockedTiers[ballType] && (prevTier ? unlockedTiers[prevTier] : true) && score >= baseCost * upgrades[upgradeKey];
- buttonGraphics.tint = isEnabled ? 0x00ffff : 0x666666;
+ buttonGraphics.tint = isEnabled ? 0x00ffff : 0x666666; // Button background tint
button.interactive = isEnabled;
+ // Update icon tint based on enabled state
if (icon) {
- icon.tint = isEnabled ? iconType === 'splashBall' ? 0xff0066 : iconType === 'sniperBall' ? 0x00ff99 : iconType === 'scatterBall' ? 0xffff00 : 0xffffff : 0x666666;
+ if (isEnabled) {
+ // Restore original ball color when enabled
+ icon.tint = iconType === 'splashBall' ? 0xff0066 : iconType === 'sniperBall' ? 0x00ff99 : iconType === 'scatterBall' ? 0xffff00 : iconType === 'ball' ? 0xffffff : 0x00ffff;
+ } else {
+ // Grey out when disabled
+ icon.tint = 0x666666;
+ }
}
};
powerupContainer.addChild(button);
upgradeButtons[upgradeKey] = button;
@@ -801,65 +867,23 @@
for (var key in upgradeButtons) {
upgradeButtons[key].updateState();
}
}
-function handleBallBrickCollision(ball, brick, stepX, stepY) {
- var ballLeft = ball.x - BALL_RADIUS;
- var ballRight = ball.x + BALL_RADIUS;
- var ballTop = ball.y - BALL_RADIUS;
- var ballBottom = ball.y + BALL_RADIUS;
- var brickLeft = brick.x - BRICK_HALF_WIDTH;
- var brickRight = brick.x + BRICK_HALF_WIDTH;
- var brickTop = brick.y - BRICK_HALF_HEIGHT;
- var brickBottom = brick.y + BRICK_HALF_HEIGHT;
- var prevX = ball.x - stepX;
- var prevY = ball.y - stepY;
- var tXEntry, tXExit, tYEntry, tYExit;
- if (stepX === 0) {
- tXEntry = -Infinity;
- tXExit = Infinity;
+function handleBallBrickCollision(ball, brick) {
+ var relativeX = (ball.x - brick.x) / (brick.width / 2);
+ var relativeY = (ball.y - brick.y) / (brick.height / 2);
+ if (Math.abs(relativeX) > Math.abs(relativeY)) {
+ ball.direction.x = -ball.direction.x + relativeX * 0.5;
+ ball.x = brick.x + (relativeX > 0 ? brick.width / 2 + BALL_RADIUS : -brick.width / 2 - BALL_RADIUS);
} else {
- tXEntry = (brickLeft - (prevX + BALL_RADIUS)) / stepX;
- tXExit = (brickRight - (prevX - BALL_RADIUS)) / stepX;
- if (stepX < 0) {
- var _ref = [tXExit, tXEntry];
- tXEntry = _ref[0];
- tXExit = _ref[1];
- }
+ ball.direction.y = -ball.direction.y;
+ ball.y = brick.y + (relativeY > 0 ? brick.height / 2 + BALL_RADIUS : -brick.height / 2 - BALL_RADIUS);
}
- if (stepY === 0) {
- tYEntry = -Infinity;
- tYExit = Infinity;
- } else {
- tYEntry = (brickTop - (prevY + BALL_RADIUS)) / stepY;
- tYExit = (brickBottom - (prevY - BALL_RADIUS)) / stepY;
- if (stepY < 0) {
- var _ref2 = [tYExit, tYEntry];
- tYEntry = _ref2[0];
- tYExit = _ref2[1];
- }
- }
- var tEntry = Math.max(tXEntry, tYEntry);
- var tExit = Math.min(tXExit, tYExit);
- if (tEntry > tExit || tEntry < 0 || tEntry > 1) {
- return;
- }
- ball.x = prevX + stepX * tEntry;
- ball.y = prevY + stepY * tEntry;
- var dx = ball.x - brick.x;
- var dy = ball.y - brick.y;
- var absDx = Math.abs(dx);
- var absDy = Math.abs(dy);
- if (absDx * BRICK_HALF_HEIGHT > absDy * BRICK_HALF_WIDTH) {
- ball.direction.x *= -1;
- ball.x = brick.x + (dx > 0 ? BRICK_HALF_WIDTH + BALL_RADIUS : -BRICK_HALF_WIDTH - BALL_RADIUS);
- } else {
- ball.direction.y *= -1;
- ball.y = brick.y + (dy > 0 ? BRICK_HALF_HEIGHT + BALL_RADIUS : -BRICK_HALF_HEIGHT - BALL_RADIUS);
- }
- ball.direction.x += (Math.random() - 0.5) * 0.1;
- normalizeDirection(ball);
LK.getSound('bounce').play();
+ ball.direction.x += (Math.random() - 0.5) * 0.1;
+ 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 applySplashDamage(brick, gridSize) {
var gridX = Math.floor(brick.x / gridSize);
var gridY = Math.floor(brick.y / gridSize);
@@ -867,9 +891,9 @@
adjacentKeys.forEach(function (key) {
if (brickGrid[key]) {
brickGrid[key].forEach(function (adjBrick) {
if (adjBrick && adjBrick.health > 0) {
- adjBrick.hit(Math.floor(upgrades.splashPower * 0.25));
+ adjBrick.hit(Math.floor(upgrades.splashPower * 0.5));
}
});
}
});
@@ -909,16 +933,16 @@
}
function createBricks() {
var config = levelConfig[level] || {};
var totalBricks = config.totalBricks || 50;
- var baseHitpoints = config.hitpoints || 1;
+ var baseHitpoints = config.hitpoints || 1; // Base HP from level config
var gridSize = config.gridSize || 200;
var pattern = config.pattern || 'grid';
- var spacingX = 1;
+ var spacingX = 1; // Reduced spacing between columns
var spacingY = 2;
brickGrid = {};
bricks = [];
- var cols = 7;
+ var cols = 7; // Set to 7 columns
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;
@@ -931,28 +955,34 @@
brickCount++;
}
}
} else if (pattern === 'staggered') {
- var centerRow = Math.floor(rows / 2);
- var centerCol = Math.floor(cols / 2);
+ // Staggered pattern with HP gradient from center
+ var centerRow = Math.floor(rows / 2); // Approximate center row
+ var centerCol = Math.floor(cols / 2); // Approximate center column
for (var i = 0; i < rows && brickCount < totalBricks; i++) {
- var offsetX = 0;
+ var offsetX = 0; // No offset for staggered grid
for (var j = 0; j < cols && brickCount < totalBricks; j++) {
var x = startX + offsetX + j * (BRICK_WIDTH + spacingX);
var y = startY + i * (BRICK_HEIGHT + spacingY);
+ // Calculate distance from center (Manhattan distance for simplicity)
var rowDistance = Math.abs(i - centerRow);
var colDistance = Math.abs(j - centerCol);
- var maxDistance = Math.max(centerRow, centerCol);
+ var maxDistance = Math.max(centerRow, centerCol); // Max possible distance to edge
var distance = Math.max(rowDistance, colDistance);
+ // HP decreases linearly from center to edge
+ // Center gets baseHitpoints, edges get at least 1 HP
var hitpoints = Math.max(1, Math.round(baseHitpoints * (1 - distance / maxDistance)));
addBrick(x, y, hitpoints, gridSize);
brickCount++;
}
}
} else if (pattern === 'clustered') {
+ // Clustered pattern: fill from outside in
var centerRow = Math.floor(rows / 2);
var centerCol = Math.floor(cols / 2);
var maxDistance = Math.max(centerRow, centerCol);
+ // Create a list of all possible grid positions with their distances
var positions = [];
for (var i = 0; i < rows; i++) {
for (var j = 0; j < cols; j++) {
var rowDistance = Math.abs(i - centerRow);
@@ -964,36 +994,76 @@
distance: distance
});
}
}
+ // Sort positions by distance (descending) to fill from outside in
positions.sort(function (a, b) {
return b.distance - a.distance;
});
+ // Place bricks up to totalBricks limit
for (var k = 0; k < positions.length && brickCount < totalBricks; k++) {
var pos = positions[k];
var i = pos.i;
var j = pos.j;
var distance = pos.distance;
var x = startX + j * (BRICK_WIDTH + spacingX);
var y = startY + i * (BRICK_HEIGHT + spacingY);
+ // Optional: HP can still vary if desired, higher on edges here
var hitpoints = Math.max(1, Math.round(baseHitpoints * (distance / maxDistance)));
addBrick(x, y, hitpoints, gridSize);
brickCount++;
}
+ } else if (pattern === 'diagonal') {
+ // [Unchanged diagonal pattern code]
+ var stepX = (GAME_WIDTH - BRICK_WIDTH) / (totalBricks - 1);
+ var stepY = GAME_HEIGHT / 3 / (totalBricks - 1);
+ for (var i = 0; i < totalBricks; i++) {
+ var offsetX = i % 2 === 0 ? BRICK_WIDTH / 4 : 0;
+ addBrick(startX + i * stepX + offsetX, startY + i * stepY, baseHitpoints, gridSize);
+ brickCount++;
+ }
+ } else if (pattern === 'sparse') {
+ // Sparse pattern: groups of 3 rows with 2-row gaps
+ var groupSize = 3; // 3 rows per group
+ var gapSize = 2; // 2 rows gap
+ var cycleLength = groupSize + gapSize; // Total rows in one cycle (3 + 2 = 5)
+ while (brickCount < totalBricks) {
+ // Pick a random column
+ var col = Math.floor(Math.random() * cols);
+ var x = startX + col * (BRICK_WIDTH + spacingX);
+ // Pick a random group start row, ensuring space for 3 rows
+ var maxGroupStart = rows - groupSize; // Leave room for 3 rows
+ var groupStart = Math.floor(Math.random() * Math.floor(maxGroupStart / cycleLength)) * cycleLength;
+ // Place bricks in the 3 rows of the group
+ for (var rowOffset = 0; rowOffset < groupSize && brickCount < totalBricks; rowOffset++) {
+ var row = groupStart + rowOffset;
+ if (row >= rows) {
+ continue;
+ } // Skip if beyond grid bounds
+ var y = startY + row * (BRICK_HEIGHT + spacingY);
+ // Check for collision to maintain sparsity
+ if (!bricks.some(function (b) {
+ return b.x === x && b.y === y;
+ })) {
+ addBrick(x, y, baseHitpoints, gridSize);
+ brickCount++;
+ }
+ }
+ }
}
brickGridBounds = {
- minX: Math.min.apply(Math, bricks.map(function (b) {
- return b.x - BRICK_HALF_WIDTH;
- })),
- maxX: Math.max.apply(Math, bricks.map(function (b) {
- return b.x + BRICK_HALF_WIDTH;
- })),
- minY: Math.min.apply(Math, bricks.map(function (b) {
- return b.y - BRICK_HALF_HEIGHT;
- })),
- maxY: Math.max.apply(Math, bricks.map(function (b) {
- return b.y + BRICK_HALF_HEIGHT;
- }))
+ minX: Math.min.apply(Math, _toConsumableArray2(bricks.map(function (b) {
+ return b.x - BRICK_WIDTH / 2;
+ }))),
+ maxX: Math.max.apply(Math, _toConsumableArray2(bricks.map(function (b) {
+ return b.x + BRICK_WIDTH / 2;
+ }))),
+ minY: Math.min.apply(Math, _toConsumableArray2(bricks.map(function (b) {
+ return b.y - BRICK_HEIGHT / 2;
+ }))),
+ maxY: Math.max.apply(Math, _toConsumableArray2(bricks.map(function (b) {
+ return b.y + BRICK_HEIGHT / 2;
+ })))
};
}
function addBrick(x, y, hitpoints, gridSize) {
var brick = new Brick();
@@ -1021,9 +1091,11 @@
ball.y = Math.min(gridBottom + 100, GAME_HEIGHT - BALL_RADIUS * 2);
var angle = (Math.random() * 0.5 + 0.25) * Math.PI;
ball.direction.x = Math.cos(angle);
ball.direction.y = -Math.sin(angle);
- normalizeDirection(ball);
+ var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y);
+ ball.direction.x /= magnitude;
+ ball.direction.y /= magnitude;
for (var i = 0; i < bricks.length; i++) {
if (ball.intersects(bricks[i])) {
ball.y = brickGridBounds.maxY + BALL_RADIUS + 10;
break;
@@ -1031,15 +1103,8 @@
}
balls.push(ball);
game.addChild(ball);
}
-function normalizeDirection(ball) {
- var magnitude = Math.sqrt(ball.direction.x * ball.direction.x + ball.direction.y * ball.direction.y);
- if (magnitude > 0) {
- ball.direction.x /= magnitude;
- ball.direction.y /= magnitude;
- }
-}
game.update = function () {
for (var i = 0; i < stars.length; i++) {
stars[i].update();
}
@@ -1061,8 +1126,10 @@
createBricks();
}
}
updateButtonStates();
+ // Increment playTime by 1 second (assuming update is called 60 times per second)
+ // Removed playTime increment to ensure it only prints once
};
game.down = function (x, y, obj) {
if (!bricks || !Array.isArray(bricks)) {
return;
@@ -1165,23 +1232,28 @@
resetButton.visible = false;
upgradeButton.visible = true;
hud.visible = true;
createBricks();
+ // Check if it's the first time the game is loaded
if (storage.firstLoad !== true) {
+ // Display welcome message
welcomeText = new Text2('Welcome! Click to cash in and power up!', {
size: 90,
fill: 0xffffff
});
welcomeText.anchor.set(0.5, 0);
welcomeText.x = GAME_WIDTH / 2;
welcomeText.y = GAME_HEIGHT / 2 + 600;
game.addChild(welcomeText);
+ // Set firstLoad to true to prevent showing the message again
storage.firstLoad = true;
}
playTimeInterval = LK.setInterval(function () {
playTime += 1;
+ // Ensure playTime is printed once
console.log('Time Played:', playTime, 'seconds');
}, 1000);
+ // Load balls from storage
for (var type in ballQuantities) {
for (var i = 0; i < ballQuantities[type]; i++) {
createBall(type);
}