Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'self.lightContainer is undefined' in or related to this line: 'self.y = Math.sin(LK.ticks * LAVA_BOB_PERIOD + config.index * LAVA_BOB_OFFSET) * LAVA_BOB_HEIGHT;' Line Number: 158
User prompt
Please fix the bug: 'self.lightContainer is undefined' in or related to this line: 'self.lightContainer.removeChildren();' Line Number: 279
User prompt
Please fix the bug: 'self.parent is null' in or related to this line: 'self.lightContainer = lightManager.addChild(new ConfigContainer({' Line Number: 248
User prompt
Please fix the bug: 'self.parent is null' in or related to this line: 'self.lightContainer = lightManager.addChild(new ConfigContainer({' Line Number: 248
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Point is not a constructor' in or related to this line: 'var lightPosition = self.toGlobal(new Point());' Line Number: 248
User prompt
Please fix the bug: 'e is undefined' in or related to this line: 'var lightPosition = self.toGlobal();' Line Number: 248
Code edit (11 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Point is not a constructor' in or related to this line: 'self.lightContainer = lightManager.addChild(new ConfigContainer({' Line Number: 248
User prompt
In the block class, set the lightContainer x and y position to be the global position of the block
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
before calling the onFinish callback in the Light class's tween, check that it is attached to a parent
Code edit (3 edits merged)
Please save this source code
User prompt
add a callback to the Light's tween that calls it's parent's onLit function
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'downRow is undefined' in or related to this line: 'var downBlock = downRow.blocks[i];' Line Number: 206
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'blockClasses is undefined' in or related to this line: 'var blockClass = blockClasses[i];' Line Number: 183
User prompt
Please fix the bug: 'blockClasses is undefined' in or related to this line: 'var blockClass = blockClasses[i];' Line Number: 183
Code edit (1 edits merged)
Please save this source code
User prompt
in the randomizeBlockClass return a random element in the classes array
Code edit (7 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BlockManager = Container.expand(function () {
var self = Container.call(this);
var blockRows = [];
self.addRow = function (settings) {
blockRows.push(self.addChild(new BlockRow(settings)));
};
self.popRow = function () {
blockRows.pop();
blockRows[0].blocks.forEach(function (block) {
if (block) {
block.downBlock = undefined;
}
});
self.addRow({});
};
return self;
});
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
var destroyCalled = false;
self.tags = {};
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
self.alpha = config.alpha !== undefined ? config.alpha : 1.0;
if (config.scale !== undefined || config.scaleX !== undefined || config.scaleY !== undefined) {
var scaleX = config.scaleX !== undefined ? config.scaleX : config.scale !== undefined ? config.scale : 1;
var scaleY = config.scaleY !== undefined ? config.scaleY : config.scale !== undefined ? config.scale : 1;
self.scale.set(scaleX, scaleY);
}
self.callDestroy = function () {
if (!destroyCalled) {
destroyCalled = true;
self.onDestroy();
self.destroy();
}
};
self.onDestroy = function () {};
return self;
});
var Light = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var lightShape = self.attachAsset('shapeEllipse', {
width: BLOCK_SIZE,
height: BLOCK_SIZE,
anchorX: 0.5,
anchorY: 1,
scaleX: 0,
scaleY: 0,
alpha: 0
});
tween(lightShape, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: LIGHT_GROW_SPEED,
easing: tween.easeInOut
});
return self;
});
var LavaSlice = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
self.attachAsset('lava' + config.index, {
anchorX: 0.5,
anchorY: 0,
width: LAVA_SLICE_WIDTH,
tint: 0xFFA500
});
self.attachAsset('shapeBox', {
width: LAVA_SLICE_WIDTH,
height: 5,
anchorX: 0.5,
anchorY: 0,
tint: 0xFF4D00
});
self.addChild(new Glow({
asset: 'shapeBox',
anchorX: 0.5,
anchorY: 0.75,
height: 20,
rangeY: 150,
width: 3 * LAVA_SLICE_WIDTH,
alpha: 0.25,
tint: 0xFF4D00
}));
self.update = function () {
self.y = Math.sin(LK.ticks * LAVA_BOB_PERIOD + config.index * LAVA_BOB_OFFSET) * LAVA_BOB_HEIGHT;
};
return self;
});
var Lava = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var position = Math.round((-0.5 - LAVA_SLICE_COUNT / 2) * LAVA_SLICE_WIDTH);
for (var i = 1; i <= LAVA_SLICE_COUNT; i++) {
var lavaSlice = self.addChild(new LavaSlice({
x: position += LAVA_SLICE_WIDTH,
index: i
}));
}
return self;
});
var Glow = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var layers = Math.max(2, config.layers || 10);
var layerAlpha = 1 / layers;
var widthStep = (config.rangeX || 0) * layerAlpha;
var heightStep = (config.rangeY || 0) * layerAlpha;
for (var i = 0; i < layers; i++) {
self.attachAsset(config.asset, {
width: config.width + widthStep * i,
height: config.height + heightStep * i,
anchorX: config.anchorX,
anchorY: config.anchorY,
tint: config.tint,
alpha: layerAlpha
});
}
return self;
});
var BlockRow = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var blockClasses = generateBlockClasses(config.index);
self.blocks = [];
for (var i = 0; i < ROW_SPAN; i++) {
var blockClass = blockClasses[i];
self.blocks[i] = self.addChild(new blockClass({
x: (i - ROW_SPAN / 2) * BLOCK_SIZE * BLOCK_SCALE,
scale: BLOCK_SCALE
}));
}
return self;
});
var Block = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var isRotating = false;
self.orientation = config.orientation !== undefined ? config.orientation : Math.floor(4 * Math.random());
self.lit = !!config.lit;
self.upPath = false;
self.rightPath = false;
self.downPath = false;
self.leftPath = false;
self.upBlock;
self.rightBlock;
self.downBlock;
self.leftBlock;
self.attachAsset('shapeBox', {
width: BLOCK_SIZE,
height: BLOCK_SIZE,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.lightContainer = self.addChild(new Container());
self.blockContainer = self.addChild(new ConfigContainer({
rotation: self.orientation * Math.PI / 2
}));
self.rotate = function () {
if (!self.lit && !isRotating) {
isRotating = true;
self.lightContainer.removeChildren();
tween(self.blockContainer, {
rotation: self.blockContainer.rotation + Math.PI / 2
}, {
duration: BLOCK_ROTATE_SPEED,
onFinish: function onFinish() {
isRotating = false;
self.orientation = (self.orientation + 1) % 4;
self.onSettle();
}
});
}
};
self.down = function () {
self.rotate();
};
self.onLit = function () {};
self.onSettle = function () {
self.updatePaths();
if (self.lit) {
if (self.upPath && self.upBlock && !self.upBlock.lit) {
self.upBlock.lightContainer.addChild(new ConfigContainer({
y: BLOCK_HALFSIZE,
rotation: 0
}));
}
if (self.rightPath && self.rightBlock && !self.rightBlock.lit) {
self.rightBlock.lightContainer.addChild(new ConfigContainer({
x: -BLOCK_HALFSIZE,
rotation: Math.PI / 2
}));
}
if (self.downPath && self.downBlock && !self.downBlock.lit) {
self.downBlock.lightContainer.addChild(new ConfigContainer({
y: -BLOCK_HALFSIZE,
rotation: Math.PI
}));
}
if (self.leftPath && self.leftBlock && !self.leftBlock.lit) {
self.leftBlock.lightContainer.addChild(new ConfigContainer({
x: BLOCK_HALFSIZE,
rotation: 3 * Math.PI / 2
}));
}
} else {
if (self.upPath && self.upBlock && self.upBlock.lit) {
self.lightContainer.addChild(new ConfigContainer({
y: -BLOCK_HALFSIZE,
rotation: 0
}));
}
if (self.rightPath && self.rightBlock && self.rightBlock.lit) {
self.lightContainer.addChild(new ConfigContainer({
x: -BLOCK_HALFSIZE,
rotation: Math.PI / 2
}));
}
if (self.downPath && self.downBlock && self.downBlock.lit) {
self.lightContainer.addChild(new ConfigContainer({
y: BLOCK_HALFSIZE,
rotation: Math.PI
}));
}
if (self.leftPath && self.leftBlock && self.leftBlock.lit) {
self.lightContainer.addChild(new ConfigContainer({
x: BLOCK_HALFSIZE,
rotation: 3 * Math.PI / 2
}));
}
}
};
self.updatePaths = function () {};
if (self.lit) {
self.onLit();
}
return self;
});
var BlockX = Block.expand(function (config) {
var self = Block.call(this, config);
self.upPath = true;
self.rightPath = true;
self.downPath = true;
self.leftPath = true;
self.blockContainer.attachAsset('blockX1', {
x: -BLOCK_HALFSIZE,
y: -BLOCK_HALFSIZE,
anchorX: 0,
anchorY: 0
});
self.blockContainer.attachAsset('blockX2', {
x: BLOCK_HALFSIZE,
y: -BLOCK_HALFSIZE,
anchorX: 1,
anchorY: 0
});
self.blockContainer.attachAsset('blockX3', {
x: -BLOCK_HALFSIZE,
y: BLOCK_HALFSIZE,
anchorX: 0,
anchorY: 1
});
self.blockContainer.attachAsset('blockX4', {
x: BLOCK_HALFSIZE,
y: BLOCK_HALFSIZE,
anchorX: 1,
anchorY: 1
});
self.down = function () {};
return self;
});
var BlockT = Block.expand(function (config) {
var self = Block.call(this, config);
self.blockContainer.attachAsset('blockT1', {
x: -BLOCK_HALFSIZE,
y: -BLOCK_HALFSIZE,
anchorX: 0,
anchorY: 0
});
self.blockContainer.attachAsset('blockT2', {
x: BLOCK_HALFSIZE,
y: -BLOCK_HALFSIZE,
anchorX: 1,
anchorY: 0
});
self.blockContainer.attachAsset('blockT3', {
y: BLOCK_HALFSIZE,
anchorX: 0.5,
anchorY: 1
});
self.updatePaths = function () {
self.downPath = self.orientation !== 0;
self.leftPath = self.orientation !== 1;
self.upPath = self.orientation !== 2;
self.rightPath = self.orientation !== 3;
};
self.updatePaths();
return self;
});
var BlockLine = Block.expand(function (config) {
var self = Block.call(this, config);
self.blockContainer.attachAsset('blockLine1', {
x: -BLOCK_HALFSIZE,
anchorX: 0,
anchorY: 0.5,
height: BLOCK_SIZE
});
self.blockContainer.attachAsset('blockLine2', {
x: BLOCK_HALFSIZE,
anchorX: 1,
anchorY: 0.5,
height: BLOCK_SIZE
});
self.updatePaths = function () {
var vertical = !(self.orientation % 2);
self.upPath = vertical;
self.downPath = vertical;
self.leftPath = !vertical;
self.rightPath = !vertical;
};
self.updatePaths();
return self;
});
var BlockL = Block.expand(function (config) {
var self = Block.call(this, config);
self.blockContainer.attachAsset('blockL1', {
anchorX: 0.5,
anchorY: 0.5,
height: BLOCK_SIZE
});
self.blockContainer.attachAsset('blockL2', {
x: -BLOCK_HALFSIZE,
y: BLOCK_HALFSIZE,
anchorX: 0,
anchorY: 1
});
self.updatePaths = function () {
self.leftPath = self.orientation === 0 || self.orientation === 1;
self.upPath = self.orientation === 1 || self.orientation === 2;
self.rightPath = self.orientation === 2 || self.orientation === 3;
self.downPath = self.orientation === 3 || self.orientation === 0;
};
self.updatePaths();
return self;
});
var BlockBlank = Block.expand(function (config) {
var self = Block.call(this, config);
var blockBlankAssets = ['blockBlank1', 'blockBlank2', 'blockBlank3'];
var randomAsset = blockBlankAssets[Math.floor(Math.random() * blockBlankAssets.length)];
self.blockContainer.attachAsset(randomAsset, {
anchorX: 0.5,
anchorY: 0.5,
width: BLOCK_SIZE,
height: BLOCK_SIZE
});
self.down = function () {};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var LAVA_LINE = game.height - 200;
var LAVA_SLICE_COUNT = 18;
var LAVA_SLICE_WIDTH = 128;
var LAVA_BOB_HEIGHT = 10;
var LAVA_BOB_OFFSET = Math.PI / 5;
var LAVA_BOB_PERIOD = Math.PI / 60;
var BLOCK_SCALE = 2.5;
var BLOCK_SIZE = 100;
var BLOCK_HALFSIZE = BLOCK_SIZE * 0.5;
var BLOCK_ROTATE_SPEED = 100;
var LIGHT_GROW_SPEED = 500;
var ROW_SPAN = 7;
var blockManager = game.addChild(new BlockManager());
var lava = game.addChild(new Lava({
x: game.width / 2,
y: LAVA_LINE
}));
function shuffle(array) {
var currentIndex = array.length;
while (currentIndex != 0) {
var randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
var _ref = [array[randomIndex], array[currentIndex]];
array[currentIndex] = _ref[0];
array[randomIndex] = _ref[1];
}
}
function generateBlockClasses(index) {
switch (index) {
case 0:
return [BlockBlank, BlockBlank, BlockBlank, BlockX, BlockBlank, BlockBlank, BlockBlank];
case 1:
return [BlockBlank, randomizeBlockClass(index), randomizeBlockClass(index), BlockX, randomizeBlockClass(index), randomizeBlockClass(index), BlockBlank];
default:
return shuffle([randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index), randomizeBlockClass(index)]);
}
}
function randomizeBlockClass(index) {
var classes = [BlockBlank, BlockT, BlockX, BlockLine, BlockL];
}
background
Music
light
Sound effect
rotate
Sound effect
error
Sound effect
crack
Sound effect
break
Sound effect
flow
Sound effect
bubble1
Sound effect
bubble2
Sound effect
bubble3
Sound effect
bubble4
Sound effect
bubble5
Sound effect
gong
Sound effect