Bläddra i källkod

decay working

Dima Mironov 10 år sedan
förälder
incheckning
a6dda0256b
3 ändrade filer med 24 tillägg och 11 borttagningar
  1. 16 4
      js/controller.js
  2. 6 6
      js/models/particles.json.js
  3. 2 1
      js/views/particle.js

+ 16 - 4
js/controller.js

@@ -43,8 +43,8 @@ Controller.prototype.spawn_collectibles = function(){
 }
 
 Controller.prototype.add_collectible = function(collectible){
-    if(collectible.halflife_time > 0){
-        collectible.decay_time = createjs.Ticker.getTime() + collectible.halflife_time;
+    if(collectible.half_life > 0){
+        collectible.decay_time = createjs.Ticker.getTime() + collectible.half_life;
     }
     this.collectibles.push(collectible);
     this.add_view(new ParticleView(collectible));
@@ -174,7 +174,7 @@ Controller.prototype.check_decays = function(){
                     offset.x++;
                     offset.y++;
                 }
-                var daughter = new Particle(p.position);
+                var daughter = this.get_particle_by_type("electron", p.position);
                 daughter.start_time = createjs.Ticker.getTime();
                 daughter.target = {
                     time: daughter.start_time + 500,
@@ -190,6 +190,18 @@ Controller.prototype.check_decays = function(){
     }
 }
 
+Controller.prototype.get_particle_by_type = function(ptype, position){
+	for (var pIndex in this.possible_collectibles){
+		var cc = this.possible_collectibles[pIndex];
+		if (cc.collectible.type == ptype){
+			cc = Object.create(cc.collectible);
+			var pos = Object.create(position);
+			cc.position = pos;
+			return cc;
+		}
+	}
+}
+
 Controller.prototype.get_next_cell_position = function(){
 	var ph0 = this.snake.physicists[0];
 	var next_cell = Object.create(ph0.position);
@@ -225,7 +237,7 @@ Controller.prototype.hit_test = function(particle){
 	for (var ph_i in this.snake.physicists){
 		var ph = this.snake.physicists[ph_i];
 		if (ph.view.hitTest(particle.position.x, particle.position.y)) {
-			this.ph.collect(particle);
+			ph.collect(particle);
 		}
 	}
 }

+ 6 - 6
js/models/particles.json.js

@@ -5,13 +5,13 @@ window.possible_particles = function(){ return [
 		charge: 0,
 		points: 125,
 		appearence_probabilty: .03,
-		half_life: 5,
+		half_life: 500,
 		decays: [{particles: ["W", "W"], probability: 1.}],
 		draw_properties: {
-			colors: ["hsl(0, 100%, 50%)", "hsl(0, 40%, 50%)"],
+			colors: ["hsl(120, 100%, 50%)", "hsl(120, 40%, 50%)"],
 			ratios: [0, 1],
 			inner_radius: .03,
-			outer_radius: .13,
+			outer_radius: .23,
 			inner_center: {x: .07, y: .07},
 			outer_center: {x: 0, y: 0}
 		},
@@ -32,10 +32,10 @@ window.possible_particles = function(){ return [
 		points: 1,
 		appearence_probabilty: .03,
 		draw_properties: {
-			colors: ["hsl(120, 100%, 50%)", "hsl(120, 40%, 50%)"],
+			colors: ["hsl(0, 100%, 50%)", "hsl(0, 40%, 50%)"],
 			ratios: [0, 1],
-			inner_radius: .02,
-			outer_radius: .04,
+			inner_radius: .04,
+			outer_radius: .17,
 			inner_center: {x: .01, y: .01},
 			outer_center: {x: 0, y: 0}
 		},

+ 2 - 1
js/views/particle.js

@@ -40,9 +40,10 @@
                 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);
-	        })
+	        })*/
 			;
         }