Kevin Heinicke 10 anni fa
parent
commit
2beaf9158a
2 ha cambiato i file con 14 aggiunte e 13 eliminazioni
  1. 8 8
      js/controller.js
  2. 6 5
      js/views/particle.js

+ 8 - 8
js/controller.js

@@ -2,7 +2,7 @@ var Controller = function(){
 	this.grid_size = {x: 20, y: 20};
 	this.initial_length = 3;
 	this.time_step = 400;
-    this.maximum_spawns = 100;
+    this.maximum_spawns = 2;
 	this.collectibles = [];
 	this.views = [];
 	this.snake = new Snake(this.initial_length);
@@ -47,12 +47,12 @@ Controller.prototype.spawn_collectibles = function(){
 	collectible = Object.create(collectible.collectible);
 	var rnd_pos = this.get_random_position();
 	if (!this.is_position_occupied(rnd_pos)) {
-        this.add_collectible(collectible, rnd_pos);
+        collectible.position = rnd_pos;
+        this.add_collectible(collectible);
     }
 }
 
-Controller.prototype.add_collectible = function(collectible, position){
-    collectible.position = position;
+Controller.prototype.add_collectible = function(collectible){
     if(collectible.halflife_time > 0){
         collectible.decay_time = createjs.Ticker.getTime() + collectible.halflife_time;
     }
@@ -174,11 +174,11 @@ Controller.prototype.check_decays = function(){
             var counter = 0;
             for(var daughterInd in p.decays[0]){
                 if(counter % 2){
-                    offset.x = Math.floor((Math.random() * this.grid_size.x / 10)) % this.grid_size.x;
-                    offset.y = Math.floor((Math.random() * this.grid_size.y / 10)) % this.grid_size.y;
-                } else {
                     offset.x = - offset.x;
                     offset.y = - offset.y;
+                } else {
+                    offset.x = Math.floor((Math.random() * this.grid_size.x / 10)) % this.grid_size.x;
+                    offset.y = Math.floor((Math.random() * this.grid_size.y / 10)) % this.grid_size.y;
                 }
                 while(this.is_position_occupied(offset)){
                     offset.x++;
@@ -192,7 +192,7 @@ Controller.prototype.check_decays = function(){
                     y: daughter.position.y + offset.y
                 }
                 daughter.decays = null;
-                this.add_collectible(daughter, p.position);
+                this.add_collectible(daughter);
                 counter++;
             }
             this.remove_collectible(p);

+ 6 - 5
js/views/particle.js

@@ -35,14 +35,15 @@
                 // {guide:{ path:[0,0, 0,200,200,200, 200,0,0,0] }},
                 this.model.target.time - this.model.start_time
 				)
-			.addEventListener("change", function(){
-				controller.hit_test(own_view.model);
-	        })
-			.call(function(){
+            .call(function(){
                 own_view.update = ParticleView.prototype.update;
                 own_view.model.position.x = own_view.model.target.x;
                 own_view.model.position.y = own_view.model.target.y;
-            });
+            })
+			.addEventListener("change", function(){
+				controller.hit_test(own_view.model);
+	        })
+			;
         } else {
             createjs.Tween.get(this, {loop: true})
                 .to({ scaleX: 0.9, scaleY: 1.1 }, 200)