Commits

Shu Zong Chen committed a0befd4

fixed game over

  • Participants
  • Parent commits df944a8

Comments (0)

Files changed (1)

File public_html/static/js/main.js

 	var BLUE = 3;
 	var GREEN = 4;
 	var RED = 5;
-	var ALL_COLORS = [BLUE, GREEN, RED];
+	var YELLOW = 6;
+	var PURPLE = 7;
+	var ORANGE = 8;
+	var ALL_COLORS = [BLUE, GREEN, RED, YELLOW, PURPLE, ORANGE];
 
 	var STOP = -1;
 	var LEFT = 0;
 			var p = this.hud.score;
 			this.hud.show_message(["OOPS, NO HIGH SCORE", "SERVER, BUT HERE ARE SOME", "NUMBERS I JUST MADE UP:", "", "SOMEONE ELSE: " + (p + 10000 + random_num(10000)), "HIS COUSIN: " + (p + 5000 + random_num(5000)), "MY DOG: " + (p + 2500 + random_num(2500)), "NOT YOU: " + (p + 1), "YOU: " + p]);
 		},
-		panic: function(){
+		panic: function(game_over){
+			if (_.isUndefined(game_over)){
+				game_over = false;
+			}
 			// our temporary stuff that happens when you die
 			this.snake.emote('dead');
 			this.snake.render();
 			this.sounds.play('crash');
 
 			this.hud.lock_screen();
-			window.setTimeout(lang.hitch(this, function(){
-				this.hud.unlock_screen();
-				this.hud.show_message(["YOU SHOULD AVOID THINGS", "(THINGS THAT YOU CAN'T", "EAT THAT IS)"]);
-				this.grid.add(this.snake);
-				this.snake.reset();
-			}), 2000);
+			if (game_over){
+				window.setTimeout(lang.hitch(this, function(){
+					this.go_game_over();
+				}), 2000);
+			}else{
+				window.setTimeout(lang.hitch(this, function(){
+					this.hud.unlock_screen();
+					this.hud.show_message(["YOU SHOULD AVOID THINGS", "(THINGS THAT YOU CAN'T", "EAT THAT IS)"]);
+					this.grid.add(this.snake);
+					this.snake.reset();
+				}), 2000);
+			}
 		},
 		hooray: function(){
 			this.grid.add(this.snake);
 			new_pos = rel_to_pos(head.pos, this.heading);
 			this.direction = this.heading;
 			if (is_offsides(new_pos) || this.collides_with(new_pos)){
-				this.engine.panic();
 				return this.engine.hud.lose_life();
 			}
 			if (this.engine.grid.collides_with(new_pos)){
 					this.engine.sounds.play('blast');
 					this.set_color(CLEAR);
 				}else{
-					this.engine.panic();
 					return this.engine.hud.lose_life();
 				}
 			}
 			this.lives--;
 			this.render();
 			if (this.lives < 1){
-				this.engine.go_game_over();
+				this.engine.panic(true);
+			}else{
+				this.engine.panic();
 			}
 		},
 		render: function(){