|
@@ -9,12 +9,15 @@ var Controller = function(){
|
|
|
this.canTurn = true;
|
|
this.canTurn = true;
|
|
|
var pos0 = {x: -1, y: -1};
|
|
var pos0 = {x: -1, y: -1};
|
|
|
|
|
|
|
|
|
|
+ createjs.DisplayObject.suppressCrossDomainErrors = true;
|
|
|
|
|
+
|
|
|
var higgs = new Particle(pos0);
|
|
var higgs = new Particle(pos0);
|
|
|
higgs.mass = 125;
|
|
higgs.mass = 125;
|
|
|
higgs.type = "Higgs"
|
|
higgs.type = "Higgs"
|
|
|
var electron = new Particle(pos0);
|
|
var electron = new Particle(pos0);
|
|
|
electron.mass = .0005;
|
|
electron.mass = .0005;
|
|
|
electron.type = "electron";
|
|
electron.type = "electron";
|
|
|
|
|
+ electron.decays = null;
|
|
|
higgs.draw_properties = {
|
|
higgs.draw_properties = {
|
|
|
colors: ["hsl(120, 100%, 50%)", "hsl(120, 40%, 50%)"],
|
|
colors: ["hsl(120, 100%, 50%)", "hsl(120, 40%, 50%)"],
|
|
|
ratios: [0, 1],
|
|
ratios: [0, 1],
|
|
@@ -42,11 +45,18 @@ Controller.prototype.spawn_collectibles = function(){
|
|
|
if (!collectible) return;
|
|
if (!collectible) return;
|
|
|
collectible = Object.create(collectible.collectible);
|
|
collectible = Object.create(collectible.collectible);
|
|
|
var rnd_pos = this.get_random_position();
|
|
var rnd_pos = this.get_random_position();
|
|
|
- if (! this.is_position_occupied(rnd_pos)) {
|
|
|
|
|
- collectible.position = rnd_pos;
|
|
|
|
|
- this.collectibles.push(collectible);
|
|
|
|
|
- this.add_view(new ParticleView(collectible));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!this.is_position_occupied(rnd_pos)) {
|
|
|
|
|
+ this.add_collectible(collectible, rnd_pos);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Controller.prototype.add_collectible = function(collectible, position){
|
|
|
|
|
+ collectible.position = position;
|
|
|
|
|
+ if(collectible.halflife_time > 0){
|
|
|
|
|
+ collectible.decay_time = createjs.Ticker.getTime() + collectible.halflife_time;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.collectibles.push(collectible);
|
|
|
|
|
+ this.add_view(new ParticleView(collectible));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Controller.prototype.start_game = function(){
|
|
Controller.prototype.start_game = function(){
|
|
@@ -140,9 +150,44 @@ Controller.prototype.tick = function(event){
|
|
|
}
|
|
}
|
|
|
this.update_views();
|
|
this.update_views();
|
|
|
}
|
|
}
|
|
|
|
|
+ this.check_decays();
|
|
|
this.stage.update(event);
|
|
this.stage.update(event);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+Controller.prototype.check_decays = function(){
|
|
|
|
|
+ for(var pIndex in this.collectibles){
|
|
|
|
|
+ var p = this.collectibles[pIndex];
|
|
|
|
|
+ if(p.decay_time && p.decays && p.decays.length && createjs.Ticker.getTime() > p.decay_time){
|
|
|
|
|
+ var offset = {x: 0, y: 0};
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ while(this.is_position_occupied(offset)){
|
|
|
|
|
+ offset.x++;
|
|
|
|
|
+ offset.y++;
|
|
|
|
|
+ }
|
|
|
|
|
+ var daughter = new Particle(p.position);
|
|
|
|
|
+ daughter.start_time = createjs.Ticker.getTime();
|
|
|
|
|
+ daughter.target = {
|
|
|
|
|
+ time: daughter.start_time + 500,
|
|
|
|
|
+ x: daughter.position.x + offset.x,
|
|
|
|
|
+ y: daughter.position.y + offset.y
|
|
|
|
|
+ }
|
|
|
|
|
+ daughter.decays = null;
|
|
|
|
|
+ this.add_collectible(daughter, p.position);
|
|
|
|
|
+ counter++;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.remove_collectible(p);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Controller.prototype.get_next_cell_position = function(){
|
|
Controller.prototype.get_next_cell_position = function(){
|
|
|
var ph0 = this.snake.physicists[0];
|
|
var ph0 = this.snake.physicists[0];
|
|
|
var next_cell = Object.create(ph0.position);
|
|
var next_cell = Object.create(ph0.position);
|
|
@@ -174,10 +219,10 @@ Controller.prototype.is_position_occupied = function(position){
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Controller.prototype.hit_test = function(e, particle){
|
|
|
|
|
|
|
+Controller.prototype.hit_test = function(particle){
|
|
|
for (var ph_i in this.snake.physicists){
|
|
for (var ph_i in this.snake.physicists){
|
|
|
var ph = this.snake.physicists[ph_i];
|
|
var ph = this.snake.physicists[ph_i];
|
|
|
- if (ph.view.hitTest(e.x, e.y)) {
|
|
|
|
|
|
|
+ if (ph.view.hitTest(particle.position.x, particle.position.y)) {
|
|
|
this.ph.collect(particle);
|
|
this.ph.collect(particle);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|