Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed drop bug, added speed multipler

  • Loading branch information...
commit 037f73c920de2b18965759db9e870562d30fc185 1 parent 9ad6560
Hunter Loftis authored
View
4 app/public/js/boardVM.js
@@ -63,6 +63,10 @@ function Board(options) {
this.set_next_block();
}, this]);
+ radio('player.drop').subscribe([function(player) {
+ this.render();
+ }, this]);
+
radio('game.start').subscribe([function(player) {
this.game_over(false);
this.started(true);
View
19 app/public/js/gamerules.js
@@ -355,7 +355,7 @@ function Tetris() {
this.running = false;
this.speed = 500;
this.speed_interval = 10000;
- this.speed_delta = -5;
+ this.speed_multiplier = 0.99;
this.next_speed = 0;
this.min_speed = 100;
this.game_over = true;
@@ -368,7 +368,7 @@ Tetris.prototype = {
if (this.game_over) this.clear();
this.game_over = false;
this.running = true;
- this.next_speed = new Date().getTime() + this.speed_interval;
+ this.slow_down();
radio('game.start').broadcast();
this.tick();
},
@@ -396,8 +396,7 @@ Tetris.prototype = {
}
var now = new Date().getTime();
if (now > this.next_speed && this.speed > this.min_speed) {
- this.speed += this.speed_delta;
- this.next_speed = now + this.speed_interval;
+ this.slow_down();
}
if (this.speed > 100) this.speed --;
radio('game.tick').broadcast();
@@ -406,6 +405,11 @@ Tetris.prototype = {
}, this.speed);
}
},
+ slow_down: function() {
+ this.speed *= this.speed_multiplier;
+ this.next_speed = new Date().getTime() + this.speed_interval;
+ radio('game.speed').broadcast();
+ },
tick_players: function() {
var i = this.players.length;
while (i--) {
@@ -810,7 +814,12 @@ Player.prototype = {
if (this.board.block) return this.board.block.rotate(this.board.rows, false);
},
drop: function() {
- if (this.board.block) return this.board.block.drop(this.board.rows);
+ if (this.board.block) {
+ var result = this.board.block.drop(this.board.rows);
+ radio('player.drop').broadcast(this);
+ this.board.apply_block();
+ return result;
+ }
},
create_game: function(user_id) {
// End any games the user is currently running
View
19 app/public/js/tetris_game.js
@@ -719,7 +719,12 @@ Player.prototype = {
if (this.board.block) return this.board.block.rotate(this.board.rows, false);
},
drop: function() {
- if (this.board.block) return this.board.block.drop(this.board.rows);
+ if (this.board.block) {
+ var result = this.board.block.drop(this.board.rows);
+ radio('player.drop').broadcast(this);
+ this.board.apply_block();
+ return result;
+ }
},
create_game: function(user_id) {
// End any games the user is currently running
@@ -2022,7 +2027,7 @@ function Tetris() {
this.running = false;
this.speed = 500;
this.speed_interval = 10000;
- this.speed_delta = -5;
+ this.speed_multiplier = 0.99;
this.next_speed = 0;
this.min_speed = 100;
this.game_over = true;
@@ -2035,7 +2040,7 @@ Tetris.prototype = {
if (this.game_over) this.clear();
this.game_over = false;
this.running = true;
- this.next_speed = new Date().getTime() + this.speed_interval;
+ this.slow_down();
radio('game.start').broadcast();
this.tick();
},
@@ -2063,8 +2068,7 @@ Tetris.prototype = {
}
var now = new Date().getTime();
if (now > this.next_speed && this.speed > this.min_speed) {
- this.speed += this.speed_delta;
- this.next_speed = now + this.speed_interval;
+ this.slow_down();
}
if (this.speed > 100) this.speed --;
radio('game.tick').broadcast();
@@ -2073,6 +2077,11 @@ Tetris.prototype = {
}, this.speed);
}
},
+ slow_down: function() {
+ this.speed *= this.speed_multiplier;
+ this.next_speed = new Date().getTime() + this.speed_interval;
+ radio('game.speed').broadcast();
+ },
tick_players: function() {
var i = this.players.length;
while (i--) {
View
7 app/shared/gamerules/player.js
@@ -98,7 +98,12 @@ Player.prototype = {
if (this.board.block) return this.board.block.rotate(this.board.rows, false);
},
drop: function() {
- if (this.board.block) return this.board.block.drop(this.board.rows);
+ if (this.board.block) {
+ var result = this.board.block.drop(this.board.rows);
+ radio('player.drop').broadcast(this);
+ this.board.apply_block();
+ return result;
+ }
},
create_game: function(user_id) {
// End any games the user is currently running
View
12 app/shared/gamerules/tetris_game.js
@@ -11,7 +11,7 @@ function Tetris() {
this.running = false;
this.speed = 500;
this.speed_interval = 10000;
- this.speed_delta = -5;
+ this.speed_multiplier = 0.99;
this.next_speed = 0;
this.min_speed = 100;
this.game_over = true;
@@ -24,7 +24,7 @@ Tetris.prototype = {
if (this.game_over) this.clear();
this.game_over = false;
this.running = true;
- this.next_speed = new Date().getTime() + this.speed_interval;
+ this.slow_down();
radio('game.start').broadcast();
this.tick();
},
@@ -52,8 +52,7 @@ Tetris.prototype = {
}
var now = new Date().getTime();
if (now > this.next_speed && this.speed > this.min_speed) {
- this.speed += this.speed_delta;
- this.next_speed = now + this.speed_interval;
+ this.slow_down();
}
if (this.speed > 100) this.speed --;
radio('game.tick').broadcast();
@@ -62,6 +61,11 @@ Tetris.prototype = {
}, this.speed);
}
},
+ slow_down: function() {
+ this.speed *= this.speed_multiplier;
+ this.next_speed = new Date().getTime() + this.speed_interval;
+ radio('game.speed').broadcast();
+ },
tick_players: function() {
var i = this.players.length;
while (i--) {
Please sign in to comment.
Something went wrong with that request. Please try again.