Skip to content

Commit c38b145

Browse files
author
Null
committed
0.6
0.6更新: 1. 修复了一个会增大难度的BUG 2. 添加了公式种类 3. 难度随着时间的正常而变大 4. 取消了甩的操作 5. 修复了拖得时候会一下子拽出来的BUG 6. 修复了有可能*1,/1的BUG 7. 修改了平分方式(从无球处按下在要切开的球处松开) 8. 优化了操作感 9. 增大了合并的有效距离
1 parent 70de081 commit c38b145

File tree

2 files changed

+82
-66
lines changed

2 files changed

+82
-66
lines changed

assets/Script/Main.js

+76-60
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ var timer=0;
2828

2929
var score=0;
3030

31+
var roll=0;
32+
3133
var gameover=false;
3234

3335
var formulas=[
34-
"X+d",
35-
"X-d",
36-
"X*a+d","X*a-d",
37-
"X/a+d","X/a-d"
36+
"X+D",
37+
"X-D",
38+
"X*A&+D","X*A&-D",
39+
"X/A&+D","X/A&-D",
40+
"Math.sqrt(X)",
41+
"X*X-D",
42+
"D*Math.sin(X)"
3843
];
3944

4045
var formula = "";
@@ -47,23 +52,26 @@ var Ball = cc.Class({
4752
y:0,
4853
orx:0,
4954
ory:0,
50-
ortimer:0,
55+
drx:0,
56+
dry:0,
5157
ballnode : null,
5258
labelnode: null,
5359
pnode: null,psf:null,
54-
tow:false,toa:false,tod:false,tos:false,
5560
getSelfPosInBalls: function(){
5661
let id=0;
5762
for(id=0;id<balls.length;id++){
5863
if(balls[id].x==this.x&&balls[id].y==this.y&&balls[id].num==this.num) break;
5964
}
6065
return id;
6166
},
62-
67+
getR: function(){
68+
return this.ballnode.width*calcSize(this.num)/2;
69+
},
6370
ctor: function (node,sf) {
6471
this.pnode=node;
6572
this.psf=sf;
6673
this.num = Math.round(Math.random()*19)+1;
74+
this.targetnum=this.num;
6775

6876
//Set position
6977
var size = cc.winSize;
@@ -89,51 +97,23 @@ var Ball = cc.Class({
8997
this.ballnode.on(cc.Node.EventType.TOUCH_START, function ( event ) {
9098
this.orx=this.x;
9199
this.ory=this.y;
92-
this.ortimer=timer;
93-
this.tow=false;
94-
this.toa=false;
95-
this.tod=false;
96-
this.tos=false;
100+
this.drx=event.getLocationX()-size.width/2-this.x;
101+
this.dry=event.getLocationY()-size.height/2-this.y;
97102
}.bind(this));
98103

99104
//Move
100105
this.ballnode.on(cc.Node.EventType.TOUCH_MOVE, function ( event ) {
101106
var size = cc.winSize;
102-
this.setPos(event.getLocationX()-size.width/2,event.getLocationY()-size.height/2);
103-
if(this.x-this.orx>50) this.tow=true;
104-
if(this.x-this.orx<-50) this.tos=true;
105-
if(this.y-this.ory>50) this.tod=true;
106-
if(this.y-this.ory<-50)this.toa=true;
107-
//Throw
108-
if(this.num>=5&&(this.tow&&this.tos)||(this.tod&&this.toa)){
109-
let ballNum=Math.round(Math.random()*8)+2;
110-
let allNum=this.num;
111-
for(let i=0;i<ballNum;i++){
112-
let xd=Math.round(Math.random()*38)+12;
113-
let yd=Math.round(Math.random()*38)+12;
114-
if(Math.random()>0.5) xd=-xd;
115-
if(Math.random()>0.5) yd=-yd;
116-
let takeNum=i!=ballNum-1?Math.floor(Math.random()*allNum):allNum;
117-
if(takeNum===0) break;
118-
let ball=new Ball(this.pnode, this.psf);
119-
ball.setPos(this.x + xd,this.y +yd);
120-
ball.setNum(takeNum);
121-
allNum-=takeNum;
122-
balls.push(ball);
123-
}
124-
this.rm();
125-
removeFromBalls(this.getSelfPosInBalls());
126-
}
107+
this.setPos(event.getLocationX()-size.width/2-this.drx,event.getLocationY()-size.height/2-this.dry);
127108
}.bind(this));
128-
129109

130110
this.ballnode.on(cc.Node.EventType.TOUCH_END, function ( event ) {
131111
//碰撞检测,合并
132112
for(let i=0;i<balls.length;i++){
133113
let balli=balls[i];
134114
let ballj=this;
135115
if(balli.x==ballj.x&&balli.y==ballj.y&&balli.num==ballj.num) continue;
136-
if(posDiff(balli.x,balli.y,ballj.x,ballj.y)<20){
116+
if(posDiff(balli.x,balli.y,ballj.x,ballj.y)<ballj.getR()){
137117
let ball=new Ball(this.pnode, this.psf);
138118
ball.setPos(ballj.x,ballj.y);
139119
ball.targetnum=balli.num+ballj.num;
@@ -146,20 +126,6 @@ var Ball = cc.Class({
146126
return;
147127
}
148128
}
149-
150-
//平分
151-
if(this.num>=2&&timer-this.ortimer<1&&posDiff(this.x,this.y,this.orx,this.ory)<10){
152-
let ball1=new Ball(this.pnode, this.psf);
153-
let ball2=new Ball(this.pnode, this.psf);
154-
ball1.setPos(this.x - 15, this.y);
155-
ball1.setNum(Math.floor(this.num/2));
156-
ball2.setPos(this.x + 15, this.y);
157-
ball2.setNum(this.num - Math.floor(this.num/2));
158-
this.rm();
159-
removeFromBalls(this.getSelfPosInBalls());
160-
balls.push(ball1);
161-
balls.push(ball2);
162-
}
163129
}.bind(this));
164130
},
165131
setPos: function(x,y){
@@ -205,10 +171,14 @@ cc.Class({
205171

206172
numsum:0,
207173

174+
outstart:false,
175+
208176
genFormula: function(){
209-
formula=formulas[Math.floor(Math.random()*formulas.length)]
210-
.replace("a", random(1,5)).replace("a!", random(2,5)).replace("b", random(1,100)).replace("c", Math.floor(randomfloat(0,0.1)*this.numsum))
211-
.replace("d", Math.floor(randomfloat(0.5,0.8)*this.numsum)).replace("e", randomfloat(0,1));
177+
let id=Math.floor(Math.random()*formulas.length);
178+
if(id!=formulas.length - 1&&random(0,100)<roll) id++;
179+
formula=formulas[id]
180+
.replace("A&", random(2,5)).replace("A", random(1,5)).replace("B", random(1,100)).replace("C", Math.floor(randomfloat(0,0.1)*this.numsum))
181+
.replace("D", Math.floor(randomfloat(0.5,0.8)*this.numsum)).replace("E", randomfloat(0,1));
212182
this.formulaNode.string=formula;
213183
},
214184

@@ -217,13 +187,58 @@ cc.Class({
217187
balls.push(new Ball(this.node, this.ballsprite));
218188

219189
score=0;
190+
roll=0;
220191
formula="";
221192
this.numsum=0;
222193
for(let i=0;i<balls.length;i++){
223194
this.numsum+=balls[i].num;
224195
}
225196
this.scoreNode.string="Score: " + this.numsum + "/" + score;
226197
this.genFormula();
198+
199+
this.node.on(cc.Node.EventType.TOUCH_START, function ( event ) {
200+
let size = cc.winSize;
201+
let x=event.getLocationX()-size.width/2;
202+
let y=event.getLocationY()-size.height/2;
203+
this.outstart=true;
204+
for(let i=0;i<balls.length;i++){
205+
if(posDiff(x,y,balls[i].x,balls[i].y)<balls[i].getR()){
206+
this.outstart=false;
207+
break;
208+
}
209+
}
210+
}.bind(this));
211+
212+
this.node.on(cc.Node.EventType.TOUCH_END, function ( event ) {
213+
if(!this.outstart) return;
214+
215+
let size = cc.winSize;
216+
let x=event.getLocationX()-size.width/2;
217+
let y=event.getLocationY()-size.height/2;
218+
for(let i=0;i<balls.length;i++){
219+
if(balls[i].num>=2&&posDiff(x,y,balls[i].x,balls[i].y)<balls[i].getR()){
220+
//平分
221+
let ball1=new Ball(this.node, this.ballsprite);
222+
let ball2=new Ball(this.node, this.ballsprite);
223+
let ball1Num=Math.floor(balls[i].num/2);
224+
let ball2Num=balls[i].num - Math.floor(balls[i].num/2);
225+
let d=balls[i].ballnode.width*calcSize(balls[i].num/2)*2;
226+
ball1.setPos(balls[i].x - 30, balls[i].y);
227+
ball1.setNum(ball1Num);
228+
ball1.targetnum=ball1Num;
229+
ball2.setPos(balls[i].x + 30, balls[i].y);
230+
ball2.setNum(ball2Num);
231+
ball2.targetnum=ball2Num;
232+
balls[i].rm();
233+
removeFromBalls(balls[i].getSelfPosInBalls());
234+
balls.push(ball1);
235+
balls.push(ball2);
236+
break;
237+
}
238+
}
239+
240+
}.bind(this));
241+
227242
},
228243

229244
// use this for initialization
@@ -247,8 +262,8 @@ cc.Class({
247262

248263
let test=false;
249264
for(let i=0;i<balls.length;i++){
250-
//Test Apply formula
251-
if(parseInt(eval(formula.replace("X", balls[i].num)))>0){
265+
//Test apply formula
266+
if(parseInt(eval(formula.replace("X", balls[i].targetnum).replace("X", balls[i].targetnum)))>0){
252267
test=true;
253268
break;
254269
}
@@ -258,10 +273,11 @@ cc.Class({
258273

259274
if(timer>=TimeEachRound){
260275
timer=0;
276+
roll++;
261277

262278
for(let i=0;i<balls.length;){
263279
//Apply formula
264-
balls[i].targetnum=parseInt(eval(formula.replace("X", balls[i].num)));
280+
balls[i].targetnum=parseInt(eval(formula.replace("X", balls[i].targetnum).replace("X", balls[i].targetnum)));
265281
if(balls[i].targetnum<=0){
266282
balls[i].rm();
267283
removeFromBalls(i);
@@ -272,7 +288,7 @@ cc.Class({
272288

273289
this.numsum=0;
274290
for(let i=0;i<balls.length;i++){
275-
this.numsum+=balls[i].num;
291+
this.numsum+=balls[i].targetnum;
276292
}
277293
if(this.numsum>score) score=this.numsum;
278294
this.scoreNode.string="Score: " + this.numsum + "/" + score;

docs/formulas.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
| 替代符 | 含义 |
44
| :--: | :--------: |
55
| X | 球的数字 |
6-
| a | 1~5 任意数字 |
7-
| b | 1~100 任意数字 |
8-
| c | 0~10% 分数 |
9-
| d | 50%~80% 分数 |
10-
| e | 0~1 任意数字 |
11-
| a& | 2~5 任意数字 |
6+
| A | 1~5 任意数字 |
7+
| B | 1~100 任意数字 |
8+
| C | 0~10% 分数 |
9+
| D | 50%~80% 分数 |
10+
| E | 0~1 任意数字 |
11+
| A& | 2~5 任意数字 |
1212

0 commit comments

Comments
 (0)