/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Counter = Container.expand(function () {
var self = Container.call(this);
var counterGraphics = self.attachAsset('counter', {
anchorX: 0.5,
anchorY: 0.5
});
var glowGraphics = self.attachAsset('counterGlow', {
anchorX: 0.5,
anchorY: 0.5
});
glowGraphics.alpha = 0.3;
self.level = 1;
self.pointsCollected = 0;
self.pointsNeeded = 5;
self.addPoints = function (amount) {
self.pointsCollected += amount;
var scaleIncrease = 1 + self.pointsCollected / (self.pointsNeeded * 2);
tween(counterGraphics, {
scaleX: scaleIncrease,
scaleY: scaleIncrease
}, {
duration: 200,
easing: tween.easeOut
});
tween(glowGraphics, {
scaleX: scaleIncrease * 1.2,
scaleY: scaleIncrease * 1.2
}, {
duration: 200,
easing: tween.easeOut
});
if (self.pointsCollected >= self.pointsNeeded) {
self.levelUp();
}
};
self.levelUp = function () {
self.level++;
self.pointsCollected = 0;
self.pointsNeeded = 4 + self.level * 2;
var newColor = self.getColorForLevel(self.level);
counterGraphics.tint = newColor;
tween(counterGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(counterGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
}
});
LK.getSound('levelUp').play();
};
self.getColorForLevel = function (lvl) {
var colors = [0xff6b35, 0xff9f1c, 0xffbf69, 0x2a9d8f, 0x264653, 0xe76f51, 0xf4a261, 0xe9c46a];
return colors[(lvl - 1) % colors.length];
};
return self;
});
var Point = Container.expand(function () {
var self = Container.call(this);
var pointGraphics = self.attachAsset('point', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 3;
self.velocityX = 0;
self.collected = false;
self.update = function () {
self.y += self.velocityY;
self.x += self.velocityX;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var penguinBackground = game.addChildAt(LK.getAsset('penguin', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
scaleX: 1,
scaleY: 1,
width: 2048,
height: 2732
}), 0);
var counter = game.addChild(new Counter());
counter.x = 1024;
counter.y = 1366;
var points = [];
var score = 0;
var gameActive = true;
var spawnRate = 40;
var spawnTimer = 0;
var pointSpeed = 3;
var maxPoints = 8;
var titleTxt = new Text2('MACRO', {
size: 120,
fill: 0xFFFFFF
}); //{S_title}
titleTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(titleTxt);
var scoreTxt = new Text2('Level: 1 | Points: 0/5', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 140;
LK.gui.top.addChild(scoreTxt);
function updateScoreDisplay() {
scoreTxt.setText('Level: ' + counter.level + ' | Points: ' + counter.pointsCollected + '/' + counter.pointsNeeded);
}
function spawnPoint() {
if (points.length >= maxPoints) return;
var newPoint = game.addChild(new Point());
newPoint.x = Math.random() * 1800 + 124;
newPoint.y = -100;
newPoint.velocityX = (Math.random() - 0.5) * 2;
newPoint.velocityY = pointSpeed;
newPoint.lastY = newPoint.y;
newPoint.lastIntersecting = false;
points.push(newPoint);
}
var draggedPoint = null;
game.move = function (x, y, obj) {
if (draggedPoint && gameActive) {
draggedPoint.x = x;
draggedPoint.y = y;
}
};
game.down = function (x, y, obj) {
for (var i = 0; i < points.length; i++) {
if (points[i].intersects && points[i].intersects(points[i])) {
if (x >= points[i].x - 50 && x <= points[i].x + 50 && y >= points[i].y - 50 && y <= points[i].y + 50) {
draggedPoint = points[i];
break;
}
}
}
};
game.up = function (x, y, obj) {
draggedPoint = null;
};
game.update = function () {
if (!gameActive) return;
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnPoint();
spawnTimer = 0;
}
for (var i = points.length - 1; i >= 0; i--) {
var point = points[i];
if (point.lastY === undefined) point.lastY = point.y;
if (point.lastIntersecting === undefined) point.lastIntersecting = false;
if (point.lastY >= -100 && point.y < -100) {
point.destroy();
points.splice(i, 1);
continue;
}
var currentIntersecting = point.intersects(counter);
if (!point.lastIntersecting && currentIntersecting) {
counter.addPoints(1);
score++;
updateScoreDisplay();
point.destroy();
points.splice(i, 1);
LK.getSound('collect').play();
continue;
}
point.lastY = point.y;
point.lastIntersecting = currentIntersecting;
}
if (counter.level >= 10) {
gameActive = false;
LK.showYouWin();
}
};
LK.playMusic('bgmusic', {
loop: true
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Counter = Container.expand(function () {
var self = Container.call(this);
var counterGraphics = self.attachAsset('counter', {
anchorX: 0.5,
anchorY: 0.5
});
var glowGraphics = self.attachAsset('counterGlow', {
anchorX: 0.5,
anchorY: 0.5
});
glowGraphics.alpha = 0.3;
self.level = 1;
self.pointsCollected = 0;
self.pointsNeeded = 5;
self.addPoints = function (amount) {
self.pointsCollected += amount;
var scaleIncrease = 1 + self.pointsCollected / (self.pointsNeeded * 2);
tween(counterGraphics, {
scaleX: scaleIncrease,
scaleY: scaleIncrease
}, {
duration: 200,
easing: tween.easeOut
});
tween(glowGraphics, {
scaleX: scaleIncrease * 1.2,
scaleY: scaleIncrease * 1.2
}, {
duration: 200,
easing: tween.easeOut
});
if (self.pointsCollected >= self.pointsNeeded) {
self.levelUp();
}
};
self.levelUp = function () {
self.level++;
self.pointsCollected = 0;
self.pointsNeeded = 4 + self.level * 2;
var newColor = self.getColorForLevel(self.level);
counterGraphics.tint = newColor;
tween(counterGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(counterGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
}
});
LK.getSound('levelUp').play();
};
self.getColorForLevel = function (lvl) {
var colors = [0xff6b35, 0xff9f1c, 0xffbf69, 0x2a9d8f, 0x264653, 0xe76f51, 0xf4a261, 0xe9c46a];
return colors[(lvl - 1) % colors.length];
};
return self;
});
var Point = Container.expand(function () {
var self = Container.call(this);
var pointGraphics = self.attachAsset('point', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 3;
self.velocityX = 0;
self.collected = false;
self.update = function () {
self.y += self.velocityY;
self.x += self.velocityX;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var penguinBackground = game.addChildAt(LK.getAsset('penguin', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
scaleX: 1,
scaleY: 1,
width: 2048,
height: 2732
}), 0);
var counter = game.addChild(new Counter());
counter.x = 1024;
counter.y = 1366;
var points = [];
var score = 0;
var gameActive = true;
var spawnRate = 40;
var spawnTimer = 0;
var pointSpeed = 3;
var maxPoints = 8;
var titleTxt = new Text2('MACRO', {
size: 120,
fill: 0xFFFFFF
}); //{S_title}
titleTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(titleTxt);
var scoreTxt = new Text2('Level: 1 | Points: 0/5', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 140;
LK.gui.top.addChild(scoreTxt);
function updateScoreDisplay() {
scoreTxt.setText('Level: ' + counter.level + ' | Points: ' + counter.pointsCollected + '/' + counter.pointsNeeded);
}
function spawnPoint() {
if (points.length >= maxPoints) return;
var newPoint = game.addChild(new Point());
newPoint.x = Math.random() * 1800 + 124;
newPoint.y = -100;
newPoint.velocityX = (Math.random() - 0.5) * 2;
newPoint.velocityY = pointSpeed;
newPoint.lastY = newPoint.y;
newPoint.lastIntersecting = false;
points.push(newPoint);
}
var draggedPoint = null;
game.move = function (x, y, obj) {
if (draggedPoint && gameActive) {
draggedPoint.x = x;
draggedPoint.y = y;
}
};
game.down = function (x, y, obj) {
for (var i = 0; i < points.length; i++) {
if (points[i].intersects && points[i].intersects(points[i])) {
if (x >= points[i].x - 50 && x <= points[i].x + 50 && y >= points[i].y - 50 && y <= points[i].y + 50) {
draggedPoint = points[i];
break;
}
}
}
};
game.up = function (x, y, obj) {
draggedPoint = null;
};
game.update = function () {
if (!gameActive) return;
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnPoint();
spawnTimer = 0;
}
for (var i = points.length - 1; i >= 0; i--) {
var point = points[i];
if (point.lastY === undefined) point.lastY = point.y;
if (point.lastIntersecting === undefined) point.lastIntersecting = false;
if (point.lastY >= -100 && point.y < -100) {
point.destroy();
points.splice(i, 1);
continue;
}
var currentIntersecting = point.intersects(counter);
if (!point.lastIntersecting && currentIntersecting) {
counter.addPoints(1);
score++;
updateScoreDisplay();
point.destroy();
points.splice(i, 1);
LK.getSound('collect').play();
continue;
}
point.lastY = point.y;
point.lastIntersecting = currentIntersecting;
}
if (counter.level >= 10) {
gameActive = false;
LK.showYouWin();
}
};
LK.playMusic('bgmusic', {
loop: true
});