Commit 11e1b71d authored by Master Q's avatar Master Q

1

parent c687a1b6
......@@ -70,6 +70,9 @@
var main = new Main(canvas, {
isNewGuy: true
});
setTimeout(() => {
GDispatcher.dispatchEvent('GAME_START')
}, 1000)
var mouseEvent = main.stage.onMouseEvent.bind(main.stage);
canvas.addEventListener("touchstart", mouseEvent, false);
canvas.addEventListener('touchmove', mouseEvent, false);
......
......@@ -376,5 +376,5 @@ export const ResJson = {
}
}
],
"path": "https://yun.duiba.com.cn/db_games/activity/template/1646301974/resource/"
"path": "https://yun.duiba.com.cn/db_games/activity/template/1646360490/resource/"
}
\ No newline at end of file
......@@ -39,7 +39,8 @@ export const myApp:AppType = getApp()
export class Tools {
public static PAGE = {
isNewGuy: false
isNewGuy: false,
countDownNum: 30
};
/**
......
......@@ -15,6 +15,7 @@ function randomNum(m: number, n: number) {
const GameEvent = {
GAME_START: 'GAME_START',
GAME_OVER: 'GAME_OVER',
}
class CountDownBoard extends FYGE.Container {
......@@ -392,16 +393,15 @@ export default class IndexScene extends Scene {
async start(data?: any) {
super.start()
}
/**
* 初始化倒计时器
*/
initCountDown() {
this.CountDownCont = this.addChild(new CountDownBoard(100))
this.CountDownCont = this.addChild(new CountDownBoard(Tools.PAGE.countDownNum))
this.CountDownCont.position.set(0, layers.stageOffsetY + 100)
this.CountDownCont.addEventListener('countdown', this.onGameOver, this)
}
/**
......@@ -494,9 +494,12 @@ export default class IndexScene extends Scene {
* 游戏开始
*/
async onGameStart() {
this.score = 0
if (Tools.PAGE.isNewGuy) {
await this.onShowNewGuySteps()
}
this.recoverGameEles()
this.onInitGamer()
await this.onShowPreCountDown()
this.GameStatus = 1
this.CountDownCont.restart()
......@@ -508,22 +511,26 @@ export default class IndexScene extends Scene {
onGameOver() {
this.GameStatus = 0
this.CountDownCont.stopCountDown()
GDispatcher.dispatchEvent(GameEvent.GAME_OVER, {
score: this.score
})
}
/**
* 初始化游戏元素
*/
onInitGamer() {
if (!this.RobotGameEle) {
this.RobotGameEle = this.addChild(new GameEleSprit('robotGamer.png'))
this.RobotGameEle.position.set(375 - this.RobotGameEle.width / 2, 1100)
this.RobotGameEle.addPythicCont(new RectPythicCont(50, 190, 100, 60), true)
}
this.RobotGameEle.position.set(375 - this.RobotGameEle.width / 2, 1100)
}
/**
* 初始化游戏掉落元素
*/
onInitFallGameEle() {
console.log('onInitFallGameEle')
this.spl = randomNum(40, 300)
const curr = this.currGameEleResource
const currResource: GameEleResource = curr.resource
......@@ -590,6 +597,15 @@ export default class IndexScene extends Scene {
this.RobotGameEle.position.set(this.startRobotPos.x + currPos.x - this.startPos.x, this.startRobotPos.y)
}
recoverGameEles() {
for (let i = 0; i < this.gameElesList.length; i++) {
const gameEle = this.gameElesList[i];
gameEle.visible = false
GPool.takeIn(gameEle.resource, gameEle)
}
this.gameElesList.length = 0
}
_cacheLen:number = 0
frameUpdate() {
if (!this.GameStatus) return
......@@ -601,17 +617,18 @@ export default class IndexScene extends Scene {
this.onInitFallGameEle()
}
this.gameElesList.forEach((item) => {
for (let i = this.gameElesList.length - 1; i >= 0; i--) {
const item = this.gameElesList[i]
item.y += sdt
if (item.y > 1624) {
item.visible = false
GPool.takeIn(item.resource, item)
this.gameElesList.splice(this.gameElesList.indexOf(item), 1)
this.gameElesList.splice(i, 1)
}
if (onCollsionJudge(item.pythicCont.commonPythicPos, this.RobotGameEle.pythicCont.commonPythicPos)) {
item.visible = false
GPool.takeIn(item.resource, item)
this.gameElesList.splice(this.gameElesList.indexOf(item), 1)
this.gameElesList.splice(i, 1)
// console.log(item)
if (item.score == -1) {
console.log('boom', item)
......@@ -619,7 +636,7 @@ export default class IndexScene extends Scene {
}
this.score += item.score
}
})
}
}
......
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