User prompt
oyun 3 ten geri doğru saysın sonra başlasın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
aı daha akıllı olsun
User prompt
skor tablosu ortada olsun
User prompt
skorun yanında kimin olduğuda yazsın
User prompt
tam tersi olcak
User prompt
ama olmuyor tekrar dene
User prompt
rakibin duvarına çarpınca bize, bizim duvarımıza çarpınca rakibe puan gitsin
User prompt
rakibin duvarına çarpıncada bize 1 puan gelsin
User prompt
az önce dediğimin tam tersi
User prompt
sadece yan duvarlardan seksi bizim duvarımıza deyerse rakip 1 puan kazansın
User prompt
ortadan 30 derece açıyla herhangi bir yöne doğru gitsin
User prompt
topu 3 kat hızlandır
User prompt
duvardan seksin
Code edit (1 edits merged)
Please save this source code
User prompt
AI Pong Challenge
Initial prompt
pong oyunu yap karşı taraf yapay zeka olsun
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.baseSpeed = 6;
self.speedMultiplier = 3;
self.reset = function () {
self.x = 2048 / 2;
self.y = 2732 / 2;
self.speedMultiplier = 3;
// Exactly 30 degrees in any random direction
var angle = Math.PI / 6; // 30 degrees
var direction = Math.floor(Math.random() * 8); // 8 possible directions
var finalAngle = angle + direction * Math.PI / 4; // 30°, 75°, 120°, 165°, 210°, 255°, 300°, 345°
self.velocityX = Math.cos(finalAngle) * self.baseSpeed;
self.velocityY = Math.sin(finalAngle) * self.baseSpeed;
};
self.update = function () {
self.x += self.velocityX * self.speedMultiplier;
self.y += self.velocityY * self.speedMultiplier;
// Bounce off top and bottom walls
if (self.y <= 15 || self.y >= 2732 - 15) {
self.velocityY = -self.velocityY;
LK.getSound('wallHit').play();
}
// Check paddle collisions
if (self.intersects(playerPaddle)) {
if (self.velocityY > 0) {
// Ball moving down
self.velocityY = -Math.abs(self.velocityY);
var paddleCenter = playerPaddle.x;
var hitPos = (self.x - paddleCenter) / 100; // Normalize hit position
self.velocityX = hitPos * self.baseSpeed;
self.speedMultiplier = Math.min(self.speedMultiplier + 0.1, 6.0);
LK.getSound('paddleHit').play();
}
}
if (self.intersects(aiPaddle)) {
if (self.velocityY < 0) {
// Ball moving up
self.velocityY = Math.abs(self.velocityY);
var paddleCenter = aiPaddle.x;
var hitPos = (self.x - paddleCenter) / 100; // Normalize hit position
self.velocityX = hitPos * self.baseSpeed;
self.speedMultiplier = Math.min(self.speedMultiplier + 0.1, 6.0);
LK.getSound('paddleHit').play();
}
}
// Bounce off side walls
if (self.x <= 15 || self.x >= 2048 - 15) {
self.velocityX = -self.velocityX;
LK.getSound('wallHit').play();
}
// Check for goals - top and bottom walls
if (self.y <= 0) {
// Ball hit top wall - player scores
playerScore++;
updateScoreDisplay();
LK.getSound('goal').play();
LK.effects.flashScreen(0x00ff00, 500);
self.reset();
if (playerScore >= targetScore) {
LK.showYouWin();
}
} else if (self.y >= 2732) {
// Ball hit bottom wall - AI scores
aiScore++;
updateScoreDisplay();
LK.getSound('goal').play();
LK.effects.flashScreen(0xff0000, 500);
self.reset();
if (aiScore >= targetScore) {
LK.showGameOver();
}
}
};
return self;
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.targetY = 0;
self.isPlayer = false;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var playerScore = 0;
var aiScore = 0;
var targetScore = 10;
var dragNode = null;
// Create center line
var centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
// Create paddles
var playerPaddle = game.addChild(new Paddle());
playerPaddle.x = 2048 / 2;
playerPaddle.y = 2732 - 100;
playerPaddle.isPlayer = true;
var aiPaddle = game.addChild(new Paddle());
aiPaddle.x = 2048 / 2;
aiPaddle.y = 100;
aiPaddle.targetY = aiPaddle.y;
// Create ball
var ball = game.addChild(new Ball());
ball.reset();
// Create score display
var scoreText = new Text2('0 - 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function updateScoreDisplay() {
scoreText.setText(playerScore + ' - ' + aiScore);
}
// AI behavior
function updateAI() {
var ballCenterX = ball.x;
var paddleCenterX = aiPaddle.x;
var difference = ballCenterX - paddleCenterX;
// Only move if ball is coming towards AI
if (ball.velocityY < 0) {
if (Math.abs(difference) > 20) {
if (difference > 0) {
aiPaddle.targetY = aiPaddle.y;
aiPaddle.x += aiPaddle.speed;
} else {
aiPaddle.targetY = aiPaddle.y;
aiPaddle.x -= aiPaddle.speed;
}
}
}
// Keep AI paddle in bounds
if (aiPaddle.x < 100) aiPaddle.x = 100;
if (aiPaddle.x > 2048 - 100) aiPaddle.x = 2048 - 100;
}
// Touch controls
game.down = function (x, y, obj) {
// Check if touch is near player paddle
var distance = Math.sqrt(Math.pow(x - playerPaddle.x, 2) + Math.pow(y - playerPaddle.y, 2));
if (distance < 150 || y > 2732 / 2) {
dragNode = playerPaddle;
}
};
game.move = function (x, y, obj) {
if (dragNode === playerPaddle) {
playerPaddle.x = x;
// Keep paddle in bounds
if (playerPaddle.x < 100) playerPaddle.x = 100;
if (playerPaddle.x > 2048 - 100) playerPaddle.x = 2048 - 100;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
updateAI();
};
// Initialize score display
updateScoreDisplay(); ===================================================================
--- original.js
+++ change.js
@@ -57,21 +57,26 @@
self.speedMultiplier = Math.min(self.speedMultiplier + 0.1, 6.0);
LK.getSound('paddleHit').play();
}
}
- // Check for goals - left and right walls
- if (self.x <= 0) {
- // Ball hit left wall - AI scores
- aiScore++;
+ // Bounce off side walls
+ if (self.x <= 15 || self.x >= 2048 - 15) {
+ self.velocityX = -self.velocityX;
+ LK.getSound('wallHit').play();
+ }
+ // Check for goals - top and bottom walls
+ if (self.y <= 0) {
+ // Ball hit top wall - player scores
+ playerScore++;
updateScoreDisplay();
LK.getSound('goal').play();
- LK.effects.flashScreen(0xff0000, 500);
+ LK.effects.flashScreen(0x00ff00, 500);
self.reset();
- if (aiScore >= targetScore) {
- LK.showGameOver();
+ if (playerScore >= targetScore) {
+ LK.showYouWin();
}
- } else if (self.x >= 2048) {
- // Ball hit right wall - AI scores
+ } else if (self.y >= 2732) {
+ // Ball hit bottom wall - AI scores
aiScore++;
updateScoreDisplay();
LK.getSound('goal').play();
LK.effects.flashScreen(0xff0000, 500);