Commit 70e24b13 authored by Tt's avatar Tt

随机机器人难度

parent 123fa0e2
This diff is collapsed.
{
"ver": "1.2.9",
"uuid": "78d42262-aebf-4332-a79b-f96bf10a0800",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.0.8",
"uuid": "bcf6af36-5a46-4eb5-a2a0-ba1bb2fadfc7",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -2,6 +2,9 @@ import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import pg from "./pg";
import map from "./map";
import {
showFireworks,
} from '../script/utils';
const { ccclass, property } = cc._decorator;
......@@ -70,11 +73,20 @@ export default class NewClass extends MyCocosSceneComponent {
private playerPoint: number;//
private robotPoint: number;//
private turnRobot: boolean;//当前是谁操作
private robotLevel: number;
onGameStart() {
this.log("test onGameStart")
this.playerPoint = 0;
this.robotPoint = 0;
this.turnRobot = Math.random() < 0.5;
let rand = Math.random();
if (rand < 0.3) {
this.robotLevel = 0;//0 1 2 三个级别 0 最高
} else if (rand < 0.6) {
this.robotLevel = 1;//0 1 2 三个级别 0 最高
} else {
this.robotLevel = 2;//0 1 2 三个级别 0 最高
}
this.initChess();
this.scheduleOnce(this.startTouzi, 2.1);
}
......@@ -240,7 +252,8 @@ export default class NewClass extends MyCocosSceneComponent {
let runNum = 1;
let rand = Math.random();
if (this.turnRobot) {
runNum = 1 + Math.floor(rand * 5);
//确认当前机器人是哪个级别,然后再对应级别进行抽奖
runNum = 1 + Math.floor(rand * (6 - (this.robotLevel * 1.3)));
} else {
runNum = 1 + Math.floor(rand * 6);
}
......@@ -289,7 +302,8 @@ export default class NewClass extends MyCocosSceneComponent {
if (this.playerPoint > this.robotPoint) {
pg.view.visible(bg_win, true);
pg.view.visible(bg_lose, false);
pg.hw.playLocalAudio("flower");
this.showFireFlower();
// pg.hw.playLocalAudio("flower");
} else {
pg.view.visible(bg_win, false);
pg.view.visible(bg_lose, true);
......@@ -303,6 +317,29 @@ export default class NewClass extends MyCocosSceneComponent {
onHomeworkFinish();
}
//-----------------------------TOOL-------------------------------
showFireFlower() {
return new Promise((resolve, reject) => {
this.playLocalAudio("flower")
showFireworks(
this.node,
pg.view.find(this, 'RibbonNodeBase').children,
cc.v2(0, -600), cc.v2(0, 1000), 200, 200
);
showFireworks(
this.node,
pg.view.find(this, 'RibbonNodeBase').children,
cc.v2(-600, -600), cc.v2(200, 1000), 200, 200
);
showFireworks(
this.node,
pg.view.find(this, 'RibbonNodeBase').children,
cc.v2(600, -600), cc.v2(-200, 1000), 200, 200
);
setTimeout(() => {
resolve('');
}, 1500);
});
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
......
export function getPosByAngle(angle, len) {
const radian = angle * Math.PI / 180;
const x = Math.sin(radian) * len;
const y = Math.cos(radian) * len;
return { x, y };
}
export function getAngleByPos(px, py, mx, my) {
const x = Math.abs(px - mx);
const y = Math.abs(py - my);
const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
const cos = y / z;
const radina = Math.acos(cos); // 用反三角函数求弧度
let angle = Math.floor(180 / (Math.PI / radina) * 100) / 100; // 将弧度转换成角度
if (mx > px && my > py) {// 鼠标在第四象限
angle = 180 - angle;
}
if (mx === px && my > py) {// 鼠标在y轴负方向上
angle = 180;
}
if (mx > px && my === py) {// 鼠标在x轴正方向上
angle = 90;
}
if (mx < px && my > py) {// 鼠标在第三象限
angle = 180 + angle;
}
if (mx < px && my === py) {// 鼠标在x轴负方向
angle = 270;
}
if (mx < px && my < py) {// 鼠标在第二象限
angle = 360 - angle;
}
// console.log('angle: ', angle);
return angle;
}
export function exchangeNodePos(baseNode, targetNode) {
return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)));
}
export function RandomInt(a, b = 0) {
let max = Math.max(a, b);
let min = Math.min(a, b);
return Math.floor(Math.random() * (max - min) + min);
}
export function randomSortByArr(arr) {
const newArr = [];
const tmpArr = arr.concat();
while (tmpArr.length > 0) {
const randomIndex = Math.floor(tmpArr.length * Math.random());
newArr.push(tmpArr[randomIndex]);
tmpArr.splice(randomIndex, 1);
}
return newArr;
}
export async function asyncTweenTo(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(duration, obj, ease)
.call(() => {
resolve();
})
.start();
});
}
export async function asyncTweenBy(node, duration, obj, ease = undefined) {
return new Promise((resolve, reject) => {
cc.tween(node)
.by(duration, obj, ease)
.call(() => {
resolve();
})
.start();
});
}
export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1, onFrameEvent) {
return new Promise((resolve, reject) => {
node.getComponent(dragonBones.ArmatureDisplay)
.once(dragonBones.EventObject.COMPLETE, () => {
resolve();
});
node.getComponent(dragonBones.ArmatureDisplay)
.on(dragonBones.EventObject.FRAME_EVENT, ({ name }) => {
if (onFrameEvent && typeof (onFrameEvent) == 'function') {
onFrameEvent(name);
}
});
node.getComponent(dragonBones.ArmatureDisplay)
.playAnimation(animationName, time);
});
}
export async function asyncPlayEffectByUrl(url, loop = false) {
return new Promise((resolve, reject) => {
cc.assetManager.loadRemote(url, (err, clip) => {
console.log(clip);
cc.audioEngine.playEffect(clip, loop);
resolve();
});
});
}
export async function jelly(node) {
return new Promise((resolve, reject) => {
cc.tween(node)
.to(0.1, { scaleX: 0.9, scaleY: 1.1 })
.to(0.1, { scaleX: 1.1, scaleY: 0.9 })
.to(0.1, { scaleX: 1, scaleY: 1 })
.call(resolve)
.start();
});
}
export async function asyncDelay(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, time * 1000);
})
}
export async function showFireworks(baseNode, nodeList, pos = cc.v2(0, 0), side = cc.v2(0, 100), range = 50, number = 100) {
new Array(number).fill(' ').forEach(async (_, i) => {
let rabbonNode = new cc.Node();
rabbonNode.parent = baseNode;
rabbonNode.x = pos.x;
rabbonNode.y = pos.y;
rabbonNode.angle = 60 * Math.random() - 30;
let node = cc.instantiate(nodeList[RandomInt(nodeList.length)]);
node.parent = rabbonNode;
node.active = true;
node.x = 0;
node.y = 0;
node.angle = 0;
const rate = Math.random();
const angle = Math.PI * (Math.random() * 2 - 1);
await asyncTweenBy(rabbonNode, 0.3, {
x: side.x * rate + Math.cos(angle) * range * rate,
y: side.y * rate + Math.sin(angle) * range * rate
}, {
easing: 'quadIn'
});
cc.tween(rabbonNode)
.by(8, { y: -2000 })
.start();
rabbonFall(rabbonNode);
await asyncDelay(Math.random());
cc.tween(node)
.by(0.15, { x: -10, angle: -10 })
.by(0.3, { x: 20, angle: 20 })
.by(0.15, { x: -10, angle: -10 })
.union()
.repeatForever()
.start();
cc.tween(rabbonNode)
.delay(5)
.to(0.3, { opacity: 0 })
.call(() => {
node.stopAllActions();
node.active = false;
node.parent = null;
node = null;
})
.start();
});
}
async function rabbonFall(node) {
const time = 1 + Math.random();
const offsetX = RandomInt(-200, 200) * time;
await asyncTweenBy(node, time, { x: offsetX, angle: offsetX * 60 / 200 });
rabbonFall(node);
}
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "3bbd94ac-4119-4b46-bc17-21f2f45fff4d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "f21339cc-58b6-47bd-b701-7d5cab49ec53",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "7a305826-0fed-4051-9f16-5542637cc8da",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 36,
"height": 24,
"platformSettings": {},
"subMetas": {
"bg_sahua": {
"ver": "1.0.4",
"uuid": "95a1b983-981a-4b0a-854c-7cc38cd2f9d6",
"rawTextureUuid": "7a305826-0fed-4051-9f16-5542637cc8da",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 36,
"height": 24,
"rawWidth": 36,
"rawHeight": 24,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
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