Commit ee62695e authored by Master Q's avatar Master Q

游戏基本逻辑确定

parent febedac1
...@@ -43,7 +43,11 @@ ...@@ -43,7 +43,11 @@
} }
</style> </style>
<!-- <script src="//yun.duiba.com.cn/db_games/libs0924/fyge2020.min.js" crossorigin="anonymous"></script> --> <!-- <script src="//yun.duiba.com.cn/db_games/libs0924/fyge2020.min.js" crossorigin="anonymous"></script> -->
<!-- 渲染引擎 -->
<script src="//yun.duiba.com.cn/db_games/libs0924/fyge2044.min.js" crossorigin="anonymous"></script> <script src="//yun.duiba.com.cn/db_games/libs0924/fyge2044.min.js" crossorigin="anonymous"></script>
<!-- svga解析库 -->
<script src="//yun.duiba.com.cn/db_games/libs0924/svgaParser.minWeb.js" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
<div class="ss" style="line-height:0;font-size:0;position: absolute;"> <div class="ss" style="line-height:0;font-size:0;position: absolute;">
...@@ -65,7 +69,9 @@ ...@@ -65,7 +69,9 @@
const canvas = document.getElementById('stage') const canvas = document.getElementById('stage')
canvas.width = document.body.clientWidth * (window.devicePixelRatio || 1) canvas.width = document.body.clientWidth * (window.devicePixelRatio || 1)
canvas.height = document.body.clientHeight * (window.devicePixelRatio || 1) canvas.height = document.body.clientHeight * (window.devicePixelRatio || 1)
new Main(canvas) new Main(canvas, {
isFirstGame: true
})
}) })
</script> </script>
......
{ {
"groups": [ "groups": [
{ {
"keys": "GSB.png,platform.png,rabbit.png,scoreBoardBack.png", "keys": "GSB.png,clockBack.png,platform.png,rabbit.png,scoreBoardBack.png,sp_boom.png,sp_milk.png",
"name": "GameScene" "name": "GameScene"
}, },
{ {
......
...@@ -12,6 +12,6 @@ fs.writeFileSync(endPath + "output.js", ...@@ -12,6 +12,6 @@ fs.writeFileSync(endPath + "output.js",
// 'import * as FYGE from "fyge";\n' +//以后改成这个 // 'import * as FYGE from "fyge";\n' +//以后改成这个
// 'import * as SvgaParser from "svga-parser";\n' + // 'import * as SvgaParser from "svga-parser";\n' +
'/* eslint-disable */\n' + '/* eslint-disable */\n' +
'const FYGE = require("./fyge.min.js");\n' + // 'const FYGE = require("./fyge.min.js");\n' +
fs.readFileSync("./output.js")); fs.readFileSync("./output.js"));
console.log("js生成") console.log("js生成")
export const ResJson = { export const ResJson = {
"groups": [ "groups": [
{ {
"keys": "GSB.png,platform.png,rabbit.png,scoreBoardBack.png", "keys": "GSB.png,clockBack.png,platform.png,rabbit.png,scoreBoardBack.png,sp_boom.png,sp_milk.png",
"name": "GameScene" "name": "GameScene",
"atlas": {
"GSB.png": {
"x": 2,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
},
"rabbit.png": {
"x": 754,
"y": 2,
"w": 110,
"h": 218,
"ox": 0,
"oy": 0,
"sw": 110,
"sh": 218,
"ro": false
},
"scoreBoardBack.png": {
"x": 754,
"y": 222,
"w": 193,
"h": 81,
"ox": 0,
"oy": 0,
"sw": 193,
"sh": 81,
"ro": true
},
"platform.png": {
"x": 754,
"y": 417,
"w": 142,
"h": 52,
"ox": 0,
"oy": 0,
"sw": 142,
"sh": 52,
"ro": true
},
"sp_boom.png": {
"x": 754,
"y": 561,
"w": 94,
"h": 99,
"ox": 0,
"oy": 0,
"sw": 94,
"sh": 99,
"ro": true
},
"sp_milk.png": {
"x": 754,
"y": 657,
"w": 93,
"h": 93,
"ox": 0,
"oy": 0,
"sw": 93,
"sh": 93,
"ro": false
},
"clockBack.png": {
"x": 754,
"y": 752,
"w": 80,
"h": 91,
"ox": 0,
"oy": 0,
"sw": 80,
"sh": 91,
"ro": true
}
}
}, },
{ {
"keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png", "keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png",
"name": "NewGuyScene" "name": "NewGuyScene",
"atlas": {
"Guide1.png": {
"x": 2,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
},
"Guide2.png": {
"x": 754,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
},
"Guide3.png": {
"x": 1506,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
},
"Guide4.png": {
"x": 2,
"y": 1628,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": true
}
}
}, },
{ {
"keys": "closebtn.png,giftBoxIcon.png,waitingBg.png,waitingRot.png", "keys": "closebtn.png,giftBoxIcon.png,waitingBg.png,waitingRot.png",
"name": "common" "name": "common",
"atlas": {
"waitingBg.png": {
"x": 2,
"y": 2,
"w": 160,
"h": 180,
"ox": 0,
"oy": 0,
"sw": 160,
"sh": 180,
"ro": false
},
"giftBoxIcon.png": {
"x": 164,
"y": 2,
"w": 127,
"h": 125,
"ox": 0,
"oy": 0,
"sw": 127,
"sh": 125,
"ro": true
},
"waitingRot.png": {
"x": 2,
"y": 184,
"w": 56,
"h": 56,
"ox": 0,
"oy": 0,
"sw": 56,
"sh": 56,
"ro": false
},
"closebtn.png": {
"x": 60,
"y": 184,
"w": 52,
"h": 52,
"ox": 0,
"oy": 0,
"sw": 52,
"sh": 52,
"ro": false
}
}
} }
], ],
"path": "./resource/" // eslint-disable-next-line
"path": "https://yun.duiba.com.cn/db_games/activity/template/1670923535/resource/"
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ export const DreamTextField: OriginalElementWidthEvents<{ ...@@ -9,6 +9,8 @@ export const DreamTextField: OriginalElementWidthEvents<{
bold?: boolean, bold?: boolean,
textHeight?: number textHeight?: number
verticalAlign?: FYGE.VERTICAL_ALIGN verticalAlign?: FYGE.VERTICAL_ALIGN
stroke?: number
strokeColor?: string
}, FYGE.TextField> = ({ }, FYGE.TextField> = ({
text, text,
color='#000000', color='#000000',
...@@ -17,7 +19,9 @@ export const DreamTextField: OriginalElementWidthEvents<{ ...@@ -17,7 +19,9 @@ export const DreamTextField: OriginalElementWidthEvents<{
align=FYGE.TEXT_ALIGN.CENTER, align=FYGE.TEXT_ALIGN.CENTER,
bold=false, bold=false,
textHeight, textHeight,
verticalAlign = FYGE.VERTICAL_ALIGN.MIDDLE verticalAlign = FYGE.VERTICAL_ALIGN.MIDDLE,
stroke = 0,
strokeColor = '#000000'
}) => { }) => {
const textIns = new FYGE.TextField() const textIns = new FYGE.TextField()
textIns.fillColor = color; textIns.fillColor = color;
...@@ -28,5 +32,9 @@ export const DreamTextField: OriginalElementWidthEvents<{ ...@@ -28,5 +32,9 @@ export const DreamTextField: OriginalElementWidthEvents<{
textIns.bold = bold textIns.bold = bold
textHeight && (textIns.textHeight = textHeight) textHeight && (textIns.textHeight = textHeight)
textIns.verticalAlign = verticalAlign textIns.verticalAlign = verticalAlign
textIns.stroke = stroke
textIns.strokeColor = strokeColor
return textIns return textIns
} }
\ No newline at end of file
...@@ -19,8 +19,11 @@ import getEnv = FYGE.getEnv; ...@@ -19,8 +19,11 @@ import getEnv = FYGE.getEnv;
*/ */
export const GDispatcher = new EventDispatcher(); export const GDispatcher = new EventDispatcher();
export {
G_Events
} from './scenes/GameScene/GameEvents'
export const loadAllGroups = async function() { export const loadAllGroups = async function() {
FYGE.setEnv('tb')
RES.loadConfig(ResJson) RES.loadConfig(ResJson)
await RES.loadAllGroup() await RES.loadAllGroup()
} }
...@@ -35,8 +38,7 @@ export class Main { ...@@ -35,8 +38,7 @@ export class Main {
constructor( constructor(
canvas: HTMLCanvasElement, canvas: HTMLCanvasElement,
config: { config: {
isFirstGame: boolean, isFirstGame: boolean
liveCard: number
}, },
desWidth = 750, desWidth = 750,
desHeight = 1624, desHeight = 1624,
...@@ -108,7 +110,7 @@ export class Main { ...@@ -108,7 +110,7 @@ export class Main {
RES.loadConfig(ResJson) RES.loadConfig(ResJson)
await RES.loadGroup('common') await RES.loadGroup('common')
SceneController.changeScene(GameScene) SceneController.changeScene(Tools.PageData.isFirstGame ? NewGuyScene : GameScene)
} }
initWebEvent(){ initWebEvent(){
......
import { layers } from "../../modules/layers"; import { layers } from "../../modules/layers";
// type 1 正常 2必出道具 3必出炸弹 4 随机出 道具 5 随机出炸弹
// 一行中 最多一个炸弹,这样配合 概率就不会导致出现死局
export const GameConfig = { export const GameConfig = {
debugger: true, debugger: true,
sp_p: 0.3, // 出现道具的 概率
sp_b: 0.8, // 出现炸弹的概率
offsetYLen: 180, offsetYLen: 180,
offsetXLen: 150,// 格子间隔 offsetXLen: 150, // 格子间隔
rowNum: 30, // 单个地图的显示 行数 rowNum: 30, // 单个地图的显示 行数
speed: 100, // 卷轴速度 speed: 100, // 卷轴速度
mapChangeAddSpeed: 10, // 切换地图就会 增加速度
renderMapScreenNum: 200, //当卷轴 移动到视窗上面多少 会去生成地图 renderMapScreenNum: 200, //当卷轴 移动到视窗上面多少 会去生成地图
rabbitConfig: { rabbitConfig: {
offsetX: 10, offsetX: 10,
offsetY: -203, offsetY: -203,
}, },
DecisionLine: [ // 判定线 当前屏幕显示区域 DecisionLine: [
300, layers.stageHeight // 这里个需要后续设定 // 判定线 当前屏幕显示区域
300,
layers.stageHeight, // 这里个需要后续设定
], ],
landPlatformScore: 2, // 平台上的分数
spCountTime: 3100, //道具倒计时
boxColNum: 5, // 几列格子 boxColNum: 5, // 几列格子
mapList: [ mapList: [
{ {
initPos: { initPos: {
x: 2, x: 2,
y: 26 y: 26,
}, },
boxMap: [ boxMap: [
[0, 1, 0, 1, 1], [0, 1, 0, 1, 3],
[0, 1, 1, 0, 0], [0, 4, 1, 0, 0],
[1, 0, 0, 1, 0], [4, 0, 0, 5, 0],
[0, 1, 1, 0, 1], [0, 1, 1, 0, 1],
[1, 1, 0, 1, 0], [4, 3, 0, 1, 0],
[0, 1, 1, 0, 0], [0, 1, 1, 0, 0],
[1, 0, 0, 0, 1], [5, 0, 0, 0, 1],
[1, 0, 1, 1, 1], [1, 0, 1, 1, 1],
[0, 1, 0, 0, 1], [0, 1, 0, 0, 5],
[1, 0, 1, 0, 0],
[0, 1,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 2, 0, 1],
[5, 0, 0, 0, 5],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 4, 0, 4, 0],
[1, 3, 1, 1, 1],
[1, 0, 2, 0, 1],
[0, 1, 0, 1, 0],
], ],
}, },
], ],
......
export const G_Events = {
GameOver: 'GameOver'
}
\ No newline at end of file
import { GDispatcher } from "../..";
import { DreamContainer } from "../../components/DreamContainer/DreamContainer"; import { DreamContainer } from "../../components/DreamContainer/DreamContainer";
import { DreamShape } from "../../components/DreamShape/DreamShape"; import { DreamShape } from "../../components/DreamShape/DreamShape";
import { DreamSprite } from "../../components/DreamSprite/DreamSprite"; import { DreamSprite } from "../../components/DreamSprite/DreamSprite";
...@@ -7,9 +8,11 @@ import { RES } from "../../modules/RES"; ...@@ -7,9 +8,11 @@ import { RES } from "../../modules/RES";
import { UsePreload } from "../../modules/UseDecorator/usePreload"; import { UsePreload } from "../../modules/UseDecorator/usePreload";
import { PromiseAwait } from "../../tools/Tools"; import { PromiseAwait } from "../../tools/Tools";
import { GameConfig } from "./GameConfig"; import { GameConfig } from "./GameConfig";
import { G_Events } from "./GameEvents";
import { Platform } from "./Platform"; import { Platform } from "./Platform";
import { RabbitPlayer } from "./Player"; import { RabbitPlayer } from "./Player";
import { ScoreBoard } from "./ScoreBoard"; import { ScoreBoard } from "./ScoreBoard";
import { SpClock } from "./SpClock";
type Pos = { type Pos = {
x: number, x: number,
...@@ -21,6 +24,10 @@ const { ...@@ -21,6 +24,10 @@ const {
} = GameConfig } = GameConfig
const mapHeight = rowNum * offsetYLen const mapHeight = rowNum * offsetYLen
function randomPro(n: number) {
return Math.random() < n
}
@UsePreload({ @UsePreload({
preAction: async function() { preAction: async function() {
await RES.loadGroup('GameScene') await RES.loadGroup('GameScene')
...@@ -46,7 +53,10 @@ export class GameScene extends Dream.RenderContainer { ...@@ -46,7 +53,10 @@ export class GameScene extends Dream.RenderContainer {
rabbitPos: Pos rabbitPos: Pos
rabbitContainer: FYGE.Container // 兔子Container rabbitContainer: FYGE.Container // 兔子Container
rabbitCloneContainer: FYGE.Container // 兔子的克隆体 做创屏幕动画的 rabbitCloneContainer: FYGE.Container // 兔子的克隆体 做创屏幕动画的
rabbitBoxMap: number[][] = [] // 兔子地图map rabbitBoxMap: Platform[][] = [] // 兔子地图map
ScoreBoardIns: ScoreBoard // 当前分数面板
SpClockIns: SpClock // 道具倒计时
double: number = 1 // 是否双倍
set dir(v: number) { set dir(v: number) {
this.rabbitContainer.scaleX = v this.rabbitContainer.scaleX = v
...@@ -56,7 +66,30 @@ export class GameScene extends Dream.RenderContainer { ...@@ -56,7 +66,30 @@ export class GameScene extends Dream.RenderContainer {
didRendered(): void { didRendered(): void {
this.renderMap(true) this.renderMap(true)
this.initEvents()
this.onGameStart()
}
unMount(): void {
this.removeEvents()
}
initEvents() {
// 测试地图
document.body.addEventListener('keydown', (e) => {
const keyCode = e.code
console.log(keyCode)
if (keyCode == 'ArrowDown') {
this.onGameStart() this.onGameStart()
} else {
this.onGameOver()
}
})
}
removeEvents() {
} }
onGameStart() { onGameStart() {
...@@ -77,9 +110,14 @@ export class GameScene extends Dream.RenderContainer { ...@@ -77,9 +110,14 @@ export class GameScene extends Dream.RenderContainer {
this.isPause = false this.isPause = false
} }
/**
* 游戏结束
*/
onGameOver() { onGameOver() {
FYGE.Tween.removeTweens(this.rabbitContainer) FYGE.Tween.removeTweens(this.rabbitContainer)
this.isPause = true this.isPause = true
GDispatcher.dispatchEvent(G_Events.GameOver, this.ScoreBoardIns.score)
} }
/** /**
...@@ -87,9 +125,9 @@ export class GameScene extends Dream.RenderContainer { ...@@ -87,9 +125,9 @@ export class GameScene extends Dream.RenderContainer {
* @param init 是否是初始化 * @param init 是否是初始化
*/ */
renderMap(init: boolean = false) { renderMap(init: boolean = false) {
// TODO 随机
console.info('=========render map ===========') console.info('=========render map ===========')
const mapConfig = GameConfig.mapList[0]
const mapConfig = GameConfig.mapList[Math.random() * GameConfig.mapList.length >> 0]
const { const {
rowNum, rowNum,
offsetYLen offsetYLen
...@@ -101,22 +139,56 @@ export class GameScene extends Dream.RenderContainer { ...@@ -101,22 +139,56 @@ export class GameScene extends Dream.RenderContainer {
this.rabbitPos.y += rowNum this.rabbitPos.y += rowNum
} }
// 地图平台数组
const mapPlatform:Platform[][] = []
this.GameMapContainer.addChildAt( this.GameMapContainer.addChildAt(
<DreamContainer className="mapContainer" inlineProps={{ <DreamContainer className="mapContainer" inlineProps={{
y: this.mapCount * rowNum * offsetYLen * -1 y: this.mapCount * rowNum * offsetYLen * -1
}}> }}>
{ {
mapBoxes.map((rowItem, rowIndex) => { mapBoxes.map((rowItem, rowIndex) => {
const rowArr: any[] = mapPlatform[rowIndex] = []
let boomflag = false // 一行就让出一个炸弹吧
let clockflag = false // 一行最多一个 道具吧
return ( return (
<DreamContainer inlineProps={{ <DreamContainer inlineProps={{
y: rowIndex * GameConfig.offsetYLen y: rowIndex * GameConfig.offsetYLen
}}> }}>
{ {
rowItem.map((colItem, colIndex) => { rowItem.map((colItem, colIndex) => {
// TODO type if (colItem == 4) {
return ( colItem = randomPro(GameConfig.sp_p) ? 2 : 1
colItem ? <Platform type={1} x={colIndex * offsetXLen} /> : undefined } else if (colItem == 5) {
) colItem = randomPro(GameConfig.sp_b) ? 3 : 1
}
// 一行中还是 随机到 炸弹就变成平台
if (colItem == 3) {
if (boomflag) {
colItem = 1
} else {
boomflag = true
}
}
if (colItem == 2) {
if (clockflag) {
colItem = 1
} else {
clockflag = true
}
}
if (
colItem
) {
return <Platform ref={el => {
rowArr[colIndex] = el
}}
pos={[rowIndex, colIndex]} type={colItem} x={colIndex * offsetXLen} />
} else {
rowArr[colIndex] = undefined
return undefined
}
}) })
} }
</DreamContainer> </DreamContainer>
...@@ -126,8 +198,9 @@ export class GameScene extends Dream.RenderContainer { ...@@ -126,8 +198,9 @@ export class GameScene extends Dream.RenderContainer {
</DreamContainer> </DreamContainer>
, 0) , 0)
this.mapCount += 1 this.mapCount += 1
this.rabbitBoxMap.unshift(...mapBoxes) // 增加速度
console.log(this.rabbitBoxMap) GameConfig.speed += GameConfig.mapChangeAddSpeed
this.rabbitBoxMap.unshift(...mapPlatform)
} }
/** /**
...@@ -157,7 +230,7 @@ export class GameScene extends Dream.RenderContainer { ...@@ -157,7 +230,7 @@ export class GameScene extends Dream.RenderContainer {
const now = Date.now() const now = Date.now()
const st = (now - this.lastTime) / 1000 const st = (now - this.lastTime) / 1000
this.lastTime = now this.lastTime = now
if (st > 1) { if (st > 0.2) {
return return
} }
this.GameReelContainer.y += GameConfig.speed * st this.GameReelContainer.y += GameConfig.speed * st
...@@ -203,7 +276,8 @@ export class GameScene extends Dream.RenderContainer { ...@@ -203,7 +276,8 @@ export class GameScene extends Dream.RenderContainer {
const willX = (_willX + GameConfig.boxColNum) % GameConfig.boxColNum const willX = (_willX + GameConfig.boxColNum) % GameConfig.boxColNum
let shouldY = ray - (screenRY < GameConfig.DecisionLine[0] ? 0 : 1) let shouldY = ray - (screenRY < GameConfig.DecisionLine[0] ? 0 : 1)
// console.log('========',shouldY, '\n===stageX===\n', stageX) // console.log('========',shouldY, '\n===stageX===\n', stageX)
while(!rabbitBoxMap[shouldY][willX]) { let landPlatform: Platform
while(!(landPlatform = rabbitBoxMap[shouldY][willX])) {
shouldY += 1 shouldY += 1
if (shouldY >= rabbitBoxMap.length - 1) { if (shouldY >= rabbitBoxMap.length - 1) {
break break
...@@ -252,12 +326,39 @@ export class GameScene extends Dream.RenderContainer { ...@@ -252,12 +326,39 @@ export class GameScene extends Dream.RenderContainer {
this.rabbitContainer = rabbitCloneContainer this.rabbitContainer = rabbitCloneContainer
this.rabbitCloneContainer = rabbitContainer this.rabbitCloneContainer = rabbitContainer
} }
this.onPlatformLand(landPlatform)
resolve() resolve()
}) })
}) })
} }
/**
* 平台判断
* @param platform
*/
onPlatformLand(platform: Platform) {
platform.onLand((type: number, s: number) => {
if (type == 3) {
return this.onGameOver()
} else if (type == 2) {
this.double = 2
this.SpClockIns.onShowCountDown(() => {
this.double = 1
})
}
this.onAddScore(s)
})
}
/**
* 添加分数
* @param s
*/
onAddScore(s: number) {
this.ScoreBoardIns.score += s * this.double
}
GameJudgeFrame() { GameJudgeFrame() {
if (this.isPause) return if (this.isPause) return
// 当前兔子在屏幕上的 y // 当前兔子在屏幕上的 y
...@@ -285,7 +386,9 @@ export class GameScene extends Dream.RenderContainer { ...@@ -285,7 +386,9 @@ export class GameScene extends Dream.RenderContainer {
</DreamContainer> </DreamContainer>
<ScoreBoard /> <ScoreBoard ref={(el: ScoreBoard) => this.ScoreBoardIns = el} />
<SpClock ref={(el: SpClock) => this.SpClockIns = el} />
</DreamContainer> </DreamContainer>
) )
} }
......
import { DreamContainer } from "../../components/DreamContainer/DreamContainer"; import { DreamContainer } from "../../components/DreamContainer/DreamContainer";
import { DreamSprite } from "../../components/DreamSprite/DreamSprite"; import { DreamSprite } from "../../components/DreamSprite/DreamSprite";
import { DreamTextField } from "../../components/DreamTextField/DreamTextField";
import Dream from "../../Dream"; import Dream from "../../Dream";
import { fadeOutUpFactory } from "../../modules/animations";
import { RES } from "../../modules/RES"; import { RES } from "../../modules/RES";
import { GameConfig } from "./GameConfig";
export class Platform extends Dream.RenderContainer<{ export class Platform extends Dream.RenderContainer<{
type: number // 1 就是默认 2 道具 3 炸弹 type: number // 1 就是默认 2 道具 3 炸弹
x: number x: number
pos?: [number, number]
}> { }> {
private isLanded: boolean = false // 是否被踩过
private spCont: FYGE.Container
onLand(cb?: (type: number, s: number) => void) {
if (this.isLanded) return
this.isLanded = true
if (this.spCont) {
fadeOutUpFactory(500)(this.spCont)
}
cb && cb(this.props.type, GameConfig.landPlatformScore)
}
/**
* 渲染道具
* @returns
*/
renderSp() {
if (this.props.type == 2) {
return this.spCont = <DreamSprite inlineProps={{
x: 28,
y: -100
}} src={RES.getRes('sp_milk.png')} />
} else if (this.props.type == 3) {
return this.spCont = <DreamSprite inlineProps={{
x: 20,
y: -90
}} src={RES.getRes('sp_boom.png')} />
}
}
render() { render() {
const backRes = RES.getRes('platform.png') const backRes = RES.getRes('platform.png')
return ( return (
...@@ -16,6 +49,14 @@ export class Platform extends Dream.RenderContainer<{ ...@@ -16,6 +49,14 @@ export class Platform extends Dream.RenderContainer<{
<DreamSprite src={backRes} inlineProps={{ <DreamSprite src={backRes} inlineProps={{
x: 2 x: 2
}} /> }} />
{
this.renderSp()
}
{
GameConfig.debugger && this.props.pos && (
<DreamTextField text={this.props.pos.join(',')} />
)
}
</DreamContainer> </DreamContainer>
) )
} }
......
import { DreamContainer } from "../../components/DreamContainer/DreamContainer";
import { DreamSprite } from "../../components/DreamSprite/DreamSprite";
import { DreamTextField } from "../../components/DreamTextField/DreamTextField";
import Dream from "../../Dream";
import { layers } from "../../modules/layers";
import { RES } from "../../modules/RES";
import { GameConfig } from "./GameConfig";
export class SpClock extends Dream.RenderContainer {
RoleCont: FYGE.Container
CountText: FYGE.TextField
set visible(v: boolean) {
this.RoleCont.visible = v
}
_countTime: number = GameConfig.spCountTime
get countTime() {
return Math.floor(this._countTime / 1000 )
}
set countTime(v: number) {
this._countTime = v
this.CountText.text = Math.floor(v / 1000) + 's'
}
didRendered(): void {
this.visible = false
}
cobj = {t: 3000}
onShowCountDown(cb: Function) {
this.cobj.t = GameConfig.spCountTime
this.visible = true
FYGE.Tween.removeTweens(this.cobj)
FYGE.Tween.get(this.cobj, {
onChange: () => {
this.countTime = this.cobj.t
}
})
.to({
t: 0
}, GameConfig.spCountTime)
.call(() => {
this.visible = false
cb()
})
}
render() {
const roleCont = RES.getRes('clockBack.png')
return (
<DreamContainer ref={el => {
this.RoleCont = el
}} inlineProps={{
x: 640,
y: layers.stageOffsetY + 50
}}>
<DreamSprite src={roleCont} />
<DreamTextField
ref={el => this.CountText = el}
text={this.countTime + 's'} color="#ffffff"
textWidth={roleCont.width + 5}
textHeight={roleCont.height}
stroke={2}
size={32}
strokeColor="#a45549"
/>
</DreamContainer>
)
}
}
\ No newline at end of file
export class Tools { export class Tools {
static PageData: { static PageData: {
isFirstGame: boolean, isFirstGame: boolean
liveCard: number
} = { } = {
isFirstGame: false, isFirstGame: false
liveCard: 1
} }
} }
......
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