FINALLY you can shoot asteroid!.. and dead.
This commit is contained in:
parent
2db1cda5bb
commit
65b99a20d8
3 changed files with 49 additions and 6 deletions
|
|
@ -1,8 +1,11 @@
|
|||
import Phaser from 'phaser'
|
||||
import Bullet from '../classes/Bullet'
|
||||
|
||||
export default class Asteroid extends Phaser.Physics.Arcade.Sprite {
|
||||
static unbornAge = 1000 // asteroid can't kill player
|
||||
// if younger than 1000ms
|
||||
// asteroid can't kill player
|
||||
// if younger than unbornAge in ms
|
||||
static unbornAge = 1000
|
||||
|
||||
readonly wrapMargin = 30
|
||||
|
||||
age = 0
|
||||
|
|
@ -30,11 +33,20 @@ export default class Asteroid extends Phaser.Physics.Arcade.Sprite {
|
|||
|
||||
preUpdate(time: number, delta: number) {
|
||||
super.preUpdate(time, delta)
|
||||
|
||||
|
||||
this.scene.physics.world.wrap(this, this.scale * this.wrapMargin)
|
||||
this.age += delta
|
||||
}
|
||||
|
||||
gotHit(me, bullet) {
|
||||
if (!(bullet instanceof Bullet)) return
|
||||
if (bullet.active == false) return
|
||||
|
||||
me.destroy() // TODO: use objects pool
|
||||
bullet.setActive(false)
|
||||
bullet.setVisible(false)
|
||||
}
|
||||
|
||||
private setRandomShade() {
|
||||
const color = new Phaser.Display.Color()
|
||||
color.randomGray(0xa0) //the darkest possible dye is 0xa0a0a0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import Phaser from 'phaser'
|
||||
import Bullets from './Bullets'
|
||||
import Thruster from './Thruster'
|
||||
import Asteroid from './Asteroid'
|
||||
|
||||
export default class Ship extends Phaser.Physics.Arcade.Sprite {
|
||||
readonly acceleration = 5
|
||||
|
|
@ -66,4 +67,13 @@ export default class Ship extends Phaser.Physics.Arcade.Sprite {
|
|||
this.scene.physics.world.wrap(this, this.wrapMargin)
|
||||
this.thruster.update(time, delta)
|
||||
}
|
||||
|
||||
gotHit(_, asteroid) {
|
||||
if (!(asteroid instanceof Asteroid)) return
|
||||
|
||||
if (asteroid.age > Asteroid.unbornAge) {
|
||||
console.log("%cU ded", "color:red")
|
||||
this.scene.cameras.main.shake(100, 0.02)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue