User prompt
yazıları sil
User prompt
geri al yazmasın
User prompt
sol biraz daha sağ gitsin
User prompt
mapın yukarsınına yukarı (Up) yaz aşağı (Down) sağ (Right) sol (Left) yaz
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'btn.attachShape is not a function' in or related to this line: 'var bg = btn.attachShape('box', {' Line Number: 458
User prompt
ok tuşları ekle
Code edit (1 edits merged)
Please save this source code
User prompt
ok tuşları ekle
User prompt
geri al
User prompt
// Ok tuşları container var controlsContainer = game.addChild(new Container()); // Tuşların boyutu ve aralık var btnSize = 120; var spacing = 20; // Ok tuşları için basit kutular (düğme görseli yerine) function createButton(label, x, y, onClick) { var btn = controlsContainer.addChild(new Container()); var bg = btn.attachShape('box', {width: btnSize, height: btnSize, color: 0x666666, alpha: 0.7}); var text = btn.addChild(new Text2(label, {size: 50, fill: 0xffffff})); text.anchor.set(0.5, 0.5); text.x = btnSize / 2; text.y = btnSize / 2; btn.x = x; btn.y = y; btn.down = function () { onClick(); // Butona basınca ses vs ekleyebilirsin }; return btn; } // Ortadaki yatay koordinat var centerX = 2048 / 2; // Düğmeleri ekle var leftBtn = createButton('←', centerX - btnSize - spacing, 2732 - btnSize - spacing, function () { movePlayer(-1, 0); }); var rightBtn = createButton('→', centerX + btnSize + spacing, 2732 - btnSize - spacing, function () { movePlayer(1, 0); }); var upBtn = createButton('↑', centerX, 2732 - 2 * btnSize - 2 * spacing, function () { movePlayer(0, -1); }); var downBtn = createButton('↓', centerX, 2732 - btnSize - spacing, function () { movePlayer(0, 1); });
User prompt
geri al
User prompt
var mapOffsetY = -200; // Haritayı yukarı kaydır function updateMazePosition() { for (var y = 0; y < MAZE_HEIGHT; y++) { for (var x = 0; x < MAZE_WIDTH; x++) { mazeCells[y][x].x = x * CELL_SIZE + CELL_SIZE / 2; mazeCells[y][x].y = y * CELL_SIZE + CELL_SIZE / 2 + mapOffsetY; } } ball.x = ball.gridX * CELL_SIZE + CELL_SIZE / 2; ball.y = ball.gridY * CELL_SIZE + CELL_SIZE / 2 + mapOffsetY; } updateMazePosition(); // Butonlar için ayrı container var controlsContainer = LK.gui.bottom || game.addChild(new Container()); controlsContainer.x = 2048 / 2 - 150; controlsContainer.y = 2732 - 220; // Buton oluşturma fonksiyonu, event vs. aynen devam // Her hareketten sonra topun pozisyonunu güncelle function movePlayer(deltaX, deltaY) { if (ball.isMoving) return; var newGridX = ball.gridX + deltaX; var newGridY = ball.gridY + deltaY; if (isValidMove(newGridX, newGridY)) { ball.moveToGrid(newGridX, newGridY); ball.x = newGridX * CELL_SIZE + CELL_SIZE / 2; ball.y = newGridY * CELL_SIZE + CELL_SIZE / 2 + mapOffsetY; // ... diğer hareket sonrası işlemler } }
Code edit (1 edits merged)
Please save this source code
User prompt
tween leri sil
Code edit (1 edits merged)
Please save this source code
User prompt
Maze Ball Adventure
Initial prompt
/**** * Assets ****/ LK.init.shape('ballShape', {width:60, height:60, color:0xffd700, shape:'ellipse'}); LK.init.shape('exitShape', {width:80, height:80, color:0x00ff00, shape:'box'}); LK.init.shape('floorShape', {width:80, height:80, color:0x44aa44, shape:'box'}); // Çimen rengi yeşil yaptım LK.init.shape('wallShape', {width:80, height:80, color:0x333333, shape:'box'}); LK.init.sound('move'); LK.init.sound('win'); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ballShape', {anchorX:0.5, anchorY:0.5}); self.gridX = 0; self.gridY = 0; self.isMoving = false; self.moveToGrid = function (newGridX, newGridY) { if (self.isMoving) return; self.gridX = newGridX; self.gridY = newGridY; self.isMoving = true; var targetX = newGridX * CELL_SIZE + CELL_SIZE / 2; var targetY = newGridY * CELL_SIZE + CELL_SIZE / 2; self.x = targetX; self.y = targetY; self.isMoving = false; LK.getSound('move').play(); }; return self; }); var MazeCell = Container.expand(function (cellType) { var self = Container.call(this); var assetName = 'floorShape'; if (cellType === 'wall') assetName = 'wallShape'; else if (cellType === 'exit') assetName = 'exitShape'; var cellGraphics = self.attachAsset(assetName, {anchorX:0.5, anchorY:0.5}); self.cellType = cellType; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({backgroundColor: 0x224422}); // koyu çimen arka planı /**** * Game Constants & Variables ****/ var CELL_SIZE = 80; var MAZE_WIDTH = 15; var MAZE_HEIGHT = 20; var MAX_LEVELS = 200; var currentLevel = 1; /**** * Predefined maze maps (örnek, sadece birkaç level, istediğin kadar ekleyebilirsin) ****/ var maps = [ // Level 1 (örnek) [ "011010110011100", "000011011101000", "001001101010010", "011000111110001", "111001110001110", "100010000111010", "111111111010111", "110001100001000", "001100011001011", "110000101011011", "111011101100111", "000110001000010", "111000111100111", "010000110000010", "011111111111110", "000000000000000", "111111111111110", "100000000000010", "101111111111010", "100000000000000" ], // Level 2 [ "110110110101010", "100001110001111", "101100001100100", "111101011110000", "101101110001010", "100111011000111", "010100000111101", "111010111100010", "111100011101001", "011111100100000", "101010101010101", "010101010101010", "101010101010101", "010101010101010", "111111111111111", "000000000000000", "111111111111111", "000000000000000", "111111111111111", "000000000000000" ] // ... daha fazla harita ekleyebilirsin ]; /**** * Maze generation function ****/ function generateMazeForLevel(level) { var mapIndex = Math.min(level - 1, maps.length - 1); var mapString = maps[mapIndex]; var maze = []; var mapHeight = mapString.length; var mapWidth = mapString[0] ? mapString[0].length : 0; for (var y = 0; y < MAZE_HEIGHT; y++) { maze[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { var _char = '0'; if (y < mapHeight && x < mapWidth && mapString[y]) { _char = mapString[y].charAt(x); } maze[y][x] = (_char === '1') ? 1 : 0; } } // Çıkış sabit sağ alt köşede var exitX = MAZE_WIDTH - 2; var exitY = MAZE_HEIGHT - 2; maze[exitY][exitX] = 2; // çıkış // Çıkış önü temiz (duvar yok) maze[exitY][exitX - 1] = 0; maze[exitY - 1][exitX] = 0; maze[exitY - 1][exitX - 1] = 0; // Başlangıç noktası boş maze[1][1] = 0; // Rastgele duvar ekle (çıkış ve önüne dokunma) for (var yWall = 1; yWall < MAZE_HEIGHT - 1; yWall++) { for (var xWall = 1; xWall < MAZE_WIDTH - 1; xWall++) { if ( (yWall === exitY && (xWall === exitX || xWall === exitX - 1)) || (yWall === exitY - 1 && (xWall === exitX || xWall === exitX - 1)) ) continue; if (yWall === 1 && xWall === 1) continue; if (maze[yWall][xWall] === 0 && Math.random() < 0.18) { maze[yWall][xWall] = 1; } } } return maze; } /**** * Setup Maze & Ball ****/ var mazeData = generateMazeForLevel(currentLevel); var mazeContainer = game.addChild(new Container()); var mazeCells = []; var ball = game.addChild(new Ball()); var cameraX = 0; var cameraY = 0; var targetCameraX = 0; var targetCameraY = 0; // Labirent hücrelerini oluştur for (var y = 0; y < MAZE_HEIGHT; y++) { mazeCells[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { var cellType = 'floor'; if (mazeData[y][x] === 1) cellType = 'wall'; else if (mazeData[y][x] === 2) cellType = 'exit'; var cell = mazeContainer.addChild(new MazeCell(cellType)); cell.x = x * CELL_SIZE + CELL_SIZE / 2; cell.y = y * CELL_SIZE + CELL_SIZE / 2; mazeCells[y][x] = cell; } } // Seviye yazısı var levelText = new Text2('Level ' + currentLevel, { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); // Top başlangıç pozisyonu ball.gridX = 1; ball.gridY = 1; ball.x = ball.gridX * CELL_SIZE + CELL_SIZE / 2; ball.y = ball.gridY * CELL_SIZE + CELL_SIZE / 2; // Kamera başlangıç pozisyonu (ekran ortasında top) targetCameraX = 2048 / 2 - ball.x; targetCameraY = 2732 / 2 - ball.y; cameraX = targetCameraX; cameraY = targetCameraY; mazeContainer.x = cameraX; mazeContainer.y = cameraY; ball.x += cameraX; ball.y += cameraY; /**** * Hareket Fonksiyonları ****/ function isValidMove(gridX, gridY) { if (gridX < 0 || gridX >= MAZE_WIDTH || gridY < 0 || gridY >= MAZE_HEIGHT) return false; return mazeData[gridY][gridX] !== 1; } function movePlayer(deltaX, deltaY) { if (ball.isMoving) return; var newGridX = ball.gridX + deltaX; var newGridY = ball.gridY + deltaY; if (isValidMove(newGridX, newGridY)) { ball.moveToGrid(newGridX, newGridY); // Kamera hedefi güncelle var ballWorldX = newGridX * CELL_SIZE + CELL_SIZE / 2; var ballWorldY = newGridY * CELL_SIZE + CELL_SIZE / 2; targetCameraX = 2048 / 2 - ballWorldX; targetCameraY = 2732 / 2 - ballWorldY; // Çıkış kontrolü if (mazeData[newGridY][newGridX] === 2) { LK.setTimeout(function () { LK.getSound('win').play(); if (currentLevel >= MAX_LEVELS) { LK.showYouWin(); } else { currentLevel++; // Yeni labirent üret mazeData = generateMazeForLevel(currentLevel); // Seviye metni güncelle levelText.setText('Level ' + currentLevel); // Önceki hücreleri temizle for (var y = 0; y < MAZE_HEIGHT; y++) { for (var x = 0; x < MAZE_WIDTH; x++) { mazeContainer.removeChild(mazeCells[y][x]); } } mazeCells = []; // Yeni hücreleri oluştur for (var y = 0; y < MAZE_HEIGHT; y++) { mazeCells[y] = []; for (var x = 0; x < MAZE_WIDTH; x++) { var cellType = 'floor'; if (mazeData[y][x] === 1) cellType = 'wall'; else if (mazeData[y][x] === 2) cellType = 'exit'; var cell = mazeContainer.addChild(new MazeCell(cellType)); cell.x = x * CELL_SIZE + CELL_SIZE / 2; cell.y = y * CELL_SIZE + CELL_SIZE / 2; mazeCells[y][x] = cell; } } // Top başlangıç pozisyonuna resetle ball.gridX = 1; ball.gridY = 1; ball.x = ball.gridX * CELL_SIZE + CELL_SIZE / 2; ball.y = ball.gridY * CELL_SIZE + CELL_SIZE / 2; // Kamera resetle targetCameraX = 2048 / 2 - ball.x; targetCameraY = 2732 / 2 - ball.y; cameraX = targetCameraX; cameraY = targetCameraY; mazeContainer.x = cameraX; mazeContainer.y = cameraY; ball.x += cameraX; ball.y += cameraY; } }, 300); } } } /**** * Kullanıcı Girişi ****/ game.down = function (x, y, obj) { var ballScreenX = 2048 / 2; var ballScreenY = 2732 / 2; var deltaX = x - ballScreenX; var deltaY = y - ballScreenY; if (Math.abs(deltaX) > Math.abs(deltaY)) { if (deltaX > 0) movePlayer(1, 0); else movePlayer(-1, 0); } else { if (deltaY > 0) movePlayer(0, 1); else movePlayer(0, -1); } }; /**** * Oyun Güncelleme Döngüsü ****/ game.update = function () { var cameraSpeed = 0.1; cameraX += (targetCameraX - cameraX) * cameraSpeed; cameraY += (targetCameraY - cameraY) * cameraSpeed; mazeContainer.x = cameraX; mazeContainer.y = cameraY; ball.x = ball.gridX * CELL_SIZE + CELL_SIZE / 2 + cameraX; ball.y = ball.gridY * CELL_SIZE + CELL_SIZE / 2 + cameraY; };
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 });
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});