MapView.ts
6.29 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { SaveDataManager } from "../../../component/SaveDataManager";
import { tMgr } from "../../../Global";
import ObjBaseView from "../../../prefabs/ObjBaseView";
import { BallSkinTable, TableName } from "../../table/TableDefine";
import { ObjType } from "../BattleConst";
import { MapData } from "./MapData";
import { RectBlockData } from "./RectBlockData";
export class MapView extends cc.Node {
private _colliderLayer: cc.Node;
get colliderLayer(): cc.Node { return this._colliderLayer; }
private _blockImgLayer: cc.Node;
/**砖块图层 */
get blockImgLayer(): cc.Node { return this._blockImgLayer; }
private _blockIconLayer: cc.Node;
/**砖块的图标图层 */
get blockIconLayer(): cc.Node { return this._blockIconLayer; }
private _effectLayer: cc.Node;
/**砖块的效果特效图层 */
get effectLayer(): cc.Node { return this._effectLayer; }
private _lightLayer: cc.Node;
/**砖块的高亮图层 */
get lightLayer(): cc.Node { return this._lightLayer; }
private _txtLayer: cc.Node;
/**数字图层 */
get txtLayer(): cc.Node { return this._txtLayer; }
private _txtUpLayer: cc.Node;
/** 遮住数字的图层*/
get txtUpLayer(): cc.Node { return this._txtUpLayer; }
private _ballLayer: cc.Node;
/**弹球 */
get ballLayer(): cc.Node { return this._ballLayer; }
private _mapData: MapData;
private _prefabCollection: cc.Node;
get prefabCollection(): cc.Node { return this._prefabCollection; }
private _testBall: cc.Node;
get testBall(): cc.Node { return this._testBall; }
private _rectBlcokUidList: number[] = [];
init(data: MapData, prefabCollection: cc.Node, preview: boolean) {
this._mapData = data;
this._prefabCollection = prefabCollection;
let height = data.mapGridSize.y * data.gridSize.y;
this.setContentSize(data.mapGridSize.x * data.gridSize.x, height);
this._colliderLayer = this.createLayer('colliderLayer');
this.addChild(this._colliderLayer);
this._blockImgLayer = this.createLayer('blockImgLayer');
this.addChild(this._blockImgLayer);
this._blockIconLayer = this.createLayer('blockIconLayer');
this.addChild(this._blockIconLayer);
this._effectLayer = this.createLayer('effectLayer');
this.addChild(this._effectLayer);
this._lightLayer = this.createLayer('lightLayer');
this.addChild(this._lightLayer);
this._txtLayer = this.createLayer('txtLayer');
this.addChild(this._txtLayer);
this._txtUpLayer = this.createLayer('txtUpLayer');
this.addChild(this._txtUpLayer);
this._ballLayer = this.createLayer('ballLayer');
this.addChild(this._ballLayer);
let foo: cc.Node;
let cmpt: ObjBaseView;
data.objData.forEach((obj, index, map) => {
foo = null;
if (obj.type == ObjType.PLUS_ONE || obj.type == ObjType.SPLITER) {
foo = cc.instantiate(prefabCollection.getChildByName('dotSkill'));
}
else if (obj.type >= ObjType.LANCER_1 && obj.type <= ObjType.LANCER_3) {
foo = cc.instantiate(prefabCollection.getChildByName('laser'));
}
else if (obj.type == ObjType.BIG_BOMB || obj.type == ObjType.BIG_BOMB_33) {
foo = cc.instantiate(prefabCollection.getChildByName('bigBomb'));;
}
else if (obj.type == ObjType.TRANGLE_1 || obj.type == ObjType.TRANGLE_2 || obj.type == ObjType.TRANGLE_3 || obj.type == ObjType.TRANGLE_4) {
let fff = obj.type - 2;
foo = cc.instantiate(prefabCollection.getChildByName('trangleBlock' + fff.toString()));
}
else if (obj.type == ObjType.POT) {
foo = cc.instantiate(prefabCollection.getChildByName('pot'));
}
else if (obj.type == ObjType.ROTATER) {
foo = cc.instantiate(prefabCollection.getChildByName('rotater'));
}
else if (obj.type == ObjType.STATIC_IRON) {
foo = cc.instantiate(prefabCollection.getChildByName('staticNail'));
}
else if (obj.type == ObjType.PATROL) {
foo = cc.instantiate(prefabCollection.getChildByName('patrol'));
}
else {
if (obj instanceof RectBlockData) {
if (!this._rectBlcokUidList.includes(obj.uid)) {
this._rectBlcokUidList.push(obj.uid);
foo = cc.instantiate(prefabCollection.getChildByName('rectBlock'));;
}
}
else {
foo = cc.instantiate(prefabCollection.getChildByName('block'));;
}
}
if (foo) {
let cmpt = foo.getComponent(ObjBaseView);
cmpt.init(obj, this);
preview && cmpt.onPreview();
}
}, this);
this._testBall = cc.instantiate(prefabCollection.getChildByName('testBall'));
this._ballLayer.addChild(this._testBall);
}
private createLayer(name: string): cc.Node {
let layer = new cc.Node(name);
layer.setContentSize(this._mapData.mapGridSize.x * this._mapData.gridSize.x, this._mapData.mapGridSize.y * this._mapData.gridSize.y);
return layer;
}
playBlockParticle(node: cc.Node) {
let parPrefab = this._prefabCollection.getChildByName('parBlockBoom');
let par = cc.instantiate(parPrefab);
par.setPosition(node.position);
par.active = false;
let skinId = SaveDataManager.ins.runtimeData.ballSkinCurrent;
SaveDataManager.ins.runtimeData.ballSkinTry > 0 && (skinId = SaveDataManager.ins.runtimeData.ballSkinTry);
let ballSkin = tMgr.getConfig(TableName.BALL_SKIN, skinId) as BallSkinTable;
cc.resources.load('battle/' + ballSkin.Particle, cc.SpriteFrame, (error, asset) => {
if (!error) {
par.active = true;
par.getComponent(cc.ParticleSystem).custom = true;
par.getComponent(cc.ParticleSystem).spriteFrame = asset as cc.SpriteFrame;
par.getComponent(cc.ParticleSystem).resetSystem();
}
})
// par.getComponent(cc.ParticleSystem).resetSystem();
this._effectLayer.addChild(par);
}
}