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.
===================================================================
--- original.js
+++ change.js
@@ -15,35 +15,20 @@
self.update = function () {
if (!ballCanMove) {
return;
}
- var newX = self.x + self.speedX;
- var newY = self.y + self.speedY;
- if (newX - self.half > 0 && newX + self.half < 2048) {
- self.x = newX;
- } else {
- self.speedX *= -1;
- }
- if (newY - self.half > 0 && newY + self.half < 2000) {
- self.y = newY;
- } else {
- self.speedY *= -1;
- }
self.speedY += 0.5; // Gravity effect
- if (self.x - self.half <= 0) {
- self.x = 0;
+ // 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;
- } else if (self.x >= 2048 - self.half) {
- self.x = 2048 - self.half;
- self.speedX *= -1;
}
- 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
- }
- if (self.y <= 0) {
+ 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
@@ -55,11 +40,18 @@
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.speedX *= -1; // Reflect horizontally when hitting the nose
+ 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 () {
@@ -115,20 +107,19 @@
});
game.addChild(background);
var player2Debug = true;
var player1 = game.addChild(new Player());
-player1.x = 100;
+player1.x = 512;
player1.y = 2000;
var player2 = game.addChild(new Player());
-player2.x = 1948;
+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());
-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.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,
@@ -160,13 +151,13 @@
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.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;
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