From 73e7a76e3dcdac90cc29d2f69aeafeaebdaa4dab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Ho=CC=88lscher?= <git@hoelshare.de>
Date: Sun, 17 Sep 2017 15:51:58 +0200
Subject: [PATCH] Changed to state version

---
 game.js | 47 ++++++++++++++++++++++++-----------------------
 main.js | 13 +++++++------
 2 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/game.js b/game.js
index b3bf7a6..37f7069 100644
--- a/game.js
+++ b/game.js
@@ -4,8 +4,8 @@ var Game = {
 };
 
 Game.preload = function() {
-    Game.loadImages();
-    Game.loadSpritesheets();
+    this.loadImages();
+    this.loadSpritesheets();
 };
 
 Game.loadImages = function() {
@@ -18,41 +18,42 @@ Game.loadSpritesheets = function() {
 }
 
 Game.create = function() {
-    Game.createPhysics();
-    Game.createPlayer();
-    Game.createWorld();
-    Game.applyPhysicsToPlayer();
-    Game.createPickups();
+    this.createPhysics();
+    this.createPlayer();
+    this.createWorld();
+    this.applyPhysicsToPlayer();
+    this.createPickups();
 }
 
 Game.createPhysics = function() {
     game.physics.startSystem(game.physics.ARCADE);
+    this.stage.disableVisibilityChange = true;
 };
 
 Game.createPlayer = function() {
-    Game.player = game.add.sprite(game.world.width / 2, 10, 'boris');
-    game.camera.follow(Game.player);
+    this.player = game.add.sprite(game.world.width / 2, 10, 'boris');
+    game.camera.follow(this.player);
 };
 
 Game.createWorld = function() {
     game.world.resize(game.world.width, 10000);
-    game.stage.backgroundColor = 0x0000F0;
+    this.stage.backgroundColor = 0x0000F0;
 };
 
 Game.applyPhysicsToPlayer = function() {
-    game.physics.arcade.enable(Game.player);
-    Game.player.body.gravity.y = 100;
-    Game.player.body.collideWorldBounds = true;
+    game.physics.arcade.enable(this.player);
+    this.player.body.gravity.y = 100;
+    this.player.body.collideWorldBounds = true;
 };
 
 Game.createPickups = function() {
-    Game.pickups = game.add.group();
-    Game.pickups.enableBody = true;
+    this.pickups = game.add.group();
+    this.pickups.enableBody = true;
 
     var numPickups = game.world.height / (game.camera.height / 2);
     console.log(numPickups-1 + ' pickups will be created');
     for (var i = 1; i < numPickups; i++) {
-        Game.createPickup(i);        
+        this.createPickup(i);
     }
 }
 
@@ -64,31 +65,31 @@ Game.createPickup = function(i) {
     if(isStalin) {
         spriteName = 'stalin';
     }
-    var pickup = Game.pickups.create(xCoordinate, yCoordinate, spriteName);
+    var pickup = this.pickups.create(xCoordinate, yCoordinate, spriteName);
     pickup.body.immovable = true;
     pickup.body.isStalin = isStalin;
     console.log('X: ' + xCoordinate + ';Y: ' + yCoordinate + ';isStalin: ' + (isStalin == true));
 }
 
 Game.update = function() {
-    game.physics.arcade.overlap(Game.player, Game.pickups, Game.pickupItem, null, this);
-    Game.updateXLocation();
+    game.physics.arcade.overlap(this.player, this.pickups, this.pickupItem, null, this);
+    this.updateXLocation();
 }
 
 Game.updateXLocation = function() {
     var velocity = 0;
     if (game.input.mousePointer.isDown) {
-        var xPos = Game.player.body.position.x;
+        var xPos = this.player.body.position.x;
         var xInp = game.input.x;
         velocity = (xInp - xPos) * 10;
     } 
-    Game.player.body.velocity.x = velocity;
+    this.player.body.velocity.x = velocity;
 }
 
 Game.pickupItem = function(player, pickup) {
     var factor = pickup.body.isStalin ? 30 : -30;
-    Game.player.body.gravity.y += factor;
-    Game.player.body.gravity.y = Math.max(Game.player.body.gravity.y, 10);
+    this.player.body.gravity.y += factor;
+    this.player.body.gravity.y = Math.max(this.player.body.gravity.y, 10);
     console.log(pickup.body.isStalin == true);
     pickup.kill();
 }
\ No newline at end of file
diff --git a/main.js b/main.js
index b5d84e3..ffcf96f 100644
--- a/main.js
+++ b/main.js
@@ -3,9 +3,10 @@ var game = new Phaser.Game(
     800, 
     Phaser.CANVAS, 
     'game-div', 
-    { 
-        preload: Game.preload, 
-        create: Game.create, 
-        update: Game.update, 
-        render: Game.render
-    });
+    Game,
+    false,
+    true);
+
+//game.state.add('Game', Game);
+
+//game.state.start('Game');
\ No newline at end of file
-- 
GitLab