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 * 1.02;
if (dx + dy < radii) {
return true;
} else {
return false;
}
};
var currentLevel = 0;
var Particle = Container.expand(function () {
var self = Container.call(this);
self.scale.set(3, 3);
var particleGraphics = self.createAsset('particle', 'Particle Graphics', 0.5, 0.5);
self.vx = (Math.random() - 0.5) * 30;
self.vy = (Math.random() - 0.5) * 30;
self.gravity = 0.2;
self.alpha = 0.75;
self.tick = function () {
self.x += self.vx;
self.y += self.vy;
self.vy += self.gravity;
self.scale.x = Math.max(0.1, self.scale.x - 0.025);
self.scale.y = Math.max(0.1, self.scale.y - 0.025);
if (self.y > 2732 + self.height || self.x < -self.width || self.x > 2048 + self.width) {
self.destroy();
}
};
});
var Background = Container.expand(function () {
var self = Container.call(this);
var bgGraphics = self.createAsset('backgroundImage', 'Background Image', 0, 0);
bgGraphics.width = 2048;
bgGraphics.height = 2732;
self.addChild(bgGraphics);
self.alpha = 1;
});
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.08;
self.scale.y += 0.08;
} 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.9;
self.rotation = Math.random() * (Math.PI * 2);
self.addChild(shapeGraphics);
self.isCollided = true;
self.scalingUp = true;
self.scalingDown = false;
self.scale.set(1, 1);
var scaleDown2 = function () {
console.log('StaticShape.scaleDown2 called');
self.scalingDown = true;
};
var update = function () {
if (self.scalingUp) {
if (self.scale.x < 4) {
self.scale.x += 0.08;
self.scale.y += 0.08;
} else {
self.scalingUp = false;
LK.setTimeout(scaleDown2, 4000);
}
} 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;
if (false) var underlayTypes = ['underlay1', 'underlay2', 'underlay3', 'underlay4', 'underlay5', 'underlay6', 'underlay7', 'underlay8', 'underlay9', 'underlay10'];
var underlayTypes = ['underlay4', 'underlay5', 'underlay6', 'underlay7', 'underlay8', 'underlay9', 'underlay10'];
if (currentLevel > 8) {
underlayTypes = ['underlay8', 'underlay9', 'underlay10'];
}
underlayTypes = [];
var shapeGraphicsUnderlay;
for (var i = 0; i < underlayTypes.length; i++) {
var underlayType = underlayTypes[i];
shapeGraphicsUnderlay = LK.getAsset(underlayType, 'Shape Underlay', 0.5, 0.5);
shapeGraphicsUnderlay.tint = 0xfffaa0;
shapeGraphicsUnderlay.y = 10;
shapeGraphicsUnderlay.alpha = 0.9 - i * 0.12;
shapeGraphicsUnderlay.scale.x = 1 + i * 0.05;
shapeGraphicsUnderlay.scale.y = 1 + i * 0.05;
self.addChild(shapeGraphicsUnderlay);
}
if (false) {
underlayTypes.forEach(function (underlayType) {
shapeGraphicsUnderlay = LK.getAsset(underlayType, 'Shape Underlay', 0.5, 0.5);
if (false) shapeGraphicsUnderlay.tint = hsvToRgb(1.6, 1, 1);
shapeGraphicsUnderlay.tint = 0xfffaa0;
shapeGraphicsUnderlay.y = 10;
if (underlayType == 'underlay1') {
shapeGraphicsUnderlay.alpha = 0.6;
shapeGraphicsUnderlay.scale.x = 1.1;
shapeGraphicsUnderlay.scale.y = 1.1;
} else if (underlayType == 'underlay2') {
shapeGraphicsUnderlay.alpha = 0.5;
shapeGraphicsUnderlay.scale.x = 1.2;
shapeGraphicsUnderlay.scale.y = 1.2;
} else if (underlayType == 'underlay3') {
shapeGraphicsUnderlay.alpha = 0.4;
shapeGraphicsUnderlay.scale.x = 1.3;
shapeGraphicsUnderlay.scale.y = 1.3;
} else if (underlayType == 'underlay4') {
shapeGraphicsUnderlay.alpha = 0.3;
shapeGraphicsUnderlay.scale.x = 1.4;
shapeGraphicsUnderlay.scale.y = 1.4;
} else if (underlayType == 'underlay5') {
shapeGraphicsUnderlay.alpha = 0.1;
shapeGraphicsUnderlay.scale.x = 1.8;
shapeGraphicsUnderlay.scale.y = 1.8;
}
self.addChild(shapeGraphicsUnderlay);
});
}
shapeGraphics = LK.getAsset('circle', 'Circle Shape', 0.5, 0.5);
self.updateColor = function () {
var h = self.colorIndex / 32;
var s = 1;
var v = 1;
self.color = hsvToRgb(h, s, v);
shapeGraphics.tint = self.color;
};
self.colorIndex = Math.floor(Math.random() * 32);
self.rotation = Math.random() * (Math.PI * 2);
self.updateColor();
shapeGraphics.alpha = 0.8;
self.scale.x = 1 - currentLevel * 0.017;
self.scale.y = 1 - currentLevel * 0.017;
self.addChild(shapeGraphics);
var angle = Math.random() * Math.PI * 2;
var speed = 7 + currentLevel * 0.5;
self.vx = Math.cos(angle) * speed;
self.vy = Math.sin(angle) * speed;
self.move = function () {
if (!self.isCollided) {
self.rotation += 0.02;
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.isCollided = true;
self.scalingU = true;
}
};
self.scalingUp = false;
self.scalingDown = false;
var scaleUp2 = function () {
self.scalingUp = true;
};
self.explode = function () {
self.isCollided = true;
LK.setTimeout(scaleUp2, 1);
var times = 24;
if (currentLevel > 8) {
times = 10;
}
for (var i = 0; i < times; i++) {
var particle = self.parent.addChild(new Particle());
particle.x = self.x;
particle.y = self.y;
}
};
var scaleDown2 = function () {
self.scalingDown = true;
};
self.update = function () {
if (self.scalingUp) {
if (self.scale.x < 4 - currentLevel * 0.2) {
self.scale.x += 0.2;
self.scale.y += 0.2;
} else {
self.scalingUp = false;
LK.setTimeout(scaleDown2, 4000);
}
} else if (self.scalingDown) {
if (self.scale.x > 0.2) {
self.scale.x -= 0.2;
self.scale.y -= 0.2;
} else {
if (self.parent) self.parent.expandedCount--;
self.destroy();
}
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.expandedCount = 1;
self.addChild(new Background());
LK.stageContainer.setBackgroundColor('0xCCCCFF');
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',
outline: true
});
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: "#dddddd",
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) {
collisionText.setText('Good Job!\nAll levels completed!\nYou win :)');
LK.showGameOver();
return;
}
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;
if (currentLevel < levels.length) {
levelText.setText('Level ' + (currentLevel + 1) + ' - Get ' + levels[currentLevel][0] + ' out of ' + levels[currentLevel][1] + ' shapes');
} else {
levelText.setText('All levels completed!');
}
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);
}
});
});
self.children.forEach(function (child) {
if (child instanceof Particle && child.tick) {
child.tick();
}
});
});
});
a white geometric square shape Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white flat circle 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.
A cozy living room with a christmas tree, presents, snacks, ornaments and everythning in place for christmas. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a shining star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A super shiny white metallic christmas glass ball decoration with a glowing outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.