User prompt
5 ve 9 u uygula
User prompt
5 top yerine 3 top ekle kademeli şekilde büyüsünler ama top spawnlamada ilk 4 top spawnlansın daha büyük toplar sadece birleştirerek olsun
User prompt
yeni 5 tane daha büyük top ekle
User prompt
There will be no ball unless you drag and drop the ball
User prompt
Don't let the ball get in your way when you start
Code edit (1 edits merged)
Please save this source code
User prompt
Merge Balls Mania
Initial prompt
Make me a game. Let there be 9 balls of different sizes. When two balls of the same size touch each other, one big ball is formed. Let's lose when we pass a certain limit and let the balls come in random sizes. When I drag and click on a section, a new ball falls there.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Ball class var Ball = Container.expand(function () { var self = Container.call(this); // Ball properties self.size = 1; // 1-9 self.radius = 60; // default, will be set in init self.vx = 0; self.vy = 0; self.isMerging = false; // Prevent double merge // Attach asset based on size self.setSize = function (size) { self.size = size; // Remove previous asset if any if (self.ballAsset) { self.removeChild(self.ballAsset); } var assetId = 'ball' + size; self.ballAsset = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.radius = self.ballAsset.width / 2; }; // Set initial size self.setSize(1); // For merge animation self.flash = function () { tween(self.ballAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 120, easing: tween.easeOut, onFinish: function onFinish() { tween(self.ballAsset, { scaleX: 1, scaleY: 1 }, { duration: 120, easing: tween.easeIn }); } }); }; // For showing value self.showValue = function () { if (self.valueText) { self.removeChild(self.valueText); } self.valueText = new Text2('' + self.size, { size: Math.max(60, self.radius), fill: 0xFFFFFF }); self.valueText.anchor.set(0.5, 0.5); self.addChild(self.valueText); }; self.showValue(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222831 }); /**** * Game Code ****/ // Sound for merging // Ball shapes for different sizes (size1, size2, size3, size4, size5, size6, size7, size8, size9) // Game constants var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var BALL_MIN_SIZE = 1; var BALL_MAX_SIZE = 5; // Start with 5, can increase for more challenge var BALL_LIMIT = 16; // Max balls allowed on screen before game over // var INIT_BALLS = 9; // No longer needed, no initial balls var GRAVITY = 1.2; var BOUNCE = 0.7; var FRICTION = 0.995; var WALL_BOUNCE = 0.8; var SPAWN_Y = 180; // y position for new balls // Ball array var balls = []; // Score var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Next ball preview var nextBallSize = BALL_MIN_SIZE + Math.floor(Math.random() * BALL_MAX_SIZE); var nextBallPreview = LK.getAsset('ball' + nextBallSize, { anchorX: 0.5, anchorY: 0.5, x: GAME_WIDTH / 2, y: SPAWN_Y - 100 }); game.addChild(nextBallPreview); // Helper: get random ball size function getRandomBallSize() { return BALL_MIN_SIZE + Math.floor(Math.random() * BALL_MAX_SIZE); } // Helper: clamp function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } // Helper: distance squared function dist2(a, b) { var dx = a.x - b.x; var dy = a.y - b.y; return dx * dx + dy * dy; } // Helper: check overlap function isOverlapping(ballA, ballB) { var rSum = ballA.radius + ballB.radius; return dist2(ballA, ballB) < rSum * rSum - 1; } // Helper: resolve overlap function resolveOverlap(ballA, ballB) { var dx = ballB.x - ballA.x; var dy = ballB.y - ballA.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist === 0) { // Random nudge dx = 1; dy = 0; dist = 1; } var overlap = ballA.radius + ballB.radius - dist; if (overlap > 0) { var pushX = dx / dist * (overlap / 2); var pushY = dy / dist * (overlap / 2); ballA.x -= pushX; ballA.y -= pushY; ballB.x += pushX; ballB.y += pushY; } } // Helper: merge balls function mergeBalls(ballA, ballB) { // Only merge if both are not merging and same size if (ballA.isMerging || ballB.isMerging) return false; if (ballA.size !== ballB.size) return false; ballA.isMerging = true; ballB.isMerging = true; // New ball at average position var newBall = new Ball(); var newSize = clamp(ballA.size + 1, BALL_MIN_SIZE, 9); newBall.setSize(newSize); newBall.x = (ballA.x + ballB.x) / 2; newBall.y = (ballA.y + ballB.y) / 2; newBall.vx = (ballA.vx + ballB.vx) / 2; newBall.vy = (ballA.vy + ballB.vy) / 2; newBall.showValue(); newBall.flash(); // Remove old balls ballA.destroy(); ballB.destroy(); var idxA = balls.indexOf(ballA); var idxB = balls.indexOf(ballB); if (idxA !== -1) balls.splice(idxA, 1); if (idxB !== -1) balls.splice(balls.indexOf(ballB), 1); // index may have shifted // Add new ball balls.push(newBall); game.addChild(newBall); // Play merge sound LK.getSound('merge').play(); // Add score score += Math.pow(2, newSize); scoreTxt.setText(score); // Animate newBall.flash(); return newBall; } // Spawn a ball at (x, y) with given size function spawnBall(x, y, size) { var ball = new Ball(); ball.setSize(size); ball.x = clamp(x, ball.radius, GAME_WIDTH - ball.radius); ball.y = y; ball.vx = (Math.random() - 0.5) * 16; ball.vy = 0; ball.showValue(); balls.push(ball); game.addChild(ball); return ball; } // No initial balls function needed // Drag and drop for new balls var isDragging = false; var dragX = GAME_WIDTH / 2; var dragBall = null; // Show drag preview var dragPreview = null; function showDragPreview(x) { if (!dragPreview) { dragPreview = LK.getAsset('ball' + nextBallSize, { anchorX: 0.5, anchorY: 0.5, x: x, y: SPAWN_Y }); game.addChild(dragPreview); } dragPreview.x = clamp(x, dragPreview.width / 2, GAME_WIDTH - dragPreview.width / 2); dragPreview.y = SPAWN_Y; } function hideDragPreview() { if (dragPreview) { dragPreview.destroy(); dragPreview = null; } } // Handle touch/mouse down game.down = function (x, y, obj) { // Only allow drop in top 1/3 of screen if (y > GAME_HEIGHT / 2) return; isDragging = true; dragX = clamp(x, 100, GAME_WIDTH - 100); showDragPreview(dragX); }; // Handle move game.move = function (x, y, obj) { if (isDragging) { dragX = clamp(x, 100, GAME_WIDTH - 100); showDragPreview(dragX); } }; // Handle up (drop ball) game.up = function (x, y, obj) { if (isDragging) { isDragging = false; hideDragPreview(); // Drop ball at dragX spawnBall(dragX, SPAWN_Y, nextBallSize); // Next ball nextBallSize = getRandomBallSize(); // Update preview if (nextBallPreview) { nextBallPreview.destroy(); } nextBallPreview = LK.getAsset('ball' + nextBallSize, { anchorX: 0.5, anchorY: 0.5, x: GAME_WIDTH / 2, y: SPAWN_Y - 100 }); game.addChild(nextBallPreview); } }; // Main update loop game.update = function () { // Physics for each ball for (var i = 0; i < balls.length; i++) { var ball = balls[i]; // Gravity ball.vy += GRAVITY; // Move ball.x += ball.vx; ball.y += ball.vy; // Wall collision if (ball.x - ball.radius < 0) { ball.x = ball.radius; ball.vx = -ball.vx * WALL_BOUNCE; } if (ball.x + ball.radius > GAME_WIDTH) { ball.x = GAME_WIDTH - ball.radius; ball.vx = -ball.vx * WALL_BOUNCE; } // Floor if (ball.y + ball.radius > GAME_HEIGHT) { ball.y = GAME_HEIGHT - ball.radius; ball.vy = -ball.vy * BOUNCE; ball.vx *= FRICTION; // Stop tiny bounces if (Math.abs(ball.vy) < 2) ball.vy = 0; } // Ceiling if (ball.y - ball.radius < 0) { ball.y = ball.radius; ball.vy = -ball.vy * BOUNCE; } // Friction ball.vx *= FRICTION; ball.vy *= FRICTION; } // Ball-ball collision and merging for (var i = 0; i < balls.length; i++) { for (var j = i + 1; j < balls.length; j++) { var a = balls[i], b = balls[j]; if (isOverlapping(a, b)) { // If same size, merge if (a.size === b.size && !a.isMerging && !b.isMerging) { mergeBalls(a, b); break; // balls array changed, restart } else { // Elastic collision resolveOverlap(a, b); // Simple velocity swap var dx = b.x - a.x; var dy = b.y - a.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { var nx = dx / dist, ny = dy / dist; var p = 2 * (a.vx * nx + a.vy * ny - b.vx * nx - b.vy * ny) / 2; a.vx = a.vx - p * nx; a.vy = a.vy - p * ny; b.vx = b.vx + p * nx; b.vy = b.vy + p * ny; } } } } } // Remove balls marked for destroy (already handled in mergeBalls) // Check for game over if (balls.length > BALL_LIMIT) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); } // Optionally: win condition (e.g. create a ball of size 9) for (var i = 0; i < balls.length; i++) { if (balls[i].size === 9) { LK.effects.flashScreen(0xffff00, 1000); LK.showYouWin(); break; } } };
===================================================================
--- original.js
+++ change.js
@@ -83,9 +83,9 @@
var GAME_HEIGHT = 2732;
var BALL_MIN_SIZE = 1;
var BALL_MAX_SIZE = 5; // Start with 5, can increase for more challenge
var BALL_LIMIT = 16; // Max balls allowed on screen before game over
-var INIT_BALLS = 9;
+// var INIT_BALLS = 9; // No longer needed, no initial balls
var GRAVITY = 1.2;
var BOUNCE = 0.7;
var FRICTION = 0.995;
var WALL_BOUNCE = 0.8;
@@ -197,36 +197,9 @@
balls.push(ball);
game.addChild(ball);
return ball;
}
-// Initial balls
-function spawnInitialBalls() {
- var previewX = GAME_WIDTH / 2;
- var previewY = SPAWN_Y - 100;
- var previewRadius = LK.getAsset('ball' + nextBallSize, {
- anchorX: 0.5,
- anchorY: 0.5
- }).width / 2 + 80; // add margin
- var tries = 0;
- for (var i = 0; i < INIT_BALLS; i++) {
- var size = getRandomBallSize();
- var angle = Math.PI * 2 * (i / INIT_BALLS);
- var r = 600 + Math.random() * 200;
- var x = GAME_WIDTH / 2 + Math.cos(angle) * r;
- var y = GAME_HEIGHT / 2 + Math.sin(angle) * r;
- // Prevent spawn in preview area
- tries = 0;
- while (tries < 10 && Math.sqrt((x - previewX) * (x - previewX) + (y - previewY) * (y - previewY)) < previewRadius) {
- angle = Math.random() * Math.PI * 2;
- r = 600 + Math.random() * 200;
- x = GAME_WIDTH / 2 + Math.cos(angle) * r;
- y = GAME_HEIGHT / 2 + Math.sin(angle) * r;
- tries++;
- }
- spawnBall(x, y, size);
- }
-}
-spawnInitialBalls();
+// No initial balls function needed
// Drag and drop for new balls
var isDragging = false;
var dragX = GAME_WIDTH / 2;
var dragBall = null;
Pinpon ball. In-Game asset. 2d. High contrast. No shadows
tennis ball. In-Game asset. 2d. High contrast. No shadows
american football ball. In-Game asset. 2d. High contrast. No shadows
volleyball ball. In-Game asset. 2d. High contrast. No shadows
football ball. In-Game asset. 2d. High contrast. No shadows
basketball ball. In-Game asset. 2d. High contrast. No shadows
dodge ball ball. In-Game asset. 2d. High contrast. No shadows
medicine ball. In-Game asset. 2d. High contrast. No shadows
yoga ball. In-Game asset. 2d. High contrast. No shadows
beach ball. In-Game asset. 2d. High contrast. No shadows
zorbing ball. In-Game asset. 2d. High contrast. No shadows
flying air balloon. In-Game asset. 2d. High contrast. No shadows