-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
77 lines (62 loc) · 1.87 KB
/
game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var game = new Phaser.Game(600, 320, Phaser.AUTO);
var GameState = {
preload: function() {
this.load.image('background', 'assets/images/house-bg.jpg');
this.load.image('coin', 'assets/images/coin.png');
this.load.image('person', 'assets/images/property-agent.png');
},
create: function() {
this.setResponsive();
// The game background
this.background = this.game.add.sprite(0, 0, 'background');
// Coins!
this.coin = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'coin');
this.coin.anchor.setTo(0.5, 0.5);
this.coin.scale.setTo(2);
// Agent
this.person = this.game.add.sprite(120, 10, 'person');
this.person.scale.setTo(0.6);
this.cursors = this.game.input.keyboard.createCursorKeys();
},
update: function() {
// This allows us to move the game camera using the keyboard
if (this.cursors.left.isDown) {
this.person.anchor.setTo(0.8, 0.4);
this.person.scale.setTo(0.2);
} else {
this.resetPerson();
}
if (this.cursors.right.isDown) {
this.person.scale.setTo(0.5);
this.person.anchor.x = -1;
} else {
this.resetPerson();
}
if (this.cursors.up.isDown) {
this.person.scale.setTo(0.6);
} else {
this.resetPerson();
}
if (this.cursors.down.isDown) {
this.coin.scale.x = -1;
this.person.scale.setTo(0.5);
} else {
this.resetPerson();
this.resetCoin();
}
},
resetPerson: function() {
this.person.scale.setTo(0.6);
this.person.anchor.setTo(0);
},
resetCoin: function() {
this.coin.scale.x = 1;
},
setResponsive: function() {
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
},
};
game.state.add('GameState', GameState);
game.state.start('GameState');