Commit 3bd5ba7f authored by Master Q's avatar Master Q

Go

parent d299bf9a
...@@ -70,8 +70,64 @@ ...@@ -70,8 +70,64 @@
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: false, isFirstGame: true,
skinName: 'c' skinName: 'c',
gameDiff: [],
extraFunc: (function(lc, et, es) {
let lifeCount = lc
let timer
let tweenSelf1
let tweenSelf2
function reset() {
for (let i = 0; i < arguments.length; i ++) {
arguments[i].alpha = 1
}
}
return function(type) {
// 炸弹
let cb = () => {}
if (type == 3) {
--lifeCount
if (lifeCount > 0) {
cb = function(r, c) {
clearTimeout(timer)
reset(r, c)
FYGE.Tween.removeTweenSelf(tweenSelf1)
FYGE.Tween.removeTweenSelf(tweenSelf2)
tweenSelf1 = FYGE.Tween.get(r, {
loop: true
}).to({
alpha: 0.5
}, 300).to({
alpha: 1
}, 300)
tweenSelf2 = FYGE.Tween.get(c, {
loop: true
}).to({
alpha: 0.5
}, 300).to({
alpha: 1
}, 300)
timer = setTimeout(() => {
reset(r, c)
FYGE.Tween.removeTweenSelf(tweenSelf1)
FYGE.Tween.removeTweenSelf(tweenSelf2)
}, 2000)
}
}
}
return {
extraScore: es,
done: lifeCount == 0,
extraTime: et,
landCb: cb
}
}
})(2, 2000, 20)
}) })
}) })
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"name": "GameScene" "name": "GameScene"
}, },
{ {
"keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png", "keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png,Guide5.png",
"name": "NewGuyScene" "name": "NewGuyScene"
}, },
{ {
......
...@@ -84,7 +84,7 @@ export const ResJson = { ...@@ -84,7 +84,7 @@ export const ResJson = {
} }
}, },
{ {
"keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png", "keys": "Guide1.png,Guide2.png,Guide3.png,Guide4.png,Guide5.png",
"name": "NewGuyScene", "name": "NewGuyScene",
"atlas": { "atlas": {
"Guide1.png": { "Guide1.png": {
...@@ -130,6 +130,17 @@ export const ResJson = { ...@@ -130,6 +130,17 @@ export const ResJson = {
"sw": 750, "sw": 750,
"sh": 1624, "sh": 1624,
"ro": true "ro": true
},
"Guide5.png": {
"x": 2258,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
} }
} }
}, },
...@@ -193,5 +204,5 @@ export const ResJson = { ...@@ -193,5 +204,5 @@ export const ResJson = {
} }
], ],
// eslint-disable-next-line // eslint-disable-next-line
"path": "https://yun.duiba.com.cn/db_games/activity/template/1671522711/resource/" "path": "https://yun.duiba.com.cn/db_games/activity/template/1677835925/resource/"
} }
\ No newline at end of file
...@@ -39,6 +39,11 @@ export class Main { ...@@ -39,6 +39,11 @@ export class Main {
canvas: HTMLCanvasElement, canvas: HTMLCanvasElement,
config: { config: {
isFirstGame: boolean isFirstGame: boolean
skinName: string,
gameDiff: {
score: number
speed: number
}[]
}, },
desWidth = 750, desWidth = 750,
desHeight = 1624, desHeight = 1624,
......
...@@ -19,12 +19,50 @@ export const GameConfig = { ...@@ -19,12 +19,50 @@ export const GameConfig = {
}, },
DecisionLine: [ DecisionLine: [
// 判定线 当前屏幕显示区域 // 判定线 当前屏幕显示区域
300, 800,
layers.stageHeight, // 这里个需要后续设定 layers.stageHeight, // 这里个需要后续设定
], ],
landPlatformScore: 2, // 平台上的分数 landPlatformScore: 2, // 平台上的分数
spCountTime: 3100, //道具倒计时 spCountTime: 3100, //道具倒计时
boxColNum: 5, // 几列格子 boxColNum: 5, // 几列格子
sptMap: {
initPos: {
x: 1,
y: 26,
},
boxMap: [
[0, 0, 1, 0, 0],
[0, 0, 1, 2, 0],
[0, 0, 1, 1, 0],
[0, 1, 0, 0, 1],
[0, 0, 1, 1, 0],
[0, 0, 0, 1, 1],
[0, 0, 1, 1, 0],
[0, 2, 1, 0, 0],
[1, 0, 0, 1, 0],
[0, 0, 1, 0, 1],
[0, 1, 0, 1, 0],
[1, 0, 1, 0, 0],
[0, 1, 0, 0, 1],
[1, 0, 0, 1, 0],
[0, 1, 2, 0, 0],
[0, 1, 1, 0, 0],
[1, 0, 0, 1, 0],
[0, 2, 0, 0, 1],
[1, 0, 1, 0, 0],
[1, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
[1, 1, 0, 1, 0],
[0, 0, 1, 0, 1],
[1, 0, 0, 6, 1],
[0, 1, 0, 1, 0],
[0, 1, 1, , 0],
[1, 1, 0, 0, 0],
[0, 0, 1, 0, 1],
[0, 1, 0, 2, 0],
[0, 0, 1, 0, 0],
],
},
mapList: [ mapList: [
{ {
initPos: { initPos: {
...@@ -61,7 +99,7 @@ export const GameConfig = { ...@@ -61,7 +99,7 @@ export const GameConfig = {
[0, 3, 1, 0, 4], [0, 3, 1, 0, 4],
[4, 0, 0, 5, 0], [4, 0, 0, 5, 0],
[0, 4, 2, 0, 1], [0, 4, 2, 0, 1],
[1, 1, 5, 2, 1], [1, 1, 1, 1, 1],
], ],
}, },
{ {
...@@ -99,7 +137,7 @@ export const GameConfig = { ...@@ -99,7 +137,7 @@ export const GameConfig = {
[1, 0, 1, 0, 0], [1, 0, 1, 0, 0],
[0, 0, 1, 0, 4], [0, 0, 1, 0, 4],
[4, 0, 0, 4, 0], [4, 0, 0, 4, 0],
[0, 1, 4, 1, 0], [0, 1, 1, 1, 0],
], ],
}, },
{ {
...@@ -137,7 +175,7 @@ export const GameConfig = { ...@@ -137,7 +175,7 @@ export const GameConfig = {
[0, 0, 1, 0, 5], [0, 0, 1, 0, 5],
[1, 4, 0, 0, 0], [1, 4, 0, 0, 0],
[0, 0, 0, 4, 1], [0, 0, 0, 4, 1],
[1, 5, 1, 0, 4], [1, 1, 1, 0, 1],
], ],
}, },
{ {
......
...@@ -6,7 +6,7 @@ import Dream from "../../Dream"; ...@@ -6,7 +6,7 @@ import Dream from "../../Dream";
import { layers } from "../../modules/layers"; import { layers } from "../../modules/layers";
import { RES } from "../../modules/RES"; import { RES } from "../../modules/RES";
import { UsePreload } from "../../modules/UseDecorator/usePreload"; import { UsePreload } from "../../modules/UseDecorator/usePreload";
import { PromiseAwait, PromiseAwaitCacheMap } from "../../tools/Tools"; import { PromiseAwait, PromiseAwaitCacheMap, Tools } from "../../tools/Tools";
import { GameConfig } from "./GameConfig"; import { GameConfig } from "./GameConfig";
import { G_Events } from "./GameEvents"; import { G_Events } from "./GameEvents";
import { Platform } from "./Platform"; import { Platform } from "./Platform";
...@@ -62,13 +62,15 @@ export class GameScene extends Dream.RenderContainer { ...@@ -62,13 +62,15 @@ export class GameScene extends Dream.RenderContainer {
rabbitIns: PlayerIns rabbitIns: PlayerIns
cloneRabbitIns: PlayerIns cloneRabbitIns: PlayerIns
GuidanceCont: FYGE.Container
set dir(v: number) { set dir(v: number) {
this.rabbitContainer.scaleX = v this.rabbitContainer.scaleX = v
this.rabbitCloneContainer.scaleX = v this.rabbitCloneContainer.scaleX = v
} }
didRendered(): void { didRendered(): void {
this.renderMap(true) this.renderMap(true, GameConfig.sptMap)
this.initEvents() this.initEvents()
...@@ -77,7 +79,6 @@ export class GameScene extends Dream.RenderContainer { ...@@ -77,7 +79,6 @@ export class GameScene extends Dream.RenderContainer {
unMount(): void { unMount(): void {
this.removeEvents() this.removeEvents()
PromiseAwaitCacheMap.clear() PromiseAwaitCacheMap.clear()
} }
...@@ -124,6 +125,7 @@ export class GameScene extends Dream.RenderContainer { ...@@ -124,6 +125,7 @@ export class GameScene extends Dream.RenderContainer {
this.onShowRabbitAni(RabbitActionMap.Fail) this.onShowRabbitAni(RabbitActionMap.Fail)
FYGE.Tween.removeTweens(this.rabbitContainer) FYGE.Tween.removeTweens(this.rabbitContainer)
FYGE.Tween.removeTweens(this.rabbitCloneContainer)
this.isPause = true this.isPause = true
GDispatcher.dispatchEvent(G_Events.GameOver, this.ScoreBoardIns.score) GDispatcher.dispatchEvent(G_Events.GameOver, this.ScoreBoardIns.score)
...@@ -141,10 +143,13 @@ export class GameScene extends Dream.RenderContainer { ...@@ -141,10 +143,13 @@ export class GameScene extends Dream.RenderContainer {
* 开始渲染地图 * 开始渲染地图
* @param init 是否是初始化 * @param init 是否是初始化
*/ */
renderMap(init: boolean = false) { renderMap(init: boolean = false, mapConfig?: any) {
const index = Math.random() * GameConfig.mapList.length >> 0 if (!mapConfig) {
console.info('=========render map ===========:', index) const index = Math.random() * GameConfig.mapList.length >> 0
const mapConfig = GameConfig.mapList[index] console.info('=========render map ===========:', index)
mapConfig = GameConfig.mapList[index]
}
const { const {
rowNum, rowNum,
offsetYLen offsetYLen
...@@ -201,10 +206,10 @@ export class GameScene extends Dream.RenderContainer { ...@@ -201,10 +206,10 @@ export class GameScene extends Dream.RenderContainer {
if ( if (
colItem colItem
) { ) {
return <Platform ref={el => { return <Platform ref={(el: Platform) => {
rowArr[colIndex] = el rowArr[colIndex] = el
}} }}
pos={[rowIndex, colIndex]} type={colItem} x={colIndex * offsetXLen} /> pos={[rowIndex, colIndex]} type={colItem % 4} x={colIndex * offsetXLen} />
} else { } else {
rowArr[colIndex] = undefined rowArr[colIndex] = undefined
return undefined return undefined
...@@ -219,8 +224,6 @@ export class GameScene extends Dream.RenderContainer { ...@@ -219,8 +224,6 @@ export class GameScene extends Dream.RenderContainer {
, 0) , 0)
this.mapCount += 1 this.mapCount += 1
// 增加速度
GameConfig.speed += GameConfig.mapChangeAddSpeed
this.rabbitBoxMap.unshift(...mapPlatform) this.rabbitBoxMap.unshift(...mapPlatform)
// 第三章图片的话,清楚掉第一张地图 // 第三章图片的话,清楚掉第一张地图
...@@ -327,7 +330,7 @@ export class GameScene extends Dream.RenderContainer { ...@@ -327,7 +330,7 @@ export class GameScene extends Dream.RenderContainer {
const afterCb = this.onPlatformLand(landPlatform) const afterCb = this.onPlatformLand(landPlatform)
FYGE.Tween.removeTweens(rabbitContainer) // FYGE.Tween.removeTweens(rabbitContainer)
if (rax == 4) { if (rax == 4) {
rabbitCloneContainer.visible = true rabbitCloneContainer.visible = true
rabbitCloneContainer.position.set(rabbitContainer.x - 750, rabbitContainer.y) rabbitCloneContainer.position.set(rabbitContainer.x - 750, rabbitContainer.y)
...@@ -381,8 +384,19 @@ export class GameScene extends Dream.RenderContainer { ...@@ -381,8 +384,19 @@ export class GameScene extends Dream.RenderContainer {
let noop = () => {} let noop = () => {}
platform.onLand((type: number, s: number, cb: Function) => { platform.onLand((type: number, s: number, cb: Function) => {
const extraConfig = Tools.PageData.extraFunc
? Tools.PageData.extraFunc(type)
: {
extraScore: 0,
done: false,
extraTime: 0,
landCb: () => {}
}
const isDone = type == 3 && extraConfig.done
// pre 去做动作吧 // pre 去做动作吧
if (type == 3) { if (isDone) {
this.onShowRabbitAni(RabbitActionMap.Jump, RabbitActionMap.Fail) this.onShowRabbitAni(RabbitActionMap.Jump, RabbitActionMap.Fail)
} else if (type == 2) { } else if (type == 2) {
this.onShowRabbitAni(RabbitActionMap.Jump, RabbitActionMap.Smile) this.onShowRabbitAni(RabbitActionMap.Jump, RabbitActionMap.Smile)
...@@ -393,15 +407,16 @@ export class GameScene extends Dream.RenderContainer { ...@@ -393,15 +407,16 @@ export class GameScene extends Dream.RenderContainer {
// 落地的回调 // 落地的回调
noop = () => { noop = () => {
cb() cb()
if (type == 3) { extraConfig.landCb(this.rabbitContainer, this.rabbitCloneContainer)
if (isDone) {
return this.onGameOver() return this.onGameOver()
} else if (type == 2) { } else if (type == 2) {
this.double = 2 this.double = 2
this.SpClockIns.onShowCountDown(() => { this.SpClockIns.onShowCountDown(() => {
this.double = 1 this.double = 1
}) }, extraConfig.extraTime)
} }
this.onAddScore(s) this.onAddScore(s + extraConfig.extraScore || 0)
} }
}) })
...@@ -414,6 +429,12 @@ export class GameScene extends Dream.RenderContainer { ...@@ -414,6 +429,12 @@ export class GameScene extends Dream.RenderContainer {
*/ */
onAddScore(s: number) { onAddScore(s: number) {
this.ScoreBoardIns.score += s * this.double this.ScoreBoardIns.score += s * this.double
const currScore = this.ScoreBoardIns.score
const speedScoreMap = Tools.PageData.gameDiff
const currConfig = speedScoreMap.find(it => currScore < it.score) || {speed: 200}
GameConfig.speed = currConfig.speed
console.info('游戏速度:', GameConfig.speed, currConfig)
} }
GameJudgeFrame() { GameJudgeFrame() {
...@@ -446,6 +467,10 @@ export class GameScene extends Dream.RenderContainer { ...@@ -446,6 +467,10 @@ export class GameScene extends Dream.RenderContainer {
<ScoreBoard ref={(el: ScoreBoard) => this.ScoreBoardIns = el} /> <ScoreBoard ref={(el: ScoreBoard) => this.ScoreBoardIns = el} />
<SpClock ref={(el: SpClock) => this.SpClockIns = el} /> <SpClock ref={(el: SpClock) => this.SpClockIns = el} />
<DreamContainer ref={el => {
this.GuidanceCont = el
}}></DreamContainer>
</DreamContainer> </DreamContainer>
) )
} }
......
export class Guidance {
parent: FYGE.Container
currStep: number
pause: () => void
play: () => void
constructor(
parent: FYGE.Container,
currStep: number,
pause: () => void,
play: () => void
) {
this.parent = parent
this.currStep = currStep
this.pause = pause
this.play = play
}
showGuide(pos: any, s: number) {
const {currStep, parent} = this
if (!(s > currStep)) {
return
}
this.currStep ++
this.pause()
parent.removeAllChildren()
const shape = new FYGE.Graphics()
shape.beginFill('#000000', 0.7)
.drawRect(0,0,750,1624)
.endFill()
.beginHole()
.arc(pos.x, pos.y, 150, 0, 2 * Math.PI)
.endHole()
parent.addChild(shape)
switch(currStep) {
case 1:
break
}
}
}
\ No newline at end of file
import { layers } from "../../modules/layers"
type CallArgs<T extends any> = {
isIntersecting: boolean,
target: T,
pos: FYGE.Point
}
type EventCall<T extends any> = (e?: CallArgs<T>) => any
type OffsetPos = {x: number, y: number}
export class IntersectionObserver<TE extends FYGE.Container> {
private obCallBack?: (changes: CallArgs<TE>[]) => void
entries: {
t: TE,
offset: OffsetPos
cb: EventCall<TE>
}[] = []
constructor(obCallBack?: (changes: CallArgs<TE>[]) => void) {
this.entries = []
this.obCallBack = obCallBack
}
flush() {
const _copy = this.entries.slice(0)
const tempPoint = new FYGE.Point()
const result = []
for (let i = _copy.length - 1; i >= 0; i--) {
const currItem = _copy[i]
tempPoint.set(currItem.offset.x, currItem.offset.y)
const p = currItem.t.localToGlobal(tempPoint)
if (p.x >= 0 && p.y >= layers.stageOffsetY && p.x <= layers.stageWidth && p.y <= layers.stageOffsetY + layers.stageHeight) {
const arg = {
target: currItem.t,
isIntersecting: true,
pos: p
}
currItem.cb(arg)
result.push(arg)
}
}
this.obCallBack && this.obCallBack(result)
}
observe<T extends TE>(target: T, offset: OffsetPos={x: 0, y: 0}, cb?: EventCall<T>) {
this.entries.push({
t: target,
offset,
cb
})
}
unobserve<T extends TE>(target: T) {
const i = this.entries.findIndex(c => c.t == target)
i !== -1 && this.entries.splice(i, 1)
}
unobserveAll() {
this.entries.length = 0
}
}
...@@ -26,8 +26,8 @@ export class SpClock extends Dream.RenderContainer { ...@@ -26,8 +26,8 @@ export class SpClock extends Dream.RenderContainer {
} }
cobj = {t: 3000} cobj = {t: 3000}
onShowCountDown(cb: Function) { onShowCountDown(cb: Function, exT: number) {
this.cobj.t = GameConfig.spCountTime this.cobj.t = GameConfig.spCountTime + exT
this.visible = true this.visible = true
FYGE.Tween.removeTweens(this.cobj) FYGE.Tween.removeTweens(this.cobj)
FYGE.Tween.get(this.cobj, { FYGE.Tween.get(this.cobj, {
...@@ -37,7 +37,7 @@ export class SpClock extends Dream.RenderContainer { ...@@ -37,7 +37,7 @@ export class SpClock extends Dream.RenderContainer {
}) })
.to({ .to({
t: 0 t: 0
}, GameConfig.spCountTime) }, GameConfig.spCountTime + exT)
.call(() => { .call(() => {
this.visible = false this.visible = false
cb() cb()
......
...@@ -32,20 +32,25 @@ export class NewGuyScene extends Dream.RenderContainer { ...@@ -32,20 +32,25 @@ export class NewGuyScene extends Dream.RenderContainer {
break break
case 2: case 2:
this.GuideContainer.addChild(<DreamContainer onClick={nextStep}> this.GuideContainer.addChild(<DreamContainer onClick={nextStep}>
<DreamSprite src={RES.getRes('Guide2.png')} /> <DreamSprite src={RES.getRes('Guide5.png')} />
</DreamContainer>) </DreamContainer>)
break break
case 3: case 3:
this.GuideContainer.addChild(<DreamContainer onClick={nextStep}> this.GuideContainer.addChild(<DreamContainer onClick={nextStep}>
<DreamSprite src={RES.getRes('Guide3.png')} /> <DreamSprite src={RES.getRes('Guide2.png')} />
</DreamContainer>) </DreamContainer>)
break break
case 4: case 4:
this.GuideContainer.addChild(<DreamContainer onClick={nextStep}> this.GuideContainer.addChild(<DreamContainer onClick={nextStep}>
<DreamSprite src={RES.getRes('Guide4.png')} /> <DreamSprite src={RES.getRes('Guide3.png')} />
</DreamContainer>) </DreamContainer>)
break break
case 5: case 5:
this.GuideContainer.addChild(<DreamContainer onClick={nextStep}>
<DreamSprite src={RES.getRes('Guide4.png')} />
</DreamContainer>)
break
case 6:
// 完成新手引导 // 完成新手引导
SceneController.changeScene(GameScene) SceneController.changeScene(GameScene)
break break
......
type ExtraConfig = {
extraScore: number,
done: boolean
extraTime: number,
landCb: (...args: any[]) => void
}
export class Tools { export class Tools {
static PageData: { static PageData: {
isFirstGame: boolean isFirstGame: boolean
skinName: string skinName: string,
gameDiff: {
score: number
speed: number
}[],
extraFunc?: (...args: any[]) => ExtraConfig
} = { } = {
isFirstGame: false, isFirstGame: false,
skinName: '' skinName: '',
gameDiff: []
} }
} }
......
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