snake.js 852 B

123456789101112131415161718192021222324252627282930
  1. var Snake = function(n_physicisits){
  2. this.physicists = [];
  3. for (var i = 0; i < n_physicisits; i++){
  4. this.physicists.push(new Physicist(this, {x: 0, y: 0}));
  5. }
  6. this.physicists[0].direction = {x: 0, y: 0};
  7. this.new_physicists = [];
  8. this.bonuses = [];
  9. this.speed = 1;
  10. }
  11. Snake.prototype.add_physicist = function(physicist){
  12. this.new_physicists.push_back(new Physicist(this, this.physicists[this.physicists.length - 1].position));
  13. }
  14. Snake.prototype.add_bonus = function(bonus){
  15. this.bonuses.push_back(bonus);
  16. }
  17. Snake.prototype.remove_physicist = function(index){
  18. }
  19. Snake.prototype.move = function(next_cell){
  20. for(var i = this.physicists.length - 1; i > 0; i--){
  21. this.physicists[i].position = this.physicists[i-1].position;
  22. this.physicists[i].direction = this.physicists[i-1].direction;
  23. }
  24. this.physicists[0].position = next_cell;
  25. }