Przeglądaj źródła

finally eating :yeah:

Dima Mironov 10 lat temu
rodzic
commit
6f3b013a9a
2 zmienionych plików z 6 dodań i 5 usunięć
  1. 4 3
      js/controller.js
  2. 2 2
      js/script.js

+ 4 - 3
js/controller.js

@@ -96,7 +96,7 @@ Controller.prototype.tick = function(event){
         var next_cell = this.get_next_cell_position();
 		var next_cell_content = this.is_position_occupied(next_cell);
 		this.snake.move(next_cell);
-		if (next_cell_content) this.snake.physicists[0].collect(next_cell_content);
+		if (next_cell_content && next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
 		this.spawn_collectibles();
         this.update_views();
 	}
@@ -125,11 +125,11 @@ Controller.prototype.is_position_occupied = function(position){
 	var phs = this.snake.physicists;
 	for (var ph in phs){
 		var pos = phs[ph].position;
-		if (pos.x == position.x && pos.y == position.y) return phs[ph];
+		if (pos.x == position.x && pos.y == position.y) return {physicist:phs[ph]};
 	}
 	for (var c in this.collectibles){
 		var pos = this.collectibles[c].position;
-		if (pos.x == position.x && pos.y == position.y) return this.collectibles[c];
+		if (pos.x == position.x && pos.y == position.y) return {collectible:this.collectibles[c]};
 	}
 	return null;
 }
@@ -153,6 +153,7 @@ Controller.prototype.remove_collectible = function(collectible){
 	if (i > -1) {
 	    this.views.splice(i, 1);
 	}
+	this.stage.removeChild(collectible.view);
 
 }
 

+ 2 - 2
js/script.js

@@ -7,7 +7,7 @@ function init() {
 
     controller.start_game();
 
-    var p2 = new Particle({x: 3, y: 3});
+    /*var p2 = new Particle({x: 3, y: 3});
     p2.start_time = createjs.Ticker.getTime();
     p2.target = {
         time: p2.start_time + 1000,
@@ -15,7 +15,7 @@ function init() {
         y: 7
     }
     var p2v = new ParticleView(p2);
-    controller.add_view(p2v);
+    controller.add_view(p2v);*/
 }
 
 function resize() {