|
@@ -7,6 +7,7 @@ var Controller = function(){
|
|
|
this.views = [];
|
|
this.views = [];
|
|
|
this.snake = new Snake(this.initial_length);
|
|
this.snake = new Snake(this.initial_length);
|
|
|
this.canTurn = true;
|
|
this.canTurn = true;
|
|
|
|
|
+ this.counter = 0;
|
|
|
var pos0 = {x: -1, y: -1};
|
|
var pos0 = {x: -1, y: -1};
|
|
|
|
|
|
|
|
createjs.DisplayObject.suppressCrossDomainErrors = true;
|
|
createjs.DisplayObject.suppressCrossDomainErrors = true;
|
|
@@ -59,6 +60,15 @@ Controller.prototype.add_collectible = function(collectible, position){
|
|
|
this.add_view(new ParticleView(collectible));
|
|
this.add_view(new ParticleView(collectible));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+Controller.prototype.add_physicist = function(){
|
|
|
|
|
+ //var new_physicist = Object.create(this.snake.physicists[this.snake.physicists.length - 1]);
|
|
|
|
|
+ var new_physicist = new Physicist(this, {x: 0, y: 0});//Object.create(physicist.physicist);
|
|
|
|
|
+ new_physicist.position = this.snake.physicists[this.snake.physicists.length - 1].position;
|
|
|
|
|
+ new_physicist.direction = this.snake.physicists[this.snake.physicists.length - 1].direction;
|
|
|
|
|
+ this.snake.physicists.push(new_physicist);
|
|
|
|
|
+ this.add_view(new PhysicistView(new_physicist));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Controller.prototype.start_game = function(){
|
|
Controller.prototype.start_game = function(){
|
|
|
// this.session = new Session();
|
|
// this.session = new Session();
|
|
|
var c = this;
|
|
var c = this;
|
|
@@ -144,6 +154,7 @@ Controller.prototype.tick = function(event){
|
|
|
var next_cell_content = this.is_position_occupied(next_cell);
|
|
var next_cell_content = this.is_position_occupied(next_cell);
|
|
|
this.snake.move(next_cell);
|
|
this.snake.move(next_cell);
|
|
|
this.canTurn = true;
|
|
this.canTurn = true;
|
|
|
|
|
+ this.physicists_count();
|
|
|
if (next_cell_content && next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
|
|
if (next_cell_content && next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
|
|
|
if(this.collectibles.length < this.maximum_spawns){
|
|
if(this.collectibles.length < this.maximum_spawns){
|
|
|
this.spawn_collectibles();
|
|
this.spawn_collectibles();
|
|
@@ -251,3 +262,11 @@ var get_random_element_with_probabilities = function(array){
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+Controller.prototype.physicists_count = function(){
|
|
|
|
|
+ if(this.counter >= 3) {
|
|
|
|
|
+ this.add_physicist();
|
|
|
|
|
+ this.counter = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|