Ver Fonte

add physicist

every 3 particles collected
eraisedtoipi há 10 anos atrás
pai
commit
4bd8b1a46e
2 ficheiros alterados com 20 adições e 0 exclusões
  1. 19 0
      js/controller.js
  2. 1 0
      js/models/physicist.js

+ 19 - 0
js/controller.js

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

+ 1 - 0
js/models/physicist.js

@@ -10,4 +10,5 @@ Physicist.prototype.collect = function(collectible) {
 	this.bonus += " fat!";
 	controller.score += collectible.points;
 	controller.remove_collectible(collectible);
+	controller.counter += 1;
 };