User prompt
Çarpışma çözüm sistemini öngörücü yap
User prompt
Toplar birnirinin içinden geçiyor
User prompt
Toplar birbirinin içinden geçemez
User prompt
Toplar biribirinin üzerine çarptıgında zeminden dışarı cıkıyor
User prompt
Topladı biraz büyült
User prompt
Topları büyült
User prompt
Başlangıcta konteynırın birazı toplarla dolu olsun
User prompt
Toplar konteynır alt çizgisinden aşagı cıkıyor
User prompt
Toplar zemin çizgisinden aşagı düşüyor
User prompt
Olmuyor top yukardan aşagı dogru düşmeye başladıgında zemine varmadan tehlike bölgesine degiyor ve oyun biyitor
User prompt
Top yukardan düşmeye başladıgında tehlike bölgesine dokunup oyun bitti diyor
User prompt
Çalışmıyor
User prompt
Oyun barlıklarını ekle
User prompt
Herşeyi ayarla
Code edit (1 edits merged)
Please save this source code
User prompt
Ball Merge 2048
Initial prompt
Toplarla oynanan 2048 oyunu
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Ball = Container.expand(function (value) { var self = Container.call(this); self.value = value || 2; self.velocityX = 0; self.velocityY = 0; self.gravity = 0.8; self.bounce = 0.4; self.friction = 0.98; self.radius = 40; self.isStatic = false; self.mergeTimer = 0; self.hasBeenMerged = false; var ballAsset = self.attachAsset('ball' + self.value, { anchorX: 0.5, anchorY: 0.5 }); var valueText = new Text2(self.value.toString(), { size: 28, fill: 0xFFFFFF }); valueText.anchor.set(0.5, 0.5); self.addChild(valueText); self.update = function () { if (self.hasBeenMerged) return; if (self.mergeTimer > 0) { self.mergeTimer--; return; } if (!self.isStatic) { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Ground collision if (self.y + self.radius > gameAreaBottom) { self.y = gameAreaBottom - self.radius; self.velocityY *= -self.bounce; self.velocityX *= self.friction; if (Math.abs(self.velocityY) < 1) { self.velocityY = 0; self.isStatic = true; } } // Side walls collision if (self.x - self.radius < gameAreaLeft) { self.x = gameAreaLeft + self.radius; self.velocityX *= -self.bounce; } if (self.x + self.radius > gameAreaRight) { self.x = gameAreaRight - self.radius; self.velocityX *= -self.bounce; } // Ball to ball collisions for (var i = 0; i < balls.length; i++) { var otherBall = balls[i]; if (otherBall === self || otherBall.hasBeenMerged) continue; var dx = otherBall.x - self.x; var dy = otherBall.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); var minDistance = self.radius + otherBall.radius; if (distance < minDistance && distance > 0) { // Check for merge if (self.value === otherBall.value && self.mergeTimer === 0 && otherBall.mergeTimer === 0) { // Merge balls var newValue = self.value * 2; if (newValue <= 2048) { var newBall = new Ball(newValue); newBall.x = (self.x + otherBall.x) / 2; newBall.y = (self.y + otherBall.y) / 2; newBall.velocityX = (self.velocityX + otherBall.velocityX) / 2; newBall.velocityY = (self.velocityY + otherBall.velocityY) / 2; newBall.mergeTimer = 10; balls.push(newBall); gameArea.addChild(newBall); // Mark for removal self.hasBeenMerged = true; otherBall.hasBeenMerged = true; LK.getSound('merge').play(); LK.setScore(LK.getScore() + newValue); scoreText.setText(LK.getScore()); // Check win condition if (newValue === 2048) { LK.showYouWin(); } return; } } // Physical collision var overlap = minDistance - distance; var separationX = dx / distance * overlap * 0.5; var separationY = dy / distance * overlap * 0.5; self.x -= separationX; self.y -= separationY; otherBall.x += separationX; otherBall.y += separationY; // Velocity exchange var relativeVelocityX = self.velocityX - otherBall.velocityX; var relativeVelocityY = self.velocityY - otherBall.velocityY; var collisionForce = (relativeVelocityX * dx + relativeVelocityY * dy) / (distance * distance); self.velocityX -= collisionForce * dx * 0.8; self.velocityY -= collisionForce * dy * 0.8; otherBall.velocityX += collisionForce * dx * 0.8; otherBall.velocityY += collisionForce * dy * 0.8; self.velocityX *= self.friction; self.velocityY *= self.friction; otherBall.velocityX *= otherBall.friction; otherBall.velocityY *= otherBall.friction; } } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x34495e }); /**** * Game Code ****/ var balls = []; var nextBallValue = 2; var gameAreaLeft = 224; var gameAreaRight = 1824; var gameAreaTop = 400; var gameAreaBottom = 2600; var dropCooldown = 0; var gameAreaHeight = gameAreaBottom - gameAreaTop; // Create game area background var gameArea = game.addChild(LK.getAsset('gameArea', { anchorX: 0.5, anchorY: 0, x: 1024, y: gameAreaTop })); // Create score display var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); scoreText.y = 100; // Create next ball preview var nextBallPreview = LK.getAsset('ball' + nextBallValue, { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 300, scaleX: 0.75, scaleY: 0.75 }); game.addChild(nextBallPreview); // Create next ball value text var nextBallText = new Text2(nextBallValue.toString(), { size: 24, fill: 0xFFFFFF }); nextBallText.anchor.set(0.5, 0.5); nextBallText.x = 1024; nextBallText.y = 300; game.addChild(nextBallText); // Create instruction text var instructionText = new Text2('Tap to drop ball', { size: 40, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.x = 1024; instructionText.y = 150; game.addChild(instructionText); function getRandomNextBallValue() { var values = [2, 4, 8]; return values[Math.floor(Math.random() * values.length)]; } function updateNextBallPreview() { game.removeChild(nextBallPreview); game.removeChild(nextBallText); nextBallPreview = LK.getAsset('ball' + nextBallValue, { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 300, scaleX: 0.75, scaleY: 0.75 }); game.addChild(nextBallPreview); nextBallText = new Text2(nextBallValue.toString(), { size: 24, fill: 0xFFFFFF }); nextBallText.anchor.set(0.5, 0.5); nextBallText.x = 1024; nextBallText.y = 300; game.addChild(nextBallText); } function checkGameOver() { for (var i = 0; i < balls.length; i++) { if (balls[i].y - balls[i].radius < gameAreaTop + 100) { LK.showGameOver(); return; } } } function cleanupMergedBalls() { for (var i = balls.length - 1; i >= 0; i--) { if (balls[i].hasBeenMerged) { balls[i].destroy(); balls.splice(i, 1); } } } game.down = function (x, y, obj) { if (dropCooldown > 0) return; // Constrain drop position to game area var dropX = Math.max(gameAreaLeft + 40, Math.min(gameAreaRight - 40, x)); var newBall = new Ball(nextBallValue); newBall.x = dropX; newBall.y = gameAreaTop + 50; newBall.velocityX = 0; newBall.velocityY = 0; balls.push(newBall); gameArea.addChild(newBall); LK.getSound('drop').play(); // Update next ball nextBallValue = getRandomNextBallValue(); updateNextBallPreview(); dropCooldown = 30; // 0.5 seconds at 60fps }; game.update = function () { if (dropCooldown > 0) { dropCooldown--; } cleanupMergedBalls(); checkGameOver(); // Update score display scoreText.setText(LK.getScore()); };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,249 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Ball = Container.expand(function (value) {
+ var self = Container.call(this);
+ self.value = value || 2;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.gravity = 0.8;
+ self.bounce = 0.4;
+ self.friction = 0.98;
+ self.radius = 40;
+ self.isStatic = false;
+ self.mergeTimer = 0;
+ self.hasBeenMerged = false;
+ var ballAsset = self.attachAsset('ball' + self.value, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var valueText = new Text2(self.value.toString(), {
+ size: 28,
+ fill: 0xFFFFFF
+ });
+ valueText.anchor.set(0.5, 0.5);
+ self.addChild(valueText);
+ self.update = function () {
+ if (self.hasBeenMerged) return;
+ if (self.mergeTimer > 0) {
+ self.mergeTimer--;
+ return;
+ }
+ if (!self.isStatic) {
+ self.velocityY += self.gravity;
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Ground collision
+ if (self.y + self.radius > gameAreaBottom) {
+ self.y = gameAreaBottom - self.radius;
+ self.velocityY *= -self.bounce;
+ self.velocityX *= self.friction;
+ if (Math.abs(self.velocityY) < 1) {
+ self.velocityY = 0;
+ self.isStatic = true;
+ }
+ }
+ // Side walls collision
+ if (self.x - self.radius < gameAreaLeft) {
+ self.x = gameAreaLeft + self.radius;
+ self.velocityX *= -self.bounce;
+ }
+ if (self.x + self.radius > gameAreaRight) {
+ self.x = gameAreaRight - self.radius;
+ self.velocityX *= -self.bounce;
+ }
+ // Ball to ball collisions
+ for (var i = 0; i < balls.length; i++) {
+ var otherBall = balls[i];
+ if (otherBall === self || otherBall.hasBeenMerged) continue;
+ var dx = otherBall.x - self.x;
+ var dy = otherBall.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var minDistance = self.radius + otherBall.radius;
+ if (distance < minDistance && distance > 0) {
+ // Check for merge
+ if (self.value === otherBall.value && self.mergeTimer === 0 && otherBall.mergeTimer === 0) {
+ // Merge balls
+ var newValue = self.value * 2;
+ if (newValue <= 2048) {
+ var newBall = new Ball(newValue);
+ newBall.x = (self.x + otherBall.x) / 2;
+ newBall.y = (self.y + otherBall.y) / 2;
+ newBall.velocityX = (self.velocityX + otherBall.velocityX) / 2;
+ newBall.velocityY = (self.velocityY + otherBall.velocityY) / 2;
+ newBall.mergeTimer = 10;
+ balls.push(newBall);
+ gameArea.addChild(newBall);
+ // Mark for removal
+ self.hasBeenMerged = true;
+ otherBall.hasBeenMerged = true;
+ LK.getSound('merge').play();
+ LK.setScore(LK.getScore() + newValue);
+ scoreText.setText(LK.getScore());
+ // Check win condition
+ if (newValue === 2048) {
+ LK.showYouWin();
+ }
+ return;
+ }
+ }
+ // Physical collision
+ var overlap = minDistance - distance;
+ var separationX = dx / distance * overlap * 0.5;
+ var separationY = dy / distance * overlap * 0.5;
+ self.x -= separationX;
+ self.y -= separationY;
+ otherBall.x += separationX;
+ otherBall.y += separationY;
+ // Velocity exchange
+ var relativeVelocityX = self.velocityX - otherBall.velocityX;
+ var relativeVelocityY = self.velocityY - otherBall.velocityY;
+ var collisionForce = (relativeVelocityX * dx + relativeVelocityY * dy) / (distance * distance);
+ self.velocityX -= collisionForce * dx * 0.8;
+ self.velocityY -= collisionForce * dy * 0.8;
+ otherBall.velocityX += collisionForce * dx * 0.8;
+ otherBall.velocityY += collisionForce * dy * 0.8;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ otherBall.velocityX *= otherBall.friction;
+ otherBall.velocityY *= otherBall.friction;
+ }
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x34495e
+});
+
+/****
+* Game Code
+****/
+var balls = [];
+var nextBallValue = 2;
+var gameAreaLeft = 224;
+var gameAreaRight = 1824;
+var gameAreaTop = 400;
+var gameAreaBottom = 2600;
+var dropCooldown = 0;
+var gameAreaHeight = gameAreaBottom - gameAreaTop;
+// Create game area background
+var gameArea = game.addChild(LK.getAsset('gameArea', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 1024,
+ y: gameAreaTop
+}));
+// Create score display
+var scoreText = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 100;
+// Create next ball preview
+var nextBallPreview = LK.getAsset('ball' + nextBallValue, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 300,
+ scaleX: 0.75,
+ scaleY: 0.75
+});
+game.addChild(nextBallPreview);
+// Create next ball value text
+var nextBallText = new Text2(nextBallValue.toString(), {
+ size: 24,
+ fill: 0xFFFFFF
+});
+nextBallText.anchor.set(0.5, 0.5);
+nextBallText.x = 1024;
+nextBallText.y = 300;
+game.addChild(nextBallText);
+// Create instruction text
+var instructionText = new Text2('Tap to drop ball', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.x = 1024;
+instructionText.y = 150;
+game.addChild(instructionText);
+function getRandomNextBallValue() {
+ var values = [2, 4, 8];
+ return values[Math.floor(Math.random() * values.length)];
+}
+function updateNextBallPreview() {
+ game.removeChild(nextBallPreview);
+ game.removeChild(nextBallText);
+ nextBallPreview = LK.getAsset('ball' + nextBallValue, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 300,
+ scaleX: 0.75,
+ scaleY: 0.75
+ });
+ game.addChild(nextBallPreview);
+ nextBallText = new Text2(nextBallValue.toString(), {
+ size: 24,
+ fill: 0xFFFFFF
+ });
+ nextBallText.anchor.set(0.5, 0.5);
+ nextBallText.x = 1024;
+ nextBallText.y = 300;
+ game.addChild(nextBallText);
+}
+function checkGameOver() {
+ for (var i = 0; i < balls.length; i++) {
+ if (balls[i].y - balls[i].radius < gameAreaTop + 100) {
+ LK.showGameOver();
+ return;
+ }
+ }
+}
+function cleanupMergedBalls() {
+ for (var i = balls.length - 1; i >= 0; i--) {
+ if (balls[i].hasBeenMerged) {
+ balls[i].destroy();
+ balls.splice(i, 1);
+ }
+ }
+}
+game.down = function (x, y, obj) {
+ if (dropCooldown > 0) return;
+ // Constrain drop position to game area
+ var dropX = Math.max(gameAreaLeft + 40, Math.min(gameAreaRight - 40, x));
+ var newBall = new Ball(nextBallValue);
+ newBall.x = dropX;
+ newBall.y = gameAreaTop + 50;
+ newBall.velocityX = 0;
+ newBall.velocityY = 0;
+ balls.push(newBall);
+ gameArea.addChild(newBall);
+ LK.getSound('drop').play();
+ // Update next ball
+ nextBallValue = getRandomNextBallValue();
+ updateNextBallPreview();
+ dropCooldown = 30; // 0.5 seconds at 60fps
+};
+game.update = function () {
+ if (dropCooldown > 0) {
+ dropCooldown--;
+ }
+ cleanupMergedBalls();
+ checkGameOver();
+ // Update score display
+ scoreText.setText(LK.getScore());
+};
\ No newline at end of file
Koyu yeşil bilye. In-Game asset. 2d. High contrast. No shadows
Kahverengi bilye. In-Game asset. 2d. High contrast. No shadows
Bprdo renk bilye. In-Game asset. 2d. High contrast. No shadows
Açık kahve bilye. In-Game asset. 2d. High contrast. No shadows
Gri bilye. In-Game asset. 2d. High contrast. No shadows