/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3.5 + Math.random() * 1.5;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.15;
for (var i = 0; i < 6; i++) {
var spike = LK.getAsset('bombSpike', {
anchorX: 0.5,
anchorY: 0
});
spike.rotation = Math.PI * 2 / 6 * i;
spike.x = Math.cos(spike.rotation) * 40;
spike.y = Math.sin(spike.rotation) * 40;
bombGraphics.addChild(spike);
}
self.update = function () {
self.y += self.speed;
self.rotation += self.rotationSpeed;
};
self.hit = function () {
LK.getSound('bombHit').play();
tween(self, {
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4 + Math.random() * 2;
self.isSliced = false;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.update = function () {
if (!self.isSliced) {
self.y += self.speed;
self.rotation += self.rotationSpeed;
}
};
self.slice = function () {
if (!self.isSliced) {
self.isSliced = true;
LK.getSound('fruitSlice').play();
tween(self, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
return true;
}
return false;
};
return self;
});
var SlicePath = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('sliceLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 100;
self.update = function () {
self.lifetime--;
self.alpha = self.lifetime / 100;
if (self.lifetime <= 0) {
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
var fruits = [];
var bombs = [];
var slicePaths = [];
var score = 0;
var combo = 0;
var comboMultiplier = 1;
var gameActive = true;
var spawnRate = 60;
var spawnCounter = 0;
var difficulty = 1;
var lastMouseX = 0;
var lastMouseY = 0;
var isDrawingLine = false;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: '#FFFFFF'
});
scoreTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreTxt);
var comboTxt = new Text2('Combo: 0x', {
size: 80,
fill: '#FFD700'
});
comboTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(comboTxt);
function spawnFruit() {
var newFruit = new Fruit();
newFruit.x = Math.random() * 1900 + 74;
newFruit.y = -100;
newFruit.speed = newFruit.speed * (1 + difficulty * 0.1);
fruits.push(newFruit);
game.addChild(newFruit);
}
function spawnBomb() {
var newBomb = new Bomb();
newBomb.x = Math.random() * 1900 + 74;
newBomb.y = -110;
newBomb.speed = newBomb.speed * (1 + difficulty * 0.1);
bombs.push(newBomb);
game.addChild(newBomb);
}
function createSlicePath(x, y, rotation) {
var slicePath = new SlicePath();
slicePath.x = x;
slicePath.y = y;
slicePath.rotation = rotation;
slicePaths.push(slicePath);
game.addChild(slicePath);
}
function updateScore(points) {
combo++;
comboMultiplier = Math.min(1 + combo * 0.1, 3);
var totalPoints = Math.floor(points * comboMultiplier);
score += totalPoints;
scoreTxt.setText('Score: ' + score);
comboTxt.setText('Combo: ' + combo + 'x');
if (combo % 5 === 0) {
LK.getSound('combo').play();
}
difficulty = 1 + score / 1000;
if (spawnRate > 20) {
spawnRate = 60 - Math.floor(difficulty * 5);
}
}
function resetCombo() {
combo = 0;
comboMultiplier = 1;
comboTxt.setText('Combo: 0x');
}
function getDistanceToPoint(x1, y1, x2, y2) {
var dx = x2 - x1;
var dy = y2 - y1;
return Math.sqrt(dx * dx + dy * dy);
}
function checkLineIntersection(x1, y1, x2, y2, circleX, circleY, radius) {
var dx = x2 - x1;
var dy = y2 - y1;
var px = circleX - x1;
var py = circleY - y1;
var dLengthSq = dx * dx + dy * dy;
if (dLengthSq === 0) {
return getDistanceToPoint(x1, y1, circleX, circleY) <= radius;
}
var t = Math.max(0, Math.min(1, (px * dx + py * dy) / dLengthSq));
var closestX = x1 + t * dx;
var closestY = y1 + t * dy;
var distance = getDistanceToPoint(closestX, closestY, circleX, circleY);
return distance <= radius;
}
game.move = function (x, y, obj) {
if (!gameActive) {
return;
}
if (isDrawingLine && (lastMouseX !== x || lastMouseY !== y)) {
var distance = getDistanceToPoint(lastMouseX, lastMouseY, x, y);
if (distance > 30) {
var angle = Math.atan2(y - lastMouseY, x - lastMouseX);
createSlicePath((lastMouseX + x) / 2, (lastMouseY + y) / 2, angle);
for (var f = fruits.length - 1; f >= 0; f--) {
var fruit = fruits[f];
if (checkLineIntersection(lastMouseX, lastMouseY, x, y, fruit.x, fruit.y, 50)) {
if (fruit.slice()) {
updateScore(10);
fruits.splice(f, 1);
}
}
}
for (var b = bombs.length - 1; b >= 0; b--) {
var bomb = bombs[b];
if (checkLineIntersection(lastMouseX, lastMouseY, x, y, bomb.x, bomb.y, 55)) {
gameActive = false;
bomb.hit();
tween(game, {
alpha: 0.5
}, {
duration: 500,
onFinish: function onFinish() {
LK.showGameOver();
}
});
return;
}
}
lastMouseX = x;
lastMouseY = y;
}
}
};
game.down = function (x, y, obj) {
if (!gameActive) {
return;
}
isDrawingLine = true;
lastMouseX = x;
lastMouseY = y;
};
game.up = function (x, y, obj) {
isDrawingLine = false;
if (combo > 0) {
LK.setTimeout(function () {
resetCombo();
}, 800);
}
};
game.update = function () {
if (!gameActive) {
return;
}
spawnCounter++;
if (spawnCounter >= spawnRate) {
if (Math.random() < 0.15) {
spawnBomb();
} else {
spawnFruit();
}
spawnCounter = 0;
}
for (var f = fruits.length - 1; f >= 0; f--) {
var fruit = fruits[f];
fruit.update();
if (fruit.y > 2800) {
fruit.destroy();
fruits.splice(f, 1);
resetCombo();
}
}
for (var b = bombs.length - 1; b >= 0; b--) {
var bomb = bombs[b];
bomb.update();
if (bomb.y > 2850) {
bomb.destroy();
bombs.splice(b, 1);
resetCombo();
}
}
for (var s = slicePaths.length - 1; s >= 0; s--) {
var slicePath = slicePaths[s];
slicePath.update();
if (slicePath.lifetime <= 0) {
slicePaths.splice(s, 1);
}
}
};
LK.playMusic('backgroundMusic', {
loop: true
}); ===================================================================
--- original.js
+++ change.js
@@ -197,9 +197,11 @@
var distance = getDistanceToPoint(closestX, closestY, circleX, circleY);
return distance <= radius;
}
game.move = function (x, y, obj) {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
if (isDrawingLine && (lastMouseX !== x || lastMouseY !== y)) {
var distance = getDistanceToPoint(lastMouseX, lastMouseY, x, y);
if (distance > 30) {
var angle = Math.atan2(y - lastMouseY, x - lastMouseX);
@@ -234,9 +236,11 @@
}
}
};
game.down = function (x, y, obj) {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
isDrawingLine = true;
lastMouseX = x;
lastMouseY = y;
};
@@ -248,9 +252,11 @@
}, 800);
}
};
game.update = function () {
- if (!gameActive) return;
+ if (!gameActive) {
+ return;
+ }
spawnCounter++;
if (spawnCounter >= spawnRate) {
if (Math.random() < 0.15) {
spawnBomb();