User prompt
Oyuncuların kafasının üzerinde resimler var. Onları kaldır. Onların yerine can health bar'ı ekle ve o beşer tane canları olsun.
User prompt
Oyuncuların kafalarının üstündeki barlar için bir aset aç ve onlara yeni resim ekleyebileyim.
User prompt
başlasın. Dövüşçüler birbirinden uzakta başlasın dövüşe.
User prompt
Cam barlarını arka plan resminin üst kısmına büyük olarak ekle ve her bir oyuncunun 10 tane canı olsun.
User prompt
Sağdakine bir bot oynasın. Aynı anda iki kişi oynadığında ise onlar karşılıklı yüzleşsin.
User prompt
Oyunculara can barı ekler misin? Bir de oyuncuların can barı bizim görebileceğimiz şekilde olsun ve oyuncular birbirine yaklaşıp dövüşebilsinler.
User prompt
jump
User prompt
Cam barını büyütelim her iki oyuncuda da ve biraz daha oyuncular birbirine yaklaşarak vuruşsunlar. Vurduklarında sesler çıksın.
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'self.body = self.attachAsset(self.assetId, {' Line Number: 28
Code edit (1 edits merged)
Please save this source code
User prompt
Dragon Arena: Çin Dövüşü
Initial prompt
bir dövüş oyunu istiyorum arkası çin temalı olacak ve dövüşe başlarken Fight yazsın istiyorum.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Dövüşçü sınıfı
var Fighter = Container.expand(function () {
var self = Container.call(this);
// Özellikler
self.hp = 100;
self.isAttacking = false;
self.isDefending = false;
self.isPlayer = false; // Oyuncu mu, rakip mi
self.attackCooldown = 0;
self.defendCooldown = 0;
// Görsel
self.body = self.attachAsset(self.assetId, {
anchorX: 0.5,
anchorY: 1
});
// Can göstergesi
self.hpBarBg = self.addChild(LK.getAsset('arenaFloor', {
width: 160,
height: 18,
color: 0x333333,
anchorX: 0.5,
anchorY: 0.5,
y: -350
}));
self.hpBar = self.addChild(LK.getAsset('arenaFloor', {
width: 150,
height: 12,
color: self.assetId === 'fighter1' ? 0xff4444 : 0x44aaff,
anchorX: 0.5,
anchorY: 0.5,
y: -350
}));
// Saldırı animasyonu
self.attackAnim = function () {
if (self.isAttacking || self.attackCooldown > 0) return;
self.isAttacking = true;
self.attackCooldown = 30; // 0.5 sn
var oldX = self.x;
var targetX = self.x + (self.isPlayer ? 80 : -80);
tween(self, {
x: targetX
}, {
duration: 120,
easing: tween.cubicOut,
onFinish: function onFinish() {
tween(self, {
x: oldX
}, {
duration: 120,
easing: tween.cubicIn,
onFinish: function onFinish() {
self.isAttacking = false;
}
});
}
});
};
// Savunma animasyonu
self.defendAnim = function () {
if (self.isDefending || self.defendCooldown > 0) return;
self.isDefending = true;
self.defendCooldown = 40; // 0.66 sn
tween(self.body, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 100,
easing: tween.easeIn,
onFinish: function onFinish() {
tween(self.body, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isDefending = false;
}
});
}
});
};
// Hasar alma
self.takeHit = function (amount) {
if (self.isDefending) {
amount = Math.floor(amount / 2);
}
self.hp -= amount;
if (self.hp < 0) self.hp = 0;
self.updateHpBar();
LK.effects.flashObject(self.body, 0xffffff, 120);
};
// Can barını güncelle
self.updateHpBar = function () {
self.hpBar.width = 150 * (self.hp / 100);
};
// Her frame güncelle
self.update = function () {
if (self.attackCooldown > 0) self.attackCooldown--;
if (self.defendCooldown > 0) self.defendCooldown--;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Dövüşçü 1: Kırmızı kutu, Dövüşçü 2: Mavi kutu, Arenanın zemini: Geniş sarı kutu, "Fight" için: büyük metin
// Arena zemini ve dekor
var arenaFloor = LK.getAsset('arenaFloor', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
y: 2200
});
game.addChild(arenaFloor);
// Ejderha dekorları (üstte ve altta)
var dragonTop = LK.getAsset('dragonDeco', {
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 80
});
var dragonBottom = LK.getAsset('dragonDeco', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
y: 2732 - 80
});
game.addChild(dragonTop);
game.addChild(dragonBottom);
// Dövüşçüler
var fighter1 = new Fighter();
fighter1.assetId = 'fighter1';
fighter1.isPlayer = true;
fighter1.x = 2048 / 2 - 400;
fighter1.y = 2200;
game.addChild(fighter1);
var fighter2 = new Fighter();
fighter2.assetId = 'fighter2';
fighter2.isPlayer = false;
fighter2.x = 2048 / 2 + 400;
fighter2.y = 2200;
game.addChild(fighter2);
// "Fight" yazısı
var fightText = new Text2('FIGHT', {
size: 260,
fill: 0xFFCC00,
font: "Impact, 'Arial Black', Tahoma"
});
fightText.anchor.set(0.5, 0.5);
fightText.x = 2048 / 2;
fightText.y = 900;
game.addChild(fightText);
// "Fight" yazısını fade out ile kaldır
tween(fightText, {
alpha: 0
}, {
duration: 1200,
easing: tween.cubicIn,
onFinish: function onFinish() {
fightText.destroy();
}
});
// Skor ve can göstergesi (GUI)
var playerHpTxt = new Text2('Sen: 100', {
size: 70,
fill: "#fff"
});
playerHpTxt.anchor.set(0, 0);
LK.gui.top.addChild(playerHpTxt);
var enemyHpTxt = new Text2('Rakip: 100', {
size: 70,
fill: "#fff"
});
enemyHpTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(enemyHpTxt);
// Oyun durumu
var gameState = 'playing'; // 'playing', 'over'
var dragFighter = null;
var dragOffsetX = 0;
var dragOffsetY = 0;
// Dokunma/sürükleme ile oyuncu karakterini hareket ettir
game.down = function (x, y, obj) {
// Sadece oyuncu karakterine dokunulduysa sürükle
var local = fighter1.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -fighter1.body.width / 2 && local.x < fighter1.body.width / 2 && local.y > -fighter1.body.height && local.y < 0) {
dragFighter = fighter1;
dragOffsetX = fighter1.x - x;
dragOffsetY = fighter1.y - y;
}
};
game.move = function (x, y, obj) {
if (dragFighter && gameState === 'playing') {
// Sadece yatay eksende hareket etsin, arenadan çıkmasın
var minX = 2048 / 2 - 700;
var maxX = 2048 / 2 - 100;
var newX = x + dragOffsetX;
if (newX < minX) newX = minX;
if (newX > maxX) newX = maxX;
dragFighter.x = newX;
}
};
game.up = function (x, y, obj) {
dragFighter = null;
};
// Oyuncu saldırı ve savunma: ekrana çift dokunma saldırı, uzun basma savunma
var lastTap = 0;
var tapTimeout = null;
var longPressTimeout = null;
game.down = function (x, y, obj) {
// Sürükleme için
var local = fighter1.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -fighter1.body.width / 2 && local.x < fighter1.body.width / 2 && local.y > -fighter1.body.height && local.y < 0) {
dragFighter = fighter1;
dragOffsetX = fighter1.x - x;
dragOffsetY = fighter1.y - y;
}
// Saldırı: çift dokunma
var now = Date.now();
if (now - lastTap < 350) {
// Çift dokunma: saldırı
fighter1.attackAnim();
tapTimeout && LK.clearTimeout(tapTimeout);
} else {
// Uzun basma: savunma
longPressTimeout = LK.setTimeout(function () {
fighter1.defendAnim();
}, 400);
tapTimeout = LK.setTimeout(function () {}, 350);
}
lastTap = now;
};
game.up = function (x, y, obj) {
dragFighter = null;
if (longPressTimeout) {
LK.clearTimeout(longPressTimeout);
longPressTimeout = null;
}
};
// Rakip AI: basit saldırı/savunma döngüsü
var aiTimer = 0;
var aiState = 'idle'; // 'idle', 'attack', 'defend'
function aiUpdate() {
if (gameState !== 'playing') return;
aiTimer--;
if (aiTimer <= 0) {
var r = Math.random();
if (r < 0.5) {
// Saldırı
fighter2.attackAnim();
aiState = 'attack';
aiTimer = 60 + Math.floor(Math.random() * 30);
} else {
// Savunma
fighter2.defendAnim();
aiState = 'defend';
aiTimer = 80 + Math.floor(Math.random() * 40);
}
}
}
// Saldırı çarpışma kontrolü
function checkAttack() {
// Oyuncu saldırısı
if (fighter1.isAttacking && Math.abs(fighter1.x - fighter2.x) < 260) {
if (!fighter2.isDefending && fighter2.attackCooldown < 15) {
fighter2.takeHit(18);
} else if (fighter2.isDefending && fighter2.attackCooldown < 15) {
fighter2.takeHit(9);
}
}
// Rakip saldırısı
if (fighter2.isAttacking && Math.abs(fighter1.x - fighter2.x) < 260) {
if (!fighter1.isDefending && fighter1.attackCooldown < 15) {
fighter1.takeHit(18);
} else if (fighter1.isDefending && fighter1.attackCooldown < 15) {
fighter1.takeHit(9);
}
}
}
// Oyun güncellemesi
game.update = function () {
if (gameState !== 'playing') return;
fighter1.update();
fighter2.update();
aiUpdate();
checkAttack();
// Can göstergelerini güncelle
playerHpTxt.setText('Sen: ' + fighter1.hp);
enemyHpTxt.setText('Rakip: ' + fighter2.hp);
// Kazananı kontrol et
if (fighter1.hp <= 0 && gameState === 'playing') {
gameState = 'over';
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (fighter2.hp <= 0 && gameState === 'playing') {
gameState = 'over';
LK.effects.flashScreen(0x00ff00, 1000);
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,323 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Dövüşçü sınıfı
+var Fighter = Container.expand(function () {
+ var self = Container.call(this);
+ // Özellikler
+ self.hp = 100;
+ self.isAttacking = false;
+ self.isDefending = false;
+ self.isPlayer = false; // Oyuncu mu, rakip mi
+ self.attackCooldown = 0;
+ self.defendCooldown = 0;
+ // Görsel
+ self.body = self.attachAsset(self.assetId, {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Can göstergesi
+ self.hpBarBg = self.addChild(LK.getAsset('arenaFloor', {
+ width: 160,
+ height: 18,
+ color: 0x333333,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -350
+ }));
+ self.hpBar = self.addChild(LK.getAsset('arenaFloor', {
+ width: 150,
+ height: 12,
+ color: self.assetId === 'fighter1' ? 0xff4444 : 0x44aaff,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -350
+ }));
+ // Saldırı animasyonu
+ self.attackAnim = function () {
+ if (self.isAttacking || self.attackCooldown > 0) return;
+ self.isAttacking = true;
+ self.attackCooldown = 30; // 0.5 sn
+ var oldX = self.x;
+ var targetX = self.x + (self.isPlayer ? 80 : -80);
+ tween(self, {
+ x: targetX
+ }, {
+ duration: 120,
+ easing: tween.cubicOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: oldX
+ }, {
+ duration: 120,
+ easing: tween.cubicIn,
+ onFinish: function onFinish() {
+ self.isAttacking = false;
+ }
+ });
+ }
+ });
+ };
+ // Savunma animasyonu
+ self.defendAnim = function () {
+ if (self.isDefending || self.defendCooldown > 0) return;
+ self.isDefending = true;
+ self.defendCooldown = 40; // 0.66 sn
+ tween(self.body, {
+ scaleX: 1.2,
+ scaleY: 0.8
+ }, {
+ duration: 100,
+ easing: tween.easeIn,
+ onFinish: function onFinish() {
+ tween(self.body, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.isDefending = false;
+ }
+ });
+ }
+ });
+ };
+ // Hasar alma
+ self.takeHit = function (amount) {
+ if (self.isDefending) {
+ amount = Math.floor(amount / 2);
+ }
+ self.hp -= amount;
+ if (self.hp < 0) self.hp = 0;
+ self.updateHpBar();
+ LK.effects.flashObject(self.body, 0xffffff, 120);
+ };
+ // Can barını güncelle
+ self.updateHpBar = function () {
+ self.hpBar.width = 150 * (self.hp / 100);
+ };
+ // Her frame güncelle
+ self.update = function () {
+ if (self.attackCooldown > 0) self.attackCooldown--;
+ if (self.defendCooldown > 0) self.defendCooldown--;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+// Dövüşçü 1: Kırmızı kutu, Dövüşçü 2: Mavi kutu, Arenanın zemini: Geniş sarı kutu, "Fight" için: büyük metin
+// Arena zemini ve dekor
+var arenaFloor = LK.getAsset('arenaFloor', {
+ anchorX: 0.5,
+ anchorY: 1,
+ x: 2048 / 2,
+ y: 2200
+});
+game.addChild(arenaFloor);
+// Ejderha dekorları (üstte ve altta)
+var dragonTop = LK.getAsset('dragonDeco', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 2048 / 2,
+ y: 80
+});
+var dragonBottom = LK.getAsset('dragonDeco', {
+ anchorX: 0.5,
+ anchorY: 1,
+ x: 2048 / 2,
+ y: 2732 - 80
+});
+game.addChild(dragonTop);
+game.addChild(dragonBottom);
+// Dövüşçüler
+var fighter1 = new Fighter();
+fighter1.assetId = 'fighter1';
+fighter1.isPlayer = true;
+fighter1.x = 2048 / 2 - 400;
+fighter1.y = 2200;
+game.addChild(fighter1);
+var fighter2 = new Fighter();
+fighter2.assetId = 'fighter2';
+fighter2.isPlayer = false;
+fighter2.x = 2048 / 2 + 400;
+fighter2.y = 2200;
+game.addChild(fighter2);
+// "Fight" yazısı
+var fightText = new Text2('FIGHT', {
+ size: 260,
+ fill: 0xFFCC00,
+ font: "Impact, 'Arial Black', Tahoma"
+});
+fightText.anchor.set(0.5, 0.5);
+fightText.x = 2048 / 2;
+fightText.y = 900;
+game.addChild(fightText);
+// "Fight" yazısını fade out ile kaldır
+tween(fightText, {
+ alpha: 0
+}, {
+ duration: 1200,
+ easing: tween.cubicIn,
+ onFinish: function onFinish() {
+ fightText.destroy();
+ }
+});
+// Skor ve can göstergesi (GUI)
+var playerHpTxt = new Text2('Sen: 100', {
+ size: 70,
+ fill: "#fff"
+});
+playerHpTxt.anchor.set(0, 0);
+LK.gui.top.addChild(playerHpTxt);
+var enemyHpTxt = new Text2('Rakip: 100', {
+ size: 70,
+ fill: "#fff"
+});
+enemyHpTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(enemyHpTxt);
+// Oyun durumu
+var gameState = 'playing'; // 'playing', 'over'
+var dragFighter = null;
+var dragOffsetX = 0;
+var dragOffsetY = 0;
+// Dokunma/sürükleme ile oyuncu karakterini hareket ettir
+game.down = function (x, y, obj) {
+ // Sadece oyuncu karakterine dokunulduysa sürükle
+ var local = fighter1.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (local.x > -fighter1.body.width / 2 && local.x < fighter1.body.width / 2 && local.y > -fighter1.body.height && local.y < 0) {
+ dragFighter = fighter1;
+ dragOffsetX = fighter1.x - x;
+ dragOffsetY = fighter1.y - y;
+ }
+};
+game.move = function (x, y, obj) {
+ if (dragFighter && gameState === 'playing') {
+ // Sadece yatay eksende hareket etsin, arenadan çıkmasın
+ var minX = 2048 / 2 - 700;
+ var maxX = 2048 / 2 - 100;
+ var newX = x + dragOffsetX;
+ if (newX < minX) newX = minX;
+ if (newX > maxX) newX = maxX;
+ dragFighter.x = newX;
+ }
+};
+game.up = function (x, y, obj) {
+ dragFighter = null;
+};
+// Oyuncu saldırı ve savunma: ekrana çift dokunma saldırı, uzun basma savunma
+var lastTap = 0;
+var tapTimeout = null;
+var longPressTimeout = null;
+game.down = function (x, y, obj) {
+ // Sürükleme için
+ var local = fighter1.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (local.x > -fighter1.body.width / 2 && local.x < fighter1.body.width / 2 && local.y > -fighter1.body.height && local.y < 0) {
+ dragFighter = fighter1;
+ dragOffsetX = fighter1.x - x;
+ dragOffsetY = fighter1.y - y;
+ }
+ // Saldırı: çift dokunma
+ var now = Date.now();
+ if (now - lastTap < 350) {
+ // Çift dokunma: saldırı
+ fighter1.attackAnim();
+ tapTimeout && LK.clearTimeout(tapTimeout);
+ } else {
+ // Uzun basma: savunma
+ longPressTimeout = LK.setTimeout(function () {
+ fighter1.defendAnim();
+ }, 400);
+ tapTimeout = LK.setTimeout(function () {}, 350);
+ }
+ lastTap = now;
+};
+game.up = function (x, y, obj) {
+ dragFighter = null;
+ if (longPressTimeout) {
+ LK.clearTimeout(longPressTimeout);
+ longPressTimeout = null;
+ }
+};
+// Rakip AI: basit saldırı/savunma döngüsü
+var aiTimer = 0;
+var aiState = 'idle'; // 'idle', 'attack', 'defend'
+function aiUpdate() {
+ if (gameState !== 'playing') return;
+ aiTimer--;
+ if (aiTimer <= 0) {
+ var r = Math.random();
+ if (r < 0.5) {
+ // Saldırı
+ fighter2.attackAnim();
+ aiState = 'attack';
+ aiTimer = 60 + Math.floor(Math.random() * 30);
+ } else {
+ // Savunma
+ fighter2.defendAnim();
+ aiState = 'defend';
+ aiTimer = 80 + Math.floor(Math.random() * 40);
+ }
+ }
+}
+// Saldırı çarpışma kontrolü
+function checkAttack() {
+ // Oyuncu saldırısı
+ if (fighter1.isAttacking && Math.abs(fighter1.x - fighter2.x) < 260) {
+ if (!fighter2.isDefending && fighter2.attackCooldown < 15) {
+ fighter2.takeHit(18);
+ } else if (fighter2.isDefending && fighter2.attackCooldown < 15) {
+ fighter2.takeHit(9);
+ }
+ }
+ // Rakip saldırısı
+ if (fighter2.isAttacking && Math.abs(fighter1.x - fighter2.x) < 260) {
+ if (!fighter1.isDefending && fighter1.attackCooldown < 15) {
+ fighter1.takeHit(18);
+ } else if (fighter1.isDefending && fighter1.attackCooldown < 15) {
+ fighter1.takeHit(9);
+ }
+ }
+}
+// Oyun güncellemesi
+game.update = function () {
+ if (gameState !== 'playing') return;
+ fighter1.update();
+ fighter2.update();
+ aiUpdate();
+ checkAttack();
+ // Can göstergelerini güncelle
+ playerHpTxt.setText('Sen: ' + fighter1.hp);
+ enemyHpTxt.setText('Rakip: ' + fighter2.hp);
+ // Kazananı kontrol et
+ if (fighter1.hp <= 0 && gameState === 'playing') {
+ gameState = 'over';
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ if (fighter2.hp <= 0 && gameState === 'playing') {
+ gameState = 'over';
+ LK.effects.flashScreen(0x00ff00, 1000);
+ LK.showYouWin();
+ }
+};
\ No newline at end of file