Files
Test/js/player/bullet.js
2025-12-10 17:47:15 +08:00

49 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}
}