RectBlockData.ts
3.17 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
100
101
import { ObjType } from "../BattleConst";
import { BlockData } from "./BlockData";
import { MapData } from "./MapData";
import { ObjDataUtil } from "./ObjDataUtil";
export class RectBlockData extends BlockData {
private _widthGrid: number;
get widthGrid(): number { return this._widthGrid; }
get widthPixel(): number { return this._widthGrid * this.map.gridSize.x; }
private _heightGrid: number;
get heightGrid(): number { return this._heightGrid; }
get heightPixel(): number { return this._heightGrid * this.map.gridSize.y; }
get viewPixelPosX(): number { return this._pixelPos.x + (this._widthGrid) / 2 * this.map.gridSize.x - this.map.gridSize.x / 2; }
get viewPixelPosY(): number { return this._pixelPos.y - (this._heightGrid) / 2 * this.map.gridSize.y + this.map.gridSize.y / 2 }
//#region life cycle
initBlock(map: MapData, type: ObjType, hp: number, gridX: number, gridY: number, width: number = 1, height: number = 1): void {
this._widthGrid = width;
this._heightGrid = height;
super.initBlock(map, type, hp, gridX, gridY);
for (let i = this._gridPos.x; i < this._gridPos.x + this._widthGrid; ++i) {
for (let j = this._gridPos.y; j < this._gridPos.y + this._heightGrid; ++j) {
if (i == this._gridPos.x && j == this._gridPos.y) {
continue;
}
let index = ObjDataUtil.getIndex(i, j);
this.map.objData.delete(index);//删除范围内的其他格子
this.map.blockData.delete(index);
}
}
this._contentY = this._gridPos.y + this._heightGrid - 1;
}
clone(): RectBlockData {
return this.cloneValue(new RectBlockData())
}
protected cloneValue(target: RectBlockData): RectBlockData {
super.cloneValue(target);
target._widthGrid = this._widthGrid;
target._heightGrid = this._heightGrid;
return target;
}
//#endregion
//#region public method
setGridPos(gridX: number, gridY: number): void {
// this.clearFromMap();
super.setGridPos(gridX, gridY);
this._contentY = this._gridPos.y + this._heightGrid - 1;
// this.addToMap();
}
isReachedDownBorder(): boolean {
return !this._droped && (this._gridPos.y + this._heightGrid - 1 >= this.map.mapGridSize.y - 1);
}
// private clearFromMap() {
// for (let i = this._gridPos.x; i < this._gridPos.x + this._widthGrid; ++i) {
// for (let j = this._gridPos.y; j < this._gridPos.y + this._heightGrid; ++j) {
// let index = ObjDataUtil.getIndex(i, j);
// this.map.blockData.delete(index);
// }
// }
// }
// private addToMap() {
// for (let i = this._gridPos.x; i < this._gridPos.x + this._widthGrid; ++i) {
// for (let j = this._gridPos.y; j < this._gridPos.y + this._heightGrid; ++j) {
// let index = ObjDataUtil.getIndex(i, j);
// this.map.blockData.set(index, this);
// }
// }
// }
//#endregion
//#region event
//#endregion
//#region private method
//#endregion
}