User prompt
Establish a scoring mechanism that incentivizes efficient gameplay. For instance, award more points for clearing multiple lines simultaneously or achieving higher levels. Display the current score, level, and potentially other relevant metrics prominently within the game interface.
User prompt
Collision detection is pivotal for gameplay integrity. Implement robust algorithms to detect collisions between Tetromino blocks and the game board boundaries or other stationary blocks. If a collision occurs, prevent the Tetromino from moving further in the obstructed direction and consider it for potential line completion
User prompt
Develop algorithms for spawning Tetrominoes at the top of the game board, allowing them to descend automatically at regular intervals. Incorporate logic to enable players to rotate Tetromino shapes clockwise or counterclockwise, ensuring that rotations do not result in illegal placements or overlaps.
User prompt
The game board serves as the canvas for gameplay. It should manage the grid system, keep track of occupied cells by Tetromino blocks, and detect completed rows. Implement functions to check for completed lines. Once a line is filled with blocks, remove those blocks, shift the remaining blocks down, and increment the player's score.
User prompt
Object-oriented programming can greatly simplify the game's structure. Create distinct classes for game entities such as Tetrominoes and the game board. Within the Tetromino class, define methods for movement (left, right, down), rotation, and collision detection. Each Tetromino shape should be modular, consisting of individual blocks that move and rotate cohesively
User prompt
Assets are crucial for visual representation. Utilize a function like LK.getAsset to import or retrieve the graphics for each Tetromino shape (e.g., L-shape, T-shape). Ensure that the anchor points of these assets are appropriately set. This ensures consistent positioning and rotation behavior when manipulating the Tetromino blocks.
User prompt
Begin by establishing the foundational elements of your game. This entails setting up the game board grid, often represented as a 2D array where each cell can be occupied by a Tetromino block or remain empty. Initialize essential variables such as the current score, level, and game state (e.g., paused, active, game over). Consider implementing a background color or even a background image to enhance the visual appeal and atmosphere of the game.
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'nextTetrominoType')' in this line: 'var type = GameState.nextTetrominoType != null ? GameState.nextTetrominoType : GameState.tetrominoTypes[Math.floor(Math.random() * GameState.tetrominoTypes.length)];' Line Number: 373
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'nextTetrominoType')' in this line: 'var type = GameState.nextTetrominoType != null ? GameState.nextTetrominoType : GameState.tetrominoTypes[Math.floor(Math.random() * GameState.tetrominoTypes.length)];' Line Number: 372
User prompt
Game Initialization: Begin by establishing the foundational elements of your game. This entails setting up the game board grid, often represented as a 2D array where each cell can be occupied by a Tetromino block or remain empty. Initialize essential variables such as the current score, level, and game state (e.g., paused, active, game over). Consider implementing a background color or even a background image to enhance the visual appeal and atmosphere of the game. Asset Creation: Assets are crucial for visual representation. Utilize a function like LK.getAsset to import or retrieve the graphics for each Tetromino shape (e.g., L-shape, T-shape). Ensure that the anchor points of these assets are appropriately set. This ensures consistent positioning and rotation behavior when manipulating the Tetromino blocks. Game Object Classes: Object-oriented programming can greatly simplify the game's structure. Create distinct classes for game entities such as Tetrominoes and the game board. Within the Tetromino class, define methods for movement (left, right, down), rotation, and collision detection. Each Tetromino shape should be modular, consisting of individual blocks that move and rotate cohesively. Game Board: The game board serves as the canvas for gameplay. It should manage the grid system, keep track of occupied cells by Tetromino blocks, and detect completed rows. Implement functions to check for completed lines. Once a line is filled with blocks, remove those blocks, shift the remaining blocks down, and increment the player's score. Tetromino Mechanics: Develop algorithms for spawning Tetrominoes at the top of the game board, allowing them to descend automatically at regular intervals. Incorporate logic to enable players to rotate Tetromino shapes clockwise or counterclockwise, ensuring that rotations do not result in illegal placements or overlaps. Collision Detection: Collision detection is pivotal for gameplay integrity. Implement robust algorithms to detect collisions between Tetromino blocks and the game board boundaries or other stationary blocks. If a collision occurs, prevent the Tetromino from moving further in the obstructed direction and consider it for potential line completion. Line Clearing: Upon detecting a fully occupied horizontal line, trigger a line-clearing mechanism. Remove the filled line, shift all blocks above downward, and update the player's score based on the number of lines cleared simultaneously. Scoring System: Establish a scoring mechanism that incentivizes efficient gameplay. For instance, award more points for clearing multiple lines simultaneously or achieving higher levels. Display the current score, level, and potentially other relevant metrics prominently within the game interface. Game Over Condition: Define clear conditions that signify the end of a game session, such as when newly spawned Tetrominoes cannot descend due to obstruction at the top of the game board. Upon meeting these conditions, transition the game into a 'Game Over' state, display the player's final score, and provide options for restarting or exiting. Game Loop: Implement a consistent game loop using events or timers to manage game progression. This loop should handle Tetromino descent speed, user input responsiveness, and periodic game state updates. Ensure that the game loop maintains a smooth and consistent frame rate for optimal player experience. User Input: Facilitate intuitive user interactions by incorporating touch event handlers for mobile devices or mouse interactions for desktop environments. Translate user gestures, such as swipes or taps, into actionable commands for Tetromino movement, rotation, and other gameplay actions. Game State Management: Maintain a centralized game state management system that tracks essential variables, including active Tetrominoes, game board status, player score, and overall game progression. This centralized approach ensures coherence across different game components and simplifies debugging and feature additions. UI Elements: Design an intuitive user interface that enhances gameplay immersion. Incorporate elements like score displays, level indicators, and potentially a preview of the upcoming Tetromino shape. Utilize LK.gui or similar tools to position UI elements strategically, ensuring visibility without obstructing critical gameplay areas. Game Flow: Establish a seamless game flow that guides players from the start of a game session through various stages, including pausing, resuming, and restarting. Implement user-friendly controls or buttons for initiating game sessions, navigating menus, and managing game state transitions. Testing and Debugging: Prioritize rigorous testing across various devices and platforms to identify potential bugs, performance issues, or gameplay inconsistencies. Incorporate debugging tools or logging mechanisms to trace errors, monitor game metrics, and refine gameplay mechanics iteratively. In summary, creating a Tetris game necessitates meticulous planning, consistent execution, and iterative refinement. By systematically addressing each component, from game initialization to testing, developers can craft an engaging and authentic Tetris experience for players of all ages.
User prompt
Fix Bug: 'Uncaught ReferenceError: nextTetrominoType is not defined' in this line: 'var type = nextTetrominoType != null ? nextTetrominoType : tetrominoTypes[Math.floor(Math.random() * tetrominoTypes.length)];' Line Number: 329
User prompt
**UI Elements**: Add UI elements like the score display, using `LK.gui` to position them on the screen.
User prompt
Manage the game state, including the current and next Tetromino, the state of the game board, and whether the game is over
User prompt
**User Input**: Handle touch events to allow players to move and rotate Tetrominoes. Use `obj.event.getLocalPosition` to determine touch positions
User prompt
Use the `LK.on('tick', function() {})` to create a game loop that handles the automatic downward movement of Tetrominoes, user input, and game state updates.
User prompt
**Game Over Condition**: Define the conditions that will trigger the end of the game, such as when new Tetrominoes cannot be placed at the top of the board.
User prompt
**Scoring**: Implement a scoring system that rewards the player for clearing lines.
User prompt
7. **Line Clearing**: When a horizontal line is completely filled with blocks, it should be cleared, and the blocks above should fall down to fill the space.
User prompt
Write code to detect collisions between Tetrominoes and the game board boundaries or other fixed blocks
User prompt
**Collision Detection**: Write code to detect collisions between Tetrominoes and the game board boundaries or other fixed blocks.
User prompt
The game board is a grid where the Tetrominoes will be placed. It should keep track of the positions of fixed blocks and check for completed lines.
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'var type = typeof nextTetrominoType !== 'undefined' ? nextTetrominoType : tetrominoTypes[Math.floor(Math.random() * tetrominoTypes.length)];' Line Number: 249
User prompt
**Game Board**: The game board is a grid where the Tetrominoes will be placed. It should keep track of the positions of fixed blocks and check for completed lines.
User prompt
Create classes for the game objects, such as Tetrominoes and the game board. Each Tetromino should be composed of individual blocks that can be moved and rotated as a unit.
User prompt
**Game Object Classes**: Create classes for the game objects, such as Tetrominoes and the game board. Each Tetromino should be composed of individual blocks that can be moved and rotated as a unit.
/**** * Classes ****/ var TetrominoBlock = Container.expand(function (type, i, j) { var self = Container.call(this); var blockGraphic = self.createAsset('tetromino_' + type + '_' + i + '_' + j, type + ' Tetromino block at (' + i + ', ' + j + ')', 0.5, 0.5); self.x = j * blockSize; self.y = i * blockSize; }); // Define Tetromino class var Tetromino = Container.expand(function () { var self = Container.call(this); Tetromino.prototype.checkCollision = function (dx, dy, board) { for (var i = 0; i < this.blocks.length; i++) { var block = this.blocks[i]; var newX = this.x + block.x + dx; var newY = this.y + block.y + dy; var gridX = Math.floor(newX / blockSize); var gridY = Math.floor(newY / blockSize); if (gridX < 0 || gridX >= boardWidth || gridY >= boardHeight) { return true; // Collision with board boundaries } if (gridY >= 0 && board.grid[gridY] && board.grid[gridY][gridX]) { return true; // Collision with another block } } return false; }; this.blocks = []; this.type = ''; this.rotationIndex = 0; this.initializeBlocks = function (layout) {this.initializeBlocks = function (layout) { for (var i = 0; i < layout.length; i++) { for (var j = 0; j < layout[i].length; j++) { if (layout[i][j]) { var block = new TetrominoBlock(this.type, i, j); this.blocks.push(this.addChild(block)); } } } }; }; this.create = function (type) { this.type = type; this.rotationIndex = 0; var layout = tetrominoLayouts[type][this.rotationIndex]; this.initializeBlocks(layout); }; this.rotate = function () { var oldRotationIndex = this.rotationIndex; var newRotationIndex = (this.rotationIndex + 1) % tetrominoLayouts[this.type].length; this.rotationIndex = newRotationIndex; this.updateBlockPositions(); if (this.checkCollision(0, 0, board)) { this.rotationIndex = oldRotationIndex; this.updateBlockPositions(); } }; this.updateBlockPositions = function () { var layout = tetrominoLayouts[this.type][this.rotationIndex]; var k = 0; for (var i = 0; i < layout.length; i++) { for (var j = 0; j < layout[i].length; j++) { if (layout[i][j]) { this.blocks[k].x = j * this.blocks[k].width; this.blocks[k].y = i * this.blocks[k].height; k++; } } } }; this.move = function (dx, dy) { if (!this.checkCollision(dx, dy, board)) { this.x += dx; this.y += dy; } else if (dy > 0) { board.fixTetromino(this); spawnTetromino(); } }; }); // Define GameBoard class var GameBoard = Container.expand(function () { var self = Container.call(this); this.grid = gameBoardGrid; // Reference the initialized game board grid this.checkLines = function () { var linesCleared = 0; for (var y = 0; y < boardHeight; y++) { var lineComplete = true; for (var x = 0; x < boardWidth; x++) { if (this.grid[y][x] === null) { lineComplete = false; break; } } if (lineComplete) { linesCleared++; for (var row = y; row > 0; row--) { for (var x = 0; x < boardWidth; x++) { this.grid[row][x] = this.grid[row - 1][x]; if (this.grid[row][x]) { this.grid[row][x].y += blockSize; } } } for (var x = 0; x < boardWidth; x++) { this.grid[0][x] = null; } } } if (linesCleared > 0) { var scoreToAdd = linesCleared * linesCleared * 100; LK.setScore(LK.getScore() + scoreToAdd); scoreDisplay.updateScore(LK.getScore()); GameState.level = Math.floor(LK.getScore() / 1000) + 1; fallRate = Math.max(1000 - (GameState.level - 1) * 100, 200); scoreDisplay.updateLevel(GameState.level); scoreDisplay.updateLinesCleared(GameState.linesCleared); } } this.fixTetromino = function (tetromino) { // Fix Tetromino to the board // ... (Fixing code here) }; }); // Define GameBoard class var GameBoard = Container.expand(function () { var self = Container.call(this); this.grid = []; this.init = function () { for (var i = 0; i < boardHeight; i++) { this.grid[i] = []; for (var j = 0; j < boardWidth; j++) { this.grid[i][j] = null; } } }; this.fixTetromino = function (tetromino) { var blocks = tetromino.blocks; for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; var x = Math.round((block.x + tetromino.x - this.x) / blockSize); var y = Math.round((block.y + tetromino.y - this.y) / blockSize); if (y < boardHeight && x < boardWidth) { this.grid[y][x] = block; block.x = x * blockSize; block.y = y * blockSize; this.addChild(block); } else if (y < 0) { LK.showGameOver(); return false; } } this.checkLines(); return true; }; this.isGameOver = function () { for (var x = 0; x < boardWidth; x++) { if (this.grid[0][x] !== null) { return true; } } return false; }; this.checkLines = function () { for (var y = 0; y < boardHeight; y++) { var lineComplete = true; for (var x = 0; x < boardWidth; x++) { if (this.grid[y][x] === null) { lineComplete = false; break; } } if (lineComplete) { for (var row = y; row > 0; row--) { for (var x = 0; x < boardWidth; x++) { this.grid[row][x] = this.grid[row - 1][x]; if (this.grid[row][x]) { this.grid[row][x].y += blockSize; } } } for (var x = 0; x < boardWidth; x++) { this.grid[0][x] = null; } for (var x = 0; x < boardWidth; x++) { if (this.grid[y][x]) { this.grid[y][x].destroy(); this.grid[y][x] = null; } } var linesCleared = 0; for (var y = 0; y < boardHeight; y++) { var lineComplete = true; for (var x = 0; x < boardWidth; x++) { if (this.grid[y][x] === null) { lineComplete = false; break; } } if (lineComplete) { linesCleared++; for (var row = y; row > 0; row--) { for (var x = 0; x < boardWidth; x++) { this.grid[row][x] = this.grid[row - 1][x]; if (this.grid[row][x]) { this.grid[row][x].y += blockSize; } } } for (var x = 0; x < boardWidth; x++) { this.grid[0][x] = null; } for (var x = 0; x < boardWidth; x++) { if (this.grid[y][x]) { this.grid[y][x].destroy(); this.grid[y][x] = null; } } } } if (linesCleared > 0) { var scoreToAdd = (linesCleared === 1) ? 100 : (linesCleared === 2) ? 300 : (linesCleared === 3) ? 500 : 800; LK.setScore(LK.getScore() + scoreToAdd); scoreTxt.setText(LK.getScore()); } } } }; this.init(); }); // Define LowerField class for collecting Tetrominoes var LowerField = Container.expand(function () { var self = Container.call(this); this.init = function () { this.grid = []; for (var i = 0; i < boardHeight; i++) { this.grid[i] = []; for (var j = 0; j < boardWidth; j++) { this.grid[i][j] = null; } } }; this.init(); this.addBlock = function (block, x, y) { if (y < boardHeight && x < boardWidth) { this.grid[y][x] = block; block.x = x * blockSize; block.y = y * blockSize; this.addChild(block); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background for better contrast }); /**** * Game Code ****/ // Define game constants and variables var boardWidth = 10; var boardHeight = 20; var blockSize = 2048 / boardWidth; // Calculate block size based on viewable area width var fallRate = 1000; // Time in milliseconds between each Tetromino fall step var score = 0; // Initialize current score var level = 1; // Initialize game level var gameState = 'active'; // Game state can be 'paused', 'active', or 'gameOver' this.grid = []; for (var i = 0; i < boardHeight; i++) { this.grid[i] = []; for (var j = 0; j < boardWidth; j++) { this.grid[i][j] = null; // Each cell starts as null (empty) } } // GameBoard class is now encapsulated and instantiated separately var board = new GameBoard(); board.init(); // Center the board on the screen board.x = (2048 - boardWidth * blockSize) / 2; board.y = (2732 - boardHeight * blockSize) / 2; // Add the board to the game game.addChild(board); // Create score display var ScoreDisplay = Container.expand(function () { var self = Container.call(this); this.scoreText = new Text2('Score: 0', { size: 100, fill: "#ffffff", anchor: { x: 0.5, y: 0 } }); this.levelText = new Text2('Level: 1', { size: 100, fill: "#ffffff", anchor: { x: 0.5, y: 0 } }); this.linesText = new Text2('Lines: 0', { size: 100, fill: "#ffffff", anchor: { x: 0.5, y: 0 } }); LK.gui.top.addChild(this.scoreText); LK.gui.top.addChild(this.levelText); LK.gui.top.addChild(this.linesText); this.levelText.y = this.scoreText.height; this.linesText.y = this.scoreText.height * 2; this.updateScore = function (score) { this.scoreText.setText('Score: ' + score.toString()); }; this.updateLevel = function (level) { this.levelText.setText('Level: ' + level.toString()); }; this.updateLinesCleared = function (lines) { this.linesText.setText('Lines: ' + lines.toString()); }; }); // Create a new ScoreDisplay instance var scoreDisplay = new ScoreDisplay(); // Initialize the first Tetromino spawnTetromino(); // Define game constants and variables var TetrominoMovement = { calculateMove: function calculateMove(tetromino, dx, dy, board) { var newX = tetromino.x + dx; var newY = tetromino.y + dy; var canMove = true; for (var i = 0; i < tetromino.blocks.length; i++) { var block = tetromino.blocks[i]; var gridX = Math.round((block.x + newX - board.x) / blockSize); var gridY = Math.round((block.y + newY - board.y) / blockSize); if (gridX < 0 || gridX >= boardWidth || gridY < 0 || gridY >= boardHeight) { canMove = false; break; } else if (gridY >= 0 && board.grid[gridY] && board.grid[gridY][gridX]) { canMove = false; break; } } return { canMove: canMove, newX: newX, newY: newY }; } }; var boardWidth = 10; var boardHeight = 20; var blockSize = 2048 / boardWidth; // Calculate block size based on viewable area width var fallRate = 1000; // Time in milliseconds between each Tetromino fall step // GameBoard class is now encapsulated and instantiated separately var board = new GameBoard(); game.addChild(board); var GameState = { currentTetromino: null, nextTetrominoType: null, tetrominoTypes: ['I', 'J', 'L', 'O', 'S', 'T', 'Z'], tetrominoLayouts: { 'I': [[[1, 1, 1, 1]]], 'J': [[[1, 0, 0], [1, 1, 1]]], 'L': [[[0, 0, 1], [1, 1, 1]]], 'O': [[[1, 1], [1, 1]]], 'S': [[[0, 1, 1], [1, 1, 0]]], 'T': [[[0, 1, 0], [1, 1, 1]]], 'Z': [[[1, 1, 0], [0, 1, 1]]] }, scoreTxt: null, isGameOver: false, initialize: function() { GameState.nextTetrominoType = this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)]; GameState.linesCleared = 0; GameState.spawnTetromino(); scoreDisplay = new ScoreDisplay(); }, spawnTetromino: function() { GameState.linesCleared = 0; scoreDisplay.updateLinesCleared(GameState.linesCleared); var type = this.nextTetrominoType != null ? this.nextTetrominoType : this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)]; this.nextTetrominoType = this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)]; this.currentTetromino = new Tetromino(); this.currentTetromino.create(type); this.currentTetromino.x = board.x + (boardWidth * blockSize - this.currentTetromino.width) / 2; this.currentTetromino.y = board.y - this.currentTetromino.height; game.addChild(this.currentTetromino); }, gameOver: function() { this.isGameOver = true; LK.showGameOver(); } }; GameState.initialize(); // Initialize board board.init(); // Center the board on the screen board.x = (2048 - boardWidth * blockSize) / 2; board.y = (2732 - boardHeight * blockSize) / 2; // Create score display scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.top.addChild(scoreTxt); // Function to spawn a new tetromino function spawnTetromino() { var type = GameState.nextTetrominoType != null ? GameState.nextTetrominoType : GameState.tetrominoTypes[Math.floor(Math.random() * GameState.tetrominoTypes.length)]; GameState.nextTetrominoType = GameState.tetrominoTypes[Math.floor(Math.random() * GameState.tetrominoTypes.length)]; GameState.currentTetromino = new Tetromino(); GameState.currentTetromino.create(type); GameState.currentTetromino.x = board.x + boardWidth / 2 * blockSize - GameState.currentTetromino.width / 2; GameState.currentTetromino.y = board.y; game.addChild(GameState.currentTetromino); } // Start the game with a new tetromino spawnTetromino(); // Implement automatic Tetromino descent var fallInterval = LK.setInterval(function() { if (GameState.currentTetromino) { GameState.currentTetromino.move(0, blockSize); } }, fallRate); // Game tick event LK.on('tick', function () { // Implement fall rate timer if (LK.ticks % (fallRate / (1000 / 60)) === 0) { // Attempt to move current tetromino down and check for collision currentTetromino.move(0, blockSize); if (currentTetromino.isFixed) { // Collision occurred and Tetromino is fixed, spawn a new Tetromino spawnTetromino(); } } // Check for completed lines board.checkLines(); // Check for game over if (board.isGameOver()) { isGameOver = true; LK.showGameOver(); } // Handle user input for moving and rotating the tetromino handleUserInput(); }); // Function to handle user input for moving and rotating the tetromino function handleUserInput() { game.on('down', function (obj) { var touchPos = obj.event.getLocalPosition(game); // Define touch areas for control var leftArea = { x: board.x, width: boardWidth * blockSize / 3 }; var rightArea = { x: board.x + boardWidth * blockSize * 2 / 3, width: boardWidth * blockSize / 3 }; var rotateArea = { x: board.x + boardWidth * blockSize / 3, width: boardWidth * blockSize / 3 }; // Move tetromino left if (touchPos.x >= leftArea.x && touchPos.x < leftArea.x + leftArea.width) { currentTetromino.move(-blockSize, 0); } // Move tetromino right else if (touchPos.x >= rightArea.x && touchPos.x < rightArea.x + rightArea.width) { currentTetromino.move(blockSize, 0); } // Rotate tetromino else if (touchPos.x >= rotateArea.x && touchPos.x < rotateArea.x + rotateArea.width) { currentTetromino.rotate(); } }); } // Touch event listeners for rotating and moving tetromino
===================================================================
--- original.js
+++ change.js
@@ -109,11 +109,15 @@
}
}
}
if (linesCleared > 0) {
-var scoreToAdd = (linesCleared === 1) ? 100 : (linesCleared === 2) ? 300 : (linesCleared === 3) ? 500 : 800;
+var scoreToAdd = linesCleared * linesCleared * 100;
LK.setScore(LK.getScore() + scoreToAdd);
-scoreTxt.setText(LK.getScore());
+scoreDisplay.updateScore(LK.getScore());
+GameState.level = Math.floor(LK.getScore() / 1000) + 1;
+fallRate = Math.max(1000 - (GameState.level - 1) * 100, 200);
+scoreDisplay.updateLevel(GameState.level);
+scoreDisplay.updateLinesCleared(GameState.linesCleared);
}
}
this.fixTetromino = function (tetromino) {
// Fix Tetromino to the board
@@ -288,17 +292,37 @@
// Create score display
var ScoreDisplay = Container.expand(function () {
var self = Container.call(this);
-this.scoreText = new Text2('0', {
-size: 150,
+this.scoreText = new Text2('Score: 0', {
+size: 100,
fill: "#ffffff",
anchor: { x: 0.5, y: 0 }
});
+this.levelText = new Text2('Level: 1', {
+size: 100,
+fill: "#ffffff",
+anchor: { x: 0.5, y: 0 }
+});
+this.linesText = new Text2('Lines: 0', {
+size: 100,
+fill: "#ffffff",
+anchor: { x: 0.5, y: 0 }
+});
LK.gui.top.addChild(this.scoreText);
+LK.gui.top.addChild(this.levelText);
+LK.gui.top.addChild(this.linesText);
+this.levelText.y = this.scoreText.height;
+this.linesText.y = this.scoreText.height * 2;
this.updateScore = function (score) {
-this.scoreText.setText(score.toString());
+this.scoreText.setText('Score: ' + score.toString());
};
+this.updateLevel = function (level) {
+this.levelText.setText('Level: ' + level.toString());
+};
+this.updateLinesCleared = function (lines) {
+this.linesText.setText('Lines: ' + lines.toString());
+};
});
// Create a new ScoreDisplay instance
var scoreDisplay = new ScoreDisplay();
@@ -354,17 +378,15 @@
scoreTxt: null,
isGameOver: false,
initialize: function() {
GameState.nextTetrominoType = this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)];
+GameState.linesCleared = 0;
GameState.spawnTetromino();
-this.scoreTxt = new Text2('0', {
-size: 150,
-fill: "#ffffff"
-});
-this.scoreTxt.anchor.set(.5, 0);
-LK.gui.top.addChild(this.scoreTxt);
+scoreDisplay = new ScoreDisplay();
},
spawnTetromino: function() {
+GameState.linesCleared = 0;
+scoreDisplay.updateLinesCleared(GameState.linesCleared);
var type = this.nextTetrominoType != null ? this.nextTetrominoType : this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)];
this.nextTetrominoType = this.tetrominoTypes[Math.floor(Math.random() * this.tetrominoTypes.length)];
this.currentTetromino = new Tetromino();
this.currentTetromino.create(type);