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.
Code edit (1 edits merged)
Please save this source code
User prompt
Au début, la balle ne doit pas bouger jusqu'à ce qu'un joueur la touche.
User prompt
add an image background
User prompt
Actuellement la balle ne se coince pas, par contre elle ne peut pas passer au dessus du filet.
User prompt
Actuellement, la balle se coince dans le filet. Corrigez cela.
User prompt
Ré-imaginez quelque chose de plus simple et de plus efficace, car la balle traverse toujours le filet actuellement.
User prompt
ne pas utiliser intersect pour le filet mais utiliser la position du filet
User prompt
La balle ne doit bouger que si le mouvement est possible.
Code edit (1 edits merged)
Please save this source code
User prompt
in Ball class, instead of using `self.width / 2` add a property half
User prompt
Toujours pensez à prendre en compte la largeur de l'objet pour vérifier les limites.
/****
* 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.speedX = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += 0.5; // Gravity effect
if (self.x <= 0) {
self.x = 0;
self.speedX *= -1;
} else if (self.x >= 2048 - self.width / 2) {
self.x = 2048 - self.width / 2;
self.speedX *= -1;
}
if (self.y + self.height / 2 >= 2000) {
self.speedY *= -0.8; // Bounce effect
self.y = 2000 - self.height / 2; // Reset position to ground level considering ball's height
}
if (self.y <= 0) {
self.speedY *= -1;
}
if (self.x + self.width / 2 > net.x - net.width / 2 && self.x - self.width / 2 < net.x + net.width / 2) {
if (self.y + self.speedY > net.y - net.height / 2) {
self.speedY *= -1; // Bounce effect when hitting the top of the net
self.y = net.y - net.height / 2 - self.height / 2; // Adjust position to be above the net
} else if (self.intersects(net)) {
if (self.y < net.y - net.height / 2) {
self.speedY *= -1; // Bounce effect when hitting the top of the net
self.y = net.y - net.height / 2 - self.height / 2; // Adjust position to be above the net
} else {
self.speedX *= -1; // Reflect horizontally when hitting the side of the net
self.x += self.speedX; // Move ball out of the net to prevent merging
}
}
}
if (self.intersects(player1) || self.intersects(player2)) {
self.speedX *= -1; // Reflect horizontally when hitting the nose
}
};
});
// 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 <= 1600) {
// 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 player2Debug = true;
var player1 = game.addChild(new Player());
player1.x = 100;
player1.y = 2000;
var player2 = game.addChild(new Player());
player2.x = 1948;
player2.y = 2000;
var net = game.addChild(new Net());
net.x = 2048 / 2;
net.y = 2000;
var ball = game.addChild(new Ball());
var startingPlayer = Math.random() < 0.5 ? player1 : player2;
ball.x = startingPlayer.x;
ball.y = 300; // 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() {
var startingPlayer = Math.random() < 0.5 ? player1 : player2;
ball.x = startingPlayer.x;
ball.y = 300; // Set the ball's initial vertical position to y = 300
ball.speedX = 5;
ball.speedY = -10; // Initial upward speed
}
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 (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