Files
Test/js/player/bullet.js

49 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2025-12-10 17:47:15 +08:00
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
}
}