Skip to content

Commit 33d44d1

Browse files
committed
Pause button
1 parent 77a7902 commit 33d44d1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jake Gordon and contributors
1+
Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Jake Gordon and contributors
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

index.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
// game constants
6969
//-------------------------------------------------------------------------
7070

71-
var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SHIFT: 16 },
71+
var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SHIFT: 16, P: 80 },
7272
// drop all the way to BOTTOM is an action, but MAX=3 to avoid reaching
7373
// it by rotation
7474
DIR = { UP: 0, RIGHT: 1, DOWN: 2, LEFT: 3, BOTTOM:4, MIN: 0, MAX: 3 },
@@ -78,6 +78,7 @@
7878
ucanvas = get('upcoming'),
7979
uctx = ucanvas.getContext('2d'),
8080
speed = { start: 0.6, decrement: 0.005, min: 0.1 }, // how long before piece drops by 1 row (seconds)
81+
paused = 0,
8182
nx = 10, // width of tetris court (in blocks)
8283
ny = 20, // height of tetris court (in blocks)
8384
nu = 5; // width/height of upcoming preview (in blocks)
@@ -229,6 +230,15 @@
229230
}
230231
break;
231232
case KEY.ESC: lose(); handled = true; break;
233+
case KEY.P:
234+
if( paused == 1 ) {
235+
paused = 0;
236+
}
237+
else {
238+
paused = 1;
239+
}
240+
handled = true;
241+
break;
232242
}
233243
}
234244
else if (ev.keyCode == KEY.SPACE) {
@@ -320,6 +330,9 @@
320330
}
321331

322332
function drop() {
333+
if( paused == 0 ) {
334+
console.log( "0" );
335+
323336
if (!move(DIR.DOWN)) {
324337
addScore(10);
325338
dropPiece();
@@ -331,6 +344,7 @@
331344
lose();
332345
}
333346
}
347+
} // paused
334348
}
335349

336350
function dropMany() {

0 commit comments

Comments
 (0)