Commit ef479ff3 authored by Joker Huang's avatar Joker Huang

1

parent 651de262
import { DataManager } from './../../libs/tw/manager/DataManager';
import prePlayScene from "./prePlayScene";
import Game from "./Game/Game";
import PlaySceneBase from "../../libs/new_wx/components/PlaySceneBase";
import PanelCtrl from "../../libs/new_wx/ctrls/panelCtrl";
import { ModuleTypes } from "../../libs/new_wx/types/sceneTypes";
import { NetManager } from "../../libs/tw/manager/NetManager";
const BABYLON = window['BABYLON'];
const { TouchEvent } = egret;
export default class PlayScene extends PlaySceneBase{
public get skinKey() { return 'Play' }
......@@ -15,98 +15,58 @@ export default class PlayScene extends PlaySceneBase{
public scoreTxt:eui.Label;
public scoreTip:eui.Image;
public BABYLON:any = window['BABYLON'];
public rocketP:any;
public rocketLine:any;
public score:number = 0; // 分数
private touchDown:boolean; // 是否点击屏幕
private createCount:number = 0; // 生成云的计数
gameNode
constructor(){
super()
this.restart();
}
restart(){
prePlayScene.instance.disposeAll();
prePlayScene.instance.rocketP.position.y = 10;
prePlayScene.instance.lastY = 0;
prePlayScene.instance.maxDepth = 0;
prePlayScene.instance.startTimestamp = Date.now();
prePlayScene.instance.initElementPool()
this.addEventListener(egret.Event.ENTER_FRAME,this.onEnterFrame,this);
}
private onEnterFrame(){
this.createCount++;
// 是否触控发生
if(this.touchDown){
prePlayScene.instance.rotateSpeed = 0.1;
}else{
prePlayScene.instance.rotateSpeed = 0;
}
prePlayScene.instance.mainObj.rotation.y -= prePlayScene.instance.rotateSpeed;
prePlayScene.instance.scene.render();
prePlayScene.instance.accelerateByVector3(prePlayScene.instance.rocketP,new this.BABYLON.Vector3(0,-1,0), prePlayScene.instance.downSpeed, prePlayScene.instance.downAddSpeed)
if(prePlayScene.instance.eleTemplatePool.length>0){
if(prePlayScene.instance.rocketP.position.y < prePlayScene.instance.lastY + prePlayScene.instance.elementInterval * 5 ){
let num = Math.min(Math.floor( Math.random() * 5 ) , 4)
let nEle = prePlayScene.instance.eleTemplatePool[num].clone(`element_${num}`);
let newAngle = Math.random()*Math.PI*2;
nEle.position.y = prePlayScene.instance.lastY - prePlayScene.instance.elementInterval;
nEle.rotate(new this.BABYLON.Vector3(0,1,0), newAngle);
nEle.parent = prePlayScene.instance.mainObj;
prePlayScene.instance.lastY -= prePlayScene.instance.elementInterval;
prePlayScene.instance.nElePool.push(nEle);
for(let e = 0; e < nEle['_children'].length; e++){
let element = nEle['_children'][e];
let redEleNum = Math.min(Math.floor( Math.random() * prePlayScene.instance.eleTemplatePool.length ) , prePlayScene.instance.eleTemplatePool.length - 1);
if(e == redEleNum){
element.gameType = 'redElement';
element.material = prePlayScene.instance.redMaterial.clone();
}
element.visibility = 1;
prePlayScene.instance.elementPool.push(element);
}
}
if(prePlayScene.instance.rocketP.position.y<prePlayScene.instance.maxDepth){
if(Math.abs(prePlayScene.instance.rocketP.position.y - prePlayScene.instance.maxDepth) > prePlayScene.instance.elementInterval){
this.updateScore(1);
prePlayScene.instance.maxDepth = prePlayScene.instance.rocketP.position.y;
}
}
}
// 碰撞检测
for(let element of prePlayScene.instance.elementPool){
if (element.intersectsMesh(prePlayScene.instance.realRocket, true)) {
console.log(1)
if(element.gameType == 'redElement'){
// 撞到了黑云 游戏结束
this.gameOver();
}else{
// 如果碰到了就让速度反向
prePlayScene.instance.downSpeed = -0.5;
prePlayScene.instance.startTimestamp = Date.now()
//
}
}else{
}
let config = {
sps:[{
depth:5,
fall:5
},{
depth:35,
fall:5
},{
depth:55,
fall:5
},{
depth:65,
fall:5
}],
beyondFriends : [{
score:5,
id:1
},
{
score:15,
id:2
},
{
score:25,
id:3
},
{
score:35,
id:4
}]
}
this.gameNode = new Game(config)
}
initEvents() {
this.touchPlane.addEventListener( egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin_touchPlane, this);
this.touchPlane.addEventListener( egret.TouchEvent.TOUCH_END, this.onTouchOut_touchPlane, this);
this.touchPlane.addEventListener( egret.TouchEvent.TOUCH_CANCEL, this.onTouchOut_touchPlane, this);
this.touchPlane.addEventListener( egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchOut_touchPlane, this);
this.addEventListener(egret.Event.ENTER_FRAME,this.onEnterFrame,this);
}
removeEvents() {
......@@ -114,18 +74,22 @@ export default class PlayScene extends PlaySceneBase{
this.touchPlane.removeEventListener( egret.TouchEvent.TOUCH_END, this.onTouchOut_touchPlane, this);
this.touchPlane.removeEventListener( egret.TouchEvent.TOUCH_CANCEL, this.onTouchOut_touchPlane, this);
this.touchPlane.removeEventListener( egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchOut_touchPlane, this);
this.removeEventListener(egret.Event.ENTER_FRAME,this.onEnterFrame,this);
}
onEnterFrame(){
this.gameNode?.scene?.render()
}
private onTouchBegin_touchPlane(e:egret.TouchEvent){
this.touchDown = true;
this.gameNode&&(this.gameNode.touchDown = true);
}
private onTouchOut_touchPlane(e:egret.TouchEvent){
this.touchDown = false;
this.gameNode&&(this.gameNode.touchDown = false);
}
gameOver(){
this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
this.removeEventListener(egret.Event.ENTER_FRAME, this.gameNode.onEnterFrame, this);
this.gameSubmitData(this.gameSubmitResult.bind(this), this.score);
}
......@@ -182,6 +146,7 @@ export default class PlayScene extends PlaySceneBase{
}
// 更新分数
private updateScore(score?:number){
let _score = 1;
......
import StartSceneBase from "../../libs/new_wx/components/StartSceneBase";
import prePlayScene from "../playScene/prePlayScene";
export default class StartScene extends StartSceneBase {
async start(){
super.start();
if(!prePlayScene.instance.canvasWebgl){
prePlayScene.instance.initScene();
}
}
}
\ No newline at end of file
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