Commit f923ffff authored by Edwise's avatar Edwise 🍷

Merge branch '20230322_tiaoyitiao_2.0' of...

Merge branch '20230322_tiaoyitiao_2.0' of gitlab2.dui88.com:wangyongxia/zjzy_client_game into 20230322_tiaoyitiao_2.0
parents 44cade3f 6f053187
......@@ -32,7 +32,7 @@
height: 100%;
overflow: hidden;
position: absolute;
background-color: #9a3636;
background-color: #54c5f4;
-webkit-user-select: none;
/* Safari */
-ms-user-select: none;
......
resource/GameScene/cdbg.png

9.21 KB | W: | H:

resource/GameScene/cdbg.png

6.09 KB | W: | H:

resource/GameScene/cdbg.png
resource/GameScene/cdbg.png
resource/GameScene/cdbg.png
resource/GameScene/cdbg.png
  • 2-up
  • Swipe
  • Onion skin
resource/GameScene/cloud.png

4.83 KB | W: | H:

resource/GameScene/cloud.png

13.5 KB | W: | H:

resource/GameScene/cloud.png
resource/GameScene/cloud.png
resource/GameScene/cloud.png
resource/GameScene/cloud.png
  • 2-up
  • Swipe
  • Onion skin
resource/GameScene/controlpeo.png

29.9 KB | W: | H:

resource/GameScene/controlpeo.png

23.3 KB | W: | H:

resource/GameScene/controlpeo.png
resource/GameScene/controlpeo.png
resource/GameScene/controlpeo.png
resource/GameScene/controlpeo.png
  • 2-up
  • Swipe
  • Onion skin
resource/GameScene/gamebg.jpg

288 KB | W: | H:

resource/GameScene/gamebg.jpg

347 KB | W: | H:

