User prompt
In LifeIndicator calculate x position such that lives are centered in the element
User prompt
do not set lifeIndicator.x
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'lifeIndicator.anchor.set')' in this line: 'lifeIndicator.anchor.set(0.5, 0);' Line Number: 247
User prompt
Add life indicator to topCenter
User prompt
Do not set y of lifeIndicator
User prompt
Show lives as 10 hearts
User prompt
Add a life indicator to the game, that shows that you have 10 lives. This indicator should show below score.
User prompt
initialize totalCellTypes with 4
User prompt
Make totalTypes an argument that is passed to cell
Code edit (3 edits merged)
Please save this source code
User prompt
Move score calculation code to attachCellListeners
User prompt
Score should be increased based on how many nodes exist cellsToDestroy. With bonuses for removing more cells in one click
User prompt
Add a score variable to the game
User prompt
At bottom of tick, if no cells are moving, check if we have any possible moves. If not call resetBoard
User prompt
Remove the endOfRoundCondition if and related endOfRoundCondition variable
User prompt
Fix Bug: 'ReferenceError: Can't find variable: endOfRoundCondition' in this line: 'if (endOfRoundCondition) {' Line Number: 97
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self')' in this line: 'self.resetBoard = function () {' Line Number: 81
User prompt
Add the ability for the game to reset the board and start next round
User prompt
set boardBackground alpha to .7ยจ
User prompt
When positing boardBackground subtract half half of cell width and hight
Code edit (1 edits merged)
Please save this source code
User prompt
factor in the boardBackground width and hight when centering it
Code edit (1 edits merged)
Please save this source code
User prompt
After calculating total grid size, use this information to move boardBackground such that it's centered behind the board
User prompt
After calculating total grid size, use this information to center boardBackground on the board.
function hsvToRgb(h, s, v) {
var i = Math.floor(h * 6), f = h * 6 - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
return (r * 255 << 16) + (g * 255 << 8) + b * 255;
}
var Snowflake = Container.expand(function () {
var self = Container.call(this);
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = Math.random() * 0.05 - 0.025;
var flakeGraphics = self.createAsset('snowflake', 'Snowflake', 0.5, 0.5);
self.speed = Math.random() * 1.5 + 1;
self.direction = Math.random() * Math.PI * 2;
self.xSpeed = Math.cos(self.direction) * Math.abs(Math.random() * 1 + 0.5);
self.ySpeed = Math.abs(Math.sin(self.direction)) * self.speed;
self.tick = function () {
self.x += self.xSpeed;
self.y += self.ySpeed;
self.scale.x = self.scale.y = 0.5 + self.ySpeed / 6;
self.rotation += self.rotationSpeed;
if (self.x > 2048 || self.x < 0 || self.y > 2732) {
self.x = Math.random() * 2048;
self.y = -50;
}
};
});
var Cell = Container.expand(function (type) {
var self = Container.call(this);
self.targetX = 0;
self.targetY = 0;
self.isMoving = false;
self.totalTypes = 8;
self.type = typeof type === 'undefined' ? Math.floor(Math.random() * self.totalTypes) : type;
var assetName = 'cellType' + self.type;
var cellBackground = self.createAsset('cellBackground', 'Cell Background', .5, .5);
cellBackground.alpha = 0;
var cellGraphics = self.createAsset(assetName, 'Grid Cell Type ' + self.type, .5, .5);
self.move = function (x, y, instant) {
self.targetX = x;
self.targetY = y;
if (instant) {
self.x = x;
self.y = y;
}
};
self.tick = function () {
var acceleration = 2;
self.speedX = self.speedX || 0;
self.speedY = self.speedY || 0;
var threshold = 1;
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
if (Math.abs(dx) < threshold && Math.abs(dy) < threshold) {
self.x = self.targetX;
self.y = self.targetY;
self.isMoving = false;
self.speedX = 0;
self.speedY = 0;
} else {
if (dx !== 0) {
self.speedX += dx > 0 ? acceleration : -acceleration;
}
if (dy !== 0) {
self.speedY += dy > 0 ? acceleration : -acceleration;
}
var nextX = self.x + self.speedX;
var nextY = self.y + self.speedY;
if (self.speedX > 0 && nextX > self.targetX || self.speedX < 0 && nextX < self.targetX) {
nextX = self.targetX;
self.speedX = 0;
}
if (self.speedY > 0 && nextY > self.targetY || self.speedY < 0 && nextY < self.targetY) {
nextY = self.targetY;
self.speedY = 0;
}
self.x = nextX;
self.y = nextY;
self.isMoving = self.x !== self.targetX || self.y !== self.targetY;
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('background', 'Game Background', 0.5, 0.5);
background.x = 2048 / 2;
background.y = 2732 / 2;
self.addChild(background);
var gridWidth = 8;
var gridHeight = 8;
var gridSpacing = 8;
var cellWidth = 180;
var cellHeight = 180;
var gridContainer = new Container();
var boardBackground = self.createAsset('boardBackground', 'Board Background', 0.5, 0.5);
gridContainer.addChildAt(boardBackground, 0);
self.addChild(gridContainer);
var totalGridWidth = gridWidth * (cellWidth + gridSpacing) - gridSpacing;
var totalGridHeight = gridHeight * (cellHeight + gridSpacing) - gridSpacing;
boardBackground.x = totalGridWidth / 2;
boardBackground.y = totalGridHeight / 2;
self.calculateTargetPosition = function (col, row) {
return {
x: col * (cellWidth + gridSpacing),
y: row * (cellHeight + gridSpacing)
};
};
self.findConnectedNeighbors = function (cell, connectedNeighbors) {
connectedNeighbors = connectedNeighbors || [];
if (!cell) return [];
var cellType = cell.type;
var cellColRow = self.findCellColRow(cell);
if (cellColRow) {
var directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];
directions.forEach(function (dir) {
var newRow = cellColRow.row + dir[0];
var newCol = cellColRow.col + dir[1];
if (newRow >= 0 && newRow < gridHeight && newCol >= 0 && newCol < gridWidth) {
var neighborCell = grid[newCol][newRow];
if (neighborCell && neighborCell.type === cellType && connectedNeighbors.indexOf(neighborCell) === -1) {
connectedNeighbors.push(neighborCell);
self.findConnectedNeighbors(neighborCell, connectedNeighbors);
}
}
});
}
return connectedNeighbors;
};
self.findCellColRow = function (cell) {
for (var col = 0; col < gridWidth; col++) {
for (var row = 0; row < gridHeight; row++) {
if (grid[col][row] === cell) {
return {
col: col,
row: row
};
}
}
}
return null;
};
self.deleteCell = function (cell) {
var colRow = self.findCellColRow(cell);
if (colRow) {
grid[colRow.col][colRow.row] = null;
cell.destroy();
}
};
self.attachCellListeners = function (cell) {
cell.on('down', function (obj) {
var connectedNeighbors = self.findConnectedNeighbors(cell);
if (connectedNeighbors.length > 0) {
var cellsToDestroy = [cell].concat(connectedNeighbors);
cellsToDestroy.forEach(function (cell) {
self.deleteCell(cell);
});
self.moveToEmptySpace('down', false);
self.moveToEmptySpace('left', true);
}
});
cell.on('up', function (obj) {});
cell.on('move', function (obj) {});
};
var grid = [];
for (var i = 0; i < gridWidth; i++) {
grid[i] = [];
for (var j = 0; j < gridHeight; j++) {
var cell = new Cell();
var targetPos = self.calculateTargetPosition(i, j);
cell.move(targetPos.x, targetPos.y, true);
self.attachCellListeners(cell);
grid[i][j] = cell;
gridContainer.addChild(cell);
}
}
self.moveToEmptySpace = function (direction, rowMode) {
var moved;
do {
moved = false;
var dx = direction === 'left' ? 1 : direction === 'right' ? -1 : 0;
var dy = direction === 'up' ? 1 : direction === 'down' ? -1 : 0;
for (var col = 0; col < gridWidth; col++) {
for (var row = 0; row < gridHeight; row++) {
if (!grid[col][row]) {
var isRowOrColumnEmpty = true;
if (rowMode) {
for (var checkIndex = 0; checkIndex < (direction === 'left' || direction === 'right' ? gridHeight : gridWidth); checkIndex++) {
isRowOrColumnEmpty = isRowOrColumnEmpty && !grid[direction === 'left' || direction === 'right' ? col : checkIndex][direction === 'up' || direction === 'down' ? row : checkIndex];
}
}
if (isRowOrColumnEmpty) {
if (rowMode) {
for (var checkIndex = 0; checkIndex < (direction === 'left' || direction === 'right' ? gridHeight : gridWidth); checkIndex++) {
var targetCol = direction === 'left' || direction === 'right' ? col : checkIndex;
var targetRow = direction === 'up' || direction === 'down' ? row : checkIndex;
if (targetCol + dx >= 0 && targetCol + dx < gridWidth && targetRow + dy >= 0 && targetRow + dy < gridHeight && grid[targetCol + dx][targetRow + dy]) {
var targetCell = grid[targetCol + dx][targetRow + dy];
var targetPos = self.calculateTargetPosition(targetCol, targetRow);
targetCell.move(targetPos.x, targetPos.y);
grid[targetCol][targetRow] = targetCell;
grid[targetCol + dx][targetRow + dy] = null;
moved = true;
}
}
} else {
var targetCol = col + dx;
var targetRow = row + dy;
if (targetCol >= 0 && targetCol < gridWidth && targetRow >= 0 && targetRow < gridHeight && grid[targetCol][targetRow]) {
var targetCell = grid[targetCol][targetRow];
var targetPos = self.calculateTargetPosition(col, row);
targetCell.move(targetPos.x, targetPos.y);
grid[col][row] = targetCell;
grid[targetCol][targetRow] = null;
moved = true;
}
}
}
}
}
}
} while (moved);
};
var maxSnowflakes = 100;
var snowflakeContainer = new Container();
self.addChildAt(snowflakeContainer, 1);
var snowflakes = [];
for (var i = 0; i < maxSnowflakes; i++) {
var flake = new Snowflake();
flake.x = Math.random() * 2048;
flake.y = Math.random() * 2732;
snowflakeContainer.addChild(flake);
snowflakes.push(flake);
}
LK.on('tick', function () {
for (var i = 0; i < gridWidth; i++) {
for (var j = 0; j < gridHeight; j++) {
if (grid[i][j]) grid[i][j].tick();
}
}
for (var i = 0; i < snowflakes.length; i++) {
snowflakes[i].tick();
}
});
});
Cartoon Christmas decoration Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas candy cane Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas stocking Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas yellow starr Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas ornament Blue Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas snow flake. Blue Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas outdoor scene. Forest, northern lights. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White square. Narrow round corners. Background element. Flat. Vector. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas heart Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Simple Cartoon Christmas particle. White. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas ornament yellow and purple Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon Christmas snow man head. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Simple Cartoon Christmas wreath. Purple Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.