generated from yandeu/phaser-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ceddy6 <ceddy6@users.noreply.github.com> Co-authored-by: wgilmour@hotmail.co.uk <wgilmour@hotmail.co.uk>
- Loading branch information
1 parent
a4c293b
commit 2bbd6ba
Showing
6 changed files
with
56 additions
and
19 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export default class Submarine extends Phaser.Physics.Arcade.Sprite { | ||
// Constructor for submarine | ||
constructor(scene, x, y) { | ||
// Create submarine | ||
super(scene, x, y, 'submarine') | ||
scene.add.existing(this) | ||
scene.physics.add.existing(this) | ||
|
||
// Set physics params | ||
this.body.setMass(100) | ||
this.setDamping(true) | ||
this.setDrag(0.25) | ||
this.setMaxVelocity(200) | ||
this.setCollideWorldBounds(false) | ||
} | ||
|
||
// Update loop - game physics tbc | ||
update(cursors: Phaser.Types.Input.Keyboard.CursorKeys) { | ||
// X direction - assume no key pressed | ||
let somethingDownX = false | ||
// Check for left and right keys | ||
if (cursors.left.isDown) { | ||
somethingDownX = true | ||
this.setAccelerationX(-100) | ||
this.setFlip(true, false) | ||
} else if (cursors.right.isDown) { | ||
somethingDownX = true | ||
this.setAccelerationX(100) | ||
this.setFlip(false, false) | ||
} | ||
// If still no key pressed, set horizontal acceleration to 0 | ||
if (!somethingDownX) this.setAccelerationX(0) | ||
|
||
// Y direction - assume no key pressed | ||
let somethingDownY = false | ||
// Check for up and down keys | ||
if (cursors.up.isDown) { | ||
somethingDownY = true | ||
this.setAccelerationY(-100) | ||
} else if (cursors.down.isDown) { | ||
somethingDownY = true | ||
this.setAccelerationY(100) | ||
} | ||
// If still no key pressed, set vertical acceleration to 0 | ||
if (!somethingDownY) this.setAccelerationY(0) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters