Fix Arcade Physics player controls
This commit is contained in:
parent
f4d627e6e7
commit
7f401b3e94
@ -42,7 +42,7 @@ class GameScene extends Phaser.Scene {
|
|||||||
this.drawWorld();
|
this.drawWorld();
|
||||||
this.createTextures();
|
this.createTextures();
|
||||||
|
|
||||||
this.player = this.physics.add.image(1200, 1550, 'player-ship');
|
this.player = this.physics.add.sprite(1200, 1550, 'player-ship');
|
||||||
this.player.setDepth(6).setCollideWorldBounds(true);
|
this.player.setDepth(6).setCollideWorldBounds(true);
|
||||||
this.player.body.setAllowGravity(false);
|
this.player.body.setAllowGravity(false);
|
||||||
this.player.body.setSize(42, 56, true);
|
this.player.body.setSize(42, 56, true);
|
||||||
@ -81,7 +81,7 @@ class GameScene extends Phaser.Scene {
|
|||||||
this.hud = this.add.text(18, 42, '', {
|
this.hud = this.add.text(18, 42, '', {
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
color: '#e8f2ff',
|
color: '#e8f2f7',
|
||||||
backgroundColor: '#071018cc',
|
backgroundColor: '#071018cc',
|
||||||
padding: { x: 12, y: 10 },
|
padding: { x: 12, y: 10 },
|
||||||
lineSpacing: 4,
|
lineSpacing: 4,
|
||||||
@ -195,6 +195,8 @@ class GameScene extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updatePlayer(dt, deltaMs) {
|
updatePlayer(dt, deltaMs) {
|
||||||
|
if (!this.player?.body) return;
|
||||||
|
|
||||||
if (this.cursors.up.isDown) this.playerSpeed += PLAYER_ACCELERATION * dt;
|
if (this.cursors.up.isDown) this.playerSpeed += PLAYER_ACCELERATION * dt;
|
||||||
if (this.cursors.down.isDown) this.playerSpeed -= PLAYER_BRAKE * dt;
|
if (this.cursors.down.isDown) this.playerSpeed -= PLAYER_BRAKE * dt;
|
||||||
if (this.keys.stop.isDown) this.playerSpeed *= Math.pow(0.025, dt);
|
if (this.keys.stop.isDown) this.playerSpeed *= Math.pow(0.025, dt);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user