/****
* Classes
****/
var Crane = Container.expand(function () {
var self = Container.call(this);
var craneGraphics = self.attachAsset('crane', {
anchorX: 0.5,
anchorY: 0.5
});
// Vinç sabit kalacağı için update fonksiyonuna gerek yok
self.update = function () {};
return self;
});
var GameContainer = Container.expand(function () {
var self = Container.call(this);
var containerGraphics = self.attachAsset('container', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.grounded = false;
self.settled = false;
self.settleTimer = 0;
self.isAttached = true;
self.intersects = function (other) {
// Daha hassas çarpışma kontrolü
return Math.abs(self.x - other.x) < 200 &&
// X ekseninde çarpışma alanı
Math.abs(self.y - other.y) < 150; // Y ekseninde çarpışma alanı
};
self.update = function () {
if (self.isAttached) {
return;
}
if (!self.grounded) {
self.velocity.y += 0.8; // Yerçekimi
self.x += self.velocity.x;
self.y += self.velocity.y;
// Çarpışma kontrolü - HER FRAME'DE kontrol et
var hitSomething = false;
var landingY = null;
// Platform ile çarpışma kontrolü
if (self.x >= platformX - 150 && self.x <= platformX + 150 && self.y >= platformY - 182.62 / 2) {
landingY = platformY - 182.62 / 2;
hitSomething = true;
console.log("Platforma çarptı");
}
// Diğer konteynerlerle çarpışma kontrolü
var highestContainer = null;
var highestY = platformY; // Başlangıç referansı
for (var i = 0; i < containers.length; i++) {
var other = containers[i];
if (other !== self && other.grounded) {
// Önce X ekseninde çakışma var mı kontrol et
if (Math.abs(self.x - other.x) < 200) {
// Sonra Y ekseninde bu konteynerin üstüne düşüp düşmediğini kontrol et
var containerTop = other.y - 182.62 / 2;
if (self.y + 182.62 / 2 >= containerTop && self.y < other.y) {
if (containerTop < highestY) {
highestY = containerTop;
highestContainer = other;
landingY = containerTop - 182.62 / 2;
hitSomething = true;
}
}
}
}
}
// Eğer bir yere çarptıysa
if (hitSomething && landingY !== null) {
self.y = landingY;
self.grounded = true;
self.velocity.y = 0;
self.velocity.x *= 0.3;
self.settleTimer = 60;
LK.getSound('stack').play();
console.log("Kutu yerleşti: x=" + self.x + ", y=" + self.y);
// Denge kontrolü
if (highestContainer && Math.abs(self.x - highestContainer.x) > 150) {
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
console.log("Denge bozuldu: x farkı=" + Math.abs(self.x - highestContainer.x));
}
}
// Ekran dışına çıkma kontrolü
if (self.y > 2732 + 182.62) {
self.destroy();
containers.splice(containers.indexOf(self), 1);
LK.showGameOver();
console.log("Ekran dışına çıktı");
}
} else {
// Yerleştikten sonraki hareket
if (self.settleTimer > 0) {
self.settleTimer--;
if (self.settleTimer <= 0) {
self.settled = true;
}
}
if (Math.abs(self.velocity.x) > 0.1) {
self.x += self.velocity.x;
self.velocity.x *= 0.95;
}
}
};
return self;
});
var Hook = Container.expand(function () {
var self = Container.call(this);
var hookGraphics = self.attachAsset('hook', {
anchorX: 0.5,
anchorY: 0.5
});
var ropeGraphics = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0
});
ropeGraphics.visible = false;
self.hasContainer = false;
self.attachedContainer = null;
self.direction = 1; // Kanca hareket yönü
self.speed = 6; // Kanca hareket hızı
self.update = function () {
// Kanca sağa-sola hareket eder
self.x += self.direction * self.speed;
// Hareket sınırları (örneğin, ekranın 200-1848 piksel arası)
if (self.x <= 200) {
self.direction = 1;
} else if (self.x >= 1848) {
self.direction = -1;
}
// İp görünümünü vinç ile kanca arasında güncelle
ropeGraphics.visible = true; // İp her zaman görünür (konteyner olmasa bile)
var ropeLength = Math.abs(self.y - crane.y); // Vinç ile kanca arasındaki mesafe
ropeGraphics.height = ropeLength;
ropeGraphics.x = crane.x - self.x; // İpin x ofseti (vinç ile kanca arası)
ropeGraphics.y = ropeLength / 2; // İpin y pozisyonu
// Konteyner bağlıysa, konteyneri kancaya göre güncelle
if (self.hasContainer && self.attachedContainer) {
self.attachedContainer.x = self.x;
self.attachedContainer.y = self.y + 80;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var containers = [];
var crane;
var hook;
var platform;
var ground;
var platformX = 2048 / 2;
var platformY = 2732 - 300;
var scoreText;
var nextContainerTimer = 0;
var gameSpeed = 1;
var maxContainers = 12; // 12 konteyner = 120 puan
var gameEnded = false;
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 50
}));
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
x: platformX,
y: platformY
}));
crane = game.addChild(new Crane());
crane.x = 2048 / 2;
crane.y = 1550;
hook = game.addChild(new Hook());
hook.x = crane.x;
hook.y = 100;
scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function createNewContainer() {
// Maksimum konteyner sayısına ulaşıldı mı kontrol et
if (containers.length >= maxContainers) {
return false;
}
var newContainer = new GameContainer();
newContainer.x = hook.x;
newContainer.y = hook.y + 80;
newContainer.isAttached = true;
containers.push(newContainer);
game.addChild(newContainer);
hook.hasContainer = true;
hook.attachedContainer = newContainer;
return true;
}
function dropContainer() {
if (hook.hasContainer && hook.attachedContainer) {
hook.attachedContainer.isAttached = false;
hook.attachedContainer.velocity.x = hook.direction * hook.speed * 0.5;
hook.attachedContainer.velocity.y = 2;
hook.hasContainer = false;
hook.attachedContainer = null;
LK.getSound('drop').play();
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
nextContainerTimer = 120;
if (LK.getScore() % 100 === 0) {
hook.speed += 0.5;
}
}
}
createNewContainer();
game.down = function (x, y, obj) {
if (!gameEnded) {
dropContainer();
}
};
game.update = function () {
if (gameEnded) {
return;
}
if (nextContainerTimer > 0) {
nextContainerTimer--;
if (nextContainerTimer <= 0 && !hook.hasContainer) {
// Yeni konteyner oluştur, eğer maksimuma ulaşmadıysak
if (!createNewContainer()) {
// Maksimum konteyner sayısına ulaşıldı, oyunu bitir
gameEnded = true;
LK.effects.flashScreen(0x00ff00, 500); // Yeşil flash - başarı
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
return;
}
}
}
for (var i = containers.length - 1; i >= 0; i--) {
var container = containers[i];
// Platform dışına çıkma kontrolü
if (container.grounded && (container.x < platformX - 250 || container.x > platformX + 250)) {
gameEnded = true;
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
break;
}
// Ekranın üstüne çıkma kontrolü (Y değeri 0'a yaklaştığında)
if (container.grounded && container.y <= 100) {
gameEnded = true;
LK.effects.flashScreen(0x00ff00, 500); // Yeşil flash - başarı
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
break;
}
}
// Alternatif bitiş koşulu - 120 puana ulaşma
if (LK.getScore() >= 120) {
gameEnded = true;
LK.effects.flashScreen(0x00ff00, 500);
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
}
}; ===================================================================
--- original.js
+++ change.js
@@ -25,51 +25,78 @@
self.settled = false;
self.settleTimer = 0;
self.isAttached = true;
self.intersects = function (other) {
- // Çarpışma mesafesini kutu boyutlarına tam uyumlu hale getir
- return Math.abs(self.x - other.x) < 100 && Math.abs(self.y - other.y) < 100;
+ // Daha hassas çarpışma kontrolü
+ return Math.abs(self.x - other.x) < 200 &&
+ // X ekseninde çarpışma alanı
+ Math.abs(self.y - other.y) < 150; // Y ekseninde çarpışma alanı
};
self.update = function () {
if (self.isAttached) {
return;
}
if (!self.grounded) {
- self.velocity.y += 0.8;
+ self.velocity.y += 0.8; // Yerçekimi
self.x += self.velocity.x;
self.y += self.velocity.y;
- if (self.y >= platformY - 50) {
- var hitSomething = false;
- // Platformla çarpışma
- if (self.x >= platformX - 250 && self.x <= platformX + 250) {
- self.y = platformY - 50; // Platformun tam üstü
- hitSomething = true;
- }
- // Diğer kutularla çarpışma
- for (var i = 0; i < containers.length; i++) {
- var other = containers[i];
- if (other !== self && other.grounded && self.intersects(other)) {
- self.y = other.y - 150; // Alttaki kutunun tam üstü
- hitSomething = true;
- break;
+ // Çarpışma kontrolü - HER FRAME'DE kontrol et
+ var hitSomething = false;
+ var landingY = null;
+ // Platform ile çarpışma kontrolü
+ if (self.x >= platformX - 150 && self.x <= platformX + 150 && self.y >= platformY - 182.62 / 2) {
+ landingY = platformY - 182.62 / 2;
+ hitSomething = true;
+ console.log("Platforma çarptı");
+ }
+ // Diğer konteynerlerle çarpışma kontrolü
+ var highestContainer = null;
+ var highestY = platformY; // Başlangıç referansı
+ for (var i = 0; i < containers.length; i++) {
+ var other = containers[i];
+ if (other !== self && other.grounded) {
+ // Önce X ekseninde çakışma var mı kontrol et
+ if (Math.abs(self.x - other.x) < 200) {
+ // Sonra Y ekseninde bu konteynerin üstüne düşüp düşmediğini kontrol et
+ var containerTop = other.y - 182.62 / 2;
+ if (self.y + 182.62 / 2 >= containerTop && self.y < other.y) {
+ if (containerTop < highestY) {
+ highestY = containerTop;
+ highestContainer = other;
+ landingY = containerTop - 182.62 / 2;
+ hitSomething = true;
+ }
+ }
}
}
- if (hitSomething) {
- self.grounded = true;
- self.velocity.y = 0;
- self.velocity.x *= 0.3;
- self.settleTimer = 60;
- LK.getSound('stack').play();
- // Hata ayıklama için konumları logla
- console.log("Kutu yerleşti: x=" + self.x + ", y=" + self.y);
+ }
+ // Eğer bir yere çarptıysa
+ if (hitSomething && landingY !== null) {
+ self.y = landingY;
+ self.grounded = true;
+ self.velocity.y = 0;
+ self.velocity.x *= 0.3;
+ self.settleTimer = 60;
+ LK.getSound('stack').play();
+ console.log("Kutu yerleşti: x=" + self.x + ", y=" + self.y);
+ // Denge kontrolü
+ if (highestContainer && Math.abs(self.x - highestContainer.x) > 150) {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 500);
+ console.log("Denge bozuldu: x farkı=" + Math.abs(self.x - highestContainer.x));
}
}
- if (self.y > 2732 + 100) {
+ // Ekran dışına çıkma kontrolü
+ if (self.y > 2732 + 182.62) {
self.destroy();
containers.splice(containers.indexOf(self), 1);
LK.showGameOver();
+ console.log("Ekran dışına çıktı");
}
} else {
+ // Yerleştikten sonraki hareket
if (self.settleTimer > 0) {
self.settleTimer--;
if (self.settleTimer <= 0) {
self.settled = true;
@@ -96,9 +123,9 @@
ropeGraphics.visible = false;
self.hasContainer = false;
self.attachedContainer = null;
self.direction = 1; // Kanca hareket yönü
- self.speed = 2; // Kanca hareket hızı
+ self.speed = 6; // Kanca hareket hızı
self.update = function () {
// Kanca sağa-sola hareket eder
self.x += self.direction * self.speed;
// Hareket sınırları (örneğin, ekranın 200-1848 piksel arası)
@@ -141,17 +168,19 @@
var platformY = 2732 - 300;
var scoreText;
var nextContainerTimer = 0;
var gameSpeed = 1;
+var maxContainers = 12; // 12 konteyner = 120 puan
+var gameEnded = false;
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 - 50
}));
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
- anchorY: -2.5,
+ anchorY: 0.5,
x: platformX,
y: platformY
}));
crane = game.addChild(new Crane());
@@ -166,54 +195,89 @@
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function createNewContainer() {
+ // Maksimum konteyner sayısına ulaşıldı mı kontrol et
+ if (containers.length >= maxContainers) {
+ return false;
+ }
var newContainer = new GameContainer();
newContainer.x = hook.x;
newContainer.y = hook.y + 80;
newContainer.isAttached = true;
containers.push(newContainer);
game.addChild(newContainer);
hook.hasContainer = true;
hook.attachedContainer = newContainer;
+ return true;
}
function dropContainer() {
if (hook.hasContainer && hook.attachedContainer) {
hook.attachedContainer.isAttached = false;
- hook.attachedContainer.velocity.x = crane.direction * crane.speed * 0.5;
+ hook.attachedContainer.velocity.x = hook.direction * hook.speed * 0.5;
hook.attachedContainer.velocity.y = 2;
hook.hasContainer = false;
hook.attachedContainer = null;
LK.getSound('drop').play();
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
nextContainerTimer = 120;
if (LK.getScore() % 100 === 0) {
- crane.speed += 0.5;
+ hook.speed += 0.5;
}
}
}
createNewContainer();
game.down = function (x, y, obj) {
- dropContainer();
+ if (!gameEnded) {
+ dropContainer();
+ }
};
game.update = function () {
+ if (gameEnded) {
+ return;
+ }
if (nextContainerTimer > 0) {
nextContainerTimer--;
if (nextContainerTimer <= 0 && !hook.hasContainer) {
- createNewContainer();
+ // Yeni konteyner oluştur, eğer maksimuma ulaşmadıysak
+ if (!createNewContainer()) {
+ // Maksimum konteyner sayısına ulaşıldı, oyunu bitir
+ gameEnded = true;
+ LK.effects.flashScreen(0x00ff00, 500); // Yeşil flash - başarı
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 500);
+ return;
+ }
}
}
for (var i = containers.length - 1; i >= 0; i--) {
var container = containers[i];
+ // Platform dışına çıkma kontrolü
if (container.grounded && (container.x < platformX - 250 || container.x > platformX + 250)) {
+ gameEnded = true;
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
break;
}
+ // Ekranın üstüne çıkma kontrolü (Y değeri 0'a yaklaştığında)
+ if (container.grounded && container.y <= 100) {
+ gameEnded = true;
+ LK.effects.flashScreen(0x00ff00, 500); // Yeşil flash - başarı
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 500);
+ break;
+ }
}
- if (LK.getScore() >= 500) {
- LK.showYouWin();
+ // Alternatif bitiş koşulu - 120 puana ulaşma
+ if (LK.getScore() >= 120) {
+ gameEnded = true;
+ LK.effects.flashScreen(0x00ff00, 500);
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 500);
}
};
\ No newline at end of file