123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { UITransform, v3 } from "cc";
- import CountDownSchedule from "./CountDownSchedule";
- export class Global {
- public static IsDevelop = false;
- //事件类型
- public static EventType_AddScore = "AddScore";
- public static EventType_MinusScore = "MinusScore";
- public static EventType_ShowTips = "ShowTips";
- public static EventType_GameOver = "GameOver";
- //音效
- public static Audio_Bg = "/audio/bg"
- public static Audio_AddScore = "/audio/AddScore"
- public static Audio_MinusScore = "/audio/minusScore"
- public static Audio_gameOver = "/audio/gameOver"
- public static Audio_GameFail = "/audio/GameFail"
- public static Audio_GameWin = "/audio/GameWin"
- public static Audio_Success = "/audio/success"
- public static Audio_SelectFail = "/audio/SelectFail"
- public static Audio_SelectWin = "/audio/SelectWin"
- public static Audio_Selected = "/audio/Selected"
- public static Audio_Drop = "/audio/Drop"
- public static Audio_timeOutFail = "/audio/timeOutFail"
- public static Audio_BlockRAndS = "/audio/BlockRAndS"
- //游戏
- public static StartLv = 1;
- public static MaxLv = 5;
- public static GameSetTime = 120;
- public static DifficultyRate = 1; //游戏难度系数
- //全局定时器
- public static cdSchedule: CountDownSchedule = new CountDownSchedule();
- public static getLevelData(datas, count) {
- let data = [];
- for (let i = 0; i < count; i++) {
- let index = 0;
- do {
- index = Global.getRandom(0, datas.length - 1);
- } while (data.indexOf(index) != -1);
- }
- }
- /**
- * 获取xxx-xxx之间的随机数
- * @param min 最小数
- * @param max 最大数
- * @returns 随机数字
- */
- public static getRandom(min, max): number {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- /**
- * 获取两个数字之差
- * @param num1
- * @param num2
- * @returns
- */
- public static getDifference(num1, num2): number {
- return Math.abs(num1 - num2);
- }
- public static randomSort(a) {
- return a.sort(() => Math.random() - 0.5);
- }
- public static nodeToOtherPos(s, o) {
- return Global.worldConvertLocalPointAR(s, Global.localConvertWorldPointAR(o))
- }
- /**
- * 得到一个节点的世界坐标
- * node的原点在中心
- * @param {*} node
- */
- public static localConvertWorldPointAR(node) {
- if (node) {
- return node.getComponent(UITransform).convertToWorldSpaceAR(v3());
- }
- return null;
- }
- /**
- * 把一个世界坐标的点,转换到某个节点下的坐标
- * 原点在node中心
- * @param {*} node
- * @param {*} worldPoint
- */
- public static worldConvertLocalPointAR(node, worldPoint) {
- if (node) {
- return node.getComponent(UITransform).convertToNodeSpaceAR(worldPoint);
- }
- return null;
- }
- }
|