|
|
@@ -145,15 +145,14 @@ Controller.prototype.tick = function(event){
|
|
|
if(event.time - this.time > this.time_step){
|
|
|
this.time = event.time;
|
|
|
var next_cell = this.get_next_cell_position();
|
|
|
- this.snake.move(next_cell);
|
|
|
+ var next_cell_content;
|
|
|
this.canTurn = true;
|
|
|
this.physicists_count();
|
|
|
- var next_cell_content = this.is_position_occupied(next_cell);
|
|
|
- while (next_cell_content){
|
|
|
- if (next_cell_content && next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
|
|
|
- if (next_cell_content && next_cell_content.physicist && event.time > 5000) this.game_over();
|
|
|
- next_cell_content = this.is_position_occupied(next_cell);
|
|
|
+ while (next_cell_content = this.is_position_occupied(next_cell)){
|
|
|
+ if (next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
|
|
|
+ if (next_cell_content.physicist && event.time > 5000) this.game_over();
|
|
|
}
|
|
|
+ this.snake.move(next_cell);
|
|
|
if(this.collectibles.length < this.maximum_spawns){
|
|
|
this.spawn_collectibles();
|
|
|
}
|
|
|
@@ -230,15 +229,16 @@ Controller.prototype.get_random_position = function(){
|
|
|
}
|
|
|
|
|
|
Controller.prototype.is_position_occupied = function(position){
|
|
|
+
|
|
|
+ for (var c in this.collectibles){
|
|
|
+ var pos = this.collectibles[c].position;
|
|
|
+ if (pos.x == position.x && pos.y == position.y) return {collectible:this.collectibles[c]};
|
|
|
+ }
|
|
|
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 {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 {collectible:this.collectibles[c]};
|
|
|
- }
|
|
|
return null;
|
|
|
}
|
|
|
|