Skip to content

Instantly share code, notes, and snippets.

@acacha
Created April 24, 2018 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acacha/b6cb1262d673c2b8fc991404b2917972 to your computer and use it in GitHub Desktop.
Save acacha/b6cb1262d673c2b8fc991404b2917972 to your computer and use it in GitHub Desktop.
var level1 = {
preload: function() {
console.log('PRELOAD')
game.load.image('wall','assets/wall.png')
game.load.image('ground','assets/ground.png')
game.load.spritesheet('player','assets/player.png', 28, 22)
},
create: function() {
this.cursor = game.input.keyboard.createCursorKeys()
this.loadLevel()
this.player = game.add.sprite(250,50,'player')
game.physics.arcade.enable(this.player)
this.player.body.gravity.y = 600;
},
update: function() {
// console.log('update')
game.physics.arcade.collide(this.player,this.ground);
this.inputs()
},
render: function() {
// console.log('render')
},
loadLevel() {
game.add.sprite(90,200/2-50,'wall')
game.add.sprite(390,200/2-50,'wall')
this.ground = game.add.sprite(500/2-160,200/2 + 30 ,'ground')
game.physics.arcade.enable(this.ground)
// this.ground.enableBody = true
this.ground.body.immovable = true
},
inputs: function() {
if (this.cursor.left.isDown) {
this.player.body.velocity.x = -200;
} else if (this.cursor.right.isDown) {
this.player.body.velocity.x = 200;
} else {
this.player.body.velocity.x = 0;
}
}
}
var game = new Phaser.Game(500,200,Phaser.AUTO,'game')
game.state.add('level1',level1)
game.state.start('level1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment