click and it changes the alien

This commit is contained in:
Tyrel Souza 2016-04-07 00:19:29 -04:00
parent 5945139e48
commit 7b3000256e
5 changed files with 56 additions and 10 deletions

BIN
assets/bg/castle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
assets/bg/desert.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
assets/bg/forest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
assets/bg/talltrees.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,22 +1,68 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, '');
var game = new Phaser.Game(800, 500, Phaser.AUTO, '');
var alienData;
game.state.add('play', {
preload: function(){
game.load.image('pink', 'assets/pink.png');
game.load.image('green', 'assets/green.png');
game.load.image('grey', 'assets/grey.png');
game.load.image('blue', 'assets/blue.png');
console.log("preload");
game.load.image('alien:pink', 'assets/pink.png');
game.load.image('alien:green', 'assets/green.png');
game.load.image('alien:grey', 'assets/grey.png');
game.load.image('alien:blue', 'assets/blue.png');
game.load.image('bg:castle', 'assets/bg/castle.png');
game.load.image('bg:desert', 'assets/bg/desert.png');
game.load.image('bg:forest', 'assets/bg/forest.png');
game.load.image('bg:talltrees', 'assets/bg/talltrees.png');
alienData = [
{name: 'Pink', image: 'alien:pink'},
{name: 'Green', image: 'alien:green'},
{name: 'Grey', image: 'alien:grey'},
{name: 'Blue', image: 'alien:blue'}
];
},
create: function(){
var alienSprite = game.add.sprite(450, 290, 'pink');
console.log(alienSprite);
alienSprite.anchor.setTo(0.5, 0.5);
var state = this;
this.background = this.game.add.group();
var bg = state.game.add.tileSprite(0, 0, state.game.world.width,
state.game.world.height, 'bg:castle', '', state.background);
bg.tileScale.setTo(0.5, 0.5);
this.aliens = this.game.add.group();
var alien;
alienData.forEach(function(data){
alien = state.aliens.create(1000, state.game.world.centerY, data.image);
alien.anchor.setTo(0.5);
alien.details = data;
alien.inputEnabled = true;
alien.events.onInputDown.add(state.onClickAlien, state);
});
this.currentAlien = this.aliens.getRandom();
this.currentAlien.position.set(this.game.world.centerX + 100, this.game.world.centerY);
},
render: function(){
game.debug.text('Adventure Awaits!', 250, 40);
game.debug.text(
this.currentAlien.details.name,
this.game.world.centerX - this.currentAlien.width / 2,
this.game.world.centerY - this.currentAlien.height / 2);
},
onClickAlien: function(){
this.currentAlien.position.set(1000, this.game.world.centerY);
this.currentAlien = this.aliens.getRandom();
this.currentAlien.position.set(this.game.world.centerX + 100, this.game.world.centerY);
}
});
game.state.start('play');