forked from mileung/PhaserDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state5.js
42 lines (36 loc) · 1.24 KB
/
state5.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
var accel = 400, platform, platformGroup;
demo.state5 = function(){};
demo.state5.prototype = {
preload: function(){
game.load.image('platform', 'assets/sprites/platform.png');
},
create: function(){
game.stage.backgroundColor = '#ff99dd';
addChangeStateEventListeners();
adam = game.add.sprite(centerX, 500, 'adam');
platform = game.add.sprite(0, 800, 'platform');
platformGroup = game.add.group();
platformGroup.create(650, 400, 'platform');
platformGroup.create(1300, 400, 'platform');
game.physics.enable([adam, platform, platformGroup]);
adam.body.gravity.y = 500;
adam.body.bounce.y = 0.3;
adam.body.drag.x = 400;
adam.body.collideWorldBounds = true;
platform.body.immovable = true;
platformGroup.setAll('body.immovable', true);
},
update: function(){
game.physics.arcade.collide(adam, [platform, platformGroup]);
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
adam.body.acceleration.x = -accel;
} else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
adam.body.acceleration.x = accel;
} else {
adam.body.acceleration.x = 0;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
adam.body.velocity.y = -300;
}
}
};