Commit e9a9bef4 authored by Master Q's avatar Master Q

难度调整

parent 713825e8
......@@ -3826,5 +3826,5 @@ export const ResJson = {
}
}
],
"path": "https://yun.duiba.com.cn/db_games/activity/template/1629979469/resource/"
"path": "https://yun.duiba.com.cn/db_games/activity/template/1630392653/resource/"
}
\ No newline at end of file
import { showToast, wait, clearWait, showWaiting, hideWaiting } from "../module/ctrls";
import { GDispatcher } from "./Main";
import { myApp, Tools } from "./Tools";
//接口枚举,包括需要调用淘宝的api,用是否含有兑吧区分,或者单独区分
export enum TbNetName {
......@@ -147,6 +148,12 @@ export function sendTbNet(
hidWaiting: boolean = false,
): Promise<dataOut> {
return new Promise((resolve, reject) => {
// musicStatus false 默认不进行音乐处理
if (netName == TbNetName.openMusic && !myApp.musicStatus && !parameter.force) {
resolve(null)
return
}
!hidWaiting && showWaiting();
//网络超时
// let waitObj;
......
import { showToast } from "../module/ctrls";
import { RES } from "../module/RES";
import { GTool } from "../module/tools/GTool";
import { layers } from "../module/views/layers";
import { sendTbNet, TbNetName } from "./TaoBaoNet";
import Tween = FYGE.Tween;
......@@ -26,6 +27,12 @@ export async function sleep(time: number): Promise<void> {
});
}
type AppType = {
musicStatus: boolean
}
export const myApp:AppType = getApp()
/**
* 定制,记录一些全局量和通用方法
*/
......
......@@ -24,10 +24,10 @@ export class PrizeShowPanel extends Panel {
preview.width = 300
preview.height = 300
preview.position.set(150, 236)
preview.mask = panelCtn.addChild(new FYGE.Graphics())
.beginFill()
.drawRoundedRect(150, 236, 300, 300, 20)
.endFill()
// preview.mask = panelCtn.addChild(new FYGE.Graphics())
// .beginFill()
// .drawRoundedRect(150, 236, 300, 300, 20)
// .endFill()
UI.Btn(panelCtn, 'confirm-btn.png', function() {
this.btnDelay(this)
......
export const GameCfg = {
acc: 0.3, // 垂直重力加速度 todo 对不同帧率进行处理
class GameDiff {
data: Array<any>
constructor(data: Array<any>) {
this.data = data
}
get(i: number) {
if (i > this.data.length - 1) {
return this.data[this.data.length - 1]
}
return this.data[i]
}
}
type CfgType = {
acc: number,
ispeed: number,
fpsScale: number,
resisteAcc: number,
rct_l: GameDiff,
balanceValue: number,
rc_l: GameDiff,
iTime_l: GameDiff,
hTime_l: GameDiff,
arc_l: GameDiff
}
class GameConifg {
private opts: CfgType
private level: number = 0
balanceValue: number
acc: number
ispeed: number
fpsScale: number
resisteAcc: number
constructor(data: CfgType) {
this.opts = data
this.balanceValue = data.balanceValue
this.acc = data.acc
this.ispeed = data.ispeed
this.fpsScale = data.fpsScale
this.resisteAcc = data.resisteAcc
this.initLevel()
}
initLevel() {
this.level = 0
}
setLevel(level: number) {
this.level = level
}
nextLevel() {
console.log(this.getRct())
this.level += 1
}
getRc():number {
return this.opts.rc_l.get(this.level)
}
getHTime():number {
return this.opts.hTime_l.get(this.level)
}
getRct() {
return this.opts.rct_l.get(this.level)
}
getInitTime() {
return this.opts.iTime_l.get(this.level)
}
getArc() {
var arc = this.opts.arc_l.get(this.level)
return Math.sin(arc / 180 * Math.PI)
}
}
const cfg = {
acc: 0.5, // 垂直重力加速度 todo 对不同帧率进行处理
ispeed: 0, // 初速度
fpsScale: 1000 / 60, // 帧变数
resisteAcc: 0.04, // 摩擦力反加速度
rc: 400, // 误差值,距离中心点的误差值
duanpingValue: 8 / 180 * Math.PI, // 默认小于 8 度就算端平
iTime: 6000, // 初始化游戏时间
rt: 1000 //每次递减
balanceValue: 8 / 180 * Math.PI, // 默认小于 8 度就算端平
rct_l: new GameDiff([600, 500, 300, 200, 200]), // [300, 250, 200, 150, 100, 50, 30]
rc_l: new GameDiff(Array.from(Array(21), (_, i) => {
var n = ~~(i / 3)
return 300 - n * 270 / 6
})), // 游戏难度处理
iTime_l: new GameDiff([10000]), // 游戏时长,
hTime_l: new GameDiff(Array.from(Array(30), (_, i) => 1500 + Math.floor((i+1) / 2) * 100)), // hold time array
arc_l: new GameDiff(Array.from(Array(30), (_, i) => {
// 30 - 2 / 3 * (i + 1)
return 30 - ~~((i + 1) / 2) * 4 / 3
}))
}
export const GameCfg = new GameConifg(cfg)
\ No newline at end of file
......@@ -83,7 +83,40 @@ function pos2Len(p1: pos, p2:pos):number {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2))
}
class RandomArray {
iarr: Array<any>
arr: Array<any>
get len():number {
return this.arr.length
}
constructor(data: Array<any>) {
if (data.length == 0) {
console.warn('data require a Array which has length')
throw new Error('data require a Array which has length')
return
}
this.iarr = [...data]
this.arr = [...data]
}
getRandomValue() {
if (this.len == 0) {
this.arr = this.iarr
}
var i = Math.floor(Math.random() * this.len)
var value = this.arr[i]
this.arr.splice(i, 1)
return value
}
spliceValue(v:any) {
var i = this.arr.indexOf(v)
if (i == -1) return
this.arr.splice(i, 1)
}
}
export class GameScene extends MotionInitScene {
......@@ -94,6 +127,7 @@ export class GameScene extends MotionInitScene {
gameEle: GameEle
_gIndex: number = 1 // 游戏元素索引
isJordan: boolean
arr_t: RandomArray = new RandomArray(Array.from(Array(20), (_, i) => ++i))
constructor(){
super()
......@@ -128,44 +162,13 @@ export class GameScene extends MotionInitScene {
return this._score
}
musicStatus: boolean
musicBtn: FYGE.Button
get musicBoolean() {
return this.musicStatus
}
set musicBoolean(m: boolean) {
if (m) {
(this.musicBtn || (this.musicBtn = UI.Btn(this, 'music-on.png', this.onMusicClick, this, 650, layers.stageOffsetY + (getApp().isLarge ? 220 : 168 )))).texture = RES.getRes('music-on.png');
this.musicBtn.anchorX = 30
this.musicBtn.anchorY = 30
FYGE.Tween.get(this.musicBtn, {loop: true})
.to({rotation: 360}, 5000)
} else {
(this.musicBtn || (this.musicBtn = UI.Btn(this, 'music-on.png', this.onMusicClick, this, 650, layers.stageOffsetY + (getApp().isLarge ? 220 : 168 )))).texture = RES.getRes('music-off.png');
FYGE.Tween.removeTweens(this.musicBtn)
this.musicBtn.rotation = 0
}
this.musicStatus = m
sendTbNet(TbNetName.openMusic, {
isOn: m,
kurl: TBBgm.gameBgm,
loop: true
}, null, null, true)
}
async initUi() {
super.initUi()
this.score = 0
// 开背景音乐
// this.musicBoolean = true
var cdp = this.cdp = this.addChild(new CountDownComp(GameCfg.iTime))
var cdp = this.cdp = this.addChild(new CountDownComp(GameCfg.getInitTime()))
this.setChildIndex(this.cdp, 2)
this.cdp.addTimeoutFunc(() => {
this.cdp.destory()
......@@ -175,7 +178,7 @@ export class GameScene extends MotionInitScene {
FYGE.Tween.removeAllTweens()
var fail = UI.Lottie(this, yoga_fail,180, 290)
fail.play(1, () => {
// 关闭背景
// close bgm
this.musicBoolean = false
//@ts-ignore
......@@ -190,20 +193,17 @@ export class GameScene extends MotionInitScene {
}
onMusicClick() {
this.musicBoolean = !this.musicBoolean
}
async initGame() {
this.musicBoolean = true
this.cdp.start()
this.gameEle = this.addChild(new GameEle('p1.png', this.centerp, () => {
GameCfg.initLevel()
this.cdp.start()
this.arr_t.spliceValue(1)
this.gameEle = this.addChild(new GameEle(`p1.png`, this.centerp, () => {
GameCfg.nextLevel()
this.score += 1
this.gIndex += 1
this.cdp.initTime = GameCfg.iTime
this.gIndex = this.arr_t.getRandomValue()
this.cdp.initTime = GameCfg.getInitTime()
this.cdp.visible = true
this.cdp.start()
// 直接出来一个
......@@ -426,15 +426,16 @@ export class GameEle extends Container {
var v2 = new Vector2(this.vx, this.vy)
var a2 = new Vector2(this.accx, this.accy)
if (this.isIn && a2.length() < GameCfg.acc * 0.5) return
// 数量积运算 lenA*lanB*cos = A * B = A.x*B.x + A.
if (len <= GameCfg.rc) {
// 吸附后 小于一定角度 就直接return
if (this.isIn && a2.length() < GameCfg.acc * GameCfg.getArc()) return
if (a2.length() < GameCfg.acc * 0.5) {
// 数量积运算 lenA*lanB*cos = A * B = A.x*B.x + A.
// 在范围内
if (len <= GameCfg.getRc()) {
// 30度 倾斜度 acc / x = sina
if (a2.length() < GameCfg.acc * GameCfg.getArc()) {
if (v2.length() < 3 && !this.isIn) {
console.log('吸附')
this.isIn = true
this.vx = 0
this.vy = 0
......@@ -442,7 +443,7 @@ export class GameEle extends Container {
.to({
x: this.fixedCenter.x,
y: this.fixedCenter.y
}, GameCfg.rc)
}, GameCfg.getRct())
.call(() => {
GDispatcher.dispatchEvent('focus-in', () => {
this.finishFunc()
......@@ -451,7 +452,6 @@ export class GameEle extends Container {
}
} else {
if (this.isIn) {
console.log('取消吸附')
this.isIn = false
FYGE.Tween.removeTweens(this)
GDispatcher.dispatchEvent('focus-out')
......
......@@ -8,12 +8,13 @@ import { balance_guidance } from "../../lotties/balance_guidance"
import { excellent_icon } from "../../lotties/excellent_icon"
import { GDispatcher } from "../../Main"
import { sendTbNet, TbNetName } from "../../TaoBaoNet"
import { Tools } from "../../Tools"
import { myApp, Tools } from "../../Tools"
import UI from "../../UI"
import { onceFnc, setCenterPos } from "../../utils/utils"
import DeviceMotion from "./DeviceMotion"
import { GameCfg } from "./GameConfig"
import { GameEle } from './GameScene';
import { GTool } from '../../../module/tools/GTool';
const Container = FYGE.Container
const TEXT_ALIGN = FYGE.TEXT_ALIGN
......@@ -250,7 +251,7 @@ export class MotionInitFunc extends Container {
timer
deviceOritationChange(e) {
if (abs(e.beta) < GameCfg.duanpingValue && abs(e.gamma) < GameCfg.duanpingValue) {
if (abs(e.beta) < GameCfg.balanceValue && abs(e.gamma) < GameCfg.balanceValue) {
if (this.timer == null) {
this.timer = FYGE.Tween.get(this.progress, {
onChange: () => {
......@@ -297,6 +298,44 @@ export class MotionInitScene extends Scene {
centerp: FYGE.Sprite // 中心校准点
excellentIcon: FYGE.Lottie
musicStatus: boolean
musicBtn: FYGE.Button
get musicBoolean() {
return this.musicStatus
}
set musicBoolean(m: boolean) {
if (m) {
(this.musicBtn || (this.musicBtn = UI.Btn(this, 'music-on.png', this.onMusicClick, this, 650, layers.stageOffsetY + (getApp().isLarge ? 220 : 168 )))).texture = RES.getRes('music-on.png');
this.musicBtn.anchorX = 30
this.musicBtn.anchorY = 30
FYGE.Tween.get(this.musicBtn, {loop: true})
.to({rotation: 360}, 5000)
} else {
(this.musicBtn || (this.musicBtn = UI.Btn(this, 'music-on.png', this.onMusicClick, this, 650, layers.stageOffsetY + (getApp().isLarge ? 220 : 168 )))).texture = RES.getRes('music-off.png');
FYGE.Tween.removeTweens(this.musicBtn)
this.musicBtn.rotation = 0
}
this.musicStatus = m
sendTbNet(TbNetName.openMusic, {
isOn: m,
kurl: TBBgm.gameBgm,
loop: true,
force: true
}, null, null, true)
}
onMusicClick() {
var v = !this.musicBoolean
this.musicBoolean = v
myApp.musicStatus = v
GTool.writeCache('yoga_music', v)
}
initUi() {
UI.Rect(this, 750, 1624, 0xf1ebdd, 0, 0, 0)
var app = getApp()
......@@ -333,7 +372,11 @@ export class MotionInitScene extends Scene {
this.holdOnTxt.anchorX = layers.stageWidth / 2
this.holdOnTxt.anchorY = 30
var cb = this.initGame.bind(this)
var cb = () => {
this.initGame.call(this)
// 默认开启音乐, 依赖于 storage
this.musicBoolean = myApp.musicStatus
}
this.motionInitFunc = this.addChild(new MotionInitFunc(this.data?.type, cb))
this.setChildIndex(this.motionInitFunc, 1000)
......@@ -405,7 +448,7 @@ export class MotionInitScene extends Scene {
})
.set({value: 0, visible: true, radius: 240, alpha: 1})
.to({radius: 285}, 300)
.to({value: 1.001}, 3000, FYGE.Ease.quartOut)
.to({value: 1.001}, GameCfg.getHTime(), FYGE.Ease.quartOut)
.call(() => {
console.log('%c 成功套种', 'color: green');
//@ts-ignore
......
......@@ -51,6 +51,7 @@ export class NewGuyScene extends MotionInitScene {
this.desc.visible = false
this.gameEle = this.addChild(new GameEle('p1.png', this.centerp, async () => {
this.musicBoolean = false
const {success} = await sendTbNet(TbNetName.complteGuidance)
success && showPanel(NewCompletePanel)
}))
......
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