Home > other >  * * * game development - rotary draw logical thinking * * *
* * * game development - rotary draw logical thinking * * *

Time:09-29

* * * game development - rotary draw logical thinking * * *

& gt; Engine: CocosCreator & gt; Language: JS

Thinking: no matter what language and engine all thinking and logic are exchanged, the following are local to get the data; Rotary draw the way a lot of kinds, we only said one of the most simple, practical and easy to understand way according to the Angle value calculation
1> Such as rotary table is divided into eight awards area, natural for each region of the Angle of 45 degrees,
2 & gt; According to the planning of the random probability random value, with the degree of value judgment should be rotating,
Are these two, lottery prizes have been actually, in the process of wheel rotation is merely the effect, if as a novice don't too situation next look at the code show

` ` `
Here I am in accordance with the turntable equal 8, for example, first make a random probability
//100 200 300 400 500 600 700 900 -- -- -- -- -- prizes
//40% 25% 15% 10% 4% 3% 2% 1% probability of -- -- -- -- --
Enclosing randomArray=[];
For (the let I=1; i<=40; I++) {
This. RandomArray. Push (" 100 ");
}
Continue to cycle according to different proportion to push to the array...
` ` `

` ` `
Then at least there is a button, click on the lottery;
CalculateCallBack: function () {//button callback
Let the date=new date ();
Let lastTime=cc. Sys. LocalStorage. The getItem (" lastTime ");
If (lastTime==null) {
Cc. Sys. LocalStorage. SetItem (" lastTime, "date. GetTime ());
Enclosing randomReward ();//this is the drive wheel rotation, the other can not to; Other function: click on a free click the lottery words need interval 24
}
The else {
Let intervalTime=(date. GetTime () - lastTime)/1000;
If (intervalTime & gt; 24 * 60 * 60) {
Cc. Sys. LocalStorage. SetItem (" lastTime, "date. GetTime ());
Enclosing randomReward ();
}
The else {
//call broadcast video
}
}
},
//specific functions according to their own needs to add, this is not about
` ` `

` ` `
The most important rotation of the rotary table
RandomReward: function () {
Let rand=Math. Floor (Math. The random () * 100);
Let random_Angle=null;//random degree
Let random_TurnsNumber=null;//random turns
This. Reward=null;
The switch (enclosing randomArray [rand]) {
Case "100" :
://minus the current Angle is repeatedly turned the wheel to stop after an Angle; Enclosing rotaryTable on behalf of the rotary table
Random_Angle=Math. Floor (Math. The random () * 45) + 0 - this. RotaryTable. Angle % 360;
//get a reward logic
break;
Case "200" :
Random_Angle=Math. Floor (Math. The random () * 45) + 45 - this. RotaryTable. Angle % 360;
break;
Case "300" :
Random_Angle=Math. Floor (Math. The random () * 45) + 90 - enclosing rotaryTable. Angle % 360;
break;
To continue the case...
}
Random_TurnsNumber=Math. Floor (Math. The random () * 6) + 12;//random rotation of a circle of
Let sumAngle=360 * random_TurnsNumber + random_Angle;//the current need to rotate Angle
This, rotaryTable runAction (cc rotateTo (8, sumAngle). Much (cc) easeInOut (3.0)));
},
` ` `
  • Related