/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Oyun kutusu sınıfı
var GameBox = Container.expand(function () {
var self = Container.call(this);
// Kutunun tipi ve puan değeri
self.boxType = 'normal'; // 'normal' veya 'bonus'
self.points = 1;
self.bonusTime = 0;
// Renk ve boyut rastgele seçilecek
var boxTypes = [{
id: 'box_red',
points: 1
}, {
id: 'box_green',
points: 1
}, {
id: 'box_blue',
points: 1
}, {
id: 'box_yellow',
points: 1
}, {
id: 'box_purple',
points: 1
}];
// %15 ihtimalle bonus kutu
if (Math.random() < 0.15) {
self.boxType = 'bonus';
self.points = 3;
self.bonusTime = 2; // saniye
var assetId = 'box_bonus';
} else {
var t = boxTypes[Math.floor(Math.random() * boxTypes.length)];
self.points = t.points;
var assetId = t.id;
}
// Kutunun grafiğini ekle
var box = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Dokunma olayı
self.down = function (x, y, obj) {
// Animasyon: kutu küçülerek kaybolsun
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 180,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
// Kutu kaybolduktan hemen sonra yeni kutu spawn et
if (isGameActive) spawnBox();
}
});
// Puanı artır
LK.setScore(LK.getScore() + self.points);
scoreTxt.setText(LK.getScore());
// Bonus kutu ise süre ekle
if (self.boxType === 'bonus') {
timeLeft += self.bonusTime;
if (timeLeft > maxTime) timeLeft = maxTime;
updateTimerText();
LK.getSound('bonus').play();
// Kısa bir efekt: kutu sarı renge tintlensin
tween(box, {
tint: 0xffff00
}, {
duration: 120,
onFinish: function onFinish() {
tween(box, {
tint: 0xff9500
}, {
duration: 120
});
}
});
} else {
LK.getSound('pop').play();
}
// Kutuyu kutular listesinden çıkar
for (var i = boxes.length - 1; i >= 0; i--) {
if (boxes[i] === self) {
boxes.splice(i, 1);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// bonus kutu
// Kutular için farklı renk ve boyutlarda şekiller tanımlanacak
// Oyun alanı boyutları
var GAME_W = 2048;
var GAME_H = 2732;
// Puan ve zaman değişkenleri
var scoreTxt;
var timerTxt;
var timeLeft = 30; // saniye
var maxTime = 30;
var timerInterval;
var boxes = [];
var isGameActive = false;
// Puan göstergesi
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Zaman göstergesi
timerTxt = new Text2('30', {
size: 90,
fill: 0xFFD700
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 120;
// Timer güncelleme fonksiyonu
function updateTimerText() {
timerTxt.setText(Math.ceil(timeLeft));
}
// Yeni kutu oluşturma fonksiyonu
function spawnBox() {
// Rastgele konum (kutu boyutunu dikkate al)
var box = new GameBox();
var margin = 160;
var w = 220,
h = 220;
if (box.children.length > 0) {
w = box.children[0].width;
h = box.children[0].height;
}
// Oyun alanı içinde, üstteki 200px ve alttaki 200px'e kutu koyma
var minX = margin + w / 2;
var maxX = GAME_W - margin - w / 2;
var minY = 200 + h / 2;
var maxY = GAME_H - 200 - h / 2;
box.x = minX + Math.random() * (maxX - minX);
box.y = minY + Math.random() * (maxY - minY);
// Animasyon: kutu büyüyerek gelsin
box.scaleX = 0.2;
box.scaleY = 0.2;
box.alpha = 0.7;
tween(box, {
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 180,
easing: tween.easeOut
});
boxes.push(box);
game.addChild(box);
}
// Oyun başlatma fonksiyonu
function startGame() {
LK.setScore(0);
scoreTxt.setText(0);
timeLeft = maxTime;
updateTimerText();
isGameActive = true;
// Önceki kutuları temizle
for (var i = boxes.length - 1; i >= 0; i--) {
boxes[i].destroy();
boxes.splice(i, 1);
}
// İlk kutuları oluştur
for (var i = 0; i < 3; i++) {
spawnBox();
}
// Timer başlat
if (timerInterval) LK.clearInterval(timerInterval);
timerInterval = LK.setInterval(function () {
if (!isGameActive) return;
timeLeft -= 0.1;
if (timeLeft < 0) timeLeft = 0;
updateTimerText();
if (timeLeft <= 0) {
endGame();
}
}, 100);
// Kutu oluşturma aralığı
if (boxSpawnTimeout) LK.clearTimeout(boxSpawnTimeout);
scheduleNextBox();
}
// Kutu oluşturma zamanlayıcısı
var boxSpawnTimeout;
function scheduleNextBox() {
if (!isGameActive) return;
// 0.5-1.2 sn arası rastgele aralık
var delay = 500 + Math.random() * 700;
boxSpawnTimeout = LK.setTimeout(function () {
if (!isGameActive) return;
// Ekranda 5'ten az kutu varsa yeni kutu oluştur
if (boxes.length < 5) {
spawnBox();
}
scheduleNextBox();
}, delay);
}
// Oyun bitişi
function endGame() {
isGameActive = false;
if (timerInterval) LK.clearInterval(timerInterval);
if (boxSpawnTimeout) LK.clearTimeout(boxSpawnTimeout);
// Kalan kutuları sil
for (var i = boxes.length - 1; i >= 0; i--) {
boxes[i].destroy();
boxes.splice(i, 1);
}
// Oyun bitti popup'ı göster
LK.showGameOver();
}
// Oyun alanına dokunma: kutuya dokunulmadıysa yeni kutu oluştur
game.down = function (x, y, obj) {
if (!isGameActive) return;
// Eğer kutuya dokunulmadıysa, ekrana dokunulduğunda yeni kutu oluştur
// (Kutuya dokunma olayı kutu üzerinde tetiklenir, burada sadece boş alana dokunma var)
var touchedBox = false;
for (var i = 0; i < boxes.length; i++) {
var box = boxes[i];
// Kutuya dokunulduysa, dokunma kutu üzerinde ise
if (box.containsPoint && box.containsPoint({
x: x,
y: y
})) {
touchedBox = true;
break;
}
}
if (!touchedBox) {
spawnBox();
}
};
// Oyun güncelleme fonksiyonu
game.update = function () {
// Oyun aktif değilse bir şey yapma
if (!isGameActive) return;
// Kutuların süresi dolduysa sil
for (var i = boxes.length - 1; i >= 0; i--) {
var box = boxes[i];
// 2.5 sn ekranda kalan kutular kaybolsun
if (!box.spawnTick) box.spawnTick = LK.ticks;
if (LK.ticks - box.spawnTick > 150) {
// Animasyonla kaybolsun
tween(box, {
alpha: 0
}, {
duration: 180,
onFinish: function onFinish() {
box.destroy();
}
});
boxes.splice(i, 1);
}
}
};
// Oyun başladığında otomatik başlat
startGame();
// Oyun bittiğinde tekrar başlatmak için LK otomatik olarak Game'i resetler, bu nedenle ekstra kod gerekmez. /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Oyun kutusu sınıfı
var GameBox = Container.expand(function () {
var self = Container.call(this);
// Kutunun tipi ve puan değeri
self.boxType = 'normal'; // 'normal' veya 'bonus'
self.points = 1;
self.bonusTime = 0;
// Renk ve boyut rastgele seçilecek
var boxTypes = [{
id: 'box_red',
points: 1
}, {
id: 'box_green',
points: 1
}, {
id: 'box_blue',
points: 1
}, {
id: 'box_yellow',
points: 1
}, {
id: 'box_purple',
points: 1
}];
// %15 ihtimalle bonus kutu
if (Math.random() < 0.15) {
self.boxType = 'bonus';
self.points = 3;
self.bonusTime = 2; // saniye
var assetId = 'box_bonus';
} else {
var t = boxTypes[Math.floor(Math.random() * boxTypes.length)];
self.points = t.points;
var assetId = t.id;
}
// Kutunun grafiğini ekle
var box = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Dokunma olayı
self.down = function (x, y, obj) {
// Animasyon: kutu küçülerek kaybolsun
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 180,
easing: tween.easeIn,
onFinish: function onFinish() {
self.destroy();
// Kutu kaybolduktan hemen sonra yeni kutu spawn et
if (isGameActive) spawnBox();
}
});
// Puanı artır
LK.setScore(LK.getScore() + self.points);
scoreTxt.setText(LK.getScore());
// Bonus kutu ise süre ekle
if (self.boxType === 'bonus') {
timeLeft += self.bonusTime;
if (timeLeft > maxTime) timeLeft = maxTime;
updateTimerText();
LK.getSound('bonus').play();
// Kısa bir efekt: kutu sarı renge tintlensin
tween(box, {
tint: 0xffff00
}, {
duration: 120,
onFinish: function onFinish() {
tween(box, {
tint: 0xff9500
}, {
duration: 120
});
}
});
} else {
LK.getSound('pop').play();
}
// Kutuyu kutular listesinden çıkar
for (var i = boxes.length - 1; i >= 0; i--) {
if (boxes[i] === self) {
boxes.splice(i, 1);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// bonus kutu
// Kutular için farklı renk ve boyutlarda şekiller tanımlanacak
// Oyun alanı boyutları
var GAME_W = 2048;
var GAME_H = 2732;
// Puan ve zaman değişkenleri
var scoreTxt;
var timerTxt;
var timeLeft = 30; // saniye
var maxTime = 30;
var timerInterval;
var boxes = [];
var isGameActive = false;
// Puan göstergesi
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Zaman göstergesi
timerTxt = new Text2('30', {
size: 90,
fill: 0xFFD700
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 120;
// Timer güncelleme fonksiyonu
function updateTimerText() {
timerTxt.setText(Math.ceil(timeLeft));
}
// Yeni kutu oluşturma fonksiyonu
function spawnBox() {
// Rastgele konum (kutu boyutunu dikkate al)
var box = new GameBox();
var margin = 160;
var w = 220,
h = 220;
if (box.children.length > 0) {
w = box.children[0].width;
h = box.children[0].height;
}
// Oyun alanı içinde, üstteki 200px ve alttaki 200px'e kutu koyma
var minX = margin + w / 2;
var maxX = GAME_W - margin - w / 2;
var minY = 200 + h / 2;
var maxY = GAME_H - 200 - h / 2;
box.x = minX + Math.random() * (maxX - minX);
box.y = minY + Math.random() * (maxY - minY);
// Animasyon: kutu büyüyerek gelsin
box.scaleX = 0.2;
box.scaleY = 0.2;
box.alpha = 0.7;
tween(box, {
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 180,
easing: tween.easeOut
});
boxes.push(box);
game.addChild(box);
}
// Oyun başlatma fonksiyonu
function startGame() {
LK.setScore(0);
scoreTxt.setText(0);
timeLeft = maxTime;
updateTimerText();
isGameActive = true;
// Önceki kutuları temizle
for (var i = boxes.length - 1; i >= 0; i--) {
boxes[i].destroy();
boxes.splice(i, 1);
}
// İlk kutuları oluştur
for (var i = 0; i < 3; i++) {
spawnBox();
}
// Timer başlat
if (timerInterval) LK.clearInterval(timerInterval);
timerInterval = LK.setInterval(function () {
if (!isGameActive) return;
timeLeft -= 0.1;
if (timeLeft < 0) timeLeft = 0;
updateTimerText();
if (timeLeft <= 0) {
endGame();
}
}, 100);
// Kutu oluşturma aralığı
if (boxSpawnTimeout) LK.clearTimeout(boxSpawnTimeout);
scheduleNextBox();
}
// Kutu oluşturma zamanlayıcısı
var boxSpawnTimeout;
function scheduleNextBox() {
if (!isGameActive) return;
// 0.5-1.2 sn arası rastgele aralık
var delay = 500 + Math.random() * 700;
boxSpawnTimeout = LK.setTimeout(function () {
if (!isGameActive) return;
// Ekranda 5'ten az kutu varsa yeni kutu oluştur
if (boxes.length < 5) {
spawnBox();
}
scheduleNextBox();
}, delay);
}
// Oyun bitişi
function endGame() {
isGameActive = false;
if (timerInterval) LK.clearInterval(timerInterval);
if (boxSpawnTimeout) LK.clearTimeout(boxSpawnTimeout);
// Kalan kutuları sil
for (var i = boxes.length - 1; i >= 0; i--) {
boxes[i].destroy();
boxes.splice(i, 1);
}
// Oyun bitti popup'ı göster
LK.showGameOver();
}
// Oyun alanına dokunma: kutuya dokunulmadıysa yeni kutu oluştur
game.down = function (x, y, obj) {
if (!isGameActive) return;
// Eğer kutuya dokunulmadıysa, ekrana dokunulduğunda yeni kutu oluştur
// (Kutuya dokunma olayı kutu üzerinde tetiklenir, burada sadece boş alana dokunma var)
var touchedBox = false;
for (var i = 0; i < boxes.length; i++) {
var box = boxes[i];
// Kutuya dokunulduysa, dokunma kutu üzerinde ise
if (box.containsPoint && box.containsPoint({
x: x,
y: y
})) {
touchedBox = true;
break;
}
}
if (!touchedBox) {
spawnBox();
}
};
// Oyun güncelleme fonksiyonu
game.update = function () {
// Oyun aktif değilse bir şey yapma
if (!isGameActive) return;
// Kutuların süresi dolduysa sil
for (var i = boxes.length - 1; i >= 0; i--) {
var box = boxes[i];
// 2.5 sn ekranda kalan kutular kaybolsun
if (!box.spawnTick) box.spawnTick = LK.ticks;
if (LK.ticks - box.spawnTick > 150) {
// Animasyonla kaybolsun
tween(box, {
alpha: 0
}, {
duration: 180,
onFinish: function onFinish() {
box.destroy();
}
});
boxes.splice(i, 1);
}
}
};
// Oyun başladığında otomatik başlat
startGame();
// Oyun bittiğinde tekrar başlatmak için LK otomatik olarak Game'i resetler, bu nedenle ekstra kod gerekmez.