From 33d44d1bb12acdde493ad1e5f3d37605ea7bdf46 Mon Sep 17 00:00:00 2001 From: Stasinos Konstantopoulos Date: Wed, 17 Oct 2018 11:38:46 +0300 Subject: [PATCH] Pause button --- LICENSE | 2 +- index.html | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 7d4b906..6d2b72f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jake Gordon and contributors +Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Jake Gordon and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/index.html b/index.html index 13772a9..8405d8d 100644 --- a/index.html +++ b/index.html @@ -68,7 +68,7 @@ // game constants //------------------------------------------------------------------------- - var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SHIFT: 16 }, + var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SHIFT: 16, P: 80 }, // drop all the way to BOTTOM is an action, but MAX=3 to avoid reaching // it by rotation DIR = { UP: 0, RIGHT: 1, DOWN: 2, LEFT: 3, BOTTOM:4, MIN: 0, MAX: 3 }, @@ -78,6 +78,7 @@ ucanvas = get('upcoming'), uctx = ucanvas.getContext('2d'), speed = { start: 0.6, decrement: 0.005, min: 0.1 }, // how long before piece drops by 1 row (seconds) + paused = 0, nx = 10, // width of tetris court (in blocks) ny = 20, // height of tetris court (in blocks) nu = 5; // width/height of upcoming preview (in blocks) @@ -229,6 +230,15 @@ } break; case KEY.ESC: lose(); handled = true; break; + case KEY.P: + if( paused == 1 ) { + paused = 0; + } + else { + paused = 1; + } + handled = true; + break; } } else if (ev.keyCode == KEY.SPACE) { @@ -320,6 +330,9 @@ } function drop() { + if( paused == 0 ) { + console.log( "0" ); + if (!move(DIR.DOWN)) { addScore(10); dropPiece(); @@ -331,6 +344,7 @@ lose(); } } + } // paused } function dropMany() {