Commit ac2e77f9 authored by Master Q's avatar Master Q

游戏

parent e538c88a
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<!-- <script src="libs/svgaParser.min1.js"></script> --> <!-- <script src="libs/svgaParser.min1.js"></script> -->
<script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script> <script src="//yun.duiba.com.cn/js-libs/vConsole/3.3.4/vconsole.min.js"></script>
<script> <script>
var vConsole = new VConsole(); // var vConsole = new VConsole();
</script> </script>
<style> <style>
html, html,
......
resource/GameScene/p1-b.png

14.4 KB | W: | H:

resource/GameScene/p1-b.png

13.5 KB | W: | H:

resource/GameScene/p1-b.png
resource/GameScene/p1-b.png
resource/GameScene/p1-b.png
resource/GameScene/p1-b.png
  • 2-up
  • Swipe
  • Onion skin
resource/GameScene/p1.png

37.2 KB | W: | H:

resource/GameScene/p1.png

30.8 KB | W: | H:

resource/GameScene/p1.png
resource/GameScene/p1.png
resource/GameScene/p1.png
resource/GameScene/p1.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"name": "GameOverPanel" "name": "GameOverPanel"
}, },
{ {
"keys": "balance_guidance.png,guidance-t1.png,p1-b.png,p1.png", "keys": "back.png,balance_guidance.png,guidance-t1.png,num0.png,num1.png,num2.png,num3.png,num4.png,num5.png,num6.png,num7.png,num8.png,num9.png,nump.png,p1-b.png,p1.png,p10-b.png,p10.png,p11-b.png,p11.png,p12-b.png,p12.png,p13-b.png,p13.png,p14-b.png,p14.png,p15-b.png,p15.png,p16-b.png,p16.png,p17-b.png,p17.png,p18-b.png,p18.png,p19-b.png,p19.png,p2-b.png,p2.png,p20-b.png,p20.png,p3-b.png,p3.png,p4-b.png,p4.png,p5-b.png,p5.png,p6-b.png,p6.png,p7-b.png,p7.png,p8-b.png,p8.png,p9-b.png,p9.png",
"name": "GameScene" "name": "GameScene"
}, },
{ {
......
...@@ -178,7 +178,7 @@ export class Main { ...@@ -178,7 +178,7 @@ export class Main {
// const scene = Tools.globalData.newUser ? StoryScene : IndexScene; // const scene = Tools.globalData.newUser ? StoryScene : IndexScene;
// vtodo 是否是新手 // vtodo 是否是新手
changeScene(GameScene); changeScene(NewGuyScene);
// MusicBtn.changeMusicStatus(true); // TODO 进游戏打开音乐先 // MusicBtn.changeMusicStatus(true); // TODO 进游戏打开音乐先
......
...@@ -2,20 +2,732 @@ export const ResJson = { ...@@ -2,20 +2,732 @@ export const ResJson = {
"groups": [ "groups": [
{ {
"keys": "countdown-back.png", "keys": "countdown-back.png",
"name": "CountDownComp" "name": "CountDownComp",
"atlas": {
"countdown-back.png": {
"x": 2,
"y": 2,
"w": 207,
"h": 57,
"ox": 0,
"oy": 0,
"sw": 207,
"sh": 57,
"ro": false
}
}
}, },
{ {
"keys": "back_index.png,gg_back.png,one_more-btn.png", "keys": "back_index.png,gg_back.png,one_more-btn.png",
"name": "GameOverPanel" "name": "GameOverPanel",
"atlas": {
"gg_back.png": {
"x": 2,
"y": 2,
"w": 667,
"h": 578,
"ox": 0,
"oy": 1,
"sw": 666,
"sh": 579,
"ro": false
},
"back_index.png": {
"x": 2,
"y": 582,
"w": 254,
"h": 74,
"ox": 0,
"oy": 0,
"sw": 254,
"sh": 74,
"ro": false
},
"one_more-btn.png": {
"x": 2,
"y": 658,
"w": 254,
"h": 75,
"ox": 0,
"oy": 0,
"sw": 254,
"sh": 75,
"ro": false
}
}
}, },
{ {
"keys": "balance_guidance.png,guidance-t1.png,p1-b.png,p1.png", "keys": "back.png,balance_guidance.png,guidance-t1.png,num0.png,num1.png,num2.png,num3.png,num4.png,num5.png,num6.png,num7.png,num8.png,num9.png,nump.png,p1-b.png,p1.png,p10-b.png,p10.png,p11-b.png,p11.png,p12-b.png,p12.png,p13-b.png,p13.png,p14-b.png,p14.png,p15-b.png,p15.png,p16-b.png,p16.png,p17-b.png,p17.png,p18-b.png,p18.png,p19-b.png,p19.png,p2-b.png,p2.png,p20-b.png,p20.png,p3-b.png,p3.png,p4-b.png,p4.png,p5-b.png,p5.png,p6-b.png,p6.png,p7-b.png,p7.png,p8-b.png,p8.png,p9-b.png,p9.png",
"name": "GameScene" "name": "GameScene",
"atlas": {
"back.png": {
"x": 2,
"y": 2,
"w": 750,
"h": 1624,
"ox": 0,
"oy": 0,
"sw": 750,
"sh": 1624,
"ro": false
},
"guidance-t1.png": {
"x": 754,
"y": 2,
"w": 574,
"h": 183,
"ox": 0,
"oy": 0,
"sw": 574,
"sh": 183,
"ro": true
},
"p1-b.png": {
"x": 939,
"y": 2,
"w": 377,
"h": 537,
"ox": 0,
"oy": 0,
"sw": 377,
"sh": 537,
"ro": false
},
"p1.png": {
"x": 939,
"y": 541,
"w": 377,
"h": 537,
"ox": 0,
"oy": 0,
"sw": 377,
"sh": 537,
"ro": false
},
"p12-b.png": {
"x": 754,
"y": 1080,
"w": 335,
"h": 535,
"ox": 0,
"oy": 0,
"sw": 335,
"sh": 535,
"ro": false
},
"p12.png": {
"x": 1318,
"y": 2,
"w": 335,
"h": 535,
"ox": 0,
"oy": 0,
"sw": 335,
"sh": 535,
"ro": false
},
"p20-b.png": {
"x": 1091,
"y": 1080,
"w": 287,
"h": 535,
"ox": 0,
"oy": 0,
"sw": 287,
"sh": 535,
"ro": false
},
"p20.png": {
"x": 1318,
"y": 539,
"w": 287,
"h": 535,
"ox": 0,
"oy": 0,
"sw": 287,
"sh": 535,
"ro": false
},
"p11-b.png": {
"x": 2,
"y": 1628,
"w": 496,
"h": 533,
"ox": 0,
"oy": 0,
"sw": 496,
"sh": 533,
"ro": true
},
"p11.png": {
"x": 537,
"y": 1628,
"w": 496,
"h": 533,
"ox": 0,
"oy": 0,
"sw": 496,
"sh": 533,
"ro": true
},
"p13-b.png": {
"x": 1072,
"y": 1617,
"w": 421,
"h": 533,
"ox": 0,
"oy": 0,
"sw": 421,
"sh": 533,
"ro": true
},
"p13.png": {
"x": 1655,
"y": 2,
"w": 421,
"h": 533,
"ox": 0,
"oy": 0,
"sw": 421,
"sh": 533,
"ro": false
},
"balance_guidance.png": {
"x": 1380,
"y": 1076,
"w": 258,
"h": 532,
"ox": 0,
"oy": 0,
"sw": 258,
"sh": 532,
"ro": false
},
"p3-b.png": {
"x": 2078,
"y": 2,
"w": 532,
"h": 520,
"ox": 0,
"oy": 0,
"sw": 532,
"sh": 520,
"ro": true
},
"p3.png": {
"x": 2078,
"y": 536,
"w": 532,
"h": 520,
"ox": 0,
"oy": 0,
"sw": 532,
"sh": 520,
"ro": true
},
"p9-b.png": {
"x": 1607,
"y": 1610,
"w": 487,
"h": 532,
"ox": 0,
"oy": 0,
"sw": 487,
"sh": 532,
"ro": true
},
"p9.png": {
"x": 1640,
"y": 1070,
"w": 487,
"h": 532,
"ox": 0,
"oy": 0,
"sw": 487,
"sh": 532,
"ro": false
},
"p4-b.png": {
"x": 2,
"y": 2126,
"w": 499,
"h": 531,
"ox": 0,
"oy": 0,
"sw": 499,
"sh": 531,
"ro": true
},
"p4.png": {
"x": 535,
"y": 2126,
"w": 499,
"h": 531,
"ox": 0,
"oy": 0,
"sw": 499,
"sh": 531,
"ro": true
},
"p6-b.png": {
"x": 1072,
"y": 2099,
"w": 526,
"h": 368,
"ox": 0,
"oy": 0,
"sw": 526,
"sh": 368,
"ro": true
},
"p6.png": {
"x": 1442,
"y": 2099,
"w": 526,
"h": 368,
"ox": 0,
"oy": 0,
"sw": 526,
"sh": 368,
"ro": true
},
"p2-b.png": {
"x": 1812,
"y": 2099,
"w": 524,
"h": 518,
"ox": 0,
"oy": 0,
"sw": 524,
"sh": 518,
"ro": true
},
"p2.png": {
"x": 2600,
"y": 2,
"w": 524,
"h": 518,
"ox": 0,
"oy": 0,
"sw": 524,
"sh": 518,
"ro": true
},
"p18-b.png": {
"x": 1607,
"y": 539,
"w": 270,
"h": 521,
"ox": 0,
"oy": 0,
"sw": 270,
"sh": 521,
"ro": false
},
"p18.png": {
"x": 2129,
"y": 1070,
"w": 270,
"h": 521,
"ox": 0,
"oy": 0,
"sw": 270,
"sh": 521,
"ro": false
},
"p10-b.png": {
"x": 2141,
"y": 1593,
"w": 502,
"h": 513,
"ox": 0,
"oy": 0,
"sw": 502,
"sh": 513,
"ro": true
},
"p10.png": {
"x": 2600,
"y": 528,
"w": 502,
"h": 513,
"ox": 0,
"oy": 0,
"sw": 502,
"sh": 513,
"ro": true
},
"p5-b.png": {
"x": 2656,
"y": 1032,
"w": 460,
"h": 513,
"ox": 0,
"oy": 0,
"sw": 460,
"sh": 513,
"ro": false
},
"p5.png": {
"x": 2656,
"y": 1547,
"w": 460,
"h": 513,
"ox": 0,
"oy": 0,
"sw": 460,
"sh": 513,
"ro": false
},
"p15-b.png": {
"x": 2332,
"y": 2097,
"w": 499,
"h": 463,
"ox": 0,
"oy": 0,
"sw": 499,
"sh": 463,
"ro": true
},
"p15.png": {
"x": 2,
"y": 2627,
"w": 499,
"h": 463,
"ox": 0,
"oy": 0,
"sw": 499,
"sh": 463,
"ro": false
},
"p14-b.png": {
"x": 503,
"y": 2627,
"w": 438,
"h": 460,
"ox": 0,
"oy": 0,
"sw": 438,
"sh": 460,
"ro": false
},
"p14.png": {
"x": 943,
"y": 2627,
"w": 438,
"h": 460,
"ox": 0,
"oy": 0,
"sw": 438,
"sh": 460,
"ro": false
},
"p8-b.png": {
"x": 1383,
"y": 2627,
"w": 308,
"h": 460,
"ox": 0,
"oy": 0,
"sw": 308,
"sh": 460,
"ro": false
},
"p8.png": {
"x": 1693,
"y": 2627,
"w": 308,
"h": 460,
"ox": 0,
"oy": 0,
"sw": 308,
"sh": 460,
"ro": false
},
"p7-b.png": {
"x": 2003,
"y": 2625,
"w": 426,
"h": 443,
"ox": 0,
"oy": 0,
"sw": 426,
"sh": 443,
"ro": false
},
"p7.png": {
"x": 2431,
"y": 2598,
"w": 426,
"h": 443,
"ox": 0,
"oy": 0,
"sw": 426,
"sh": 443,
"ro": false
},
"p17-b.png": {
"x": 2,
"y": 3092,
"w": 434,
"h": 398,
"ox": 0,
"oy": 0,
"sw": 434,
"sh": 398,
"ro": false
},
"p17.png": {
"x": 438,
"y": 3092,
"w": 434,
"h": 398,
"ox": 0,
"oy": 0,
"sw": 434,
"sh": 398,
"ro": false
},
"p19-b.png": {
"x": 2003,
"y": 3070,
"w": 416,
"h": 364,
"ox": 0,
"oy": 0,
"sw": 416,
"sh": 364,
"ro": true
},
"p19.png": {
"x": 2369,
"y": 3070,
"w": 416,
"h": 364,
"ox": 0,
"oy": 0,
"sw": 416,
"sh": 364,
"ro": true
},
"p16-b.png": {
"x": 2735,
"y": 3043,
"w": 406,
"h": 360,
"ox": 0,
"oy": 0,
"sw": 406,
"sh": 360,
"ro": true
},
"p16.png": {
"x": 874,
"y": 3089,
"w": 406,
"h": 360,
"ox": 0,
"oy": 0,
"sw": 406,
"sh": 360,
"ro": false
},
"nump.png": {
"x": 2600,
"y": 1032,
"w": 52,
"h": 59,
"ox": 1,
"oy": 0,
"sw": 54,
"sh": 59,
"ro": false
},
"num0.png": {
"x": 1072,
"y": 2040,
"w": 39,
"h": 57,
"ox": 1,
"oy": 0,
"sw": 41,
"sh": 58,
"ro": false
},
"num3.png": {
"x": 1113,
"y": 2040,
"w": 38,
"h": 57,
"ox": 1,
"oy": 0,
"sw": 38,
"sh": 58,
"ro": false
},
"num8.png": {
"x": 1153,
"y": 2040,
"w": 38,
"h": 57,
"ox": 0,
"oy": 0,
"sw": 39,
"sh": 58,
"ro": false
},
"num2.png": {
"x": 1193,
"y": 2040,
"w": 40,
"h": 56,
"ox": 0,
"oy": 0,
"sw": 39,
"sh": 57,
"ro": false
},
"num5.png": {
"x": 1235,
"y": 2040,
"w": 37,
"h": 56,
"ox": 1,
"oy": 0,
"sw": 38,
"sh": 57,
"ro": false
},
"num6.png": {
"x": 2735,
"y": 3451,
"w": 38,
"h": 56,
"ox": 1,
"oy": 0,
"sw": 39,
"sh": 57,
"ro": true
},
"num9.png": {
"x": 874,
"y": 3451,
"w": 38,
"h": 56,
"ox": 1,
"oy": 0,
"sw": 38,
"sh": 57,
"ro": true
},
"num1.png": {
"x": 1274,
"y": 2040,
"w": 22,
"h": 55,
"ox": 1,
"oy": 1,
"sw": 23,
"sh": 57,
"ro": false
},
"num4.png": {
"x": 1298,
"y": 2040,
"w": 40,
"h": 55,
"ox": 1,
"oy": 0,
"sw": 41,
"sh": 56,
"ro": false
},
"num7.png": {
"x": 1340,
"y": 2040,
"w": 42,
"h": 55,
"ox": 1,
"oy": 0,
"sw": 42,
"sh": 56,
"ro": false
}
}
}, },
{ {
"keys": "comCloseBtn.png,com_light.png,toastBg.png,waitingBg.png,waitingRot.png,跳过按钮.png", "keys": "comCloseBtn.png,com_light.png,toastBg.png,waitingBg.png,waitingRot.png,跳过按钮.png",
"name": "common" "name": "common",
"atlas": {
"com_light.png": {
"x": 2,
"y": 2,
"w": 746,
"h": 756,
"ox": 0,
"oy": 0,
"sw": 746,
"sh": 756,
"ro": false
},
"toastBg.png": {
"x": 750,
"y": 2,
"w": 460,
"h": 130,
"ox": 0,
"oy": 0,
"sw": 460,
"sh": 130,
"ro": true
},
"waitingBg.png": {
"x": 2,
"y": 760,
"w": 160,
"h": 180,
"ox": 0,
"oy": 0,
"sw": 160,
"sh": 180,
"ro": true
},
"跳过按钮.png": {
"x": 750,
"y": 464,
"w": 123,
"h": 57,
"ox": 0,
"oy": 0,
"sw": 123,
"sh": 57,
"ro": false
},
"comCloseBtn.png": {
"x": 750,
"y": 523,
"w": 72,
"h": 72,
"ox": 0,
"oy": 0,
"sw": 72,
"sh": 72,
"ro": false
},
"waitingRot.png": {
"x": 824,
"y": 523,
"w": 56,
"h": 56,
"ox": 0,
"oy": 0,
"sw": 56,
"sh": 56,
"ro": false
}
}
} }
], ],
"path": "./resource/" "path": "https://yun.duiba.com.cn/db_games/activity/template/1628480167/resource/"
} }
\ No newline at end of file
type CircleProgressType = {
x?: number,
y?: number,
radius?: number,
circleColor?: number,
backColor?: number,
lineWidth?: number,
value?:number
}
export default class CircleProgressBar extends FYGE.Container {
opt: CircleProgressType
_value: number
constructor(opt?: CircleProgressType) {
super()
this.opt = Object.assign({}, {
x: 0,
y: 0,
radius: 10,
lineWidth: 10,
circleColor: 0xfe5000,
backColor: 0xf0e4ce,
value: 0
}, opt)
this._value = this.opt.value > 1 ? 1 : (this.opt.value < 0 ? 0 : this.opt.value)
this.initUi()
}
backCircle: FYGE.Shape
progressCircle: FYGE.Shape
initUi() {
var radius = this.opt.radius
var lw = this.opt.lineWidth
this.x = this.opt.x - radius - lw
this.y = this.opt.y - radius - lw
this.backCircle = this.addChild(new FYGE.Shape)
this.backCircle.anchorTexture.set(0.5, 0.5)
this.backCircle.beginStroke(this.opt.backColor, this.opt.lineWidth)
this.backCircle.arc(radius + lw, radius + lw, radius, 0, 2*Math.PI)
this.backCircle.endStroke()
this.strokeProgress(this.opt.value)
}
strokeProgress(v) {
var radius = this.opt.radius
var lw = this.opt.lineWidth
if (!this.progressCircle) {
this.progressCircle = this.addChild(new FYGE.Shape)
this.progressCircle.anchorX = radius + lw
this.progressCircle.anchorY = radius + lw
this.progressCircle.rotation = -90 // 好看点
this.progressCircle.beginStroke(this.opt.circleColor, this.opt.lineWidth, FYGE.LINE_CAP.ROUND)
this.progressCircle.arc(radius + lw, radius + lw, radius, 0, 2*Math.PI * v)
this.progressCircle.endStroke()
} else {
this.progressCircle.clear()
this.progressCircle.beginStroke(this.opt.circleColor, this.opt.lineWidth, FYGE.LINE_CAP.ROUND)
.arc(radius + lw, radius + lw, radius, 0, 2*Math.PI * v)
.endStroke()
}
}
get value() {
return this._value;
}
set value(v) {
if (v < 0) v = 0;
if (v > 1) v = 1;
this._value = v;
// this.progressTxt && (this.progressTxt.text = this.progressCfg.valueDesc + ((v * 100) >> 0) + "%");
this.strokeProgress(v)
}
}
\ No newline at end of file
...@@ -11,6 +11,22 @@ type TimeObj = { ...@@ -11,6 +11,22 @@ type TimeObj = {
export default class CountDownComp extends Module { export default class CountDownComp extends Module {
timeoutFn: Array<Function> timeoutFn: Array<Function>
tobj: TimeObj // 倒计时 tobj: TimeObj // 倒计时
iTime: number // 第一次的时间
get initTime():number {
return this.iTime
}
/**
* 初始化时间
* @param t
*/
set initTime(t:number) {
this.iTime = t
this.tobj = {t}
this.formatTime(t)
}
constructor(t: number) { constructor(t: number) {
super(t) super(t)
} }
...@@ -25,7 +41,7 @@ export default class CountDownComp extends Module { ...@@ -25,7 +41,7 @@ export default class CountDownComp extends Module {
this.cdt = UI.Txt(this, '00:00:00', 30, '#ffffff', FYGE.TEXT_ALIGN.LEFT, 200, 63, 17) this.cdt = UI.Txt(this, '00:00:00', 30, '#ffffff', FYGE.TEXT_ALIGN.LEFT, 200, 63, 17)
this.initTime(this.data) this.initTime = this.data
} }
/** /**
...@@ -42,15 +58,6 @@ export default class CountDownComp extends Module { ...@@ -42,15 +58,6 @@ export default class CountDownComp extends Module {
this.timeoutFn.splice(i, 1) this.timeoutFn.splice(i, 1)
} }
/**
* 初始化时间
* @param t
*/
initTime(t:number) {
this.tobj = {t}
this.formatTime(t)
}
formatTime(n:number) { formatTime(n:number) {
var _t = dateLeftFormat('mm:ss', (n / 1000) >> 0) var _t = dateLeftFormat('mm:ss', (n / 1000) >> 0)
_t += `:${padStart((n%1000/10 >> 0), 2, '0')}`; _t += `:${padStart((n%1000/10 >> 0), 2, '0')}`;
...@@ -78,7 +85,7 @@ export default class CountDownComp extends Module { ...@@ -78,7 +85,7 @@ export default class CountDownComp extends Module {
} }
restart(t?:number) { restart(t?:number) {
t && this.initTime(t) t && (this.initTime = t)
this.start() this.start()
} }
......
...@@ -58,7 +58,7 @@ class DeviceMotion { ...@@ -58,7 +58,7 @@ class DeviceMotion {
} }
removeEvents() { _tmdremoveEvents() {
if (my) { if (my) {
//@ts-ignore //@ts-ignore
my.offDeviceMotionChange(); my.offDeviceMotionChange();
......
...@@ -2,7 +2,10 @@ export const GameCfg = { ...@@ -2,7 +2,10 @@ export const GameCfg = {
acc: 0.3, // 垂直重力加速度 todo 对不同帧率进行处理 acc: 0.3, // 垂直重力加速度 todo 对不同帧率进行处理
ispeed: 0, // 初速度 ispeed: 0, // 初速度
fpsScale: 1000 / 60, // 帧变数 fpsScale: 1000 / 60, // 帧变数
resisteAcc: 0.03, // 摩擦力反加速度 resisteAcc: 0.06, // 摩擦力反加速度
rc: 20, // 误差值,距离中心点的误差值 rc: 20, // 误差值,距离中心点的误差值
duanpingValue: 8 / 180 * Math.PI, // 默认小于 8 度就算端平 duanpingValue: 8 / 180 * Math.PI, // 默认小于 8 度就算端平
iTime: 12000, // 初始化游戏时间
rt: 1000 //每次递减
} }
\ No newline at end of file
...@@ -8,6 +8,8 @@ import { GDispatcher } from '../../Main'; ...@@ -8,6 +8,8 @@ import { GDispatcher } from '../../Main';
import { MotionInitFunc, MotionInitScene } from './MotionInit'; import { MotionInitFunc, MotionInitScene } from './MotionInit';
import { setCenterPos } from '../NewGuyScene/NewGuyScene'; import { setCenterPos } from '../NewGuyScene/NewGuyScene';
import CountDownComp from '../../components/CountDownComp'; import CountDownComp from '../../components/CountDownComp';
import CircleProgressBar from '../../common/CircleProgressBar';
import { RES } from '../../../module/RES';
const Container = FYGE.Container const Container = FYGE.Container
const TEXT_ALIGN = FYGE.TEXT_ALIGN const TEXT_ALIGN = FYGE.TEXT_ALIGN
...@@ -55,42 +57,54 @@ function pos2Len(p1: pos, p2:pos):number { ...@@ -55,42 +57,54 @@ function pos2Len(p1: pos, p2:pos):number {
export class GameScene extends MotionInitScene { export class GameScene extends MotionInitScene {
ralpha: number = 0
rbeta: number = 0
rgamma: number = 0
constructor(...args){ cdp: CountDownComp
scoreText: FYGE.TextField
_score: number
gameEle: GameEle
_gIndex: number = 1 // 游戏元素索引
constructor(...args: any){
super(...args) super(...args)
} }
set gIndex(n: number) {
this._gIndex = n % 20 || 20
this.gameEle && this.gameEle.resetInit(`p${n}.png`)
this.centerp && (this.centerp.texture = RES.getRes(`p${n}-b.png`))
}
get gIndex(): number {
return this._gIndex
}
get groupNames(): string[] { get groupNames(): string[] {
return ['GameScene'] return ['GameScene']
} }
alphaText: FYGE.TextField set score(n: number) {
betaText: FYGE.TextField this._score = n;
gammaText: FYGE.TextField (this.scoreText || (this.scoreText = UI.Txt(this, '连续完成: ' + n, 40, '#111111', FYGE.TEXT_ALIGN.CENTER, layers.stageWidth, 0, layers.stageOffsetY + 200, true))).text = '连续完成: '+n
centerp: FYGE.Sprite }
gyroscope: FYGE.TextField
cdp: CountDownComp
async initUi() {
UI.Txt(this, '陀螺仪游戏调试', 50, '#000000', TEXT_ALIGN.CENTER, layers.stageWidth, layers.stageOffsetX, layers.stageOffsetY + 10, true) get score() {
this.alphaText = UI.Txt(this, 'alpha: 0', 40, '#000000', TEXT_ALIGN.CENTER, layers.stageWidth, layers.stageOffsetX, layers.stageOffsetY + 100) return this._score
this.betaText = UI.Txt(this, 'beta: 0', 40, '#000000', TEXT_ALIGN.CENTER, layers.stageWidth, layers.stageOffsetX, layers.stageOffsetY + 150) }
this.gammaText = UI.Txt(this, 'gamma: 0', 40, '#000000', TEXT_ALIGN.CENTER, layers.stageWidth, layers.stageOffsetX, layers.stageOffsetY + 200)
this.gyroscope = UI.Txt(this, '', 40, '#000000', TEXT_ALIGN.CENTER, layers.stageWidth, 0, layers.stageOffsetY + 300) async initUi() {
UI.Sp(this, 'back.png')
// vtodo 模拟中心点 this.score = 0
var centerp = this.centerp = setCenterPos(UI.Sp(this, 'p1-b.png'))
var cdp = this.cdp = this.addChild(new CountDownComp(12000)) var cdp = this.cdp = this.addChild(new CountDownComp(GameCfg.iTime))
this.cdp.addTimeoutFunc(() => { this.cdp.addTimeoutFunc(() => {
console.log('时间结束') // this.cdp.visible = false
//@ts-ignore
my.showToast({
content: '游戏结束'
})
}) })
cdp.position.set(layers.stageOffsetX + layers.stageWidth - 230, layers.stageOffsetY + 40) cdp.position.set(layers.stageCenterX - 105, layers.stageOffsetY + 260)
super.initUi() super.initUi()
} }
...@@ -98,9 +112,12 @@ export class GameScene extends MotionInitScene { ...@@ -98,9 +112,12 @@ export class GameScene extends MotionInitScene {
initGame() { initGame() {
this.cdp.start() this.cdp.start()
this.addChild(new GameEle('p1.png', this.centerp, () => { this.gameEle = this.addChild(new GameEle('p1-b.png', this.centerp, () => {
this.cdp.initTime(15000) this.score += 1
this.motionInitFunc.showGuidance() this.gIndex += 1
this.cdp.initTime = GameCfg.iTime
// 直接出来一个
// this.motionInitFunc.showGuidance()
})) }))
} }
...@@ -113,36 +130,28 @@ export class GameScene extends MotionInitScene { ...@@ -113,36 +130,28 @@ export class GameScene extends MotionInitScene {
} }
initEvents() { initEvents() {
console.log('%c 初始化事件 ========', 'color: green')
// vtodo 先用window 陀螺仪进行处理
deviceMotionSubs.notify(this.orientationHandler, this)
//@ts-ignore
// my && my.onGyroscopeChange((res) => {
// this.gyroscope.text = `x:${res.x.toFixed(2)}, y: ${res.y.toFixed(2)}, z: ${res.z.toFixed(2)}`
// this.alphaText.text = `alpha: ${(this.ralpha += res.z).toFixed(2)}`
// this.betaText.text = `beta: ${(this.rbeta += res.x).toFixed(2)}`
// this.gammaText.text = `gamma: ${(this.rgamma += res.y).toFixed(2)}`
// })
} }
removeEvents() { removeEvents() {
deviceMotionSubs.off(this.orientationHandler)
} }
orientationHandler(event) {
var alpha = event.alpha
var beta = event.beta
var gamma = event.gamma
this.alphaText.text = `alpha: ${event.alpha.toFixed(2)}`
this.betaText.text = `beta: ${event.beta.toFixed(2)}`
this.gammaText.text = `gamma: ${event.gamma.toFixed(2)}`
}
} }
var posList = [
{
x: 0, y: layers.stageHeight + layers.stageOffsetY
},
{
x: layers.stageWidth + layers.stageOffsetX,
y: 0
},
{
x: layers.stageWidth + layers.stageOffsetX,
y: layers.stageHeight + layers.stageOffsetY
}
]
export class GameEle extends Container { export class GameEle extends Container {
rorate:number // 旋转角度 rorate:number // 旋转角度
vx = GameCfg.ispeed // 当前x速度, 有初速度 vx = GameCfg.ispeed // 当前x速度, 有初速度
...@@ -160,7 +169,6 @@ export class GameEle extends Container { ...@@ -160,7 +169,6 @@ export class GameEle extends Container {
/** /**
* 是否固定在页面上 * 是否固定在页面上
* @param fixedCenter
* @param cb 正中心的回调函数 * @param cb 正中心的回调函数
*/ */
constructor(textureName: string ,fixedCenter: pos, cb?: Function) { constructor(textureName: string ,fixedCenter: pos, cb?: Function) {
...@@ -174,8 +182,10 @@ export class GameEle extends Container { ...@@ -174,8 +182,10 @@ export class GameEle extends Container {
initUi(tn: string) { initUi(tn: string) {
if (tn) { if (tn) {
this.sprite = UI.Sp(this, tn) this.sprite = UI.Sp(this, tn)
this.sprite.scaleX = 0.5 var pos = posList[Math.floor(Math.random() * 3)]
this.sprite.scaleY = 0.5 this.position.set(pos.x, pos.y)
// this.sprite.scaleX = 0.5
// this.sprite.scaleY = 0.5
this.sprite.anchorTexture.set(0.5, 0.5) this.sprite.anchorTexture.set(0.5, 0.5)
} else { } else {
throw new Error('GameEle need a sprite') throw new Error('GameEle need a sprite')
...@@ -188,6 +198,15 @@ export class GameEle extends Container { ...@@ -188,6 +198,15 @@ export class GameEle extends Container {
} }
resetInit(tName: string) {
this.sprite.texture = RES.getRes(tName)
var pos = posList[Math.floor(Math.random() * 3)]
this.position.set(pos.x, pos.y)
var rotation = Math.floor(Math.random() * 361)
this.k = (rotation + 360) / (pos2Len(this.fixedCenter, this) - GameCfg.rc)
}
initEvents() { initEvents() {
deviceMotionSubs.notify(this.orientationChange, this) deviceMotionSubs.notify(this.orientationChange, this)
} }
...@@ -197,7 +216,6 @@ export class GameEle extends Container { ...@@ -197,7 +216,6 @@ export class GameEle extends Container {
} }
destroy() { destroy() {
deviceMotionSubs.removeEvents()
this.removeEvents() this.removeEvents()
super.destroy() super.destroy()
} }
...@@ -255,8 +273,7 @@ export class GameEle extends Container { ...@@ -255,8 +273,7 @@ export class GameEle extends Container {
// this.vy =0 // this.vy =0
// } // }
// vtodo 游戏大小 先设置100 var sw = this.sprite.width / 4
var sw = this.sprite.width / 2
if (this.x > layers.stageWidth + layers.stageOffsetX - sw) { if (this.x > layers.stageWidth + layers.stageOffsetX - sw) {
this.x = layers.stageWidth + layers.stageOffsetX - sw this.x = layers.stageWidth + layers.stageOffsetX - sw
this.vx = 0 this.vx = 0
...@@ -265,7 +282,7 @@ export class GameEle extends Container { ...@@ -265,7 +282,7 @@ export class GameEle extends Container {
this.vx = 0 this.vx = 0
} }
var sh = this.sprite.height / 2 var sh = this.sprite.height / 4
if (this.y > layers.stageHeight + layers.stageOffsetY - sh) { if (this.y > layers.stageHeight + layers.stageOffsetY - sh) {
this.y = layers.stageHeight + layers.stageOffsetY - sh this.y = layers.stageHeight + layers.stageOffsetY - sh
this.vy = 0 this.vy = 0
......
import { RES } from "../../../module/RES"
import { layers } from "../../../module/views/layers" import { layers } from "../../../module/views/layers"
import { Scene } from "../../../module/views/Scene" import { Scene } from "../../../module/views/Scene"
import CircleProgressBar from "../../common/CircleProgressBar"
import { ProgressBar } from "../../common/ProgressBar" import { ProgressBar } from "../../common/ProgressBar"
import { GDispatcher } from "../../Main" import { GDispatcher } from "../../Main"
import { Tools } from "../../Tools"
import UI from "../../UI" import UI from "../../UI"
import { setCenterPos } from "../NewGuyScene/NewGuyScene"
import deviceMotionSubs from "./DeviceMotion" import deviceMotionSubs from "./DeviceMotion"
import { GameCfg } from "./GameConfig" import { GameCfg } from "./GameConfig"
const Container = FYGE.Container const Container = FYGE.Container
...@@ -102,15 +106,39 @@ export class MotionInitFunc extends Container { ...@@ -102,15 +106,39 @@ export class MotionInitFunc extends Container {
export class MotionInitScene extends Scene { export class MotionInitScene extends Scene {
motionInitFunc: MotionInitFunc // 端平action类 motionInitFunc: MotionInitFunc // 端平action类
holdOnTxt: FYGE.TextField // 保持住文案
constructor(...args) { constructor(...args) {
super(...args) super(...args)
this._initEvents() this._initEvents()
} }
bitmapTextCount: FYGE.BitmapText
centerp: FYGE.Sprite // 中心校准点
initUi() { initUi() {
// 中间的小圆
var c = this.addChild(new FYGE.Shape())
.beginFill(0xf0e4ce)
.arc(layers.stageCenterX, layers.stageCenterY, 240, 0, 2*Math.PI)
.endFill()
this.centerp = setCenterPos(UI.Sp(this, 'p1-b.png'))
var bitMapc = Tools.getNumTextures('num')
bitMapc['%'] = RES.getRes('nump.png')
this.bitmapTextCount = this.addChild(new FYGE.BitmapText(bitMapc))
this.bitmapTextCount.position.set(layers.stageCenterX, layers.stageCenterY + 380)
this.holdOnTxt = UI.Txt(this, '保持住!', 50, '#111111', FYGE.TEXT_ALIGN.CENTER, layers.stageWidth, 0, layers.stageCenterY - 400, true)
this.holdOnTxt.visible = false
this.setChildIndex(c, 1)
var cb = this.initGame.bind(this) var cb = this.initGame.bind(this)
this.motionInitFunc = this.addChild(new MotionInitFunc(cb)) this.motionInitFunc = this.addChild(new MotionInitFunc(cb))
super.initUi() super.initUi()
} }
...@@ -138,23 +166,39 @@ export class MotionInitScene extends Scene { ...@@ -138,23 +166,39 @@ export class MotionInitScene extends Scene {
} }
focusProgress: ProgressBar focusProgress: CircleProgressBar
addTimeCountDown = debounce((e) => { addTimeCountDown = debounce((e) => {
this.shoot() this.shoot()
this.focusProgress = this.addChild(new ProgressBar(0xff200d, { // this.focusProgress = this.addChild(new ProgressBar(0xff200d, {
valueDesc: '保存进度', // valueDesc: '保存进度',
valueColor: '#000000', // valueColor: '#000000',
type: 'fill', // type: 'fill',
typeColor: 0x111111 // typeColor: 0x111111
// }))
this.focusProgress = this.addChild(new CircleProgressBar({
x: layers.stageCenterX,
y: layers.stageCenterY, // vtodo 这里后面可能会调试
radius: 260,
lineWidth: 15,
value: 0
})) }))
this.focusProgress.position.set(177, layers.stageCenterY + 400)
FYGE.Tween.get(this.focusProgress) FYGE.Tween.get(this.holdOnTxt)
.set({visible: true, alpha: 0.4})
.to({alpha: 1}, 600)
FYGE.Tween.get(this.focusProgress,{
onChange: () => {
this.bitmapTextCount.text = ((this.focusProgress.value * 100) >> 0) + "%"
}
})
.to({value: 1}, 3000) .to({value: 1}, 3000)
.call(() => { .call(() => {
console.log('%c 成功套种', 'color: green') console.log('%c 成功套种', 'color: green')
typeof e.data == 'function' && e.data() typeof e.data == 'function' && e.data()
this.removeTimeCountDown() this.removeTimeCountDown()
}) })
}, 400) }, 400)
removeTimeCountDown() { removeTimeCountDown() {
...@@ -162,7 +206,12 @@ export class MotionInitScene extends Scene { ...@@ -162,7 +206,12 @@ export class MotionInitScene extends Scene {
this.unshoot() this.unshoot()
FYGE.Tween.removeTweens(this.focusProgress) FYGE.Tween.removeTweens(this.focusProgress)
this.removeChild(this.focusProgress) this.removeChild(this.focusProgress)
this.bitmapTextCount.text = ''
} }
FYGE.Tween.removeTweens(this.holdOnTxt)
this.holdOnTxt.visible = false
// @ts-ignore // @ts-ignore
clearTimeout(this.addTimeCountDown.timer.curr) clearTimeout(this.addTimeCountDown.timer.curr)
} }
......
...@@ -3,14 +3,15 @@ import { layers } from "../../../module/views/layers" ...@@ -3,14 +3,15 @@ import { layers } from "../../../module/views/layers"
import { GameEle, GameScene } from "../GameScene/GameScene" import { GameEle, GameScene } from "../GameScene/GameScene"
import { MotionInitScene } from '../GameScene/MotionInit'; import { MotionInitScene } from '../GameScene/MotionInit';
import UI from '../../UI'; import UI from '../../UI';
import { RES } from '../../../module/RES';
export function setCenterPos(cont: FYGE.Sprite) { export function setCenterPos(cont: FYGE.Sprite) {
cont.anchorTexture.set(0.5, 0.5) cont.anchorTexture.set(0.5, 0.5)
// vtodo 先这里设置一般大 // vtodo 先这里设置一般大
cont.scaleX = 0.5 // cont.scaleX = 0.5
cont.scaleY = 0.5 // cont.scaleY = 0.5
cont.x = layers.stageOffsetX + layers.stageWidth / 2 cont.x = layers.stageCenterX
cont.y = layers.stageOffsetY + layers.stageHeight / 2 cont.y = layers.stageCenterY
return cont return cont
} }
...@@ -24,12 +25,9 @@ export class NewGuyScene extends MotionInitScene { ...@@ -24,12 +25,9 @@ export class NewGuyScene extends MotionInitScene {
super() super()
} }
centerp: FYGE.Sprite async initUi() {
initUi() { UI.Sp(this, 'back.png')
var centerp = this.centerp = setCenterPos(UI.Sp(this, 'p1-b.png'))
this.setChildIndex(centerp, -1)
super.initUi() super.initUi()
} }
...@@ -39,7 +37,7 @@ export class NewGuyScene extends MotionInitScene { ...@@ -39,7 +37,7 @@ export class NewGuyScene extends MotionInitScene {
this.g1 = UI.Sp(this, 'guidance-t1.png', layers.stageCenterX, layers.stageCenterY + 400) this.g1 = UI.Sp(this, 'guidance-t1.png', layers.stageCenterX, layers.stageCenterY + 400)
this.g1.anchorTexture.set(0.5, 0.5) this.g1.anchorTexture.set(0.5, 0.5)
var e = this.addChild(new GameEle('p1-b.png', this.centerp, () => { var e = this.addChild(new GameEle('p1.png', this.centerp, () => {
changeScene(GameScene) changeScene(GameScene)
})) }))
} }
......
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