/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Kutuların sınıfı var DraggableBox = Container.expand(function () { var self = Container.call(this); // Renk seçimi var colorList = ['box_red', 'box_blue', 'box_green', 'box_yellow', 'box_purple']; var colorId = colorList[Math.floor(Math.random() * colorList.length)]; self.colorId = colorId; // Kutu grafiği var box = self.attachAsset(colorId, { anchorX: 0.5, anchorY: 0.5 }); // Kutu sürükleniyor mu? self.isDragging = false; // Kutu hedefe ulaştı mı? self.isDelivered = false; // Kutuya dokunulduğunda self.down = function (x, y, obj) { if (self.isDelivered) return; self.isDragging = true; // Hafifçe büyüt tween(self, { scaleX: 1.15, scaleY: 1.15 }, { duration: 120, easing: tween.easeOut }); }; // Kutu bırakıldığında self.up = function (x, y, obj) { if (self.isDelivered) return; self.isDragging = false; // Eski boyuta dön tween(self, { scaleX: 1, scaleY: 1 }, { duration: 120, easing: tween.easeOut }); }; // Kutu sürüklenirken self.move = function (x, y, obj) { // Sürükleme işlemi game.move'da yönetilecek }; // Kutu hedefe ulaştığında animasyon self.deliver = function () { self.isDelivered = true; // Hedefte hafif büyütüp kaybolma animasyonu tween(self, { scaleX: 1.4, scaleY: 1.4, alpha: 0 }, { duration: 220, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xf7f7f7 }); /**** * Game Code ****/ // Kutular için farklı renklerde kutu şekilleri oluşturuluyor // Oyun alanı boyutları var GAME_W = 2048; var GAME_H = 2732; // Hedef bölgeyi ortala var target = LK.getAsset('target', { anchorX: 0.5, anchorY: 0.5, x: GAME_W / 2, y: GAME_H * 0.78 // Alt kısımda, ama ekranın dışında değil }); game.addChild(target); // Skor metni var scoreTxt = new Text2('0', { size: 120, fill: 0x222222 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Zamanlayıcı metni var timerTxt = new Text2('0', { size: 70, fill: 0x666666 }); timerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(timerTxt); timerTxt.y = 130; // Kutular dizisi var boxes = []; // Sürüklenen kutu var dragBox = null; // Sürükleme offseti var dragOffsetX = 0; var dragOffsetY = 0; // Oyun süresi (saniye) var elapsedTime = 0; // Kutu oluşturma aralığı (ms) var boxInterval = 1600; var boxIntervalMin = 600; var boxIntervalStep = 60; // Son kutu oluşturma tick'i var lastBoxTick = 0; // Skoru güncelle function updateScore(val) { LK.setScore(val); scoreTxt.setText(val); } // Zamanı güncelle function updateTimer(sec) { timerTxt.setText(sec + " sn"); } // Yeni kutu oluştur function spawnBox() { var box = new DraggableBox(); // Rastgele bir konum (hedeften uzakta, üst 2/3'te) var safeRadius = 400; var spawnAreaY = GAME_H * 0.12 + Math.random() * (GAME_H * 0.5); var spawnAreaX = 200 + Math.random() * (GAME_W - 400); // Hedeften uzaksa var dx = spawnAreaX - target.x; var dy = spawnAreaY - target.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < safeRadius) { // Uzaklaştır if (dx === 0 && dy === 0) { spawnAreaX += 300; } else { spawnAreaX += dx / dist * safeRadius; spawnAreaY += dy / dist * safeRadius; } } box.x = spawnAreaX; box.y = spawnAreaY; box.scaleX = 1; box.scaleY = 1; box.alpha = 1; // Kutuyu ekle game.addChild(box); boxes.push(box); } // Oyun başladığında ilk kutuyu oluştur spawnBox(); // Oyun tick fonksiyonu game.update = function () { // Zamanı güncelle if (LK.ticks % 60 === 0) { elapsedTime += 1; updateTimer(elapsedTime); // 20 saniye dolduysa oyunu bitir if (elapsedTime >= 20) { LK.showGameOver(); return; } } // Kutu oluşturma aralığını azalt (oyun hızlanır) if (boxInterval > boxIntervalMin && LK.ticks % 180 === 0) { boxInterval -= boxIntervalStep; if (boxInterval < boxIntervalMin) boxInterval = boxIntervalMin; } // Yeni kutu oluşturma zamanı geldiyse if (LK.ticks - lastBoxTick > Math.floor(boxInterval / 16.67)) { spawnBox(); lastBoxTick = LK.ticks; } // Kutular hedefe ulaştı mı kontrol et for (var i = boxes.length - 1; i >= 0; i--) { var box = boxes[i]; if (box.isDelivered) continue; // 3 saniye içinde yok olma (ateşli animasyon) if (!box._fireStarted) { box._fireStarted = true; // Ateş efekti için kutuya kırmızımsı bir tint ve titreme animasyonu var fireTween = tween(box, { scaleX: 1.1, scaleY: 1.1 }, { duration: 200, yoyo: true, repeat: 6, onFinish: function onFinish() { // 3 saniye sonunda kutu yok olsun if (!box.isDelivered) { box.isDelivered = true; tween(box, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { box.destroy(); } }); boxes.splice(i, 1); // Blok yok olma sayacı fireBlockCount = typeof fireBlockCount === "undefined" ? 1 : fireBlockCount + 1; // 5 blok yok olursa hedef küçülsün if (fireBlockCount % 5 === 0 && target.scaleX > 0.4) { tween(target, { scaleX: target.scaleX - 0.12, scaleY: target.scaleY - 0.12 }, { duration: 350, easing: tween.easeIn }); } } } }); // 3 saniye sonra yok olma tetikleyici box._fireTimeout = LK.setTimeout(function () { if (!box.isDelivered) { box.isDelivered = true; tween(box, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { box.destroy(); } }); boxes.splice(i, 1); fireBlockCount = typeof fireBlockCount === "undefined" ? 1 : fireBlockCount + 1; if (fireBlockCount % 5 === 0 && target.scaleX > 0.4) { tween(target, { scaleX: target.scaleX - 0.12, scaleY: target.scaleY - 0.12 }, { duration: 350, easing: tween.easeIn }); } } }, 3000); } // Hedefle kesişiyor mu? if (box.intersects(target)) { // Sadece sürükleniyorsa teslim et if (box.isDragging) { box.deliver(); updateScore(LK.getScore() + 1); boxes.splice(i, 1); // Yeni kutu hemen gelsin spawnBox(); // Ateşli yok olma zamanlayıcısını temizle if (box._fireTimeout) LK.clearTimeout(box._fireTimeout); } } } }; // Sürükleme işlemleri game.down = function (x, y, obj) { // Ters sıradan kutulara bak (üstteki kutu öncelikli) for (var i = boxes.length - 1; i >= 0; i--) { var box = boxes[i]; if (box.isDelivered) continue; // Kutuya tıklandı mı? var local = box.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -box.width / 2 && local.x < box.width / 2 && local.y > -box.height / 2 && local.y < box.height / 2) { dragBox = box; dragBox.isDragging = true; dragOffsetX = box.x - x; dragOffsetY = box.y - y; // Kutuya down eventini ilet if (typeof box.down === 'function') box.down(x, y, obj); break; } } }; game.move = function (x, y, obj) { if (dragBox && dragBox.isDragging && !dragBox.isDelivered) { // Kutu pozisyonunu güncelle dragBox.x = x + dragOffsetX; dragBox.y = y + dragOffsetY; } }; game.up = function (x, y, obj) { if (dragBox) { if (typeof dragBox.up === 'function') dragBox.up(x, y, obj); dragBox.isDragging = false; dragBox = null; } }; // Oyun başladığında skor ve zaman sıfırla updateScore(0); updateTimer(0);
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Kutuların sınıfı
var DraggableBox = Container.expand(function () {
var self = Container.call(this);
// Renk seçimi
var colorList = ['box_red', 'box_blue', 'box_green', 'box_yellow', 'box_purple'];
var colorId = colorList[Math.floor(Math.random() * colorList.length)];
self.colorId = colorId;
// Kutu grafiği
var box = self.attachAsset(colorId, {
anchorX: 0.5,
anchorY: 0.5
});
// Kutu sürükleniyor mu?
self.isDragging = false;
// Kutu hedefe ulaştı mı?
self.isDelivered = false;
// Kutuya dokunulduğunda
self.down = function (x, y, obj) {
if (self.isDelivered) return;
self.isDragging = true;
// Hafifçe büyüt
tween(self, {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 120,
easing: tween.easeOut
});
};
// Kutu bırakıldığında
self.up = function (x, y, obj) {
if (self.isDelivered) return;
self.isDragging = false;
// Eski boyuta dön
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 120,
easing: tween.easeOut
});
};
// Kutu sürüklenirken
self.move = function (x, y, obj) {
// Sürükleme işlemi game.move'da yönetilecek
};
// Kutu hedefe ulaştığında animasyon
self.deliver = function () {
self.isDelivered = true;
// Hedefte hafif büyütüp kaybolma animasyonu
tween(self, {
scaleX: 1.4,
scaleY: 1.4,
alpha: 0
}, {
duration: 220,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf7f7f7
});
/****
* Game Code
****/
// Kutular için farklı renklerde kutu şekilleri oluşturuluyor
// Oyun alanı boyutları
var GAME_W = 2048;
var GAME_H = 2732;
// Hedef bölgeyi ortala
var target = LK.getAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_W / 2,
y: GAME_H * 0.78 // Alt kısımda, ama ekranın dışında değil
});
game.addChild(target);
// Skor metni
var scoreTxt = new Text2('0', {
size: 120,
fill: 0x222222
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Zamanlayıcı metni
var timerTxt = new Text2('0', {
size: 70,
fill: 0x666666
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 130;
// Kutular dizisi
var boxes = [];
// Sürüklenen kutu
var dragBox = null;
// Sürükleme offseti
var dragOffsetX = 0;
var dragOffsetY = 0;
// Oyun süresi (saniye)
var elapsedTime = 0;
// Kutu oluşturma aralığı (ms)
var boxInterval = 1600;
var boxIntervalMin = 600;
var boxIntervalStep = 60;
// Son kutu oluşturma tick'i
var lastBoxTick = 0;
// Skoru güncelle
function updateScore(val) {
LK.setScore(val);
scoreTxt.setText(val);
}
// Zamanı güncelle
function updateTimer(sec) {
timerTxt.setText(sec + " sn");
}
// Yeni kutu oluştur
function spawnBox() {
var box = new DraggableBox();
// Rastgele bir konum (hedeften uzakta, üst 2/3'te)
var safeRadius = 400;
var spawnAreaY = GAME_H * 0.12 + Math.random() * (GAME_H * 0.5);
var spawnAreaX = 200 + Math.random() * (GAME_W - 400);
// Hedeften uzaksa
var dx = spawnAreaX - target.x;
var dy = spawnAreaY - target.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < safeRadius) {
// Uzaklaştır
if (dx === 0 && dy === 0) {
spawnAreaX += 300;
} else {
spawnAreaX += dx / dist * safeRadius;
spawnAreaY += dy / dist * safeRadius;
}
}
box.x = spawnAreaX;
box.y = spawnAreaY;
box.scaleX = 1;
box.scaleY = 1;
box.alpha = 1;
// Kutuyu ekle
game.addChild(box);
boxes.push(box);
}
// Oyun başladığında ilk kutuyu oluştur
spawnBox();
// Oyun tick fonksiyonu
game.update = function () {
// Zamanı güncelle
if (LK.ticks % 60 === 0) {
elapsedTime += 1;
updateTimer(elapsedTime);
// 20 saniye dolduysa oyunu bitir
if (elapsedTime >= 20) {
LK.showGameOver();
return;
}
}
// Kutu oluşturma aralığını azalt (oyun hızlanır)
if (boxInterval > boxIntervalMin && LK.ticks % 180 === 0) {
boxInterval -= boxIntervalStep;
if (boxInterval < boxIntervalMin) boxInterval = boxIntervalMin;
}
// Yeni kutu oluşturma zamanı geldiyse
if (LK.ticks - lastBoxTick > Math.floor(boxInterval / 16.67)) {
spawnBox();
lastBoxTick = LK.ticks;
}
// Kutular hedefe ulaştı mı kontrol et
for (var i = boxes.length - 1; i >= 0; i--) {
var box = boxes[i];
if (box.isDelivered) continue;
// 3 saniye içinde yok olma (ateşli animasyon)
if (!box._fireStarted) {
box._fireStarted = true;
// Ateş efekti için kutuya kırmızımsı bir tint ve titreme animasyonu
var fireTween = tween(box, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
yoyo: true,
repeat: 6,
onFinish: function onFinish() {
// 3 saniye sonunda kutu yok olsun
if (!box.isDelivered) {
box.isDelivered = true;
tween(box, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
box.destroy();
}
});
boxes.splice(i, 1);
// Blok yok olma sayacı
fireBlockCount = typeof fireBlockCount === "undefined" ? 1 : fireBlockCount + 1;
// 5 blok yok olursa hedef küçülsün
if (fireBlockCount % 5 === 0 && target.scaleX > 0.4) {
tween(target, {
scaleX: target.scaleX - 0.12,
scaleY: target.scaleY - 0.12
}, {
duration: 350,
easing: tween.easeIn
});
}
}
}
});
// 3 saniye sonra yok olma tetikleyici
box._fireTimeout = LK.setTimeout(function () {
if (!box.isDelivered) {
box.isDelivered = true;
tween(box, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
box.destroy();
}
});
boxes.splice(i, 1);
fireBlockCount = typeof fireBlockCount === "undefined" ? 1 : fireBlockCount + 1;
if (fireBlockCount % 5 === 0 && target.scaleX > 0.4) {
tween(target, {
scaleX: target.scaleX - 0.12,
scaleY: target.scaleY - 0.12
}, {
duration: 350,
easing: tween.easeIn
});
}
}
}, 3000);
}
// Hedefle kesişiyor mu?
if (box.intersects(target)) {
// Sadece sürükleniyorsa teslim et
if (box.isDragging) {
box.deliver();
updateScore(LK.getScore() + 1);
boxes.splice(i, 1);
// Yeni kutu hemen gelsin
spawnBox();
// Ateşli yok olma zamanlayıcısını temizle
if (box._fireTimeout) LK.clearTimeout(box._fireTimeout);
}
}
}
};
// Sürükleme işlemleri
game.down = function (x, y, obj) {
// Ters sıradan kutulara bak (üstteki kutu öncelikli)
for (var i = boxes.length - 1; i >= 0; i--) {
var box = boxes[i];
if (box.isDelivered) continue;
// Kutuya tıklandı mı?
var local = box.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -box.width / 2 && local.x < box.width / 2 && local.y > -box.height / 2 && local.y < box.height / 2) {
dragBox = box;
dragBox.isDragging = true;
dragOffsetX = box.x - x;
dragOffsetY = box.y - y;
// Kutuya down eventini ilet
if (typeof box.down === 'function') box.down(x, y, obj);
break;
}
}
};
game.move = function (x, y, obj) {
if (dragBox && dragBox.isDragging && !dragBox.isDelivered) {
// Kutu pozisyonunu güncelle
dragBox.x = x + dragOffsetX;
dragBox.y = y + dragOffsetY;
}
};
game.up = function (x, y, obj) {
if (dragBox) {
if (typeof dragBox.up === 'function') dragBox.up(x, y, obj);
dragBox.isDragging = false;
dragBox = null;
}
};
// Oyun başladığında skor ve zaman sıfırla
updateScore(0);
updateTimer(0);