Code edit (20 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'bobble.y += launcher.y - self.y;' Line Number: 275
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var dist = bubble.y - nextYx - self.x;' Line Number: 243
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (21 edits merged)
Please save this source code
User prompt
Add a method to Grid, that takes a point and a direction given as an angle and returns a path of movement as an array of points. It should do this by starting at the point, stepping 10px in the direction of the angle with the following rules. * If the left wall or right wall is hit, bounce * If the top of the screen is hit, stop * If a bubble in the rows array is hit bounce. To do intersection testing, use circle to circle intersection, with the radius of the circle used for the iteration being 70
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Add a function to the game code that is used to increase the game score. This should use LK methods to update score and also update the label value
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
The score colors does not work as the format must be "#xxxxxx"
User prompt
In ScoreIndicatorLabel use the bubbleColors values to set color based on type. Make sure to covert to string hex values
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'scoreMultipliers[Math.floor(self.x / (2048 / 5))].applyBubble')' in or related to this line: 'scoreMultipliers[Math.floor(self.x / (2048 / 5))].applyBubble(self);' Line Number: 77
Code edit (5 edits merged)
Please save this source code
User prompt
If unattached bubbles falls below 2732 - 500 remove them
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
In ScoreMultipliers add a score label text string. This should be white with the font Impact.
/****
* Classes
****/
var Barrier = Container.expand(function () {
var self = Container.call(this);
var barrierGraphics = self.attachAsset('barrier', {
anchorX: .5,
anchorY: .5
});
});
var Bubble = Container.expand(function (max_types) {
var self = Container.call(this);
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xff00ff, 0xffff00, 0x00ffff, 0xffffff];
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5
});
var state = 0;
var targetX = 0;
var targetY = 0;
var isAttached = true;
var speedX = 0;
var speedY = 0;
self.setPos = function (x, y) {
self.x = targetX = x;
self.y = targetY = y;
};
max_types = max_types || 3;
self.type = Math.floor(Math.random() * max_types);
bubbleGraphics.tint = colors[self.type];
self.detatch = function () {
game.addChild(self);
self.y += grid.y;
isAttached = false;
speedX = Math.random() * 40 - 20;
speedY = -Math.random() * 30;
self.down = undefined;
};
self.update = function () {
if (!isAttached) {
self.x += speedX;
self.y += speedY;
speedY += 1.5;
if (self.x < self.width / 2 && speedX < 0 || self.x > game.width - self.width / 2 && speedX > 0) {
speedX = -speedX;
}
// Check for collision with barriers
for (var i = 0; i < barriers.length; i++) {
var barrier = barriers[i];
var dx = self.x - barrier.x;
var dy = self.y - barrier.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDist = self.width / 2 + barrier.width / 2;
if (distance < minDist) {
// Calculate the angle of the collision
var angle = Math.atan2(dy, dx);
// Calculate the new speed based on the angle of collision, treating the barrier as a static billiard ball
var newSpeed = Math.sqrt(speedX * speedX + speedY * speedY);
speedX = Math.cos(angle) * newSpeed * .7;
speedY = Math.sin(angle) * newSpeed * .7;
// Move the bubble back to the point where it just touches the barrier
var overlap = minDist - distance;
self.x += overlap * Math.cos(angle);
self.y += overlap * Math.sin(angle);
}
}
}
};
});
var Grid = Container.expand(function () {
var self = Container.call(this);
var rows = [];
self.container = self.addChild(new Container());
var rowCount = 0;
function insertRow() {
var row = [];
var rowWidth = rowCount % 2 == 0 ? 13 : 12;
for (var a = 0; a < rowWidth; a++) {
var bubble = new Bubble();
bubble.setPos((2048 - bubble.width * rowWidth) / 2 + bubble.width * a + bubble.width / 2, -rowCount * (1.7320508076 * bubble.height) / 2);
self.container.addChild(bubble);
row.push(bubble);
bubble.down = function () {
var bubbles = self.getConnectedBubbles(this);
self.removeBubbles(bubbles);
var disconnected = self.getDetachedBubbles();
self.removeBubbles(disconnected);
};
}
rows.push(row);
rowCount++;
}
//Method that removes an array of bubbles from the rows array.
self.removeBubbles = function (bubbles) {
for (var i = 0; i < bubbles.length; i++) {
var bubble = bubbles[i];
var bubbleIndex = this.findBubbleIndex(bubble);
if (bubbleIndex) {
rows[bubbleIndex.row][bubbleIndex.col] = null;
bubble.detatch();
}
}
};
self.getConnectedBubbles = function (bubble, ignoreType) {
var connectedBubbles = [];
var queue = [bubble];
var visited = [];
while (queue.length > 0) {
var currentBubble = queue.shift();
if (visited.indexOf(currentBubble) === -1) {
visited.push(currentBubble);
connectedBubbles.push(currentBubble);
var neighbors = self.getNeighbors(currentBubble);
for (var i = 0; i < neighbors.length; i++) {
var neighbor = neighbors[i];
if (neighbor && (neighbor.type === bubble.type || ignoreType)) {
queue.push(neighbor);
}
}
}
}
return connectedBubbles;
};
//Get a list of bubbles that are not connected to the top row, or to a chain of bubbles connected to the top row.
self.getDetachedBubbles = function () {
var detachedBubbles = [];
var connectedToTop = [];
// Mark all bubbles connected to the bottom row
var lastRowIndex = rows.length - 1;
for (var i = 0; i < rows[lastRowIndex].length; i++) {
if (rows[lastRowIndex][i] !== null) {
var bottomConnected = self.getConnectedBubbles(rows[lastRowIndex][i], true);
connectedToTop = connectedToTop.concat(bottomConnected);
}
}
// Mark all bubbles as visited or not
var visited = connectedToTop.filter(function (bubble) {
return bubble != null;
});
// Find all bubbles that are not visited and not connected to the top
for (var row = 0; row < rows.length - 1; row++) {
for (var col = 0; col < rows[row].length; col++) {
var bubble = rows[row][col];
if (bubble !== null && visited.indexOf(bubble) == -1) {
detachedBubbles.push(bubble);
}
}
}
return detachedBubbles;
};
self.getNeighbors = function (bubble) {
var neighbors = [];
var bubbleIndex = this.findBubbleIndex(bubble);
var directions = [[-1, 0], [1, 0],
// left and right
[0, -1], [0, 1],
// above and below
[-1, -1], [1, -1] // diagonals for even rows
];
if (bubbleIndex.row % 2 === 1) {
// Adjust diagonals for odd rows
directions[4] = [-1, 1];
directions[5] = [1, 1];
}
for (var i = 0; i < directions.length; i++) {
var dir = directions[i];
var newRow = bubbleIndex.row + dir[0];
var newCol = bubbleIndex.col + dir[1];
if (newRow >= 0 && newRow < rows.length && newCol >= 0 && newCol < rows[newRow].length) {
neighbors.push(rows[newRow][newCol]);
}
}
return neighbors;
};
self.findBubbleIndex = function (bubble) {
for (var row = 0; row < rows.length; row++) {
var col = rows[row].indexOf(bubble);
if (col !== -1) {
return {
row: row,
col: col
};
}
}
return null;
};
insertRow();
insertRow();
insertRow();
insertRow();
insertRow();
insertRow();
insertRow();
insertRow();
insertRow();
});
var HintBubble = Container.expand(function () {
var self = Container.call(this);
});
var Launcher = Container.expand(function () {
var self = Container.call(this);
});
var ScoreMultipliers = Container.expand(function () {
var self = Container.call(this);
// Create a score label text string for ScoreMultipliers
var scoreMultiplierLabel = new Text2('Score Multiplier: x1', {
size: 50,
fill: "#ffffff",
font: "Impact"
});
scoreMultiplierLabel.anchor.set(0.5, 0);
self.addChild(scoreMultiplierLabel);
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x010c42
});
/****
* Game Code
****/
/*
Todo:
[ ] Make sure empty rows are removed from the array
[ ] Make sure we GC nodes that drop of screen
*/
//Game size 2048x2732
var grid = game.addChild(new Grid());
grid.y = 1300;
var barriers = [];
for (var a = 0; a < 4; a++) {
for (var b = 0; b < 4; b++) {
var barrier = game.addChild(new Barrier());
barrier.y = 2732 - 500 + b * 18;
barrier.x = 2048 / 5 * a + 2048 / 5;
barriers.push(barrier);
}
}
// Create a score label
var scoreLabel = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
font: "Impact"
});
scoreLabel.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreLabel);
var scoreMultipliers = [];
for (var a = 0; a < 5; a++) {
var sm = new ScoreMultipliers();
game.addChild(sm);
}
Circular white gradient circle on black background. Gradient from white on the center to black on the outer edge all around.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Soft straight Long red paint on black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Fire ball. Bubble shooter game. Thin black outline.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green notification bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.