User prompt
seslerde son yazan sesi bitiş müziği olarak kullan
User prompt
top used 50 ye ulaştığından oyunu bitir
User prompt
oyun bitiş ekranı olsun ve müziği olsun the end yazsın yeşil bir çerçeve de
User prompt
ekran tamamen bitince oyunu bitir.
User prompt
Make combos like the others on the purple ball.
User prompt
combolar da extra çok top üret
User prompt
mor,kırmızı,sarı renkli toplar yendiğinde en az 5 tane top alana giriş yapsın dört bir yana dağılsın ve çok yavaş hereket etsin
User prompt
oyunda bulunan hataları gözden geçir ve düzelt
User prompt
combo her top rengi değiştiğinde değişşin aynı renk olduğu zaman sadece combo saysın
User prompt
toplar kademeli olarak hızlansın ve her alanın dışına çıkan top için yeni 2 tane top alana girsin
User prompt
combo ile iligli olan yazılar ekranda biraz daha uzun kalsın
User prompt
oyunun dinamiklerini geliştir. daha detaylı efektler ve combolar ekle
User prompt
topu atacağı yönü minik bir okla göstersin
User prompt
toplar daha yoğun olsun
User prompt
oyun başlarkenki topların dağılımı karışık olsun tek bir yerden olmasın
User prompt
özel alan buda çok koyu normal tonların da olsun
User prompt
özel alanı daha koyu ve belirgin yapalım
User prompt
biraz daha üst boşluğa hatta kendine ait bir alan küçük ayrıksı gözüksün diye ortamda
User prompt
Bukalemunun üstünde duran ve az sonra fırlatılacak topu gösteren top → şu an karakterin suratında duruyor, kötü görünüyor. ben bu topun konumunu değiştirmek istiyorum
User prompt
ortadaki şuan hangi topun atılacağını gösteren yeri bukalemunun altına özel bir çerçeve yaparak koy
User prompt
ortada hangi topun atılacağını gösteren kutucuğu ortadaki tapınak merkezi olan konumun alt tarafına ekleyelim
User prompt
sol üstte yazan clain yazını kaldıralım onun yerine sağ üste kaç tane top harcadığını gösteren bir gösterge koyalım
User prompt
Dekoratif bir kutunun içinde, bukalemunun üstünden atılacak top için görsel bir gösterge ekleyin
User prompt
hazırda olan ve atacağı topu alt kısma bir kutucuk açıp oraya yerleştirelim
User prompt
hazırda olan yani atacağı top tapınak merkezinin ucunda durabilir mi
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function (color) {
var self = Container.call(this);
self.ballColor = color || 'red';
self.ballGraphics = self.attachAsset('ball_' + self.ballColor, {
anchorX: 0.5,
anchorY: 0.5
});
self.chainIndex = 0;
self.pathPosition = 0;
self.isExploding = false;
self.isBigComboBall = false; // Default: not a big combo ball
self.lastPathPosition = 0;
self.isOffScreen = false;
self.lastX = 0;
self.lastY = 0;
self.checkOffScreen = function () {
// Check if ball has moved completely off screen
var margin = 100; // Extra margin to ensure ball is truly gone
var wasOnScreen = self.lastX >= -margin && self.lastX <= 2048 + margin && self.lastY >= -margin && self.lastY <= 2732 + margin;
var isNowOffScreen = self.x < -margin || self.x > 2048 + margin || self.y < -margin || self.y > 2732 + margin;
// Detect transition from on-screen to off-screen
if (wasOnScreen && isNowOffScreen && !self.isOffScreen) {
self.isOffScreen = true;
}
// Update last known positions
self.lastX = self.x;
self.lastY = self.y;
};
self.explode = function () {
if (self.isExploding) return;
self.isExploding = true;
tween(self.ballGraphics, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
LK.getSound('explosion').play();
};
self.destroyOnHit = function () {
// 2x big combo balls: require 3 hits, persist longer
if (self.isBigComboBall) {
if (!self.bigHitCount) self.bigHitCount = 0;
self.bigHitCount++;
// Flash effect to show hit
tween(self.ballGraphics, {
tint: 0xFFD700,
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.ballGraphics, {
tint: 0xFFFFFF,
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Only destroy after 3 hits
if (self.bigHitCount >= 3) {
// Fade out and remove after a longer time
tween(self.ballGraphics, {
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
self.isExploding = true;
LK.getSound('explosion').play();
// If this was the persistent big combo ball, clear the reference
if (typeof persistentBigComboBall !== "undefined" && persistentBigComboBall === self) {
persistentBigComboBall = null;
persistentBigComboBallColor = null;
}
return true;
} else {
// Persist on screen, not destroyed yet
return false;
}
}
// Simple effect: fade out the ballGraphics and remove the ball
tween(self.ballGraphics, {
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
// Purple balls require multiple hits, others destroyed immediately
if (self.ballColor === 'purple') {
if (!self.hitCount) self.hitCount = 0;
self.hitCount++;
if (self.hitCount >= 2) {
// Mor top tamamen yok edildiğinde: bir kaos patlaması gibi zincire çok ve karışık top ekle
if (typeof addBallToChain === "function" && typeof addBallGroup === "function") {
// 4-7 arası rastgele top ekle
var extraBalls = 4 + Math.floor(Math.random() * 4);
for (var i = 0; i < extraBalls; i++) {
if (Math.random() < 0.5) {
addBallToChain();
} else {
addBallGroup();
}
}
}
// Mor top yok edildiğinde purpleFrenzy başlat
if (typeof triggerPurpleFrenzy === "function") {
triggerPurpleFrenzy();
}
self.explode();
return true;
} else {
// Flash purple ball to show it was hit
tween(self.ballGraphics, {
tint: 0xFF00FF,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.ballGraphics, {
tint: 0xFFFFFF,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
return false;
}
} else {
self.explode();
return true;
}
};
return self;
});
var Frog = Container.expand(function () {
var self = Container.call(this);
self.frogGraphics = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 0.5
});
self.currentBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
self.nextBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
// Place the ready-to-shoot ball at the tip of the temple center (centered, just above the frog's mouth)
self.currentBall = self.attachAsset('ball_' + self.currentBallColor, {
anchorX: 0.5,
anchorY: 0.5,
// x: 0, y: -40, //{1O}{1P} -- replaced below
x: 0,
y: -templeCenter.height * 0.5 - 30,
// 30px above the temple center's tip
scaleX: 0.6,
scaleY: 0.6
});
// Removed highlight circle behind frog
self.aimAngle = 0;
self.canShoot = true;
self.updateFrogColor = function () {
// Color mapping for frog tinting based on ball color
var colorMap = {
'red': 0xff8888,
'blue': 0x8888ff,
'yellow': 0xffff88,
'green': 0x88ff88,
'purple': 0xff88ff
};
self.frogGraphics.tint = colorMap[self.currentBallColor] || 0xffffff;
};
// Initialize frog color
self.updateFrogColor();
self.updateAim = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
self.aimAngle = Math.atan2(dy, dx);
self.frogGraphics.rotation = self.aimAngle + Math.PI / 2;
// Keep next ball indicator above frog if frog moves
if (typeof nextBallBox !== "undefined") {
nextBallBox.x = self.x;
nextBallBox.y = self.y - 180;
}
if (typeof nextBallIcon !== "undefined") {
nextBallIcon.x = self.x;
nextBallIcon.y = self.y - 180;
}
};
self.shoot = function () {
if (!self.canShoot) return null;
var projectile = new Projectile(self.currentBallColor);
projectile.x = self.x;
projectile.y = self.y;
projectile.velocityX = Math.cos(self.aimAngle) * projectile.speed;
projectile.velocityY = Math.sin(self.aimAngle) * projectile.speed;
// Add visual effect when projectile is fired
// Create shooting effect with glow and scale animation
tween(projectile.projectileGraphics, {
scaleX: 1.2,
scaleY: 1.2,
tint: 0xFFFFFF
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(projectile.projectileGraphics, {
scaleX: 0.8,
scaleY: 0.8,
tint: 0xFFFFFF
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Create muzzle flash effect at frog's mouth
var muzzleFlash = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x + Math.cos(self.aimAngle) * 30,
y: self.y + Math.sin(self.aimAngle) * 30,
scaleX: 0.4,
scaleY: 0.4,
alpha: 0.8,
tint: 0xFFD700
});
game.addChild(muzzleFlash);
// Animate muzzle flash
tween(muzzleFlash, {
scaleX: 0.8,
scaleY: 0.8,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (muzzleFlash.parent) {
muzzleFlash.parent.removeChild(muzzleFlash);
}
}
});
// Update frog's current ball
self.currentBallColor = self.nextBallColor;
self.nextBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
if (self.currentBall.parent) {
self.currentBall.parent.removeChild(self.currentBall);
}
// Place the ready-to-shoot ball at the tip of the temple center (centered, just above the frog's mouth)
self.currentBall = self.attachAsset('ball_' + self.currentBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -templeCenter.height * 0.5 - 30,
// 30px above the temple center's tip
scaleX: 0.6,
scaleY: 0.6
});
// Update next ball icon above frog
if (typeof nextBallIcon !== "undefined" && nextBallIcon.parent) {
nextBallIcon.parent.removeChild(nextBallIcon);
}
nextBallIcon = LK.getAsset('ball_' + self.nextBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y - 180,
scaleX: 0.7,
scaleY: 0.7
});
if (typeof game !== "undefined") {
game.addChild(nextBallIcon);
}
// Removed highlight circle and pulsing effect logic
// Update frog color to match new ball
self.updateFrogColor();
LK.getSound('shoot').play();
return projectile;
};
return self;
});
// Game constants
var Projectile = Container.expand(function (color) {
var self = Container.call(this);
self.ballColor = color;
self.projectileGraphics = self.attachAsset('ball_' + self.ballColor, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 12;
self.active = true;
self.update = function () {
if (!self.active) return;
self.x += self.velocityX;
self.y += self.velocityY;
// Check bounds
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.active = false;
if (self.parent) {
self.parent.removeChild(self);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d5016
});
/****
* Game Code
****/
// Initialize game assets with Maya theme and retro pixel style
// Game constants
var ballColors = ['red', 'blue', 'yellow', 'green', 'purple'];
var pathRadius = 400;
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var chainSpeed = 0.22; // Slower chain movement for longer play
var maxChainLength = 220; // Allow even more balls in chain
var MAX_SPEED = 8; // Maximum allowed speed for balls
// Game variables
var ballChain = [];
var projectiles = [];
var gameRunning = true;
var chainProgress = 0;
var matchCombo = 0;
// Add green leafy background image (fills the screen, behind all game elements)
var leafyBg = LK.getAsset('path_marker', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY,
scaleX: 2048 / 3000,
scaleY: 2732 / 3000,
alpha: 0.7 // subtle, not too strong
});
game.addChild(leafyBg);
// Create temple center
var templeCenter = LK.getAsset('temple_center', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY
});
game.addChild(templeCenter);
// Create frog
var frog = new Frog();
frog.x = centerX;
frog.y = centerY;
game.addChild(frog);
// --- Next Ball Indicator UI ---
// Decorative box for next ball indicator
var nextBallBox = LK.getAsset('bud', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY - 180,
// Above frog, visually clear
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.95
});
game.addChild(nextBallBox);
// Next ball icon (will be updated dynamically)
var nextBallIcon = LK.getAsset('ball_' + frog.nextBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY - 180,
scaleX: 0.7,
scaleY: 0.7
});
game.addChild(nextBallIcon);
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create chain length display
var chainTxt = new Text2('Chain: 0', {
size: 60,
fill: 0xFFFF00
});
chainTxt.anchor.set(0, 0);
chainTxt.x = 50;
chainTxt.y = 50;
LK.gui.topLeft.addChild(chainTxt);
// Initialize ball chain
function createInitialChain() {
for (var i = 0; i < 130; i++) {
// Increased from 90 to 130 for longer play
var color = ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = i;
ball.pathPosition = i * 70;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
}
// Update ball position along scattered path with orderly movement
function updateBallPosition(ball) {
if (!ball.scatterDirection) {
// Initialize scatter direction for each ball
var angleOffset = ball.chainIndex * 137.5 % 360; // Golden angle for even distribution
ball.scatterDirection = angleOffset * Math.PI / 180;
ball.scatterRadius = 200 + ball.chainIndex % 3 * 50; // Varying distances
}
var totalProgress = chainProgress + ball.pathPosition;
// If this is a 2x big combo ball, move it at least 5x slower
var moveSpeedFactor = ball.isBigComboBall ? 0.1 : 0.5; // 0.1 is 5x slower than 0.5
var moveDistance = totalProgress * moveSpeedFactor;
var targetX = centerX + Math.cos(ball.scatterDirection) * (ball.scatterRadius + moveDistance);
var targetY = centerY + Math.sin(ball.scatterDirection) * (ball.scatterRadius + moveDistance);
// Smooth movement towards target position
// For big combo balls, also move more slowly towards their target
var lerpFactor = ball.isBigComboBall ? 0.02 : 0.1;
ball.x = ball.x + (targetX - ball.x) * lerpFactor;
ball.y = ball.y + (targetY - ball.y) * lerpFactor;
}
// Add new ball to front of chain
function addBallToChain() {
if (ballChain.length >= maxChainLength) return;
var color = ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
// Add group of same color balls occasionally
function addBallGroup() {
if (ballChain.length >= maxChainLength - 5) return;
var groupColor = ballColors[Math.floor(Math.random() * ballColors.length)];
var groupSize = 3 + Math.floor(Math.random() * 3); // 3-5 balls
for (var i = 0; i < groupSize; i++) {
if (ballChain.length >= maxChainLength) break;
var ball = new Ball(groupColor);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
}
// Check for matches in chain
function checkMatches() {
var matches = [];
var currentColor = null;
var currentGroup = [];
for (var i = 0; i < ballChain.length; i++) {
var ball = ballChain[i];
if (ball.isExploding) continue;
if (ball.ballColor === currentColor) {
currentGroup.push(ball);
} else {
if (currentGroup.length >= 3) {
matches = matches.concat(currentGroup);
}
currentColor = ball.ballColor;
currentGroup = [ball];
}
}
// Check last group
if (currentGroup.length >= 3) {
matches = matches.concat(currentGroup);
}
if (matches.length > 0) {
// Award points
var points = matches.length * 10;
if (matchCombo > 0) {
points *= matchCombo + 1;
}
LK.setScore(LK.getScore() + points);
matchCombo++;
// Explode matched balls with Maya-themed effects
for (var j = 0; j < matches.length; j++) {
var matchedBall = matches[j];
// Create temple-themed glow effect
tween(matchedBall.ballGraphics, {
tint: 0xFFD700,
// Golden glow
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
easing: tween.easeOut
});
// Add screen flash effect for larger matches
if (matches.length >= 5) {
LK.effects.flashScreen(0xFFD700, 400); // Golden flash
}
matchedBall.explode();
}
// Remove exploded balls from chain
ballChain = ballChain.filter(function (ball) {
return !ball.isExploding;
});
// Reindex remaining balls
for (var k = 0; k < ballChain.length; k++) {
ballChain[k].chainIndex = k;
}
// Create energy burst effect at match location
if (matches.length > 0) {
var centerMatchX = 0;
var centerMatchY = 0;
for (var effectIndex = 0; effectIndex < matches.length; effectIndex++) {
centerMatchX += matches[effectIndex].x;
centerMatchY += matches[effectIndex].y;
}
centerMatchX /= matches.length;
centerMatchY /= matches.length;
// Create energy orbs radiating from match center
for (var orbIndex = 0; orbIndex < 6; orbIndex++) {
var energyOrb = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: centerMatchX,
y: centerMatchY,
scaleX: 0.3,
scaleY: 0.3,
alpha: 0.8
});
game.addChild(energyOrb);
var angle = orbIndex * 60 * Math.PI / 180;
var distance = 120 + Math.random() * 80;
tween(energyOrb, {
x: centerMatchX + Math.cos(angle) * distance,
y: centerMatchY + Math.sin(angle) * distance,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
if (energyOrb.parent) {
energyOrb.parent.removeChild(energyOrb);
}
}
});
}
}
LK.getSound('match').play();
// Add new balls after successful matches to increase difficulty
// Add more balls for larger matches to reward skillful play
var ballsToAdd = 3 + Math.floor(matches.length / 3); // Base 3 + bonus for larger matches
for (var addCount = 0; addCount < ballsToAdd; addCount++) {
addBallToChain();
}
// Check for chain reactions
LK.setTimeout(function () {
checkMatches();
}, 300);
} else {
matchCombo = 0;
}
}
// Insert projectile into chain
function insertProjectileIntoChain(projectile, insertIndex) {
var newBall = new Ball(projectile.ballColor);
newBall.chainIndex = insertIndex;
// Adjust positions of balls after insertion point
for (var i = insertIndex; i < ballChain.length; i++) {
ballChain[i].chainIndex++;
ballChain[i].pathPosition += 70;
}
// Set position for new ball
if (insertIndex < ballChain.length) {
newBall.pathPosition = ballChain[insertIndex].pathPosition - 70;
} else {
newBall.pathPosition = insertIndex * 70;
}
ballChain.splice(insertIndex, 0, newBall);
game.addChild(newBall);
updateBallPosition(newBall);
// Remove projectile
if (projectile.parent) {
projectile.parent.removeChild(projectile);
}
// Check for matches
LK.setTimeout(function () {
checkMatches();
}, 100);
}
function handleBallHit(projectileColor, targetBallColor) {
if (targetBallColor === "purple") {
// Mor topa vurulunca 20 puan ekle
LK.setScore(LK.getScore() + 20);
LK.getSound('explosion').play(); // sinek efekti
return;
}
if (projectileColor === targetBallColor) {
// Doğru renge vurulduysa
// Check if the hit ball is a big combo ball (2x size, 50 points)
if (typeof hitBall !== "undefined" && hitBall.isBigComboBall) {
LK.setScore(LK.getScore() + 50);
} else {
LK.setScore(LK.getScore() + 5);
}
LK.getSound('match').play();
} else {
// Yanlış renge vurulduysa
LK.setScore(Math.max(0, LK.getScore() - 5));
LK.getSound('shoot').play();
}
}
// Handle touch input
game.down = function (x, y, obj) {
if (!gameRunning) return;
frog.updateAim(x, y);
var projectile = frog.shoot();
if (projectile) {
projectiles.push(projectile);
game.addChild(projectile);
}
};
game.move = function (x, y, obj) {
if (!gameRunning) return;
frog.updateAim(x, y);
};
// Main game update loop
game.update = function () {
if (!gameRunning) return;
// Update chain progress
chainProgress += chainSpeed;
// Update ball positions
for (var i = 0; i < ballChain.length; i++) {
var ball = ballChain[i];
if (!ball.isExploding) {
ball.lastPathPosition = ball.pathPosition;
var lastX = ball.x;
var lastY = ball.y;
updateBallPosition(ball);
// Check off-screen status, but do not remove persistent big combo ball
if (!(typeof persistentBigComboBall !== "undefined" && ball === persistentBigComboBall)) {
ball.checkOffScreen();
}
// Detect very fast moving balls and occasionally destroy them
var deltaX = ball.x - lastX;
var deltaY = ball.y - lastY;
var speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Limit ball speed to MAX_SPEED
if (speed > MAX_SPEED) {
var speedRatio = MAX_SPEED / speed;
var limitedDeltaX = deltaX * speedRatio;
var limitedDeltaY = deltaY * speedRatio;
ball.x = lastX + limitedDeltaX;
ball.y = lastY + limitedDeltaY;
speed = MAX_SPEED;
}
if (speed > 8 && Math.random() < 0.02) {
// 2% chance to destroy fast balls, but not persistent big combo ball
if (!(typeof persistentBigComboBall !== "undefined" && ball === persistentBigComboBall)) {
ball.explode();
ballChain.splice(i, 1);
i--; // Adjust index after removal
// Reindex remaining balls
for (var reindexI = 0; reindexI < ballChain.length; reindexI++) {
ballChain[reindexI].chainIndex = reindexI;
}
continue;
}
}
// Check if chain reached center (game over condition)
var totalProgress = chainProgress + ball.pathPosition;
var distanceFromCenter = Math.sqrt((ball.x - centerX) * (ball.x - centerX) + (ball.y - centerY) * (ball.y - centerY));
if (distanceFromCenter <= 120 && ball.chainIndex === 0) {
gameRunning = false;
LK.showGameOver();
return;
}
}
}
// Update projectiles
for (var j = projectiles.length - 1; j >= 0; j--) {
var projectile = projectiles[j];
if (!projectile.active) {
projectiles.splice(j, 1);
continue;
}
// Check collision with chain balls
var hitBall = null;
var insertIndex = -1;
for (var k = 0; k < ballChain.length; k++) {
var chainBall = ballChain[k];
if (chainBall.isExploding) continue;
var dx = projectile.x - chainBall.x;
var dy = projectile.y - chainBall.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 55) {
hitBall = chainBall;
insertIndex = k;
break;
}
}
if (hitBall) {
// Check if projectile color matches hit ball color for scoring
var isColorMatch = projectile.ballColor === hitBall.ballColor;
var isPurpleBall = hitBall.ballColor === 'purple';
// Destroy ball on hit (purple balls need multiple hits)
var ballDestroyed = hitBall.destroyOnHit();
if (ballDestroyed) {
// Remove destroyed ball from chain, but keep persistent big combo ball until 3 hits
for (var removeIndex = 0; removeIndex < ballChain.length; removeIndex++) {
if (ballChain[removeIndex] === hitBall) {
// If this is the persistent big combo ball and it hasn't reached 3 hits, do not remove
if (!(typeof persistentBigComboBall !== "undefined" && hitBall === persistentBigComboBall && (!hitBall.isExploding || hitBall.bigHitCount < 3))) {
ballChain.splice(removeIndex, 1);
}
break;
}
}
// Reindex remaining balls
for (var reindexK = 0; reindexK < ballChain.length; reindexK++) {
ballChain[reindexK].chainIndex = reindexK;
}
// Use centralized scoring function
handleBallHit(projectile.ballColor, hitBall.ballColor);
}
// Only create special effects for matching colors (excluding purple)
if (isColorMatch && !isPurpleBall && hitBall && hitBall.ballGraphics) {
// Create Maya-themed matching effect
tween(hitBall.ballGraphics, {
tint: 0xFFD700,
// Golden glow
scaleX: 1.4,
scaleY: 1.4
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (hitBall && hitBall.ballGraphics) {
tween(hitBall.ballGraphics, {
tint: 0xFFFFFF,
// Return to normal
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
}
});
// Create energy burst effect around the hit ball
for (var effectIndex = 0; effectIndex < 4; effectIndex++) {
var energyParticle = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: hitBall.x,
y: hitBall.y,
scaleX: 0.2,
scaleY: 0.2,
alpha: 0.9
});
game.addChild(energyParticle);
var angle = effectIndex * 90 * Math.PI / 180;
var distance = 80;
tween(energyParticle, {
x: hitBall.x + Math.cos(angle) * distance,
y: hitBall.y + Math.sin(angle) * distance,
alpha: 0,
scaleX: 0.05,
scaleY: 0.05
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
if (energyParticle.parent) {
energyParticle.parent.removeChild(energyParticle);
}
}
});
}
// Only add bonus balls for correct color matches (not purple)
if (isColorMatch && !isPurpleBall) {
// Increase combo count for consecutive correct hits
if (typeof comboCount === "undefined") comboCount = 1;else comboCount++;
// Her doğru vuruştan sonra ortaya çıkan top sayısını artır (kombo stili)
var ballsToAdd = Math.min(5 + comboCount, 20); // Kombo ile artan, bolca top
for (var comboI = 0; comboI < ballsToAdd; comboI++) {
addBallToChain();
}
// Her doğru vuruşta toplar çok yavaş hareket etsin
chainSpeed = 0.05; // Çok yavaş hareket
// --- Combo: Track per-color hit counts for 2x big, 50-point ball after 3 hits of same color ---
// Only increment color hit count if there is no persistent big combo ball on screen
if (typeof colorHitCounts === "undefined") colorHitCounts = {};
if (typeof persistentBigComboBall === "undefined" || !persistentBigComboBall) {
// Initialize color hit count if not present
if (!colorHitCounts[hitBall.ballColor]) {
colorHitCounts[hitBall.ballColor] = 0;
}
colorHitCounts[hitBall.ballColor]++;
}
// Track persistent 2x big combo ball
if (typeof persistentBigComboBall === "undefined") persistentBigComboBall = null;
if (typeof persistentBigComboBallColor === "undefined") persistentBigComboBallColor = null;
// When 3 hits of the same color (at any time), spawn a 2x big random color ball and keep it until next 3 hits of any color
if (colorHitCounts[hitBall.ballColor] === 3) {
// Remove previous persistent big combo ball if it exists
if (persistentBigComboBall && persistentBigComboBall.parent) {
persistentBigComboBall.parent.removeChild(persistentBigComboBall);
}
// Pick a random color for the big ball
var bigColors = ballColors.slice();
var randomBigColor = bigColors[Math.floor(Math.random() * bigColors.length)];
var bigBall = new Ball(randomBigColor);
bigBall.chainIndex = ballChain.length;
bigBall.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
// Büyük top için scale artır
bigBall.ballGraphics.scaleX = 2.0;
bigBall.ballGraphics.scaleY = 2.0;
// Mark as big and worth 50 points, and require 3 hits to destroy
bigBall.isBigComboBall = true;
bigBall.bigHitCount = 0; // Track hits for this big ball
// Mark as persistent
bigBall.isPersistentBigComboBall = true;
persistentBigComboBall = bigBall;
persistentBigComboBallColor = hitBall.ballColor;
ballChain.push(bigBall);
game.addChild(bigBall);
updateBallPosition(bigBall);
// 50 puan ekle
LK.setScore(LK.getScore() + 50);
// Reset this color's hit count
colorHitCounts[hitBall.ballColor] = 0;
}
// Remove persistent big combo ball only if it was hit 3 times
if (persistentBigComboBall && persistentBigComboBall.isExploding) {
persistentBigComboBall = null;
persistentBigComboBallColor = null;
}
} else {
// Reset combo on wrong color or purple
comboCount = 0;
// Reset unique color combo
colorComboHits = {};
colorComboOrder = [];
}
}
// Remove projectile immediately after hit
projectile.active = false;
if (projectile.parent) {
projectile.parent.removeChild(projectile);
}
projectiles.splice(j, 1);
if (!ballDestroyed) {
insertProjectileIntoChain(projectile, insertIndex);
}
}
}
// --- Continuous, looping ball and group spawns until score is zero ---
// Mor top yendikten sonra bir süre mor topların spawn oranını ve karmaşıklığını artır
if (typeof purpleFrenzyTicks === "undefined") {
var purpleFrenzyTicks = 0;
var purpleFrenzyEndTick = 0;
}
if (typeof lastPurpleFrenzyTriggerTick === "undefined") {
var lastPurpleFrenzyTriggerTick = -10000;
}
// Mor top yendikten sonra tetiklenecek fonksiyon
if (typeof triggerPurpleFrenzy === "undefined") {
var triggerPurpleFrenzy = function triggerPurpleFrenzy() {
purpleFrenzyTicks = 0;
purpleFrenzyEndTick = LK.ticks + 600 + Math.floor(Math.random() * 300); // 10-15 saniye
lastPurpleFrenzyTriggerTick = LK.ticks;
};
}
// Mor top yendikten sonra Ball.destroyOnHit içinde triggerPurpleFrenzy() çağrılır
if (LK.getScore() > 0) {
// Timers for next ball and group spawn
if (typeof nextBallSpawnTick === "undefined") {
var nextBallSpawnTick = LK.ticks + 30 + Math.floor(Math.random() * 90); // 0.5-2s
var nextBallGroupSpawnTick = LK.ticks + 120 + Math.floor(Math.random() * 180); // 2-5s
var nextChaosSpawnTick = LK.ticks + 180 + Math.floor(Math.random() * 300); // 3-8s
}
// Mor top fazlalığı aktif mi?
var purpleFrenzyActive = purpleFrenzyEndTick > LK.ticks;
// Random single ball spawns
if (LK.ticks >= nextBallSpawnTick && ballChain.length < maxChainLength) {
var ballsToAdd = purpleFrenzyActive ? 2 + Math.floor(Math.random() * 3) : 1 + Math.floor(Math.random() * 2); // 2-4 balls if frenzy, else 1-2
for (var i = 0; i < ballsToAdd; i++) {
// Frenzy sırasında %40 mor top, %60 random
if (purpleFrenzyActive && Math.random() < 0.4) {
var ball = new Ball('purple');
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
} else {
addBallToChain();
}
}
// Next spawn in 0.3-1s if frenzy, else 0.5-2s
nextBallSpawnTick = LK.ticks + (purpleFrenzyActive ? 18 + Math.floor(Math.random() * 30) : 30 + Math.floor(Math.random() * 90));
}
// Random group spawns
if (LK.ticks >= nextBallGroupSpawnTick && ballChain.length < maxChainLength - 5) {
var doGroup = Math.random() < (purpleFrenzyActive ? 0.9 : 0.7); // 90% group if frenzy
if (doGroup) {
// Frenzy sırasında grup içinde mor toplar karışık
if (purpleFrenzyActive && Math.random() < 0.5) {
var groupSize = 3 + Math.floor(Math.random() * 3); // 3-5 balls
for (var gi = 0; gi < groupSize; gi++) {
var color = Math.random() < 0.5 ? 'purple' : ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
} else {
addBallGroup();
}
} else {
addBallToChain();
addBallToChain();
}
// Next group in 1-2.5s if frenzy, else 2-5s
nextBallGroupSpawnTick = LK.ticks + (purpleFrenzyActive ? 60 + Math.floor(Math.random() * 90) : 120 + Math.floor(Math.random() * 180));
}
// Rare chaos burst: lots of balls at once, unpredictable
if (LK.ticks >= nextChaosSpawnTick && ballChain.length < maxChainLength - 8) {
var chaosCount = purpleFrenzyActive ? 5 + Math.floor(Math.random() * 4) : 3 + Math.floor(Math.random() * 3); // 5-8 balls if frenzy, else 3-5
for (var i = 0; i < chaosCount; i++) {
if (purpleFrenzyActive && Math.random() < 0.5) {
var color = Math.random() < 0.7 ? 'purple' : ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
} else if (Math.random() < 0.5) {
addBallToChain();
} else {
addBallGroup();
}
}
// Next chaos in 2-4s if frenzy, else 3-8s
nextChaosSpawnTick = LK.ticks + (purpleFrenzyActive ? 120 + Math.floor(Math.random() * 120) : 180 + Math.floor(Math.random() * 300));
}
} else {
// If score is zero, stop all new ball spawns
// Optionally, you could clear timers or handle end-of-loop logic here
}
// Update UI
scoreTxt.setText('Score: ' + LK.getScore());
chainTxt.setText('Chain: ' + ballChain.length);
// Check if all balls are scattered off screen (game over condition)
var allBallsOffScreen = ballChain.length > 0;
for (var m = 0; m < ballChain.length; m++) {
if (!ballChain[m].isOffScreen && !ballChain[m].isExploding) {
allBallsOffScreen = false;
break;
}
}
if (allBallsOffScreen && ballChain.length > 0) {
gameRunning = false;
LK.showGameOver();
return;
}
// Win condition - clear all balls
if (ballChain.length === 0) {
gameRunning = false;
LK.setScore(LK.getScore() + 1000); // Bonus for clearing
LK.showYouWin();
return;
}
};
// Initialize the game
createInitialChain();
;
// Play background music 'amazon'
LK.playMusic('amazon');
// Minimalistic tween library for animations /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function (color) {
var self = Container.call(this);
self.ballColor = color || 'red';
self.ballGraphics = self.attachAsset('ball_' + self.ballColor, {
anchorX: 0.5,
anchorY: 0.5
});
self.chainIndex = 0;
self.pathPosition = 0;
self.isExploding = false;
self.isBigComboBall = false; // Default: not a big combo ball
self.lastPathPosition = 0;
self.isOffScreen = false;
self.lastX = 0;
self.lastY = 0;
self.checkOffScreen = function () {
// Check if ball has moved completely off screen
var margin = 100; // Extra margin to ensure ball is truly gone
var wasOnScreen = self.lastX >= -margin && self.lastX <= 2048 + margin && self.lastY >= -margin && self.lastY <= 2732 + margin;
var isNowOffScreen = self.x < -margin || self.x > 2048 + margin || self.y < -margin || self.y > 2732 + margin;
// Detect transition from on-screen to off-screen
if (wasOnScreen && isNowOffScreen && !self.isOffScreen) {
self.isOffScreen = true;
}
// Update last known positions
self.lastX = self.x;
self.lastY = self.y;
};
self.explode = function () {
if (self.isExploding) return;
self.isExploding = true;
tween(self.ballGraphics, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
LK.getSound('explosion').play();
};
self.destroyOnHit = function () {
// 2x big combo balls: require 3 hits, persist longer
if (self.isBigComboBall) {
if (!self.bigHitCount) self.bigHitCount = 0;
self.bigHitCount++;
// Flash effect to show hit
tween(self.ballGraphics, {
tint: 0xFFD700,
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.ballGraphics, {
tint: 0xFFFFFF,
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Only destroy after 3 hits
if (self.bigHitCount >= 3) {
// Fade out and remove after a longer time
tween(self.ballGraphics, {
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
self.isExploding = true;
LK.getSound('explosion').play();
// If this was the persistent big combo ball, clear the reference
if (typeof persistentBigComboBall !== "undefined" && persistentBigComboBall === self) {
persistentBigComboBall = null;
persistentBigComboBallColor = null;
}
return true;
} else {
// Persist on screen, not destroyed yet
return false;
}
}
// Simple effect: fade out the ballGraphics and remove the ball
tween(self.ballGraphics, {
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (self.parent) {
self.parent.removeChild(self);
}
}
});
// Purple balls require multiple hits, others destroyed immediately
if (self.ballColor === 'purple') {
if (!self.hitCount) self.hitCount = 0;
self.hitCount++;
if (self.hitCount >= 2) {
// Mor top tamamen yok edildiğinde: bir kaos patlaması gibi zincire çok ve karışık top ekle
if (typeof addBallToChain === "function" && typeof addBallGroup === "function") {
// 4-7 arası rastgele top ekle
var extraBalls = 4 + Math.floor(Math.random() * 4);
for (var i = 0; i < extraBalls; i++) {
if (Math.random() < 0.5) {
addBallToChain();
} else {
addBallGroup();
}
}
}
// Mor top yok edildiğinde purpleFrenzy başlat
if (typeof triggerPurpleFrenzy === "function") {
triggerPurpleFrenzy();
}
self.explode();
return true;
} else {
// Flash purple ball to show it was hit
tween(self.ballGraphics, {
tint: 0xFF00FF,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.ballGraphics, {
tint: 0xFFFFFF,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
return false;
}
} else {
self.explode();
return true;
}
};
return self;
});
var Frog = Container.expand(function () {
var self = Container.call(this);
self.frogGraphics = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 0.5
});
self.currentBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
self.nextBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
// Place the ready-to-shoot ball at the tip of the temple center (centered, just above the frog's mouth)
self.currentBall = self.attachAsset('ball_' + self.currentBallColor, {
anchorX: 0.5,
anchorY: 0.5,
// x: 0, y: -40, //{1O}{1P} -- replaced below
x: 0,
y: -templeCenter.height * 0.5 - 30,
// 30px above the temple center's tip
scaleX: 0.6,
scaleY: 0.6
});
// Removed highlight circle behind frog
self.aimAngle = 0;
self.canShoot = true;
self.updateFrogColor = function () {
// Color mapping for frog tinting based on ball color
var colorMap = {
'red': 0xff8888,
'blue': 0x8888ff,
'yellow': 0xffff88,
'green': 0x88ff88,
'purple': 0xff88ff
};
self.frogGraphics.tint = colorMap[self.currentBallColor] || 0xffffff;
};
// Initialize frog color
self.updateFrogColor();
self.updateAim = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
self.aimAngle = Math.atan2(dy, dx);
self.frogGraphics.rotation = self.aimAngle + Math.PI / 2;
// Keep next ball indicator above frog if frog moves
if (typeof nextBallBox !== "undefined") {
nextBallBox.x = self.x;
nextBallBox.y = self.y - 180;
}
if (typeof nextBallIcon !== "undefined") {
nextBallIcon.x = self.x;
nextBallIcon.y = self.y - 180;
}
};
self.shoot = function () {
if (!self.canShoot) return null;
var projectile = new Projectile(self.currentBallColor);
projectile.x = self.x;
projectile.y = self.y;
projectile.velocityX = Math.cos(self.aimAngle) * projectile.speed;
projectile.velocityY = Math.sin(self.aimAngle) * projectile.speed;
// Add visual effect when projectile is fired
// Create shooting effect with glow and scale animation
tween(projectile.projectileGraphics, {
scaleX: 1.2,
scaleY: 1.2,
tint: 0xFFFFFF
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(projectile.projectileGraphics, {
scaleX: 0.8,
scaleY: 0.8,
tint: 0xFFFFFF
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Create muzzle flash effect at frog's mouth
var muzzleFlash = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x + Math.cos(self.aimAngle) * 30,
y: self.y + Math.sin(self.aimAngle) * 30,
scaleX: 0.4,
scaleY: 0.4,
alpha: 0.8,
tint: 0xFFD700
});
game.addChild(muzzleFlash);
// Animate muzzle flash
tween(muzzleFlash, {
scaleX: 0.8,
scaleY: 0.8,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (muzzleFlash.parent) {
muzzleFlash.parent.removeChild(muzzleFlash);
}
}
});
// Update frog's current ball
self.currentBallColor = self.nextBallColor;
self.nextBallColor = ballColors[Math.floor(Math.random() * ballColors.length)];
if (self.currentBall.parent) {
self.currentBall.parent.removeChild(self.currentBall);
}
// Place the ready-to-shoot ball at the tip of the temple center (centered, just above the frog's mouth)
self.currentBall = self.attachAsset('ball_' + self.currentBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -templeCenter.height * 0.5 - 30,
// 30px above the temple center's tip
scaleX: 0.6,
scaleY: 0.6
});
// Update next ball icon above frog
if (typeof nextBallIcon !== "undefined" && nextBallIcon.parent) {
nextBallIcon.parent.removeChild(nextBallIcon);
}
nextBallIcon = LK.getAsset('ball_' + self.nextBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y - 180,
scaleX: 0.7,
scaleY: 0.7
});
if (typeof game !== "undefined") {
game.addChild(nextBallIcon);
}
// Removed highlight circle and pulsing effect logic
// Update frog color to match new ball
self.updateFrogColor();
LK.getSound('shoot').play();
return projectile;
};
return self;
});
// Game constants
var Projectile = Container.expand(function (color) {
var self = Container.call(this);
self.ballColor = color;
self.projectileGraphics = self.attachAsset('ball_' + self.ballColor, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 12;
self.active = true;
self.update = function () {
if (!self.active) return;
self.x += self.velocityX;
self.y += self.velocityY;
// Check bounds
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.active = false;
if (self.parent) {
self.parent.removeChild(self);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d5016
});
/****
* Game Code
****/
// Initialize game assets with Maya theme and retro pixel style
// Game constants
var ballColors = ['red', 'blue', 'yellow', 'green', 'purple'];
var pathRadius = 400;
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var chainSpeed = 0.22; // Slower chain movement for longer play
var maxChainLength = 220; // Allow even more balls in chain
var MAX_SPEED = 8; // Maximum allowed speed for balls
// Game variables
var ballChain = [];
var projectiles = [];
var gameRunning = true;
var chainProgress = 0;
var matchCombo = 0;
// Add green leafy background image (fills the screen, behind all game elements)
var leafyBg = LK.getAsset('path_marker', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY,
scaleX: 2048 / 3000,
scaleY: 2732 / 3000,
alpha: 0.7 // subtle, not too strong
});
game.addChild(leafyBg);
// Create temple center
var templeCenter = LK.getAsset('temple_center', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY
});
game.addChild(templeCenter);
// Create frog
var frog = new Frog();
frog.x = centerX;
frog.y = centerY;
game.addChild(frog);
// --- Next Ball Indicator UI ---
// Decorative box for next ball indicator
var nextBallBox = LK.getAsset('bud', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY - 180,
// Above frog, visually clear
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.95
});
game.addChild(nextBallBox);
// Next ball icon (will be updated dynamically)
var nextBallIcon = LK.getAsset('ball_' + frog.nextBallColor, {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY - 180,
scaleX: 0.7,
scaleY: 0.7
});
game.addChild(nextBallIcon);
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create chain length display
var chainTxt = new Text2('Chain: 0', {
size: 60,
fill: 0xFFFF00
});
chainTxt.anchor.set(0, 0);
chainTxt.x = 50;
chainTxt.y = 50;
LK.gui.topLeft.addChild(chainTxt);
// Initialize ball chain
function createInitialChain() {
for (var i = 0; i < 130; i++) {
// Increased from 90 to 130 for longer play
var color = ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = i;
ball.pathPosition = i * 70;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
}
// Update ball position along scattered path with orderly movement
function updateBallPosition(ball) {
if (!ball.scatterDirection) {
// Initialize scatter direction for each ball
var angleOffset = ball.chainIndex * 137.5 % 360; // Golden angle for even distribution
ball.scatterDirection = angleOffset * Math.PI / 180;
ball.scatterRadius = 200 + ball.chainIndex % 3 * 50; // Varying distances
}
var totalProgress = chainProgress + ball.pathPosition;
// If this is a 2x big combo ball, move it at least 5x slower
var moveSpeedFactor = ball.isBigComboBall ? 0.1 : 0.5; // 0.1 is 5x slower than 0.5
var moveDistance = totalProgress * moveSpeedFactor;
var targetX = centerX + Math.cos(ball.scatterDirection) * (ball.scatterRadius + moveDistance);
var targetY = centerY + Math.sin(ball.scatterDirection) * (ball.scatterRadius + moveDistance);
// Smooth movement towards target position
// For big combo balls, also move more slowly towards their target
var lerpFactor = ball.isBigComboBall ? 0.02 : 0.1;
ball.x = ball.x + (targetX - ball.x) * lerpFactor;
ball.y = ball.y + (targetY - ball.y) * lerpFactor;
}
// Add new ball to front of chain
function addBallToChain() {
if (ballChain.length >= maxChainLength) return;
var color = ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
// Add group of same color balls occasionally
function addBallGroup() {
if (ballChain.length >= maxChainLength - 5) return;
var groupColor = ballColors[Math.floor(Math.random() * ballColors.length)];
var groupSize = 3 + Math.floor(Math.random() * 3); // 3-5 balls
for (var i = 0; i < groupSize; i++) {
if (ballChain.length >= maxChainLength) break;
var ball = new Ball(groupColor);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
}
// Check for matches in chain
function checkMatches() {
var matches = [];
var currentColor = null;
var currentGroup = [];
for (var i = 0; i < ballChain.length; i++) {
var ball = ballChain[i];
if (ball.isExploding) continue;
if (ball.ballColor === currentColor) {
currentGroup.push(ball);
} else {
if (currentGroup.length >= 3) {
matches = matches.concat(currentGroup);
}
currentColor = ball.ballColor;
currentGroup = [ball];
}
}
// Check last group
if (currentGroup.length >= 3) {
matches = matches.concat(currentGroup);
}
if (matches.length > 0) {
// Award points
var points = matches.length * 10;
if (matchCombo > 0) {
points *= matchCombo + 1;
}
LK.setScore(LK.getScore() + points);
matchCombo++;
// Explode matched balls with Maya-themed effects
for (var j = 0; j < matches.length; j++) {
var matchedBall = matches[j];
// Create temple-themed glow effect
tween(matchedBall.ballGraphics, {
tint: 0xFFD700,
// Golden glow
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
easing: tween.easeOut
});
// Add screen flash effect for larger matches
if (matches.length >= 5) {
LK.effects.flashScreen(0xFFD700, 400); // Golden flash
}
matchedBall.explode();
}
// Remove exploded balls from chain
ballChain = ballChain.filter(function (ball) {
return !ball.isExploding;
});
// Reindex remaining balls
for (var k = 0; k < ballChain.length; k++) {
ballChain[k].chainIndex = k;
}
// Create energy burst effect at match location
if (matches.length > 0) {
var centerMatchX = 0;
var centerMatchY = 0;
for (var effectIndex = 0; effectIndex < matches.length; effectIndex++) {
centerMatchX += matches[effectIndex].x;
centerMatchY += matches[effectIndex].y;
}
centerMatchX /= matches.length;
centerMatchY /= matches.length;
// Create energy orbs radiating from match center
for (var orbIndex = 0; orbIndex < 6; orbIndex++) {
var energyOrb = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: centerMatchX,
y: centerMatchY,
scaleX: 0.3,
scaleY: 0.3,
alpha: 0.8
});
game.addChild(energyOrb);
var angle = orbIndex * 60 * Math.PI / 180;
var distance = 120 + Math.random() * 80;
tween(energyOrb, {
x: centerMatchX + Math.cos(angle) * distance,
y: centerMatchY + Math.sin(angle) * distance,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
if (energyOrb.parent) {
energyOrb.parent.removeChild(energyOrb);
}
}
});
}
}
LK.getSound('match').play();
// Add new balls after successful matches to increase difficulty
// Add more balls for larger matches to reward skillful play
var ballsToAdd = 3 + Math.floor(matches.length / 3); // Base 3 + bonus for larger matches
for (var addCount = 0; addCount < ballsToAdd; addCount++) {
addBallToChain();
}
// Check for chain reactions
LK.setTimeout(function () {
checkMatches();
}, 300);
} else {
matchCombo = 0;
}
}
// Insert projectile into chain
function insertProjectileIntoChain(projectile, insertIndex) {
var newBall = new Ball(projectile.ballColor);
newBall.chainIndex = insertIndex;
// Adjust positions of balls after insertion point
for (var i = insertIndex; i < ballChain.length; i++) {
ballChain[i].chainIndex++;
ballChain[i].pathPosition += 70;
}
// Set position for new ball
if (insertIndex < ballChain.length) {
newBall.pathPosition = ballChain[insertIndex].pathPosition - 70;
} else {
newBall.pathPosition = insertIndex * 70;
}
ballChain.splice(insertIndex, 0, newBall);
game.addChild(newBall);
updateBallPosition(newBall);
// Remove projectile
if (projectile.parent) {
projectile.parent.removeChild(projectile);
}
// Check for matches
LK.setTimeout(function () {
checkMatches();
}, 100);
}
function handleBallHit(projectileColor, targetBallColor) {
if (targetBallColor === "purple") {
// Mor topa vurulunca 20 puan ekle
LK.setScore(LK.getScore() + 20);
LK.getSound('explosion').play(); // sinek efekti
return;
}
if (projectileColor === targetBallColor) {
// Doğru renge vurulduysa
// Check if the hit ball is a big combo ball (2x size, 50 points)
if (typeof hitBall !== "undefined" && hitBall.isBigComboBall) {
LK.setScore(LK.getScore() + 50);
} else {
LK.setScore(LK.getScore() + 5);
}
LK.getSound('match').play();
} else {
// Yanlış renge vurulduysa
LK.setScore(Math.max(0, LK.getScore() - 5));
LK.getSound('shoot').play();
}
}
// Handle touch input
game.down = function (x, y, obj) {
if (!gameRunning) return;
frog.updateAim(x, y);
var projectile = frog.shoot();
if (projectile) {
projectiles.push(projectile);
game.addChild(projectile);
}
};
game.move = function (x, y, obj) {
if (!gameRunning) return;
frog.updateAim(x, y);
};
// Main game update loop
game.update = function () {
if (!gameRunning) return;
// Update chain progress
chainProgress += chainSpeed;
// Update ball positions
for (var i = 0; i < ballChain.length; i++) {
var ball = ballChain[i];
if (!ball.isExploding) {
ball.lastPathPosition = ball.pathPosition;
var lastX = ball.x;
var lastY = ball.y;
updateBallPosition(ball);
// Check off-screen status, but do not remove persistent big combo ball
if (!(typeof persistentBigComboBall !== "undefined" && ball === persistentBigComboBall)) {
ball.checkOffScreen();
}
// Detect very fast moving balls and occasionally destroy them
var deltaX = ball.x - lastX;
var deltaY = ball.y - lastY;
var speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Limit ball speed to MAX_SPEED
if (speed > MAX_SPEED) {
var speedRatio = MAX_SPEED / speed;
var limitedDeltaX = deltaX * speedRatio;
var limitedDeltaY = deltaY * speedRatio;
ball.x = lastX + limitedDeltaX;
ball.y = lastY + limitedDeltaY;
speed = MAX_SPEED;
}
if (speed > 8 && Math.random() < 0.02) {
// 2% chance to destroy fast balls, but not persistent big combo ball
if (!(typeof persistentBigComboBall !== "undefined" && ball === persistentBigComboBall)) {
ball.explode();
ballChain.splice(i, 1);
i--; // Adjust index after removal
// Reindex remaining balls
for (var reindexI = 0; reindexI < ballChain.length; reindexI++) {
ballChain[reindexI].chainIndex = reindexI;
}
continue;
}
}
// Check if chain reached center (game over condition)
var totalProgress = chainProgress + ball.pathPosition;
var distanceFromCenter = Math.sqrt((ball.x - centerX) * (ball.x - centerX) + (ball.y - centerY) * (ball.y - centerY));
if (distanceFromCenter <= 120 && ball.chainIndex === 0) {
gameRunning = false;
LK.showGameOver();
return;
}
}
}
// Update projectiles
for (var j = projectiles.length - 1; j >= 0; j--) {
var projectile = projectiles[j];
if (!projectile.active) {
projectiles.splice(j, 1);
continue;
}
// Check collision with chain balls
var hitBall = null;
var insertIndex = -1;
for (var k = 0; k < ballChain.length; k++) {
var chainBall = ballChain[k];
if (chainBall.isExploding) continue;
var dx = projectile.x - chainBall.x;
var dy = projectile.y - chainBall.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 55) {
hitBall = chainBall;
insertIndex = k;
break;
}
}
if (hitBall) {
// Check if projectile color matches hit ball color for scoring
var isColorMatch = projectile.ballColor === hitBall.ballColor;
var isPurpleBall = hitBall.ballColor === 'purple';
// Destroy ball on hit (purple balls need multiple hits)
var ballDestroyed = hitBall.destroyOnHit();
if (ballDestroyed) {
// Remove destroyed ball from chain, but keep persistent big combo ball until 3 hits
for (var removeIndex = 0; removeIndex < ballChain.length; removeIndex++) {
if (ballChain[removeIndex] === hitBall) {
// If this is the persistent big combo ball and it hasn't reached 3 hits, do not remove
if (!(typeof persistentBigComboBall !== "undefined" && hitBall === persistentBigComboBall && (!hitBall.isExploding || hitBall.bigHitCount < 3))) {
ballChain.splice(removeIndex, 1);
}
break;
}
}
// Reindex remaining balls
for (var reindexK = 0; reindexK < ballChain.length; reindexK++) {
ballChain[reindexK].chainIndex = reindexK;
}
// Use centralized scoring function
handleBallHit(projectile.ballColor, hitBall.ballColor);
}
// Only create special effects for matching colors (excluding purple)
if (isColorMatch && !isPurpleBall && hitBall && hitBall.ballGraphics) {
// Create Maya-themed matching effect
tween(hitBall.ballGraphics, {
tint: 0xFFD700,
// Golden glow
scaleX: 1.4,
scaleY: 1.4
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
if (hitBall && hitBall.ballGraphics) {
tween(hitBall.ballGraphics, {
tint: 0xFFFFFF,
// Return to normal
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
}
});
// Create energy burst effect around the hit ball
for (var effectIndex = 0; effectIndex < 4; effectIndex++) {
var energyParticle = LK.getAsset('ball_yellow', {
anchorX: 0.5,
anchorY: 0.5,
x: hitBall.x,
y: hitBall.y,
scaleX: 0.2,
scaleY: 0.2,
alpha: 0.9
});
game.addChild(energyParticle);
var angle = effectIndex * 90 * Math.PI / 180;
var distance = 80;
tween(energyParticle, {
x: hitBall.x + Math.cos(angle) * distance,
y: hitBall.y + Math.sin(angle) * distance,
alpha: 0,
scaleX: 0.05,
scaleY: 0.05
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
if (energyParticle.parent) {
energyParticle.parent.removeChild(energyParticle);
}
}
});
}
// Only add bonus balls for correct color matches (not purple)
if (isColorMatch && !isPurpleBall) {
// Increase combo count for consecutive correct hits
if (typeof comboCount === "undefined") comboCount = 1;else comboCount++;
// Her doğru vuruştan sonra ortaya çıkan top sayısını artır (kombo stili)
var ballsToAdd = Math.min(5 + comboCount, 20); // Kombo ile artan, bolca top
for (var comboI = 0; comboI < ballsToAdd; comboI++) {
addBallToChain();
}
// Her doğru vuruşta toplar çok yavaş hareket etsin
chainSpeed = 0.05; // Çok yavaş hareket
// --- Combo: Track per-color hit counts for 2x big, 50-point ball after 3 hits of same color ---
// Only increment color hit count if there is no persistent big combo ball on screen
if (typeof colorHitCounts === "undefined") colorHitCounts = {};
if (typeof persistentBigComboBall === "undefined" || !persistentBigComboBall) {
// Initialize color hit count if not present
if (!colorHitCounts[hitBall.ballColor]) {
colorHitCounts[hitBall.ballColor] = 0;
}
colorHitCounts[hitBall.ballColor]++;
}
// Track persistent 2x big combo ball
if (typeof persistentBigComboBall === "undefined") persistentBigComboBall = null;
if (typeof persistentBigComboBallColor === "undefined") persistentBigComboBallColor = null;
// When 3 hits of the same color (at any time), spawn a 2x big random color ball and keep it until next 3 hits of any color
if (colorHitCounts[hitBall.ballColor] === 3) {
// Remove previous persistent big combo ball if it exists
if (persistentBigComboBall && persistentBigComboBall.parent) {
persistentBigComboBall.parent.removeChild(persistentBigComboBall);
}
// Pick a random color for the big ball
var bigColors = ballColors.slice();
var randomBigColor = bigColors[Math.floor(Math.random() * bigColors.length)];
var bigBall = new Ball(randomBigColor);
bigBall.chainIndex = ballChain.length;
bigBall.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
// Büyük top için scale artır
bigBall.ballGraphics.scaleX = 2.0;
bigBall.ballGraphics.scaleY = 2.0;
// Mark as big and worth 50 points, and require 3 hits to destroy
bigBall.isBigComboBall = true;
bigBall.bigHitCount = 0; // Track hits for this big ball
// Mark as persistent
bigBall.isPersistentBigComboBall = true;
persistentBigComboBall = bigBall;
persistentBigComboBallColor = hitBall.ballColor;
ballChain.push(bigBall);
game.addChild(bigBall);
updateBallPosition(bigBall);
// 50 puan ekle
LK.setScore(LK.getScore() + 50);
// Reset this color's hit count
colorHitCounts[hitBall.ballColor] = 0;
}
// Remove persistent big combo ball only if it was hit 3 times
if (persistentBigComboBall && persistentBigComboBall.isExploding) {
persistentBigComboBall = null;
persistentBigComboBallColor = null;
}
} else {
// Reset combo on wrong color or purple
comboCount = 0;
// Reset unique color combo
colorComboHits = {};
colorComboOrder = [];
}
}
// Remove projectile immediately after hit
projectile.active = false;
if (projectile.parent) {
projectile.parent.removeChild(projectile);
}
projectiles.splice(j, 1);
if (!ballDestroyed) {
insertProjectileIntoChain(projectile, insertIndex);
}
}
}
// --- Continuous, looping ball and group spawns until score is zero ---
// Mor top yendikten sonra bir süre mor topların spawn oranını ve karmaşıklığını artır
if (typeof purpleFrenzyTicks === "undefined") {
var purpleFrenzyTicks = 0;
var purpleFrenzyEndTick = 0;
}
if (typeof lastPurpleFrenzyTriggerTick === "undefined") {
var lastPurpleFrenzyTriggerTick = -10000;
}
// Mor top yendikten sonra tetiklenecek fonksiyon
if (typeof triggerPurpleFrenzy === "undefined") {
var triggerPurpleFrenzy = function triggerPurpleFrenzy() {
purpleFrenzyTicks = 0;
purpleFrenzyEndTick = LK.ticks + 600 + Math.floor(Math.random() * 300); // 10-15 saniye
lastPurpleFrenzyTriggerTick = LK.ticks;
};
}
// Mor top yendikten sonra Ball.destroyOnHit içinde triggerPurpleFrenzy() çağrılır
if (LK.getScore() > 0) {
// Timers for next ball and group spawn
if (typeof nextBallSpawnTick === "undefined") {
var nextBallSpawnTick = LK.ticks + 30 + Math.floor(Math.random() * 90); // 0.5-2s
var nextBallGroupSpawnTick = LK.ticks + 120 + Math.floor(Math.random() * 180); // 2-5s
var nextChaosSpawnTick = LK.ticks + 180 + Math.floor(Math.random() * 300); // 3-8s
}
// Mor top fazlalığı aktif mi?
var purpleFrenzyActive = purpleFrenzyEndTick > LK.ticks;
// Random single ball spawns
if (LK.ticks >= nextBallSpawnTick && ballChain.length < maxChainLength) {
var ballsToAdd = purpleFrenzyActive ? 2 + Math.floor(Math.random() * 3) : 1 + Math.floor(Math.random() * 2); // 2-4 balls if frenzy, else 1-2
for (var i = 0; i < ballsToAdd; i++) {
// Frenzy sırasında %40 mor top, %60 random
if (purpleFrenzyActive && Math.random() < 0.4) {
var ball = new Ball('purple');
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
} else {
addBallToChain();
}
}
// Next spawn in 0.3-1s if frenzy, else 0.5-2s
nextBallSpawnTick = LK.ticks + (purpleFrenzyActive ? 18 + Math.floor(Math.random() * 30) : 30 + Math.floor(Math.random() * 90));
}
// Random group spawns
if (LK.ticks >= nextBallGroupSpawnTick && ballChain.length < maxChainLength - 5) {
var doGroup = Math.random() < (purpleFrenzyActive ? 0.9 : 0.7); // 90% group if frenzy
if (doGroup) {
// Frenzy sırasında grup içinde mor toplar karışık
if (purpleFrenzyActive && Math.random() < 0.5) {
var groupSize = 3 + Math.floor(Math.random() * 3); // 3-5 balls
for (var gi = 0; gi < groupSize; gi++) {
var color = Math.random() < 0.5 ? 'purple' : ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
}
} else {
addBallGroup();
}
} else {
addBallToChain();
addBallToChain();
}
// Next group in 1-2.5s if frenzy, else 2-5s
nextBallGroupSpawnTick = LK.ticks + (purpleFrenzyActive ? 60 + Math.floor(Math.random() * 90) : 120 + Math.floor(Math.random() * 180));
}
// Rare chaos burst: lots of balls at once, unpredictable
if (LK.ticks >= nextChaosSpawnTick && ballChain.length < maxChainLength - 8) {
var chaosCount = purpleFrenzyActive ? 5 + Math.floor(Math.random() * 4) : 3 + Math.floor(Math.random() * 3); // 5-8 balls if frenzy, else 3-5
for (var i = 0; i < chaosCount; i++) {
if (purpleFrenzyActive && Math.random() < 0.5) {
var color = Math.random() < 0.7 ? 'purple' : ballColors[Math.floor(Math.random() * ballColors.length)];
var ball = new Ball(color);
ball.chainIndex = ballChain.length;
ball.pathPosition = ballChain.length > 0 ? ballChain[ballChain.length - 1].pathPosition + 70 : 0;
ballChain.push(ball);
game.addChild(ball);
updateBallPosition(ball);
} else if (Math.random() < 0.5) {
addBallToChain();
} else {
addBallGroup();
}
}
// Next chaos in 2-4s if frenzy, else 3-8s
nextChaosSpawnTick = LK.ticks + (purpleFrenzyActive ? 120 + Math.floor(Math.random() * 120) : 180 + Math.floor(Math.random() * 300));
}
} else {
// If score is zero, stop all new ball spawns
// Optionally, you could clear timers or handle end-of-loop logic here
}
// Update UI
scoreTxt.setText('Score: ' + LK.getScore());
chainTxt.setText('Chain: ' + ballChain.length);
// Check if all balls are scattered off screen (game over condition)
var allBallsOffScreen = ballChain.length > 0;
for (var m = 0; m < ballChain.length; m++) {
if (!ballChain[m].isOffScreen && !ballChain[m].isExploding) {
allBallsOffScreen = false;
break;
}
}
if (allBallsOffScreen && ballChain.length > 0) {
gameRunning = false;
LK.showGameOver();
return;
}
// Win condition - clear all balls
if (ballChain.length === 0) {
gameRunning = false;
LK.setScore(LK.getScore() + 1000); // Bonus for clearing
LK.showYouWin();
return;
}
};
// Initialize the game
createInitialChain();
;
// Play background music 'amazon'
LK.playMusic('amazon');
// Minimalistic tween library for animations
kocaman gözleri olan ve ağzında olan her renge göre renk değiştiren bir bukalemun. In-Game asset. 2d. High contrast. No shadows
minik ve çok sevimli bir yusufçuk. In-Game asset. 2d. High contrast. No shadows
minik sevimli bir tırtıl. In-Game asset. 2d. High contrast. No shadows
çirkin ve sevimsiz kara sinek mor renkli bir kısmı. In-Game asset. 2d. High contrast. No shadows
çok güzel renkleri olan ağırlıklı olarak kırmızı renkli kelebek. In-Game asset. 2d. High contrast. No shadows
yeşil yapraklar ve ağaçlar olan orta bir alan. In-Game asset. 2d. High contrast. No shadows
oval kütük küçük bir meydan gibi üstten görünümlü. In-Game asset. 2d. High contrast. No shadows
çember şeklinde bir görseli çerçeve içine alan çevresi yeşillik çerçeve. In-Game asset. 2d. High contrast. No shadows