Commit 595aea93 authored by Edwise's avatar Edwise 🍷

hha

parents
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
/**
* Created by rockyl on 2020/10/23.
*/
import {getPxToken} from "../src/projectx";
function sum(a, b) {
return a + b;
}
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
test('getPxToken', async () => {
expect.assertions(1);
const {type, payload} = await getPxToken();
expect(type).toBe('success');
});
{
"id": "animation",
"name": "动画库",
"desc": "一些公共的动画",
"exports": [
{
"id": "d1fd0205-a999-49f5-9d57-2d8af1e53e48",
"name": "动画测试",
"type": 4,
"data": {
"attrs": {
"loop": "0",
"time": "2.0",
"autoPlay": true,
"timingFunction": "linear"
},
"frame": [
{
"key": 0,
"style": {
"scaleX": "1",
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 13.99999999,
"style": {
"scaleX": "1",
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 14,
"style": {
"scaleX": "1.3",
"scaleY": "1.3",
"moveX": 0,
"moveY": "0",
"rotate": 0,
"opacity": 1
}
},
{
"key": 27.99999999,
"style": {
"scaleX": "1.3",
"scaleY": "1.3",
"moveX": 0,
"moveY": "0",
"rotate": 0,
"opacity": 1
}
},
{
"key": 28,
"style": {
"scaleX": "1",
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 41.99999999,
"style": {
"scaleX": "1",
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 42,
"style": {
"scaleX": "1.3",
"scaleY": "1.3",
"moveX": "0",
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 69.99999999,
"style": {
"scaleX": "1.3",
"scaleY": "1.3",
"moveX": "0",
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 70,
"style": {
"scaleX": "1",
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
}
]
}
},
{
"id": "fcfeab33-2005-4d99-90c3-ead1075249e6",
"name": "123123",
"type": 4,
"data": {
"attrs": {
"loop": 0,
"time": "2.0",
"autoPlay": true,
"timingFunction": "linear"
},
"frame": [
{
"key": 10,
"style": {
"scaleX": 1,
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 34.99999999,
"style": {
"scaleX": 1,
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 35,
"style": {
"scaleX": 1,
"scaleY": "2",
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 58.99999999,
"style": {
"scaleX": 1,
"scaleY": "2",
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
},
{
"key": 59,
"style": {
"scaleX": 1,
"scaleY": 1,
"moveX": 0,
"moveY": 0,
"rotate": 0,
"opacity": 1
}
}
]
}
}
]
}
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "packages",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"pack": "node scripts/pack.js",
"test": "jest"
},
"dependencies": {
"fyge": "^2.0.0",
"isuuid": "^0.1.0",
"svga-parser": "^1.1.0"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"babel-jest": "^26.6.0",
"chalk": "^4.1.0",
"jest": "^26.6.0",
"rollup": "^2.26.11",
"tslib": "^2.0.1"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
export * from './log';
import isuuidImport from 'isuuid';
/**
* @type 1
* @name 判断是不是uuid
* @desc 判断是不是uuid
* @outputs {success:'是', failed:'不是'}
* @param {string} text 文本
*/
export function isuuid(text) {
return isuuidImport(text);
}
/**
* @type 1
* @name ua判断
* @desc 对ua进行正则判断,用于判断环境
* @outputs {success:'匹配成功', failed:'匹配失败'}
* @param {string|RegExp} reg 正则表达式
* @param {string} [flags] 正则标识
*/
export function testUA(reg, flags) {
let regexp = reg;
if (typeof reg === 'string') {
regexp = new RegExp(reg, flags);
}
return {
type: navigator.userAgent.match(regexp) ? 'success' : 'failed',
}
}
/**
* @type 1
* @name 返回前一个页面
* @desc 返回前一个历史记录的页面
*/
export function back() {
history.back();
}
/**
* @type 1
* @name 打印日志
* @desc 打印日志到控制台
* @outputs {success:'打印完成'}
* @param {*} [content] 内容
*/
export function log(content) {
console.log(content);
return {
type: 'success',
}
}
{
"id": "browser",
"name": "浏览器相关的过程",
"desc": "浏览器相关的一些过程"
}
/**
* Created by rockyl on 2020/8/26.
*
* @id duiba
* @name 兑吧相关的过程
* @desc 兑吧相关的过程
*/
/**
* @type 1
* @name 请求API接口
* @desc 请求api
* @outputs {success:'成功:响应内容', failed:'失败:错误信息'}
* @param {string} uri 地址
* @param {Object} [options] 请求配置
*/
export async function fetchApi(uri, options) {
const resp = await fetch(uri, options);
try {
const respObj = await resp.json();
return {
type: 'complete',
payload: respObj,
}
} catch (e) {
return {
type: 'exception',
payload: e,
}
}
}
import {
Ease,
Event,
GDispatcher,
MovieClip,
Point,
Shape,
Sound,
Sprite,
TextField,
TextureCache,
TEXT_ALIGN,
Tween,
VERTICAL_ALIGN
} from "fyge";
import {
Ins,
bezier
} from "./Ins";
import {
Smoke
} from "./Smoke";
import { cusPlaySound } from "./Sound";
export class Car extends Sprite {
worldTime = 0;
carImg; //车辆图片
speedX; //X轴速度
speedY; //Y轴速度
speedVector; //速度矢量
type; //类型,0:路上的车,1:玩家的车
isTurning; //正在转弯,特指玩家的车
isVip; //是否是vip车辆
vipId; //vipId,判断是哪种vip,主要用于不同的svga动效
dir; //方向,0:朝右,1:朝左,2:朝上,3:朝下
carState; //车辆状态
distance;
turnOver = false;
t;
isLast; //是否是当前车辆的最后一辆
smokePoint; //生成烟的位置,为了简单快捷,用shape当作点,因为shape会跟着rotation变动
smokePoint1;
waitSvga; //等待尾气svga动效
gasSvga; //甩尾svga动效
vipTipsFrame; //vip提示框图片
vipTipsLabel; //vip提示框文本
light; //车辆灯,vip是蓝灯,普通车是转弯失败的红灯
turnFailedImg; //右转失败的图片
constructor() {
super();
this.addEventListener(Event.ADDED_TO_STAGE, this.addToViewPort, this)
GDispatcher.addEventListener(Event.REMOVED_FROM_STAGE, this.removeFromViewPort, this);
}
addToViewPort() {
this.removeEventListener(Event.ADDED_TO_STAGE, this.addToViewPort, this)
this.initEle();
}
removeFromViewPort() {
this.removeEventListener(Event.REMOVED_FROM_STAGE, this.removeFromViewPort, this);
if (this.waitSvga) {
Ins.effectLayer.removeChild(this.waitSvga);
}
if (this.gasSvga) {
Ins.effectLayer.removeChild(this.gasSvga);
}
if(this.vipTipsLabel&&this.vipTipsFrame){
this.vipTipsFrame.removeChild(this.vipTipsLabel);
}
if(this.vipTipsFrame&&this.vipTipsFrame.parent){
this.vipTipsFrame.parent.removeChild(this.vipTipsFrame);
}
Tween.removeTweens(this);
}
initEle() {
}
/**
*
* @param type 类型,0:路上的车,1:玩家的车
* @param isVip 是否是vip车辆
* @param x x坐标
* @param y y坐标
* @param dir 方向,0:朝右,1:朝左,2:朝上,3:朝下
* @param
*/
initUi({
type,
isVip,
x,
y,
dir,
isLast
}) {
this.type = type;
this.isVip = isVip;
this.dir = dir;
this.x = x;
this.y = y;
this.isLast = isLast;
this.speedVector = new Point(0, 0);
this.carImg = new Sprite();
this.addChild(this.carImg);
let index1 = Math.floor(Math.random() * Ins.normalCarArr.length);
let uuid1 = Ins.normalCarArr[index1];
let index2 = Math.floor(Math.random() * Ins.vipCarArr.length);
let uuid2 = Ins.vipCarArr[index2];
if (type == 0) {
if (Math.random() > 0.3) {
this.carImg.texture = TextureCache[uuid1];
} else {
this.carImg.texture = TextureCache[uuid2];
}
} else {
// this.turnFailedImg = new Sprite(TextureCache['c1ab4c77-ec5e-48f3-9bdc-8753e892c705']);
this.light = new Sprite();
this.addChildAt(this.light, 0);
if (isVip) {
this.vipId = index2;
this.carImg.texture = TextureCache[uuid2];
this.light.texture = TextureCache["144a900b-e799-468d-b511-0f71b7caa114"];
this.vipTipsFrame = new Sprite(TextureCache["8177b4e1-2032-47e3-b8e9-f3b802b85b5b"]);
this.parent.addChild(this.vipTipsFrame);
this.vipTipsLabel = new TextField();
this.vipTipsLabel.textWidth = this.vipTipsFrame.width;
this.vipTipsLabel.textHeight = this.vipTipsFrame.height;
this.vipTipsLabel.textAlign = TEXT_ALIGN.CENTER;
this.vipTipsLabel.verticalAlign = VERTICAL_ALIGN.MIDDLE;
this.vipTipsLabel.size = 24;
this.vipTipsLabel.text = Ins.vipText[Math.floor(Math.random()*Ins.vipText.length)]
this.vipTipsFrame.addChild(this.vipTipsLabel);
this.vipTipsFrame.alpha = 0;
} else {
// console.log(TextureCache[uuid1]);
this.carImg.texture = TextureCache[uuid1];
this.light.texture = TextureCache["5460bdbf-5770-4b99-a570-3013bb4fe415"];
}
this.light.x = -this.light.width * 0.5;
this.light.y = -this.light.height - this.carImg.height * 0.5 + 10;
this.light.alpha = 0;
}
this.carImg.x = -this.carImg.width * 0.5;
this.carImg.y = -this.carImg.height * 0.5;
this.smokePoint = new Shape();
this.smokePoint.beginFill(6, 1);
this.smokePoint.drawCircle(0, 0, 0);
this.smokePoint.endFill();
this.addChild(this.smokePoint);
this.smokePoint.x = 0;
this.smokePoint.y = this.carImg.height * 0.5 + 5;
// this.smokePoint1 = new Shape();
// this.smokePoint1.beginFill(6, 0);
// this.smokePoint1.drawCircle(0, 0, 10);
// this.smokePoint1.endFill();
// this.addChild(this.smokePoint1);
// this.smokePoint1.x = -16;
// this.smokePoint1.y = this.carImg.height * 0.5+10;
//方向,0:朝右,1:朝左,2:朝上,3:朝下
switch (dir) {
case 0:
this.rotation = 90;
this.speedX = Ins.speedX;
this.speedY = 0;
this.speedVector.x = 1;
this.speedVector.y = 0;
this.changeState(Ins.CarState.goStage);
break;
case 1:
this.rotation = -90;
this.speedX = Ins.speedX;
this.speedY = 0;
this.speedVector.x = -1;
this.speedVector.y = 0;
this.changeState(Ins.CarState.goStage);
break;
case 2:
this.speedY = Ins.speedY;
this.speedX = 0;
this.speedVector.y = -1;
break;
case 3:
this.rotation = 180;
this.speedY = Ins.speedY;
this.speedX = 0;
this.speedVector.y = 1;
break;
default:
console.log("dir设置出错");
break;
}
}
setDistance(distance) {
this.resetFailSvga();
this.distance = distance
}
/**重置失败动效 */
resetFailSvga(){
if(this.light){
Tween.removeTweens(this.light)
this.light.alpha = 0;
}
if(this.turnFailedImg){
this.turnFailedImg.visible = false;;
// this.turnFailedImg.scaleX = 1.2;
// this.turnFailedImg.scaleY = 1.2;
// this.turnFailedImg.alpha = 0.2
}
}
stopSvga() {
if (this.gasSvga) {
this.gasSvga.stop();
}
}
/**转弯失败 */
turnFailed(){
this.stopSvga();
console.log("音效",this.sound);
if(this.sound){
this.sound.stop();
}
if(!this.turnFailedImg){
// console.log("haha",Ins.svgaPool['turnFailed'])
this.turnFailedImg = new MovieClip(Ins.svgaPool.turnFailed)
this.parent.addChildAt(this.turnFailedImg,999);
// this.turnFailedImg.anchorX = this.turnFailedImg.videoWidth*0.5;
// this.turnFailedImg.anchorY = this.turnFailedImg.videoHeight*0.5;
this.turnFailedImg.visible = true;
this.turnFailedImg.x = this.x-this.turnFailedImg.videoWidth*0.5;
this.turnFailedImg.y = this.y+this.carImg.height*0.5-this.turnFailedImg.videoHeight*0.4;
this.turnFailedImg.startAniRange(1,this.turnFailedImg.totalFrames,1);
// console.log(this.turnFailedImg);
}else{
this.turnFailedImg.visible = true;
this.turnFailedImg.x = this.x-this.turnFailedImg.videoWidth*0.5;
this.turnFailedImg.y = this.y+this.carImg.height*0.5-this.turnFailedImg.videoHeight*0.4;
this.turnFailedImg.startAniRange(1,this.turnFailedImg.totalFrames,1);
// console.log(this.turnFailedImg);
}
// Tween.get(this.turnFailedImg).to({alpha:1},100);
// Tween.get(this.turnFailedImg).to({alpha:1,scaleX:1,scaleY:1},600,Ease.quartOut);
if(!this.isVip){
Tween.get(this.light)
.to({alpha:1},100)
.to({alpha:0.2},100)
.to({alpha:1},100)
.to({alpha:0.2},100)
.to({alpha:1},100)
.to({alpha:0.2},100)
.to({alpha:1},100)
}
}
updateSelf(index) {
if (this.type == 0) {
this.x += this.speedX * this.speedVector.x;
this.y += this.speedY * this.speedVector.y;
if (this.speedVector.y > 0) {
if (this.y >= 3348) {
return true;
}
} else if (this.speedVector.y < 0) {
if (this.y <= -100) {
return true;
}
}
} else {
switch (this.carState) {
case Ins.CarState.default:
break;
case Ins.CarState.goStage:
this.goStage(index);
break;
case Ins.CarState.inStage:
this.inStage(index);
break;
case Ins.CarState.turning:
this.turning();
break;
case Ins.CarState.wait:
break;
case Ins.CarState.turnOver:
this.x += this.speedX * this.speedVector.x;
this.y += this.speedY * this.speedVector.y;
if (this.speedVector.y > 0) {
if (this.y >= 3348) {
return true;
}
} else if (this.speedVector.y < 0) {
if (this.y <= -100) {
return true;
}
}
break;
default:
console.log("变换车辆状态错误");
break;
}
}
}
inStage(index) {
if (this.waitSvga) {
let p = this.localToGlobal(new Point(this.smokePoint.x, this.smokePoint.y))
this.waitSvga.x = p.x - this.waitSvga.videoWidth * 0.5;
this.waitSvga.y = p.y - this.waitSvga.videoHeight * 0.5;
}
if (this.isVip && index == 0) {
let targetX = 0;
let targetY = 0;
let canTurn = true;
let scale = Ins.speedY / Ins.minSpeedY;
if (this.dir == 0) { //朝右
targetY = bezier(1, 820, 820, 920);
for (let i = 0; i < Ins.trackCarArr1.length; i++) {
let y1 = Ins.trackCarArr1[i].y + Ins.trackCarArr1[i].carImg.height * 0.5 + Ins.speedY * 12;
let y2 = Ins.trackCarArr1[i].y - Ins.trackCarArr1[i].carImg.height * 0.5 + Ins.speedY * 12;
if ((y1) >= (this.y - this.carImg.height * 0.8) && y2 <= (targetY + this.carImg.height * 0.8)) {
canTurn = false;
}
}
} else if (this.dir == 1) { //朝左
// targetX = bezier(1, Ins.rightStartX, 451, 451);
targetY = bezier(1, 2422, 2422, 2322);
for (let i = 0; i < Ins.trackCarArr2.length; i++) {
let y1 = Ins.trackCarArr2[i].y - Ins.trackCarArr2[i].carImg.height * 0.5 - Ins.speedY * 12;
let y2 = Ins.trackCarArr2[i].y + Ins.trackCarArr2[i].carImg.height * 0.5 - Ins.speedY * 12;
if ((y1) <= (this.y + this.carImg.height * 0.8) && y2 >= (targetY - this.carImg.height * 0.8)) {
canTurn = false;
}
}
}
if (canTurn) {
// this.changeState(Ins.CarState.turning)
GDispatcher.dispatchEvent(Ins.msg.vipStartTurn);
}
}
}
carMoveNormal() {
}
turning() {
// this.worldTime ++ ;
// if (this.worldTime % 5 == 0) {
// let p = this.localToGlobal(new Point(this.smokePoint.x, this.smokePoint.y))
// console.log(p.x, p.y);
// Ins.effectLayer.addChild(new Smoke(p.x, p.y,this.rotation));
// let p1 = this.localToGlobal(new Point(this.smokePoint1.x, this.smokePoint1.y))
// console.log(p1.x, p1.y);
// Ins.effectLayer.addChild(new Smoke(p1.x, p1.y,this.rotation));
// }
if (this.dir == 0) {
this.t += 0.04;
if (this.t >= 1) {
this.changeState(Ins.CarState.turnOver);
return;
}
this.x = bezier(this.t, Ins.leftStartX, 302, 302);
this.y = bezier(this.t, 820, 820, 920);
if (this.t <= 0.6) {
this.rotation += 3;
} else {
let r = this.rotation + 5;
if (r >= 180) {
this.rotation = 180;
} else {
this.rotation += 5;
}
}
} else if (this.dir == 1) {
this.t += 0.04;
if (this.t >= 1) {
this.changeState(Ins.CarState.turnOver);
return;
}
this.x = bezier(this.t, Ins.rightStartX, 451, 451);
this.y = bezier(this.t, 2422, 2422, 2322);
if (this.t <= 0.6) {
this.rotation += 3;
} else {
let r = this.rotation + 5;
if (r >= 0) {
this.rotation = 0;
} else {
this.rotation += 5;
}
}
}
}
goStage(index) {
if (this.dir == 0) { //朝右
this.x += this.speedX * this.speedVector.x;
if (this.x >= (Ins.leftStartX - this.distance)) {
this.changeState(Ins.CarState.inStage,index);
}
} else if (this.dir == 1) { //朝左
this.x += this.speedX * this.speedVector.x;
if (this.x <= Ins.rightStartX + this.distance) {
this.changeState(Ins.CarState.inStage,index);
}
}
}
setGasSvga() {
if (!this.gasSvga) {
if (!this.isVip) {
this.gasSvga = new MovieClip(Ins.svgaPool.trailGas);
Ins.effectLayer.addChild(this.gasSvga);
if (this.dir == 0) {
let p = this.localToGlobal(new Point(0, 0));
this.gasSvga.anchorX = this.gasSvga.videoWidth * 0.5;
this.gasSvga.anchorY = this.gasSvga.videoHeight * 0.5;
this.gasSvga.rotation = 180;
this.gasSvga.x = p.x - 130;
this.gasSvga.y = p.y - 142;
// console.log("gasSvga", p.x, p.y);
this.gasSvga.visible = true;
this.gasSvga.startAniRange(1, this.gasSvga.totalFrames, 1, () => {
this.gasSvga.visible = false
});
} else if (this.dir == 1) {
let p = this.localToGlobal(new Point(0, 0));
this.gasSvga.x = p.x - 274;
this.gasSvga.y = p.y - 242;
// console.log("gasSvga", p.x, p.y);
this.gasSvga.visible = true;
this.gasSvga.startAniRange(1, this.gasSvga.totalFrames, 1, () => {
this.gasSvga.visible = false
});
}
} else {
switch (this.vipId) {
case 0:
this.gasSvga = new MovieClip(Ins.svgaPool.vipWhite);
break;
case 1:
this.gasSvga = new MovieClip(Ins.svgaPool.vipOrigen)
break;
case 2:
this.gasSvga = new MovieClip(Ins.svgaPool.vipRed);
break;
case 3:
this.gasSvga = new MovieClip(Ins.svgaPool.vipBlue);
break;
default:
console.log("vipId出错");
break;
}
Ins.effectLayer.addChild(this.gasSvga);
if (this.dir == 0) {
let p = this.localToGlobal(new Point(0, 0));
this.gasSvga.anchorX = this.gasSvga.videoWidth * 0.5;
this.gasSvga.anchorY = this.gasSvga.videoHeight * 0.5;
this.gasSvga.rotation = 180;
this.gasSvga.x = p.x - 100;
this.gasSvga.y = p.y - 50;
// console.log("gasSvga", p.x, p.y);
this.gasSvga.visible = true;
this.gasSvga.startAniRange(5, this.gasSvga.totalFrames, 1, () => {
this.gasSvga.visible = false
});
} else if (this.dir == 1) {
let p = this.localToGlobal(new Point(0, 0));
this.gasSvga.x = p.x - 205;
this.gasSvga.y = p.y - 150;
// console.log("gasSvga", p.x, p.y);
this.gasSvga.visible = true;
this.gasSvga.startAniRange(5, this.gasSvga.totalFrames, 1, () => {
this.gasSvga.visible = false
});
}
}
} else {
this.gasSvga.visible = true;
this.gasSvga.startAniRange(1, this.gasSvga.totalFrames, 1, () => {
this.gasSvga.visible = false
});
}
}
sound;
changeState(state,index) {
this.carState = state;
if (state != Ins.CarState.inStage) {
if (this.waitSvga) {
this.waitSvga.visible = false;
}
} else {
if (this.waitSvga) {
this.waitSvga.visible = true;
}
}
switch (state) {
case Ins.CarState.default:
break;
case Ins.CarState.goStage:
this.resetFailSvga();
if (this.gasSvga) {
this.gasSvga.visible = false;
}
if (this.dir == 0) {
this.speedVector.x = 1;
this.speedVector.y = 0;
} else if (this.dir == 1) {
this.speedVector.x = -1;
this.speedVector.y = 0;
}
break;
case Ins.CarState.inStage:
this.resetFailSvga();
if (!this.waitSvga) {
this.waitSvga = new MovieClip(Ins.svgaPool.Wait);
// this.waitSvga.visible = false;
// console.log(p.x, p.y);
Ins.effectLayer.addChild(this.waitSvga);
let p = this.localToGlobal(new Point(this.smokePoint.x, this.smokePoint.y))
// console.log("动效属性",p.videoWidth,p.videoHeight)
this.waitSvga.anchorY = this.waitSvga.videoHeight * 0.5;
this.waitSvga.anchorX = this.waitSvga.videoWidth * 0.5;
if (this.dir == 0) {
this.waitSvga.scaleY = -1
this.waitSvga.rotation = 180;
}
this.waitSvga.x = p.x - this.waitSvga.videoWidth * 0.5;
this.waitSvga.y = p.y - this.waitSvga.videoHeight * 0.5;
this.waitSvga.visible = true;
// console.log(this.waitSvga);
}
if (this.isLast) {
Ins.canTouch = true;
}
if(index == 0){
if(this.vipTipsFrame){
this.vipTipsFrame.x = this.x - this.vipTipsFrame.width*0.5;
this.vipTipsFrame.y = this.y - this.carImg.width-this.vipTipsFrame.height-20;
Tween.removeTweens(this.vipTipsFrame);
Tween.get(this.vipTipsFrame).to({alpha:1},200)
}
}
this.speedVector.x = this.speedVector.y = 0;
break;
case Ins.CarState.turning:
if(this.vipTipsFrame){
Tween.removeTweens(this.vipTipsFrame);
Tween.get(this.vipTipsFrame).to({alpha:0},200)
}
this.setGasSvga();
this.worldTime = 0;
this.speedVector.x = 1;
this.speedVector.y = 1;
this.speedX = Ins.speedX;
this.speedY = Ins.speedY;
this.t = 0;
if(this.isVip){
this.light.alpha = 1;
this.sound = cusPlaySound("https://yun.duiba.com.cn/aurora/assets/cb2b36805e0040b89574cfebb2669f3032d5fdb8.mp3")
}else{
this.sound = cusPlaySound("https://yun.duiba.com.cn/aurora/assets/b06dee061913e866c4cec051be7020224aa220d3.mp3")
}
break;
case Ins.CarState.wait:
break;
case Ins.CarState.turnOver:
if(this.isVip){
Tween.get(this.light).to({alpha:0},200)
// this.light.alpha = 0;
}
this.turnOver = true;
this.speedVector.x = 0;
if (this.dir == 0) {
this.speedVector.y = 1;
} else if (this.dir == 1) {
this.speedVector.y = -1;
}
GDispatcher.dispatchEvent(Ins.msg.trackTurnOver, {isVip:this.isVip,x:this.x,y:this.y});
break;
default:
console.log("变换车辆状态错误");
break;
}
}
}
\ No newline at end of file
import { Event, Sprite } from "fyge";
export class GameStage extends Sprite{
constructor(data){
super();
this.props = data;
this.addEventListener(Event.ADDED_TO_STAGE,this.addToViewPort,this);
}
addToViewPort(){
this.removeEventListener(Event.ADDED_TO_STAGE,this.addToViewPort,this);
const {
assets,
angleOffset,
speedRange,
initPosRange
} = this.props;
console.log("props", this.props)
console.log("ass", assets)
// console.log(TextureCache);
}
}
\ No newline at end of file
import { Sound } from "fyge";
import * as SvgaParser from "svga-parser";
export class Ins{
static stageW;
static stageH;
static normalCarArr;
static vipCarArr;
static speedX;
static speedY;
static minSpeedY = 10;
static maxLevel = 2;
static effectLayer;
static CarState = {
default:1,
goStage:2,
inStage:3,
turning:4,
wait:5,
turnOver:6
}
static leftStartX = 150;
static rightStartX = 600;
static canTouch = false;
static trackCarArr1 = [];
static trackCarArr2 = [];
static msg = {
trackTurnOver:"trackTurnOver",
oneTurnOver:"oneTurnOver",
vipStartTurn:"vipStartTurn"
}
static svgaSource = [
{src:'https://yun.duiba.com.cn/spark/assets/dedd4a9ac243add7a6d98832169d7cf9619b8ace.svga',pool:'vipWhite'}, //白色vip轨迹
{src:'https://yun.duiba.com.cn/spark/assets/408c7fef572cb91d72c61d6683fd58195bdb0d6b.svga',pool:'vipOrigen'}, //橙色vip轨迹
{src:'https://yun.duiba.com.cn/spark/assets/73ac94bd65aac58ae9aa579c5c002c2580ba1b4f.svga',pool:'vipRed'}, //红色vip轨迹
{src:'https://yun.duiba.com.cn/spark/assets/262dc08ac3d0854dd0a476ba8840831598d7f233.svga',pool:'vipBlue'}, //蓝色vip轨迹
{src:'https://yun.duiba.com.cn/spark/assets/1fd4eb658813a6662186ab6d867e80b5ea7d2860.svga',pool:'Wait'}, //等待尾气
{src:'https://yun.duiba.com.cn/spark/assets/64ce8e739f9fdc1718fb03401d170f413755ade5.svga',pool:'trailGas'}, //普通车转弯轨迹
{src:'https://yun.duiba.com.cn/spark/assets/753d6cd47b35a6da2065e902dfaa7820e7df5865.svga',pool:'turnFailed'} //右转弯失败
]
static svgaPool={
vipWhite:'',
vipOrigen:'',
vipRed:'',
vipBlue:'',
Wait:'',
trailGas:'',
turnFailed:''
};
static vipText = [
'智能安全模式',
'沉浸式座舱',
'宽敞舒适空间',
'动力强油耗低'
]
static levelInitTrackerTime = {
1:[30,100],
2:[30,100],
3:[30,100],
4:[30,100],
5:[30,100],
6:[30,90],
7:[30,90],
8:[30,90],
9:[30,90],
10:[30,90],
11:[40,60],
12:[40,60],
13:[40,60],
14:[40,60],
15:[40,60],
16:[40,50],
17:[40,50],
18:[40,50],
19:[40,50],
20:[40,50]
}
}
export function LoadSvgaToCache(callback, arr) {
let count = 0;
let countAll = arr.length;
// console.log(countAll)
if (!countAll) callback(true);
let mark = true;
for (let i = 0; i < countAll; i++) {
SvgaParser.loadSvga(
arr[i].src,
(v) => {
Ins.svgaPool[arr[i].pool] = v;
},
(err) => {
mark = false;
console.log(err);
}
)
if (++count == countAll) callback(mark);
}
}
export function loadSvgaList() {
console.log("开始加载svga资源")
let list = [];
for (let key in Ins.svgaSource) {
list.push(Ins.svgaSource[key]);
}
// console.log(list)
let p = new Promise((resolve, reject) => {
LoadSvgaToCache((s) => {
if (s) {
console.log("svgapool",Ins.svgaPool);
resolve()
} else {
reject();
}
}, list /*, resPath + name*/ )
})
Sound
return p;
}
export class vector {
x;
y;
constructor(x, y) {
this.x = x||0;
this.y = y||0;
}
sub(v) {
return new vector(this.x-v.x,this.y-v.y);
}
dot(v) {
return this.x * v.x + this.y * v.y;
}
}
export class OBB {
centerPoint;
extents;
axes;
w;
h;
rotation;
constructor(cenerPoint,w,h,r){
let radius = r*Math.PI/180;
this.centerPoint = cenerPoint;
this.extents = [w/2,h/2];
this.axes = [new vector(Math.cos(radius),Math.sin(radius)),new vector(-1*Math.sin(radius),Math.cos(radius))];
this.w=w;
this.h=h;
this.rotation = r;
}
getProjectionRadius(axis) {
return this.extents[0] * Math.abs(axis.dot(this.axes[0]))+this.extents[1]*Math.abs(axis.dot(this.axes[1]));
}
}
export function detectorOBBvsOBB(OBB1, OBB2) {
var nv = OBB1.centerPoint.sub(OBB2.centerPoint);
var axisA1 = OBB1.axes[0];
if (OBB1.getProjectionRadius(axisA1) + OBB2.getProjectionRadius(axisA1) <= Math.abs(nv.dot(axisA1))) return false;
var axisA2 = OBB1.axes[1];
if (OBB1.getProjectionRadius(axisA2) + OBB2.getProjectionRadius(axisA2) <= Math.abs(nv.dot(axisA2))) return false;
var axisB1 = OBB2.axes[0];
if (OBB1.getProjectionRadius(axisB1) + OBB2.getProjectionRadius(axisB1) <= Math.abs(nv.dot(axisB1))) return false;
var axisB2 = OBB2.axes[1];
if (OBB1.getProjectionRadius(axisB2) + OBB2.getProjectionRadius(axisB2) <= Math.abs(nv.dot(axisB2))) return false;
return true;
}
/**生成范围内的随机数 */
export function getRandomValue(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
// 二次贝塞尔,用于做曲线运动
export function bezier(t, p0, p1, p2) {
// (1-t)^2 P0 + 2(1-t)tP1+ t^2P2
return Math.pow(1 - t, 2) * p0 + 2 * (1 - t) * t * p1 + Math.pow(t, 2) * p2;
}
\ No newline at end of file
import { Ins } from "./Ins";
export class LoadSvga {
static LoadSvgaToCache(callback, arr) {
let count = 0;
let countAll = arr.length;
// console.log(countAll)
if (!countAll) callback(true);
let mark = true;
// console.log("aaaa",arr);
for (let i = 0; i < countAll; i++) {
// SvgaParser.loadSvga(
// arr[i].src,
// (v) => {
// Ins.svgaPool[arr[i].pool]=v;
// },
// (err) => {
// mark = false;
// console.log(err);
// }
// )
if (++count == countAll) callback(mark);
}
}
static loadSvgaList() {
console.log("开始加载lottie资源")
let list = [];
for (let key in this.svgaSource) {
list.push(resList[key]);
}
console.log(list)
let p = new Promise((resolve, reject) => {
LoadSvgaToCache((s) => {
if (s) {
resolve()
} else {
reject();
}
}, list /*, resPath + name*/ )
})
return p;
}
}
export function initLottie(callback, arr) {
let count = 0;
let countAll = arr.length;
console.log(countAll)
if (!countAll) callback(true);
let mark = true;
for (let i = 0; i < countAll; i++) {
let textureJson = arr[i].json;
FYGE.GlobalLoader.loadImage((s, image) => {
if (s) {
FYGE.createTextureSheet(new FYGE.BaseTexture(image), textureJson);
} else {
mark = false
}
if (++count == countAll) callback(mark);
}, arr[i]["imgUrl"])
}
}
export function initLottieList(resList) {
console.log("开始加载lottie资源")
let list = [];
for (let key in resList) {
list.push(resList[key]);
}
console.log(list)
let p = new Promise((resolve, reject) => {
8
initLottie((s) => {
if (s) {
resolve()
} else {
reject();
}
}, list /*, resPath + name*/ )
})
return p;
}
\ No newline at end of file
import { Sprite, TextField, Tween } from "fyge";
export class ScoreTips extends Sprite{
score = 0;
scoreLabel;
constructor(){
super();
}
init(val,x,y){
this.score = val;
this.x = x;
this.y = y;
this.scoreLabel = new TextField();
this.scoreLabel.size = 32;
this.scoreLabel.strokeColor = "#66ccff"
this.scoreLabel.stroke = 2;
this.scoreLabel.text = '+'+this.score;
this.addChild(this.scoreLabel);
this.scoreLabel.x = -this.scoreLabel.textWidth*0.5;
this.scoreLabel.y = -this.scoreLabel.textHeight*0.5;
Tween.get(this).to({y:y-50},500).call(()=>{
if(this&&this.parent){
this.parent.removeChild(this);
}
})
}
}
\ No newline at end of file
import { Sprite, TextureCache, Tween } from "fyge";
export class Smoke extends Sprite{
smokeImg;
constructor(x,y,r){
super();
this.x = x;
this.y = y;
if(r){
this.rotation = r;
}
this.init();
}
init(){
this.smokeImg = new Sprite(TextureCache["13ef2773-e156-4bef-8730-37f3a0578a22"]);
this.addChild(this.smokeImg);
this.smokeImg.x = -this.smokeImg.width*0.5;
this.smokeImg.y = -this.smokeImg.height*0.5;
// this.rotation = 180;
// this.smokeImg.scaleX = this.smokeImg.scaleY = 0.5;
Tween.get(this).to({alpha:0},300).call(()=>{
if(this&&this.parent){
this.parent.removeChild(this);
}
})
}
}
\ No newline at end of file
/**
* 根据路径记录
*/
export const soundHash={};
export function cusPlaySound(src, loop = false) {
return playSound(src, loop);
}
/**
* 提前加载音频
* @param type
*/
export function preloadSound(src) {
soundHash[src] = new Howl({
src: src,
preload: true,
});
}
export function playSound(src, loop = false) {
let sound;
//循环的,且有缓存,取缓存的
if (soundHash[src] && loop) sound = soundHash[src]
//没有就新建
if (!sound) sound = new Howl({ src: [src], autoplay: false, loop });
//记录下,方便停止
soundHash[src] = sound;
//不循环删除缓存
if (!loop) sound.on('stop', function () { delete soundHash[src] });
//播放
sound.play();
//返回一个,可以自行控制
return sound;
}
export function stopSound(src) {
if (soundHash[src]) soundHash[src].stop();
}
export function stopAllSound() {
for (let key in soundHash) soundHash[key].stop();
}
export function playAllSound() {
for (let key in soundHash) soundHash[key].play();
}
//设置隐藏属性和改变可见属性的事件的名称
let hidden, visibilityChange;
if (typeof document.hidden !== 'undefined') {
hidden = 'hidden';
visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
hidden = 'msHidden';
visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
hidden = 'webkitHidden';
visibilityChange = 'webkitvisibilitychange';
}
const handleVisibilityChange = (e) => {
if (document.visibilityState == "visible") {
playAllSound();
console.log("网页显示")
}
else if (document.visibilityState == "hidden") {
stopAllSound()
console.log("网页隐藏")
}
};
document.addEventListener(
visibilityChange,
handleVisibilityChange,
false
);
window.onbeforeunload = function () {
//发接口
}
\ No newline at end of file
import {
Event,
Sprite,
TextureCache,
WidgetBase,
injectProp,
TextField,
TEXT_ALIGN,
Shape,
MouseEvent,
Point,
GDispatcher,
Tween,
MovieClip
} from "fyge";
import {
Car
} from "./car";
import {
GameStage
} from "./GameStage";
import {
Ins,
getRandomValue,
OBB,
vector,
detectorOBBvsOBB,
loadSvgaList
} from "./Ins";
import * as SvgaParser from "svga-parser";
import { LoadSvga } from "./LoadSvga";
import { ScoreTips } from "./ScoreTips";
export class CornerRacingWidget extends WidgetBase {
gameBg;
gameGroup;
gameUi;
lastLevelLabel;
nextLevelLabel;
scoreLabel;
levelProgress;
levelProgressBg;
curScore;
curLevel;
maxCarCnt = 10;
goneCarCnt;
curPlayerCarL;
playerCarInitOver = false;
isChangeDir = false;
gameState = 0; //游戏状态,0:暂停,1:运行
trackTime1; //赛道1的经过时间
trackTime2; //赛道2的经过时间
trackInitTime1; //赛道1的出车时间
trackInitTime2; //赛道2的出车时间
randomInitTime; //随机出车的时间段
trackCarArr1 = []; //赛道1的车辆
trackCarArr2 = []; //赛道2的车辆
turningCar = []; //当前在拐弯的玩家车辆
playerCarArr = []; //玩家车辆组
levelInfo = [];
constructor() {
super();
this.addEventListener(Event.ADDED_TO_STAGE, this.addToViewPort, this)
this.addEventListener(Event.REMOVED_FROM_STAGE, this.removeFromViewPort, this);
}
addToViewPort() {
this.removeEventListener(Event.ADDED_TO_STAGE, this.addToViewPort, this)
// setTimeout(() => {
// // this.initUi();
// this.dispatchOutEvent('initOver')
// }, 1500)
}
removeFromViewPort() {
// this.parent.removeChild(this);
// for(let i=0;i<this.children.length;i++){
// this.removeChild(this.children[i]);
// i--;
// }
if(this&&this.parent)
this.parent.removeChild(this);
// GDispatcher.dispatchEvent(Event.REMOVED_FROM_STAGE)
// console.log("ewwefwefwefewf");
this.removeEventListener(Event.REMOVED_FROM_STAGE, this.removeFromViewPort, this);
this.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
// this.stage.removeEventListener(MouseEvent.MOUSE_DOWN, this.carTurning, this);
GDispatcher.removeEventListener(Ins.msg.trackTurnOver, this.tackTurnOverHandler, this);
GDispatcher.removeEventListener(Ins.msg.vipStartTurn,this.vipCarTurning,this);
}
initUi() {
Ins.stageW = this.stage.viewRect.width;
Ins.stageH = this.stage.viewRect.height;
// console.log("舞台高",Ins.stageh)
Ins.normalCarArr = this.props.normalCar;
Ins.vipCarArr = this.props.vipCar;
this.curPlayerCarL = true;
this.trackTime1 = 0;
this.trackTime2 = 0;
this.randomInitTime = [30, 80];
this.trackInitTime1 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.trackInitTime2 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.trackTime1 = this.trackInitTime1 - 1;
this.trackTime2 = this.trackInitTime2 - 1
this.levelInfo = this.props.levelInfo;
// console.log(Ins.normalCarArr, Ins.vipCarArr)
// SvgaParser.loadSvga(
// "https://yun.duiba.com.cn/spark/assets/46b86276f0d04b34d50d98a852b9ee9ffd0d6f03.svga",
// (v) => {
// this.addChild(new MovieClip(v));
// },
// (err) => {
// console.log(err)
// }
// )
if(this.curLevel>Ins.maxLevel){
/**通关 */
this.gameClear();
return;
}
// console.log("insss",Ins.trackCarArr1)
for (let i = 0; i < Ins.trackCarArr1.length; i++) {
Ins.trackCarArr1[i].parent.removeChild(Ins.trackCarArr1[i]);
Ins.trackCarArr1.splice(i, 1);
i--;
}
for (let i = 0; i < Ins.trackCarArr2.length; i++) {
Ins.trackCarArr2[i].parent.removeChild(Ins.trackCarArr2[i]);
Ins.trackCarArr2.splice(i, 1);
i--;
}
for (let i = 0; i < this.playerCarArr.length; i++) {
this.gameGroup.removeChild(this.playerCarArr[i]);
this.playerCarArr.splice(i, 1);
i--;
}
for (let i = 0; i < this.turningCar.length; i++) {
this.gameGroup.removeChild(this.turningCar[i]);
this.turningCar.splice(i, 1);
i--;
}
this.goneCarCnt = 0;
this.initConfig();
this.initGameMap();
this.initGameUi();
this.initNewLevel();
this.addEvent();
this.start();
}
initConfig() {
this.curLevel = 1;
this.curScore = 0;
this.goneCarCnt = 0;
}
initGameMap() {
this.gameGroup = new Sprite();
this.addChild(this.gameGroup);
this.gameBg = new Sprite(TextureCache["807ec201-9341-40f4-b32a-721c337ad81c"]);
this.gameGroup.addChild(this.gameBg);
Ins.effectLayer = new Sprite();
this.gameGroup.addChild(Ins.effectLayer);
}
initGameUi() {
this.gameUi = new Sprite(TextureCache["c2df98d5-8fa6-4e17-a3bd-9440be05f33d"]);
this.addChild(this.gameUi);
this.gameUi.x = Ins.stageW * 0.5 - this.gameUi.width * 0.5;
this.gameUi.y = 52;
//关卡标识初始化
{
this.lastLevelLabel = new TextField();
this.gameUi.addChild(this.lastLevelLabel);
this.nextLevelLabel = new TextField();
this.gameUi.addChild(this.nextLevelLabel);
this.lastLevelLabel.size = this.nextLevelLabel.size = 24;
this.lastLevelLabel.textWidth = this.nextLevelLabel.textWidth = 80;
this.lastLevelLabel.textAlign = this.nextLevelLabel.textAlign = TEXT_ALIGN.CENTER;
this.lastLevelLabel.text = this.curLevel >= Ins.maxLevel ? '最终关' : '第' + this.curLevel + '关';
this.nextLevelLabel.text = (this.curLevel + 1) >= Ins.maxLevel ? '最终关' : '第' + (this.curLevel + 1) + '关';
this.lastLevelLabel.x = 26;
this.lastLevelLabel.y = 32;
this.nextLevelLabel.x = 484;
this.nextLevelLabel.y = 32;
}
//关卡分数初始化
{
this.scoreLabel = new TextField();
this.gameUi.addChild(this.scoreLabel);
this.scoreLabel.textAlign = TEXT_ALIGN.CENTER;
this.scoreLabel.size = 24;
this.scoreLabel.textWidth = 304;
this.scoreLabel.text = '分数:' + this.curScore + '分';
this.scoreLabel.x = 145;
this.scoreLabel.y = 83;
}
//关卡进度条初始化
{
this.levelProgressBg = new Sprite(TextureCache["e1308cff-8f0c-4824-bd1d-b7a1a69760a6"]);
this.gameUi.addChild(this.levelProgressBg);
this.levelProgressBg.x = this.gameUi.width * 0.5 - this.levelProgressBg.width * 0.5 - 5;
this.levelProgressBg.y = 23;
this.levelProgress = new Sprite(TextureCache["59a1460a-cfa9-4f10-a3ed-00978c2c8a5e"]);
this.levelProgress.y = 1.5;
this.levelProgress.x = 2;
this.levelProgressBg.addChild(this.levelProgress);
let mask = new Shape();
mask.beginFill(66, 0.5);
mask.drawRoundedRect(0, 0, this.levelProgress.width, this.levelProgress.height, 30, 30, 30, 30);
mask.endFill();
this.levelProgressBg.addChild(mask);
mask.x = 2;
mask.y = 1.5;
this.levelProgress.mask = mask;
this.levelProgress.anchorY = this.levelProgress.height * 0.5;
let scale = this.goneCarCnt / this.maxCarCnt;
this.levelProgress.x = scale * this.levelProgress.width - this.levelProgress.width + 2;
}
}
addEvent() {
this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, this.carTurning, this);
GDispatcher.addEventListener(Ins.msg.trackTurnOver, this.tackTurnOverHandler, this);
GDispatcher.addEventListener(Ins.msg.vipStartTurn,this.vipCarTurning,this);
}
onEnterFrame() {
// console.log("11111111111")
if (this.gameState != 1) return;
this.track1();
this.track2();
this.updateCar();
}
initNewLevel() {
console.log("初始化时间",Ins.levelInitTrackerTime[this.curLevel])
this.randomInitTime = Ins.levelInitTrackerTime[this.curLevel];
this.trackInitTime1 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.trackInitTime2 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.trackTime1 = this.trackInitTime1 - 1;
this.trackTime2 = this.trackInitTime2 - 1
Ins.speedY = 10+Math.floor(this.curLevel/4);
Ins.speedX = 6;
this.isChangeDir = false;
this.curPlayerCarL = true;
// this.gameGroup.y = Ins.stageH - this.gameBg.height;
this.gameGroup.y = (document.body.clientHeight - 1624)*0.5+200
Ins.effectLayer.y = -(document.body.clientHeight - 1624)*0.5-200;
this.maxCarCnt = this.levelInfo[this.curLevel-1].num;
this.setUi();
this.initPlayerCar();
}
vipCarTurning(){
if(this.gameState == 0) return;
Ins.canTouch = false;
let car = this.playerCarArr.shift();
this.turningCar.push(car);
for (let i = 0; i < this.playerCarArr.length; i++) {
if (i == 0) {
this.playerCarArr[i].setDistance(0);
} else {
if (this.curPlayerCarL) {
this.playerCarArr[i].setDistance(this.playerCarArr[0].x - this.playerCarArr[i].x);
} else {
this.playerCarArr[i].setDistance(this.playerCarArr[i].x - this.playerCarArr[0].x);
}
}
this.playerCarArr[i].changeState(Ins.CarState.goStage);
}
car.changeState(Ins.CarState.turning);
}
carTurning() {
if (this.gameState == 0 || !Ins.canTouch) return;
Ins.canTouch = false;
if (!this.playerCarArr[0].isVip) {
let car = this.playerCarArr.shift();
this.turningCar.push(car);
for (let i = 0; i < this.playerCarArr.length; i++) {
// this.playerCarArr[i].setDistance(this.playerCarArr[i].distance - car.x)
if (i == 0) {
this.playerCarArr[i].setDistance(0);
} else {
if (this.curPlayerCarL) {
this.playerCarArr[i].setDistance(this.playerCarArr[0].x - this.playerCarArr[i].x);
} else {
this.playerCarArr[i].setDistance(this.playerCarArr[i].x - this.playerCarArr[0].x);
}
}
this.playerCarArr[i].changeState(Ins.CarState.goStage);
}
car.changeState(Ins.CarState.turning);
} else {
}
}
/**复活 */
resurrection() {
console.log("复活嘛", this.turningCar, this.playerCarArr);
let car = this.turningCar.pop();
this.playerCarArr.unshift(car);
for (let i = 0; i < this.playerCarArr.length; i++) {
let car = this.playerCarArr[i];
if (this.curPlayerCarL) {
if (i < 1) {
car.x = -100;
car.setDistance(0);
} else {
car.x = this.playerCarArr[i - 1].x - (car.carImg.height + 60);
car.setDistance(this.playerCarArr[0].x - car.x);
}
car.y = 820;
car.rotation = 90;
} else {
if (i < 1) {
car.x = Ins.stageW + 100;
car.setDistance(0);
} else {
car.x = this.playerCarArr[i - 1].x + (car.carImg.height + 60);
car.setDistance(car.x - this.playerCarArr[0].x);
}
car.y = 2422;
car.rotation = -90;
}
car.changeState(Ins.CarState.goStage);
}
this.gameState = 1;
}
/**游戏结束 */
gameOver() {
console.log("游戏结束");
this.gameState = 0;
Ins.canTouch = false;
Tween.get(this).wait(700).call(()=>{this.dispatchOutEvent('gameOver',{score:this.curScore,level:this.curLevel});})
// setTimeout(() => {
// this.resurrection();
// }, 700);
}
/**新的一关 */
newlevel() {
this.curLevel++;
if(this.curLevel>Ins.maxLevel){
/**通关 */
this.gameClear();
return;
}
for (let i = 0; i < Ins.trackCarArr1.length; i++) {
this.gameGroup.removeChild(Ins.trackCarArr1[i]);
Ins.trackCarArr1.splice(i, 1);
i--;
}
for (let i = 0; i < Ins.trackCarArr2.length; i++) {
this.gameGroup.removeChild(Ins.trackCarArr2[i]);
Ins.trackCarArr2.splice(i, 1);
i--;
}
for (let i = 0; i < this.playerCarArr.length; i++) {
this.gameGroup.removeChild(this.playerCarArr[i]);
this.playerCarArr.splice(i, 1);
i--;
}
for (let i = 0; i < this.turningCar.length; i++) {
this.gameGroup.removeChild(this.turningCar[i]);
this.turningCar.splice(i, 1);
i--;
}
this.goneCarCnt = 0;
this.initNewLevel();
}
gameClear(){
this.gameState = 0;
Ins.canTouch = false;
this.dispatchOutEvent("gameClear",{score:this.curScore,level:this.curLevel})
}
/**更新车辆 */
updateCar() {
for (let i = 0; i < Ins.trackCarArr1.length; i++) {
if (this.curPlayerCarL) {
for (let j = 0; j < this.turningCar.length; j++) {
let rect1 = Ins.trackCarArr1[i];
let rect2 = this.turningCar[j];
let obb1 = new OBB(new vector(rect1.x, rect1.y), rect1.carImg.width, rect1.carImg.height+5, rect1.rotation);
let obb2 = new OBB(new vector(rect2.x, rect2.y), rect2.carImg.width, rect2.carImg.height+5, rect2.rotation);
if (detectorOBBvsOBB(obb1, obb2)) {
this.turningCar[j].turnFailed();
this.gameOver();
return;
}
}
}
if (Ins.trackCarArr1[i].updateSelf()) {
this.gameGroup.removeChild(Ins.trackCarArr1[i]);
Ins.trackCarArr1.splice(i, 1);
i--;
}
}
for (let i = 0; i < Ins.trackCarArr2.length; i++) {
if (!this.curPlayerCarL) {
for (let j = 0; j < this.turningCar.length; j++) {
let rect1 = Ins.trackCarArr2[i];
let rect2 = this.turningCar[j];
let obb1 = new OBB(new vector(rect1.x, rect1.y), rect1.carImg.width, rect1.carImg.height+5, rect1.rotation);
let obb2 = new OBB(new vector(rect2.x, rect2.y), rect2.carImg.width, rect2.carImg.height+2, rect2.rotation);
if (detectorOBBvsOBB(obb1, obb2)) {
this.turningCar[j].turnFailed();
this.gameOver();
return;
}
}
}
if (Ins.trackCarArr2[i].updateSelf()) {
this.gameGroup.removeChild(Ins.trackCarArr2[i]);
Ins.trackCarArr2.splice(i, 1);
i--;
}
}
if (this.playerCarInitOver) {
for (let i = 0; i < this.playerCarArr.length; i++) {
this.playerCarArr[i].updateSelf(i);
}
}
for (let i = 0; i < this.turningCar.length; i++) {
this.turningCar[i].updateSelf();
if (this.turningCar[i].turnOver) {
if (this.turningCar[i].dir == 0) {
Ins.trackCarArr1.push(this.turningCar[i]);
} else if (this.turningCar[i].dir == 1) {
Ins.trackCarArr2.push(this.turningCar[i]);
}
this.turningCar.splice(i, 1);
i--;
}
}
}
/**赛道1的更新 */
track1() {
this.trackTime1++;
if (this.trackTime1 % this.trackInitTime1 == 0) {
this.trackTime1 = 0;
this.trackInitTime1 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.initTrackCar(1);
}
}
/**赛道2的更新 */
track2() {
this.trackTime2++;
if (this.trackTime2 % this.trackInitTime2 == 0) {
this.trackTime2 = 0;
this.trackInitTime2 = getRandomValue(this.randomInitTime[0], this.randomInitTime[1]);
this.initTrackCar(2);
}
}
initTrackCar(trackIndex) {
let car = new Car();
this.gameGroup.addChildAt(car,2);
let x = 0;
let y = 0;
let dir = 0;
if (trackIndex == 1) {
x = 302;
y = -100;
dir = 3;
Ins.trackCarArr1.push(car);
} else {
x = 451;
y = 3348;
dir = 2;
Ins.trackCarArr2.push(car);
}
let data = {
type: 0,
isVip: false,
x: x,
y: y,
dir: dir
}
car.initUi(data)
}
/**生成一组玩家车辆 */
initPlayerCar() {
let randomIndex = Math.floor(Math.random()*this.maxCarCnt*0.5);
for (let i = 0; i < this.maxCarCnt * 0.5; i++) {
if(i==randomIndex){
this.initOnePlayerCar(true);
}else{
this.initOnePlayerCar(false);
}
}
// console.log(this.playerCarArr);
this.playerCarInitOver = true;
}
/**生成一个玩家车辆 */
initOnePlayerCar(isVip) {
let car = new Car();
this.gameGroup.addChild(car);
let x = -100;
let y = 0;
let dir = 0;
let isLast = false;
if (this.curPlayerCarL) {
y = 820;
dir = 0;
} else {
y = 2422;
dir = 1;
}
if (this.playerCarArr.length >= this.maxCarCnt * 0.5 - 1) {
isLast = true;
}
let data = {
type: 1,
isVip: isVip,
x: x,
y: y,
dir: dir,
isLast: isLast
}
car.initUi(data)
if (this.curPlayerCarL) {
if (this.playerCarArr.length < 1) {
car.x = -100;
car.setDistance(0);
} else {
car.x = this.playerCarArr[this.playerCarArr.length - 1].x - (car.carImg.height + 60);
car.setDistance(this.playerCarArr[0].x - car.x);
}
} else {
if (this.playerCarArr.length < 1) {
car.x = Ins.stageW + 100;
car.setDistance(0);
} else {
car.x = this.playerCarArr[this.playerCarArr.length - 1].x + (car.carImg.height + 60);
car.setDistance(car.x - this.playerCarArr[0].x);
}
}
this.playerCarArr.push(car);
}
/**当前赛道玩家车辆转弯结束 */
tackTurnOverHandler(e) {
if (e.data.isVip) {
let scoreTips = new ScoreTips();
this.gameGroup.addChild(scoreTips);
scoreTips.init(2,e.data.x,e.data.y-50)
this.curScore += 2;
} else {
let scoreTips = new ScoreTips();
this.gameGroup.addChild(scoreTips);
scoreTips.init(1,e.data.x,e.data.y-50)
this.curScore += 1;
}
this.goneCarCnt++;
this.setUi();
if (this.goneCarCnt >= this.maxCarCnt) {
/**过关 */
if(this.curLevel>(Ins.maxLevel-1)){
/**通关 */
this.gameClear();
return;
}
this.dispatchOutEvent("clearLevel",{score:this.curScore,level:this.curLevel});
// setTimeout(() => {
// this.newlevel()
// },1500)
} else if (!this.isChangeDir && this.goneCarCnt >= this.maxCarCnt * 0.5) {
Ins.canTouch = false;
this.isChangeDir = true;
this.curPlayerCarL = !this.curPlayerCarL;
Tween.get(this).wait(500).call(()=>{this.changeGameGroup()})
}
}
changeGameGroup(){
if (this.curPlayerCarL) {
// console.log("设置y",document.body.clientHeight);
let stageH = document.body.clientHeight;
Tween.get(this.gameGroup).to({
y: (stageH - 1624)*0.5+200
}, 600).call(() => {
Ins.effectLayer.y = Math.abs((stageH - 1624)*0.5+200);
// Ins.canTouch = false;
this.initPlayerCar();
})
} else {
let stageH = document.body.clientHeight;
Tween.get(this.gameGroup).to({
y: (Ins.stageH - this.gameBg.height)
}, 600).call(() => {
Ins.effectLayer.y = this.gameBg.height - Ins.stageH;
// Ins.canTouch = true;
this.initPlayerCar();
})
}
}
setUi() {
let maxScore = 0;
let totalCar = 0;
for(let i=0;i<this.curLevel;i++){
totalCar += this.levelInfo[i].num;
}
// console.log("管卡信息",this.curLevel,this.levelInfo,totalCar);
maxScore = totalCar+2*this.curLevel;
this.scoreLabel.text = '分数:' + this.curScore + '分'+'/'+maxScore+'分';
let scale = this.goneCarCnt / this.maxCarCnt;
this.levelProgress.x = scale * this.levelProgress.width - this.levelProgress.width + 2;
this.lastLevelLabel.text = this.curLevel >= Ins.maxLevel ? '最终关' : '第' + this.curLevel + '关';
this.nextLevelLabel.text = (this.curLevel + 1) >= Ins.maxLevel ? '最终关' : '第' + (this.curLevel + 1) + '关';
}
async onEvent(type, payload) {
switch (type) {
case 'init':
this.initUi();
break;
case 'reset':
// this.reset();
break;
case 'start':
injectProp(this, payload);
// console.log("a",payload);
this.start();
break;
case 'pause':
// this.pause();
break;
case 'resume':
// this.start();
break;
case 'stop':
// this.stop();
break;
case 'assetsComplete':
await loadSvgaList();
this.dispatchOutEvent("loadOver");
break;
case 'resurrection':
this.resurrection();
break;
case 'nextLevel':
this.newlevel();
break;
case 'remove':
this.removeFromViewPort();
break;
default:
console.log(type);
}
}
start() {
this.gameState = 1;
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020/9/19.
*/
import {Sprite, Point, TextureCache} from 'fyge'
export class RedPack extends Sprite {
constructor() {
super();
this._pos = new Point();
this._globalPos = new Point();
}
get pos() {
return this._pos;
}
get globalPos() {
return this._globalPos;
}
init(data) {
this.data = data;
const {source, initPos, type} = data;
this.type = type;
this.texture = TextureCache[source];
this.x = this._pos.x = initPos;
this.y = this._pos.y = -this.height;
}
schedule() {
const {width, height, data: {angleOffset, speed}} = this;
let radian = (angleOffset + 90) * Math.PI / 180;
let speedX = Math.cos(radian) * speed;
let speedY = Math.sin(radian) * speed;
this.x = this._pos.x += speedX;
this.y = this._pos.y += speedY;
this.parent.localToGlobal(this._pos, this._globalPos);
const {_globalPos: {x, y}} = this;
if (y < -height || y > this.stage.stageHeight) {
return true;
}
if (angleOffset > 0) {
if (x < -width) {
return true;
}
} else if (angleOffset < 0) {
if (x > this.stage.width) {
return true;
}
}
}
}
/**
* Created by rockyl on 2020/9/19.
*/
import {RedPack} from "./RedPack";
import {WidgetBase, ObjectPool, Event, MouseEvent, injectProp, TextureCache} from "fyge";
const PoolName = 'pack';
ObjectPool.registerPool(PoolName, function () {
return new RedPack();
}, function (redPack, data) {
redPack.init(data);
});
export class RedPackRainWidget extends WidgetBase {
_status;
_intervalCounting;
constructor() {
super();
this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
this.addEventListener(MouseEvent.CLICK, this.onTap, this);
}
onEvent(type, payload) {
switch (type) {
case 'reset':
this.reset();
break;
case 'start':
injectProp(this, payload);
// console.log("aa",payload)
this.start();
break;
case 'pause':
this.pause();
break;
case 'resume':
this.start();
break;
case 'stop':
this.stop();
break;
default:
console.log(type);
}
}
reset() {
this.pause();
while (this.children.length > 0) {
this.recycleOne(this.children[0]);
}
}
start() {
console.log(TextureCache)
console.log("props",this.props);
this._status = 1;
this._intervalCounting = this.props.intervalFrames;
}
pause() {
this._status = 0;
}
stop() {
this.reset();
}
recycleOne(child) {
this.removeChild(child);
ObjectPool.recycleObject(PoolName, child);
}
dropOne() {
const {assets, angleOffset, speedRange, initPosRange} = this.props;
console.log("Ass",assets);
let r = Math.random();
let targetAssetIndex;
for (let i = 0, li = assets.length; i < li; i++) {
const asset = assets[i];
r -= asset.ratio;
if (r <= 0) {
targetAssetIndex = i;
break;
}
}
let pack = ObjectPool.getObject(PoolName, {
type: targetAssetIndex,
source: assets[targetAssetIndex].source,
angleOffset,
speed: Math.random() * (speedRange.max - speedRange.min) + speedRange.min,
initPos: Math.random() * (initPosRange.max - initPosRange.min) + initPosRange.min,
});
this.addChild(pack);
};
onEnterFrame() {
if (this._status === 1) {
this._intervalCounting--;
if (this._intervalCounting <= 0) {
this._intervalCounting = this.props.intervalFrames;
this.dropOne();
}
for (let i = 0, li = this.children.length; i < li; i++) {
const child = this.children[i];
if (child.schedule()) {
i--;
li--;
this.recycleOne(child);
}
}
}
}
onTap(event) {
if (event.currentTarget instanceof RedPack) {
const {type, pos, globalPos} = event.currentTarget;
let payload = {type, pos, globalPos};
this.recycleOne(event.currentTarget);
this.dispatchOutEvent('hit', payload);
}
}
}
import {RedPackRainWidget} from "./RedPackRain";
import {CornerRacingWidget} from "./CornerRacing";
/**
* @type 3
* @name 红包雨
* @desc 红包雨模块的工厂方法
*/
export function RedPackRain() {
return new RedPackRainWidget();
}
/**
* @type 3
* @name 弯道赛车
* @desc 弯道赛车模块的工厂方法
*/
export function CornerRacing() {
return new CornerRacingWidget();
}
{
"id": "games",
"name": "游戏模块包",
"desc": "实现了各种游戏模块",
"config": {
"RedPackRain": {
"props": [
{
"name": "assets",
"alias": "素材UUID组",
"type": "string",
"default": [
{
"source": "a6b3f654-2c26-434a-a873-aabc12cd1d80",
"ratio": 1
}
]
},
{
"name": "angleOffset",
"alias": "角度偏移量",
"type": "number",
"default": 0
},
{
"name": "speedRange",
"alias": "速度范围",
"type": "range",
"default": "1,10",
"type_config": {
"min": 1,
"max": 50
}
},
{
"name": "initPosRange",
"alias": "初始坐标范围",
"type": "range",
"default": "0,750"
},
{
"name": "intervalFrames",
"alias": "红包生成间隔帧数",
"type": "number",
"default": "10"
}
],
"assets": [
{
"name": "红包",
"url": "//yun.duiba.com.cn/aurora/59ba44954450d7493ef5c630070808496c242f11.png",
"uuid": "a6b3f654-2c26-434a-a873-aabc12cd1d80",
"ext": ".png"
}
],
"events": {
"in": {
"reset": {
"alias": "重置"
},
"start": {
"alias": "开始",
"data": {
"assets": "素材列表[{source,ratio}]",
"speedRange": "速度范围{min,max}",
"initPosRange": "初始坐标范围{min,max}",
"angleOffset": "角度偏移量",
"intervalFrames": "掉落帧间隔"
}
},
"pause": {
"alias": "暂停"
},
"resume": {
"alias": "恢复"
},
"stop": {
"alias": "停止"
}
},
"out": {
"hit": {
"alias": "击中红包",
"data": {
"type": "类型",
"pos": "坐标",
"globalPos": "全局坐标"
}
}
}
}
}
}
}
/**
* Created by rockyl on 2020/10/13.
*
* @id porjectx
* @name 星速台相关的过程
* @desc 星速台相关的过程
*/
/**
* @type 1
* @name 获取token
* @desc 获取星速台防刷token
* @outputs {success:'成功:响应内容', failed:'失败:错误信息'}
*/
export function getPxToken() {
return new Promise(resolve => {
if (location.href.indexOf('.com.cn/projectx') < 0) { //本地环境测试
resolve({
type: 'success',
payload: {
token: 'test_token'
}
})
} else {
window.getPxToken((e, token) => {
if (e) {
resolve({
type: 'failed',
payload: e,
})
} else if (!token) {
resolve({
type: 'failed',
payload: new Error('empty token')
})
} else {
resolve({
type: 'success',
payload: {
token
}
})
}
});
}
})
}
/**
* Created by rockyl on 2020/8/26.
*
* @id ui
* @name 一些UI组件
* @desc 一些UI组件
*/
/**
* @type 3
* @name 下拉选择器
* @desc 下拉选择器,传入键值对options,例:{aaa:'哈哈',bbb:'嘿嘿'}即生成两个下拉选项}
*/
export class Select {
render() {
const {options, value, onValueChange} = this.props;
return (
<select value={value} onChange={e => onValueChange(e.target.value)}>
{Object.keys(options).map(key => (
<option key={key} value={key}>{options[key]}</option>
))}
</select>
)
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
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