Commit 43a22912 authored by Master Q's avatar Master Q

先这样吧

parent 2c6d0278
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"name": "GameRes" "name": "GameRes"
}, },
{ {
"keys": "back.png,fkingCar.png,obstack1.png,obstack2.png,obstack3.png,背景移动元素.svga,跑道.svga,路架子.svga", "keys": "0.png,1.png,2.png,3.png,4.png,5.png,6.png,7.png,8.png,9.png,back.png,countdownback.png,fkingCar.png,obstack1.png,obstack2.png,obstack3.png,scoreboardback.png,倒计时.svga,护盾.png,背景移动元素.svga,跑道.svga,路架子.svga",
"name": "GameScene" "name": "GameScene"
}, },
{ {
......
...@@ -38,7 +38,7 @@ const options = { ...@@ -38,7 +38,7 @@ const options = {
file: "debug/output.js", file: "debug/output.js",
format: "umd", format: "umd",
name: "output", name: "output",
sourcemap: false, sourcemap: true,
}, },
{ {
file: 'debug/output.module.js', file: 'debug/output.module.js',
......
...@@ -5,7 +5,7 @@ export const ResJson = { ...@@ -5,7 +5,7 @@ export const ResJson = {
"name": "GameRes" "name": "GameRes"
}, },
{ {
"keys": "back.png,fkingCar.png,obstack1.png,obstack2.png,obstack3.png,背景移动元素.svga,跑道.svga,路架子.svga", "keys": "0.png,1.png,2.png,3.png,4.png,5.png,6.png,7.png,8.png,9.png,back.png,countdownback.png,fkingCar.png,obstack1.png,obstack2.png,obstack3.png,scoreboardback.png,倒计时.svga,护盾.png,背景移动元素.svga,跑道.svga,路架子.svga",
"name": "GameScene" "name": "GameScene"
}, },
{ {
......
import { Tools } from './../tools/Tools';
import { layers } from '../../module/views/layers';
import { GDispatcher } from '../Game';
import UI from '../tools/UI';
import { Module } from './../../module/views/Module';
import { ConveyorBeltItem } from './comp/ConveyorBelt';
import { ExtraConfig, ExtraEvents } from './ExtraConfig';
import { ParkourGameEvents } from './ParkourGameConfig';
import { CountDownWithTween, CountDownWithTweenCls, PromiseAwait } from './utils';
export class BalalaScene extends Module {
get groupNames(): string[] {
return ['GameScene']
}
MovieClipList: FYGE.MovieClip[] = []
CountDownAniMoiveClip: FYGE.MovieClip
CountDownAniMoiveClipCont: FYGE.Container
UiCont: FYGE.Container
isInShieldTime: boolean = false
shieldTimer: any
scoreText: FYGE.BitmapText
_score: number = 0
countDownFactory: CountDownWithTweenCls
get score() {
return this._score
}
set score(v: number) {
this.scoreText.text = (~~v) + ''
}
countDownText: FYGE.BitmapText
set countDownNum(v: number) {
this.countDownText.text = v + ''
}
constructor(props?: any) {
super(props)
this.initEvents()
}
initUi(): void {
const BaseScene = UI.Ctn(this)
UI.Sp(BaseScene, 'back.png')
this.MovieClipList.push(UI.MoiveClip(BaseScene, '跑道.svga'))
this.MovieClipList.push(UI.MoiveClip(BaseScene, '背景移动元素.svga'))
this.MovieClipList.push(UI.MoiveClip(BaseScene, '路架子.svga'))
this.UiCont = UI.Ctn(BaseScene)
BaseScene.setChildIndex(this.UiCont, 10000)
const scoreBoardCont = UI.Ctn(BaseScene, 0, 200)
UI.Sp(scoreBoardCont, 'scoreboardback.png')
this.scoreText = scoreBoardCont.addChild(new FYGE.BitmapText(Tools.getNumTextures('')))
this.scoreText.position.set(30, 20)
this.scoreText.textAlign = FYGE.TEXT_ALIGN.LEFT
this.score = 0
const countDownCont = UI.Ctn(BaseScene, 750 - 171, 200)
UI.Sp(countDownCont, 'countdownback.png')
this.countDownText = countDownCont.addChild(new FYGE.BitmapText(Tools.getNumTextures('')))
this.countDownText.position.set(120, 40)
this.countDownNum = ExtraConfig.CountDownTime
this.countDownFactory = new CountDownWithTweenCls(ExtraConfig.CountDownTime * 1000, (t) => {
this.countDownNum = ~~(t / 1000)
}, () => {
this.onGameOver()
})
this.onPause()
setTimeout(() => {
this.onGameRestart()
}, 1000)
}
initEvents(): void {
GDispatcher.addEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision, this)
GDispatcher.addEventListener(ParkourGameEvents.CONVEYOR_MOVE_Y, this.onCalcScore, this)
}
removeEvents(): void {
GDispatcher.removeEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision, this)
GDispatcher.removeEventListener(ParkourGameEvents.CONVEYOR_MOVE_Y, this.onCalcScore, this)
}
/**
* 计算分数
* @param e
*/
onCalcScore(e: FYGE.Event) {
this.score = e.data
}
/**
* 碰撞检测
* @param e
*/
onGameEleCollision(e: FYGE.Event) {
const CollisionContainer: ConveyorBeltItem = e.data
if (CollisionContainer.uniqueKey === 'shit') {
this.isInShieldTime || this.onPause()
} else if (CollisionContainer.uniqueKey === 'coins') {
this.score += 100
} else if (CollisionContainer.uniqueKey === 'protect') {
this.onGetShieldTime()
}
}
/**
* 获取护盾时间
*/
onGetShieldTime() {
this.isInShieldTime = true
this.shieldTimer && clearTimeout(this.shieldTimer)
GDispatcher.dispatchEvent(ExtraEvents.GET_PROTECT)
this.shieldTimer = setTimeout(() => {
GDispatcher.dispatchEvent(ExtraEvents.REMOVE_PROTECT)
this.isInShieldTime = false
}, ExtraConfig.shieldTime)
}
/**
* 游戏开始之前的 倒计时
*/
@PromiseAwait
onGameStartBeforeCountdownAni() {
return new Promise<void>((resolve, reject) => {
let _CountDownAniMoiveClipCont = this.CountDownAniMoiveClipCont
if (!_CountDownAniMoiveClipCont) {
_CountDownAniMoiveClipCont = this.CountDownAniMoiveClipCont = UI.Ctn(layers.popupLayer)
UI.Rect(_CountDownAniMoiveClipCont, 750,1624, 0x000000,0,0,0,0.6)
this.CountDownAniMoiveClip = UI.MoiveClip(_CountDownAniMoiveClipCont, '倒计时.svga', 0, 200)
}
_CountDownAniMoiveClipCont.visible = true
this.CountDownAniMoiveClip.startAniRange(0, this.CountDownAniMoiveClip.totalFrames, 1, () => {
_CountDownAniMoiveClipCont.visible = false
resolve()
})
})
}
async onGameStart() {
this.onResume()
this.countDownFactory.start()
GDispatcher.dispatchEvent(ParkourGameEvents.GAME_RESTART)
}
async onGameRestart() {
// TODO do something
this.score = 0
this.countDownNum = ExtraConfig.CountDownTime
await this.onGameStartBeforeCountdownAni()
this.onGameStart()
}
onPause() {
this.countDownFactory.stop()
this.MovieClipList.forEach(item => {
item.stop()
})
GDispatcher.dispatchEvent(ParkourGameEvents.GAME_PAUSE)
}
onGameOver() {
this.onPause()
}
/**
* 动效开始播放
*/
onResume(resume: boolean = true) {
this.countDownFactory.resume()
this.MovieClipList.forEach(item => {
item.play()
})
}
}
\ No newline at end of file
export enum ExtraEvents {
GET_PROTECT = 'get_protect',
REMOVE_PROTECT = 'remove_protect',
PARKOUR_RESTART = 'parkour_restart',
}
export const ExtraConfig = {
shieldTime: 3000,
CountDownTime: 60, // 倒计时时间 后续接口会修改的
}
\ No newline at end of file
import { ExtraEvents } from './ExtraConfig';
import { GDispatcher } from "../Game";
import UI from "../tools/UI"; import UI from "../tools/UI";
import { PromiseAwait, promiseAwaitFunc } from './utils';
type UniqueKeyType = 'uniqueKey1' | 'uniqueKey2' | 'uniqueKey3' export type UniqueKeyType = 'coins' | 'shit' | 'protect'
/** /**
* 传送带 item 的 类型申明 * 传送带 item 的 类型申明
...@@ -60,18 +63,18 @@ interface ParkourGameConfigInfer { ...@@ -60,18 +63,18 @@ interface ParkourGameConfigInfer {
/** /**
* 游戏事件 * 游戏事件
*/ */
export const ParkourGameEvents = { export enum ParkourGameEvents {
CONVEYOR_MOVE_Y: "conveyor_movey", CONVEYOR_MOVE_Y = "conveyor_movey",
CONVEYOR_INIT_OBSTACK: "conveyor_init_obstack", CONVEYOR_INIT_OBSTACK = "conveyor_init_obstack",
GAME_RESUME: 'GAME_RESUME', // 游戏resume GAME_RESUME = 'GAME_RESUME', // 游戏resume
GAME_RESTART: 'GAME_RESTART', // 游戏重新开始 GAME_RESTART = 'GAME_RESTART', // 游戏重新开始
GAME_COMPLETE: 'GAME_COMPLETE', // 游戏完成 // GAME_OVER = 'GAME_OVER', // 游戏完成
GAME_PAUSE: 'GAME_PAUSE', // 游戏暂停 GAME_PAUSE ='GAME_PAUSE', // 游戏暂停
GAME_RESET_PARKOURELE: 'GAME_RESET_PARKOURELE', // 重新设置 游戏元素配置 GAME_RESET_PARKOURELE = 'GAME_RESET_PARKOURELE', // 重新设置 游戏元素配置
GAME_SPEEDUP: 'GAME_SPEEDUP', // 游戏加速 GAME_SPEEDUP = 'GAME_SPEEDUP', // 游戏加速
GAME_COLLESION: 'GAME_COLLESION', // 游戏碰撞 GAME_COLLESION ='GAME_COLLESION', // 游戏碰撞
} }
/** /**
...@@ -85,11 +88,49 @@ export const ParkourGameConfig: ParkourGameConfigInfer = { ...@@ -85,11 +88,49 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
super(); super();
this.onInitUi() this.onInitUi()
this.initEvents()
} }
onInitUi() { onInitUi() {
UI.Sp(this, 'fkingCar.png') UI.Sp(this, 'fkingCar.png')
} }
shieldCont: FYGE.Container
onGetProtect = () => {
if (!this.shieldCont) {
this.shieldCont = UI.Sp(this, '护盾.png', -130, -100)
FYGE.Tween.get(this.shieldCont, {
loop: true
}).to({
alpha: 0.5
}, 300)
.to({alpha: 1}, 300)
}
this.shieldCont.visible = true
}
onRemoveProtect() {
this.shieldCont && (this.shieldCont.visible = false)
}
initEvents() {
GDispatcher.addEventListener(ExtraEvents.GET_PROTECT, this.onGetProtect, this)
GDispatcher.addEventListener(ExtraEvents.REMOVE_PROTECT, this.onRemoveProtect, this)
}
removeEvents() {
GDispatcher.removeEventListener(ExtraEvents.GET_PROTECT, this.onGetProtect, this)
GDispatcher.removeEventListener(ExtraEvents.REMOVE_PROTECT, this.onRemoveProtect, this)
}
destroy(): void {
super.destroy()
this.removeEvents()
}
}, },
collisionConfig: { collisionConfig: {
...@@ -142,7 +183,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = { ...@@ -142,7 +183,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
], ],
ParkourGameEleList: [ ParkourGameEleList: [
{ {
uniqueKey: 'uniqueKey1', uniqueKey: 'coins',
Container: 'obstack1.png', Container: 'obstack1.png',
ProbabilityPort: 10, ProbabilityPort: 10,
collisionConfig: { collisionConfig: {
...@@ -154,9 +195,9 @@ export const ParkourGameConfig: ParkourGameConfigInfer = { ...@@ -154,9 +195,9 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
} }
}, },
{ {
uniqueKey: 'uniqueKey2', // 这个是障碍物 uniqueKey: 'shit', // 这个是障碍物
Container: 'obstack2.png', Container: 'obstack2.png',
ProbabilityPort: 100000, ProbabilityPort: 10,
// anchorX: 130, // anchorX: 130,
// anchorY: 130, // anchorY: 130,
collisionConfig: { collisionConfig: {
...@@ -168,7 +209,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = { ...@@ -168,7 +209,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
} }
}, },
{ {
uniqueKey: 'uniqueKey3', uniqueKey: 'protect',
Container: 'obstack3.png', Container: 'obstack3.png',
ProbabilityPort: 10, ProbabilityPort: 10,
// anchorX: 100, // anchorX: 100,
...@@ -183,11 +224,11 @@ export const ParkourGameConfig: ParkourGameConfigInfer = { ...@@ -183,11 +224,11 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
} }
], ],
CommonConfig: { CommonConfig: {
speed: 300, speed: 300, // 速度 可以通过GAME_SPEEDUP 修改
CollisionDebug: true, CollisionDebug: true, // 碰撞检测 debug
GamerAxisY: 1100, GamerAxisY: 1100, // 玩家轴Y
GamerIndex: 1, GamerIndex: 1, // 当前玩家索引 在哪条道
DetermineXAxis: 100, DetermineXAxis: 50, // 左右滑动判定距离
safeDistance: 500 safeDistance: 500 // 判断的安全距离
} }
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ import UI from "../tools/UI"; ...@@ -4,6 +4,7 @@ import UI from "../tools/UI";
import { ConveyorBelt, ConveyorBeltItem } from "./comp/ConveyorBelt"; import { ConveyorBelt, ConveyorBeltItem } from "./comp/ConveyorBelt";
import { GDispatcher } from '../Game'; import { GDispatcher } from '../Game';
import { CollisionDetection, RectPhysicsCont, WithCollisionDetection } from './CollisionComposite'; import { CollisionDetection, RectPhysicsCont, WithCollisionDetection } from './CollisionComposite';
import { BalalaScene } from './BalalaScene';
/** /**
* 解个一元一次方程式咯 * 解个一元一次方程式咯
...@@ -26,10 +27,11 @@ export class ParkourScene extends Scene { ...@@ -26,10 +27,11 @@ export class ParkourScene extends Scene {
conBeltList: ConveyorBelt[] = [] conBeltList: ConveyorBelt[] = []
NewContIns: ConveyorBeltItem NewContIns: ConveyorBeltItem
MovieClipList: FYGE.MovieClip[] = []
_GamerIndex: number _GamerIndex: number
isPaused: boolean = true
get GamerIndex() { get GamerIndex() {
return this._GamerIndex return this._GamerIndex
} }
...@@ -60,12 +62,9 @@ export class ParkourScene extends Scene { ...@@ -60,12 +62,9 @@ export class ParkourScene extends Scene {
initUi() { initUi() {
const BaseScene = UI.Ctn(this) this.addChild(new BalalaScene())
UI.Sp(BaseScene, 'back.png')
this.MovieClipList.push(UI.MoiveClip(BaseScene, '跑道.svga'))
// this.MovieClipList.push(UI.MoiveClip(BaseScene, '背景移动元素.svga'))
// this.MovieClipList.push(UI.MoiveClip(BaseScene, '路架子.svga'))
// 生成传送带
ParkourGameConfig.ConveyorBeltList.forEach((item, index) => { ParkourGameConfig.ConveyorBeltList.forEach((item, index) => {
this.conBeltList.push(this.addChild(new ConveyorBelt({ this.conBeltList.push(this.addChild(new ConveyorBelt({
ParkourGameEleList: ParkourGameConfig.ParkourGameEleList, ParkourGameEleList: ParkourGameConfig.ParkourGameEleList,
...@@ -73,14 +72,20 @@ export class ParkourScene extends Scene { ...@@ -73,14 +72,20 @@ export class ParkourScene extends Scene {
}, this.onJudgeNextObstacle))) }, this.onJudgeNextObstacle)))
}) })
window['conBeltList'] = this.conBeltList
const NewContIns = this.NewContIns = this.addChild(new ConveyorBeltItem(ParkourGameConfig.ParkourGamer)) const NewContIns = this.NewContIns = this.addChild(new ConveyorBeltItem(ParkourGameConfig.ParkourGamer))
NewContIns.setPosition(0, 0) NewContIns.setPosition(0, 0)
this.onResetUi()
}
onResetUi() {
this.isPaused = false
this.GamerIndex = ParkourGameConfig.CommonConfig.GamerIndex this.GamerIndex = ParkourGameConfig.CommonConfig.GamerIndex
}
// GDispatcher.dispatchEvent(ParkourGameEvents.GAME_RESTART) onGamePause() {
this.isPaused = true
} }
...@@ -96,10 +101,10 @@ export class ParkourScene extends Scene { ...@@ -96,10 +101,10 @@ export class ParkourScene extends Scene {
// 这样就能 防止必死的情况' // 这样就能 防止必死的情况'
const safeNum = ParkourGameConfig.CommonConfig.safeDistance const safeNum = ParkourGameConfig.CommonConfig.safeDistance
if (safeNum) { if (safeNum) {
if (data.uniqueKey === 'uniqueKey2') { if (data.uniqueKey === 'shit') {
return this.conBeltList.filter(item => { return this.conBeltList.filter(item => {
return item.children.some((child: ConveyorBeltItem) => { return item.children.some((child: ConveyorBeltItem) => {
return child.y < safeNum && child.uniqueKey === "uniqueKey2" return child.y < safeNum && child.uniqueKey === 'shit'
}) })
}).length < 2 }).length < 2
} }
...@@ -113,6 +118,10 @@ export class ParkourScene extends Scene { ...@@ -113,6 +118,10 @@ export class ParkourScene extends Scene {
GDispatcher.addEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision) GDispatcher.addEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision)
GDispatcher.addEventListener(ParkourGameEvents.GAME_RESTART, this.onResetUi, this)
GDispatcher.addEventListener(ParkourGameEvents.GAME_PAUSE, this.onGamePause, this)
this.stage.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, this.onGameDetermineMouseDown, this) this.stage.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, this.onGameDetermineMouseDown, this)
// 测试碰撞检测用的 // 测试碰撞检测用的
...@@ -124,7 +133,11 @@ export class ParkourScene extends Scene { ...@@ -124,7 +133,11 @@ export class ParkourScene extends Scene {
GDispatcher.removeEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision) GDispatcher.removeEventListener(ParkourGameEvents.GAME_COLLESION, this.onGameEleCollision)
this.stage.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, this.onGameDetermineMouseDown, this) GDispatcher.removeEventListener(ParkourGameEvents.GAME_RESTART, this.onResetUi, this)
GDispatcher.removeEventListener(ParkourGameEvents.GAME_PAUSE, this.onGamePause, this)
this.stage.removeEventListener(FYGE.MouseEvent.MOUSE_DOWN, this.onGameDetermineMouseDown, this)
} }
/** /**
...@@ -140,6 +153,7 @@ export class ParkourScene extends Scene { ...@@ -140,6 +153,7 @@ export class ParkourScene extends Scene {
* @param e * @param e
*/ */
onGameDetermineMouseDown(e: FYGE.MouseEvent) { onGameDetermineMouseDown(e: FYGE.MouseEvent) {
if (this.isPaused) return
const startPos = { const startPos = {
x: e.stageX, x: e.stageX,
y: e.stageY y: e.stageY
......
import { ParkourGameEvents, ParkourGameEleType, ConveyorBeltType, ParkourGameConfig, ConveyorItemConstrutType } from './../ParkourGameConfig'; import { ParkourGameEvents, ParkourGameEleType, ConveyorBeltType, ParkourGameConfig, ConveyorItemConstrutType, UniqueKeyType } from './../ParkourGameConfig';
import { GDispatcher } from "../../Game" import { GDispatcher } from "../../Game"
import Clock from "../../tools/Clock" import Clock from "../../tools/Clock"
import UI from '../../tools/UI'; import UI from '../../tools/UI';
...@@ -18,7 +18,7 @@ export class ConveyorBeltItem extends FYGE.Container { ...@@ -18,7 +18,7 @@ export class ConveyorBeltItem extends FYGE.Container {
public speed: number = 0 public speed: number = 0
public constructType: any public constructType: any
propsData: ConveyorItemConstrutType propsData: ConveyorItemConstrutType
uniqueKey: string uniqueKey: UniqueKeyType
constructor(props: ConveyorItemConstrutType) { constructor(props: ConveyorItemConstrutType) {
super() super()
...@@ -222,7 +222,7 @@ export class ConveyorBelt extends FYGE.Container { ...@@ -222,7 +222,7 @@ export class ConveyorBelt extends FYGE.Container {
this.onInitTspeed() this.onInitTspeed()
} }
onGameReStart() { onRestartRoll() {
this.onReset() this.onReset()
this.isMoving = true this.isMoving = true
...@@ -238,18 +238,10 @@ export class ConveyorBelt extends FYGE.Container { ...@@ -238,18 +238,10 @@ export class ConveyorBelt extends FYGE.Container {
/** /**
* 暂停 * 暂停
*/ */
onGamePause() { onRollPause() {
this.isMoving = false this.isMoving = false
} }
/**
* 游戏 结束
*/
onGameOver() {
// GDispatcher.dispatchEvent(ParkourGameEvents.GAME_COMPLETE)
this.onGamePause()
}
/** /**
* 初始化事件 * 初始化事件
*/ */
...@@ -259,13 +251,11 @@ export class ConveyorBelt extends FYGE.Container { ...@@ -259,13 +251,11 @@ export class ConveyorBelt extends FYGE.Container {
GDispatcher.addEventListener(ParkourGameEvents.GAME_SPEEDUP, this.onInitTspeed, this) GDispatcher.addEventListener(ParkourGameEvents.GAME_SPEEDUP, this.onInitTspeed, this)
GDispatcher.addEventListener(ParkourGameEvents.GAME_PAUSE, this.onGamePause, this) GDispatcher.addEventListener(ParkourGameEvents.GAME_PAUSE, this.onRollPause, this)
GDispatcher.addEventListener(ParkourGameEvents.GAME_RESUME, this.onGameResume, this) GDispatcher.addEventListener(ParkourGameEvents.GAME_RESUME, this.onGameResume, this)
GDispatcher.addEventListener(ParkourGameEvents.GAME_COMPLETE, this.onGameOver, this) GDispatcher.addEventListener(ParkourGameEvents.GAME_RESTART, this.onRestartRoll, this)
GDispatcher.addEventListener(ParkourGameEvents.GAME_RESTART, this.onGameReStart, this)
} }
/** /**
...@@ -277,13 +267,11 @@ export class ConveyorBelt extends FYGE.Container { ...@@ -277,13 +267,11 @@ export class ConveyorBelt extends FYGE.Container {
GDispatcher.removeEventListener(ParkourGameEvents.GAME_SPEEDUP, this.onInitTspeed, this) GDispatcher.removeEventListener(ParkourGameEvents.GAME_SPEEDUP, this.onInitTspeed, this)
GDispatcher.removeEventListener(ParkourGameEvents.GAME_PAUSE, this.onGamePause, this) GDispatcher.removeEventListener(ParkourGameEvents.GAME_PAUSE, this.onRollPause, this)
GDispatcher.removeEventListener(ParkourGameEvents.GAME_RESUME, this.onGameResume, this) GDispatcher.removeEventListener(ParkourGameEvents.GAME_RESUME, this.onGameResume, this)
GDispatcher.removeEventListener(ParkourGameEvents.GAME_COMPLETE, this.onGameOver, this) GDispatcher.removeEventListener(ParkourGameEvents.GAME_RESTART, this.onRestartRoll, this)
GDispatcher.removeEventListener(ParkourGameEvents.GAME_RESTART, this.onGameReStart, this)
} }
/** /**
......
/**
* 装饰方法 执行完Promise 之后 才可以第二次执行
* @param target
* @param property
* @param descriptor
*/
export function PromiseAwait(target: any, property: string, descriptor: PropertyDescriptor) {
const func: Function = descriptor.value
let waitPromise: Promise<any> | null = null
let waitPromiseResolve: (value: unknown) => void
descriptor.value = async function(...args:any[]) {
if (waitPromise) return waitPromise
waitPromise = new Promise(resolve => {
waitPromiseResolve = resolve
})
const res = await func.apply(this, args)
waitPromiseResolve(res)
waitPromise = null
return res
}
}
/**
* PromiseAwait 闭包版本
* @param func
* @returns
*/
export function promiseAwaitFunc(func: Function) {
let waitPromise: Promise<any> | null = null
let waitPromiseResolve: (value: unknown) => void
return async function(...args: any[]) {
if (waitPromise) return waitPromise
waitPromise = new Promise(resolve => {
waitPromiseResolve = resolve
})
const res = await func.apply(this, args)
waitPromiseResolve(res)
waitPromise = null
return res
}
}
export class CountDownWithTweenCls {
onChangeCb: (t: number) => void
onEnd: () => void
countDownTotalTime: number
countDownTweenObj: {t: number}
constructor(time: number, onChangeCb: (t: number) => void, onEnd: () => void) {
this.onChangeCb = onChangeCb
this.onEnd = onEnd
this.countDownTotalTime = time
}
start() {
this.countDownTweenObj && FYGE.Tween.removeTweens(this.countDownTweenObj)
this.countDownTweenObj = {
t: this.countDownTotalTime
}
FYGE.Tween.get(this.countDownTweenObj,
{
onChange: () => {
this.onChangeCb(this.countDownTweenObj.t)
}
}
)
.to({
t: 0
}, this.countDownTotalTime)
.call(() => {
this.onEnd()
})
}
stop() {
if (!this.countDownTweenObj) return
FYGE.Tween.pauseTweens(this.countDownTweenObj)
}
resume() {
if (!this.countDownTweenObj) return
FYGE.Tween.resumeTweens(this.countDownTweenObj)
}
}
export function CountDownWithTween(time: number, onChangeCb: (t: number) => void, onEnd: () => void) {
const countDownTotalTime = time
let countDownTweenObj: {t: number}
return {
start: () => {
countDownTweenObj && FYGE.Tween.removeTweens(countDownTweenObj)
countDownTweenObj = {
t: countDownTotalTime
}
FYGE.Tween.get(countDownTweenObj,
{
onChange() {
onChangeCb(countDownTweenObj.t)
}
}
)
.to({
t: 0
}, countDownTotalTime)
.call(() => {
onEnd()
})
},
stop: () => {
if (!countDownTweenObj) return
FYGE.Tween.pauseTweens(countDownTweenObj)
},
resume() {
if (!countDownTweenObj) return
FYGE.Tween.resumeTweens(countDownTweenObj)
}
}
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"module": "ESNext", "module": "ESNext",
"target": "ESNext", "target": "ESNext",
"noImplicitAny": false, "noImplicitAny": false,
"sourceMap": false, "sourceMap": true,
"allowJs": true, "allowJs": true,
"noUnusedLocals": false, "noUnusedLocals": false,
"moduleResolution": "Node", "moduleResolution": "Node",
......
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