Guest User

Untitled

a guest
Dec 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. /*////////////////////////////////////////////////////////////////////////////////
  2. // CLASS
  3. ////////////////////////////////////////////////////////////////////////////////*/
  4.  
  5. var Movement = CoreClass.extend({
  6. scene_name: null,
  7. timer: [],
  8. stage: null,
  9. setup: null,
  10. groj: null,
  11.  
  12. scene_ended:function(_to, directions, setup){
  13. console.log();
  14. var _this = this;
  15.  
  16. window.location.hash = _to;
  17. this.scene_name = _to;
  18.  
  19. this.stage = setup.stage;
  20. this.assets = setup.assets;
  21. this.groj = setup.groj;
  22.  
  23. this.directions = directions;
  24.  
  25. var run_scene = false;
  26. // zoom.reset();
  27. //
  28. this.stage.update();
  29.  
  30. if(Object.keys(this.directions).length == 1){
  31. run_scene = true;
  32. speed = Global.groj.screens[_to]["speed"];
  33. }
  34. else{ speed = 30 }
  35.  
  36. console.log('* moving to scene '+_to);
  37.  
  38. this.timer["move"] = self.setInterval(function(){_this.move(_to, run_scene, 0)}, speed);
  39.  
  40. },
  41.  
  42. move:function(_to, run_scene, num){
  43. var directions = Object.keys(this.directions);
  44. var direction = directions[num];
  45.  
  46. var x = this.directions[direction]["x"];
  47. var max_x = Global.groj[x];
  48.  
  49. var y = this.directions[direction]["y"];
  50. var max_y = Global.groj[y];
  51.  
  52. var speed = Global.groj.screens[_to].speed;
  53.  
  54. this.stage.update();
  55.  
  56. var bg = this.stage.children[0];
  57.  
  58. if(direction == "up" && bg.y < -max_y){
  59. if(bg.y < -max_y){
  60. bg.y += speed;
  61. }
  62. }
  63. else if(direction == "down" && bg.y > -max_y){
  64. if(bg.y > -max_y){
  65. bg.y -= speed;
  66. }
  67. }
  68.  
  69. else if(direction == "left" && bg.x < -max_x){
  70. if(bg.x < -max_x){
  71. bg.x += speed;
  72. }
  73. }
  74. else if(direction == "right" && bg.x > -max_x){
  75. if(bg.x > -max_x){
  76. bg.x -= speed;
  77. }
  78.  
  79. }
  80.  
  81. else{
  82. this.complete(direction, _to, run_scene, num);
  83. }
  84.  
  85. },
  86.  
  87. complete:function(direction, _to, run_scene, num){
  88. var _this = this;
  89.  
  90. this.timer["move"] = window.clearInterval(this.timer["move"]);
  91.  
  92. num++;
  93.  
  94. if(run_scene == false){
  95. var speed = Global.groj.screens[_to]["speed"];
  96.  
  97. if(num == Object.keys(this.directions).length-1){
  98. run_scene = true;
  99. }
  100. this.timer["move"] = self.setInterval(function(){_this.move(screen_name,run_scene,num)},speed);
  101. }
  102.  
  103. else{
  104. var setup = {
  105. 'stage':this.stage,
  106. 'groj':this.groj,
  107. 'assets':this.assets
  108. }
  109.  
  110. var scene_switch = new SceneSwitch();
  111. scene_switch.switch_scene(setup, _to)
  112. }
  113. }
  114.  
  115. });
Add Comment
Please, Sign In to add comment