Commit cb6d0736 authored by wildfirecode's avatar wildfirecode

1

parent 36f088e4
import { TextRenderer } from 'scilla-components/src';
import { Entity } from 'scilla/src';
import Body from './Body';
import { calNextColor } from './scenePlay/colors';
export default class BallItem extends Body {
private _storedScore;
......@@ -8,6 +9,8 @@ export default class BallItem extends Body {
scoreTxt: Entity;
isBig = true;
size: BallSizeType;
colorIndex: number;
nextColorIndex: number;
constructor() {
super();
this.gravity = 0.225;
......@@ -35,6 +38,7 @@ export default class BallItem extends Body {
this._currentScore = score;
this._storedScore = score;
this.updateScoreTxt();
this.nextColorIndex = calNextColor(this.colorIndex);
}
updateScoreTxt() {
......@@ -42,7 +46,7 @@ export default class BallItem extends Body {
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;
updateColor(color: BallType) {
this.color = color;
......@@ -60,9 +64,9 @@ export default class BallItem extends Body {
export enum BallSizeType {
min = 0,
size1,
size2,
max,
size1 = 1,
size2 = 2,
max = 3,
}
export enum BallType {
blue = 'blue',
......@@ -71,4 +75,6 @@ export enum BallType {
green = 'green',
darkBlue = 'darkBlue',
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 { DropType } from './scenePlay/DropManager';
import { Entity } from 'scilla/src';
import { DropType } from './scenePlay/DropType';
export default class RocketItem extends Body {
type: DropType;
......
......@@ -125,11 +125,11 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
this._bulletManager.bullets.splice(i, 1);
i--;
const resultScore = ball.reduceScore(this.getBulletStren());
if ( ball.currentScore == 0) { //破裂
if (ball.currentScore == 0) { //破裂
this.checkBallSplit(ball);
}
this.score += resultScore;
console.log(this.getBulletStren(),resultScore);
// console.log(this.getBulletStren(), resultScore);
this.updateScoreTxt();
break;
}
......@@ -203,14 +203,15 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
this.score = 0;
this._carBullet = 0;
this._carFire = 100*10;
this._carFire = 100 ;
this._bulletManager.updateLines(this._carBullet);
this.updateScoreTxt();
this._pause = false;
this._carShootAni.enabled = true;
console.log('sceneplay onAwake');
// console.log('sceneplay onAwake');
this._timer = setInterval(() => {
this._ballManager.createBigBall();
this._ballManager.addBall(this._carBullet, this._carFire)
}, 2 * 1000);
}
......
......@@ -3,10 +3,24 @@ import { getX, getY, setScale, setXY } from 'assets/scripts/transformUtils';
import ScillaComponent from 'components/base/ScillaComponent';
import { Transform } from 'scilla-components/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 { randomColorIndex } from './colors';
import { getBallScoreRange, getBallScore } from './ballScore';
import { getNextScore } from './getNextScore';
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() {
this.disableBalls();
}
......@@ -34,8 +48,11 @@ export default class BallManager extends ScillaComponent {
this._freeBallList.push(ball);
// console.log('this.ballList', this.ballList.length, 'this._freeBallList', this._freeBallList.length);
if (ball.size > BallSizeType.min) {//开始分裂
const ball1 = this.createSplitedBall(ball);
const ball2 = this.createSplitedBall(ball);
const nextSizeType = ball.size - 1;
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;
ball2.velocityX = 5;
} else {//掉落
......@@ -46,40 +63,47 @@ export default class BallManager extends ScillaComponent {
BallItemPrefab: resource;
topline: Entity;
ballList: BallItem[];
private _freeBallList: BallItem[];
ballList: BallItem[] = [];
private _freeBallList: BallItem[]=[];
createSplitedBall(parentBall: BallItem) {
const score = Math.ceil(parentBall.storedScore / 2);
createSplitedBall(parentBall: BallItem, size, score, nextColorIndex) {
const ball = this.getBall();
ball.reset();
ball.resetScore(score);
ball.updateColor(parentBall.color)
setScale(ball, .5);
ball.size = size;
// console.log(size)
ball.updateColor(ball.childNames[nextColorIndex]);
setScale(ball, BallSizeTypeList[size] / BallSizeTypeList[BallSizeTypeList.length - 1]);
setXY(ball, getX(parentBall), getY(parentBall));
this.ballList.push(ball);
this.entity.addChild(ball.entity);
ball.enabled = true;
ball.velocityY = -10;
ball.size = BallSizeType.min;
ball.velocityY = -5;
return ball;
}
async createBigBall() {
const score = Math.ceil(10 + Math.random() * 20);
private async createBigBall(score, dir, colorIndex, size: BallSizeType) {
const ball = this.getBall();
ball.reset();
ball.resetScore(score);
ball.updateColor(pickFromList(ball.childNames))
ball.updateColor(ball.childNames[colorIndex])
setScale(ball, 1);
let dir = Math.random() > 0.5 ? -1 : 1;
setXY(ball.entity, -375, getY(this.topline));
ball.enabled = false;
this.ballList.push(ball);
this.entity.addChild(ball.entity);
ball.size = BallSizeType.max;
await getTween(this, ball.getComponent(Transform), { x: -375 + 200 }, 700);
ball.velocityX = 5;
ball.size = size;
setScale(ball, BallSizeTypeList[size] / BallSizeTypeList[BallSizeTypeList.length - 1]);
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;
}
......@@ -98,12 +122,4 @@ export default class BallManager extends ScillaComponent {
const body = ball.getComponent(BallItem);
return body;
}
onAwake() {
super.onAwake();
if (!this.ballList) {
this.ballList = [];
this._freeBallList = [];
}
}
}
......@@ -6,9 +6,8 @@ import { instantiate, resource } from 'scilla/src';
import Body from '../Body';
import RocketItem from '../RocketItem';
import { removeFromList } from '../_';
export enum DropType {
red = 'red', blue = 'blue', yellow = 'yellow', purple = 'purple'
}
import { DropType } from './DropType';
export default class DropManager extends ScillaComponent {
RedFirePrefab: 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 @@
<script src="./security.js"></script>
<script src="debug/bundle.js"></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": "" };
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