Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*////////////////////////////////////////////////////////////////////////////////
- // CLASS
- ////////////////////////////////////////////////////////////////////////////////*/
- var Movement = CoreClass.extend({
- scene_name: null,
- timer: [],
- stage: null,
- setup: null,
- groj: null,
- scene_ended:function(_to, directions, setup){
- console.log();
- var _this = this;
- window.location.hash = _to;
- this.scene_name = _to;
- this.stage = setup.stage;
- this.assets = setup.assets;
- this.groj = setup.groj;
- this.directions = directions;
- var run_scene = false;
- // zoom.reset();
- //
- this.stage.update();
- if(Object.keys(this.directions).length == 1){
- run_scene = true;
- speed = Global.groj.screens[_to]["speed"];
- }
- else{ speed = 30 }
- console.log('* moving to scene '+_to);
- this.timer["move"] = self.setInterval(function(){_this.move(_to, run_scene, 0)}, speed);
- },
- move:function(_to, run_scene, num){
- var directions = Object.keys(this.directions);
- var direction = directions[num];
- var x = this.directions[direction]["x"];
- var max_x = Global.groj[x];
- var y = this.directions[direction]["y"];
- var max_y = Global.groj[y];
- var speed = Global.groj.screens[_to].speed;
- this.stage.update();
- var bg = this.stage.children[0];
- if(direction == "up" && bg.y < -max_y){
- if(bg.y < -max_y){
- bg.y += speed;
- }
- }
- else if(direction == "down" && bg.y > -max_y){
- if(bg.y > -max_y){
- bg.y -= speed;
- }
- }
- else if(direction == "left" && bg.x < -max_x){
- if(bg.x < -max_x){
- bg.x += speed;
- }
- }
- else if(direction == "right" && bg.x > -max_x){
- if(bg.x > -max_x){
- bg.x -= speed;
- }
- }
- else{
- this.complete(direction, _to, run_scene, num);
- }
- },
- complete:function(direction, _to, run_scene, num){
- var _this = this;
- this.timer["move"] = window.clearInterval(this.timer["move"]);
- num++;
- if(run_scene == false){
- var speed = Global.groj.screens[_to]["speed"];
- if(num == Object.keys(this.directions).length-1){
- run_scene = true;
- }
- this.timer["move"] = self.setInterval(function(){_this.move(screen_name,run_scene,num)},speed);
- }
- else{
- var setup = {
- 'stage':this.stage,
- 'groj':this.groj,
- 'assets':this.assets
- }
- var scene_switch = new SceneSwitch();
- scene_switch.switch_scene(setup, _to)
- }
- }
- });
Add Comment
Please, Sign In to add comment