User prompt
Move the background to the left by 50 units
User prompt
Ensure the ball maintains a distance of 50 units from the upper edges of the image. Reset ball position to maintain a distance of 50 units from the upper edges
User prompt
Ensure the ball maintains a distance of 50 units from the upper edges of the image Reset ball position to maintain a distance of 150 units from the side edges
User prompt
Ensure the ball maintains a distance of 150 units from the side edges of the image Reset ball position to maintain a distance of 150 units from the side edges
User prompt
Move the background to the left by 10 units
User prompt
Move the background to the left by 100 units
User prompt
Move the background to the right by 100 units
User prompt
Move the background to the left by 150 units
User prompt
Move the background to the right by 150 units
User prompt
Move the background to the right by 200 units
User prompt
Move the background to the right by 300 units
User prompt
move the background to right with 300 units
User prompt
The distance between the ball and the side edges of the image is 200 units
User prompt
The distance between the ball and the side edges of the image is 90units
User prompt
The distance between the ball and the side edges of the image is 50 units
User prompt
The distance between the ball and the side edges of the image is 100 units
User prompt
If the player touches the ball, the movement of the ball accelerates to 1.5 x faster until it touches the sidelines. As soon as the ball touches the edge of the field, its speed will be the original again.
User prompt
If the player touches the ball, the movement of the ball accelerates to 1.5 x faster until it touches the sidelines.
User prompt
A computer-controlled opponent can only move anywhere in the upper half of the map.
User prompt
The opponent can move as far as he wants in his own half, but he cannot come lower than halfway through the field.
User prompt
The ball bounces off all sides of the field
User prompt
The ball and player must not touch each other
User prompt
The ball and player must not touch or obscure each other.
User prompt
Only color the player paddle blue.
User prompt
When they touch each other, the machine paddles slide away 100 units.
/**** * 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; self.speedX = 0; self.update = function () { self.y += self.speedY; self.x += self.speedX; if (self.y <= 0 || self.y >= 2732) { self.speedY *= -1; } if (self.x <= 200 || self.x >= 1848) { 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 } } } if (self.x <= 0 || self.x >= 2048) { self.speedX *= -1; self.speedY = self.speedY > 0 ? 10 : -10; // Reset speed to original self.speedX = self.speedX > 0 ? 10 : -10; // Reset speed to original } 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.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.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; } if (self.intersects(paddle)) { var angle = Math.atan2(self.y - paddle.y, self.x - paddle.x); self.speedY = -15 * Math.cos(angle); // Accelerate speed by 1.5x self.speedX = 15 * Math.sin(angle); // Accelerate speed by 1.5x } if (self.intersects(opponentPaddle)) { var angle = Math.atan2(self.y - opponentPaddle.y, self.x - opponentPaddle.x); self.speedY = 10 * Math.cos(angle); self.speedX = 10 * Math.sin(angle); // Ensure ball doesn't go out of bounds if (self.x <= 200) { self.x = 200 + ball.width / 2; self.speedX = Math.abs(self.speedX); } else if (self.x >= 1848) { self.x = 1848 - ball.width / 2; self.speedX = -Math.abs(self.speedX); } } }; }); 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; } // Ensure paddles do not touch each other if (self.intersects(paddle)) { if (self.x < paddle.x) { self.x -= 100; } else { self.x += 100; } } // 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 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)); // 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 paddles do not touch each other if (self.intersects(opponentPaddle)) { if (self.x < opponentPaddle.x) { self.x -= 100; } else { self.x += 100; } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Attach white background asset var cornerHits = 0; var lastCornerHit = null; var background = LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, x: -1730, y: -700 }); game.addChild(background); // Initialize ice hockey goals var topGoal = game.addChild(new IceGate('top')); topGoal.x = 2048 / 2; topGoal.y = 50 - 45; var bottomGoal = game.addChild(new IceGate('bottom')); bottomGoal.x = 2048 / 2; bottomGoal.y = 2732 - 50 + 40; // Initialize ball and paddles var ball = game.addChild(new Ball()); ball.x = 2048 / 2; ball.y = 2732 / 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 score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.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 paddle if (ball.intersects(paddle)) { ball.speedY *= -1; score++; scoreTxt.setText(score); } // Check if ball hits the bottom of the screen if (ball.y >= 2732) { LK.effects.flashScreen(0xff0000, 1000); ball.speedX = 0; ball.speedY = 10; ball.x = 2048 / 2; ball.y = 2732 / 2; opponentPaddle.x = 2048 / 2; opponentPaddle.y = 200; score = 0; scoreTxt.setText(score); cornerHits = 0; // Reset cornerHits counter lastCornerHit = null; // Reset lastCornerHit timestamp } };
===================================================================
--- original.js
+++ change.js
@@ -198,9 +198,9 @@
var lastCornerHit = null;
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
- x: -1530,
+ x: -1730,
y: -700
});
game.addChild(background);
// Initialize ice hockey goals
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.