|
10 | 10 | init() {
|
11 | 11 | console.log((new Date).toISOString() + ' : Entered Game init()');
|
12 | 12 | // If you want to scale the game, you can set that here.
|
13 |
| - //this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; |
| 13 | + this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; |
14 | 14 |
|
15 | 15 | // If we put our game in a div, we need to add the following as well, if you SHOW_ALL.
|
16 |
| - //this.game.scale.windowConstraints.bottom = 'visual'; |
| 16 | + this.game.scale.windowConstraints.bottom = 'visual'; |
17 | 17 |
|
18 | 18 | // Uncomment to place our game in the center of the screen both horizontally and vertically.
|
19 |
| - //this.scale.pageAlignHorizontally = true; |
20 |
| - //this.scale.pageAlignVertically = true; |
| 19 | + this.scale.pageAlignHorizontally = true; |
| 20 | + this.scale.pageAlignVertically = true; |
21 | 21 |
|
22 | 22 | // Disable multitouch. It's recommended by the creators to set this unless your game needs multitouch.
|
23 | 23 | this.input.maxPointers = 1;
|
|
33 | 33 |
|
34 | 34 | // Load the actual assets. By default the path will be set to the assets directory.
|
35 | 35 | this.load.path = 'assets/';
|
36 |
| - //this.load.image('Phaser-Logo-Small'); |
37 | 36 | this.load.image('player', 'box.png');
|
38 | 37 | this.load.image('wall', 'box.png');
|
39 | 38 | this.load.image('coin', 'box.png');
|
|
93 | 92 | }
|
94 | 93 | }
|
95 | 94 | }
|
96 |
| - //this.phaserLogo = this.add.sprite(this.world.centerX, this.world.centerY, 'Phaser-Logo-Small'); |
97 |
| - //this.phaserLogo.anchor.setTo(0.5); |
98 |
| - |
99 |
| - //this.phaserLogoText = this.add.text(this.game.width / 8, this.game.height / 8, 'Powered by', { fontSize: '24px', fill: '#fff' }); |
100 | 95 | }
|
101 | 96 |
|
102 | 97 | update() {
|
103 | 98 | // Make the player and the walls collide
|
104 | 99 | this.game.physics.arcade.collide(this.player, this.walls);
|
105 | 100 |
|
106 |
| - // Call the 'takeCoin' function when the player takes a coin |
107 |
| - this.game.physics.arcade.overlap(this.player, this.coins, this.takeCoin, null, this); |
108 |
| - |
109 |
| - // Call the 'restart' function when the player touches the enemy |
110 |
| - this.game.physics.arcade.overlap(this.player, this.enemies, this.restart, null, this); |
111 |
| - |
112 | 101 | if (this.cursor.left.isDown) {
|
113 | 102 | this.player.body.velocity.x = -200;
|
114 | 103 | } else if (this.cursor.right.isDown) {
|
|
117 | 106 | this.player.body.velocity.x = 0;
|
118 | 107 | }
|
119 | 108 |
|
120 |
| - if (this.cursor.up.isDown && this.player.body.touching.down) { |
| 109 | + if (this.cursor.up.isDown && (this.player.body as Phaser.Physics.Arcade.Body).touching.down) { |
121 | 110 | this.player.body.velocity.y = -250;
|
122 | 111 | }
|
| 112 | + |
| 113 | + this.game.physics.arcade.overlap(this.player, this.coins, this.takeCoin, null, this); |
| 114 | + |
| 115 | + this.game.physics.arcade.overlap(this.player, this.enemies, this.restart, null, this); |
123 | 116 | }
|
124 | 117 |
|
125 | 118 | takeCoin(player: any, coin: any) {
|
|
0 commit comments