User prompt
IT DOESNT WORK!
User prompt
Then get it done so it works properly!
User prompt
Then do these to count the machine's paddle scoring too!
User prompt
When the game paddle touches the ball, the speed of the ball should be only half as fast, because it will only shake!
User prompt
Then fix the problem so that it doesn't happen again!
User prompt
If the ball stops, paddlet pull up to iceGateTop and push the ball away.
User prompt
THE PLAYER'S PADDLET SHOULD HAVE ROOM FOR MANOEUVRE THROUGHOUT THE SCREEN!
User prompt
Then do it!
User prompt
Then do it!
User prompt
Slow down the speed of the ball a little so the ball doesn't bounce so much.
User prompt
Then do it!
User prompt
Make that machine paddlet a little smarter!
User prompt
Add 100 units of leeway in each direction for paddlet.
User prompt
Add 50 units of leeway in each direction.
User prompt
Slow down the speed of the ball a little so the ball doesn't bounce so much.
User prompt
Why does the paddlet of the machine squeeze the ball and therefore stop the ball?
User prompt
The machine paddlet never gets under the ball!
User prompt
At the start of the game and after each scoring, the ball is placed in the center of the field!
User prompt
The machine paddlet should never squeeze the ball!
User prompt
Slow down the speed of the ball a little so the ball doesn't bounce so much.
User prompt
Slow down the speed of the ball a little so the ball doesn't bounce so much.
User prompt
Then do it!
User prompt
Add more power when the player pushes the ball!
User prompt
THEN DO IT!
User prompt
IF THE PLAYER HITS THE BALL WITH A STRONGER SWING WITH HIS PADDLET THE BALL WILL BE FASTER WITH THIS POWER OF SWING
/****
* 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.speedY = 10.8;
self.speedX = 0;
self.update = function () {
self.y += self.speedY;
self.x += self.speedX;
if (self.y <= 50 || self.y >= 2682) {
self.speedY *= -1;
}
if (self.x <= 150 || self.x >= 1898) {
self.speedX *= -1;
if ((self.y <= 200 || self.y >= 2532) && (lastCornerHit === null || Date.now() - lastCornerHit > 1000)) {
cornerHits++;
lastCornerHit = Date.now();
if (cornerHits >= 3) {
opponentPaddle.y -= 50; // Move opponent closer to iceGateTop
cornerHits = 0; // Reset counter
}
}
}
// Removed redundant check for ball going out sideways
if (self.y >= 2732 || self.y <= 0) {
self.x = 2048 / 2;
self.y = 1366; // Center of the field
self.speedX = 0;
self.speedY = 10; // Reset speed
}
// Removed redundant check for ball going out sideways
if (self.y >= 2732) {
self.speedY *= -1;
}
// Removed redundant check for ball going out sideways
if (self.y >= 2732) {
self.speedY *= -1;
}
// Removed redundant check for ball going out sideways
if (self.y >= 2732) {
self.speedY *= -1;
}
// Removed redundant check for ball going out sideways
if (self.y >= 2732) {
self.speedY *= -1;
}
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y >= 2732) {
self.speedY *= -1;
}
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
// Check for collision with player paddle
if (self.intersects(paddle)) {
// Calculate swing strength based on paddle's movement speed
var swingStrength = Math.abs(paddle.prevY - paddle.y) / 10;
var speedMultiplier = 1 + swingStrength;
// Temporarily increase ball speed based on swing strength for 1 second
self.speedY *= speedMultiplier;
setTimeout(function () {
self.speedY /= speedMultiplier;
}, 1000);
// Calculate the angle of incidence based on where the ball hits the paddle
var relativeIntersectX = (paddle.x - self.x) / (paddle.width / 2);
var bounceAngle = relativeIntersectX * Math.PI / 4; // Max bounce angle of 45 degrees
// Update ball speed and direction
self.speedX = self.speedY * Math.sin(bounceAngle);
self.speedY = -Math.abs(self.speedY * Math.cos(bounceAngle));
}
// Check for collision with opponent paddle
if (self.intersects(opponentPaddle)) {
// Calculate the angle of incidence based on where the ball hits the paddle
var relativeIntersectX = (opponentPaddle.x - self.x) / (opponentPaddle.width / 2);
var bounceAngle = relativeIntersectX * Math.PI / 4; // Max bounce angle of 45 degrees
// Update ball speed and direction
self.speedX = self.speedY * Math.sin(bounceAngle);
self.speedY = Math.abs(self.speedY * Math.cos(bounceAngle));
}
};
});
var IceGate = Container.expand(function (color) {
var self = Container.call(this);
var gateGraphics = self.attachAsset(color === 'top' ? 'iceGateTop' : 'iceGateBottom', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Opponent Paddle class
var OpponentPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('playerPaddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.idleTime = 0;
self.update = function () {
if (self.prevX === self.x && self.prevY === self.y) {
self.idleTime += 1 / 60; // Increment idle time by 1/60th of a second
} else {
self.idleTime = 0; // Reset idle time if paddle has moved
}
self.prevX = self.x;
self.prevY = self.y;
if (self.idleTime > 1) {
// Retreat towards the center of the track
if (self.x < 2048 / 2) {
self.x += 5;
} else if (self.x > 2048 / 2) {
self.x -= 5;
}
if (self.y < 1366 / 2) {
self.y += 5;
} else if (self.y > 1366 / 2) {
self.y -= 5;
}
}
// Opponent paddle AI logic
if (ball.y < self.y) {
self.y -= 5;
} else if (ball.y > self.y && self.y < 1366) {
// Ensure opponent cannot move lower than halfway through the field
self.y += 5;
}
if (ball.x < self.x && self.x > ball.width / 2) {
self.x -= 5;
} else if (ball.x > self.x && self.x < 2048 - ball.width / 2) {
self.x += 5;
}
// Removed opponent paddle intersection logic to prevent blocking the ball
// Check if ball is in the corner of the field
if (ball.x <= 200 && ball.y <= 200 || ball.x >= 1848 && ball.y <= 200) {
// Pull opponent paddle towards its own goal
if (self.y < 200) {
self.y += 5;
}
}
// Ensure the paddle stays within the screen bounds and does not overlap with player paddle
self.y = Math.max(200 + self.height / 2, Math.min(self.y, 1366 - 200 - self.height / 2));
self.x = Math.max(200 + self.width / 2, Math.min(self.x, 2048 - 200 - self.width / 2));
// Prevent overlap with player paddle
if (self.intersects(paddle)) {
if (self.y < paddle.y) {
self.y = paddle.y - self.height;
} else {
self.y = paddle.y + paddle.height;
}
}
// Ensure opponent paddle stays within the screen bounds
if (self.y < 200) {
self.y = 200;
}
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Ensure player paddle does not overlap with opponent paddle
if (self.intersects(opponentPaddle)) {
if (self.y < opponentPaddle.y) {
self.y = opponentPaddle.y - self.height;
} else {
self.y = opponentPaddle.y + opponentPaddle.height;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
scaleMode: 'fullScreen' // Enable full screen scaling for smartphones
});
/****
* Game Code
****/
// Attach white background asset
var cornerHits = 0;
var lastCornerHit = null;
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: -1765,
y: -690
});
game.addChild(background);
// Initialize ice hockey goals
var topGoal = game.addChild(new IceGate('top'));
topGoal.x = 2048 / 2 - 10;
topGoal.y = 50 - 45;
var bottomGoal = game.addChild(new IceGate('bottom'));
bottomGoal.x = 2048 / 2 - 10;
bottomGoal.y = 2732 - 50 + 40;
// Initialize ball and paddles
var ball = game.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 50 + ball.height / 2;
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2500 + 500;
var opponentPaddle = game.addChild(new OpponentPaddle());
opponentPaddle.prevX = opponentPaddle.x;
opponentPaddle.prevY = opponentPaddle.y;
opponentPaddle.x = 2048 / 2;
opponentPaddle.y = 200;
opponentPaddle.x = 2048 / 2;
// Score display
var playerScore = 0;
var opponentScore = 0;
var scoreTxt = new Text2('0-0', {
size: 150,
fill: "#FFD700" // Golden yellow color
});
scoreTxt.anchor.set(0.5, 0.5);
scoreTxt.rotation = -Math.PI / 2; // Rotate 180 degrees to the left
scoreTxt.x = 2048 - 100; // Position 100 units from the right edge of the screen
scoreTxt.y = 1366 - 25; // Move up by 25 units
game.addChild(scoreTxt);
// Handle paddle movement
game.move = function (x, y, obj) {
paddle.x = x;
paddle.y = y;
};
// Update game logic
game.update = function () {
ball.update();
paddle.update();
opponentPaddle.update();
// Check for collision between ball and iceGateTop
if (ball.intersects(topGoal)) {
playerScore++;
scoreTxt.setText(playerScore + '-' + opponentScore);
ball.x = 2048 / 2;
ball.y = 1366; // Center of the field
ball.speedX = 0;
ball.speedY = 10.5;
}
// Check if ball hits the bottom of the screen
if (ball.y >= 2732 || ball.y <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
ball.speedX = 0;
ball.speedY = 10.5;
ball.x = 2048 / 2;
ball.y = 1366; // Center of the field
opponentPaddle.x = 2048 / 2;
opponentPaddle.y = 200;
if (ball.intersects(bottomGoal)) {
opponentScore++;
scoreTxt.setText(playerScore + '-' + opponentScore);
ball.x = 2048 / 2;
ball.y = 1366; // Center of the field
ball.speedX = 0;
ball.speedY = 10;
}
cornerHits = 0; // Reset cornerHits counter
lastCornerHit = null; // Reset lastCornerHit timestamp
}
};
New ball button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
air hockey table with neon lights. top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Air hockey disk with neon green lights. top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Air hockey disk with neon yellow lights. top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Air hockey disk with neon orange lights. top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.