fork download
  1. Game.roundPos = function(pos) {
  2. new_pos = {x: Math.round(pos.x), y: Math.round(pos.y)};
  3. return new_pos;
  4. }
  5.  
  6. this.getNextPosition = function(dir, dt) {
  7. var next = {x: this.position.x, y: this.position.y};
  8. if(dir == Game.Direction.Left) {
  9. next.x = next.x - dt;
  10. next.y = Math.round(next.y);
  11. } else if(dir == Game.Direction.Right) {
  12. next.x = next.x + dt;
  13. next.y = Math.round(next.y);
  14. } if(dir == Game.Direction.Up) {
  15. next.y = next.y - dt;
  16. next.x = Math.round(next.x);
  17. } if(dir == Game.Direction.Down) {
  18. next.y = next.y + dt;
  19. next.x = Math.round(next.x);
  20. }
  21. return next;
  22. }
  23.  
  24. this.update = function(dt) {
  25. if(this.direction === null) return;
  26.  
  27. var world = this.world;
  28. var next = this.getNextPosition(this.direction, dt);
  29. var pos = Game.roundPos(next);
  30.  
  31. if(!world.isWall(pos.x, pos.y) && !world.isBase(pos.x, pos.y)) {
  32. this.position = next;
  33. } else {
  34. this.direction = null;
  35. }
  36.  
  37. // rest of the code... not important for this problem.
  38.  
  39. }
Runtime error #stdin #stdout #stderr 0.41s 381888KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "Game" is not defined.