/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Sayı balonu sınıfı
var NumberBubble = Container.expand(function () {
var self = Container.call(this);
// Varsayılan olarak mavi balon
var bubble = self.attachAsset('numberBubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.bubble = bubble;
// Sayı metni
var numberText = new Text2('0', {
size: 140,
fill: 0xFFFFFF
});
numberText.anchor.set(0.5, 0.5);
self.addChild(numberText);
self.numberText = numberText;
// Balonun gösterdiği sayı
self.value = 0;
// Balonun doğru/yanlış animasyonu
self.flash = function (type) {
// type: 'correct' | 'wrong'
var color = 0x3a8dde;
if (type === 'correct') color = 0x44de83;
if (type === 'wrong') color = 0xde3a3a;
tween(self.bubble, {
tint: color
}, {
duration: 120,
easing: tween.linear,
onFinish: function onFinish() {
tween(self.bubble, {
tint: 0x3a8dde
}, {
duration: 200,
easing: tween.linear
});
}
});
};
// Balonun değerini ayarla
self.setValue = function (val) {
self.value = val;
self.numberText.setText(val + '');
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c24
});
/****
* Game Code
****/
// Oyun değişkenleri
// Sayı balonu için daire şekli
// Yanlış seçim için kırmızı balon
// Doğru seçim için yeşil balon
// Animasyonlar için tween eklentisi
var currentBubble = null;
var score = 0;
var scoreTxt = null;
var timerTxt = null;
var roundTimeout = null;
var roundDuration = 2000; // ms, ilk turda 2 saniye
var minRoundDuration = 800; // ms, minimum hız
var roundDecrease = 80; // Her doğru için ms azalır
var isGameActive = true;
var lastNumber = null;
// Renk döngüsü: sarı, turuncu, kırmızı, pembe, mor, koyu mavi, açık mavi
var bubbleColors = [0xFFE066,
// sarı
0xFFA500,
// turuncu
0xFF3B3B,
// kırmızı
0xFF7EB9,
// pembe
0xA259E6,
// mor
0x2D3A8C,
// koyu mavi
0x3A8DDE // açık mavi
];
var bubbleColorIndex = 0;
// Skor metni
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Zamanlayıcı metni
timerTxt = new Text2('', {
size: 60,
fill: 0xFFE066
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 130;
// Yeni sayı balonu oluştur
function spawnNumberBubble() {
// Önceki balonu kaldır
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
// Yeni sayı: 1'den başlayarak 1'er 1'er artar
var newNumber = 1;
if (lastNumber !== null) {
newNumber = lastNumber + 1;
}
lastNumber = newNumber;
// Balonu oluştur
var bubble = new NumberBubble();
bubble.setValue(newNumber);
// Balonun rengini ayarla ve döngüyü ilerlet
bubble.bubble.tint = bubbleColors[bubbleColorIndex];
bubbleColorIndex = (bubbleColorIndex + 1) % bubbleColors.length;
// Rastgele konum (balonun tamamı ekranda kalacak şekilde)
var margin = 200;
var bx = margin + Math.random() * (2048 - 2 * margin);
var by = 350 + Math.random() * (2732 - 350 - margin);
bubble.x = bx;
bubble.y = by;
// Balonu ekle
game.addChild(bubble);
currentBubble = bubble;
// Balona dokunma olayı
bubble.down = function (x, y, obj) {
if (!isGameActive) return;
// Doğru balona dokunuldu
handleCorrect();
};
// Zamanlayıcı başlat
startRoundTimer();
}
// Tur zamanlayıcısı
function startRoundTimer() {
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
var startTime = Date.now();
var duration = roundDuration;
updateTimerText(duration);
// Zamanlayıcıyı güncelle
function updateTimer() {
if (!isGameActive) return;
var elapsed = Date.now() - startTime;
var left = duration - elapsed;
if (left <= 0) {
timerTxt.setText('0.0');
handleTimeout();
} else {
updateTimerText(left);
roundTimeout = LK.setTimeout(updateTimer, 60);
}
}
roundTimeout = LK.setTimeout(updateTimer, 60);
}
// Zamanlayıcı metnini güncelle
function updateTimerText(ms) {
var sec = Math.max(0, ms / 1000);
timerTxt.setText(sec.toFixed(1));
}
// Doğru balona dokunulduğunda
function handleCorrect() {
if (!isGameActive) return;
isGameActive = false;
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
// Balonu yeşil yap, animasyon
if (currentBubble) currentBubble.flash('correct');
// Skoru artır
score += 1;
scoreTxt.setText(score + '');
// Zorluk artır: süreyi azalt
roundDuration = Math.max(minRoundDuration, roundDuration - roundDecrease);
// Kısa bekle, sonra yeni balon
LK.setTimeout(function () {
isGameActive = true;
spawnNumberBubble();
}, 180);
}
// Zaman aşımı olursa
function handleTimeout() {
if (!isGameActive) return;
isGameActive = false;
// Balonu kırmızı yap, animasyon
if (currentBubble) currentBubble.flash('wrong');
// Ekranı kırmızıya flashla
LK.effects.flashScreen(0xde3a3a, 600);
// Oyun bitti
LK.setTimeout(function () {
LK.showGameOver();
}, 600);
}
// Oyun başlat
function startGame() {
score = 0;
scoreTxt.setText('0');
roundDuration = 2000;
isGameActive = true;
lastNumber = null;
bubbleColorIndex = 0;
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
spawnNumberBubble();
}
startGame();
// Oyun bittiğinde cleanup (LK.showGameOver çağrıldığında otomatik resetlenir)
game.destroy = function () {
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
};
// Ekrana yanlışlıkla dokunulursa (balon dışında), oyun bitmesin diye hiçbir şey yapma
game.down = function (x, y, obj) {
// Sadece balonun down'u çalışsın
};
// Sürükleme, hareket, up olayları gerekmiyor
game.move = function (x, y, obj) {};
game.up = function (x, y, obj) {};
// Oyun update fonksiyonu (gerekli değil ama boş bırakıyoruz)
game.update = function () {}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Sayı balonu sınıfı
var NumberBubble = Container.expand(function () {
var self = Container.call(this);
// Varsayılan olarak mavi balon
var bubble = self.attachAsset('numberBubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.bubble = bubble;
// Sayı metni
var numberText = new Text2('0', {
size: 140,
fill: 0xFFFFFF
});
numberText.anchor.set(0.5, 0.5);
self.addChild(numberText);
self.numberText = numberText;
// Balonun gösterdiği sayı
self.value = 0;
// Balonun doğru/yanlış animasyonu
self.flash = function (type) {
// type: 'correct' | 'wrong'
var color = 0x3a8dde;
if (type === 'correct') color = 0x44de83;
if (type === 'wrong') color = 0xde3a3a;
tween(self.bubble, {
tint: color
}, {
duration: 120,
easing: tween.linear,
onFinish: function onFinish() {
tween(self.bubble, {
tint: 0x3a8dde
}, {
duration: 200,
easing: tween.linear
});
}
});
};
// Balonun değerini ayarla
self.setValue = function (val) {
self.value = val;
self.numberText.setText(val + '');
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c24
});
/****
* Game Code
****/
// Oyun değişkenleri
// Sayı balonu için daire şekli
// Yanlış seçim için kırmızı balon
// Doğru seçim için yeşil balon
// Animasyonlar için tween eklentisi
var currentBubble = null;
var score = 0;
var scoreTxt = null;
var timerTxt = null;
var roundTimeout = null;
var roundDuration = 2000; // ms, ilk turda 2 saniye
var minRoundDuration = 800; // ms, minimum hız
var roundDecrease = 80; // Her doğru için ms azalır
var isGameActive = true;
var lastNumber = null;
// Renk döngüsü: sarı, turuncu, kırmızı, pembe, mor, koyu mavi, açık mavi
var bubbleColors = [0xFFE066,
// sarı
0xFFA500,
// turuncu
0xFF3B3B,
// kırmızı
0xFF7EB9,
// pembe
0xA259E6,
// mor
0x2D3A8C,
// koyu mavi
0x3A8DDE // açık mavi
];
var bubbleColorIndex = 0;
// Skor metni
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Zamanlayıcı metni
timerTxt = new Text2('', {
size: 60,
fill: 0xFFE066
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 130;
// Yeni sayı balonu oluştur
function spawnNumberBubble() {
// Önceki balonu kaldır
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
// Yeni sayı: 1'den başlayarak 1'er 1'er artar
var newNumber = 1;
if (lastNumber !== null) {
newNumber = lastNumber + 1;
}
lastNumber = newNumber;
// Balonu oluştur
var bubble = new NumberBubble();
bubble.setValue(newNumber);
// Balonun rengini ayarla ve döngüyü ilerlet
bubble.bubble.tint = bubbleColors[bubbleColorIndex];
bubbleColorIndex = (bubbleColorIndex + 1) % bubbleColors.length;
// Rastgele konum (balonun tamamı ekranda kalacak şekilde)
var margin = 200;
var bx = margin + Math.random() * (2048 - 2 * margin);
var by = 350 + Math.random() * (2732 - 350 - margin);
bubble.x = bx;
bubble.y = by;
// Balonu ekle
game.addChild(bubble);
currentBubble = bubble;
// Balona dokunma olayı
bubble.down = function (x, y, obj) {
if (!isGameActive) return;
// Doğru balona dokunuldu
handleCorrect();
};
// Zamanlayıcı başlat
startRoundTimer();
}
// Tur zamanlayıcısı
function startRoundTimer() {
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
var startTime = Date.now();
var duration = roundDuration;
updateTimerText(duration);
// Zamanlayıcıyı güncelle
function updateTimer() {
if (!isGameActive) return;
var elapsed = Date.now() - startTime;
var left = duration - elapsed;
if (left <= 0) {
timerTxt.setText('0.0');
handleTimeout();
} else {
updateTimerText(left);
roundTimeout = LK.setTimeout(updateTimer, 60);
}
}
roundTimeout = LK.setTimeout(updateTimer, 60);
}
// Zamanlayıcı metnini güncelle
function updateTimerText(ms) {
var sec = Math.max(0, ms / 1000);
timerTxt.setText(sec.toFixed(1));
}
// Doğru balona dokunulduğunda
function handleCorrect() {
if (!isGameActive) return;
isGameActive = false;
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
// Balonu yeşil yap, animasyon
if (currentBubble) currentBubble.flash('correct');
// Skoru artır
score += 1;
scoreTxt.setText(score + '');
// Zorluk artır: süreyi azalt
roundDuration = Math.max(minRoundDuration, roundDuration - roundDecrease);
// Kısa bekle, sonra yeni balon
LK.setTimeout(function () {
isGameActive = true;
spawnNumberBubble();
}, 180);
}
// Zaman aşımı olursa
function handleTimeout() {
if (!isGameActive) return;
isGameActive = false;
// Balonu kırmızı yap, animasyon
if (currentBubble) currentBubble.flash('wrong');
// Ekranı kırmızıya flashla
LK.effects.flashScreen(0xde3a3a, 600);
// Oyun bitti
LK.setTimeout(function () {
LK.showGameOver();
}, 600);
}
// Oyun başlat
function startGame() {
score = 0;
scoreTxt.setText('0');
roundDuration = 2000;
isGameActive = true;
lastNumber = null;
bubbleColorIndex = 0;
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
spawnNumberBubble();
}
startGame();
// Oyun bittiğinde cleanup (LK.showGameOver çağrıldığında otomatik resetlenir)
game.destroy = function () {
if (roundTimeout) {
LK.clearTimeout(roundTimeout);
roundTimeout = null;
}
if (currentBubble) {
currentBubble.destroy();
currentBubble = null;
}
};
// Ekrana yanlışlıkla dokunulursa (balon dışında), oyun bitmesin diye hiçbir şey yapma
game.down = function (x, y, obj) {
// Sadece balonun down'u çalışsın
};
// Sürükleme, hareket, up olayları gerekmiyor
game.move = function (x, y, obj) {};
game.up = function (x, y, obj) {};
// Oyun update fonksiyonu (gerekli değil ama boş bırakıyoruz)
game.update = function () {};