User prompt
Mejor me este dos lanza guisantes diferentes equipos
User prompt
Ahora lanza guisantes también será de mi equipo
User prompt
Mejor que los bots vayan por todo el campo y no en su propio campo
User prompt
Que los bots vayan también a la cancha contraria para meter gol
User prompt
Pero que no se choquen con el borde los bots y cuando tengan la pelota, que vaya a la portería para meter gol
User prompt
Que los bots también metan tiros a la portería y también quitar la pelota al contricante
User prompt
Pero porque lanza guisantes no dispara su guisante. Arregla ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Pon un borde alrededor de la pantalla y que no se choquen los bots
User prompt
Pero que jueguen bien al fútbol los bots y se pueden pasar al pelota
User prompt
Pero que el guisante hace que alguien toque que no se mueva por 3 segundos. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Cuando alguien se choca con otro. Ellos rebotan. Y cuando alguien toque el guisante, será aturdido por 3 segundos y que los bots metan gol. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Agrega al lanza guisantes (qué será un bot o ia qué sabrá jugar al fútbol). Que su habilidad es disparar un guisante qué va recto (solo usa su habilidad cuando tenga la pelota o balón). Para diferenciar qué alguien no es de tu equipo, tus enemigos tendrán un borde rojo que significa que es tu enemigo. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Goal Strike Arena
Initial prompt
Es un juego al estilo fútbol. A arriba hay una portería y en la abajo hay otra portería. Los personajes tienen habilidades que pueden usarse para meter gol.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = 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.bounceStrength = 0.8;
self.kick = function (forceX, forceY) {
self.velocityX += forceX;
self.velocityY += forceY;
LK.getSound('kick').play();
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Bounce off walls
if (self.x <= 20 || self.x >= 2028) {
self.velocityX *= -self.bounceStrength;
self.x = Math.max(20, Math.min(2028, self.x));
}
// Check goal areas
if (self.y <= 100 && self.x >= 874 && self.x <= 1174) {
// Top goal (opponent scores)
if (!self.goalScored) {
self.goalScored = true;
opponentScore++;
LK.getSound('goal').play();
LK.effects.flashScreen(0xff4500, 500);
resetBall();
}
} else if (self.y >= 2632 && self.x >= 874 && self.x <= 1174) {
// Bottom goal (player scores)
if (!self.goalScored) {
self.goalScored = true;
playerScore++;
LK.getSound('goal').play();
LK.effects.flashScreen(0x4169e1, 500);
resetBall();
}
} else {
self.goalScored = false;
}
// Bounce off top and bottom (outside goal areas)
if (self.y <= 20 && (self.x < 874 || self.x > 1174) || self.y >= 2712 && (self.x < 874 || self.x > 1174)) {
self.velocityY *= -self.bounceStrength;
self.y = Math.max(20, Math.min(2712, self.y));
}
};
return self;
});
var Lanzaguisantes = Container.expand(function () {
var self = Container.call(this);
var lanzaguisantesGraphics = self.attachAsset('Lanzaguisantes', {
anchorX: 0.5,
anchorY: 0.5
});
// Add red border to indicate enemy
var redBorder = self.addChild(LK.getAsset('opponent', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.8,
scaleY: 1.8,
alpha: 0.6
}));
self.speed = 2.5;
self.targetX = 1024;
self.targetY = 400;
self.aiTimer = 0;
self.abilityCooldown = 0;
self.hasBall = false;
self.isStunned = false;
self.stunDuration = 0;
self.shootPea = function () {
if (self.abilityCooldown <= 0 && self.hasBall) {
self.abilityCooldown = 120; // 2 seconds cooldown
LK.getSound('ability').play();
var newPea = new Pea();
newPea.x = self.x;
newPea.y = self.y;
// Shoot towards bottom goal
newPea.shoot(1024, 2682);
peas.push(newPea);
game.addChild(newPea);
}
};
self.update = function () {
self.aiTimer++;
// Handle stun state
if (self.isStunned) {
self.stunDuration--;
if (self.stunDuration <= 0) {
self.isStunned = false;
self.tint = 0xFFFFFF; // Reset tint
}
return; // Skip movement and other actions while stunned
}
// Check if bot has the ball
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
self.hasBall = ballDistance < 80;
// Simple AI: move towards ball or defensive position
if (ball.y < 1366) {
// Ball in opponent's half
self.targetX = ball.x;
self.targetY = ball.y + 80;
} else {
self.targetX = 1024;
self.targetY = 400;
}
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
// Keep lanzaguisantes in their half mostly
self.y = Math.max(100, Math.min(1200, self.y));
self.x = Math.max(100, Math.min(1948, self.x));
// Use ability when has ball
if (self.hasBall && self.abilityCooldown <= 0) {
self.shootPea();
}
// Check ball collision
if (ballDistance < 60) {
var kickForceX = (ball.x - self.x) / ballDistance * 5;
var kickForceY = (ball.y - self.y) / ballDistance * 5;
ball.kick(kickForceX, kickForceY);
}
// Update cooldown
if (self.abilityCooldown > 0) {
self.abilityCooldown--;
}
};
return self;
});
var Opponent = Container.expand(function () {
var self = Container.call(this);
var opponentGraphics = self.attachAsset('opponent', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.targetX = 1024;
self.targetY = 500;
self.aiTimer = 0;
self.isStunned = false;
self.stunDuration = 0;
self.update = function () {
self.aiTimer++;
// Handle stun state
if (self.isStunned) {
self.stunDuration--;
if (self.stunDuration <= 0) {
self.isStunned = false;
self.tint = 0xFFFFFF; // Reset tint
}
return; // Skip movement and other actions while stunned
}
// Simple AI: move towards ball or defensive position
if (ball.y < 1366) {
// Ball in opponent's half
self.targetX = ball.x;
self.targetY = ball.y + 100;
} else {
self.targetX = 1024;
self.targetY = 500;
}
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
// Keep opponent in their half mostly
self.y = Math.max(100, Math.min(1300, self.y));
self.x = Math.max(100, Math.min(1948, self.x));
// Check collision with lanzaguisantes
var lanzaguisantesDistance = Math.sqrt(Math.pow(lanzaguisantes.x - self.x, 2) + Math.pow(lanzaguisantes.y - self.y, 2));
if (lanzaguisantesDistance < 70) {
// Calculate bounce direction
var bounceX = (self.x - lanzaguisantes.x) / lanzaguisantesDistance;
var bounceY = (self.y - lanzaguisantes.y) / lanzaguisantesDistance;
// Apply bounce force
self.x += bounceX * 20;
self.y += bounceY * 20;
lanzaguisantes.x -= bounceX * 20;
lanzaguisantes.y -= bounceY * 20;
// Keep characters in bounds
self.x = Math.max(50, Math.min(1998, self.x));
self.y = Math.max(50, Math.min(2682, self.y));
lanzaguisantes.x = Math.max(50, Math.min(1998, lanzaguisantes.x));
lanzaguisantes.y = Math.max(50, Math.min(2682, lanzaguisantes.y));
}
// Check ball collision
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 50) {
var kickForceX = (ball.x - self.x) / ballDistance * 6;
var kickForceY = (ball.y - self.y) / ballDistance * 6;
ball.kick(kickForceX, kickForceY);
}
};
return self;
});
var Pea = Container.expand(function () {
var self = Container.call(this);
var peaGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
peaGraphics.tint = 0x90EE90;
self.velocityX = 0;
self.velocityY = 0;
self.speed = 12;
self.shoot = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.velocityX = dx / distance * self.speed;
self.velocityY = dy / distance * self.speed;
}
};
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
// Remove pea if it goes off screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
for (var i = peas.length - 1; i >= 0; i--) {
if (peas[i] === self) {
peas.splice(i, 1);
break;
}
}
}
// Check collision with player
var playerDistance = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
if (playerDistance < 50) {
// Stun player for 3 seconds
player.isStunned = true;
player.stunDuration = 180; // 3 seconds at 60fps
tween(player, {
tint: 0xFF0000
}, {
duration: 500,
onFinish: function onFinish() {
tween(player, {
tint: 0xFFFFFF
}, {
duration: 500
});
}
});
self.destroy();
for (var i = peas.length - 1; i >= 0; i--) {
if (peas[i] === self) {
peas.splice(i, 1);
break;
}
}
return;
}
// Check collision with opponent
var opponentDistance = Math.sqrt(Math.pow(opponent.x - self.x, 2) + Math.pow(opponent.y - self.y, 2));
if (opponentDistance < 50) {
// Stun opponent for 3 seconds
opponent.isStunned = true;
opponent.stunDuration = 180; // 3 seconds at 60fps
tween(opponent, {
tint: 0xFF0000
}, {
duration: 500,
onFinish: function onFinish() {
tween(opponent, {
tint: 0xFFFFFF
}, {
duration: 500
});
}
});
self.destroy();
for (var i = peas.length - 1; i >= 0; i--) {
if (peas[i] === self) {
peas.splice(i, 1);
break;
}
}
return;
}
// Check collision with ball
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 40) {
var kickForceX = self.velocityX * 0.8;
var kickForceY = self.velocityY * 0.8;
ball.kick(kickForceX, kickForceY);
self.destroy();
for (var i = peas.length - 1; i >= 0; i--) {
if (peas[i] === self) {
peas.splice(i, 1);
break;
}
}
}
};
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 = 4;
self.targetX = 1024;
self.targetY = 2200;
self.abilityType = 'speed'; // 'speed', 'power', 'shield'
self.abilityCooldown = 0;
self.abilityDuration = 0;
self.abilityEffect = null;
self.isStunned = false;
self.stunDuration = 0;
self.activateAbility = function () {
if (self.abilityCooldown <= 0) {
self.abilityCooldown = 180; // 3 seconds at 60fps
self.abilityDuration = 120; // 2 seconds effect
LK.getSound('ability').play();
if (self.abilityType === 'speed') {
self.abilityEffect = self.addChild(LK.getAsset('speedBoostEffect', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
}));
self.speed = 8;
}
}
};
self.update = function () {
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
// Handle stun state
if (self.isStunned) {
self.stunDuration--;
if (self.stunDuration <= 0) {
self.isStunned = false;
self.tint = 0xFFFFFF; // Reset tint
}
return; // Skip movement and other actions while stunned
}
// Update ability
if (self.abilityDuration > 0) {
self.abilityDuration--;
if (self.abilityEffect) {
self.abilityEffect.rotation += 0.1;
}
} else {
if (self.abilityEffect) {
self.removeChild(self.abilityEffect);
self.abilityEffect = null;
}
self.speed = 4;
}
if (self.abilityCooldown > 0) {
self.abilityCooldown--;
}
// Check collision with other characters
var opponentDistance = Math.sqrt(Math.pow(opponent.x - self.x, 2) + Math.pow(opponent.y - self.y, 2));
if (opponentDistance < 70) {
// Calculate bounce direction
var bounceX = (self.x - opponent.x) / opponentDistance;
var bounceY = (self.y - opponent.y) / opponentDistance;
// Apply bounce force
self.x += bounceX * 20;
self.y += bounceY * 20;
opponent.x -= bounceX * 20;
opponent.y -= bounceY * 20;
// Keep characters in bounds
self.x = Math.max(50, Math.min(1998, self.x));
self.y = Math.max(50, Math.min(2682, self.y));
opponent.x = Math.max(50, Math.min(1998, opponent.x));
opponent.y = Math.max(50, Math.min(2682, opponent.y));
}
var lanzaguisantesDistance = Math.sqrt(Math.pow(lanzaguisantes.x - self.x, 2) + Math.pow(lanzaguisantes.y - self.y, 2));
if (lanzaguisantesDistance < 70) {
// Calculate bounce direction
var bounceX = (self.x - lanzaguisantes.x) / lanzaguisantesDistance;
var bounceY = (self.y - lanzaguisantes.y) / lanzaguisantesDistance;
// Apply bounce force
self.x += bounceX * 20;
self.y += bounceY * 20;
lanzaguisantes.x -= bounceX * 20;
lanzaguisantes.y -= bounceY * 20;
// Keep characters in bounds
self.x = Math.max(50, Math.min(1998, self.x));
self.y = Math.max(50, Math.min(2682, self.y));
lanzaguisantes.x = Math.max(50, Math.min(1998, lanzaguisantes.x));
lanzaguisantes.y = Math.max(50, Math.min(2682, lanzaguisantes.y));
}
// Check ball collision
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 50) {
var kickForceX = (ball.x - self.x) / ballDistance * 8;
var kickForceY = (ball.y - self.y) / ballDistance * 8;
if (self.abilityType === 'power' && self.abilityDuration > 0) {
kickForceX *= 2;
kickForceY *= 2;
}
ball.kick(kickForceX, kickForceY);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game variables
var playerScore = 0;
var opponentScore = 0;
var targetScore = 3;
var ball;
var player;
var opponent;
var lanzaguisantes;
var peas = [];
// Create field elements
var field = game.addChild(LK.getAsset('field', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var centerCircle = game.addChild(LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
alpha: 0.3
}));
// Create goals
var topGoal = game.addChild(LK.getAsset('topGoal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 50
}));
var bottomGoal = game.addChild(LK.getAsset('bottomGoal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2682
}));
// Create score display
var scoreText = new Text2('Player: 0 - Opponent: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create ability button
var abilityButton = new Text2('SPEED BOOST', {
size: 40,
fill: 0xFFFF00
});
abilityButton.anchor.set(0.5, 1);
LK.gui.bottom.addChild(abilityButton);
// Create game objects
ball = game.addChild(new Ball());
player = game.addChild(new Player());
opponent = game.addChild(new Opponent());
lanzaguisantes = game.addChild(new Lanzaguisantes());
function resetBall() {
LK.setTimeout(function () {
ball.x = 1024;
ball.y = 1366;
ball.velocityX = 0;
ball.velocityY = 0;
ball.goalScored = false;
// Update score display
scoreText.setText('Player: ' + playerScore + ' - Opponent: ' + opponentScore);
// Check win condition
if (playerScore >= targetScore) {
LK.showYouWin();
} else if (opponentScore >= targetScore) {
LK.showGameOver();
}
}, 1000);
}
// Initialize positions
resetBall();
player.x = 1024;
player.y = 2200;
opponent.x = 1024;
opponent.y = 500;
lanzaguisantes.x = 800;
lanzaguisantes.y = 400;
// Touch controls
game.down = function (x, y, obj) {
player.targetX = x;
player.targetY = y;
};
game.move = function (x, y, obj) {
player.targetX = x;
player.targetY = y;
};
// Ability button handler
abilityButton.down = function (x, y, obj) {
player.activateAbility();
};
game.update = function () {
// Update ability button text
if (player.abilityCooldown > 0) {
abilityButton.setText('COOLDOWN: ' + Math.ceil(player.abilityCooldown / 60));
abilityButton.tint = 0x666666;
} else {
abilityButton.setText('SPEED BOOST');
abilityButton.tint = 0xffff00;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -80,8 +80,10 @@
self.targetY = 400;
self.aiTimer = 0;
self.abilityCooldown = 0;
self.hasBall = false;
+ self.isStunned = false;
+ self.stunDuration = 0;
self.shootPea = function () {
if (self.abilityCooldown <= 0 && self.hasBall) {
self.abilityCooldown = 120; // 2 seconds cooldown
LK.getSound('ability').play();
@@ -95,8 +97,17 @@
}
};
self.update = function () {
self.aiTimer++;
+ // Handle stun state
+ if (self.isStunned) {
+ self.stunDuration--;
+ if (self.stunDuration <= 0) {
+ self.isStunned = false;
+ self.tint = 0xFFFFFF; // Reset tint
+ }
+ return; // Skip movement and other actions while stunned
+ }
// Check if bot has the ball
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
self.hasBall = ballDistance < 80;
// Simple AI: move towards ball or defensive position
@@ -145,10 +156,21 @@
self.speed = 3;
self.targetX = 1024;
self.targetY = 500;
self.aiTimer = 0;
+ self.isStunned = false;
+ self.stunDuration = 0;
self.update = function () {
self.aiTimer++;
+ // Handle stun state
+ if (self.isStunned) {
+ self.stunDuration--;
+ if (self.stunDuration <= 0) {
+ self.isStunned = false;
+ self.tint = 0xFFFFFF; // Reset tint
+ }
+ return; // Skip movement and other actions while stunned
+ }
// Simple AI: move towards ball or defensive position
if (ball.y < 1366) {
// Ball in opponent's half
self.targetX = ball.x;
@@ -167,8 +189,25 @@
}
// Keep opponent in their half mostly
self.y = Math.max(100, Math.min(1300, self.y));
self.x = Math.max(100, Math.min(1948, self.x));
+ // Check collision with lanzaguisantes
+ var lanzaguisantesDistance = Math.sqrt(Math.pow(lanzaguisantes.x - self.x, 2) + Math.pow(lanzaguisantes.y - self.y, 2));
+ if (lanzaguisantesDistance < 70) {
+ // Calculate bounce direction
+ var bounceX = (self.x - lanzaguisantes.x) / lanzaguisantesDistance;
+ var bounceY = (self.y - lanzaguisantes.y) / lanzaguisantesDistance;
+ // Apply bounce force
+ self.x += bounceX * 20;
+ self.y += bounceY * 20;
+ lanzaguisantes.x -= bounceX * 20;
+ lanzaguisantes.y -= bounceY * 20;
+ // Keep characters in bounds
+ self.x = Math.max(50, Math.min(1998, self.x));
+ self.y = Math.max(50, Math.min(2682, self.y));
+ lanzaguisantes.x = Math.max(50, Math.min(1998, lanzaguisantes.x));
+ lanzaguisantes.y = Math.max(50, Math.min(2682, lanzaguisantes.y));
+ }
// Check ball collision
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 50) {
var kickForceX = (ball.x - self.x) / ballDistance * 6;
@@ -211,8 +250,62 @@
break;
}
}
}
+ // Check collision with player
+ var playerDistance = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
+ if (playerDistance < 50) {
+ // Stun player for 3 seconds
+ player.isStunned = true;
+ player.stunDuration = 180; // 3 seconds at 60fps
+ tween(player, {
+ tint: 0xFF0000
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ tween(player, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 500
+ });
+ }
+ });
+ self.destroy();
+ for (var i = peas.length - 1; i >= 0; i--) {
+ if (peas[i] === self) {
+ peas.splice(i, 1);
+ break;
+ }
+ }
+ return;
+ }
+ // Check collision with opponent
+ var opponentDistance = Math.sqrt(Math.pow(opponent.x - self.x, 2) + Math.pow(opponent.y - self.y, 2));
+ if (opponentDistance < 50) {
+ // Stun opponent for 3 seconds
+ opponent.isStunned = true;
+ opponent.stunDuration = 180; // 3 seconds at 60fps
+ tween(opponent, {
+ tint: 0xFF0000
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ tween(opponent, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 500
+ });
+ }
+ });
+ self.destroy();
+ for (var i = peas.length - 1; i >= 0; i--) {
+ if (peas[i] === self) {
+ peas.splice(i, 1);
+ break;
+ }
+ }
+ return;
+ }
// Check collision with ball
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 40) {
var kickForceX = self.velocityX * 0.8;
@@ -241,8 +334,10 @@
self.abilityType = 'speed'; // 'speed', 'power', 'shield'
self.abilityCooldown = 0;
self.abilityDuration = 0;
self.abilityEffect = null;
+ self.isStunned = false;
+ self.stunDuration = 0;
self.activateAbility = function () {
if (self.abilityCooldown <= 0) {
self.abilityCooldown = 180; // 3 seconds at 60fps
self.abilityDuration = 120; // 2 seconds effect
@@ -265,8 +360,17 @@
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
+ // Handle stun state
+ if (self.isStunned) {
+ self.stunDuration--;
+ if (self.stunDuration <= 0) {
+ self.isStunned = false;
+ self.tint = 0xFFFFFF; // Reset tint
+ }
+ return; // Skip movement and other actions while stunned
+ }
// Update ability
if (self.abilityDuration > 0) {
self.abilityDuration--;
if (self.abilityEffect) {
@@ -281,8 +385,41 @@
}
if (self.abilityCooldown > 0) {
self.abilityCooldown--;
}
+ // Check collision with other characters
+ var opponentDistance = Math.sqrt(Math.pow(opponent.x - self.x, 2) + Math.pow(opponent.y - self.y, 2));
+ if (opponentDistance < 70) {
+ // Calculate bounce direction
+ var bounceX = (self.x - opponent.x) / opponentDistance;
+ var bounceY = (self.y - opponent.y) / opponentDistance;
+ // Apply bounce force
+ self.x += bounceX * 20;
+ self.y += bounceY * 20;
+ opponent.x -= bounceX * 20;
+ opponent.y -= bounceY * 20;
+ // Keep characters in bounds
+ self.x = Math.max(50, Math.min(1998, self.x));
+ self.y = Math.max(50, Math.min(2682, self.y));
+ opponent.x = Math.max(50, Math.min(1998, opponent.x));
+ opponent.y = Math.max(50, Math.min(2682, opponent.y));
+ }
+ var lanzaguisantesDistance = Math.sqrt(Math.pow(lanzaguisantes.x - self.x, 2) + Math.pow(lanzaguisantes.y - self.y, 2));
+ if (lanzaguisantesDistance < 70) {
+ // Calculate bounce direction
+ var bounceX = (self.x - lanzaguisantes.x) / lanzaguisantesDistance;
+ var bounceY = (self.y - lanzaguisantes.y) / lanzaguisantesDistance;
+ // Apply bounce force
+ self.x += bounceX * 20;
+ self.y += bounceY * 20;
+ lanzaguisantes.x -= bounceX * 20;
+ lanzaguisantes.y -= bounceY * 20;
+ // Keep characters in bounds
+ self.x = Math.max(50, Math.min(1998, self.x));
+ self.y = Math.max(50, Math.min(2682, self.y));
+ lanzaguisantes.x = Math.max(50, Math.min(1998, lanzaguisantes.x));
+ lanzaguisantes.y = Math.max(50, Math.min(2682, lanzaguisantes.y));
+ }
// Check ball collision
var ballDistance = Math.sqrt(Math.pow(ball.x - self.x, 2) + Math.pow(ball.y - self.y, 2));
if (ballDistance < 50) {
var kickForceX = (ball.x - self.x) / ballDistance * 8;