User prompt
ajoute des constantes pour les positions initiales des joueurs
User prompt
mais max speed à 30
User prompt
dans limitSpeed ajoute une constante au lieu de répéter la valeur 10
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'collisionBody')' in or related to this line: 'if (self.intersects(player1.collisionBody) || self.intersects(player2.collisionBody)) {' Line Number: 81
User prompt
Quand la balle touche le sol, elle doit être réinitialisée.
Code edit (15 edits merged)
Please save this source code
User prompt
Les joueurs marquent un point quand la balle touche le sol du côté de l'adversaire.
User prompt
La fonction update de la balle est déjà appelée automatiquement Il ne faut pas l'appeler dans la fonction update générale du jeu
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'if (self.x + self.half > net.x - net.width / 2 && self.x - self.half < net.x + net.width / 2) {' Line Number: 64
User prompt
centralise le gestion du mouvement de la balle
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
add a collisionBody to the players on the ball as a public property
User prompt
Limite la vitesse de la balle
Code edit (1 edits merged)
Please save this source code
User prompt
réduit la vitesse de la balle
Code edit (2 edits merged)
Please save this source code
User prompt
Rends le joueur 2 un peu plus rouge
User prompt
Les couleurs des joueurs sont trop prononcées. Elles doivent être plus légères.
User prompt
Ajoute une légère teinte bleue pour le joueur 1 et rouge pour le joueur 2
Code edit (4 edits merged)
Please save this source code
User prompt
utilise scale x au lieu de flip x
User prompt
Pour le joueur 2, on retourne l'image horizontalement.
User prompt
Passe un index dans la classe Player pour différencier le joueur 1 du joueur 2.
User prompt
La physique de la balle, c'est du n'importe quoi. Corrige cela.
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.half = self.width / 2;
self.speedX = 5;
self.speedY = 5;
self.update = function () {
if (!ballCanMove) {
return;
}
self.speedY += 0.5; // Gravity effect
// Update position
self.x += self.speedX;
self.y += self.speedY;
// Check for collisions with walls
if (self.x - self.half <= 0 || self.x + self.half >= 2048) {
self.speedX *= -1;
}
if (self.y - self.half <= 0 || self.y + self.half >= 2000) {
self.speedY *= -1;
}
// Check for collisions with the net
if (self.x + self.half > net.x - net.width / 2 && self.x - self.half < net.x + net.width / 2) {
if (self.y + self.half > net.y - net.height && self.y - self.half < net.y) {
self.speedY *= -1; // Bounce effect when hitting the top of the net
self.y = net.y - net.height - self.half; // Adjust position to be above the net
} else if (self.y - self.half < net.y && self.y + self.half > net.y - net.height) {
self.speedX *= -1; // Reflect horizontally when hitting the side of the net
if (self.x < net.x) {
self.x = net.x - net.width / 2 - self.half; // Adjust position to the left of the net
} else {
self.x = net.x + net.width / 2 + self.half; // Adjust position to the right of the net
}
}
}
// Check for collisions with players
if (self.intersects(player1) || self.intersects(player2)) {
self.speedY = -10; // Bounce upward
self.speedX = (self.x - (self.intersects(player1) ? player1.x : player2.x)) * 0.1; // Reflect based on collision point
}
// Check for ground collision
if (self.y + self.half >= 2000) {
self.speedY *= -0.8; // Bounce effect
self.y = 2000 - self.half; // Reset position to ground level considering ball's height
}
};
});
// Net class
var Net = Container.expand(function () {
var self = Container.call(this);
var netGraphics = self.attachAsset('net', {
anchorX: 0.5,
anchorY: 1
});
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
// Player update logic
if (self.jumping) {
self.y -= 20; // Increase jump speed
if (self.y <= 1300) {
// Adjust jump height as needed
self.jumping = false;
}
} else if (self.y < 2000) {
self.y += 20; // Increase fall speed for smoother jump
}
if (self.y < 0) {
self.y = 0; // Prevent player1 from moving above the window
}
if (self.x > 1024 && self.x < 1024 + self.width / 2) {
self.x = 1024 + self.width / 2; // Prevent player2 from moving past the net
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var ballCanMove = false;
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
var player2Debug = true;
var player1 = game.addChild(new Player());
player1.x = 512;
player1.y = 2000;
var player2 = game.addChild(new Player());
player2.x = 1536;
player2.y = 2000;
var net = game.addChild(new Net());
net.x = 2048 / 2;
net.y = 2000;
var ball = game.addChild(new Ball());
ball.x = player1.x;
ball.y = 1300; // Set the ball's initial vertical position to y = 300
var score1 = 0;
var score2 = 0;
var scoreTxt1 = new Text2('0', {
size: 100,
fill: "#ffffff"
});
scoreTxt1.anchor.set(0.5, 0);
LK.gui.topLeft.addChild(scoreTxt1);
var scoreTxt2 = new Text2('0', {
size: 100,
fill: "#ffffff"
});
scoreTxt2.anchor.set(0.5, 0);
LK.gui.topRight.addChild(scoreTxt2);
game.update = function () {
ball.update(net, player1, player2);
player1.update();
player2.update();
if (ball.x <= 0) {
score1++;
scoreTxt1.setText(score1);
resetBall();
} else if (ball.x >= 2732) {
score2++;
scoreTxt2.setText(score2);
resetBall();
}
if (ball.intersects(player1) || ball.intersects(player2)) {
ball.speedY = -10; // Bounce upward
ball.speedX = (ball.x - (ball.intersects(player1) ? player1.x : player2.x)) * 0.1; // Reflect based on collision point
}
};
function resetBall() {
ball.x = player1.x;
ball.y = 1400; // Set the ball's initial vertical position to y = 1400
ball.speedX = 5;
ball.speedY = -10; // Initial upward speed
ballCanMove = false; // Reset ball movement flag
}
game.down = function (x, y, obj) {
if (x <= 1024 - player1.width / 2 && x >= player1.width / 2) {
player1.x = x;
}
if (y < player1.y) {
player1.jumping = true;
}
if (ball.intersects(player1) || ball.intersects(player2)) {
ballCanMove = true;
}
if (player1.y < 0) {
player1.y = 0; // Prevent player1 from moving above the window
}
if (player2Debug && player2.y < 0) {
player2.y = 0; // Prevent player2 from moving above the window
}
if (player2Debug && player2.y < 0) {
player2.y = 0; // Prevent player2 from moving above the window
}
if (player2Debug && x >= 1024 + player2.width / 2 && x <= 2048 - player2.width / 2 && x >= player2.width / 2) {
player2.x = x;
}
if (y < player2.y) {
player2.jumping = true;
}
};
game.move = function (x, y, obj) {
if (x + player1.width / 2 <= 1024 && x - player1.width / 2 >= 0) {
player1.x = x;
}
if (player2Debug && x - player2.width / 2 >= 1024 && x + player2.width / 2 <= 2048) {
player2.x = x;
}
if (player2Debug && x < 1024 + player2.width / 2) {
player2.x = 1024 + player2.width / 2; // Prevent player2 from moving past the net
}
if (player1.y < 0) {
player1.y = 0; // Prevent player1 from moving above the window
}
};
game.up = function (x, y, obj) {
// No action needed on up event
};
white volley ball.
top view of a concave blue (0xADD8E6) plastic button. 4 small black directionnal chevrons engraved : right, left, top , bottom.. Photorealistic
Beach ball. photo
full view of a Beach white towel with colored infinte logo. placed on the sand. photo
Start button in the shape of a white beach volleyball with « START » written on it in black. Photo