Skip to content

Commit fe3621a

Browse files
committed
fix bullets
1 parent 7e5ec02 commit fe3621a

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/actors/bullets/column.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GAME, BULLETS, BUGS } from '../../shared/config'
22
import Bullet from './bullet'
33

44
class Column extends Phaser.Group {
5-
constructor(game, name, frame, index, remove, score) {
5+
constructor(game, name, frame, index, remove, score, bugs) {
66
super(game, null, name)
77

88
this.x = frame.x
@@ -12,6 +12,7 @@ class Column extends Phaser.Group {
1212
this.index = index
1313
this.currentPosition = 3
1414

15+
this.bugs = bugs
1516
this.score = score
1617
this.remove = remove
1718

@@ -29,7 +30,7 @@ class Column extends Phaser.Group {
2930
this.hit = false
3031
this.currentPosition = 3
3132
this.children.forEach(bullet => bullet.disable())
32-
this.remove()
33+
this.remove(this.index)
3334
}
3435

3536
render() {
@@ -41,7 +42,7 @@ class Column extends Phaser.Group {
4142
const previousBullet = this.children[this.currentPosition+1]
4243
const nextBullet = this.children[this.currentPosition-1]
4344

44-
const bugsColumn = this.parent.bugs.children[this.index]
45+
const bugsColumn = this.bugs.children[this.index]
4546
const currentBug = bugsColumn.children[this.currentPosition]
4647
const nextBug = bugsColumn.children[this.currentPosition+1]
4748

src/actors/bullets/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ class Bullets extends Phaser.Group {
1111
this.y = BULLETS.y
1212

1313
this.stack = []
14-
this.bugs = bugs
1514
this.updateTime = 0
1615

1716
this.fire = this.fire.bind(this)
1817
this.render = this.render.bind(this)
1918
this.remove = this.remove.bind(this)
2019

2120
BULLETS.frames.forEach((frame, index) => {
22-
this.addChild(new Column(this.game, name, frame, index, this.remove, score))
21+
this.addChild(new Column(this.game, name, frame, index, this.remove, score, bugs))
2322
})
2423

2524
this.game.world.addChild(this)
@@ -33,8 +32,9 @@ class Bullets extends Phaser.Group {
3332
this.stack.push(column)
3433
}
3534

36-
remove() {
37-
this.stack.shift()
35+
remove(column) {
36+
const index = this.stack.indexOf(column)
37+
this.stack.splice(index, 1)
3838
}
3939

4040
render() {

src/helpers/controls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Controls {
1212
this.left = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT)
1313
this.right = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT)
1414
this.spacebar = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR)
15+
this.enter = this.game.input.keyboard.addKey(Phaser.Keyboard.ENTER)
1516

1617
this.left.onDown.add(this.goLeft)
1718
this.right.onDown.add(this.goRight)

src/states/play.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Actors from '../actors'
22
import * as Helpers from '../helpers'
33

44
class Play extends Phaser.State {
5-
create() {
5+
create() {
66
this.game.add.sprite(0, 0, 'background')
77

88
this.score = new Helpers.Score(this.game)

0 commit comments

Comments
 (0)