Commit 33ddc46a authored by 任建锋's avatar 任建锋

--

parent b8fc171e
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
this.bubbling('showDialog', 'GameOver');
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onError_ngameSubmit() {
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
this.bubbling('showDialog', 'GameOver');
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onError_ngameSubmit() {
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
this.bubbling('showDialog', 'GameOver');
}
onError_ngameSubmit() {
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
this.bubbling('showDialog', 'GameOver');
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
const param: any = {
orderId: this.doJoinData,
};
this.broadcast('callApi', 1, 'orderStatus', param);
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
this.bubbling('showDialog', 'GameOver');
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
const param: any = {
orderId: this.doJoinData,
};
this.broadcast('callApi', 1, 'orderStatus', param);
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
console.log(this.getNgameStartStatus)
this.bubbling('showDialog', 'GameOver');
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
const param: any = {
orderId: this.doJoinData,
};
this.broadcast('callApi', 1, 'orderStatus', param);
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
console.log(this.getOrderStatus)
this.bubbling('showDialog', 'GameOver');
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
import InteractComponent from "scilla-components/src/base/InteractComponent";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { dynamic,engine} from "scilla/src";
import { createSgin } from "../net/webService";
import { Entity, Tween } from "scilla/src";
import { Transform } from 'scilla-components/src';
import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
bg3: Entity;
car: Entity;
bridge: Entity;
roadGroup: Entity;
road_0: Entity;
road_1: Entity;
road_2: Entity;
road_3: Entity;
life_1: Entity;
life_2: Entity;
life_3: Entity;
check_1:Entity;
check_2:Entity;
check_3:Entity;
check_4:Entity;
bottomGrass: Entity;
carImage: Entity;
score: number;
firstGui: Entity;
//关卡
checkpoint=0
//checkpointCounts=[3,8,18]
checkpointCounts=[3,3,3]
touchEnabled=true;
onAwake() {
super.onAwake();
this.bottomGrass["Transform"] = this.bottomGrass.getComponent(Transform);
this.firstGui["Transform"] = this.firstGui.getComponent(Transform);
this.car["Transform"] = this.car.getComponent(Transform);
this.carImage["Transform"] = this.carImage.getComponent(Transform);
this.bridge["Transform"] = this.bridge.getComponent(Transform);
this.roadGroup["Transform"] = this.roadGroup.getComponent(Transform);
this.road_0["Transform"] = this.road_0.getComponent(Transform);
this.road_1["Transform"] = this.road_1.getComponent(Transform);
this.road_2["Transform"] = this.road_2.getComponent(Transform);
this.road_3["Transform"] = this.road_3.getComponent(Transform);
this.bottomGrass["Transform"].position.y=engine.renderContext.stageSize.height;
this.check_1["Transform"] = this.check_1.getComponent(Transform);
this.check_2["Transform"] = this.check_2.getComponent(Transform);
this.check_3["Transform"] = this.check_3.getComponent(Transform);
this.check_4["Transform"] = this.check_4.getComponent(Transform);
this.bg1["Transform"] = this.bg1.getComponent(Transform);
this.bg2["Transform"] = this.bg2.getComponent(Transform);
this.bg3["Transform"] = this.bg3.getComponent(Transform);
this.setFirstGui()
this.setCarAnimation()
this.bridgeInit()
this.roadInit()
this.bridgeFirst=true;
this.check_1["Transform"].alpha=0;
this.check_2["Transform"].alpha=0;
this.check_3["Transform"].alpha=0;
this.check_4["Transform"].alpha=0;
this.carGoFirst=true;
this.roadIndex=1
this.nowPos=null;
this.lastPos=null;
this.nextPos=null;
this.nextWidth=null;
this.lastIndex=1
this.touchEnabled=true;
this.goCount=0
this.bgIndex=1;
this.checkpoint=0
this.updataBgAndTop()
this.bg1["Transform"].position.x=0;
this.bg2["Transform"].position.x=0;
this.bg3["Transform"].position.x=0;
this.road_0["Transform"].position.x=0;
this.road_1["Transform"].position.x=518;
this.road_2["Transform"].position.x=1033;
this.road_3["Transform"].position.x=1526;
this.roadGroup["Transform"].position.x=0;
this.car["Transform"].position.x=105;
}
onClick_firstGui(){
this.setVisible(this.firstGui,false)
}
//引导页
setFirstGui(){
if(localStorage["firstGui"+window["CFG"].actId]){
this.setVisible(this.firstGui,false)
}else{
localStorage["firstGui"+window["CFG"].actId]="1";
this.setVisible(this.firstGui,true)
}
}
setCarAnimation(){
createTween(this, this.carImage["Transform"],true,{loop:-1})
.set({scale: {x: 1, y: 1},position:{x:0,y:0}})
.to({scale: {x: .98, y: .98},position:{x:.5,y:.5}}, 50)
.to({scale: {x: 1, y: 1},position:{x:-.5,y:-.5}}, 50)
}
//是否隐藏对象
setVisible(obj,state){
if(state){
obj["Transform"].alpha=1;
obj.enabled=true;
}else{
obj["Transform"].alpha=0;
obj.enabled=false;
}
}
roadIndex=1
roadInit(){
this.roadIndex=1
}
carInit(){
this.car["Transform"].position.x=105
this.car["Transform"].position.y=807.5
}
carGoFirst=true;
goCount=0
carGo(){
var distanceMin=0
var distanceMax=0
if(this.roadIndex==1){
console.log("this.roadIndex")
console.log(this.roadIndex)
if(this.carGoFirst){
this.carGoFirst=false;
distanceMin=518-this["road_"+(1)]["Transform"].width
distanceMax=518-this["road_"+(1)]["Transform"].width+this["road_"+(2)]["Transform"].width
console.log("第一次")
}else{
distanceMin=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x
distanceMax=this["road_"+(1)]["Transform"].position.x-this["road_"+(1)]["Transform"].width-this["road_"+(4)]["Transform"].position.x+this["road_"+(4)]["Transform"].width
}
}else{
distanceMin=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x
distanceMax=this["road_"+(this.roadIndex)]["Transform"].position.x-this["road_"+(this.roadIndex)]["Transform"].width-this["road_"+(this.roadIndex-1)]["Transform"].position.x+this["road_"+(this.roadIndex-1)]["Transform"].width
}
/* console.log("最小距离")
console.log(distanceMin)
console.log("最大距离")
console.log(distanceMax)
console.log("当前长度")
console.log(this.bridgeX) */
if(this.bridgeX>distanceMin&&this.bridgeX<distanceMax){
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this["road_"+(this.roadIndex)]["Transform"].position.x+this.roadGroup["Transform"].position.x+100}}, 500)
.call(()=>{
console.log(2233)
this.roadGo()
})
}else{
if(this.bridgeX<distanceMin){
console.log("长度不够")
}
if(this.bridgeX>distanceMax){
console.log("长度超出")
}
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x+this.bridgeX+80}}, 500)
.call(()=>{
this.onGameLose()
})
}
}
nextLength=400+(Math.random()*100)
nowPos
lastPos
nextPos
nextWidth
lastIndex=1
roadGo(){
this.roadIndex++
if(this.roadIndex>3){
this.roadIndex=1;
}
console.log(this.roadIndex)
//缓存当前平台的位置
if(this.nowPos){
this.lastPos=this.nowPos;
}else{
this.lastPos=this["road_1"]["Transform"].position.x
}
this.nextLength=400+(Math.random()*100)
this.nowPos=this["road_"+(this.roadIndex)]["Transform"].position.x
this.nextPos=this["road_"+(this.roadIndex)]["Transform"].position.x+this.nextLength
/* console.log("lastPos")
console.log(this.lastPos)
console.log("nowPos")
console.log(this.nowPos) */
//设置下一个平台的位置
//移动平台
createTween(this, this.roadGroup["Transform"],true,{loop:0})
.to({position: {x:this.roadGroup["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this.roadIndex<3){
this["road_"+(this.roadIndex+1)]["Transform"].position.x=this.nowPos+this.nextLength
}else{
console.log()
this["road_1"]["Transform"].position.x=this.nowPos+this.nextLength
}
})
//移动背景
createTween(this, this["bg"+(this.bgIndex)]["Transform"],true,{loop:0})
.to({position: {x: this["bg"+(this.bgIndex)]["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
if(this["bg"+(this.bgIndex)]["Transform"].position.x<=-750){
this["bg"+(this.bgIndex)]["Transform"].position.x+=750
}
this.bridgeReset()
setTimeout(()=>{
this.touchEnabled=true;
},100)
this.goCount++
this.updataBgAndTop()
})
//移动车辆
createTween(this, this.car["Transform"],true,{loop:0})
.to({position: {x: this.car["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
this.bridgeGo()
}
bgIndex=1;
updataBgAndTop(){
this.bg1["Transform"].alpha=0;
this.bg2["Transform"].alpha=0;
this.bg3["Transform"].alpha=0;
if(this.goCount>=this.checkpointCounts[this.checkpoint]){
this.goCount=0;
this.checkpoint++
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onGameOver()
}
}
if(this.checkpoint<3){
this.bgIndex=this.checkpoint+1
}
if(this.checkpoint>=3){
this.bgIndex=3
}
this["bg"+(this.bgIndex)]["Transform"].alpha=1;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = true;
setTimeout(() => {
//this.bubbling('fuck', 'start');
//this.onGameOver();
}, 3000);
}
onGameOver() {
this.ngameSubmit();
}
ngameSubmit() {
console.log('createSgin', this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const sign = createSgin(this.doJoinData, this.score, '[]', this.getNgameStartStatus.submitToken);
const param: any = {
orderId: this.doJoinData,
score: this.score,
gameData: '[]',
sgin: sign,
dynamicData: '[]'
};
this.broadcast('callApi', 1, 'ngameSubmit', param);
}
onResponse_ngameSubmit() {
const param: any = {
orderId: this.doJoinData,
};
this.broadcast('callApi', 1, 'getOrderStatus', param);
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
console.log(this.getOrderStatus)
this.bubbling('showDialog', 'GameOver');
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
bridgeState=false
onGlobalTouchBegin(e){
if(!this.touchEnabled){
return
}
console.log("begin")
this.bridgeState=true
this.bridgeReset()
console.log(this.bridge["Transform"].position.x)
}
onGlobalTouchEnd(e){
if(!this.touchEnabled){
return
}
console.log("end")
this.bridgeState=false
this.touchEnabled=false;
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({rotation:0 }, 400)
.call(()=>{
this.carGo()
})
}
onGlobalTouchMove(){
if(!this.touchEnabled){
return
}
console.log("move")
}
bridgeInit(){
this.setBridgeX(1)
this.bridge["Transform"].position.y=892;
this.bridge["Transform"].scale.x=0;
}
bridgeReset(){
this.bridgeX=0;
this.bridge["Transform"].scale.x=0
this.setBridgeX(2)
this.bridge["Transform"].position.y=892;
}
//设置杆子的起始位置
bridgeFirst=true;
setBridgeX(state){
if(this.roadIndex==1){
if(this.bridgeFirst){
if(state==2){
this.bridgeFirst=false;
}
this.bridge["Transform"].position.x=this["road_"+(1)]["Transform"].width-26
}else{
this.bridge["Transform"].position.x=
this["road_"+(4)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(4)]["Transform"].width
}
}else{
this.bridge["Transform"].position.x=
this["road_"+(this.roadIndex-1)]["Transform"].position.x
+this.roadGroup["Transform"].position.x+
this["road_"+(this.roadIndex-1)]["Transform"].width
}
}
bridgeGo(){
createTween(this, this.bridge["Transform"],true,{loop:0})
.to({position: {x: this.bridge["Transform"].position.x-(this.nowPos-this.lastPos)}}, 500)
.call(()=>{
//this.carGo()
})
}
bridgeX=0;
onEnterFrame(){
if(this.bridge["Transform"]){
if(this.bridgeState){
this.bridgeX+=40
this.bridge["Transform"].scale.x=this.bridgeX/350;
this.bridge["Transform"].rotation=-90;
}
}
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
async onWillEnter(last: string, action: alien.NavigatorAction, parameters: any) {
}
async onWillLeave(next: string, action: alien.NavigatorAction, parameters: any) {
}
onWillMount(last: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onWillUnMount(next: string, action: alien.NavigatorAction, parameters: any): Promise<any> {
return undefined;
}
onUpdate(t){
super.onUpdate(t)
this.onEnterFrame()
}
}
......@@ -319,7 +319,7 @@
"uuid": "4cf8cf2d-6adf-4f87-843b-617a35e35477"
}
],
"disabled": true
"disabled": false
},
{
"name": "ScenePlay",
......@@ -364,7 +364,8 @@
"check_1": "entity|e4918819-07ed-4023-9cb5-7790865674c5",
"check_2": "entity|df4c7f2b-f693-43da-9b0b-bda88203620a",
"check_3": "entity|2e80cbfa-ef64-4383-acf9-6bd51183cadb",
"check_4": "entity|499f5470-a73f-46f4-bbcf-eff5192c9edf"
"check_4": "entity|499f5470-a73f-46f4-bbcf-eff5192c9edf",
"getOrderStatus": "dynamic|API|getOrderStatus"
}
},
{
......@@ -387,6 +388,27 @@
}
]
}
},
{
"script": "./scripts/api/SamplePollingApi",
"properties": {
"name": "getOrderStatus",
"uri": "/hdtool/recon/getOrderStatus",
"onError": [
{
"entity": "entity|5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
"component": 1,
"method": "onError_orderStatus"
}
],
"onResponse": [
{
"entity": "entity|5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
"component": 1,
"method": "onResponse_orderStatus"
}
]
}
}
],
"uuid": "5bc2f6aa-a570-46cf-bf4e-b2fb1b749bee",
......
......@@ -13,6 +13,7 @@ import {createTween, ease} from "scilla";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
doJoinData: dynamic;
getNgameStartStatus: dynamic;
getOrderStatus: dynamic;
bg1: Entity;
bg2: Entity;
......@@ -292,7 +293,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
this["check_"+this.checkpoint]["Transform"].alpha=1;
if(this.checkpoint>=3){
this["check_"+4]["Transform"].alpha=1;
this.onResponse_ngameSubmit()
this.onGameOver()
}
}
......@@ -333,9 +334,27 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
onResponse_ngameSubmit() {
const param: any = {
orderId: this.doJoinData,
};
this.broadcast('callApi', 1, 'getOrderStatus', param);
}
onError_ngameSubmit() {
}
onResponse_orderStatus() {
//this.bubbling('showDialog', 'GameOver');
console.log(1)
console.log(this.getOrderStatus)
this.bubbling('showDialog', 'GameOver');
}
onError_orderStatus() {
console.log(2)
}
onGameLose() {
this.bubbling('showDialog', 'GameLose');
}
......@@ -430,10 +449,6 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
}
onError_ngameSubmit() {
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
this.entity.enabled = false;
}
......
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