Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading '0')' in this line: 'levelText.setText('Level ' + (currentLevel + 1) + ' - Explode ' + levels[currentLevel][0] + ' of ' + levels[currentLevel][1] + ' shapes');' Line Number: 207
Code edit (7 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading '1')' in this line: 'for (var i = 0; i < levels[currentLevel][1]; i++) {' Line Number: 198
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'undefined')' in this line: 'levelText.setText('Level 1 - Explode ' + self.levels[self.currentLevel][0] + ' of ' + self.levels[self.currentLevel][0] + ' shapes');' Line Number: 204
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'undefined')' in this line: 'if (collisionsCount > self.levels[self.currentLevel][0]) {' Line Number: 188
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'expandedCount')' in this line: 'self.parent.expandedCount--;' Line Number: 136
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'expandedCount')' in this line: 'self.parent.expandedCount--;' Line Number: 136
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: expandedCount is not defined' in this line: 'expandedCount++;' Line Number: 205
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: expandedCount is not defined' in this line: 'expandedCount++;' Line Number: 205
User prompt
Fix Bug: 'ReferenceError: collisionsText is not defined' in this line: 'collisionsText.setText('Wow');' Line Number: 197
User prompt
Fix Bug: 'ReferenceError: collisionsText is not defined' in this line: 'collisionsText.setText('Wow');' Line Number: 187
User prompt
Fix Bug: 'ReferenceError: expandedCount is not defined' in this line: 'if (expandedCount == 0) {' Line Number: 185
User prompt
define a global var expandedTestCount
Code edit (8 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: expandedCount is not defined' in this line: 'expandedCount--;' Line Number: 72
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught TypeError: Shape.hsvToRgb is not a function' in this line: 'var bgColor = Shape.hsvToRgb(1, 1, 1);' Line Number: 156
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
var hsvToRgb = function (h, s, v) { var r, g, b; var i = Math.floor(h * 6); var f = h * 6 - i; var p = v * (1 - s); var q = v * (1 - f * s); var t = v * (1 - (1 - f) * s); switch (i % 6) { case 0: (r = v, g = t, b = p); break; case 1: (r = q, g = v, b = p); break; case 2: (r = p, g = v, b = t); break; case 3: (r = p, g = q, b = v); break; case 4: (r = t, g = p, b = v); break; case 5: (r = v, g = p, b = q); break; } return (r * 255 << 16) + (g * 255 << 8) + b * 255; }; var circlesCollide = function (o1, o2) { var dx = o1.x - o2.x; dx *= dx; var dy = o1.y - o2.y; dy *= dy; radii = (o1.width + o2.width) / 2; radii *= radii; if (dx + dy < radii) { return true; } else { return false; } }; var StaticShape = Container.expand(function () { var self = Container.call(this); var shapeType = 'circle'; var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'); var shapeGraphics; switch (shapeType) { case 'circle': shapeGraphics = LK.getAsset('circle', 'Circle Shape', 0.5, 0.5); break; case 'triangle': shapeGraphics = LK.getAsset('triangle', 'Triangle Shape', 0.5, 0.5); break; case 'square': shapeGraphics = LK.getAsset('square', 'Square Shape', 0.5, 0.5); break; } self.addChild(shapeGraphics); self.isCollided = true; self.scale.set(1, 1); var scaleUp = function () { if (self.scale.x < 4) { self.scale.x += 0.04; self.scale.y += 0.04; LK.setTimeout(scaleUp, 2); } else { LK.setTimeout(scaleDown, 5000); } }; var scaleDown = function () { if (self.scale.x > 0) { self.scale.x -= 0.4; self.scale.y -= 0.4; LK.setTimeout(scaleDown, 2); } else { self.destroy(); } }; LK.setTimeout(scaleUp, 33); }); var Shape = Container.expand(function () { var self = Container.call(this); var shapeType = 'circle'; var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'); var shapeGraphics; switch (shapeType) { case 'circle': shapeGraphics = LK.getAsset('circle', 'Circle Shape', 0.5, 0.5); break; case 'triangle': shapeGraphics = LK.getAsset('triangle', 'Triangle Shape', 0.5, 0.5); break; case 'square': shapeGraphics = LK.getAsset('square', 'Square Shape', 0.5, 0.5); break; } self.updateColor = function () { var h = self.colorIndex / 32; var s = 0.8; var v = 0.8; self.color = self.hsvToRgb(h, s, v); shapeGraphics.tint = self.color; self.colorIndex = (self.colorIndex + 1) % 32; }; self.colorIndex = Math.floor(Math.random() * 32); self.updateColor(); shapeGraphics.alpha = 0.2; self.addChild(shapeGraphics); var angle = Math.random() * Math.PI * 2; var speed = 5; self.vx = Math.cos(angle) * speed; self.vy = Math.sin(angle) * speed; self.move = function () { if (!self.isCollided) { self.x += self.vx; self.y += self.vy; if (self.x < 0 || self.x > 2048 - self.width) { self.vx = -self.vx; } if (self.y < 0 || self.y > 2732 - self.height) { self.vy = -self.vy; } } else { self.vx = 0; self.vy = 0; self.explode(); } }; self.explode = function () { self.isCollided = true; var scaleUp = function () { if (self.scale.x < 4) { self.scale.x += 0.04; self.scale.y += 0.04; LK.setTimeout(scaleUp, 2); } else { LK.setTimeout(scaleDown, 5000); } }; var scaleDown = function () { if (self.scale.x > 0) { self.scale.x -= 0.4; self.scale.y -= 0.4; LK.setTimeout(scaleDown, 2); } else { self.destroy(); } }; LK.setTimeout(scaleUp, 33); }; self.chain = function () {}; }); var Game = Container.expand(function () { var self = Container.call(this); var bgColor = hsvToRgb(1, 1, 1); LK.stageContainer.setBackgroundColor(bgColor); var shapes = []; var levelText = new Text2('Level 1 - Explode 1 of 5 shapes', { size: 80, fill: "#ffffff", align: 'center' }); levelText.anchor.set(0.5, 0); levelText.x = 0; levelText.y = 150; var collisionsCount = 0; var collisionText = new Text2('Exploded: ' + collisionsCount, { size: 80, fill: "#ffffff", align: 'center' }); collisionText.anchor.set(0.5, 0); collisionText.x = 0; collisionText.y = 250; LK.gui.topCenter.addChild(levelText); LK.gui.topCenter.addChild(collisionText); for (var i = 0; i < 15; i++) { var shape = self.addChild(new Shape()); shape.x = Math.random() * (1024 - shape.width); shape.y = Math.random() * (1366 - shape.height); shapes.push(shape); } var isClicked = false; stage.on('down', function (obj) { if (!isClicked) { isClicked = true; var event = obj.event; var pos = event.getLocalPosition(self); var staticShape = self.addChild(new StaticShape()); staticShape.x = pos.x - staticShape.width / 2; staticShape.y = pos.y - staticShape.height / 2; } }); LK.on('tick', function () { shapes.forEach(function (shape) { shape.move(); self.children.forEach(function (child) { if (shape !== child && !shape.isCollided && child.isCollided && circlesCollide(shape, child)) { shape.explode(); collisionsCount++; collisionText.setText('Exploded: ' + collisionsCount); } }); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,33 @@
+var hsvToRgb = function (h, s, v) {
+ var r, g, b;
+ var i = Math.floor(h * 6);
+ var f = h * 6 - i;
+ var p = v * (1 - s);
+ var q = v * (1 - f * s);
+ var t = v * (1 - (1 - f) * s);
+ switch (i % 6) {
+ case 0:
+ (r = v, g = t, b = p);
+ break;
+ case 1:
+ (r = q, g = v, b = p);
+ break;
+ case 2:
+ (r = p, g = v, b = t);
+ break;
+ case 3:
+ (r = p, g = q, b = v);
+ break;
+ case 4:
+ (r = t, g = p, b = v);
+ break;
+ case 5:
+ (r = v, g = p, b = q);
+ break;
+ }
+ return (r * 255 << 16) + (g * 255 << 8) + b * 255;
+};
var circlesCollide = function (o1, o2) {
var dx = o1.x - o2.x;
dx *= dx;
var dy = o1.y - o2.y;
@@ -65,37 +94,8 @@
case 'square':
shapeGraphics = LK.getAsset('square', 'Square Shape', 0.5, 0.5);
break;
}
- self.hsvToRgb = function (h, s, v) {
- var r, g, b;
- var i = Math.floor(h * 6);
- var f = h * 6 - i;
- var p = v * (1 - s);
- var q = v * (1 - f * s);
- var t = v * (1 - (1 - f) * s);
- switch (i % 6) {
- case 0:
- (r = v, g = t, b = p);
- break;
- case 1:
- (r = q, g = v, b = p);
- break;
- case 2:
- (r = p, g = v, b = t);
- break;
- case 3:
- (r = p, g = q, b = v);
- break;
- case 4:
- (r = t, g = p, b = v);
- break;
- case 5:
- (r = v, g = p, b = q);
- break;
- }
- return (r * 255 << 16) + (g * 255 << 8) + b * 255;
- };
self.updateColor = function () {
var h = self.colorIndex / 32;
var s = 0.8;
var v = 0.8;
@@ -104,8 +104,9 @@
self.colorIndex = (self.colorIndex + 1) % 32;
};
self.colorIndex = Math.floor(Math.random() * 32);
self.updateColor();
+ shapeGraphics.alpha = 0.2;
self.addChild(shapeGraphics);
var angle = Math.random() * Math.PI * 2;
var speed = 5;
self.vx = Math.cos(angle) * speed;
@@ -151,8 +152,10 @@
self.chain = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
+ var bgColor = hsvToRgb(1, 1, 1);
+ LK.stageContainer.setBackgroundColor(bgColor);
var shapes = [];
var levelText = new Text2('Level 1 - Explode 1 of 5 shapes', {
size: 80,
fill: "#ffffff",
a white geometric square shape Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white dot Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
flat white round disk Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
gif circle spinning animation Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.