Skip to content

Commit aa959eb

Browse files
committed
Update game to full browser and collision handling
1 parent 6d13d52 commit aa959eb

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

2dPlatformer-TypeScript/src/Game.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
init() {
1111
console.log((new Date).toISOString() + ' : Entered Game init()');
1212
// 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;
1414

1515
// 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';
1717

1818
// 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;
2121

2222
// Disable multitouch. It's recommended by the creators to set this unless your game needs multitouch.
2323
this.input.maxPointers = 1;
@@ -33,7 +33,6 @@
3333

3434
// Load the actual assets. By default the path will be set to the assets directory.
3535
this.load.path = 'assets/';
36-
//this.load.image('Phaser-Logo-Small');
3736
this.load.image('player', 'box.png');
3837
this.load.image('wall', 'box.png');
3938
this.load.image('coin', 'box.png');
@@ -93,22 +92,12 @@
9392
}
9493
}
9594
}
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' });
10095
}
10196

10297
update() {
10398
// Make the player and the walls collide
10499
this.game.physics.arcade.collide(this.player, this.walls);
105100

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-
112101
if (this.cursor.left.isDown) {
113102
this.player.body.velocity.x = -200;
114103
} else if (this.cursor.right.isDown) {
@@ -117,9 +106,13 @@
117106
this.player.body.velocity.x = 0;
118107
}
119108

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) {
121110
this.player.body.velocity.y = -250;
122111
}
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);
123116
}
124117

125118
takeCoin(player: any, coin: any) {

0 commit comments

Comments
 (0)