resource/GameScene/gamebg.jpg
resource/GameScene/gamebg.jpg
resource/GameScene/gamebg.jpg
resource/GameScene/gamebg.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -5,11 +5,11 @@
"name": "FailPanel"
},
{
"keys": "cdbg.png,closemusic.png,cloud.png,controlpeo.png,gamebg.jpg,gamebuild.png,leftbtn.png,monster.png,openmusic.png,rightbtn.png,scorebg.png,tianpop.png,xiangpop.png",
"keys": "cdbg.png,cloud.png,controlpeo.png,gamebg.jpg,monster.png,num_0.png,num_1.png,num_2.png,num_3.png,num_4.png,num_5.png,num_6.png,num_7.png,num_8.png,num_9.png,num_s.png,reset.png,tianpop.png,xiangpop.png",
"name": "GameScene"
},
{
"keys": "guide.png",
"keys": "guide.png,step1_img.png,step1_tips.png,step2_img.png,step2_tips.png,step3_img.png,step3_tips.png,step4_img.png",
"name": "GuidePanel"
},
{
......@@ -24,16 +24,12 @@
"keys": "infoline.png,light.png,sucbg.png,sucstar.png,sun.png",
"name": "SuccessPanel"
},
{
"keys": "bg.mp3,fail.mp3,get.mp3,jump.mp3",
"name": "bgm"
},
{
"keys": "closebtn.png,comCloseBtn.png,surebtn.png,toastBg.png,waitingBg.png,waitingRot.png,关闭按钮.png,关闭按钮2.png",
"name": "common"
},
{
"keys": "crypeo.svga,guidecount.svga,jumppeo.svga,popstar.svga,startbtn.svga,startpeo.svga,startpeople.svga,startpop.svga",
"keys": "atmosphere.svga,crypeo.svga,guidecount.svga,jumppeo.svga,left.svga,popstar.svga,right.svga,startbtn.svga,startpeo.svga,startpeople.svga,startpop.svga",
"name": "svga"
}
],
......
......@@ -11,7 +11,6 @@ import { G_EVENT } from "./common/G_EVENT";
import { Tools } from "./Tools";
import { destroyWebNetData } from "./webNet";
import { StartScene } from "./scenes/StartScene";
import { preloadSound } from "./common/SoundWeb";
/**
* 全局事件,为了和小程序交互
......@@ -25,7 +24,12 @@ export class Main {
private requestID;
private _pause: boolean;
private canvas: HTMLCanvasElement
constructor(canvas: HTMLCanvasElement) {
constructor(canvas: HTMLCanvasElement, data = {
time: 60,
longitude: "",
latitude: ""
}) {
Tools.configInfo = data;
var sysInfo;
//淘宝小程序环境就用canvas初始化
if (!window) {//自行处理吧,这么判断也不保险,万一淘宝小程序加进了window
......@@ -80,14 +84,6 @@ export class Main {
console.log("通用资源加载完成")
//h5环境时,隐藏加载中
if (FYGE.getEnv() == "web" && document.getElementById("__loading__")) document.getElementById("__loading__").style.display = "none";
let isIOS = Tools.isIOS()
if(isIOS){
Tools.isMusic = false
}else{
Tools.isMusic = true
}
preloadSound("bg")
changeScene(StartScene)
......
......@@ -5,11 +5,11 @@ export const ResJson = {
"name": "FailPanel"
},
{
"keys": "cdbg.png,closemusic.png,cloud.png,controlpeo.png,gamebg.jpg,gamebuild.png,leftbtn.png,monster.png,openmusic.png,rightbtn.png,scorebg.png,tianpop.png,xiangpop.png",
"keys": "cdbg.png,cloud.png,controlpeo.png,gamebg.jpg,monster.png,num_0.png,num_1.png,num_2.png,num_3.png,num_4.png,num_5.png,num_6.png,num_7.png,num_8.png,num_9.png,num_s.png,reset.png,tianpop.png,xiangpop.png",
"name": "GameScene"
},
{
"keys": "guide.png",
"keys": "guide.png,step1_img.png,step1_tips.png,step2_img.png,step2_tips.png,step3_img.png,step3_tips.png,step4_img.png",
"name": "GuidePanel"
},
{
......@@ -24,16 +24,12 @@ export const ResJson = {
"keys": "infoline.png,light.png,sucbg.png,sucstar.png,sun.png",
"name": "SuccessPanel"
},
{
"keys": "bg.mp3,fail.mp3,get.mp3,jump.mp3",
"name": "bgm"
},
{
"keys": "closebtn.png,comCloseBtn.png,surebtn.png,toastBg.png,waitingBg.png,waitingRot.png,关闭按钮.png,关闭按钮2.png",
"name": "common"
},
{
"keys": "crypeo.svga,guidecount.svga,jumppeo.svga,popstar.svga,startbtn.svga,startpeo.svga,startpeople.svga,startpop.svga",
"keys": "atmosphere.svga,crypeo.svga,guidecount.svga,jumppeo.svga,left.svga,popstar.svga,right.svga,startbtn.svga,startpeo.svga,startpeople.svga,startpop.svga",
"name": "svga"
}
],
......
......@@ -303,127 +303,6 @@ export const SkinJson = {
"source": "gamebg.jpg"
},
"id": "bg"
},
{
"name": "gamebuild",
"x": 0,
"y": 826,
"type": "sprite",
"props": {
"source": "gamebuild.png"
}
},
{
"name": "controlbtn",
"x": 80,
"y": 1164,
"type": "container",
"children": [
{
"name": "rightbtn",
"x": 0,
"y": 0,
"type": "sprite",
"props": {
"source": "rightbtn.png"
},
"id": "right"
},
{
"name": "leftbtn",
"x": 385,
"y": 0,
"type": "sprite",
"props": {
"source": "leftbtn.png"
},
"id": "left"
}
]
},
{
"name": "score",
"x": 280,
"y": 264,
"type": "container",
"children": [
{
"name": "scorebg",
"x": 0,
"y": 0,
"type": "sprite",
"props": {
"source": "scorebg.png"
},
"id": "scorebg"
},
{
"name": "scorenum",
"x": 140,
"y": 26,
"type": "text",
"props": {
"text": "",
"size": 44,
"fillColor": "#ffffff",
"textAlpha": 1,
"lineHeight": 44
},
"id": "scorenum"
}
]
},
{
"name": "countdown",
"x": 23,
"y": 264,
"type": "container",
"children": [
{
"name": "cdbg",
"x": 0,
"y": 0,
"type": "sprite",
"props": {
"source": "cdbg.png"
},
"id": "cdbg"
},
{
"name": "cdnum",
"x": 94,
"y": 26,
"type": "text",
"props": {
"text": "0s",
"size": 44,
"fillColor": "#ffffff",
"textAlpha": 1,
"lineHeight": 44
},
"id": "cdnum"
}
]
},
{
"name": "closemusic",
"x": 650,
"y": 265,
"type": "sprite",
"props": {
"source": "closemusic.png"
},
"id": "close"
},
{
"name": "openmusic",
"x": 650,
"y": 265,
"type": "sprite",
"props": {
"source": "openmusic.png"
},
"id": "open"
}
]
},
......
......@@ -7,7 +7,12 @@ import Ease = FYGE.Ease;
* 定制,记录一些全局量和通用方法
*/
export class Tools {
public static configInfo: {
longitude: string,
latitude: string,
time: number
}
/**
* 缓存key
*/
......@@ -15,8 +20,6 @@ export class Tools {
public static isMember: boolean;
public static isMusic:boolean = true;
/**
* 全局数据,重要数据
*/
......
......@@ -2,7 +2,7 @@ import { Panel } from "../../module/views/Panel";
import { changeScene, getCurrentScene, showPanel, showToast } from "../../module/ctrls";
import { StartScene } from "../scenes/StartScene";
import { GuidePanel } from "./GuidePanel";
import { getWebData, WebNetName, sendLog, LOG_TYPE, getPxTokenSave, sendWebNet } from "../webNet";
import { getWebData, WebNetName, LOG_TYPE, getPxTokenSave, sendWebNet } from "../webNet";
export class FailPanel extends Panel {
get groupNames() { return ["FailPanel"] };
get skinName() { return "FailPanel" };
......@@ -24,18 +24,14 @@ export class FailPanel extends Panel {
this.score.x = 92
this.score.textWidth = 568
this.score.textAlign = FYGE.TEXT_ALIGN.CENTER
sendLog(LOG_TYPE.EXPOSURE, 40)
sendLog(LOG_TYPE.EXPOSURE, 39)
}
back() {
this.hidePanel()
sendLog(LOG_TYPE.CLICK, 40)
changeScene(StartScene)
}
isOpen = false
async restart() {
sendLog(LOG_TYPE.CLICK, 39)
this.btnDelay(this.restartbtn)
if (!this.isOpen) {
this.isOpen = true
......
......@@ -4,10 +4,16 @@ import { RES } from "../../module/RES";
import { getCurrentScene } from "../../module/ctrls";
import { GameScene } from "../scenes/GameScene";
import { StartScene } from "../scenes/StartScene";
import UI from "../UI";
import { Tools } from "../Tools";
export class GuidePanel extends Panel {
get groupNames() { return ["GuidePanel"] };
get groupNames() { return ["GuidePanel", "GameScene"] };
get skinName() { return "GuidePanel" };
rectlayer;
clicklayer;
guideStep = 1;
svga
initUi() {
......@@ -15,35 +21,91 @@ export class GuidePanel extends Panel {
svga
async start(data) {
super.start();
GameScene.instance.scorenum.text = "0"
GameScene.instance.cdnum.text = StartScene.instance.gameInfo.duration
let svgashow = this.svga = new FYGE.SvgaAni(await RES.getResAsync("guidecount.svga"))
this.clicklayer = UI.Rect(this, 750, 1624, 0x000000, 0, 0, 0, 0.01);
this.rectlayer = UI.Ctn(this, 0, 0);
this.rectlayer.mouseEnable = false
this.rectlayer.mouseChildren = false
let svgashow = this.svga = new FYGE.SvgaAni(await RES.getResAsync("guidecount.svga"));
this.svga.position.set(170, 660)
this.svga.visible = false
this.svga.stop()
this.addChild(svgashow)
this.addChild(svgashow);
this.clicklayer.addEventListener(FYGE.MouseEvent.CLICK, () => {
if (this.guideStep < 4) {
this.guideStep++
this.guideUI();
} else if((this.guideStep == 4)) {
this.guideStep++
this.showCount();
}
}, this)
if(getWebData(WebNetName.indexInfo).data.ifFirstPlay){
this.guideUI();
} else {
this.showCount();
}
// GameScene.instance.scorenum.text = "0"
// GameScene.instance.cdnum.text = StartScene.instance.gameInfo.duration
// svgashow.lockStep = true
if(getWebData(WebNetName.startGame).data.firstGame){
svgashow.startAniRange(0,200,1,()=>{
svgashow.startAniRange(200,270,0)
this.svga.addEventListener(FYGE.MouseEvent.CLICK,this.showCount,this)
}
step3_img;
async guideUI() {
this.rectlayer.removeChildren()
if (this.guideStep == 1) {
UI.Sp(this.rectlayer, 'step1_img.png', 48, 860);
let step1_tips = UI.Sp(this.rectlayer, 'step1_tips.png', 188, 776);
FYGE.Tween.get(step1_tips, {
loop: true
})
.to({ alpha: 0.2},500)
.to({ alpha: 1},500)
} else if (this.guideStep == 2) {
UI.Sp(this.rectlayer, 'step2_img.png', 50, 492);
let step2_tips = UI.Sp(this.rectlayer, 'step2_tips.png', 198, 900);
FYGE.Tween.get(step2_tips, {
loop: true
})
this.svga.visible = true
}else{
this.showCount()
.to({ alpha: 0.2},500)
.to({ alpha: 1},500)
} else if (this.guideStep == 3) {
this.step3_img = UI.Sp(this.rectlayer, 'step3_img.png', 311, 333);
this.cdUIRender(Tools.configInfo.time)
let step3_tips = UI.Sp(this.rectlayer, 'step3_tips.png', 236, 850);
FYGE.Tween.get(step3_tips, {
loop: true
})
.to({ alpha: 0.2},500)
.to({ alpha: 1},500)
} else if (this.guideStep == 4){
let atmosphere = new FYGE.SvgaAni(await RES.getResAsync("atmosphere.svga"))
this.rectlayer.addChild(atmosphere)
atmosphere.position.set(18, 324)
UI.Sp(this.rectlayer, 'step4_img.png', 95, 540);
}
}
cdUIRender(num = 60) {
// 先清除所有节点
this.step3_img.removeChildren();
let str = num + 's';
let arr = str.split("");
let startPos = (130 - (30 * arr.length)) / 2
arr.forEach((item, index) => {
UI.Sp(this.step3_img, `num_${item}.png`, startPos + (index * 30), 38)
})
}
showCount(){
this.svga.removeEventListener(FYGE.MouseEvent.CLICK,this.showCount,this)
this.svga.startAniRange(275,undefined,1,()=>{
this.removeChild(this.rectlayer)
this.svga.visible = true
this.svga.startAniRange(1,105,1,()=>{
this.removeChild(this.svga)
this.hidePanel()
getCurrentScene().upDateInfo()
setTimeout(()=>{
this.hidePanel()
getCurrentScene().upDateInfo()
},100)
})
this.svga.visible = true
}
initEvents() {
super.initEvents();
......
......@@ -2,7 +2,7 @@ import { Panel } from "../../module/views/Panel";
import { RES } from "../../module/RES";
import { changeScene } from "../../module/ctrls";
import { StartScene } from "../scenes/StartScene";
import { getWebData, WebNetName, sendLog, LOG_TYPE } from "../webNet";
import { getWebData, WebNetName, LOG_TYPE } from "../webNet";
export class SuccessPanel extends Panel {
get groupNames() { return ["SuccessPanel"] };
get skinName() { return "SuccessPanel" };
......@@ -38,11 +38,9 @@ export class SuccessPanel extends Panel {
let endInfo = getWebData(WebNetName.submitGame).data
this.score.text = endInfo.score+""
this.sunscore.text = "x"+endInfo.sunNum+""
sendLog(LOG_TYPE.EXPOSURE,38)
}
back(){
this.hidePanel()
sendLog(LOG_TYPE.CLICK,38)
changeScene(StartScene)
}
initEvents() {
......
import { Scene } from "../../module/views/Scene";
import * as Matter from "matter-js";
import Role from "./components/Role";
import { RES } from "../../module/RES";
import AddProp from "./components/AddProp";
import ObstacleProp from "./components/ObstacleProp";
import MapItem from "./components/MapItem";
import {
getWebData,
WebNetName,
sendWebNet,
sendLog,
LOG_TYPE,
} from "../webNet";
import { getWebData, WebNetName, sendWebNet, LOG_TYPE } from "../webNet";
import { showPanel, showToast, changeScene } from "../../module/ctrls";
import { GuidePanel } from "../panels/GuidePanel";
import { StartScene } from "./StartScene";
......@@ -18,428 +13,423 @@ import { SuccessPanel } from "../panels/SuccessPanel";
import { FailPanel } from "../panels/FailPanel";
import { duiba_md5 } from "../../module/tools/security";
import { Tools } from "../Tools";
import { playAllSound, stopAllSound, cusPlaySound } from "../common/SoundWeb";
import { playAllSound } from "../common/SoundWeb";
import { layers } from "../../module/views/layers";
import UI from "../UI";
export class GameScene extends Scene {
get groupNames() {
return ["GameScene"];
}
get skinName() {
return "GameScene";
}
bg: FYGE.Sprite;
cloud: FYGE.Sprite;
peo: FYGE.Sprite;
tianpop: FYGE.Sprite;
xiangpop: FYGE.Sprite;
monster: FYGE.Sprite;
right: FYGE.Sprite;
left: FYGE.Sprite;
scorebg: FYGE.Sprite;
scorenum: FYGE.TextField;
cdbg: FYGE.Sprite;
cdnum: FYGE.TextField;
close: FYGE.Sprite;
open: FYGE.Sprite;
jumpLock = false;
isonce = false;
public static instance: GameScene;
initUi() {}
start(data) {
super.start();
sendLog(LOG_TYPE.EXPOSURE, 37);
GameScene.instance = this;
showPanel(GuidePanel);
if (Tools.isMusic) {
this.open.visible = true;
this.close.visible = false;
cusPlaySound("bg", true);
} else {
this.open.visible = false;
this.close.visible = true;
get groupNames() { return ["GameScene"] };
get skinName() { return "GameScene" };
bg: FYGE.Sprite;
left;
right;
cdbg: FYGE.Sprite;
time = Tools.configInfo.time;
// --------
cloud: FYGE.Sprite;
peo: FYGE.Sprite;
tianpop: FYGE.Sprite;
xiangpop: FYGE.Sprite;
monster: FYGE.Sprite;
jumpLock = false;
isonce = false;
public static instance: GameScene;
initUi() {
}
this.createPhyWorld();
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;
}
score;
time;
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();
async start(data) {
super.start();
GameScene.instance = this
// showPanel(GuidePanel);
// 左右按钮
this.left = new FYGE.SvgaAni(await RES.getResAsync("left.svga"))
this.left = this.addChild(this.left)
this.left.position.set(8, 979);
this.left.startAniRange(1, 1, 1);
this.right = new FYGE.SvgaAni(await RES.getResAsync("right.svga"))
this.right = this.addChild(this.right)
this.right.position.set(524, 979);
this.right.startAniRange(1, 1, 1);
this.left.addEventListener(FYGE.MouseEvent.CLICK, () => {
this.left.startAniRange(1, undefined, 1, () => {})
this._role.leftMove()
})
this.right.addEventListener(FYGE.MouseEvent.CLICK, () => {
this.right.startAniRange(1, undefined, 1, () => {})
this._role.rightMove()
})
// 倒计时
this.cdbg = UI.Sp(this, "cdbg.png", 280, 330)
this.cdUIRender(this.time)
// 物理引擎
this.createPhyWorld()
this.bgCon = this.addChild(new FYGE.Container());
this.setChildIndex(this.bgCon, 1)
this.initMap();
// TODO_wyx
this.upDateInfo()
}
score;
upDateInfo() {
// this.score = 0
// this.time = StartScene.instance.gameInfo.duration
this.time = Tools.configInfo.time;
this.cdUIRender(this.time)
this.startGame()
this.countDown(this.time)
}
}
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.addRole();
this.addEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.composites.add(this.world, [this._role.phyBody]);
}
_role; //人物
bgCon; //背景移动
addRole() {
let offset = (1624 - this.stage.viewRect.height) / 2;
let role = (this._role = new Role());
role.fx = 380;
role.fy = 980 - offset;
this.bgCon.addChild(role);
// this.composites.add(this.world, [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;
// 创建一个渲染器
countDown(time) {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
if (this.time <= 0) {
clearTimeout(this.timer);
this.composites.remove(this.world, this._role.phyBody);
console.log("zale")
this.gameOver()
return
}
this.time = this.time - 1;
this.cdUIRender(this.time)
this.countDown(this.time)
}, 1000)
}
cdUIRender(num = 60) {
// 先清除所有节点
this.cdbg.removeChildren();
let str = num + 's';
let arr = str.split("");
let startPos = (192 - (30 * arr.length)) / 2
arr.forEach((item, index) => {
UI.Sp(this.cdbg, `num_${item}.png`, startPos + (index * 30), 46)
})
}
startGame() {
this.isonce = false
this.addRole();
this.addEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.composites.add(this.world, [this._role.phyBody]);
}
_role; //人物
bgCon; //背景移动
addRole() {
let offset = (1624 - this.stage.viewRect.height) / 2;
let role = this._role = new Role();
role.fx = 380;
role.fy = 980 - offset;
this.bgCon.addChild(role);
// this.composites.add(this.world, [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;
// // 创建引擎
// const engine = Engine.create();
// // 创建渲染器
// const render = Render.create({
// engine: engine
// })
// Engine.run(engine);
// Render.run(render);
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));
// 创建一个渲染器
const render = Render.create({
// element: document.body,
canvas: document.getElementById("renderCanvas"),
engine: this.engine,
options: {
width: document.body.clientWidth,
height: document.body.clientHeight,
pixelRatio:window.devicePixelRatio, // 设置像素比
background: "rgba(255,255,255,0.3)", // 全局渲染模式时背景色
wireframeBackground: "rgba(255,255,255,0.3)", // 线框模式时背景色
hasBounds: false,
wireframes: false, // 线框模式
showSleeping: true, // 刚体睡眠状态
showDebug: false, // Debug 信息
showBroadphase: false, // 粗测阶段
showBounds: true, // 刚体的界限
showVelocity: false, // 移动刚体时速度
showCollisions: false, // 刚体碰撞点
showSeparations: false, // 刚体分离
showAxes: false, // 刚体轴线
showPositions: true, // 刚体位置
showAngleIndicator: false, // 刚体转角指示
showIds: true, // 显示每个刚体的 ID
showVertexNumbers: false, // 刚体顶点数
showConvexHulls: false, // 刚体凸包点
showInternalEdges: false, // 刚体内部边界
showMousePosition: false, // 鼠标约束线
},
});
Render.run(render);
/** 真正运行 */
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) {}
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");
if (Tools.isMusic) {
cusPlaySound("get", false);
}
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("死亡");
if (Tools.isMusic) {
cusPlaySound("fail", false);
}
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) {
if (Tools.isMusic) {
cusPlaySound("jump", false);
// element: document.body,
canvas: document.getElementById("renderCanvas"),
engine: this.engine,
options: {
width: document.body.clientWidth,
height: document.body.clientHeight,
pixelRatio:window.devicePixelRatio, // 设置像素比
background: "rgba(255,255,255,0.3)", // 全局渲染模式时背景色
wireframeBackground: "rgba(255,255,255,0.3)", // 线框模式时背景色
hasBounds: false,
wireframes: false, // 线框模式
showSleeping: true, // 刚体睡眠状态
showDebug: false, // Debug 信息
showBroadphase: false, // 粗测阶段
showBounds: true, // 刚体的界限
showVelocity: false, // 移动刚体时速度
showCollisions: false, // 刚体碰撞点
showSeparations: false, // 刚体分离
showAxes: false, // 刚体轴线
showPositions: true, // 刚体位置
showAngleIndicator: false, // 刚体转角指示
showIds: true, // 显示每个刚体的 ID
showVertexNumbers: false, // 刚体顶点数
showConvexHulls: false, // 刚体凸包点
showInternalEdges: false, // 刚体内部边界
showMousePosition: false, // 鼠标约束线
},
});
Render.run(render);
}
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.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)
}
}
}
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));
}
});
}
}
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;
}
initMap() {
let stageHeight = this.stage.stageHeight;
this.createLineItem(stageHeight - 100, 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 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);
let spriteItem = this.createOtherItem(nx, h);
this.mapList.push([mapItem, spriteItem])
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]);
createOtherItem(x, h) {
let dx = Math.floor(Math.random() * 280 + 90);
if (dx + 90 > x - 90) {
dx = dx + 310
}
return mapItem;
}
timer = null;
onFarm() {
let roleY = this._role.y + this.bgCon.y;
let mapItem = new MapItem();
mapItem.fx = dx;
mapItem.fy = h
this.bgCon.addChildAt(mapItem, 0);
this.composites.add(this.world, [mapItem.phyBody]);
if (roleY < 600) {
this.moveMap(600 - roleY);
return mapItem
}
timer = null;
onFarm() {
let roleY = this._role.y + this.bgCon.y;
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);
});
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
}
}
this.mapList.shift();
}
moveMap(y) {
this.bgCon.y = this.bgCon.y + y;
}
let firstLine = this.mapList[this.mapList.length - 1],
firstItem = firstLine[0];
removeWorld(){
this.composites.clear(this.world)
// console.log(this.composites)
this.mapList = [];
this.addPropsMap.clear()
this.obstaclePropMap.clear()
console.log(this.obstaclePropMap)
console.log(this.addPropsMap)
console.log(this.mapList)
if (firstItem.y + this.bgCon.y > -100) {
this.createLineItem(firstItem.y - 240);
}
//游戏结束
async gameOver() {
this.removeEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.removeWorld()
// let startInfo = getWebData(WebNetName.startGame).data.currInfo
// let timestamp = new Date().getTime()
// //签名方式: md5(score=分值&startId=游戏开始id&timestamp=timestamp&key=key)
// //其中key的值为开始游戏接口里返回的key+固定值9ef16b33920749fb26e8fc2f2913150a, 例如1234569ef16b33920749fb26e8fc2f2913150a
// 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})
// this._role.die(() => {
// this.bgCon.removeChildren()
// this.bgCon.y = 0
// if (!success) {
// showToast(message || "网络异常,请重试~")
// changeScene(StartScene)
// return
// }
// if (data.pass) {
// showPanel(SuccessPanel)
// } else {
// showPanel(FailPanel)
// }
// })
// 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;
}
removeWorld() {
this.composites.clear(this.world);
// console.log(this.composites)
this.mapList = [];
this.addPropsMap.clear();
this.obstaclePropMap.clear();
console.log(this.obstaclePropMap);
console.log(this.addPropsMap);
console.log(this.mapList);
}
//游戏结束
async gameOver() {
this.removeEventListener(FYGE.Event.ENTER_FRAME, this.onFarm, this);
this.removeWorld();
let startInfo = getWebData(WebNetName.startGame).data.currInfo;
let timestamp = new Date().getTime();
//签名方式: md5(score=分值&startId=游戏开始id&timestamp=timestamp&key=key)
//其中key的值为开始游戏接口里返回的key+固定值9ef16b33920749fb26e8fc2f2913150a, 例如1234569ef16b33920749fb26e8fc2f2913150a
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,
});
this._role.die(() => {
this.bgCon.removeChildren();
this.bgCon.y = 0;
if (!success) {
showToast(message || "网络异常,请重试~");
changeScene(StartScene);
return;
}
if (data.pass) {
showPanel(SuccessPanel);
} else {
showPanel(FailPanel);
}
});
}
initEvents() {
super.initEvents();
this.left.addEventListener(FYGE.MouseEvent.CLICK, () => {
sendLog(LOG_TYPE.CLICK, 37);
this._role.leftMove();
});
this.right.addEventListener(FYGE.MouseEvent.CLICK, () => {
sendLog(LOG_TYPE.CLICK, 37);
this._role.rightMove();
});
this.open.addEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this);
this.close.addEventListener(FYGE.MouseEvent.CLICK, this.changeMusic, this);
}
removeEvents() {
super.removeEvents();
this.open.removeEventListener(
FYGE.MouseEvent.CLICK,
this.changeMusic,
this
);
this.close.removeEventListener(
FYGE.MouseEvent.CLICK,
this.changeMusic,
this
);
stopAllSound();
}
initEvents() {
super.initEvents();
}
removeEvents() {
super.removeEvents();
}
}
......@@ -61,8 +61,8 @@ export class StartScene extends Scene {
"sun": 10
}
// this.openGame()
// TODO_wyx
this.openGame()
// for (let i = 0; i < data.gamecfs.length; i++) {
// if (data.gamecfs[i].code == data.gameCode) {
......@@ -75,35 +75,39 @@ export class StartScene extends Scene {
openRule() {
GDispatcher.dispatchEvent("openRule");
}
isOpen = false
startId;
getWordList() {
let dataInfo = getWebData(WebNetName.indexInfo).data.dataInfo;
let hasWordList:any = [];
let noWordList:any = [];
dataInfo.forEach(item => {
if (item.context) {
hasWordList = hasWordList.concat(item.context.split(""))
}
})
allWords.forEach(item => {
if (!hasWordList.includes(item) && !noWordList.includes(item)) {
noWordList.push(item)
}
})
return noWordList
}
async openGame() {
this.btnDelay(this.startbtn)
if (this.indexInfo) {
if (!this.indexInfo.dailyPass) {
if (!this.isOpen) {
this.isOpen = true
let token = ""
const { success, code, data, message } = await sendWebNet(WebNetName.startGame, { token: token })
if (!success) {
this.isOpen = false
if (code == "20004") {
showToast("今日已过关,明日再来~")
} else {
showToast(message || "网络异常,请重试~")
}
return
}
this.isOpen = false
changeScene(GameScene)
}
} else {
showToast("今日已过关,明日再来~")
}
if (this.getWordList().length == 0) {
showToast("您已获取今日全部游戏奖励,\n请明日再来");
return
}
const { success, code, data, desc } = await sendWebNet(WebNetName.startGame, {
activityId: getUrlParams('activityId'),
type: 3
})
if (success) {
this.startId = data.startId;
changeScene(GameScene)
} else {
showToast("网络异常,请重试~")
showToast(desc || "网络开小差了,稍后再试")
}
}
goback() {
GDispatcher.dispatchEvent("backIndex");
......
import * as Matter from "matter-js";
import { RES } from "../../../module/RES";
import UI from "../../UI";
export default class MapItem extends FYGE.Container {
public phyBody: Matter.Body;
itemImg: FYGE.Sprite;
constructor() {
super();
let itemImg = this.itemImg = new FYGE.Sprite();
itemImg.texture = RES.getRes("cloud.png");
itemImg.width = itemImg.width*1.4
itemImg.position.set(-itemImg.width / 2, -10);
this.addChild(itemImg);
// itemImg.position.set(-itemImg.width / 2, -10);
let itemImg = this.itemImg = UI.Sp(this, "cloud.png", 0, 0);
this.phyBody = Matter.Bodies.rectangle(this.x, this.y,itemImg.width,5, {
this.phyBody = Matter.Bodies.rectangle(this.x, this.y,itemImg.width, 5, {
isStatic: true,
friction: 1,
isSensor: true, // 传感器,可以检测到碰撞,但是不参与碰撞
render: {
fillStyle: "blue" // 填充的颜色
}
});
this.phyBody.gameType = 'item'
setTimeout(() => {
this.setPhyPos();
}, 200)
}
......
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