Skip to content
Snippets Groups Projects
Commit 73e7a76e authored by Sebastian Hölscher's avatar Sebastian Hölscher
Browse files

Changed to state version

parent accc703c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment