User prompt
после того, как мяч совершил 3 касания, на месте второй корзины появляется первая
User prompt
изначально появляется только корзина 2
User prompt
удалить логику работы корзины
User prompt
взять картинку из basket2
User prompt
Добавить корзину2
User prompt
add basket 2 assets
User prompt
add basket2
User prompt
изначально появляется basket2, после трех отскоков на его месте появляется basket
User prompt
добавить basket2
User prompt
Please fix the bug: 'ReferenceError: countdownInterval is not defined' in or related to this line: 'if (!countdownInterval) {' Line Number: 121
User prompt
удалить текст в левом верхнем углу
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'width')' in or related to this line: 'var graffiti = game.addChild(LK.getAsset('graffiti', {' Line Number: 94
User prompt
переместить картинку граффити в левый верхний угол экрана
User prompt
добавить картинку граффити чуть выше центра экрана
User prompt
Исправить ошибку, когда корзина не появилась на новом месте, после того как мяч не попал в корзину
User prompt
Если после броска, мяч не попал в корзину, корзины появляется рандомно на новом месте
Code edit (5 edits merged)
Please save this source code
User prompt
убрать условие, когда после броска картинка исчезает
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
переместить картинку SWIPE в нижнюю часть экрана по середине
User prompt
добавить картинку SWIPE в середине экрана перед началом игры, как мяч будет брошен, картинка SWIPE пропадает
Code edit (3 edits merged)
Please save this source code
User prompt
корзина появляется в рандомном месте на расстоянии y= От 500 до 1500, Х = от 300 до 2000
Code edit (7 edits merged)
Please save this source code
/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // 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 = 0; self.speedY = 0; self.isMoving = false; self.launch = function (speedX, speedY) { self.speedX = speedX; self.speedY = speedY; self.isMoving = true; }; self.bounceCount = 0; // Initialize bounce counter self.update = function () { if (self.isMoving) { self.x += self.speedX; self.y += self.speedY; self.speedY += 0.98; // Gravity effect // Change the direction of the ball's rotation based on its direction if (self.speedX > 0) { ballGraphics.rotation += 0.1; } else if (self.speedX < 0) { ballGraphics.rotation -= 0.1; } if (self.bounceCount >= 20) { // Stop the ball after 20 bounces self.speedX = 0; self.speedY = 0; self.isMoving = false; // Reset the ball to its initial position immediately self.reset(); self.bounceCount = 0; // Reset the bounce counter } } }; self.reset = function () { self.x = 400; // Center horizontally self.y = 1800; // Start position near bottom self.speedX = 0; self.speedY = 0; self.isMoving = false; }; }); // Basket class var Basket = Container.expand(function () { var self = Container.call(this); var basketGraphics = self.attachAsset('basket', { anchorX: 0.5, anchorY: 0.5 }); }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('Player', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('Background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 })); var player = game.addChild(new Player()); player.x = player.width / 2; // Position on the left side of the screen player.y = 2732 - player.height / 2; // Position at the bottom of the screen var ball = game.addChild(new Ball()); ball.x = 400; ball.y = 1800; var baskets = []; var basket = game.addChild(new Basket()); basket.x = Math.random() * (2000 - 400) + 150; // Random x-coordinate between 100 and 2000 basket.y = Math.random() * (1500 - 150) + 150; // Random y-coordinate between 100 and 500 baskets.push(basket); var lastTouchPosition = { x: 0, y: 0 }; // Initialize countdown timer text var countdownTimerTxt = new Text2('20', { size: 150, fill: "#000000" }); countdownTimerTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(countdownTimerTxt); countdownTimerTxt.x -= 80; var countdownTimer = 20; var countdownInterval = null; game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); lastTouchPosition.x = pos.x; lastTouchPosition.y = pos.y; // Start countdown timer after game starts if (!countdownInterval) { countdownInterval = LK.setInterval(function () { countdownTimer--; countdownTimerTxt.setText(countdownTimer); if (countdownTimer <= 0) { LK.clearInterval(countdownInterval); // Create a text object to display the number of goals scored var goalsScoredTxt = new Text2(LK.getScore(), { size: 150, fill: "#ffffff" }); goalsScoredTxt.anchor.set(0.5, 0); // Position the text at the top left of the screen goalsScoredTxt.x = 80; goalsScoredTxt.y = 80; // Add the text to the GUI overlay LK.gui.topLeft.addChild(goalsScoredTxt); LK.showGameOver(); // Reset countdown timer when game is over countdownTimer = 20; countdownTimerTxt.setText(countdownTimer); LK.clearInterval(countdownInterval); countdownInterval = null; } }, 1000); } }); game.on('up', function (obj) { if (!ball.isMoving) { var pos = obj.event.getLocalPosition(game); var speedX = (pos.x - lastTouchPosition.x) / 10; var speedY = (pos.y - lastTouchPosition.y) / 10; ball.launch(speedX, speedY); } }); var ballStoppedTimer = null; LK.on('tick', function () { ball.update(); // Check for collisions with baskets baskets.forEach(function (basket) { if (Math.sqrt(Math.pow(ball.x - basket.x, 2) + Math.pow(ball.y - basket.y, 2)) <= ball.width / 2 + basket.width / 2) { if (ball.bounceCount >= 3) { LK.effects.flashScreen(0x00FF00, 500); // Flash green for success ball.reset(); // Reset the countdown timer countdownTimer = 20; countdownTimerTxt.setText(countdownTimer); // Move the basket to a random location at the top of the screen basket.x = Math.random() * (2000 - 400) + 150; // Random x-coordinate between 100 and 2000 basket.y = Math.random() * (1500 - 150) + 150; // Random y-coordinate between 100 and 500 ball.bounceCount = 0; // Reset the bounce counter // Increment the number of goals scored LK.setScore(LK.getScore() + 1); } } }); // Bounce off the walls and ceiling if (ball.x < 100) { ball.x = 100; // Move the ball out of the wall ball.speedX *= -0.8; // Decrease speed by 10% after bouncing ball.speedX *= 0.75; // Decrease the next bounce by 20% ball.bounceCount++; // Increment bounce counter } if (ball.x > 2000) { ball.x = 2000; // Move the ball out of the wall ball.speedX *= -0.8; // Decrease speed by 10% after bouncing ball.speedX *= 0.75; // Decrease the next bounce by 20% ball.bounceCount++; // Increment bounce counter } if (ball.y < 100) { ball.y = 100; // Move the ball out of the ceiling ball.speedY *= -0.8; // Decrease speed by 10% after bouncing ball.speedY *= 0.75; // Decrease the next bounce by 20% ball.bounceCount++; // Increment bounce counter } if (ball.y > 2632) { ball.y = 2632; // Move the ball out of the floor ball.speedY *= -0.8; // Decrease speed by 10% after bouncing ball.speedY *= 0.75; // Decrease the next bounce by 20% ball.bounceCount++; // Increment bounce counter } // Check if the ball has stopped moving and if it has been launched if (ball.speedX === 0 && ball.speedY === 0 && ball.isMoving) { // Start a timer if it's not already started if (!ballStoppedTimer) { ballStoppedTimer = LK.setTimeout(function () { // Reset the ball to its initial position if it has been stopped for 1 second ball.reset(); }, 1000); } } else { // Clear the timer if the ball starts moving again if (ballStoppedTimer) { LK.clearTimeout(ballStoppedTimer); ballStoppedTimer = null; } } });
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// 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 = 0;
self.speedY = 0;
self.isMoving = false;
self.launch = function (speedX, speedY) {
self.speedX = speedX;
self.speedY = speedY;
self.isMoving = true;
};
self.bounceCount = 0; // Initialize bounce counter
self.update = function () {
if (self.isMoving) {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += 0.98; // Gravity effect
// Change the direction of the ball's rotation based on its direction
if (self.speedX > 0) {
ballGraphics.rotation += 0.1;
} else if (self.speedX < 0) {
ballGraphics.rotation -= 0.1;
}
if (self.bounceCount >= 20) {
// Stop the ball after 20 bounces
self.speedX = 0;
self.speedY = 0;
self.isMoving = false;
// Reset the ball to its initial position immediately
self.reset();
self.bounceCount = 0; // Reset the bounce counter
}
}
};
self.reset = function () {
self.x = 400; // Center horizontally
self.y = 1800; // Start position near bottom
self.speedX = 0;
self.speedY = 0;
self.isMoving = false;
};
});
// Basket class
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('Player', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('Background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
var player = game.addChild(new Player());
player.x = player.width / 2; // Position on the left side of the screen
player.y = 2732 - player.height / 2; // Position at the bottom of the screen
var ball = game.addChild(new Ball());
ball.x = 400;
ball.y = 1800;
var baskets = [];
var basket = game.addChild(new Basket());
basket.x = Math.random() * (2000 - 400) + 150; // Random x-coordinate between 100 and 2000
basket.y = Math.random() * (1500 - 150) + 150; // Random y-coordinate between 100 and 500
baskets.push(basket);
var lastTouchPosition = {
x: 0,
y: 0
};
// Initialize countdown timer text
var countdownTimerTxt = new Text2('20', {
size: 150,
fill: "#000000"
});
countdownTimerTxt.anchor.set(0.5, 0);
LK.gui.topRight.addChild(countdownTimerTxt);
countdownTimerTxt.x -= 80;
var countdownTimer = 20;
var countdownInterval = null;
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
lastTouchPosition.x = pos.x;
lastTouchPosition.y = pos.y;
// Start countdown timer after game starts
if (!countdownInterval) {
countdownInterval = LK.setInterval(function () {
countdownTimer--;
countdownTimerTxt.setText(countdownTimer);
if (countdownTimer <= 0) {
LK.clearInterval(countdownInterval);
// Create a text object to display the number of goals scored
var goalsScoredTxt = new Text2(LK.getScore(), {
size: 150,
fill: "#ffffff"
});
goalsScoredTxt.anchor.set(0.5, 0);
// Position the text at the top left of the screen
goalsScoredTxt.x = 80;
goalsScoredTxt.y = 80;
// Add the text to the GUI overlay
LK.gui.topLeft.addChild(goalsScoredTxt);
LK.showGameOver();
// Reset countdown timer when game is over
countdownTimer = 20;
countdownTimerTxt.setText(countdownTimer);
LK.clearInterval(countdownInterval);
countdownInterval = null;
}
}, 1000);
}
});
game.on('up', function (obj) {
if (!ball.isMoving) {
var pos = obj.event.getLocalPosition(game);
var speedX = (pos.x - lastTouchPosition.x) / 10;
var speedY = (pos.y - lastTouchPosition.y) / 10;
ball.launch(speedX, speedY);
}
});
var ballStoppedTimer = null;
LK.on('tick', function () {
ball.update();
// Check for collisions with baskets
baskets.forEach(function (basket) {
if (Math.sqrt(Math.pow(ball.x - basket.x, 2) + Math.pow(ball.y - basket.y, 2)) <= ball.width / 2 + basket.width / 2) {
if (ball.bounceCount >= 3) {
LK.effects.flashScreen(0x00FF00, 500); // Flash green for success
ball.reset();
// Reset the countdown timer
countdownTimer = 20;
countdownTimerTxt.setText(countdownTimer);
// Move the basket to a random location at the top of the screen
basket.x = Math.random() * (2000 - 400) + 150; // Random x-coordinate between 100 and 2000
basket.y = Math.random() * (1500 - 150) + 150; // Random y-coordinate between 100 and 500
ball.bounceCount = 0; // Reset the bounce counter
// Increment the number of goals scored
LK.setScore(LK.getScore() + 1);
}
}
});
// Bounce off the walls and ceiling
if (ball.x < 100) {
ball.x = 100; // Move the ball out of the wall
ball.speedX *= -0.8; // Decrease speed by 10% after bouncing
ball.speedX *= 0.75; // Decrease the next bounce by 20%
ball.bounceCount++; // Increment bounce counter
}
if (ball.x > 2000) {
ball.x = 2000; // Move the ball out of the wall
ball.speedX *= -0.8; // Decrease speed by 10% after bouncing
ball.speedX *= 0.75; // Decrease the next bounce by 20%
ball.bounceCount++; // Increment bounce counter
}
if (ball.y < 100) {
ball.y = 100; // Move the ball out of the ceiling
ball.speedY *= -0.8; // Decrease speed by 10% after bouncing
ball.speedY *= 0.75; // Decrease the next bounce by 20%
ball.bounceCount++; // Increment bounce counter
}
if (ball.y > 2632) {
ball.y = 2632; // Move the ball out of the floor
ball.speedY *= -0.8; // Decrease speed by 10% after bouncing
ball.speedY *= 0.75; // Decrease the next bounce by 20%
ball.bounceCount++; // Increment bounce counter
}
// Check if the ball has stopped moving and if it has been launched
if (ball.speedX === 0 && ball.speedY === 0 && ball.isMoving) {
// Start a timer if it's not already started
if (!ballStoppedTimer) {
ballStoppedTimer = LK.setTimeout(function () {
// Reset the ball to its initial position if it has been stopped for 1 second
ball.reset();
}, 1000);
}
} else {
// Clear the timer if the ball starts moving again
if (ballStoppedTimer) {
LK.clearTimeout(ballStoppedTimer);
ballStoppedTimer = null;
}
}
});
Basket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Стена белая синия. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
граффити слово Swipe. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Граффити с текстом "after three bounces of the ball, a goal is scored". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.