Commit cb6d0736 authored by wildfirecode's avatar wildfirecode

1

parent 36f088e4
import { TextRenderer } from 'scilla-components/src'; import { TextRenderer } from 'scilla-components/src';
import { Entity } from 'scilla/src'; import { Entity } from 'scilla/src';
import Body from './Body'; import Body from './Body';
import { calNextColor } from './scenePlay/colors';
export default class BallItem extends Body { export default class BallItem extends Body {
private _storedScore; private _storedScore;
...@@ -8,6 +9,8 @@ export default class BallItem extends Body { ...@@ -8,6 +9,8 @@ export default class BallItem extends Body {
scoreTxt: Entity; scoreTxt: Entity;
isBig = true; isBig = true;
size: BallSizeType; size: BallSizeType;
colorIndex: number;
nextColorIndex: number;
constructor() { constructor() {
super(); super();
this.gravity = 0.225; this.gravity = 0.225;
...@@ -35,6 +38,7 @@ export default class BallItem extends Body { ...@@ -35,6 +38,7 @@ export default class BallItem extends Body {
this._currentScore = score; this._currentScore = score;
this._storedScore = score; this._storedScore = score;
this.updateScoreTxt(); this.updateScoreTxt();
this.nextColorIndex = calNextColor(this.colorIndex);
} }
updateScoreTxt() { updateScoreTxt() {
...@@ -42,7 +46,7 @@ export default class BallItem extends Body { ...@@ -42,7 +46,7 @@ export default class BallItem extends Body {
tr.text = this._currentScore.toString(); tr.text = this._currentScore.toString();
} }
childNames = ['blue', 'purple', 'red', 'green', 'darkBlue', 'yellow']; childNames = [BallType.yellow, BallType.green, BallType.blue, BallType.darkBlue, BallType.purple, BallType.red];
color: BallType; color: BallType;
updateColor(color: BallType) { updateColor(color: BallType) {
this.color = color; this.color = color;
...@@ -60,9 +64,9 @@ export default class BallItem extends Body { ...@@ -60,9 +64,9 @@ export default class BallItem extends Body {
export enum BallSizeType { export enum BallSizeType {
min = 0, min = 0,
size1, size1 = 1,
size2, size2 = 2,
max, max = 3,
} }
export enum BallType { export enum BallType {
blue = 'blue', blue = 'blue',
...@@ -71,4 +75,6 @@ export enum BallType { ...@@ -71,4 +75,6 @@ export enum BallType {
green = 'green', green = 'green',
darkBlue = 'darkBlue', darkBlue = 'darkBlue',
yellow = 'yellow', yellow = 'yellow',
} }
\ No newline at end of file
export const BallSizeTypeList = [74, 126, 165, 227];
\ No newline at end of file
import Body from './Body'; import Body from './Body';
import { DropType } from './scenePlay/DropManager';
import { Entity } from 'scilla/src'; import { Entity } from 'scilla/src';
import { DropType } from './scenePlay/DropType';
export default class RocketItem extends Body { export default class RocketItem extends Body {
type: DropType; type: DropType;
......
...@@ -125,11 +125,11 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -125,11 +125,11 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
this._bulletManager.bullets.splice(i, 1); this._bulletManager.bullets.splice(i, 1);
i--; i--;
const resultScore = ball.reduceScore(this.getBulletStren()); const resultScore = ball.reduceScore(this.getBulletStren());
if ( ball.currentScore == 0) { //破裂 if (ball.currentScore == 0) { //破裂
this.checkBallSplit(ball); this.checkBallSplit(ball);
} }
this.score += resultScore; this.score += resultScore;
console.log(this.getBulletStren(),resultScore); // console.log(this.getBulletStren(), resultScore);
this.updateScoreTxt(); this.updateScoreTxt();
break; break;
} }
...@@ -203,14 +203,15 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -203,14 +203,15 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
} }
this.score = 0; this.score = 0;
this._carBullet = 0; this._carBullet = 0;
this._carFire = 100*10; this._carFire = 100 ;
this._bulletManager.updateLines(this._carBullet);
this.updateScoreTxt(); this.updateScoreTxt();
this._pause = false; this._pause = false;
this._carShootAni.enabled = true; this._carShootAni.enabled = true;
console.log('sceneplay onAwake'); // console.log('sceneplay onAwake');
this._timer = setInterval(() => { this._timer = setInterval(() => {
this._ballManager.createBigBall(); this._ballManager.addBall(this._carBullet, this._carFire)
}, 2 * 1000); }, 2 * 1000);
} }
......
...@@ -3,10 +3,24 @@ import { getX, getY, setScale, setXY } from 'assets/scripts/transformUtils'; ...@@ -3,10 +3,24 @@ import { getX, getY, setScale, setXY } from 'assets/scripts/transformUtils';
import ScillaComponent from 'components/base/ScillaComponent'; import ScillaComponent from 'components/base/ScillaComponent';
import { Transform } from 'scilla-components/src'; import { Transform } from 'scilla-components/src';
import { Entity, instantiate, resource, createTween, ease } from 'scilla/src'; import { Entity, instantiate, resource, createTween, ease } from 'scilla/src';
import BallItem, { BallSizeType } from '../BallItem'; import BallItem, { BallSizeType, BallSizeTypeList } from '../BallItem';
import { pickFromList, removeFromList } from '../_'; import { pickFromList, removeFromList } from '../_';
import { randomColorIndex } from './colors';
import { getBallScoreRange, getBallScore } from './ballScore';
import { getNextScore } from './getNextScore';
export default class BallManager extends ScillaComponent { export default class BallManager extends ScillaComponent {
addBall(carBullet, carFire) {
let size = Math.floor(Math.random() * 4); //随机size,0-3
let colorIndex = randomColorIndex(size); //根据size随机颜色
let scorerange = getBallScoreRange(carBullet, carFire);
scorerange = scorerange.map(val => Math.ceil(val * (window['ballscore-p'] || 1)));
const score = getBallScore(scorerange, colorIndex);// [1, 100];
let dir = Math.random() > 0.5 ? -1 : 1;
// this.createBigBall(20, dir, colorIndex, size);
this.createBigBall(score, dir, colorIndex, size);
}
onGameOver() { onGameOver() {
this.disableBalls(); this.disableBalls();
} }
...@@ -34,8 +48,11 @@ export default class BallManager extends ScillaComponent { ...@@ -34,8 +48,11 @@ export default class BallManager extends ScillaComponent {
this._freeBallList.push(ball); this._freeBallList.push(ball);
// console.log('this.ballList', this.ballList.length, 'this._freeBallList', this._freeBallList.length); // console.log('this.ballList', this.ballList.length, 'this._freeBallList', this._freeBallList.length);
if (ball.size > BallSizeType.min) {//开始分裂 if (ball.size > BallSizeType.min) {//开始分裂
const ball1 = this.createSplitedBall(ball); const nextSizeType = ball.size - 1;
const ball2 = this.createSplitedBall(ball); const nextScore = getNextScore(ball.storedScore);
const nextColorIndex = ball.nextColorIndex;
const ball1 = this.createSplitedBall(ball, nextSizeType, nextScore, nextColorIndex);
const ball2 = this.createSplitedBall(ball, nextSizeType, nextScore, nextColorIndex);
ball1.velocityX = -5; ball1.velocityX = -5;
ball2.velocityX = 5; ball2.velocityX = 5;
} else {//掉落 } else {//掉落
...@@ -46,40 +63,47 @@ export default class BallManager extends ScillaComponent { ...@@ -46,40 +63,47 @@ export default class BallManager extends ScillaComponent {
BallItemPrefab: resource; BallItemPrefab: resource;
topline: Entity; topline: Entity;
ballList: BallItem[]; ballList: BallItem[] = [];
private _freeBallList: BallItem[]; private _freeBallList: BallItem[]=[];
createSplitedBall(parentBall: BallItem) { createSplitedBall(parentBall: BallItem, size, score, nextColorIndex) {
const score = Math.ceil(parentBall.storedScore / 2);
const ball = this.getBall(); const ball = this.getBall();
ball.reset(); ball.reset();
ball.resetScore(score); ball.resetScore(score);
ball.updateColor(parentBall.color) ball.size = size;
setScale(ball, .5); // console.log(size)
ball.updateColor(ball.childNames[nextColorIndex]);
setScale(ball, BallSizeTypeList[size] / BallSizeTypeList[BallSizeTypeList.length - 1]);
setXY(ball, getX(parentBall), getY(parentBall)); setXY(ball, getX(parentBall), getY(parentBall));
this.ballList.push(ball); this.ballList.push(ball);
this.entity.addChild(ball.entity); this.entity.addChild(ball.entity);
ball.enabled = true; ball.enabled = true;
ball.velocityY = -10; ball.velocityY = -5;
ball.size = BallSizeType.min;
return ball; return ball;
} }
async createBigBall() { private async createBigBall(score, dir, colorIndex, size: BallSizeType) {
const score = Math.ceil(10 + Math.random() * 20);
const ball = this.getBall(); const ball = this.getBall();
ball.reset(); ball.reset();
ball.resetScore(score); ball.resetScore(score);
ball.updateColor(pickFromList(ball.childNames)) ball.updateColor(ball.childNames[colorIndex])
setScale(ball, 1); setScale(ball, 1);
let dir = Math.random() > 0.5 ? -1 : 1;
setXY(ball.entity, -375, getY(this.topline));
ball.enabled = false; ball.enabled = false;
this.ballList.push(ball); this.ballList.push(ball);
this.entity.addChild(ball.entity); this.entity.addChild(ball.entity);
ball.size = BallSizeType.max; ball.size = size;
await getTween(this, ball.getComponent(Transform), { x: -375 + 200 }, 700); setScale(ball, BallSizeTypeList[size] / BallSizeTypeList[BallSizeTypeList.length - 1]);
ball.velocityX = 5; if (dir == 1) {
setXY(ball.entity, -375, getY(this.topline));
await getTween(this, ball.getComponent(Transform), { x: -375 + 200 }, 700);
ball.velocityX = 5;
}
else {
setXY(ball.entity, 375, getY(this.topline));
await getTween(this, ball.getComponent(Transform), { x: 375 - 200 }, 700);
ball.velocityX = -5;
}
ball.enabled = true; ball.enabled = true;
} }
...@@ -98,12 +122,4 @@ export default class BallManager extends ScillaComponent { ...@@ -98,12 +122,4 @@ export default class BallManager extends ScillaComponent {
const body = ball.getComponent(BallItem); const body = ball.getComponent(BallItem);
return body; return body;
} }
onAwake() {
super.onAwake();
if (!this.ballList) {
this.ballList = [];
this._freeBallList = [];
}
}
} }
...@@ -6,9 +6,8 @@ import { instantiate, resource } from 'scilla/src'; ...@@ -6,9 +6,8 @@ import { instantiate, resource } from 'scilla/src';
import Body from '../Body'; import Body from '../Body';
import RocketItem from '../RocketItem'; import RocketItem from '../RocketItem';
import { removeFromList } from '../_'; import { removeFromList } from '../_';
export enum DropType { import { DropType } from './DropType';
red = 'red', blue = 'blue', yellow = 'yellow', purple = 'purple'
}
export default class DropManager extends ScillaComponent { export default class DropManager extends ScillaComponent {
RedFirePrefab: resource; RedFirePrefab: resource;
BlueRocketPrefab: resource; BlueRocketPrefab: resource;
......
export enum DropType {
red = 'red', blue = 'blue', yellow = 'yellow', purple = 'purple'
}
\ No newline at end of file
import getPropItem from './getPropItem'
//6种颜色
export const getBallScore = ([a, b], colorIndex) => {
let n = Math.abs(b - a) + 1;
n = Math.floor(n / 6);
const m = [];
// m.push([a, a + n - 1]);
// m.push([a + n, a + n + n - 1]);
for (let i = 0; i < 5; i++) {
m.push([a + n * i, a + n * i + n - 1]);
}
m.push([a + n * 4 + n, b])
const [a0, b0] = m[colorIndex]; //1-10
let result = Math.ceil(Math.random() * (b0 - a0 + 1)) + a0
return result;
}
export const getBallScoreRange = (carBullet: number, carFire: number): any => {
if (carBullet <= 20)
return [0.01 * carFire, 0.2 * carFire]
if (carBullet > 20 && carBullet <= 40)
return [0.2 * carFire, 0.6 * carFire]
if (carBullet > 40 && carBullet <= 60) {
const list = [
[0.2 * carFire, 0.6 * carFire],
[0.6 * carFire, 0.8 * carFire],
[0.8 * carFire, 1.5 * carFire],
]
return getPropItem(list, [3, 5, 2])[0];
}
if (carBullet > 60 && carBullet <= 80) {
const list = [
[0.6 * carFire, 0.8 * carFire],
[0.8 * carFire, 1.5 * carFire],
[1.5 * carFire, 2.2 * carFire],
]
return getPropItem(list, [2, 5, 2])[0];
}
if (carBullet > 80 && carBullet <= 100) {
const list = [
[1.5 * carFire, 2.2 * carFire],
[2.2 * carFire, 3.2 * carFire],
[3.2 * carFire, 4.2 * carFire],
]
return getPropItem(list, [1, 5, 4])[0];
}
if (carBullet > 100 && carBullet <= 120) {
const list = [
[2.2 * carFire, 3.2 * carFire],
[3.2 * carFire, 4.2 * carFire],
[4.2 * carFire, 5.2 * carFire],
]
return getPropItem(list, [1, 4, 5])[0];
}
// if (carBullet > 120 && carBullet <= 140) {
const list = [
[2.2 * carFire, 3.2 * carFire],
[3.2 * carFire, 4.2 * carFire],
[4.2 * carFire, 5.2 * carFire],
]
return getPropItem(list, [1, 3, 6])[0];
// }
}
\ No newline at end of file
export const colorsMcOrder = [6, 5, 2, 3, 4, 1];
export const calNextColor = (colorIndex: number) => {
return colorIndex >= 1 ? colorIndex - 1 : 0;
}
export const randomColorIndex = (sizeType) => {
let colorIndex;
if (sizeType == 0) {
colorIndex = Math.floor(Math.random() * colorsMcOrder.length);//0-5
}
if (sizeType == 1) { //1-5
colorIndex = Math.floor(Math.random() * (colorsMcOrder.length - 1)) + 1;//0-4 + 1
}
if (sizeType == 2) { //2-5
colorIndex = Math.floor(Math.random() * (colorsMcOrder.length - 2)) + 2;//0-3 + 2
}
if (sizeType == 3) {//3-5
colorIndex = Math.floor(Math.random() * (colorsMcOrder.length - 3)) + 3;//0-2 + 3
}
return colorIndex;
}
export const getChangeColor = (score, initscore, initColorIndex) => {
//红5,紫4,深蓝3,蓝2,绿1,黄0
//生成颜色分数段,总100分
//黄 0 ,黄的不变色
const per = score / initscore;
//绿 1,1/2的时候变黄
if (initColorIndex == 1) {
if (per < 1 / 2) return initColorIndex - 1
}
//蓝 2,1/3的时候变黄 2/3变绿
if (initColorIndex == 2) {
if (per < 1 / 3) return initColorIndex - 2;
if (per < 2 / 3) return initColorIndex - 1;
}
//深蓝 3,1/4的时候变黄,2/4绿,3/4蓝
if (initColorIndex == 3) {
if (per < 1 / 4) return initColorIndex - 3;
if (per < 2 / 4) return initColorIndex - 2;
if (per < 3 / 4) return initColorIndex - 1;
}
//紫 4,1/5黄,2/5绿,3/5蓝 4/5 深蓝
if (initColorIndex == 4) {
if (per < 1 / 5) return initColorIndex - 4;
if (per < 2 / 5) return initColorIndex - 3;
if (per < 3 / 5) return initColorIndex - 2;
if (per < 4 / 5) return initColorIndex - 1;
}
//红 5,1/6黄,2/6绿,3/6蓝 4/6 深蓝 5/6 紫
if (initColorIndex == 5) {
if (per < 1 / 6) return initColorIndex - 5;
if (per < 2 / 6) return initColorIndex - 4;
if (per < 3 / 6) return initColorIndex - 3;
if (per < 4 / 6) return initColorIndex - 2;
if (per < 5 / 6) return initColorIndex - 1;
}
return initColorIndex;
}
\ No newline at end of file
export const getNextScore = (initscore) => {
const p = Math.random() * 0.4 + 0.8;
return Math.ceil(initscore / 2 * p);
}
\ No newline at end of file
const fill = (item, n) => {
const result = [];
for (let i = 0; i < n; i++) {
result.push(item);
}
return result;
}
export default (items: any[], props: number[], n = 1) => {
let pool = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
pool = pool.concat(fill(item, props[i]));
}
const result = [];
for (let i = 0; i < n; i++) {
const index = Math.floor(Math.random() * pool.length);
const resultItem = pool[index];
result.push(resultItem);
}
return result;
}
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
<script src="./security.js"></script> <script src="./security.js"></script>
<script src="debug/bundle.js"></script> <script src="debug/bundle.js"></script>
<script> <script>
window['ballscore-p']=0.1;
var CFG = { "actId": "3335069", "oaId": "3335069", "unitName": "积分", "btnUnitName": "积分", "doJoin": "/hdtool/doJoin?dpm=1.3.1.0&activityId=3335069", "quireOrder": "/hdtool/getOrderStatus", "styleConfig": "/hdtool/getHdtoolConfig", "getElement": "/hdtool/ajaxElement", "getPrizeDetail": "/hdtool/prizeDetail", "ajaxThroughInfo": "/hdtool/ajaxThroughInfo", "throughSubmit": "/hdtool/throughSubmit", "gameGetOrder": "/hdtool/getOrderInfo", "gameSubmit": "/hdtool/gameSubmit", "doSubmit": "/hdtool/submit", "adslotId": "", "consumerId": "1", "isNotLoginUser": false, "uid": "1", "hdType": "duiba", "hdToolId": "42363", "appType": "credits", "subType": "custom", "directSendCoupon": "false", "ajaxAction": "", "recommendQueue": "/recommend/getRecommend", "recommendSkin": "/recommend/getRecommendSkin", "isShowDetail": true, "preview": false, "from": "", "login": "//activity.m.duiba.com.cn/hdtool/login?dpm=1.3.3.0", "flowRedirectUrl": "", "flowRedirectTuiaUrl": "", "isOpenRecommend": false, "getCreditsLink": "http://baidu.com?uid=1&dbnewopen", "appId": "1", "recordUrl": "//activity.m.duiba.com.cn/crecord/record?dbnewopen&dpm=1.3.2.0", "shareDesc": "分享分享文案文案", "entranceDesc": "测试领奖,也可到我的奖品领奖,24小时内有效哦", "isSHowMeat": true, "needCouponModal": true, "needRecommendModal": true, "asyncFiles": [], "shareAndroidLinkActivity": "http://www.duiba.com.cn", "shareIosLinkActivity": "http://www.iqiyi.com", "appName": "custom", "needShare": true, "shareTitle": "", "shareSubTitle": "", "sharePicUrl": "", "shareLink": "", "shareAndroidDeeplink": "", "shareIOSDeeplink": "" }; var CFG = { "actId": "3335069", "oaId": "3335069", "unitName": "积分", "btnUnitName": "积分", "doJoin": "/hdtool/doJoin?dpm=1.3.1.0&activityId=3335069", "quireOrder": "/hdtool/getOrderStatus", "styleConfig": "/hdtool/getHdtoolConfig", "getElement": "/hdtool/ajaxElement", "getPrizeDetail": "/hdtool/prizeDetail", "ajaxThroughInfo": "/hdtool/ajaxThroughInfo", "throughSubmit": "/hdtool/throughSubmit", "gameGetOrder": "/hdtool/getOrderInfo", "gameSubmit": "/hdtool/gameSubmit", "doSubmit": "/hdtool/submit", "adslotId": "", "consumerId": "1", "isNotLoginUser": false, "uid": "1", "hdType": "duiba", "hdToolId": "42363", "appType": "credits", "subType": "custom", "directSendCoupon": "false", "ajaxAction": "", "recommendQueue": "/recommend/getRecommend", "recommendSkin": "/recommend/getRecommendSkin", "isShowDetail": true, "preview": false, "from": "", "login": "//activity.m.duiba.com.cn/hdtool/login?dpm=1.3.3.0", "flowRedirectUrl": "", "flowRedirectTuiaUrl": "", "isOpenRecommend": false, "getCreditsLink": "http://baidu.com?uid=1&dbnewopen", "appId": "1", "recordUrl": "//activity.m.duiba.com.cn/crecord/record?dbnewopen&dpm=1.3.2.0", "shareDesc": "分享分享文案文案", "entranceDesc": "测试领奖,也可到我的奖品领奖,24小时内有效哦", "isSHowMeat": true, "needCouponModal": true, "needRecommendModal": true, "asyncFiles": [], "shareAndroidLinkActivity": "http://www.duiba.com.cn", "shareIosLinkActivity": "http://www.iqiyi.com", "appName": "custom", "needShare": true, "shareTitle": "", "shareSubTitle": "", "sharePicUrl": "", "shareLink": "", "shareAndroidDeeplink": "", "shareIOSDeeplink": "" };
function requirelogin() { function requirelogin() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment