User prompt
char kurabiye toplasın her topladığında puanı 5 artsın puanı sola yasla
User prompt
küçük daireyi bıraktığımda küçük daire büyük dairenin ortasına gelsin
User prompt
küçük daireyi sürüklemiyorsam char dursun
User prompt
küçük daireyi bıraktığımda küçük daire büyük dairenin ortasına gelsin
User prompt
küçük daireyi sürüklemiyorsam char dursun
User prompt
eğer daireye deymesem küçük daire büyük dairenin ortasına gelsin
User prompt
küçük daire ne tarafa bakıyorsa char oraya doğru gitsin
User prompt
char ekranın ortasında olsun
User prompt
bir karakter ekle
User prompt
büyük dairenin opaklığını düşür
User prompt
büyük dairenin sadece kenarları gözüksun
User prompt
küçük daire büyük dairenin dışına çıkmasın
User prompt
iki daireyide küçültüp sol alt köşeye ekle
User prompt
daire nin kenerına değerse oyun bitmesin ve sayaç ol masın
Code edit (1 edits merged)
Please save this source code
User prompt
Daire İçinde Daire: Sürükle ve Sınırda Kal
Initial prompt
bir daire olsun içinde bir küçük daire olsun küçük daireyi sürükleye bilelim ama daireden çıkmadan
/**** * Classes ****/ // Class for the big circle (background) var BigCircle = Container.expand(function () { var self = Container.call(this); // Attach the big circle asset (ellipse) var circle = self.attachAsset('bigCircle', { anchorX: 0.5, anchorY: 0.5 }); // For possible future use: self.radius = circle.width / 2; return self; }); // Character class: simple box character var Character = Container.expand(function () { var self = Container.call(this); // Attach a red box asset as the character var charAsset = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); return self; }); // Cookie class: simple collectible var Cookie = Container.expand(function () { var self = Container.call(this); // Use a smallCircle asset for cookie, but different color var cookieAsset = self.attachAsset('smallCircle', { anchorX: 0.5, anchorY: 0.5, color: 0xf5c16c // Cookie color }); // Optionally scale down to make it smaller than smallCircle self.scaleX = 0.18; self.scaleY = 0.18; return self; }); // We need tween for possible future animations, but not required for MVP. // var tween = LK.import('@upit/tween.v1'); // Class for the draggable small circle var SmallCircle = Container.expand(function () { var self = Container.call(this); // Attach the small circle asset (ellipse) var circle = self.attachAsset('smallCircle', { anchorX: 0.5, anchorY: 0.5 }); // For possible future use: self.radius = circle.width / 2; // No per-object event handlers; all drag logic is handled in the main game. return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 // Dark background for contrast }); /**** * Game Code ****/ // --- Game Variables --- // --- Asset Initialization --- // Big circle: large, greenish // Small circle: smaller, yellow var bigCircle, smallCircle; var dragNode = null; var lastInside = true; // --- Create and Position Circles --- // Place both circles in the bottom-left corner, scaled down // New radii for smaller circles var bigCircleScale = 0.35; var smallCircleScale = 0.35; // Create big circle and add to game bigCircle = new BigCircle(); game.addChild(bigCircle); // Scale down big circle bigCircle.scaleX = bigCircleScale; bigCircle.scaleY = bigCircleScale; // Lower opacity for big circle bigCircle.alpha = 0.4; // Calculate position so the big circle is fully visible in the bottom-left var bigR = bigCircle.children[0].width / 2 * bigCircleScale; bigCircle.x = bigR + 40; // 40px margin from left bigCircle.y = 2732 - bigR - 40; // 40px margin from bottom // Overlay a smaller circle of background color to create a ring effect var ringInnerScale = 0.80; // Adjust for ring thickness (0.80 = 80% of big circle) var ringInner = LK.getAsset('bigCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: ringInnerScale, scaleY: ringInnerScale, x: 0, y: 0, color: 0x222222 // match background color }); bigCircle.addChild(ringInner); // Create small circle and add to game smallCircle = new SmallCircle(); game.addChild(smallCircle); // Scale down small circle smallCircle.scaleX = smallCircleScale; smallCircle.scaleY = smallCircleScale; // Place small circle at center of big circle var smallR = smallCircle.children[0].width / 2 * smallCircleScale; smallCircle.x = bigCircle.x; smallCircle.y = bigCircle.y; // --- Create and position character in the center of the screen --- var character = new Character(); game.addChild(character); // Center character on screen (2048x2732), anchor is 0.5 so this is true center character.x = 2048 / 2; character.y = 2732 / 2; // --- Helper: Check if small circle is fully inside big circle --- function isSmallCircleInsideBigCircle() { // Both circles are centered at their x/y var dx = smallCircle.x - bigCircle.x; var dy = smallCircle.y - bigCircle.y; var dist = Math.sqrt(dx * dx + dy * dy); // Use scaled radii var bigR = bigCircle.children[0].width / 2 * bigCircle.scaleX; var smallR = smallCircle.children[0].width / 2 * smallCircle.scaleX; // The small circle is fully inside if its center is at most (bigR - smallR) from the center return dist <= bigR - smallR; } // --- Timer Logic --- // (Timer logic removed) // --- Drag Logic --- // Convert move to keep smallCircle inside bigCircle function clampSmallCirclePosition(x, y) { var bigR = bigCircle.children[0].width / 2 * bigCircle.scaleX; var smallR = smallCircle.children[0].width / 2 * smallCircle.scaleX; var dx = x - bigCircle.x; var dy = y - bigCircle.y; var dist = Math.sqrt(dx * dx + dy * dy); var maxDist = bigR - smallR; if (dist > maxDist) { // Clamp to the edge var angle = Math.atan2(dy, dx); x = bigCircle.x + Math.cos(angle) * maxDist; y = bigCircle.y + Math.sin(angle) * maxDist; } return { x: x, y: y }; } // --- Game Event Handlers --- // Only allow dragging the small circle game.down = function (x, y, obj) { // Check if the down is on the small circle // Convert global to local for smallCircle var local = smallCircle.toLocal(game.toGlobal({ x: x, y: y })); var smallR = smallCircle.children[0].width / 2; // Check if within the circle if ((local.x - 0) * (local.x - 0) + (local.y - 0) * (local.y - 0) <= smallR * smallR) { dragNode = smallCircle; } }; game.up = function (x, y, obj) { dragNode = null; // When releasing, snap smallCircle to center of bigCircle smallCircle.x = bigCircle.x; smallCircle.y = bigCircle.y; }; function handleMove(x, y, obj) { if (dragNode === smallCircle) { // Clamp position so the small circle never leaves the big circle var clamped = clampSmallCirclePosition(x, y); smallCircle.x = clamped.x; smallCircle.y = clamped.y; } // Check if small circle is still inside big circle // (No game over or timer logic needed) lastInside = isSmallCircleInsideBigCircle(); } game.move = handleMove; // --- Game Update Loop --- // --- Cookie logic --- if (typeof cookies === "undefined") { // Helper to spawn a cookie inside the big circle (not too close to edge) var _spawnCookie = function _spawnCookie() { var cookie = new Cookie(); // Find a random position inside bigCircle, not too close to edge var bigR = bigCircle.children[0].width / 2 * bigCircle.scaleX; var cookieR = cookie.children[0].width / 2 * cookie.scaleX; var safeRadius = bigR - cookieR - 10; var angle = Math.random() * Math.PI * 2; var radius = Math.random() * (safeRadius * 0.85); // 0.85 to avoid edge cookie.x = bigCircle.x + Math.cos(angle) * radius; cookie.y = bigCircle.y + Math.sin(angle) * radius; game.addChild(cookie); cookies.push(cookie); }; // Spawn 5 cookies at start var cookies = []; for (var i = 0; i < 5; i++) { _spawnCookie(); } // Score text, left-aligned if (typeof scoreTxt === "undefined") { var scoreTxt = new Text2('0', { size: 120, fill: "#222" }); scoreTxt.anchor.set(0, 0); // Left-top LK.gui.top.addChild(scoreTxt); scoreTxt.x = 120; // Leave margin for menu scoreTxt.y = 30; } // Score variable var score = 0; } game.update = function () { // Calculate direction from bigCircle center to smallCircle center var dx = smallCircle.x - bigCircle.x; var dy = smallCircle.y - bigCircle.y; var dist = Math.sqrt(dx * dx + dy * dy); // Only move if the small circle is not exactly at the center AND is being dragged if (dist > 1 && dragNode === smallCircle) { // Normalize direction var dirX = dx / dist; var dirY = dy / dist; // Move character a fixed speed per frame (e.g. 8px per frame) var speed = 8; character.x += dirX * speed; character.y += dirY * speed; } // --- Cookie collection logic --- for (var i = cookies.length - 1; i >= 0; i--) { var cookie = cookies[i]; // Check collision: character center to cookie center var cdx = character.x - cookie.x; var cdy = character.y - cookie.y; var cookieR = cookie.children[0].width / 2 * cookie.scaleX; var charR = character.children[0].width / 2 * character.scaleX; var minDist = cookieR + charR - 10; // -10 for easier pickup if (cdx * cdx + cdy * cdy < minDist * minDist) { // Collect cookie cookie.destroy(); cookies.splice(i, 1); score += 5; scoreTxt.setText(score); // Spawn a new cookie spawnCookie(); } } }; // --- Start the timer when the game starts --- // (Timer removed) // --- Reset logic: when the game is reset, everything is re-initialized by LK ---
===================================================================
--- original.js
+++ change.js
@@ -21,8 +21,22 @@
anchorY: 0.5
});
return self;
});
+// Cookie class: simple collectible
+var Cookie = Container.expand(function () {
+ var self = Container.call(this);
+ // Use a smallCircle asset for cookie, but different color
+ var cookieAsset = self.attachAsset('smallCircle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ color: 0xf5c16c // Cookie color
+ });
+ // Optionally scale down to make it smaller than smallCircle
+ self.scaleX = 0.18;
+ self.scaleY = 0.18;
+ return self;
+});
// We need tween for possible future animations, but not required for MVP.
// var tween = LK.import('@upit/tween.v1');
// Class for the draggable small circle
var SmallCircle = Container.expand(function () {
@@ -46,12 +60,12 @@
/****
* Game Code
****/
-// Small circle: smaller, yellow
-// Big circle: large, greenish
-// --- Asset Initialization ---
// --- Game Variables ---
+// --- Asset Initialization ---
+// Big circle: large, greenish
+// Small circle: smaller, yellow
var bigCircle, smallCircle;
var dragNode = null;
var lastInside = true;
// --- Create and Position Circles ---
@@ -166,8 +180,42 @@
lastInside = isSmallCircleInsideBigCircle();
}
game.move = handleMove;
// --- Game Update Loop ---
+// --- Cookie logic ---
+if (typeof cookies === "undefined") {
+ // Helper to spawn a cookie inside the big circle (not too close to edge)
+ var _spawnCookie = function _spawnCookie() {
+ var cookie = new Cookie();
+ // Find a random position inside bigCircle, not too close to edge
+ var bigR = bigCircle.children[0].width / 2 * bigCircle.scaleX;
+ var cookieR = cookie.children[0].width / 2 * cookie.scaleX;
+ var safeRadius = bigR - cookieR - 10;
+ var angle = Math.random() * Math.PI * 2;
+ var radius = Math.random() * (safeRadius * 0.85); // 0.85 to avoid edge
+ cookie.x = bigCircle.x + Math.cos(angle) * radius;
+ cookie.y = bigCircle.y + Math.sin(angle) * radius;
+ game.addChild(cookie);
+ cookies.push(cookie);
+ }; // Spawn 5 cookies at start
+ var cookies = [];
+ for (var i = 0; i < 5; i++) {
+ _spawnCookie();
+ }
+ // Score text, left-aligned
+ if (typeof scoreTxt === "undefined") {
+ var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#222"
+ });
+ scoreTxt.anchor.set(0, 0); // Left-top
+ LK.gui.top.addChild(scoreTxt);
+ scoreTxt.x = 120; // Leave margin for menu
+ scoreTxt.y = 30;
+ }
+ // Score variable
+ var score = 0;
+}
game.update = function () {
// Calculate direction from bigCircle center to smallCircle center
var dx = smallCircle.x - bigCircle.x;
var dy = smallCircle.y - bigCircle.y;
@@ -181,8 +229,27 @@
var speed = 8;
character.x += dirX * speed;
character.y += dirY * speed;
}
+ // --- Cookie collection logic ---
+ for (var i = cookies.length - 1; i >= 0; i--) {
+ var cookie = cookies[i];
+ // Check collision: character center to cookie center
+ var cdx = character.x - cookie.x;
+ var cdy = character.y - cookie.y;
+ var cookieR = cookie.children[0].width / 2 * cookie.scaleX;
+ var charR = character.children[0].width / 2 * character.scaleX;
+ var minDist = cookieR + charR - 10; // -10 for easier pickup
+ if (cdx * cdx + cdy * cdy < minDist * minDist) {
+ // Collect cookie
+ cookie.destroy();
+ cookies.splice(i, 1);
+ score += 5;
+ scoreTxt.setText(score);
+ // Spawn a new cookie
+ spawnCookie();
+ }
+ }
};
// --- Start the timer when the game starts ---
// (Timer removed)
// --- Reset logic: when the game is reset, everything is re-initialized by LK ---
\ No newline at end of file