//By Elijah Cirioli
//setup canvases
var canvas = document.getElementById("layer1");
var context = canvas.getContext("2d");
var flashLayer = document.getElementById("layer2");
var fl = flashLayer.getContext("2d");
//game information
var playing = false; //is the game actively being run
var squareSize = 32; //how many pixels across is a signal tile
var screenBounds = [132, -96]; //the corners of the playfield
var currentPiece = []; //the current tetrimino falling
var holdPiece = []; //the current tetrimino being held
var board = []; //the game board
var x = 0; //the x coordinate of the current tetrimino
var y = 0; //the y coordinate of the current tetrimino
var rotation = 0; //the rotation of the current tetrimino
var randomBag = []; //the bag of possible random tetriminoes
var queue = []; //the next three tetriminoes to fall
//scoring and levels
var score = 0; //the player's current score
var highscore = ["", 0]; //the highest score the player has achieved locally
var totalLines = 0; //the total number of lines cleared in a game
var time; //how long the game lasted
var tempTime = 0; //for tracking time when pausing
var level = 1; //game difficulty
var multiplier = 1.0; //score multipier based on level
var linesRemaining = 10; //lines to get to next level
var levelLines = [0, 10, 15, 20, 20, 30, 30, 40, 40, 50, 60, 70, 80, 90, 100, 100, -1]; //the number of lines needed to clear each level
var speeds = [0, 1000, 940, 880, 820, 760, 700, 640, 580, 520, 460, 400, 340, 280, 220, 160, 100]; //how fast tetriminoes fall
//controlling consecutive actions
var lastTetris = false; //was the last score a tetris?
var tSpin = false; //is the player currently perfoming a t-spin
var rotated = false; //have the player rotated without releasing the key
var held = false; //have they held the current piece
var pressedDown = false; //is the player holding the down arrow
var pressedUp = false; //is the player holding the up arrow
var pressedR = false; //is the player holding the...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.