User prompt
60ms yap ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Hala çok uzun sürüyor ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Satır temizlemeyi biraz hızlandır ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Satır temizle parçalanma efecti ekle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Parmagımı ortada basılı tuttugumda blok hızlıca yere insin
User prompt
Bloklar hala bozuk geliyor
User prompt
Blokların şekli tutarlı değil
User prompt
Hala bir sürü geliyor
User prompt
Lütfen düzelt
User prompt
Blokların geliş sıklıgı çok kısa
User prompt
Bloklar TEK TEK GELSİN
User prompt
Bloklar sırayla tek tek gelsin biri yere degmeddn başka blok gelmesin
User prompt
Bir blok yere degmeden başka gelmesin
User prompt
Ekranı kapla
User prompt
Tetris oyunu yap
User prompt
Block Drop Puzzle
Initial prompt
Tetris
/**** * Classes ****/ var Block = Container.expand(function (blockType) { var self = Container.call(this); self.blockType = blockType || 'block_I'; self.gridX = 0; self.gridY = 0; var blockGraphics = self.attachAsset(self.blockType, { anchorX: 0, anchorY: 0 }); self.setGridPosition = function (gridX, gridY) { self.gridX = gridX; self.gridY = gridY; self.x = GRID_OFFSET_X + gridX * BLOCK_SIZE; self.y = GRID_OFFSET_Y + gridY * BLOCK_SIZE; }; return self; }); var Tetromino = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'I'; self.rotation = 0; self.gridX = 4; // Start in middle of board self.gridY = 0; self.blocks = []; self.fallTimer = 0; self.fallSpeed = 60; // Frames until next fall // Tetromino shapes and rotations self.shapes = { 'I': [[[1, 1, 1, 1]], [[1], [1], [1], [1]], [[1, 1, 1, 1]], [[1], [1], [1], [1]]], 'O': [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]], 'T': [[[0, 1, 0], [1, 1, 1]], [[1, 0], [1, 1], [1, 0]], [[1, 1, 1], [0, 1, 0]], [[0, 1], [1, 1], [0, 1]]], 'S': [[[0, 1, 1], [1, 1, 0]], [[1, 0], [1, 1], [0, 1]], [[0, 1, 1], [1, 1, 0]], [[1, 0], [1, 1], [0, 1]]], 'Z': [[[1, 1, 0], [0, 1, 1]], [[0, 1], [1, 1], [1, 0]], [[1, 1, 0], [0, 1, 1]], [[0, 1], [1, 1], [1, 0]]], 'J': [[[1, 0, 0], [1, 1, 1]], [[1, 1], [1, 0], [1, 0]], [[1, 1, 1], [0, 0, 1]], [[0, 1], [0, 1], [1, 1]]], 'L': [[[0, 0, 1], [1, 1, 1]], [[1, 0], [1, 0], [1, 1]], [[1, 1, 1], [1, 0, 0]], [[1, 1], [0, 1], [0, 1]]] }; self.getBlockType = function () { return 'block_' + self.type; }; self.createBlocks = function () { // Clear existing blocks for (var i = 0; i < self.blocks.length; i++) { self.blocks[i].destroy(); } self.blocks = []; var shape = self.shapes[self.type][self.rotation]; for (var y = 0; y < shape.length; y++) { for (var x = 0; x < shape[y].length; x++) { if (shape[y][x] === 1) { var block = new Block(self.getBlockType()); block.setGridPosition(self.gridX + x, self.gridY + y); self.blocks.push(block); game.addChild(block); } } } }; self.updatePosition = function () { var shape = self.shapes[self.type][self.rotation]; for (var i = 0; i < self.blocks.length; i++) { var blockIndex = 0; for (var y = 0; y < shape.length; y++) { for (var x = 0; x < shape[y].length; x++) { if (shape[y][x] === 1) { if (blockIndex === i) { self.blocks[i].setGridPosition(self.gridX + x, self.gridY + y); break; } blockIndex++; } } } } }; self.canMoveTo = function (newX, newY, newRotation) { var testRotation = newRotation !== undefined ? newRotation : self.rotation; var shape = self.shapes[self.type][testRotation]; for (var y = 0; y < shape.length; y++) { for (var x = 0; x < shape[y].length; x++) { if (shape[y][x] === 1) { var checkX = newX + x; var checkY = newY + y; // Check bounds if (checkX < 0 || checkX >= GRID_WIDTH || checkY >= GRID_HEIGHT) { return false; } // Check collision with placed blocks if (checkY >= 0 && gameGrid[checkY] && gameGrid[checkY][checkX]) { return false; } } } } return true; }; self.move = function (deltaX, deltaY) { if (self.canMoveTo(self.gridX + deltaX, self.gridY + deltaY)) { self.gridX += deltaX; self.gridY += deltaY; self.updatePosition(); return true; } return false; }; self.rotate = function () { var newRotation = (self.rotation + 1) % 4; if (self.canMoveTo(self.gridX, self.gridY, newRotation)) { self.rotation = newRotation; self.createBlocks(); LK.getSound('piece_rotate').play(); return true; } return false; }; self.update = function () { self.fallTimer++; if (self.fallTimer >= self.fallSpeed) { self.fallTimer = 0; if (!self.move(0, 1)) { // Piece has landed self.placePiece(); } } }; self.placePiece = function () { // Add blocks to grid for (var i = 0; i < self.blocks.length; i++) { var block = self.blocks[i]; if (block.gridY >= 0) { if (!gameGrid[block.gridY]) gameGrid[block.gridY] = []; gameGrid[block.gridY][block.gridX] = block; } } LK.getSound('piece_drop').play(); checkCompleteLines(); spawnNewPiece(); }; return self; }); /**** * Initialize Game ****/ // Game constants var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game constants // Tetromino blocks - using different colors for each piece type // Cyan // Yellow // Purple // Green // Red // Blue // Orange var GRID_WIDTH = 10; var GRID_HEIGHT = 20; var BLOCK_SIZE = 40; var GRID_OFFSET_X = (2048 - GRID_WIDTH * BLOCK_SIZE) / 2; var GRID_OFFSET_Y = 200; // Game variables var gameGrid = []; var currentPiece = null; var nextPieceType = null; var gameLevel = 1; var linesCleared = 0; var lastMoveTime = 0; var moveDelay = 100; // Milliseconds between moves // Initialize grid for (var y = 0; y < GRID_HEIGHT; y++) { gameGrid[y] = []; for (var x = 0; x < GRID_WIDTH; x++) { gameGrid[y][x] = null; } } // Tetromino types var pieceTypes = ['I', 'O', 'T', 'S', 'Z', 'J', 'L']; function getRandomPieceType() { return pieceTypes[Math.floor(Math.random() * pieceTypes.length)]; } function spawnNewPiece() { if (!nextPieceType) { nextPieceType = getRandomPieceType(); } currentPiece = new Tetromino(nextPieceType); game.addChild(currentPiece); currentPiece.createBlocks(); nextPieceType = getRandomPieceType(); // Check game over if (!currentPiece.canMoveTo(currentPiece.gridX, currentPiece.gridY)) { LK.showGameOver(); return; } } function checkCompleteLines() { var completedLines = []; // Find completed lines for (var y = 0; y < GRID_HEIGHT; y++) { var lineComplete = true; for (var x = 0; x < GRID_WIDTH; x++) { if (!gameGrid[y][x]) { lineComplete = false; break; } } if (lineComplete) { completedLines.push(y); } } if (completedLines.length > 0) { // Remove completed lines for (var i = 0; i < completedLines.length; i++) { var lineY = completedLines[i]; // Destroy blocks in this line for (var x = 0; x < GRID_WIDTH; x++) { if (gameGrid[lineY][x]) { gameGrid[lineY][x].destroy(); gameGrid[lineY][x] = null; } } // Move lines down for (var y = lineY; y > 0; y--) { for (var x = 0; x < GRID_WIDTH; x++) { gameGrid[y][x] = gameGrid[y - 1][x]; if (gameGrid[y][x]) { gameGrid[y][x].setGridPosition(x, y); } } } // Clear top line for (var x = 0; x < GRID_WIDTH; x++) { gameGrid[0][x] = null; } } // Update score linesCleared += completedLines.length; var points = 0; switch (completedLines.length) { case 1: points = 100; break; case 2: points = 300; break; case 3: points = 500; break; case 4: points = 800; break; } LK.setScore(LK.getScore() + points * gameLevel); // Level up every 10 lines var newLevel = Math.floor(linesCleared / 10) + 1; if (newLevel > gameLevel) { gameLevel = newLevel; } LK.getSound('line_clear').play(); } } // Create score display var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); scoreText.x = 50; scoreText.y = 100; LK.gui.addChild(scoreText); var levelText = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); levelText.x = 50; levelText.y = 180; LK.gui.addChild(levelText); var linesText = new Text2('Lines: 0', { size: 60, fill: 0xFFFFFF }); linesText.anchor.set(0, 0); linesText.x = 50; linesText.y = 260; LK.gui.addChild(linesText); // Draw grid borders for (var x = 0; x <= GRID_WIDTH; x++) { for (var y = 0; y < GRID_HEIGHT + 1; y++) { if (x === 0 || x === GRID_WIDTH) { var border = LK.getAsset('grid_border', { x: GRID_OFFSET_X + x * BLOCK_SIZE - 2, y: GRID_OFFSET_Y + y * BLOCK_SIZE, scaleX: 1, scaleY: BLOCK_SIZE / 4 }); game.addChild(border); } } } for (var y = GRID_HEIGHT; y <= GRID_HEIGHT; y++) { for (var x = 0; x < GRID_WIDTH; x++) { var border = LK.getAsset('grid_border', { x: GRID_OFFSET_X + x * BLOCK_SIZE, y: GRID_OFFSET_Y + y * BLOCK_SIZE, scaleX: BLOCK_SIZE / 4, scaleY: 1 }); game.addChild(border); } } // Spawn first piece spawnNewPiece(); game.down = function (x, y, obj) { if (!currentPiece) return; var now = Date.now(); if (now - lastMoveTime < moveDelay) return; lastMoveTime = now; // Divide screen into zones for controls var leftZone = 2048 * 0.25; var rightZone = 2048 * 0.75; var rotateZone = 2732 * 0.7; if (x < leftZone) { // Left movement currentPiece.move(-1, 0); } else if (x > rightZone) { // Right movement currentPiece.move(1, 0); } else if (y > rotateZone) { // Drop piece faster currentPiece.move(0, 1); } else { // Rotate piece currentPiece.rotate(); } }; game.update = function () { if (currentPiece) { // Update fall speed based on level currentPiece.fallSpeed = Math.max(10, 60 - (gameLevel - 1) * 5); } // Update UI scoreText.setText('Score: ' + LK.getScore()); levelText.setText('Level: ' + gameLevel); linesText.setText('Lines: ' + linesCleared); };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,353 @@
-/****
+/****
+* Classes
+****/
+var Block = Container.expand(function (blockType) {
+ var self = Container.call(this);
+ self.blockType = blockType || 'block_I';
+ self.gridX = 0;
+ self.gridY = 0;
+ var blockGraphics = self.attachAsset(self.blockType, {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.setGridPosition = function (gridX, gridY) {
+ self.gridX = gridX;
+ self.gridY = gridY;
+ self.x = GRID_OFFSET_X + gridX * BLOCK_SIZE;
+ self.y = GRID_OFFSET_Y + gridY * BLOCK_SIZE;
+ };
+ return self;
+});
+var Tetromino = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.type = type || 'I';
+ self.rotation = 0;
+ self.gridX = 4; // Start in middle of board
+ self.gridY = 0;
+ self.blocks = [];
+ self.fallTimer = 0;
+ self.fallSpeed = 60; // Frames until next fall
+ // Tetromino shapes and rotations
+ self.shapes = {
+ 'I': [[[1, 1, 1, 1]], [[1], [1], [1], [1]], [[1, 1, 1, 1]], [[1], [1], [1], [1]]],
+ 'O': [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]],
+ 'T': [[[0, 1, 0], [1, 1, 1]], [[1, 0], [1, 1], [1, 0]], [[1, 1, 1], [0, 1, 0]], [[0, 1], [1, 1], [0, 1]]],
+ 'S': [[[0, 1, 1], [1, 1, 0]], [[1, 0], [1, 1], [0, 1]], [[0, 1, 1], [1, 1, 0]], [[1, 0], [1, 1], [0, 1]]],
+ 'Z': [[[1, 1, 0], [0, 1, 1]], [[0, 1], [1, 1], [1, 0]], [[1, 1, 0], [0, 1, 1]], [[0, 1], [1, 1], [1, 0]]],
+ 'J': [[[1, 0, 0], [1, 1, 1]], [[1, 1], [1, 0], [1, 0]], [[1, 1, 1], [0, 0, 1]], [[0, 1], [0, 1], [1, 1]]],
+ 'L': [[[0, 0, 1], [1, 1, 1]], [[1, 0], [1, 0], [1, 1]], [[1, 1, 1], [1, 0, 0]], [[1, 1], [0, 1], [0, 1]]]
+ };
+ self.getBlockType = function () {
+ return 'block_' + self.type;
+ };
+ self.createBlocks = function () {
+ // Clear existing blocks
+ for (var i = 0; i < self.blocks.length; i++) {
+ self.blocks[i].destroy();
+ }
+ self.blocks = [];
+ var shape = self.shapes[self.type][self.rotation];
+ for (var y = 0; y < shape.length; y++) {
+ for (var x = 0; x < shape[y].length; x++) {
+ if (shape[y][x] === 1) {
+ var block = new Block(self.getBlockType());
+ block.setGridPosition(self.gridX + x, self.gridY + y);
+ self.blocks.push(block);
+ game.addChild(block);
+ }
+ }
+ }
+ };
+ self.updatePosition = function () {
+ var shape = self.shapes[self.type][self.rotation];
+ for (var i = 0; i < self.blocks.length; i++) {
+ var blockIndex = 0;
+ for (var y = 0; y < shape.length; y++) {
+ for (var x = 0; x < shape[y].length; x++) {
+ if (shape[y][x] === 1) {
+ if (blockIndex === i) {
+ self.blocks[i].setGridPosition(self.gridX + x, self.gridY + y);
+ break;
+ }
+ blockIndex++;
+ }
+ }
+ }
+ }
+ };
+ self.canMoveTo = function (newX, newY, newRotation) {
+ var testRotation = newRotation !== undefined ? newRotation : self.rotation;
+ var shape = self.shapes[self.type][testRotation];
+ for (var y = 0; y < shape.length; y++) {
+ for (var x = 0; x < shape[y].length; x++) {
+ if (shape[y][x] === 1) {
+ var checkX = newX + x;
+ var checkY = newY + y;
+ // Check bounds
+ if (checkX < 0 || checkX >= GRID_WIDTH || checkY >= GRID_HEIGHT) {
+ return false;
+ }
+ // Check collision with placed blocks
+ if (checkY >= 0 && gameGrid[checkY] && gameGrid[checkY][checkX]) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ };
+ self.move = function (deltaX, deltaY) {
+ if (self.canMoveTo(self.gridX + deltaX, self.gridY + deltaY)) {
+ self.gridX += deltaX;
+ self.gridY += deltaY;
+ self.updatePosition();
+ return true;
+ }
+ return false;
+ };
+ self.rotate = function () {
+ var newRotation = (self.rotation + 1) % 4;
+ if (self.canMoveTo(self.gridX, self.gridY, newRotation)) {
+ self.rotation = newRotation;
+ self.createBlocks();
+ LK.getSound('piece_rotate').play();
+ return true;
+ }
+ return false;
+ };
+ self.update = function () {
+ self.fallTimer++;
+ if (self.fallTimer >= self.fallSpeed) {
+ self.fallTimer = 0;
+ if (!self.move(0, 1)) {
+ // Piece has landed
+ self.placePiece();
+ }
+ }
+ };
+ self.placePiece = function () {
+ // Add blocks to grid
+ for (var i = 0; i < self.blocks.length; i++) {
+ var block = self.blocks[i];
+ if (block.gridY >= 0) {
+ if (!gameGrid[block.gridY]) gameGrid[block.gridY] = [];
+ gameGrid[block.gridY][block.gridX] = block;
+ }
+ }
+ LK.getSound('piece_drop').play();
+ checkCompleteLines();
+ spawnNewPiece();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
+// Game constants
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* Game Code
+****/
+// Game constants
+// Tetromino blocks - using different colors for each piece type
+// Cyan
+// Yellow
+// Purple
+// Green
+// Red
+// Blue
+// Orange
+var GRID_WIDTH = 10;
+var GRID_HEIGHT = 20;
+var BLOCK_SIZE = 40;
+var GRID_OFFSET_X = (2048 - GRID_WIDTH * BLOCK_SIZE) / 2;
+var GRID_OFFSET_Y = 200;
+// Game variables
+var gameGrid = [];
+var currentPiece = null;
+var nextPieceType = null;
+var gameLevel = 1;
+var linesCleared = 0;
+var lastMoveTime = 0;
+var moveDelay = 100; // Milliseconds between moves
+// Initialize grid
+for (var y = 0; y < GRID_HEIGHT; y++) {
+ gameGrid[y] = [];
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ gameGrid[y][x] = null;
+ }
+}
+// Tetromino types
+var pieceTypes = ['I', 'O', 'T', 'S', 'Z', 'J', 'L'];
+function getRandomPieceType() {
+ return pieceTypes[Math.floor(Math.random() * pieceTypes.length)];
+}
+function spawnNewPiece() {
+ if (!nextPieceType) {
+ nextPieceType = getRandomPieceType();
+ }
+ currentPiece = new Tetromino(nextPieceType);
+ game.addChild(currentPiece);
+ currentPiece.createBlocks();
+ nextPieceType = getRandomPieceType();
+ // Check game over
+ if (!currentPiece.canMoveTo(currentPiece.gridX, currentPiece.gridY)) {
+ LK.showGameOver();
+ return;
+ }
+}
+function checkCompleteLines() {
+ var completedLines = [];
+ // Find completed lines
+ for (var y = 0; y < GRID_HEIGHT; y++) {
+ var lineComplete = true;
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ if (!gameGrid[y][x]) {
+ lineComplete = false;
+ break;
+ }
+ }
+ if (lineComplete) {
+ completedLines.push(y);
+ }
+ }
+ if (completedLines.length > 0) {
+ // Remove completed lines
+ for (var i = 0; i < completedLines.length; i++) {
+ var lineY = completedLines[i];
+ // Destroy blocks in this line
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ if (gameGrid[lineY][x]) {
+ gameGrid[lineY][x].destroy();
+ gameGrid[lineY][x] = null;
+ }
+ }
+ // Move lines down
+ for (var y = lineY; y > 0; y--) {
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ gameGrid[y][x] = gameGrid[y - 1][x];
+ if (gameGrid[y][x]) {
+ gameGrid[y][x].setGridPosition(x, y);
+ }
+ }
+ }
+ // Clear top line
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ gameGrid[0][x] = null;
+ }
+ }
+ // Update score
+ linesCleared += completedLines.length;
+ var points = 0;
+ switch (completedLines.length) {
+ case 1:
+ points = 100;
+ break;
+ case 2:
+ points = 300;
+ break;
+ case 3:
+ points = 500;
+ break;
+ case 4:
+ points = 800;
+ break;
+ }
+ LK.setScore(LK.getScore() + points * gameLevel);
+ // Level up every 10 lines
+ var newLevel = Math.floor(linesCleared / 10) + 1;
+ if (newLevel > gameLevel) {
+ gameLevel = newLevel;
+ }
+ LK.getSound('line_clear').play();
+ }
+}
+// Create score display
+var scoreText = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0, 0);
+scoreText.x = 50;
+scoreText.y = 100;
+LK.gui.addChild(scoreText);
+var levelText = new Text2('Level: 1', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+levelText.anchor.set(0, 0);
+levelText.x = 50;
+levelText.y = 180;
+LK.gui.addChild(levelText);
+var linesText = new Text2('Lines: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+linesText.anchor.set(0, 0);
+linesText.x = 50;
+linesText.y = 260;
+LK.gui.addChild(linesText);
+// Draw grid borders
+for (var x = 0; x <= GRID_WIDTH; x++) {
+ for (var y = 0; y < GRID_HEIGHT + 1; y++) {
+ if (x === 0 || x === GRID_WIDTH) {
+ var border = LK.getAsset('grid_border', {
+ x: GRID_OFFSET_X + x * BLOCK_SIZE - 2,
+ y: GRID_OFFSET_Y + y * BLOCK_SIZE,
+ scaleX: 1,
+ scaleY: BLOCK_SIZE / 4
+ });
+ game.addChild(border);
+ }
+ }
+}
+for (var y = GRID_HEIGHT; y <= GRID_HEIGHT; y++) {
+ for (var x = 0; x < GRID_WIDTH; x++) {
+ var border = LK.getAsset('grid_border', {
+ x: GRID_OFFSET_X + x * BLOCK_SIZE,
+ y: GRID_OFFSET_Y + y * BLOCK_SIZE,
+ scaleX: BLOCK_SIZE / 4,
+ scaleY: 1
+ });
+ game.addChild(border);
+ }
+}
+// Spawn first piece
+spawnNewPiece();
+game.down = function (x, y, obj) {
+ if (!currentPiece) return;
+ var now = Date.now();
+ if (now - lastMoveTime < moveDelay) return;
+ lastMoveTime = now;
+ // Divide screen into zones for controls
+ var leftZone = 2048 * 0.25;
+ var rightZone = 2048 * 0.75;
+ var rotateZone = 2732 * 0.7;
+ if (x < leftZone) {
+ // Left movement
+ currentPiece.move(-1, 0);
+ } else if (x > rightZone) {
+ // Right movement
+ currentPiece.move(1, 0);
+ } else if (y > rotateZone) {
+ // Drop piece faster
+ currentPiece.move(0, 1);
+ } else {
+ // Rotate piece
+ currentPiece.rotate();
+ }
+};
+game.update = function () {
+ if (currentPiece) {
+ // Update fall speed based on level
+ currentPiece.fallSpeed = Math.max(10, 60 - (gameLevel - 1) * 5);
+ }
+ // Update UI
+ scoreText.setText('Score: ' + LK.getScore());
+ levelText.setText('Level: ' + gameLevel);
+ linesText.setText('Lines: ' + linesCleared);
+};
\ No newline at end of file