Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: shape.update is not a function' in this line: 'shape.update();' Line Number: 240
User prompt
Fix Bug: 'TypeError: shape.update is not a function' in this line: 'shape.update();' Line Number: 259
User prompt
Fix Bug: 'TypeError: shape.update is not a function' in this line: 'shape.update();' Line Number: 278
User prompt
Fix Bug: 'TypeError: shape.update is not a function' in this line: 'shape.update();' Line Number: 278
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: staticShape is not defined' in this line: 'staticShape.x = pos.x - staticShape.width / 2;' Line Number: 216
User prompt
Fix Bug: 'TypeError: self.staticShape.update is not a function' in this line: 'if (self.staticShape) self.staticShape.update();' Line Number: 229
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'update')' in this line: 'staticShape.update();' Line Number: 229
User prompt
Fix Bug: 'ReferenceError: staticShape is not defined' in this line: 'staticShape.update();' Line Number: 228
User prompt
Fix Bug: 'ReferenceError: staticShape is not defined' in this line: 'staticShape.update();' Line Number: 228
Code edit (1 edits merged)
Please save this source code
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
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) * (o1.x - o2.x); var dy = (o1.y - o2.y) * (o1.y - o2.y); var 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); self.update = function () { if (self.scalingUp) { if (self.scale.x < 4) { self.scale.x += 0.04; self.scale.y += 0.04; } else { self.scalingUp = false; LK.setTimeout(scaleDown2, 5000); } } else if (self.scalingDown) { if (self.scale.x > 0.4) { self.scale.x -= 0.4; self.scale.y -= 0.4; } else { if (self.parent) self.parent.expandedCount--; self.destroy(); } } }; var shapeGraphics; shapeGraphics = LK.getAsset('circle', 'Circle Shape', 0.5, 0.5); shapeGraphics.alpha = 0.5; self.addChild(shapeGraphics); self.isCollided = true; self.scalingUp = false; self.scalingDown = false; 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 { if (self.parent) self.parent.expandedCount--; self.destroy(); } }; var scaleUp2 = function () { self.scalingUp = true; }; var scaleDown2 = function () { self.scalingDown = true; }; LK.setTimeout(scaleUp2, 1); var update = function () { if (self.scalingUp) { if (self.scale.x < 4) { self.scale.x += 0.04; self.scale.y += 0.04; } else { self.scalingUp = false; LK.setTimeout(scaleDown2, 5000); } } else if (self.scalingDown) { if (self.scale.x > 0.4) { self.scale.x -= 0.4; self.scale.y -= 0.4; } else { if (self.parent) self.parent.expandedCount--; self.destroy(); } } }; }); var Shape = Container.expand(function () { console.log('Shape created'); var self = Container.call(this); var shapeGraphics; shapeGraphics = LK.getAsset('circle', 'Circle Shape', 0.5, 0.5); self.updateColor = function () { var h = self.colorIndex / 32; var s = 0.8; var v = 0.8; self.color = hsvToRgb(h, s, v); shapeGraphics.tint = self.color; }; self.colorIndex = Math.floor(Math.random() * 32); self.updateColor(); shapeGraphics.alpha = 0.5; 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 - self.width / 2 < 0 || self.x > 2048 - self.width / 2) { self.vx = -self.vx; } if (self.y - self.height / 2 < 0 || self.y > 2732 - self.height / 2) { self.vy = -self.vy; } } else { self.vx = 0; self.vy = 0; self.explode(); } }; self.scalingUp = false; self.scalingDown = false; 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 { if (self.parent) self.parent.expandedCount--; self.destroy(); } }; var scaleUp2 = function () { self.scalingUp = true; }; LK.setTimeout(scaleUp2, 1); }; var scaleDown2 = function () { self.scalingDown = true; }; self.update = function () { if (self.scalingUp) { if (self.scale.x < 4) { self.scale.x += 0.04; self.scale.y += 0.04; } else { self.scalingUp = false; LK.setTimeout(scaleDown2, 5000); } } else if (self.scalingDown) { if (self.scale.x > 0.4) { self.scale.x -= 0.4; self.scale.y -= 0.4; } else { if (self.parent) self.parent.expandedCount--; self.destroy(); } } }; }); var Game = Container.expand(function () { var self = Container.call(this); self.expandedCount = 1; LK.stageContainer.setBackgroundColor('0xCCCCFF'); var currentLevel = 0; var levels = [[1, 5], [3, 7], [6, 9], [8, 12], [10, 15], [15, 20], [18, 25], [25, 32], [30, 40], [35, 50], [50, 65], [75, 75]]; var shapes = []; var levelText = new Text2('Level 1 - Get 1 out of 5 shapes', { size: 80, fill: "#ffffff", align: 'center' }); levelText.anchor.set(0.5, 0); levelText.x = 0; levelText.y = 50; LK.gui.topCenter.addChild(levelText); var collisionsCount = 0; var collisionText = new Text2('Shapes: ' + collisionsCount, { size: 80, fill: "#777777", align: 'center' }); collisionText.anchor.set(0.5, 0); collisionText.x = 0; collisionText.y = 150; LK.gui.topCenter.addChild(collisionText); for (var i = 0; i < 5; i++) { var shape = self.addChild(new Shape()); shape.x = shape.width + Math.random() * (2048 - 2 * shape.width); shape.y = shape.height + Math.random() * (2732 - 2 * shape.height); shapes.push(shape); } var isClicked = false; self.staticShape = null; stage.on('down', function (obj) { if (!isClicked) { isClicked = true; var event = obj.event; var pos = event.getLocalPosition(self); self.staticShape = self.addChild(new StaticShape()); self.staticShape.x = pos.x - self.staticShape.width / 2; self.staticShape.y = pos.y - self.staticShape.height / 2; } }); LK.on('tick', function () { if (self.expandedCount == 0) { if (collisionsCount >= levels[currentLevel][0]) { collisionText.setText('Level Completed - now try this'); currentLevel++; } else { collisionText.setText('Try again'); } shapes.forEach(function (child) { child.destroy(); }); shapes = []; if (currentLevel == levels.length) { currentLevel = 0; collisionText.setText('All levels cleared!\nGood job!\nRestarted Level 1'); } for (var i = 0; i < (levels[currentLevel] ? levels[currentLevel][1] : 0); i++) { var shape = self.addChild(new Shape()); shape.x = shape.width + Math.random() * (2048 - 2 * shape.width); shape.y = shape.height + Math.random() * (2732 - 2 * shape.height); shapes.push(shape); } isClicked = false; collisionsCount = 0; self.expandedCount = 1; levelText.setText('Level ' + (currentLevel + 1) + ' - Get ' + levels[currentLevel][0] + ' out of ' + levels[currentLevel][1] + ' shapes'); return; } if (self.staticShape && self.staticShape.update) self.staticShape.update(); shapes.forEach(function (shape) { shape.move(); if (shape.update) shape.update(); self.children.forEach(function (child) { if (shape !== child && !shape.isCollided && child.isCollided && circlesCollide(shape, child)) { shape.explode(); collisionsCount++; self.expandedCount++; collisionText.setText('Shapes: ' + collisionsCount); } }); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -92,8 +92,27 @@
var scaleDown2 = function () {
self.scalingDown = true;
};
LK.setTimeout(scaleUp2, 1);
+ var update = function () {
+ if (self.scalingUp) {
+ if (self.scale.x < 4) {
+ self.scale.x += 0.04;
+ self.scale.y += 0.04;
+ } else {
+ self.scalingUp = false;
+ LK.setTimeout(scaleDown2, 5000);
+ }
+ } else if (self.scalingDown) {
+ if (self.scale.x > 0.4) {
+ self.scale.x -= 0.4;
+ self.scale.y -= 0.4;
+ } else {
+ if (self.parent) self.parent.expandedCount--;
+ self.destroy();
+ }
+ }
+ };
});
var Shape = Container.expand(function () {
console.log('Shape created');
var self = Container.call(this);
@@ -160,8 +179,27 @@
};
var scaleDown2 = function () {
self.scalingDown = true;
};
+ self.update = function () {
+ if (self.scalingUp) {
+ if (self.scale.x < 4) {
+ self.scale.x += 0.04;
+ self.scale.y += 0.04;
+ } else {
+ self.scalingUp = false;
+ LK.setTimeout(scaleDown2, 5000);
+ }
+ } else if (self.scalingDown) {
+ if (self.scale.x > 0.4) {
+ self.scale.x -= 0.4;
+ self.scale.y -= 0.4;
+ } else {
+ if (self.parent) self.parent.expandedCount--;
+ self.destroy();
+ }
+ }
+ };
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.expandedCount = 1;
@@ -233,11 +271,12 @@
self.expandedCount = 1;
levelText.setText('Level ' + (currentLevel + 1) + ' - Get ' + levels[currentLevel][0] + ' out of ' + levels[currentLevel][1] + ' shapes');
return;
}
- if (self.staticShape && typeof self.staticShape.update === 'function') self.staticShape.update();
+ if (self.staticShape && self.staticShape.update) self.staticShape.update();
shapes.forEach(function (shape) {
shape.move();
+ if (shape.update) shape.update();
self.children.forEach(function (child) {
if (shape !== child && !shape.isCollided && child.isCollided && circlesCollide(shape, child)) {
shape.explode();
collisionsCount++;
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.