Skip to content

Instantly share code, notes, and snippets.

@michal-lipski
Created December 6, 2016 10:59
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 michal-lipski/ae909f17b07e8a12e36488f9f6e66f68 to your computer and use it in GitHub Desktop.
Save michal-lipski/ae909f17b07e8a12e36488f9f6e66f68 to your computer and use it in GitHub Desktop.
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game',
{preload: preload, create: create, update: update, render: render}
);
function preload() {
game.load.spritesheet('dude', '../assets/dude.png', 32, 48);
game.load.spritesheet('chick', '../assets/chick.png', 16, 18);
game.load.image('background', '../assets/background2.png');
game.load.image('atari','../assets/atari800xl.png')
}
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.arcade.gravity.y = 100;
var bg = game.add.tileSprite(0, 0, 800, 600, 'background');
this.dude = game.add.sprite(0, 0, 'dude');
game.physics.enable( this.dude, Phaser.Physics.ARCADE);
this.dude.body.collideWorldBounds = true;
this.dude.animations.add('left', [0, 1, 2, 3], 10, true);
this.dude.animations.play('left');
this.chick = game.add.sprite( game.world.centerX,0, 'chick');
game.physics.enable( this.chick, Phaser.Physics.ARCADE);
this.chick.body.collideWorldBounds = true;
this.chick.body.bounce.setTo(1, 1);
this.chick.scale.setTo(2, 2);
this.cursors = game.input.keyboard.createCursorKeys();
}
function update() {
game.physics.arcade.overlap(this.chick, this.dude, collision, null, this);
function collision(chick,dude){
chick.kill();
}
if (this.cursors.left.isDown) {
this.dude.animations.play('left');
this.dude.body.velocity.x = -100;
}else if (this.cursors.right.isDown) {
this.dude.animations.play('right');
this.dude.body.velocity.x = 100;
}else{
this.dude.animations.stop();
this.dude.body.velocity.x = 0;
}
}
function render() {
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment