-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.js
289 lines (275 loc) · 9.57 KB
/
Main.js
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//include('src/ProcessManager.js');
include('Classes/AppDelegate.js');
//19
include('Graphic/EventHandler/include.js');
include('Graphic/Control/include.js');
include('Graphic/Utils/Utils.js');
include('Graphic/Utils/Timer.js');
include('Graphic/Effect/Convolution.js');
include('Graphic/Basic/include.js');
include('Graphic/com/include.js');
include('src/rules.js');
include('io.js');
//19
var TotalScore = TotalScore || 0;
var Record = Record || "";
var ProcessManager = cc.Layer.extend({
TTFText:null,
Level:-1,
Score:0,
backCount:10,
GameOver:false,
Ranking:null,
ctor:function () {
this._super();
this.Ranking = new Ranking();
},
getLevel:function (score) {
this.Score = score;
if (score < ProcessManager.LEVEL_1) return -1;
if (score >= ProcessManager.LEVEL_5)return 1;
if (score >= ProcessManager.LEVEL_4)return .75;
if (score >= ProcessManager.LEVEL_3)return .5;
if (score >= ProcessManager.LEVEL_2)return .25;
if (score >= ProcessManager.LEVEL_1)return 0;
},
isLevelUP:function (level) {
if (level != this.Level) {
this.Level = level;
this.showHitPoint("Level ", cc.ccc3(0xff, 0, 0), 52, "UP!", cc.ccc3(0xff, 0xff, 0), 52, "AR");
return true;
}
return false;
},
showHitPoint:function (text01, color01, size01, text02, color02, size02, font, time) {
if (!font)font = "BigBlocko";
if (!time)
time = 1;
this.TTFText.setVisible(true);
this.TTFText.setOpacity(255);
this.TTFText.setTextByIndex(0, text01, font, size01, color01);
this.TTFText.setTextByIndex(1, text02, font, size02, color02);
Graphic.Animation.Queue.add(cc.FadeOut.create(time), Graphic.Animation.Dispatcher(this.TTFText, null, function (e) {
e.target.setVisible(false);
if (main.GameOver) {
}
}));
},
TimesUp:function () {
if (this.coin == 0) {
this.stopAll();
this.GameOver = true;
this.showHitPoint("Time's ", cc.ccc3(0xff, 0xff, 0), 64, "UP!", cc.ccc3(0xff, 0xff, 0), 64, "AR", 2);
ScoreBoard.showCalcBoard();
} else
this.showHitPoint("Time's ", cc.ccc3(0xff, 0xff, 0), 64, "UP!", cc.ccc3(0xff, 0xff, 0), 64, "AR", 0.5);
},
gameOverBackCounter:function (e) {
}
});
ProcessManager.LEVEL_1 = 200;
ProcessManager.LEVEL_2 = 350;
ProcessManager.LEVEL_3 = 500;
ProcessManager.LEVEL_4 = 650;
ProcessManager.LEVEL_5 = 800;
var main;
var Main = ProcessManager.extend({
bIsMouseDown:false,
size:null,
time:0,
label:null,
basket:null,
ball:null,
ballPoints:null,
ballGetPoints:null,
scoreBoard:null,
powerBar:null,
coin:11,
ADD_TIME_COST:15,
step:0,
index:0,
item:[],
Layers:[],
ctor:function () {
this._super();
},
init:function () {
//////////////////////////////
// 1. super init first
this._super();
return true;
},
createDinamicLayer:function (id, size) {
var layer = new Graphic.DynamicLayer(size, id);
this.addChild(layer);
this.Layers.push(layer);
return layer;
},
getLazyLayerByIndex:function (index) {
return index && index >= 0 && index < this.Layers.length ? this.Layers[index] : null;
},
onEnter:function () {
this._super();
this.initLayer();
},
ccTouchesBegan:function (pTouches, pEvent) {
},
ccTouchesMoved:function (pTouches, pEvent) {
},
ccTouchesEnded:function (pTouches, pEvent) {
if (cc.Director.sharedDirector().isPaused() || this.GameOver)return;
var level = this.getLevel(this.scoreBoard.getScore());
switch (this.step) {
case 0:
if (this.ball.ActionRunning)return;
this.powerBar.play(level);
this.step = 1;
break
case 1:
this.powerBar.stop();
var miss = !this.powerBar.isHitLine();
console.log(miss ? "MISS" : "HIT");
this.ball.Shoot(miss, (miss ? false : this.powerBar.isHitCenter()), this.addScore, this);
this.step = 0;
break;
}
},
update:function () {
return;
},
addScore:function (target, sink) {
if (sink) {
var text = target.powerBar.isHitCenter() ? "Excellent" : Math.random() * 2 > 1 ? "Great" : "Good";
target.label.showTextByName(text);
target.scoreBoard.addScore(text == "Excellent");
var level = target.getLevel(target.scoreBoard.getScore());
var result = target.isLevelUP(level);
if (result) {
target.addCoin();
}
} else {
var text = "Miss";
target.label.showTextByName(text);
}
switch (text) {
case "Excellent":
ScoreBoard.addExcellentCount();
break;
case "Great":
ScoreBoard.addGreatCount();
break;
case "Good":
ScoreBoard.addGoodCount();
break;
case "Miss":
ScoreBoard.addMissCount();
break;
}
},
addCoin:function () {
$("#CoinText").text(Graphic.Utils.AutoZeros(1, ++this.coin, true));
},
subCoin:function () {
//ScoreBoard.showCalcBoard();
if (this.coin > 0) {
if (this.scoreBoard.addTime(this.ADD_TIME_COST))
$("#CoinText").text(Graphic.Utils.AutoZeros(1, --this.coin, true));
}
},
closeCallback:function () {
history.go(-1);
},
pause:function () {
if (this.GameOver)return;
this.TimesUp();
if (this.GameOver)return;
cc.Director.sharedDirector().pause();
},
resume:function () {
cc.Director.sharedDirector().resume();
},
stopAll:function () {
this.ball.stop();
this.powerBar.stop();
this.label.stop();
this.scoreBoard.stop();
}
});
//Main.bIsMouseDown = null;
Main.prototype.initLayer = function () {
//cc.AudioManager.sharedEngine().playEffect("Audio/bounce.mp3");
var size = this.size = cc.Director.sharedDirector().getWinSize();
var backgroundLayer = this.createDinamicLayer("backgroundLayer");
this.scoreBoard = new ScoreBoard(0, 30);
this.subCoin();
$("#Coin").show();
//init background
var background = cc.Sprite.create("src/Image/Background.png");
background.setAnchorPoint(cc.ccp(0.5, 0.5));
background.setPosition(cc.ccp(size.width / 2, size.height / 2));
backgroundLayer.addChild(background);
var gameObjectsLayer = this.createDinamicLayer("gameObjectsLayer");
this.basket = new Graphic.Sprite("src/Image/Basket.png", this.basket);
this.basket.setAnchorPoint(cc.ccp(0.5, 0));
this.basket.setPosition(cc.ccp(size.width / 2, size.height - 274));
gameObjectsLayer.addChild(this.basket);
this.ball = new Ball("src/Image/basketball.png", this.basket);
this.ball.setAnchorPoint(cc.ccp(0.5, 0.5));
this.ball.setPosition(cc.ccp(size.width / 2, 8));
this.ball.BallPosition = cc.ccp(size.width / 2, 8);
gameObjectsLayer.addChild(this.ball);
Ball.BOTTON = size.height - 261;
this.ballPoints = this.ball.shooting[1];
this.ballGetPoints = this.ball.sink;
this.powerBar = new PowerBar("src/Image/PowerBar/cover.png", "src/Image/PowerBar/bar.png", "src/Image/PowerBar/mask.png");
this.powerBar.setPosition(cc.ccp(0, this.powerBar.height / 2));
var UILayer_PowerBar = this.createDinamicLayer("UILayer_PowerBar", cc.SizeMake(this.powerBar.width, this.powerBar.height));
UILayer_PowerBar.setPosition(cc.ccp(size.width / 2 - 153, size.height / 2));
UILayer_PowerBar.addChild(this.powerBar);
this.label = new CSSTextDraw("Null", "BigBlocko", 56);
this.label.setPosition(cc.ccp(this.label.getRange().width / 2, 0));
var UILayer_HitPoint = this.createDinamicLayer("UILayer_HitPoint", this.label.getRange());
UILayer_HitPoint.setPosition(cc.ccp(size.width / 2 - this.label.getRange().width / 2, 0));
UILayer_HitPoint.addChild(this.label);
var UILayer = this.createDinamicLayer("UILayer_UIText", cc.SizeMake(cc.canvas.width, 128));
var text = this.TTFText = new Graphic.CustomSizeTTF();
UILayer.setPosition(cc.ccp(0, size.height / 2 - 64));
text.setPosition(cc.ccp(size.width / 2, 64));
text.addText("Game ", "BigBlocko", 70, cc.ccc3(0xff, 0, 0));
text.addText("Start", "BigBlocko", 70, cc.ccc3(0xff, 0, 0));
Graphic.Animation.Queue.add(cc.FadeOut.create(1), Graphic.Animation.Dispatcher(this.TTFText, null, function (e) {
e.target.setVisible(false);
}));
UILayer.addChild(text);
cc.Director.sharedDirector().getTouchDispatcher().addStandardDelegate(this, 1);
cc.Director.sharedDirector().getScheduler().scheduleUpdateForTarget(this, 0, false);
//ScoreBoard.showCalcBoard();
};
Main.subCoin = function () {
if (main)
main.subCoin();
};
Main.scene = function () {
// 'scene' is an autorelease object
var scene = cc.Scene.create();
// 'layer' is an autorelease object
var layer = Main.node();
scene.addChild(layer);
return scene;
};
// implement the "static node()" method manually
Main.node = function () {
var pRet = new Main();
// Init the Main display layer.
if (pRet && pRet.init()) {
main = pRet;
return pRet;
}
return null;
};
Main.sharedLayer = function () {
if (main != null)
return main;
else
return Main.node();
};