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

feat: 记录

parent e7e92de9
......@@ -2,10 +2,8 @@ import { Scene } from "../../module/views/Scene";
import * as Matter from "matter-js";
import Role from "./components/Role";
import AddProp from "./components/AddProp";
import { RES } from "../../module/RES";
import ObstacleProp from "./components/ObstacleProp";
import MapItem from "./components/MapItem";
import Cloud from "./components/Cloud";
import { getWebData, WebNetName, sendWebNet, sendLog, LOG_TYPE } from "../webNet";
import { showPanel, showToast, changeScene } from "../../module/ctrls";
import { GuidePanel } from "../panels/GuidePanel";
......@@ -14,130 +12,74 @@ 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 { 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;
left;
right;
cdbg: FYGE.Sprite;
bgCon; //背景移动
cdnum: FYGE.TextField;
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;
score;
time;
public static instance: GameScene;
initUi() {
}
async start(data) {
start(data) {
super.start();
sendLog(LOG_TYPE.EXPOSURE,37)
GameScene.instance = this
console.log("新手引导")
// 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.cdUIRender(StartScene.instance.gameInfo.duration)
this.cdUIRender()
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
}
this.createPhyWorld()
this.bgCon = this.addChild(new FYGE.Container());
this.setChildIndex(this.bgCon, 2)
this.initCloud();
// 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
}
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.initMap();
this.scorenum.text = "0"
this.cdnum.text = StartScene.instance.gameInfo.duration
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;
// }
// }
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()
}
/**
*
* @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]);
}
upDateInfo() {
this.score = 0
this.time = StartScene.instance.gameInfo.duration
......@@ -169,7 +111,7 @@ export class GameScene extends Scene {
this.composites.add(this.world, [this._role.phyBody]);
}
_role; //人物
bgCon; //背景移动
addRole() {
let offset = (1624 - this.stage.viewRect.height) / 2;
......@@ -205,6 +147,8 @@ export class GameScene extends Scene {
Matter.Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this));
Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this));
}
onCollisionTick(e) {
}
......@@ -224,6 +168,9 @@ export class GameScene extends Scene {
num = 2
}
this._role.addScore('+' + num, '#ffffff')
if (Tools.isMusic) {
cusPlaySound("get", false)
}
this.scorenum.text = Number(this.scorenum.text) + num + '';
this.score += num
......@@ -235,6 +182,9 @@ export class GameScene extends Scene {
} 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);
......@@ -247,6 +197,9 @@ export class GameScene extends Scene {
this.gameOver()
} else {
if (!this.jumpLock) {
if (Tools.isMusic) {
cusPlaySound("jump", false)
}
this._role.jump()
this.jumpLock = true;
setTimeout(() => {
......@@ -265,13 +218,13 @@ export class GameScene extends Scene {
for (let i = 0; i < 10; i++) {
// if (i < 4) {
// this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
if (i < 4) {
this.createLineItem(stageHeight - (240 * (i + 2)), 0, false);
// } else {
// this.createLineItem(stageHeight - (240 * (i + 2)));
} else {
this.createLineItem(stageHeight - (240 * (i + 2)));
// }
}
}
......@@ -425,18 +378,23 @@ export class GameScene extends Scene {
}
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.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()
}
}
This diff is collapsed.
......@@ -5,12 +5,15 @@ export default class Role extends FYGE.Container {
public phyBody: Matter.Body;
roleImg: FYGE.Sprite;
beforeY = 0;
direction = 'down';
waittingSvga;
// direction = 'down';
direction;
jumpSvga;
downSvga;
currentIndex = -2;
position;
item
constructor() {
constructor(data?) {
super();
let roleImg = this.roleImg = new FYGE.Sprite();
......@@ -30,7 +33,6 @@ export default class Role extends FYGE.Container {
// },
// this
// );
}
async getSvga(){
this.jumpSvga = new FYGE.SvgaAni(await RES.getResAsync("jumppeo.svga"));
......@@ -60,50 +62,70 @@ export default class Role extends FYGE.Container {
}
leftMove(){
if (this.currentIndex%2 == 0) {
console.log('左移动')
this.direction = 'left'
Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
x: 0.1,
y: 0
});
}
}
rightMove(){
if (this.currentIndex%2 == 1) {
this.direction = 'right'
Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
x: -0.1,
y: 0
});
}
}
/** 根据物理刚体,更新当前的坐标。 */
private onFarm() {
if(this.beforeY){
if( this.beforeY >this.phyBody.position.y ){
if (this.direction == 'left') {
console.log('----')
Matter.Body.setPosition( this.phyBody, {
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 {
this.direction = 'up'
}
// console.log("this.beforeY", this.beforeY)
// if(this.beforeY){
// if( this.beforeY >this.phyBody.position.y ){
if( this.beforeY < this.phyBody.position.y ){
// this.direction = 'up'
// }
this.direction = 'down'
}
}
// if( this.beforeY < this.phyBody.position.y ){
if(this.phyBody.position.x > 750){
Matter.Body.setPosition( this.phyBody, {
x:0,
y:this.phyBody.position.y
})
// this.direction = 'down'
// }
// }
}else if(this.phyBody.position.x<0){
Matter.Body.setPosition( this.phyBody, {
x:750,
y:this.phyBody.position.y
})
}else{
this.x = this.phyBody.position.x;
this.y = this.phyBody.position.y;
}
// if(this.phyBody.position.x > 750){
// Matter.Body.setPosition( this.phyBody, {
// x:0,
// y:this.phyBody.position.y
// })
this.beforeY = this.phyBody.position.y;
// }else if(this.phyBody.position.x<0){
// Matter.Body.setPosition( this.phyBody, {
// x:750,
// y:this.phyBody.position.y
// })
// }else{
// this.x = this.phyBody.position.x;
// this.y = this.phyBody.position.y;
// }
// this.beforeY = this.phyBody.position.y;
}
......@@ -138,13 +160,13 @@ export default class Role extends FYGE.Container {
}
jump() {
if( this.direction == 'up'){return};
setTimeout(()=>{
Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
x: 0,
y: -1.2
});
})
// if( this.direction == 'up'){return};
// setTimeout(()=>{
// Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
// x: 0,
// y: -1.2
// });
// })
}
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