Simple Tetris Clone in TypeScript
Code generated by TypeScript
by katalin_2003
HTML
<div style="position: relative;">
<img id="stc_sprites" src="http://sites.google.com/site/exeqtor/stc_sprites.png" width="0" height="0" />
</div>
CSS
body {
background-color: black;
}
html, body {
width: 480px;
height: 272px;
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
JavaScript
var Stc;
(function (Stc) {
// Clear resources used by platform
// Process events and notify game
// Render the state of the game
// Return the current system time in milliseconds
// Return a random positive integer number
// Data structure that holds information about our tetromino blocks.
var StcTetromino = (function () {
function StcTetromino() {
this.cells = [];
for (var k = 0; k < Game.TETROMINO_SIZE; ++k) {
this.cells[k] = [];
}
}
return StcTetromino;
})();
Stc.StcTetromino = StcTetromino;
// Datas structure for statistical data
var StcStatics = (function () {
function StcStatics() {
this.pieces = [];
}
return StcStatics;
})();
Stc.StcStatics = StcStatics;
var Game = (function () {
function Game() {
this.m_map = [];
for (var k = 0; k < Game.BOARD_TILEMAP_WIDTH; ++k) {
this.m_map[k] = [];
}
this.m_fallingBlock = new StcTetromino();
this.m_nextBlock = new StcTetromino();
}
// Initialize the game. The error code (if any) is saved in [m_errorCode].
Game.BOARD_TILEMAP_WIDTH = 10;
Game.BOARD_TILEMAP_HEIGHT = 22;
Game.INIT_DELAY_FALL = 1000;
Game.SCORE_1_FILLED_ROW = 400;
Game.SCORE_2_FILLED_ROW = 1000;
Game.SCORE_3_FILLED_ROW = 3000;
Game.SCORE_4_FILLED_ROW = 12000;
Game.SCORE_MOVE_DOWN_DIVISOR = 1000;
Game.SCORE_DROP_DIVISOR = 20;
Game.SCORE_DROP_WITH_SHADOW_DIVISOR = 100;
Game.FILLED_ROWS_FOR_LEVEL_UP = 10;
Game.DELAY_FACTOR_FOR_LEVEL_UP = 9;
Game.DELAY_DIVISOR_FOR_LEVEL_UP = 10;
Game.DAS_DELAY_TIMER = 200;
Game.DAS_MOVE_TIMER = 40;
Game.ROTATION_AUTOREPEAT_DELAY = 375;
Game.ROTATION_AUTOREPEAT_TIMER = 200;
Game.ERROR_NONE = 0;
...