diff --git a/game.js b/game.js index b3bf7a6b744a408f4bff3f074f38e68cb83d5cc0..37f7069d9b746fb1fc3dde3d46c5f7dd258d8d77 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 b5d84e3a140dca14e8a4c121dcf7d5d6c33a0dfa..ffcf96f859c3a0bc0367bbcdd2e6836d814dc191 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