User prompt
Reo ekle Defansif moda geçince Siyah olsun Atak moduna geçince Turuncu olsun bide Chameleon ile rastgele bir npc nin Dribbling ini şutunu veya hızını falan kopyalasın 30 saniye aralıklarla ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Stamina mız daha yavaş bitsin
User prompt
biraz daha yavaş ve 4 kere Zig zag çizdimi dursun 10 saniye liğine Winter Zone kullandığında etrafında açık mavi bir alan göster ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Hiori ekle Hiori Zig-zag dribbling yapabilsin kusursuz falsolu paslar atabilsin ve Winter Zone kullansın rakip yakınlaşınca belirli bir alana girdiğinde yavaşlasın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Chigiri ye Speed Burst için Cooldown ekle ve savunma oyuncusu topu Forvete paslasın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
topa koşsun oyuncular ve yapay zekaları ile görevlerini iyileştir ! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Chigiri normal bir defans olmasın Orta saha gibi açlım atabilen yarı savunma yarı forvet bir hibrit oyuncu olsun ve topu önüne atıp Speed Burst le attığı topa yetişe bilsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Chigiri yarat bi tane benim takıma Defans oyuncusu olarak
User prompt
vede oyuncuların içine girersek topu bizden otomatik alsınlar
User prompt
Orta saha Dribbling yapabilsin topu aldığı zaman Etrafımızdan 1 saniyede yarım ay şeklinde bir Daire çizerek geçip Falsolu bir şut atabilsin Forvete pas vermez ise ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Defans oyuncusu ne olursa olsun yakınından geçerken bize kayarak müdahale yapıp topu uzağa uçurabilir Orta saha topu alıp bizden uzaklaşıp Forvet e Perfect Pas atabilir 30 saniyede bir Forvet Direct Shot vurabilir ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Rakip takım oyuncuları Defans Orta saha ve Forvet görevleri ver onlara mesela Orta saha topu alırsa forvet olana pas verecek defans canı pahasına topu almaya çalışacak gibi ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Karşı ve bizim kalecimiz Topu tutup pozisyonlarına geri dönüp topu sahanın ortasına atsınlar ! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'to')' in or related to this line: 'tween(self).to({' Line Number: 89 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
kalelerin önüne koy 2 tane biri mavi renkte yani Player takımında olsun diyeride Opponent takımında kırmızı kaleci olsun
User prompt
Kaleci NPC ler yarat kalelerin önüne koy birden hızlanuıp Topu tutabilsinler 20 Saniyede bir özellik olarak yaz onlara ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Top bizden ayrılamıyor düzelt direk bize temas etmeye devam ettiği için ayağımıza geri dönüyor
User prompt
Shot Power %100 olunca otomatik topu önümüze doğru bırakalım Topun yapışıklığı bitsin ve ileri doğru hızlansın !
User prompt
bunu oyuna uygula
User prompt
%100 olduğunda biz bırakana kadar 0 olmasın
User prompt
Mouse veya parmağımızın basılı olduğu tarafa atalım Shot power %100 olunca basılı tutmayı bıraktığımız an
User prompt
Şut çekmek için top ayağımızda iken 2 3 saniye ekrana basılı tutalım !
User prompt
topun yanına gittiğimizde top bizimle etkileşime girsin ve şu an kare olan oyuncumuza yapışsın ve hızını biraz daha düşür karakterimizin
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'staminaTxt.style.fill = 0x00FF00;' Line Number: 251
User prompt
sürükleyerek haraket edelim ve haraket ederken bir staminamız olsun kenarda ve yavaş yap b,raz daha ve top kenarlardan çıkamasın dışarı !
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var DefensePlayer = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.attachAsset('opponent', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.role = 'defense'; self.homeX = 1024; self.homeY = 600; self.maxDistance = 400; self.hasBall = false; self.update = function () { var dx = ball.x - self.x; var dy = ball.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Defense priority: desperately try to get the ball if (distance < 300) { // Move aggressively toward ball self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; // Kick ball away from player goal if close enough if (distance < 80) { var kickAwayX = ball.x < 1024 ? ball.x - 200 : ball.x + 200; var kickAwayY = ball.y - 300; // Kick upfield var kickDx = kickAwayX - ball.x; var kickDy = kickAwayY - ball.y; var kickDistance = Math.sqrt(kickDx * kickDx + kickDy * kickDy); if (kickDistance > 0) { ball.velocityX = kickDx / kickDistance * 8; ball.velocityY = kickDy / kickDistance * 8; } } } else { // Return to defensive position var homeDx = self.homeX - self.x; var homeDy = self.homeY - self.y; var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy); if (homeDistance > 50) { self.x += homeDx / homeDistance * self.speed * 0.5; self.y += homeDy / homeDistance * self.speed * 0.5; } } }; return self; }); var ForwardPlayer = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.attachAsset('opponent', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3.5; self.role = 'forward'; self.homeX = 1024; self.homeY = 1400; self.hasBall = false; self.update = function () { var dx = ball.x - self.x; var dy = ball.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Forward: attack and try to score if (distance < 250) { // Move toward ball self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; // If close to ball, shoot at goal if (distance < 80) { var goalDx = playerGoal.x - ball.x; var goalDy = playerGoal.y - ball.y; var goalDistance = Math.sqrt(goalDx * goalDx + goalDy * goalDy); if (goalDistance > 0) { ball.velocityX = goalDx / goalDistance * 10; ball.velocityY = goalDy / goalDistance * 10; } } } else { // Move toward attacking position var homeDx = self.homeX - self.x; var homeDy = self.homeY - self.y; var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy); if (homeDistance > 50) { self.x += homeDx / homeDistance * self.speed * 0.4; self.y += homeDy / homeDistance * self.speed * 0.4; } } }; return self; }); var Goal = Container.expand(function () { var self = Container.call(this); // Goal area var goalGraphics = self.attachAsset('goal', { anchorX: 0.5, anchorY: 0.5 }); goalGraphics.alpha = 0.3; // Left goalpost var leftPost = self.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 0.5 })); leftPost.x = -210; leftPost.y = 0; // Right goalpost var rightPost = self.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 0.5 })); rightPost.x = 210; rightPost.y = 0; return self; }); var Goalkeeper = Container.expand(function (isPlayer) { var self = Container.call(this); var keeperGraphics = self.attachAsset(isPlayer ? 'player' : 'opponent', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.isPlayer = isPlayer; self.rushCooldown = 0; self.rushCooldownTime = 20000; // 20 seconds self.isRushing = false; self.originalX = 0; self.originalY = 0; self.rushSpeed = 8; self.update = function () { // Update rush cooldown if (self.rushCooldown > 0) { self.rushCooldown -= 16; // Approximately 60 FPS if (self.rushCooldown < 0) self.rushCooldown = 0; } // Check if should rush for ball var ballDistance = Math.sqrt((ball.x - self.x) * (ball.x - self.x) + (ball.y - self.y) * (ball.y - self.y)); if (!self.isRushing && self.rushCooldown <= 0 && ballDistance < 400) { // Start rushing self.isRushing = true; self.rushCooldown = self.rushCooldownTime; } if (self.isRushing) { // Rush toward ball var dx = ball.x - self.x; var dy = ball.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0 && distance > 50) { self.x += dx / distance * self.rushSpeed; self.y += dy / distance * self.rushSpeed; } else if (distance <= 50) { // Catch ball if close enough ball.velocityX = 0; ball.velocityY = 0; ball.x = self.x; ball.y = self.y; ball.active = false; player.hasBall = false; // Return to original position first self.isRushing = false; tween(self, { x: self.originalX, y: self.originalY }, { duration: 1000, onFinish: function onFinish() { // After returning to position, throw ball to center field ball.active = true; var centerX = 1024; var centerY = 1366; var throwPower = 15; var throwDx = centerX - ball.x; var throwDy = centerY - ball.y; var throwDistance = Math.sqrt(throwDx * throwDx + throwDy * throwDy); if (throwDistance > 0) { ball.velocityX = throwDx / throwDistance * throwPower; ball.velocityY = throwDy / throwDistance * throwPower; } } }); } } else { // Normal goalkeeper movement - stay near goal line var goalCenterX = 1024; var dx = goalCenterX - self.x; if (Math.abs(dx) > 5) { self.x += dx > 0 ? self.speed : -self.speed; } } }; return self; }); var MidfieldPlayer = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.attachAsset('opponent', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.role = 'midfield'; self.homeX = 1024; self.homeY = 1000; self.hasBall = false; self.update = function () { var dx = ball.x - self.x; var dy = ball.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Midfield: get ball and pass to forward if (distance < 200) { // Move toward ball self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; // If close to ball, pass to forward player if (distance < 80) { // Find nearest forward player var nearestForward = null; var nearestDistance = Infinity; for (var i = 0; i < opponents.length; i++) { if (opponents[i].role === 'forward') { var forwardDx = opponents[i].x - self.x; var forwardDy = opponents[i].y - self.y; var forwardDistance = Math.sqrt(forwardDx * forwardDx + forwardDy * forwardDy); if (forwardDistance < nearestDistance) { nearestDistance = forwardDistance; nearestForward = opponents[i]; } } } // Pass to forward if found if (nearestForward) { var passDx = nearestForward.x - ball.x; var passDy = nearestForward.y - ball.y; var passDistance = Math.sqrt(passDx * passDx + passDy * passDy); if (passDistance > 0) { ball.velocityX = passDx / passDistance * 6; ball.velocityY = passDy / passDistance * 6; } } } } else { // Return to midfield position var homeDx = self.homeX - self.x; var homeDy = self.homeY - self.y; var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy); if (homeDistance > 50) { self.x += homeDx / homeDistance * self.speed * 0.3; self.y += homeDy / homeDistance * self.speed * 0.3; } } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.hasBall = false; return self; }); var SoccerBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.friction = 0.98; self.active = true; self.update = function () { if (self.active) { self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; // Keep ball in bounds with bounce effect if (self.x < 30) { self.x = 30; self.velocityX = Math.abs(self.velocityX) * 0.8; } if (self.x > 2018) { self.x = 2018; self.velocityX = -Math.abs(self.velocityX) * 0.8; } if (self.y < 30) { self.y = 30; self.velocityY = Math.abs(self.velocityY) * 0.8; } if (self.y > 2702) { self.y = 2702; self.velocityY = -Math.abs(self.velocityY) * 0.8; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ game.setBackgroundColor(0x228B22); // Game variables var opponents = []; var playerScore = 0; var opponentScore = 0; var dragNode = null; var maxStamina = 100; var currentStamina = 100; var staminaRegenRate = 0.2; var staminaDrainRate = 1.5; var lastPlayerX = 0; var lastPlayerY = 0; var shotChargeStart = 0; var isChargingShot = false; var shotPower = 0; var maxShotPower = 20; var minChargeTime = 2000; // 2 seconds minimum charge time var lastTouchX = 0; var lastTouchY = 0; var ballDetachCooldown = 0; var ballDetachCooldownTime = 1000; // 1 second cooldown // UI Elements var scoreTxt = new Text2('Player: 0 - Opponent: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Stamina UI var staminaTxt = new Text2('Stamina: 100', { size: 60, fill: 0x00FF00 }); staminaTxt.anchor.set(0, 0); staminaTxt.x = 50; staminaTxt.y = 50; LK.gui.topLeft.addChild(staminaTxt); // Shot Power UI var shotPowerTxt = new Text2('Shot Power: 0%', { size: 60, fill: 0xFFFFFF }); shotPowerTxt.anchor.set(0, 0); shotPowerTxt.x = 50; shotPowerTxt.y = 130; LK.gui.topLeft.addChild(shotPowerTxt); // Game objects var player = game.addChild(new Player()); player.x = 1024; player.y = 2200; var ball = game.addChild(new SoccerBall()); ball.x = 1024; ball.y = 1366; // Player's goal (bottom) var playerGoal = game.addChild(new Goal()); playerGoal.x = 1024; playerGoal.y = 2600; // Opponent's goal (top) var opponentGoal = game.addChild(new Goal()); opponentGoal.x = 1024; opponentGoal.y = 300; // Create opponents with specific roles // Defense player var defensePlayer = game.addChild(new DefensePlayer()); defensePlayer.x = 1024; defensePlayer.y = 600; defensePlayer.homeX = 1024; defensePlayer.homeY = 600; opponents.push(defensePlayer); // Midfield player var midfieldPlayer = game.addChild(new MidfieldPlayer()); midfieldPlayer.x = 1024; midfieldPlayer.y = 1000; midfieldPlayer.homeX = 1024; midfieldPlayer.homeY = 1000; opponents.push(midfieldPlayer); // Forward player var forwardPlayer = game.addChild(new ForwardPlayer()); forwardPlayer.x = 1024; forwardPlayer.y = 1400; forwardPlayer.homeX = 1024; forwardPlayer.homeY = 1400; opponents.push(forwardPlayer); // Create goalkeepers var playerGoalkeeper = game.addChild(new Goalkeeper(true)); // Blue goalkeeper for player team playerGoalkeeper.x = 1024; playerGoalkeeper.y = 2500; // In front of player's goal playerGoalkeeper.originalX = 1024; playerGoalkeeper.originalY = 2500; var opponentGoalkeeper = game.addChild(new Goalkeeper(false)); // Red goalkeeper for opponent team opponentGoalkeeper.x = 1024; opponentGoalkeeper.y = 400; // In front of opponent's goal opponentGoalkeeper.originalX = 1024; opponentGoalkeeper.originalY = 400; // Ball kicking mechanics function kickBall(targetX, targetY, power) { var dx = targetX - ball.x; var dy = targetY - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { var finalPower = power || Math.min(distance / 100, 15); // Properly detach ball from player first player.hasBall = false; ball.active = true; // Set cooldown to prevent immediate re-attachment ballDetachCooldown = ballDetachCooldownTime; // Apply velocity after detachment ball.velocityX = dx / distance * finalPower; ball.velocityY = dy / distance * finalPower; LK.getSound('kick').play(); } } // Touch controls for player movement and ball kicking game.down = function (x, y, obj) { // Always update last touch position for shot direction lastTouchX = x; lastTouchY = y; var playerDistance = Math.sqrt((x - player.x) * (x - player.x) + (y - player.y) * (y - player.y)); var ballDistance = Math.sqrt((x - ball.x) * (x - ball.x) + (y - ball.y) * (y - ball.y)); if (playerDistance < ballDistance) { // Move player dragNode = player; } else { // Start charging shot if player has ball if (player.hasBall) { shotChargeStart = Date.now(); isChargingShot = true; shotPower = 0; } } }; game.move = function (x, y, obj) { // Always update last touch position for shot direction lastTouchX = x; lastTouchY = y; if (dragNode && currentStamina > 0) { var dx = x - dragNode.x; var dy = y - dragNode.y; var distance = Math.sqrt(dx * dx + dy * dy); // Slow down movement and consume stamina - even slower when having ball var moveSpeed = player.hasBall ? 0.15 : 0.2; dragNode.x += dx * moveSpeed; dragNode.y += dy * moveSpeed; // Consume stamina based on movement if (distance > 5) { currentStamina -= staminaDrainRate; if (currentStamina < 0) currentStamina = 0; } } }; game.up = function (x, y, obj) { dragNode = null; // Handle shot release if (isChargingShot && player.hasBall) { var chargeTime = Date.now() - shotChargeStart; if (chargeTime >= minChargeTime) { // Release charged shot - use last touch position for direction kickBall(lastTouchX, lastTouchY, shotPower); } else { // Not charged enough, no shot } isChargingShot = false; shotPower = 0; } }; // Goal scoring function function scoreGoal(isPlayer) { if (isPlayer) { playerScore++; } else { opponentScore++; } scoreTxt.setText('Player: ' + playerScore + ' - Opponent: ' + opponentScore); LK.getSound('goal').play(); // Reset ball position ball.x = 1024; ball.y = 1366; ball.velocityX = 0; ball.velocityY = 0; } // Game update loop game.update = function () { // Update ball detach cooldown if (ballDetachCooldown > 0) { ballDetachCooldown -= 16; // Approximately 60 FPS if (ballDetachCooldown < 0) ballDetachCooldown = 0; } // Check if player is close to ball for interaction (only if cooldown expired) var playerToBallDistance = Math.sqrt((player.x - ball.x) * (player.x - ball.x) + (player.y - ball.y) * (player.y - ball.y)); if (playerToBallDistance < 80 && !player.hasBall && ballDetachCooldown <= 0) { player.hasBall = true; ball.active = false; ball.velocityX = 0; ball.velocityY = 0; } // If player has ball, make it stick to player if (player.hasBall && ball.active === false) { ball.x = player.x; ball.y = player.y - 50; } // Stamina regeneration when not moving var playerMoving = Math.abs(player.x - lastPlayerX) > 1 || Math.abs(player.y - lastPlayerY) > 1; if (!playerMoving && currentStamina < maxStamina) { currentStamina += staminaRegenRate; if (currentStamina > maxStamina) currentStamina = maxStamina; } // Update last position lastPlayerX = player.x; lastPlayerY = player.y; // Update stamina UI var staminaPercent = Math.round(currentStamina / maxStamina * 100); staminaTxt.setText('Stamina: ' + staminaPercent); // Change color based on stamina level if (staminaPercent > 50) { staminaTxt.fill = 0x00FF00; } else if (staminaPercent > 25) { staminaTxt.fill = 0xFFFF00; } else { staminaTxt.fill = 0xFF0000; } // Update shot charging if (isChargingShot && player.hasBall) { var chargeTime = Date.now() - shotChargeStart; if (chargeTime >= minChargeTime) { // Calculate shot power based on charge time var chargeProgress = Math.min((chargeTime - minChargeTime) / 1000, 1); // 1 second after minimum for max power shotPower = 5 + chargeProgress * maxShotPower; // Minimum 5, maximum 25 power var powerPercent = Math.round(chargeProgress * 100); shotPowerTxt.setText('Shot Power: ' + powerPercent + '%'); shotPowerTxt.fill = 0x00FF00; // Automatically kick ball forward when shot power reaches 100% if (powerPercent >= 100) { shotPower = 5 + maxShotPower; // Keep at maximum power shotPowerTxt.setText('Shot Power: 100%'); shotPowerTxt.fill = 0x00FF00; // Auto-kick ball forward when power reaches 100% var forwardX = player.x; var forwardY = player.y - 300; // Kick forward (up the field) kickBall(forwardX, forwardY, shotPower); isChargingShot = false; shotPower = 0; } } else { // Not charged enough yet var timeLeft = Math.ceil((minChargeTime - chargeTime) / 1000); shotPowerTxt.setText('Hold for ' + timeLeft + 's'); shotPowerTxt.fill = 0xFFFF00; } } else { shotPowerTxt.setText('Shot Power: 0%'); shotPowerTxt.fill = 0xFFFFFF; } // Check player goal scoring (opponent scores) if (ball.y > playerGoal.y - 50 && ball.x > playerGoal.x - 200 && ball.x < playerGoal.x + 200) { scoreGoal(false); LK.effects.flashObject(playerGoal, 0xFF0000, 500); } // Check opponent goal scoring (player scores) if (ball.y < opponentGoal.y + 50 && ball.x > opponentGoal.x - 200 && ball.x < opponentGoal.x + 200) { scoreGoal(true); LK.effects.flashObject(opponentGoal, 0x00FF00, 500); } // Check win condition if (playerScore >= 5) { LK.showYouWin(); } if (opponentScore >= 5) { LK.showGameOver(); } // Role-based AI is now handled in each player's update method // Defense, Midfield, and Forward players have their own specialized behaviors };
===================================================================
--- original.js
+++ change.js
@@ -5,8 +5,97 @@
/****
* Classes
****/
+var DefensePlayer = Container.expand(function () {
+ var self = Container.call(this);
+ var opponentGraphics = self.attachAsset('opponent', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 4;
+ self.role = 'defense';
+ self.homeX = 1024;
+ self.homeY = 600;
+ self.maxDistance = 400;
+ self.hasBall = false;
+ self.update = function () {
+ var dx = ball.x - self.x;
+ var dy = ball.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Defense priority: desperately try to get the ball
+ if (distance < 300) {
+ // Move aggressively toward ball
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ // Kick ball away from player goal if close enough
+ if (distance < 80) {
+ var kickAwayX = ball.x < 1024 ? ball.x - 200 : ball.x + 200;
+ var kickAwayY = ball.y - 300; // Kick upfield
+ var kickDx = kickAwayX - ball.x;
+ var kickDy = kickAwayY - ball.y;
+ var kickDistance = Math.sqrt(kickDx * kickDx + kickDy * kickDy);
+ if (kickDistance > 0) {
+ ball.velocityX = kickDx / kickDistance * 8;
+ ball.velocityY = kickDy / kickDistance * 8;
+ }
+ }
+ } else {
+ // Return to defensive position
+ var homeDx = self.homeX - self.x;
+ var homeDy = self.homeY - self.y;
+ var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy);
+ if (homeDistance > 50) {
+ self.x += homeDx / homeDistance * self.speed * 0.5;
+ self.y += homeDy / homeDistance * self.speed * 0.5;
+ }
+ }
+ };
+ return self;
+});
+var ForwardPlayer = Container.expand(function () {
+ var self = Container.call(this);
+ var opponentGraphics = self.attachAsset('opponent', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3.5;
+ self.role = 'forward';
+ self.homeX = 1024;
+ self.homeY = 1400;
+ self.hasBall = false;
+ self.update = function () {
+ var dx = ball.x - self.x;
+ var dy = ball.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Forward: attack and try to score
+ if (distance < 250) {
+ // Move toward ball
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ // If close to ball, shoot at goal
+ if (distance < 80) {
+ var goalDx = playerGoal.x - ball.x;
+ var goalDy = playerGoal.y - ball.y;
+ var goalDistance = Math.sqrt(goalDx * goalDx + goalDy * goalDy);
+ if (goalDistance > 0) {
+ ball.velocityX = goalDx / goalDistance * 10;
+ ball.velocityY = goalDy / goalDistance * 10;
+ }
+ }
+ } else {
+ // Move toward attacking position
+ var homeDx = self.homeX - self.x;
+ var homeDy = self.homeY - self.y;
+ var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy);
+ if (homeDistance > 50) {
+ self.x += homeDx / homeDistance * self.speed * 0.4;
+ self.y += homeDy / homeDistance * self.speed * 0.4;
+ }
+ }
+ };
+ return self;
+});
var Goal = Container.expand(function () {
var self = Container.call(this);
// Goal area
var goalGraphics = self.attachAsset('goal', {
@@ -106,22 +195,64 @@
}
};
return self;
});
-var Opponent = Container.expand(function () {
+var MidfieldPlayer = Container.expand(function () {
var self = Container.call(this);
var opponentGraphics = self.attachAsset('opponent', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
- self.direction = 1;
- self.minX = 200;
- self.maxX = 1848;
+ self.role = 'midfield';
+ self.homeX = 1024;
+ self.homeY = 1000;
+ self.hasBall = false;
self.update = function () {
- self.x += self.speed * self.direction;
- if (self.x <= self.minX || self.x >= self.maxX) {
- self.direction *= -1;
+ var dx = ball.x - self.x;
+ var dy = ball.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Midfield: get ball and pass to forward
+ if (distance < 200) {
+ // Move toward ball
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ // If close to ball, pass to forward player
+ if (distance < 80) {
+ // Find nearest forward player
+ var nearestForward = null;
+ var nearestDistance = Infinity;
+ for (var i = 0; i < opponents.length; i++) {
+ if (opponents[i].role === 'forward') {
+ var forwardDx = opponents[i].x - self.x;
+ var forwardDy = opponents[i].y - self.y;
+ var forwardDistance = Math.sqrt(forwardDx * forwardDx + forwardDy * forwardDy);
+ if (forwardDistance < nearestDistance) {
+ nearestDistance = forwardDistance;
+ nearestForward = opponents[i];
+ }
+ }
+ }
+ // Pass to forward if found
+ if (nearestForward) {
+ var passDx = nearestForward.x - ball.x;
+ var passDy = nearestForward.y - ball.y;
+ var passDistance = Math.sqrt(passDx * passDx + passDy * passDy);
+ if (passDistance > 0) {
+ ball.velocityX = passDx / passDistance * 6;
+ ball.velocityY = passDy / passDistance * 6;
+ }
+ }
+ }
+ } else {
+ // Return to midfield position
+ var homeDx = self.homeX - self.x;
+ var homeDy = self.homeY - self.y;
+ var homeDistance = Math.sqrt(homeDx * homeDx + homeDy * homeDy);
+ if (homeDistance > 50) {
+ self.x += homeDx / homeDistance * self.speed * 0.3;
+ self.y += homeDy / homeDistance * self.speed * 0.3;
+ }
}
};
return self;
});
@@ -243,15 +374,30 @@
// Opponent's goal (top)
var opponentGoal = game.addChild(new Goal());
opponentGoal.x = 1024;
opponentGoal.y = 300;
-// Create opponents
-for (var i = 0; i < 3; i++) {
- var opponent = game.addChild(new Opponent());
- opponent.x = 400 + i * 400;
- opponent.y = 800 + i * 200;
- opponents.push(opponent);
-}
+// Create opponents with specific roles
+// Defense player
+var defensePlayer = game.addChild(new DefensePlayer());
+defensePlayer.x = 1024;
+defensePlayer.y = 600;
+defensePlayer.homeX = 1024;
+defensePlayer.homeY = 600;
+opponents.push(defensePlayer);
+// Midfield player
+var midfieldPlayer = game.addChild(new MidfieldPlayer());
+midfieldPlayer.x = 1024;
+midfieldPlayer.y = 1000;
+midfieldPlayer.homeX = 1024;
+midfieldPlayer.homeY = 1000;
+opponents.push(midfieldPlayer);
+// Forward player
+var forwardPlayer = game.addChild(new ForwardPlayer());
+forwardPlayer.x = 1024;
+forwardPlayer.y = 1400;
+forwardPlayer.homeX = 1024;
+forwardPlayer.homeY = 1400;
+opponents.push(forwardPlayer);
// Create goalkeepers
var playerGoalkeeper = game.addChild(new Goalkeeper(true)); // Blue goalkeeper for player team
playerGoalkeeper.x = 1024;
playerGoalkeeper.y = 2500; // In front of player's goal
@@ -436,21 +582,7 @@
}
if (opponentScore >= 5) {
LK.showGameOver();
}
- // Simple AI for opponents to move toward ball
- for (var i = 0; i < opponents.length; i++) {
- var opponent = opponents[i];
- var dx = ball.x - opponent.x;
- var dy = ball.y - opponent.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 0 && distance < 300) {
- opponent.x += dx / distance * opponent.speed * 0.5;
- opponent.y += dy / distance * opponent.speed * 0.5;
- // Opponent kicks ball if close enough
- if (distance < 100) {
- ball.velocityX += dx / distance * 3;
- ball.velocityY += dy / distance * 3;
- }
- }
- }
+ // Role-based AI is now handled in each player's update method
+ // Defense, Midfield, and Forward players have their own specialized behaviors
};
\ No newline at end of file