49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
import Sprite from '../base/sprite';
|
||
|
||
const BULLET_IMG_SRC = 'images/bullet.png';
|
||
const BULLET_WIDTH = 16;
|
||
const BULLET_HEIGHT = 30;
|
||
|
||
export default class Bullet extends Sprite {
|
||
constructor() {
|
||
super(BULLET_IMG_SRC, BULLET_WIDTH, BULLET_HEIGHT);
|
||
}
|
||
|
||
init(x, y) {
|
||
this.x = x;
|
||
this.y = y;
|
||
this.isActive = true;
|
||
this.visible = true;
|
||
}
|
||
|
||
setPos(x, y) {
|
||
this.x = x;
|
||
this.y = y;
|
||
}
|
||
|
||
// 每一帧更新子弹位置
|
||
update() {
|
||
if (GameGlobal.databus.isGameOver) {
|
||
return;
|
||
}
|
||
|
||
// 子弹位置由外部控制(Player控制)
|
||
}
|
||
|
||
destroy() {
|
||
this.isActive = false;
|
||
// 子弹没有销毁动画,直接移除
|
||
this.remove();
|
||
}
|
||
|
||
remove() {
|
||
this.isActive = false;
|
||
this.visible = false;
|
||
// 回收子弹对象
|
||
GameGlobal.databus.removeBullets(this);
|
||
// 注意:DataBus.removeBullets 内部调用 pool.recover('bullet', bullet)
|
||
// 我们需要修改 DataBus 或者在这里手动回收
|
||
// 由于 DataBus 是通用的,我们最好修改 DataBus 或者在 DataBus 中传入 key
|
||
}
|
||
}
|