Code edit (5 edits merged)
Please save this source code
User prompt
update the animation : they should get longer vertically when jumping and get smaller when landing
User prompt
think a lot on the way to do it properly, then animate the blobs (players) when they move (like jellys)
Code edit (1 edits merged)
Please save this source code
User prompt
ball shadow should not rotate (always on the ground)
Code edit (7 edits merged)
Please save this source code
User prompt
move ball update shadow in a dicated function in ball class
User prompt
update ball shadow to look like a real one
User prompt
add shadow in Player and ball class
User prompt
wait 2sec before gameOver
Code edit (1 edits merged)
Please save this source code
User prompt
add a global for finalScore = 15
User prompt
in updateScore, in Check for game over condition, add a big result text "VICTORY!" or "DEFEAT!" at y =700
Code edit (1 edits merged)
Please save this source code
User prompt
Apply the rule : The game ends when one of the two players reach 15 (or more) points and also there is a two-point lead over the other.
User prompt
Please fix the bug: 'TypeError: setInterval is not a function' in or related to this line: 'var moveInterval = setInterval(function () {' Line Number: 239
User prompt
when reseting ball, also move players progressively to their initial X positions
Code edit (1 edits merged)
Please save this source code
User prompt
now use BALL1_INITIAL_X and BALL2_INITIAL_X for ball initial and reset position
Code edit (1 edits merged)
Please save this source code
User prompt
use new variable BALL_INITIAL_Y
Code edit (1 edits merged)
Please save this source code
User prompt
rename both PLAYER1_INITIAL_Y and PLAYER2_INITIAL_Y to PLAYER_INITIAL_Y
Code edit (3 edits merged)
Please save this source code
User prompt
create a updateScore function with an index parameter
===================================================================
--- original.js
+++ change.js
@@ -66,9 +66,9 @@
} else if (self.x + half > 2048) {
self.x = 2048 - half;
self.speedX = -Math.abs(self.speedX); // Make the ball bounce to the left
}
- self.updateShadow();
+ // Collision detection logic moved to game update
};
});
// Net class
var Net = Container.expand(function () {
@@ -89,15 +89,9 @@
scaleX: index === 2 ? -1 : 1,
tint: index === 1 ? 0xADD8E6 : 0xFF6347 // Light blue for player 1, Tomato red for player 2
});
self.index = index;
- // Add shadow
- var shadow = self.attachAsset('shadow', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.5
- });
- shadow.y = 20; // Offset shadow slightly below the player
+ self.scale.set(1, 1); // Initialize player scale to normal
self.jumping = false;
self.falling = false;
self.speedX = 0; // Initialize horizontal speed
var collidSize = 220;
@@ -125,8 +119,10 @@
if (self.y >= PLAYER_INITIAL_Y) {
self.jumping = false;
self.falling = false;
self.y = PLAYER_INITIAL_Y; // Ensure player lands on the ground
+ // Reset scale to normal when player stops moving
+ self.scale.set(1, 1);
}
if (self.y < 0) {
self.y = 0; // Prevent player1 from moving above the window
}
@@ -134,8 +130,12 @@
self.x = 1024 + self.width / 2; // Prevent player2 from moving past the net
}
self.speedX = self.x - prevX; // Calculate horizontal speed based on movement
self.speedY = self.y - prevY; // Calculate vertical speed based on movement
+ // Apply jelly-like animation based on speed
+ var scaleX = 1 + Math.abs(self.speedX) * 0.01;
+ var scaleY = 1 - Math.abs(self.speedY) * 0.01;
+ self.scale.set(scaleX, scaleY);
};
});
/****
@@ -169,9 +169,9 @@
var resetTime; // Global variable to store the reset time
var nextRoundPauseDelay;
var score1;
var score2;
-var finalScore = 1; //15; // Define the final score for the game
+var finalScore = 15; // Define the final score for the game
var servingPlayer = 1; // Initialize serving player to player 1
function playSound(soundId, cooldown) {
var currentTime = Date.now();
if (!lastPlayedTime[soundId] || currentTime - lastPlayedTime[soundId] > cooldown) {
@@ -335,8 +335,13 @@
}
}
// Check for collisions with players
var touchIndex = 0;
+ if (ball.x + ball.width / 2 < 1024) {
+ player2Touches = 0;
+ } else if (ball.x - ball.width / 2 > 1024) {
+ player1Touches = 0;
+ }
if (ball.x < 1024 && customIntersect(ball, player1.collisionBody)) {
touchIndex = 1;
} else if (ball.x > 1024 && customIntersect(ball, player2.collisionBody)) {
touchIndex = 2;
@@ -438,17 +443,19 @@
ball.rotationSpeed = 0;
game.addChild(ball);
scoreTxt1 = new Text2('00', {
size: 200,
- fill: "#00008B",
- fontWeight: "bold"
+ fill: "#0000d8",
+ fontWeight: "bold",
+ dropShadow: true
});
scoreTxt1.anchor.set(-1, 0);
LK.gui.topLeft.addChild(scoreTxt1);
scoreTxt2 = new Text2('00', {
size: 200,
fill: "#FF6347",
- fontWeight: "bold"
+ fontWeight: "bold",
+ dropShadow: true
});
scoreTxt2.anchor.set(2, 0);
LK.gui.topRight.addChild(scoreTxt2);
joystick = game.addChild(LK.getAsset('joystick', {
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