LaserObj.ts
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { SoundManager } from "../../../component/SoundManager";
import { SoundName } from "../../../Global";
import { LASER_DIR, ObjType } from "../BattleConst";
import { MapData } from "./MapData";
import { ObjData } from "./ObjData";
export class LaserObj extends ObjData {
private _dir: LASER_DIR = LASER_DIR.NONE;
get dir(): LASER_DIR { return this._dir; }
//#region life cycle
init(map: MapData, type: ObjType, gridX: number, gridY: number): void {
super.init(map, type, gridX, gridY);
if (type == ObjType.LANCER_1) {
this._dir = LASER_DIR.VERTICAL;
this._imgName = 'UI_yxz_tsfk_jg1';
}
else if (type == ObjType.LANCER_2) {
this._dir = LASER_DIR.HORIZEN;
this._imgName = 'UI_yxz_tsfk_jg2';
}
else if (type == ObjType.LANCER_3) {
this._dir = LASER_DIR.COMBINE;
this._imgName = 'UI_yxz_tsfk_jg3';
}
}
clone(): LaserObj {
return this.cloneValue(new LaserObj());
}
protected cloneValue(target: LaserObj): LaserObj {
super.cloneValue(target);
target._dir = this._dir;
return target;
}
//#endregion
//#region public method
//#endregion
//#region event
onCollisonToBall(collider: cc.Collider): void {
super.onCollisonToBall(collider);
this.map.battle.addToRoundClear(this);
if (this._dir == LASER_DIR.HORIZEN || this._dir == LASER_DIR.COMBINE) {
for (let x: number = 0; x < this.map.mapGridSize.x; ++x) {
let block = this.map.getBlockByGridPos(x, this.gridPos.y);
if (block) {
block.onCollisonToBall(null);
// if (block instanceof RectBlockData) {
// // block.widthGrid
// x += (block.widthGrid - 1); //跳过宽度
// }
}
}
}
if (this._dir == LASER_DIR.VERTICAL || this._dir == LASER_DIR.COMBINE) {
for (let y: number = 0; y < this.map.mapGridSize.y; ++y) {
let block = this.map.getBlockByGridPos(this.gridPos.x, y);
if (block) {
block.onCollisonToBall(null);
// if (block instanceof RectBlockData) {
// // block.widthGrid
// y += (block.heightGrid - 1); //跳过宽度
// }
}
}
}
SoundManager.ins.playEffect(SoundName.RAZER);
}
//#endregion
//#region private method
//#endregion
}