A Tetris Clone in JavaScript


This Could Be Better

The JavaScript code below implements a simple clone of Tetris in JavaScript. To see it in action, copy it into an .html file and open that file in a web browser that runs JavaScript.

Tetris

 <html> <body> <script type='text/javascript'> // main function main() { var blockDefnsAll = BlockDefn.Instances._All; var level0 = new Level ( 5, // fallPeriodOfBlocksInTicksPerCell new Map(new Coords(10, 20)) ); var world0 = new World ( blockDefnsAll, level0 ); Globals.Instance.initialize ( 100, // millisecondsPerTimerTick new Coords(160, 320), // viewSize world0 ); } // classes function Block(defn, posInCells) { this.defn = defn; this.posInCells = posInCells; this.orientation = new Coords(1, 0); this.cellPositionsOccupied = [ new Coords(0, 0), new Coords(0, 0), new Coords(0, 0), new Coords(0, 0), ]; this.cellPositionsOccupiedUpdate(); } { // instance methods Block.prototype.cellPositionsOccupiedUpdate = function() { var defn = this.defn; for (var i = 0; i < defn.offsets.length; i++) { var offset = defn.offsets[i]; var posToOverwrite = this.cellPositionsOccupied[i]; posToOverwrite.overwriteWith (…

View original post 1,373 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s