User prompt
Puanı ekranın altına al
User prompt
Level yazısının yanına alev koyabilir misin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Daha belirgin hale getir ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Ejdere animasyon ekle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Biraz daha soluklaştır
User prompt
Biraz daha soluklaştır
User prompt
Blokların düşeceği yeri önizle
User prompt
Ejderi 3 cm aşağı al
User prompt
Yukarıya ejderha koy ve blokları o atsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
İçinde gösterilen bloğu oturt karenin içine
User prompt
Biraz daha büyüt
User prompt
Sağ taraftaki kareyi büyüt biraz
User prompt
Şimdi sonraki gelecek bloğu sağ tarafta göster
User prompt
Kenarları daralt
User prompt
Ekranı kapla
Code edit (1 edits merged)
Please save this source code
User prompt
Tetris Yap
Initial prompt
Tetris yap
/****
* Classes
****/
var Tetromino = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.blocks = [];
self.currentRotation = 0;
// Define tetromino shapes and rotations
self.shapes = {
'I': [[[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]], [[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]]],
'O': [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]],
'T': [[[0, 1, 0], [1, 1, 1], [0, 0, 0]], [[0, 1, 0], [0, 1, 1], [0, 1, 0]], [[0, 0, 0], [1, 1, 1], [0, 1, 0]], [[0, 1, 0], [1, 1, 0], [0, 1, 0]]],
'S': [[[0, 1, 1], [1, 1, 0], [0, 0, 0]], [[0, 1, 0], [0, 1, 1], [0, 0, 1]], [[0, 0, 0], [0, 1, 1], [1, 1, 0]], [[1, 0, 0], [1, 1, 0], [0, 1, 0]]],
'Z': [[[1, 1, 0], [0, 1, 1], [0, 0, 0]], [[0, 0, 1], [0, 1, 1], [0, 1, 0]], [[0, 0, 0], [1, 1, 0], [0, 1, 1]], [[0, 1, 0], [1, 1, 0], [1, 0, 0]]],
'J': [[[1, 0, 0], [1, 1, 1], [0, 0, 0]], [[0, 1, 1], [0, 1, 0], [0, 1, 0]], [[0, 0, 0], [1, 1, 1], [0, 0, 1]], [[0, 1, 0], [0, 1, 0], [1, 1, 0]]],
'L': [[[0, 0, 1], [1, 1, 1], [0, 0, 0]], [[0, 1, 0], [0, 1, 0], [0, 1, 1]], [[0, 0, 0], [1, 1, 1], [1, 0, 0]], [[1, 1, 0], [0, 1, 0], [0, 1, 0]]]
};
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.currentRotation];
for (var row = 0; row < shape.length; row++) {
for (var col = 0; col < shape[row].length; col++) {
if (shape[row][col] === 1) {
var block = new TetrominoBlock(self.type);
block.x = col * 100;
block.y = row * 100;
self.blocks.push(block);
self.addChild(block);
}
}
}
};
self.rotate = function () {
var newRotation = (self.currentRotation + 1) % 4;
var oldRotation = self.currentRotation;
self.currentRotation = newRotation;
self.createBlocks();
// Check if rotation is valid
if (!self.isValidPosition()) {
// Revert rotation if invalid
self.currentRotation = oldRotation;
self.createBlocks();
return false;
}
LK.getSound('rotate').play();
return true;
};
self.isValidPosition = function () {
var shape = self.shapes[self.type][self.currentRotation];
var boardX = Math.floor((self.x - boardOffsetX) / 100);
var boardY = Math.floor((self.y - boardOffsetY) / 100);
for (var row = 0; row < shape.length; row++) {
for (var col = 0; col < shape[row].length; col++) {
if (shape[row][col] === 1) {
var checkX = boardX + col;
var checkY = boardY + row;
// Check boundaries
if (checkX < 0 || checkX >= boardWidth || checkY >= boardHeight) {
return false;
}
// Check collision with placed blocks
if (checkY >= 0 && board[checkY] && board[checkY][checkX] !== null) {
return false;
}
}
}
}
return true;
};
// Initialize with blocks
self.createBlocks();
return self;
});
var TetrominoBlock = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.blockGraphics = self.attachAsset('tetromino' + type, {
anchorX: 0,
anchorY: 0
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x111111
});
/****
* Game Code
****/
// Sound effects
// Board elements
// Tetromino blocks
// Game constants
var boardWidth = 20;
var boardHeight = 20;
var blockSize = 100;
var boardOffsetX = 24;
var boardOffsetY = 200;
// Game state
var board = [];
var currentPiece = null;
var nextPieces = ['I', 'O', 'T', 'S', 'Z', 'J', 'L'];
var fallTimer = 0;
var fallSpeed = 60; // frames per fall
var level = 1;
var linesCleared = 0;
var isGameOver = false;
// Initialize board
function initializeBoard() {
board = [];
for (var row = 0; row < boardHeight; row++) {
board[row] = [];
for (var col = 0; col < boardWidth; col++) {
board[row][col] = null;
}
}
}
// Create board borders
function createBoardBorders() {
// Left border
var leftBorder = LK.getAsset('boardBorder', {
anchorX: 0,
anchorY: 0,
width: 4,
height: boardHeight * blockSize
});
leftBorder.x = boardOffsetX - 4;
leftBorder.y = boardOffsetY;
game.addChild(leftBorder);
// Right border
var rightBorder = LK.getAsset('boardBorder', {
anchorX: 0,
anchorY: 0,
width: 4,
height: boardHeight * blockSize
});
rightBorder.x = boardOffsetX + boardWidth * blockSize;
rightBorder.y = boardOffsetY;
game.addChild(rightBorder);
// Bottom border
var bottomBorder = LK.getAsset('boardBorder', {
anchorX: 0,
anchorY: 0,
width: boardWidth * blockSize + 8,
height: 4
});
bottomBorder.x = boardOffsetX - 4;
bottomBorder.y = boardOffsetY + boardHeight * blockSize;
game.addChild(bottomBorder);
}
// Generate random piece type
function getRandomPieceType() {
var types = ['I', 'O', 'T', 'S', 'Z', 'J', 'L'];
return types[Math.floor(Math.random() * types.length)];
}
// Spawn new piece
function spawnNewPiece() {
if (currentPiece) {
currentPiece.destroy();
}
var pieceType = getRandomPieceType();
currentPiece = new Tetromino(pieceType);
currentPiece.x = boardOffsetX + Math.floor(boardWidth / 2) * blockSize - blockSize * 2;
currentPiece.y = boardOffsetY;
game.addChild(currentPiece);
// Check if game over
if (!currentPiece.isValidPosition()) {
isGameOver = true;
LK.showGameOver();
}
}
// Move piece down
function movePieceDown() {
if (!currentPiece) return false;
currentPiece.y += blockSize;
if (!currentPiece.isValidPosition()) {
currentPiece.y -= blockSize;
placePiece();
return false;
}
return true;
}
// Move piece left
function movePieceLeft() {
if (!currentPiece) return;
currentPiece.x -= blockSize;
if (!currentPiece.isValidPosition()) {
currentPiece.x += blockSize;
}
}
// Move piece right
function movePieceRight() {
if (!currentPiece) return;
currentPiece.x += blockSize;
if (!currentPiece.isValidPosition()) {
currentPiece.x -= blockSize;
}
}
// Place piece on board
function placePiece() {
if (!currentPiece) return;
var shape = currentPiece.shapes[currentPiece.type][currentPiece.currentRotation];
var boardX = Math.floor((currentPiece.x - boardOffsetX) / blockSize);
var boardY = Math.floor((currentPiece.y - boardOffsetY) / blockSize);
// Place blocks on board
for (var row = 0; row < shape.length; row++) {
for (var col = 0; col < shape[row].length; col++) {
if (shape[row][col] === 1) {
var placeX = boardX + col;
var placeY = boardY + row;
if (placeY >= 0 && placeY < boardHeight && placeX >= 0 && placeX < boardWidth) {
// Create placed block
var placedBlock = new TetrominoBlock(currentPiece.type);
placedBlock.x = boardOffsetX + placeX * blockSize;
placedBlock.y = boardOffsetY + placeY * blockSize;
game.addChild(placedBlock);
board[placeY][placeX] = placedBlock;
}
}
}
}
LK.getSound('pieceLand').play();
// Check for completed lines
checkCompletedLines();
// Spawn new piece
spawnNewPiece();
}
// Check for completed lines
function checkCompletedLines() {
var completedLines = [];
// Find completed lines
for (var row = 0; row < boardHeight; row++) {
var isComplete = true;
for (var col = 0; col < boardWidth; col++) {
if (board[row][col] === null) {
isComplete = false;
break;
}
}
if (isComplete) {
completedLines.push(row);
}
}
// Clear completed lines
if (completedLines.length > 0) {
// Remove blocks from completed lines
for (var i = 0; i < completedLines.length; i++) {
var row = completedLines[i];
for (var col = 0; col < boardWidth; col++) {
if (board[row][col]) {
board[row][col].destroy();
board[row][col] = null;
}
}
}
// Drop lines above
for (var i = completedLines.length - 1; i >= 0; i--) {
var clearedRow = completedLines[i];
// Move all rows above down
for (var row = clearedRow; row > 0; row--) {
for (var col = 0; col < boardWidth; col++) {
board[row][col] = board[row - 1][col];
if (board[row][col]) {
board[row][col].y += blockSize;
}
}
}
// Clear top row
for (var col = 0; col < boardWidth; col++) {
board[0][col] = null;
}
// Adjust subsequent cleared rows
for (var j = i + 1; j < completedLines.length; j++) {
completedLines[j]++;
}
}
// Update score
var points = completedLines.length * 100 * level;
if (completedLines.length === 4) points *= 2; // Tetris bonus
LK.setScore(LK.getScore() + points);
scoreTxt.setText(LK.getScore());
linesCleared += completedLines.length;
level = Math.floor(linesCleared / 10) + 1;
fallSpeed = Math.max(10, 60 - (level - 1) * 5);
levelTxt.setText('Level: ' + level);
linesTxt.setText('Lines: ' + linesCleared);
LK.getSound('lineClear').play();
}
}
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var isTouching = false;
game.down = function (x, y, obj) {
touchStartX = x;
touchStartY = y;
isTouching = true;
};
game.up = function (x, y, obj) {
if (!isTouching) return;
isTouching = false;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
// Swipe down for fast drop
if (deltaY > 50 && Math.abs(deltaX) < 30) {
while (movePieceDown()) {
// Keep dropping until piece lands
}
return;
}
// Tap piece to rotate
if (Math.abs(deltaX) < 30 && Math.abs(deltaY) < 30) {
if (currentPiece) {
currentPiece.rotate();
}
return;
}
// Swipe left/right to move
if (Math.abs(deltaX) > 30) {
if (deltaX > 0) {
movePieceRight();
} else {
movePieceLeft();
}
}
};
// Initialize UI
var scoreTxt = new Text2('0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.setText(LK.getScore());
LK.gui.top.addChild(scoreTxt);
var levelTxt = new Text2('Level: 1', {
size: 40,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0, 0);
levelTxt.x = 100;
levelTxt.y = 100;
LK.gui.topLeft.addChild(levelTxt);
var linesTxt = new Text2('Lines: 0', {
size: 40,
fill: 0xFFFFFF
});
linesTxt.anchor.set(0, 0);
linesTxt.x = 100;
linesTxt.y = 150;
LK.gui.topLeft.addChild(linesTxt);
// Initialize game
initializeBoard();
createBoardBorders();
spawnNewPiece();
// Game update loop
game.update = function () {
if (isGameOver) return;
fallTimer++;
if (fallTimer >= fallSpeed) {
fallTimer = 0;
movePieceDown();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -26,10 +26,10 @@
for (var row = 0; row < shape.length; row++) {
for (var col = 0; col < shape[row].length; col++) {
if (shape[row][col] === 1) {
var block = new TetrominoBlock(self.type);
- block.x = col * 40;
- block.y = row * 40;
+ block.x = col * 100;
+ block.y = row * 100;
self.blocks.push(block);
self.addChild(block);
}
}
@@ -51,10 +51,10 @@
return true;
};
self.isValidPosition = function () {
var shape = self.shapes[self.type][self.currentRotation];
- var boardX = Math.floor((self.x - boardOffsetX) / 40);
- var boardY = Math.floor((self.y - boardOffsetY) / 40);
+ var boardX = Math.floor((self.x - boardOffsetX) / 100);
+ var boardY = Math.floor((self.y - boardOffsetY) / 100);
for (var row = 0; row < shape.length; row++) {
for (var col = 0; col < shape[row].length; col++) {
if (shape[row][col] === 1) {
var checkX = boardX + col;
@@ -99,12 +99,12 @@
// Sound effects
// Board elements
// Tetromino blocks
// Game constants
-var boardWidth = 10;
+var boardWidth = 20;
var boardHeight = 20;
-var blockSize = 40;
-var boardOffsetX = 2048 / 2 - boardWidth * blockSize / 2;
+var blockSize = 100;
+var boardOffsetX = 24;
var boardOffsetY = 200;
// Game state
var board = [];
var currentPiece = null;
@@ -168,9 +168,9 @@
currentPiece.destroy();
}
var pieceType = getRandomPieceType();
currentPiece = new Tetromino(pieceType);
- currentPiece.x = boardOffsetX + Math.floor(boardWidth / 2) * blockSize - blockSize;
+ currentPiece.x = boardOffsetX + Math.floor(boardWidth / 2) * blockSize - blockSize * 2;
currentPiece.y = boardOffsetY;
game.addChild(currentPiece);
// Check if game over
if (!currentPiece.isValidPosition()) {