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()
} }
} }
This diff is collapsed.
...@@ -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