{"size": 2006, "ext": "js", "max_stars_repo_path": "js/level1/fly-away.js", "max_stars_repo_name": "devgr/groundhog-island", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/level1/fly-away.js", "max_issues_repo_name": "devgr/groundhog-island", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/level1/fly-away.js", "max_forks_repo_name": "devgr/groundhog-island", "max_forks_repo_forks_event_min_datetime": "2018-02-03T20:55:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-03T21:08:56.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 25.3924050633, "max_line_length": 89, "alphanum_fraction": 0.6335992024}
window.export('FlyAway', function() {
	'use strict';
	class FlyAway{
		constructor(gameObjects, game) {
			this.gameObjects = gameObjects;
			this.game = game;
			this.watchForOverlap = false;
			this.inputEnabled = false;
		}

		update() {
			let self = this;
			if(this.watchForOverlap) {
				this.game.physics.arcade.overlap(this.gameObjects.player, this.plane, function(){
					self.watchForOverlap = false;
					self.flyPlane();
				});
			}
			if(this.gameObjects.planeMode && this.inputEnabled) {
				this.processInput();
			}
		}

		enable() {
			// Spawn the float plane
			this.plane = this.game.add.sprite(2300, 860, 'waterplane');
			this.plane.anchor.setTo(0.5, 0.5);
			this.plane.scale.setTo(2, 2);
			this.game.physics.arcade.enable(this.plane);

			this.watchForOverlap = true;
		}

		flyPlane() {
			this.inputEnabled = true;
			this.gameObjects.player.visible = false;
			this.plane.body.velocity.x = 5;
			this.plane.body.velocity.y = 1;
			this.gameObjects.planeMode = true;
			this.gameObjects.player = this.plane; // hack to make the camera follow the plane

			let self = this;
			setTimeout(function(){
				self.gameObjects.dialog.visible = true;
				self.gameObjects.dialogLines = ['[You] Wait...', "I don't know how to fly a plane!"];
				setTimeout(function(){
					self.inputEnabled = false;
					self.plane.body.gravity.y = 200;
					setTimeout(function(){
						self.gameObjects.dialog.visible = false;
						self.gameObjects.dialogLines = [''];
						setTimeout(function(){
							window.location.reload();
							//self.game.state.start('Level1');
						}, 2000);
					}, 2000);
				}, 1000);
			}, 4000);
		}

		processInput() {
			let input = this.gameObjects.input;
			if(input.left.isDown) {
				this.plane.body.velocity.x -= 5;
			}
			if(input.right.isDown) {
				this.plane.body.velocity.x += 5;
			}
			if(input.up.isDown) {
				this.plane.body.velocity.y -= 5;
			}
			if(input.down.isDown) {
				this.plane.body.velocity.y += 5;
			}
		}
	}
	
	return FlyAway;
});