Commit 5432b50e authored by 王勇霞's avatar 王勇霞

feat: 记录

parent e7e92de9
...@@ -2,10 +2,8 @@ import { Scene } from "../../module/views/Scene"; ...@@ -2,10 +2,8 @@ import { Scene } from "../../module/views/Scene";
import * as Matter from "matter-js"; import * as Matter from "matter-js";
import Role from "./components/Role"; import Role from "./components/Role";
import AddProp from "./components/AddProp"; import AddProp from "./components/AddProp";
import { RES } from "../../module/RES";
import ObstacleProp from "./components/ObstacleProp"; import ObstacleProp from "./components/ObstacleProp";
import MapItem from "./components/MapItem"; import MapItem from "./components/MapItem";
import Cloud from "./components/Cloud";
import { getWebData, WebNetName, sendWebNet, sendLog, LOG_TYPE } from "../webNet"; import { getWebData, WebNetName, sendWebNet, sendLog, LOG_TYPE } from "../webNet";
import { showPanel, showToast, changeScene } from "../../module/ctrls"; import { showPanel, showToast, changeScene } from "../../module/ctrls";
import { GuidePanel } from "../panels/GuidePanel"; import { GuidePanel } from "../panels/GuidePanel";
...@@ -14,130 +12,74 @@ import { SuccessPanel } from "../panels/SuccessPanel"; ...@@ -14,130 +12,74 @@ import { SuccessPanel } from "../panels/SuccessPanel";
import { FailPanel } from "../panels/FailPanel"; import { FailPanel } from "../panels/FailPanel";
import { duiba_md5 } from "../../module/tools/security"; import { duiba_md5 } from "../../module/tools/security";
import { Tools } from "../Tools"; import { Tools } from "../Tools";
import { playAllSound, stopAllSound, cusPlaySound } from "../common/SoundWeb";
import { layers } from "../../module/views/layers"; import { layers } from "../../module/views/layers";
import UI from "../UI";
export class GameScene extends Scene { export class GameScene extends Scene {
get groupNames() { return ["GameScene"] }; get groupNames() { return ["GameScene"] };
get skinName() { return "GameScene" }; get skinName() { return "GameScene" };
bg: FYGE.Sprite; bg: FYGE.Sprite;
left;
right;
cdbg: FYGE.Sprite;
bgCon; //背景移动
cdnum: FYGE.TextField;
cloud: FYGE.Sprite; cloud: FYGE.Sprite;
peo: FYGE.Sprite; peo: FYGE.Sprite;
tianpop: FYGE.Sprite; tianpop: FYGE.Sprite;
xiangpop: FYGE.Sprite; xiangpop: FYGE.Sprite;
monster: FYGE.Sprite; monster: FYGE.Sprite;
right: FYGE.Sprite;
left: FYGE.Sprite;
scorebg: FYGE.Sprite; scorebg: FYGE.Sprite;
scorenum: FYGE.TextField; scorenum: FYGE.TextField;
cdbg: FYGE.Sprite;
cdnum: FYGE.TextField;
close: FYGE.Sprite; close: FYGE.Sprite;
open: FYGE.Sprite; open: FYGE.Sprite;
jumpLock = false; jumpLock = false;
isonce = false; isonce = false;
score;
time;
public static instance: GameScene; public static instance: GameScene;
initUi() { initUi() {
} }
async start(data) { start(data) {
super.start(); super.start();
sendLog(LOG_TYPE.EXPOSURE,37)
GameScene.instance = this GameScene.instance = this
console.log("新手引导") showPanel(GuidePanel);
// showPanel(GuidePanel);
if (Tools.isMusic) {
this.left = new FYGE.SvgaAni(await RES.getResAsync("left.svga")) this.open.visible = true;
this.left = this.addChild(this.left) this.close.visible = false
this.left.position.set(8, 979); cusPlaySound("bg", true)
this.left.startAniRange(1, 1, 1); } else {
this.right = new FYGE.SvgaAni(await RES.getResAsync("right.svga")) this.open.visible = false;
this.right = this.addChild(this.right) this.close.visible = true
this.right.position.set(524, 979); }
this.right.startAniRange(1, 1, 1);
// this.cdUIRender(StartScene.instance.gameInfo.duration)
this.cdUIRender()
this.createPhyWorld() this.createPhyWorld()
this.bgCon = this.addChild(new FYGE.Container()); this.bgCon = this.addChild(new FYGE.Container());
this.setChildIndex(this.bgCon, 2) this.setChildIndex(this.bgCon, 2)
this.initCloud(); this.initMap();
this.scorenum.text = "0"
// this.createPhyWorld() this.cdnum.text = StartScene.instance.gameInfo.duration
// this.bgCon = this.addChild(new FYGE.Container());
// this.setChildIndex(this.bgCon, 2)
// this.initMap();
// this.scorenum.text = "0"
// this.cdnum.text = StartScene.instance.gameInfo.duration
}
cdUIRender(num=17) {
// 先清除所有节点
this.cdbg.removeChildren();
let str = num + 's';
let arr = str.split("");
let startPos = (130 - (30*arr.length))/2
arr.forEach((item, index) => {
UI.Sp(this.cdbg, `num_${item}.png`, startPos + (index*30), 38)
})
}
initCloud() {
let stageHeight = this.stage.stageHeight;
// 渲染人物脚下的一朵云层
UI.Sp(this.bgCon, 'cloud2.png', 190, stageHeight-310)
this.createCloudItem(stageHeight - 600, 'left', false);
// for (let i = 0; i < 4; i++) {
// if (i < 4) {
// this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
// } else {
// this.createLineItem(stageHeight - (240 * (i + 2)));
// }
// }
} }
/** score;
* time;
* @param h
* @param direction 方向 left right
* @param isprop
*/
createCloudItem(h, direction?: string, isprop = true) {
let nx = direction === 'left' ? 88 : 440;
let cloudItem = new Cloud();
cloudItem.fx = nx;
cloudItem.fy = h
this.bgCon.addChildAt(cloudItem, 0)
this.composites.add(this.world, [cloudItem.phyBody]);
}
changeMusic() {
this.open.visible = !this.open.visible
this.close.visible = !this.close.visible
Tools.isMusic = !Tools.isMusic
if (Tools.isMusic) {
// playAllSound()
cusPlaySound("bg", true)
} else {
stopAllSound()
}
}
upDateInfo() { upDateInfo() {
this.score = 0 this.score = 0
this.time = StartScene.instance.gameInfo.duration this.time = StartScene.instance.gameInfo.duration
...@@ -169,7 +111,7 @@ export class GameScene extends Scene { ...@@ -169,7 +111,7 @@ export class GameScene extends Scene {
this.composites.add(this.world, [this._role.phyBody]); this.composites.add(this.world, [this._role.phyBody]);
} }
_role; //人物 _role; //人物
bgCon; //背景移动
addRole() { addRole() {
let offset = (1624 - this.stage.viewRect.height) / 2; let offset = (1624 - this.stage.viewRect.height) / 2;
...@@ -205,6 +147,8 @@ export class GameScene extends Scene { ...@@ -205,6 +147,8 @@ export class GameScene extends Scene {
Matter.Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this)); Matter.Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this));
Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this)); Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this));
} }
onCollisionTick(e) { onCollisionTick(e) {
} }
...@@ -224,6 +168,9 @@ export class GameScene extends Scene { ...@@ -224,6 +168,9 @@ export class GameScene extends Scene {
num = 2 num = 2
} }
this._role.addScore('+' + num, '#ffffff') this._role.addScore('+' + num, '#ffffff')
if (Tools.isMusic) {
cusPlaySound("get", false)
}
this.scorenum.text = Number(this.scorenum.text) + num + ''; this.scorenum.text = Number(this.scorenum.text) + num + '';
this.score += num this.score += num
...@@ -235,6 +182,9 @@ export class GameScene extends Scene { ...@@ -235,6 +182,9 @@ export class GameScene extends Scene {
} else if (p.bodyB.gameType == 'dieProp' || p.bodyA.gameType == 'dieProp') { } else if (p.bodyB.gameType == 'dieProp' || p.bodyA.gameType == 'dieProp') {
// 死亡💀 // 死亡💀
console.log("死亡") console.log("死亡")
if (Tools.isMusic) {
cusPlaySound("fail", false)
}
let body = p.bodyB.gameType == 'dieProp' ? p.bodyB : p.bodyA; let body = p.bodyB.gameType == 'dieProp' ? p.bodyB : p.bodyA;
let prop = this.obstaclePropMap.get(body.id); let prop = this.obstaclePropMap.get(body.id);
this.composites.remove(this.world, prop.phyBody); this.composites.remove(this.world, prop.phyBody);
...@@ -247,6 +197,9 @@ export class GameScene extends Scene { ...@@ -247,6 +197,9 @@ export class GameScene extends Scene {
this.gameOver() this.gameOver()
} else { } else {
if (!this.jumpLock) { if (!this.jumpLock) {
if (Tools.isMusic) {
cusPlaySound("jump", false)
}
this._role.jump() this._role.jump()
this.jumpLock = true; this.jumpLock = true;
setTimeout(() => { setTimeout(() => {
...@@ -265,13 +218,13 @@ export class GameScene extends Scene { ...@@ -265,13 +218,13 @@ export class GameScene extends Scene {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
// if (i < 4) { if (i < 4) {
// this.createLineItem(stageHeight - (240 * (i + 2)), 0, false); this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
// } else { } else {
// this.createLineItem(stageHeight - (240 * (i + 2))); this.createLineItem(stageHeight - (240 * (i + 2)));
// } }
} }
...@@ -425,18 +378,23 @@ export class GameScene extends Scene { ...@@ -425,18 +378,23 @@ export class GameScene extends Scene {
} }
initEvents() { initEvents() {
super.initEvents(); super.initEvents();
// this.left.addEventListener(FYGE.MouseEvent.CLICK, () => { this.left.addEventListener(FYGE.MouseEvent.CLICK, () => {
// sendLog(LOG_TYPE.CLICK,37) sendLog(LOG_TYPE.CLICK,37)
// this._role.leftMove() this._role.leftMove()
// }) })
// this.right.addEventListener(FYGE.MouseEvent.CLICK, () => { this.right.addEventListener(FYGE.MouseEvent.CLICK, () => {
// sendLog(LOG_TYPE.CLICK,37) sendLog(LOG_TYPE.CLICK,37)
// this._role.rightMove() this._role.rightMove()
// }) })
this.open.addEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this)
this.close.addEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this)
} }
removeEvents() { removeEvents() {
super.removeEvents(); super.removeEvents();
this.open.removeEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this)
this.close.removeEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this)
stopAllSound()
} }
} }
...@@ -30,6 +30,7 @@ export class GameScene extends Scene { ...@@ -30,6 +30,7 @@ export class GameScene extends Scene {
_role; //人物 _role; //人物
wordList = ['闲', '看', '晴', '云', '自', '卷', '舒', '静', '水', '流', '深', '心', '无', '意', '在', '休']; // 待随机出现的列表 wordList = ['闲', '看', '晴', '云', '自', '卷', '舒', '静', '水', '流', '深', '心', '无', '意', '在', '休']; // 待随机出现的列表
collectList = []; // 已收集列表 collectList = []; // 已收集列表
mapList = [];
...@@ -56,7 +57,7 @@ export class GameScene extends Scene { ...@@ -56,7 +57,7 @@ export class GameScene extends Scene {
jumpLock = false; jumpLock = false;
isonce = false; isonce = false;
score; score;
time;
public static instance: GameScene; public static instance: GameScene;
initUi() { initUi() {
...@@ -68,6 +69,7 @@ export class GameScene extends Scene { ...@@ -68,6 +69,7 @@ export class GameScene extends Scene {
console.log("新手引导") console.log("新手引导")
// showPanel(GuidePanel); // showPanel(GuidePanel);
this.left = new FYGE.SvgaAni(await RES.getResAsync("left.svga")) this.left = new FYGE.SvgaAni(await RES.getResAsync("left.svga"))
this.left = this.addChild(this.left) this.left = this.addChild(this.left)
this.left.position.set(8, 979); this.left.position.set(8, 979);
...@@ -82,7 +84,24 @@ export class GameScene extends Scene { ...@@ -82,7 +84,24 @@ export class GameScene extends Scene {
this.bgCon = this.addChild(new FYGE.Container()); this.bgCon = this.addChild(new FYGE.Container());
this.setChildIndex(this.bgCon, 2) this.setChildIndex(this.bgCon, 2)
this.initCloud(); this.initCloud();
this.cdUIRender(StartScene.instance.gameInfo.duration)
this.upDateInfo(); // 用于开始游戏 ----test
// 添加指向的事件
this.left.addEventListener(FYGE.MouseEvent.CLICK, () => {
this.left.startAniRange(1, undefined, 1, () => {
let item = this._role.currentIndex < 0 ? this.mapList[0] : this.mapList[this._role.currentIndex]
this._role.leftMove({
item: item
})
})
})
this.right.addEventListener(FYGE.MouseEvent.CLICK, () => {
this.right.startAniRange(1, undefined, 1, () => {
console.log("播放完成")
this._role.rightMove()
})
})
// this.createPhyWorld() // this.createPhyWorld()
// this.bgCon = this.addChild(new FYGE.Container()); // this.bgCon = this.addChild(new FYGE.Container());
...@@ -91,8 +110,59 @@ export class GameScene extends Scene { ...@@ -91,8 +110,59 @@ export class GameScene extends Scene {
// this.scorenum.text = "0" // this.scorenum.text = "0"
// this.cdnum.text = StartScene.instance.gameInfo.duration // this.cdnum.text = StartScene.instance.gameInfo.duration
} }
engine; // matter引擎初始化
composites;
world;
runner;
ground;
addPropsMap = new Map();
obstaclePropMap = new Map();
private createPhyWorld() {
const { Engine, Render, Runner, Composite, Bodies, World, Composites } = Matter;
this.engine = Engine.create(
{
enableSleeping: true
}
);
this.world = this.engine.world;
this.engine.gravity.y = 1.5;
/** 真正运行 */
this.runner = Runner.create();
Runner.run(this.runner, this.engine);
// @ts-ignore
this.composites = Composite;
Matter.Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this));
Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this));
}
upDateInfo() {
this.time = Number(StartScene.instance.gameInfo.duration)
this.cdUIRender(this.time)
this.startGame()
// this.countDown(this.time)
}
startGame() {
this.addEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
// this.composites.add(this.world, [this._role.phyBody]);
}
time;
timer = null;
countDown(time) {
this.timer = setTimeout(() => {
// if (this.time <= 0) {
// clearTimeout(this.timer);
// this.composites.remove(this.world, this._role.phyBody);
// this.gameOver()
// return
// }
this.time = this.time - 1;
this.cdUIRender(this.time)
this.countDown(this.time)
}, 1000)
}
cdUIRender(num=17) { cdUIRender(num=60) {
// 先清除所有节点 // 先清除所有节点
this.cdbg.removeChildren(); this.cdbg.removeChildren();
let str = num + 's'; let str = num + 's';
...@@ -126,12 +196,17 @@ export class GameScene extends Scene { ...@@ -126,12 +196,17 @@ export class GameScene extends Scene {
*/ */
createCloudItem(h, direction?: string) { createCloudItem(h, direction?: string) {
// 0 - wordList长度之间的随机数 // 0 - wordList长度之间的随机数
let randomIndex = Math.floor(Math.random()*this.wordList.length); let len = this.wordList.length
// this.wordList[randomIndex] let randomIndex;
if (len > 0) {
randomIndex = Math.floor(Math.random()*len);
}
let wordItem = new Word({ let wordItem = new Word({
wordTx: '云'; wordTx: len == 0 ? '' : this.wordList[randomIndex]
}) })
wordItem.fx = (direction === 'left' ? 88 : 440) + 100; // 偏差值
let deviation = Math.floor(Math.random()*200) - 100;
wordItem.fx = (direction === 'left' ? 88 : 440) + deviation + 100;
wordItem.fy = h + 5 wordItem.fy = h + 5
this.bgCon.addChildAt(wordItem, 0) this.bgCon.addChildAt(wordItem, 0)
this.composites.add(this.world, [wordItem.phyBody]); this.composites.add(this.world, [wordItem.phyBody]);
...@@ -140,10 +215,11 @@ export class GameScene extends Scene { ...@@ -140,10 +215,11 @@ export class GameScene extends Scene {
let cloudItem = new Cloud({ let cloudItem = new Cloud({
direction direction
}); });
cloudItem.fx = direction === 'left' ? 88 : 440; cloudItem.fx = (direction === 'left' ? 88 : 440) + deviation;
cloudItem.fy = h cloudItem.fy = h
this.bgCon.addChildAt(cloudItem, 0) this.bgCon.addChildAt(cloudItem, 0)
this.composites.add(this.world, [cloudItem.phyBody]); this.mapList.push([wordItem, cloudItem])
this.composites.add(this.world, [wordItem.phyBody, cloudItem.phyBody]);
} }
// 添加角色 // 添加角色
...@@ -156,282 +232,238 @@ export class GameScene extends Scene { ...@@ -156,282 +232,238 @@ export class GameScene extends Scene {
this.bgCon.addChild(role); this.bgCon.addChild(role);
// this.composites.add(this.world, [role.phyBody]); // this.composites.add(this.world, [role.phyBody]);
} }
onFarm() {
this.moveMap()
// let roleY = this._role.y + this.bgCon.y;
// if (roleY < 600) {
// this.moveMap(600 - roleY)
// }
// let lastLine = this.mapList[0],
// lastItem = lastLine[0];
// if (lastItem.y + this.bgCon.y > this.stage.stageHeight + 10) {
// lastLine.forEach(item => {
// this.composites.remove(this.world, item.phyBody);
// item.destroy();
// this.bgCon.removeChild(item)
// })
// this.mapList.shift()
// }
// let firstLine = this.mapList[this.mapList.length - 1],
// firstItem = firstLine[0];
// if (firstItem.y + this.bgCon.y > -100) {
// this.createLineItem(firstItem.y - 240)
// }
// // console.log(this._role.y,this.bgCon.y,layers.stageHeight)
// if (this._role.y >= -(this.bgCon.y-1624)) {
// if (!this.isonce) {
// this.composites.remove(this.world, this._role.phyBody);
// console.log("siwang")
// clearTimeout(this.timer);
// this.gameOver()
// // 复活需要初始化
// this.isonce = true
// }
// }
upDateInfo() {
this.score = 0
this.time = StartScene.instance.gameInfo.duration
this.scorenum.text = this.score + ""
this.cdnum.text = this.time + ""
this.startGame()
this.countDown(this.time)
}
countDown(time) {
this.timer = setTimeout(() => {
if (Number(this.cdnum.text) <= 0) {
clearTimeout(this.timer);
this.composites.remove(this.world, this._role.phyBody);
console.log("zale")
this.gameOver()
return
}
this.cdnum.text = Number(this.cdnum.text) - 1 + ''
this.countDown(Number(this.cdnum.text))
}, 1000)
}
startGame() {
this.isonce = false
this.addEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.composites.add(this.world, [this._role.phyBody]);
}
engine; // matter引擎初始化
composites;
world;
runner;
ground;
addPropsMap = new Map();
obstaclePropMap = new Map();
private createPhyWorld() {
const { Engine, Render, Runner, Composite, Bodies, World, Composites } = Matter;
this.engine = Engine.create(
{
enableSleeping: true
}
);
this.world = this.engine.world;
this.engine.gravity.y = 1.5;
/** 真正运行 */
this.runner = Runner.create();
Runner.run(this.runner, this.engine);
// @ts-ignore
this.composites = Composite;
Matter.Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this));
Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this));
} }
onCollisionTick(e) { moveMap() {
// console.log('this.bgCon', this.bgCon)
// this.bgCon.y = this.bgCon.y + 1;
} }
onCollisionStart(e) { onCollisionTick() {
let pairs = e.pairs;
pairs.map((p) => {
// 🌹与人的碰撞
if (p.bodyB == this._role.phyBody || p.bodyA == this._role.phyBody) {
if (p.bodyB.gameType?.split("_")[0] == 'addProp' || p.bodyA.gameType?.split("_")[0] == 'addProp') {
console.log("加分")
let body = p.bodyB.gameType?.split("_")[0] == 'addProp' ? p.bodyB : p.bodyA;
let prop = this.addPropsMap.get(body.id);
let num = 1
if (body.gameType.split("_")[1] == "tian") {
num = 1
} else {
num = 2
}
this._role.addScore('+' + num, '#ffffff')
this.scorenum.text = Number(this.scorenum.text) + num + '';
this.score += num
this.composites.remove(this.world, prop.phyBody);
prop.destroy();
this.bgCon.removeChild(prop)
this.addPropsMap.delete(body.id);
} else if (p.bodyB.gameType == 'dieProp' || p.bodyA.gameType == 'dieProp') {
// 死亡💀
console.log("死亡")
let body = p.bodyB.gameType == 'dieProp' ? p.bodyB : p.bodyA;
let prop = this.obstaclePropMap.get(body.id);
this.composites.remove(this.world, prop.phyBody);
prop.destroy();
this.bgCon.removeChild(prop)
this.obstaclePropMap.delete(body.id);
// this.removeWorld()
this.composites.remove(this.world, this._role.phyBody);
clearTimeout(this.timer);
this.gameOver()
} else {
if (!this.jumpLock) {
this._role.jump()
this.jumpLock = true;
setTimeout(() => {
this.jumpLock = false
}, 300)
}
}
}
});
} }
initMap() { onCollisionStart() {
let stageHeight = this.stage.stageHeight;
this.createLineItem(stageHeight - 240, 380, false);
for (let i = 0; i < 10; i++) {
// if (i < 4) {
// this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
// } else {
// this.createLineItem(stageHeight - (240 * (i + 2)));
// }
}
} }
mapList = [];
createLineItem(h, x?: number, isprop = true) {
let nx = x ? x : Math.floor(Math.random() * 570 + 90);
if (isprop) {
let rate = Math.floor(Math.random() * 20);
switch (true) {
case rate < 18:
// 添加花🌹加分元素
let addProp = new AddProp();
addProp.fx = nx;
addProp.fy = h - 25;
this.bgCon.addChildAt(addProp, 0)
this.composites.add(this.world, [addProp.phyBody]);
this.addPropsMap.set(addProp.phyBody.id, addProp);
break;
case rate >= 19 && rate <= 20:
// 添加障碍元素
let obstacleProp = new ObstacleProp()
obstacleProp.fx = nx;
obstacleProp.fy = h - 40;
this.bgCon.addChildAt(obstacleProp, 0)
this.composites.add(this.world, [obstacleProp.phyBody]);
this.obstaclePropMap.set(obstacleProp.phyBody.id, obstacleProp)
break
default:
break
}
}
let mapItem = new MapItem();
mapItem.fx = nx;
mapItem.fy = h
this.bgCon.addChildAt(mapItem, 0)
this.composites.add(this.world, [mapItem.phyBody]);
let spriteItem = this.createOtherItem(nx, h);
this.mapList.push([mapItem, spriteItem])
}
createOtherItem(x, h) {
let dx = Math.floor(Math.random() * 280 + 90);
if (dx + 90 > x - 90) {
dx = dx + 310
}
let mapItem = new MapItem();
mapItem.fx = dx;
mapItem.fy = h
this.bgCon.addChildAt(mapItem, 0);
this.composites.add(this.world, [mapItem.phyBody]);
return mapItem
}
timer = null;
onFarm() {
let roleY = this._role.y + this.bgCon.y;
if (roleY < 600) {
this.moveMap(600 - roleY)
}
let lastLine = this.mapList[0],
lastItem = lastLine[0];
if (lastItem.y + this.bgCon.y > this.stage.stageHeight + 10) {
lastLine.forEach(item => {
this.composites.remove(this.world, item.phyBody);
item.destroy();
this.bgCon.removeChild(item)
})
this.mapList.shift()
}
let firstLine = this.mapList[this.mapList.length - 1],
firstItem = firstLine[0];
if (firstItem.y + this.bgCon.y > -100) {
this.createLineItem(firstItem.y - 240)
}
// console.log(this._role.y,this.bgCon.y,layers.stageHeight)
if (this._role.y >= -(this.bgCon.y-1624)) {
if (!this.isonce) {
this.composites.remove(this.world, this._role.phyBody);
console.log("siwang")
clearTimeout(this.timer);
this.gameOver()
// 复活需要初始化
this.isonce = true
}
}
}
moveMap(y) {
this.bgCon.y = this.bgCon.y + y;
} // onCollisionTick(e) {
// }
// onCollisionStart(e) {
// let pairs = e.pairs;
// pairs.map((p) => {
// // 🌹与人的碰撞
// if (p.bodyB == this._role.phyBody || p.bodyA == this._role.phyBody) {
// if (p.bodyB.gameType?.split("_")[0] == 'addProp' || p.bodyA.gameType?.split("_")[0] == 'addProp') {
// console.log("加分")
// let body = p.bodyB.gameType?.split("_")[0] == 'addProp' ? p.bodyB : p.bodyA;
// let prop = this.addPropsMap.get(body.id);
// let num = 1
// if (body.gameType.split("_")[1] == "tian") {
// num = 1
// } else {
// num = 2
// }
// this._role.addScore('+' + num, '#ffffff')
// this.scorenum.text = Number(this.scorenum.text) + num + '';
// this.score += num
// this.composites.remove(this.world, prop.phyBody);
// prop.destroy();
// this.bgCon.removeChild(prop)
// this.addPropsMap.delete(body.id);
// } else if (p.bodyB.gameType == 'dieProp' || p.bodyA.gameType == 'dieProp') {
// // 死亡💀
// console.log("死亡")
// let body = p.bodyB.gameType == 'dieProp' ? p.bodyB : p.bodyA;
// let prop = this.obstaclePropMap.get(body.id);
// this.composites.remove(this.world, prop.phyBody);
// prop.destroy();
// this.bgCon.removeChild(prop)
// this.obstaclePropMap.delete(body.id);
// // this.removeWorld()
// this.composites.remove(this.world, this._role.phyBody);
// clearTimeout(this.timer);
// this.gameOver()
// } else {
// if (!this.jumpLock) {
// this._role.jump()
// this.jumpLock = true;
// setTimeout(() => {
// this.jumpLock = false
// }, 300)
// }
// }
// }
// });
// }
// initMap() {
// let stageHeight = this.stage.stageHeight;
// this.createLineItem(stageHeight - 240, 380, false);
// for (let i = 0; i < 10; i++) {
// // if (i < 4) {
// // this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
// // } else {
// // this.createLineItem(stageHeight - (240 * (i + 2)));
// // }
// }
// }
// createLineItem(h, x?: number, isprop = true) {
// let nx = x ? x : Math.floor(Math.random() * 570 + 90);
// if (isprop) {
// let rate = Math.floor(Math.random() * 20);
// switch (true) {
// case rate < 18:
// // 添加花🌹加分元素
// let addProp = new AddProp();
// addProp.fx = nx;
// addProp.fy = h - 25;
// this.bgCon.addChildAt(addProp, 0)
// this.composites.add(this.world, [addProp.phyBody]);
// this.addPropsMap.set(addProp.phyBody.id, addProp);
// break;
// case rate >= 19 && rate <= 20:
// // 添加障碍元素
// let obstacleProp = new ObstacleProp()
// obstacleProp.fx = nx;
// obstacleProp.fy = h - 40;
// this.bgCon.addChildAt(obstacleProp, 0)
// this.composites.add(this.world, [obstacleProp.phyBody]);
// this.obstaclePropMap.set(obstacleProp.phyBody.id, obstacleProp)
// break
// default:
// break
// }
// }
// let mapItem = new MapItem();
// mapItem.fx = nx;
// mapItem.fy = h
// this.bgCon.addChildAt(mapItem, 0)
// this.composites.add(this.world, [mapItem.phyBody]);
// let spriteItem = this.createOtherItem(nx, h);
// this.mapList.push([mapItem, spriteItem])
// }
// createOtherItem(x, h) {
// let dx = Math.floor(Math.random() * 280 + 90);
// if (dx + 90 > x - 90) {
// dx = dx + 310
// }
// let mapItem = new MapItem();
// mapItem.fx = dx;
// mapItem.fy = h
// this.bgCon.addChildAt(mapItem, 0);
// this.composites.add(this.world, [mapItem.phyBody]);
// return mapItem
// }
removeWorld(){ // removeWorld(){
this.composites.clear(this.world) // this.composites.clear(this.world)
// console.log(this.composites) // // console.log(this.composites)
this.mapList = []; // this.mapList = [];
this.addPropsMap.clear() // this.addPropsMap.clear()
this.obstaclePropMap.clear() // this.obstaclePropMap.clear()
console.log(this.obstaclePropMap) // console.log(this.obstaclePropMap)
console.log(this.addPropsMap) // console.log(this.addPropsMap)
console.log(this.mapList) // console.log(this.mapList)
} // }
//游戏结束 // //游戏结束
async gameOver() { // async gameOver() {
this.removeEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this); // this.removeEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.removeWorld() // this.removeWorld()
let startInfo = getWebData(WebNetName.startGame).data.currInfo // let startInfo = getWebData(WebNetName.startGame).data.currInfo
let timestamp = new Date().getTime() // let timestamp = new Date().getTime()
//签名方式: md5(score=分值&startId=游戏开始id&timestamp=timestamp&key=key) // //签名方式: md5(score=分值&startId=游戏开始id&timestamp=timestamp&key=key)
//其中key的值为开始游戏接口里返回的key+固定值9ef16b33920749fb26e8fc2f2913150a, 例如1234569ef16b33920749fb26e8fc2f2913150a // //其中key的值为开始游戏接口里返回的key+固定值9ef16b33920749fb26e8fc2f2913150a, 例如1234569ef16b33920749fb26e8fc2f2913150a
let sign = duiba_md5(`score=${this.score}&startId=${startInfo.startId}&timestamp=${timestamp}&key=${startInfo.key + "9ef16b33920749fb26e8fc2f2913150a"}`) // let sign = duiba_md5(`score=${this.score}&startId=${startInfo.startId}&timestamp=${timestamp}&key=${startInfo.key + "9ef16b33920749fb26e8fc2f2913150a"}`)
const { success, data, message } = await sendWebNet(WebNetName.submitGame, { score: this.score, sign: sign, code: startInfo.code, timestamp: timestamp ,startId:startInfo.startId}) // const { success, data, message } = await sendWebNet(WebNetName.submitGame, { score: this.score, sign: sign, code: startInfo.code, timestamp: timestamp ,startId:startInfo.startId})
this._role.die(() => { // this._role.die(() => {
this.bgCon.removeChildren() // this.bgCon.removeChildren()
this.bgCon.y = 0 // this.bgCon.y = 0
if (!success) { // if (!success) {
showToast(message || "网络异常,请重试~") // showToast(message || "网络异常,请重试~")
changeScene(StartScene) // changeScene(StartScene)
return // return
} // }
if (data.pass) { // if (data.pass) {
showPanel(SuccessPanel) // showPanel(SuccessPanel)
} else { // } else {
showPanel(FailPanel) // showPanel(FailPanel)
} // }
}) // })
} // }
initEvents() { initEvents() {
super.initEvents(); super.initEvents();
// this.left.addEventListener(FYGE.MouseEvent.CLICK, () => { // this.left.addEventListener(FYGE.MouseEvent.CLICK, () => {
......
...@@ -5,12 +5,15 @@ export default class Role extends FYGE.Container { ...@@ -5,12 +5,15 @@ export default class Role extends FYGE.Container {
public phyBody: Matter.Body; public phyBody: Matter.Body;
roleImg: FYGE.Sprite; roleImg: FYGE.Sprite;
beforeY = 0; beforeY = 0;
direction = 'down'; // direction = 'down';
waittingSvga; direction;
jumpSvga; jumpSvga;
downSvga; downSvga;
currentIndex = -2;
position;
item
constructor() { constructor(data?) {
super(); super();
let roleImg = this.roleImg = new FYGE.Sprite(); let roleImg = this.roleImg = new FYGE.Sprite();
...@@ -30,7 +33,6 @@ export default class Role extends FYGE.Container { ...@@ -30,7 +33,6 @@ export default class Role extends FYGE.Container {
// }, // },
// this // this
// ); // );
} }
async getSvga(){ async getSvga(){
this.jumpSvga = new FYGE.SvgaAni(await RES.getResAsync("jumppeo.svga")); this.jumpSvga = new FYGE.SvgaAni(await RES.getResAsync("jumppeo.svga"));
...@@ -60,50 +62,70 @@ export default class Role extends FYGE.Container { ...@@ -60,50 +62,70 @@ export default class Role extends FYGE.Container {
} }
leftMove(){ leftMove(){
Matter.Body.applyForce(this.phyBody, this.phyBody.position, { if (this.currentIndex%2 == 0) {
x: 0.1, console.log('左移动')
y: 0 this.direction = 'left'
}); Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
x: 0.1,
y: 0
});
}
} }
rightMove(){ rightMove(){
Matter.Body.applyForce(this.phyBody, this.phyBody.position, { if (this.currentIndex%2 == 1) {
x: -0.1, this.direction = 'right'
y: 0 Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
}); x: -0.1,
y: 0
});
}
} }
/** 根据物理刚体,更新当前的坐标。 */ /** 根据物理刚体,更新当前的坐标。 */
private onFarm() { private onFarm() {
if(this.beforeY){ if (this.direction == 'left') {
if( this.beforeY >this.phyBody.position.y ){ console.log('----')
Matter.Body.setPosition( this.phyBody, {
this.direction = 'up' x:this.phyBody.position.x - 1,
y:this.phyBody.position.y - 1
})
this.position.set(this.phyBody.position.x,this.phyBody.position.y)
// this.downSvga.position.set(1, 1000)
// this.jumpSvga.position.set(1, 1000)
} else {
} }
// console.log("this.beforeY", this.beforeY)
// if(this.beforeY){
// if( this.beforeY >this.phyBody.position.y ){
// this.direction = 'up'
// }
if( this.beforeY < this.phyBody.position.y ){ // if( this.beforeY < this.phyBody.position.y ){
this.direction = 'down' // this.direction = 'down'
} // }
} // }
if(this.phyBody.position.x > 750){ // if(this.phyBody.position.x > 750){
Matter.Body.setPosition( this.phyBody, { // Matter.Body.setPosition( this.phyBody, {
x:0, // x:0,
y:this.phyBody.position.y // y:this.phyBody.position.y
}) // })
}else if(this.phyBody.position.x<0){ // }else if(this.phyBody.position.x<0){
Matter.Body.setPosition( this.phyBody, { // Matter.Body.setPosition( this.phyBody, {
x:750, // x:750,
y:this.phyBody.position.y // y:this.phyBody.position.y
}) // })
}else{ // }else{
this.x = this.phyBody.position.x; // this.x = this.phyBody.position.x;
this.y = this.phyBody.position.y; // this.y = this.phyBody.position.y;
} // }
this.beforeY = this.phyBody.position.y; // this.beforeY = this.phyBody.position.y;
} }
...@@ -138,13 +160,13 @@ export default class Role extends FYGE.Container { ...@@ -138,13 +160,13 @@ export default class Role extends FYGE.Container {
} }
jump() { jump() {
if( this.direction == 'up'){return}; // if( this.direction == 'up'){return};
setTimeout(()=>{ // setTimeout(()=>{
Matter.Body.applyForce(this.phyBody, this.phyBody.position, { // Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
x: 0, // x: 0,
y: -1.2 // y: -1.2
}); // });
}) // })
} }
onMouseDown(e) { onMouseDown(e) {
......
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