Commit 7a1e1360 authored by wjf's avatar wjf

l

parent 6f11ebc2
...@@ -38,6 +38,9 @@ class Layers extends Container { ...@@ -38,6 +38,9 @@ class Layers extends Container {
//初始化弹框层级 //初始化弹框层级
PanelCtrl.instance.init(this.popupLayer) PanelCtrl.instance.init(this.popupLayer)
//弹框要居中适配,加个
this.popupLayer.y = 0;
} }
/** /**
......
resource/common/comCloseBtn.png

4.87 KB | W: | H:

resource/common/comCloseBtn.png

1.72 KB | W: | H:

resource/common/comCloseBtn.png
resource/common/comCloseBtn.png
resource/common/comCloseBtn.png
resource/common/comCloseBtn.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -8,7 +8,7 @@ import { layers } from "../module/views/layers"; ...@@ -8,7 +8,7 @@ import { layers } from "../module/views/layers";
import { RES } from "../module/RES"; import { RES } from "../module/RES";
import { changeScene, showWaiting, hideWaiting, showToast } from "../module/ctrls"; import { changeScene, showWaiting, hideWaiting, showToast } from "../module/ctrls";
import { StartScene } from "./scenes/StartScene"; import { StartScene } from "./scenes/StartScene";
import { PlayScene, PlayStatus } from "./scenes/PlayScene"; import { PlayScene } from "./scenes/PlayScene";
import { sendTbNet, TbNetName, getTbData } from "./TaoBaoNet"; import { sendTbNet, TbNetName, getTbData } from "./TaoBaoNet";
...@@ -42,7 +42,8 @@ window.addEventListener("load", function () { ...@@ -42,7 +42,8 @@ window.addEventListener("load", function () {
export class Main { export class Main {
stage: Stage stage: Stage
constructor() { constructor() {
this.stage = new Stage("cusEngine", 750, 1206, 60, StageScaleMode.FIXED_WIDTH, RENDERER_TYPE.WEBGL); //设计尺寸按750*1624来
this.stage = new Stage("cusEngine", 750, 1624, 60, StageScaleMode.FIXED_WIDTH, RENDERER_TYPE.WEBGL);
//启动循环 //启动循环
Stage.flushAll(); Stage.flushAll();
//加入两个Tween //加入两个Tween
...@@ -61,7 +62,7 @@ export class Main { ...@@ -61,7 +62,7 @@ export class Main {
//隐藏加载中 //隐藏加载中
if (document.getElementById("__loading__")) document.getElementById("__loading__").style.display = "none"; if (document.getElementById("__loading__")) document.getElementById("__loading__").style.display = "none";
//打开开始场景 //打开开始场景
// changeScene(StartScene);return; changeScene(StartScene);return;
//获取数据,,必成功 //获取数据,,必成功
showWaiting(); showWaiting();
sendTbNet(TbNetName.getAppData, {}, (s, res) => { sendTbNet(TbNetName.getAppData, {}, (s, res) => {
......
import { Sprite } from "../../engine/2d/display";
import { Event } from "../../engine/2d/events/Event";
import Tween from "../../engine/tween/Tween";
import { MouseEvent } from "../../engine/2d/events/MouseEvent";
import { Scene } from "../../module/views/Scene"; import { Scene } from "../../module/views/Scene";
import { RES } from "../../module/RES";
import { layers } from "../../module/views/layers";
import { Person } from "../parts/Person";
import { TextField } from "../../engine/2d/text";
import { showToast, showPanel, showWaiting, hideWaiting } from "../../module/ctrls";
import { VERTICAL_ALIGN, TEXT_ALIGN } from "../../engine/2d/const";
import { Graphics, Shape } from "../../engine/2d/graphics";
import { countDown } from "../parts/countDown";
import { MovieClip } from "../../engine/2d/svga";
import { ScrollBg } from "../parts/ScrollBg";
import { Button } from "../../engine/2d/ui";
import { Ease } from "../../engine/tween/Ease";
import { Title } from "../parts/Title";
import { TimeCount } from "../parts/TimeCount";
import { ScoreBar } from "../parts/ScoreBar";
import { FriScoreBar, RelayInfo } from "../parts/FriScoreBar";
import { RulePanel } from "../panels/RulePanel";
import { ChoosePrizePanel } from "../panels/ChoosePrizePanel";
import { Tool } from "../Tools";
import { TimeoutPanel } from "../panels/TimeoutPanel";
import { GTool } from "../../module/tools/GTool";
import { sendTbNet, TbNetName } from "../TaoBaoNet";
import { showSharePanel } from "../Main";
import { PrizeCheckPanel } from "../panels/PrizeCheckPanel";
import { Texture } from "../../engine/2d/texture";
import { WinPanel } from "../panels/WinPanel";
import { FriendsWinPanel } from "../panels/FriendsWinPanel";
import { soundOn, MusicBtn } from "../parts/MusicBtn";
import { playSound, SoundType } from "../../module/ctrls/soundCtrl";
export enum StartStatus {
go = "goBtn",//
speedUp = "speedUpBtn",
choosePrize = "choosePrizeBtnR",
invite = "inviteFriendBtn",
continueInvite = "conInviteBtn",
actOver = "actOverBtn",
getPrize = "getPrizeBtnR",
hasntStarted = "notStarted"
}
/**
* 游戏状态
*/
export enum PlayStatus {
selfPlayNew = 0, //自己开玩,显示GO,有手势引导
selfPlayAlready,//自己已玩,按钮显示邀请好友,查询领奖信息和助力信息,显示进度条
needHelp, //好友助力,显示分享者接力信息,和自己需要助力
couldntHelp, //不能助力,显示自己的活动进度,走selfPlay
actOver, //活动已结束,显示自己的场景,按钮显示活动结束,查询领奖信息和助力信息,显示进度条,
hasntStarted, //活动未开始
}
//奖品类型
export enum PrizeType {
//权益
EQUITY = 2,
//积分
CREDITS = 3,
//实物
OBJECT = 4,
//谢谢参与
THANKS = 5,
}
export class PlayScene extends Scene { export class PlayScene extends Scene {
get groupNames() { return ["playScene"] } get groupNames() { return ["playScene"] }
data: {
playStatus: PlayStatus,
relayInfo?: {
image: string,
list: RelayInfo[],//接力信息
},
prizeInfo?: {//查询的当前奖品信息,
"image": string;
"type": PrizeType,
"ename": string,
"isComplete": false,
"_id": string,
}
}
score: number = 0;
scoreBar: ScoreBar;
friScoreBar: FriScoreBar;
/**
* 是否暂停
*/
paused: boolean;
speedUpTimeId;
//风的动画
wind: MovieClip
bg: ScrollBg;
person: Person;
title: Title;
//游戏倒计时
timeCount: TimeCount;
//跑步按钮
startBtn: StartBtn;
//规则按钮
ruleBtn: Button;
recordBtn: Button;
//点击加速的声音
// speedUpSound = new window["Howl"]({ src: ["//yun.duiba.com.cn/db_games/activity/antaParkour/sounds/speedUp.mp3"] });
musicBtn: MusicBtn
//排下所有ui先
initUi() {
playSound(SoundType.countDown)
//先适配
this.y = -(1624 - layers.stageHeight) / 2;
//背景移动
var bgUrl = Tool.globalData.theme == "kid" ? "bgKid.jpg" : "bg.jpg";
this.bg = new ScrollBg(bgUrl);
this.addChild(this.bg);
//人物
this.person = new Person();
this.addChild(this.person);
//开始按钮
this.startBtn = new StartBtn(RES.getRes("goBtn.png"))
this.startBtn.x = (750 - 238) / 2;
this.startBtn.y = 1097;
// this.startBtn.visible = false;
this.addChild(this.startBtn);
//标题
this.title = new Title();
this.addChild(this.title);
//游戏倒计时
this.timeCount = new TimeCount();
this.timeCount.visible = false;
this.addChild(this.timeCount);
//风的动画
this.wind = new MovieClip(RES.getRes("wind.svga"));
this.wind.mouseChildren = false;
this.wind.mouseEnable = false;
this.wind.visible = false;
this.addChild(this.wind)
//规则按钮
this.ruleBtn = new Button(RES.getRes("ruleBtn.png"));
this.ruleBtn.position.set(0, 240);
this.addChild(this.ruleBtn);
//我的奖品按钮
this.recordBtn = new Button(RES.getRes("recordBtn.png"));
this.recordBtn.position.set(703, 240);
this.addChild(this.recordBtn);
//声音按钮
var musicBtn = new MusicBtn();
musicBtn.position.set(650, 400)
this.addChild(musicBtn);
this.musicBtn = musicBtn;
this.musicBtn.visible = false;
// console.log(musicBtn)
}
start() {
super.start();
this.paused = true;
if (this.data.playStatus == PlayStatus.selfPlayNew) {
//新人时,
this.startBtn.startStatus = StartStatus.go;
this.title.showShareTitle();
//分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
// 弹出选择奖励
showPanel(ChoosePrizePanel);
}
else if (this.data.playStatus == PlayStatus.needHelp) {
//新人助力时
this.startBtn.startStatus = StartStatus.go;
this.title.showHelpTitle();
this.friScoreBar = new FriScoreBar(this.data.relayInfo.list);
this.addChild(this.friScoreBar)
this.friScoreBar.addTime(Tool.endTime);
this.friScoreBar.addCurHelp();
this.friScoreBar.addFriBigHead();
this.friScoreBar.changePrize(Tool.curPrizeIcon);
this.personShowUp();
}
else if (this.data.playStatus == PlayStatus.actOver) {
//活动结束
this.startBtn.startStatus = StartStatus.actOver;
this.title.showShareTitle();
//分数条怎么处理
if (this.data.relayInfo && this.data.relayInfo.list && this.data.relayInfo.list.length) {
this.friScoreBar = new FriScoreBar(this.data.relayInfo.list);
this.addChild(this.friScoreBar)
this.friScoreBar.addTime(Tool.endTime);
this.friScoreBar.changePrize();
}
//显示空的自己
else {
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
this.scoreBar.addTime(Tool.endTime);
}
//领奖
if (this.data.prizeInfo &&
this.data.prizeInfo.isComplete) {
if (Tool.hasExpired) {//过期判断
showToast("奖品已过期")
} else {
showPanel(PrizeCheckPanel, { prizeInfo: this.data.prizeInfo });
}
}
//判断奖品,弹出遗憾,或者出奖
else if (!GTool.readCache(Tool.cacheKeyNoPrize) &&
this.data.prizeInfo &&
!this.data.prizeInfo.isComplete
) {
showPanel(TimeoutPanel, { image: this.data.prizeInfo.image })
}
}
else if (this.data.playStatus == PlayStatus.selfPlayAlready) {
//标题显示自己的
this.title.showShareTitle();
//没有奖品,弹选择奖品,和selfPlayNew一致
if (!this.data.prizeInfo) {
this.startBtn.startStatus = StartStatus.go;
//分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
// 弹出选择奖励
showPanel(ChoosePrizePanel);
}
//有奖品,且已完成,弹领取奖励弹框,要清空
else if (this.data.prizeInfo.isComplete) {
this.startBtn.startStatus = StartStatus.getPrize;
//分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
//分数条清掉奖品显示
this.scoreBar.changePrize(null);
// 领取奖励
showPanel(PrizeCheckPanel, { prizeInfo: this.data.prizeInfo });
}
//有奖品,没完成,但是无助力信息,需要跑
else if (
!this.data.relayInfo ||
!this.data.relayInfo.list ||
!this.data.relayInfo.list.length
) {
this.startBtn.startStatus = StartStatus.go;
//分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
this.scoreBar.addTime(Tool.endTime);
}
//有助力信息,未完成,显示分数进度条,按钮区分邀请好友
else {
//分数条
this.friScoreBar = new FriScoreBar(this.data.relayInfo.list.slice());
this.addChild(this.friScoreBar);
this.friScoreBar.addTime(Tool.endTime);
//按钮i区分
if (this.data.relayInfo.list.length > 1) {
this.startBtn.startStatus = StartStatus.continueInvite;
} else {
this.startBtn.startStatus = StartStatus.invite;
}
}
}
else if (this.data.playStatus == PlayStatus.hasntStarted) {
this.startBtn.startStatus = StartStatus.hasntStarted;
this.title.showShareTitle();
//分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
}
}
//重置为自己的游戏,只用于给好友助力完之后,自己开跑
resetToMyGame() {
//分数空
this.score = 0;
//状态变为自己玩
this.data.playStatus = PlayStatus.selfPlayNew;
this.data.relayInfo = null;
//去掉原先的分数进度条
this.removeChild(this.friScoreBar);
//增加自己的分数条
this.scoreBar = new ScoreBar();
this.addChild(this.scoreBar);
//标题变成自己的
this.title.showShareTitle();
this.title.visible = true;
//倒计时消失
this.timeCount.visible = false;
//开始按钮
this.startBtn.startStatus = StartStatus.choosePrize;
}
/**
* 人物出现动效
*/
personShowUp() {
this.enableMouseEvt(false);
this.startBtn.visible = false;
this.startBtn.startStatus = StartStatus.go;
//人物出现,动画需要在选择奖励后出现,
this.person.showUp(() => {
this.startBtn.visible = true;
this.startBtn.scale.set(1.5, 1.5)
Tween.get(this.startBtn)
.to({ scaleX: 1, scaleY: 1 }, 300, Ease.backOut)
.call(() => {
this.enableMouseEvt(true);
this.startBtn.showGuide();
})
})
}
/**
* 首次的奖品
* @param src
*/
prizeShowUp(src: string) {
let image = Sprite.from(src);
image.anchorTexture.set(0.5, 0.5);
image.width = image.height = 92;
image.position.set(375, 1624 / 2);
this.addChild(image);
this.enableMouseEvt(false);
Tween.get(image)
.to({ x: 100, y: 550 }, 500)
.call(() => {
Tween.removeTweens(image);
image.destroy();
this.scoreBar.addTime(Tool.endTime);
this.scoreBar.changePrize(src)
})
}
initEvents() {
super.initEvents();
this.addEventListener(Event.ENTER_FRAME, this.enterFrame, this)
this.startBtn.addEventListener(MouseEvent.CLICK, this.onClick_startBtn, this)
this.ruleBtn.addEventListener(MouseEvent.CLICK, this.onClick_ruleBtn, this)
this.recordBtn.addEventListener(MouseEvent.CLICK, this.onClick_recordBtn, this)
}
//开始的按钮事件
onClick_startBtn() {
//go按钮开始
if (this.startBtn.startStatus == StartStatus.go) {
//发个开始接口,
sendTbNet(TbNetName.startGame, { activityId: Tool.globalData.activityId, nickName: Tool.globalData.nickName }, () => { }, true)
//按钮消失动效
Tween.get(this.startBtn)
.to({ alpha: 0 }, 100);
this.startBtn.mouseEnable = false;
//标题消失动效
Tween.get(this.title)
.to({ alpha: 0 }, 300)
.call(() => {
//标题隐藏
this.title.alpha = 1;
this.title.visible = false;
//显示倒计时
this.timeCount.visible = true;
this.timeCount.reset();
})
countDown(() => {
//人物开跑
this.person.run();
//循环开启
this.paused = false;
//倒计时开始
this.timeCount.startCount(() => { this.gameOver() })
//按钮变成加速
this.startBtn.startStatus = StartStatus.speedUp;
Tween.get(this.startBtn)
.to({ alpha: 1 }, 300)
.call(() => {
this.startBtn.mouseEnable = true;
})
}, this)
//声音按钮置顶
this.addChild(this.musicBtn);
}
//加速
else if (this.startBtn.startStatus == StartStatus.speedUp) {
if (soundOn) playSound(SoundType.speedUp)//播放声音
this.bgSpeed = Math.min(this.bgSpeed + this.addSpeed, this.maxSpeed);
this.person.speedUp(this.bgSpeed);
if (!this.wind.visible) this.wind.gotoAndPlay(1);
this.wind.visible = true;
clearTimeout(this.speedUpTimeId);
Tween.removeTweens(this);
//设置定时器
this.speedUpTimeId = setTimeout(() => {
this.person.slowDown();
this.wind.once(Event.END_FRAME, () => {
this.wind.visible = false;
}, this);
Tween.get(this)
.to({ bgSpeed: this.initSpeed }, 300)
}, 300)
}
//选择奖励
else if (this.startBtn.startStatus == StartStatus.choosePrize) {
showPanel(ChoosePrizePanel)
}
//已经结束
else if (this.startBtn.startStatus == StartStatus.actOver) {
showToast("活动已结束")
}
//邀请
else if (this.startBtn.startStatus == StartStatus.invite || this.startBtn.startStatus == StartStatus.continueInvite) {
showSharePanel();
}
//领奖
else if (this.startBtn.startStatus == StartStatus.getPrize) {
showPanel(PrizeCheckPanel, { prizeInfo: this.data.prizeInfo });
}
//未开始
else if (this.startBtn.startStatus == StartStatus.hasntStarted) {
showToast("活动暂未开始,敬请期待");
}
}
onClick_ruleBtn() {
showPanel(RulePanel)
}
onClick_recordBtn() {
// this.recordBtn.mouseEnable = false;
// setTimeout(() => {
// this.recordBtn.mouseEnable = true;
// //链接待写
// sendTbNet(TbNetName.navigateTo, { url: "../kupaoPrize/kupaoPrize" }, () => { })
// }, 2000);
// console.log("跳转我的奖品页面")
sendTbNet(TbNetName.navigateTo, { url: "../kupaoPrize/kupaoPrize" }, () => { })
}
/**
* 有些地方要置null
*/
lastTime;
commonDeltaTime = 1000 / 60
initSpeed = window["initSpeed"] || 10;
addSpeed = window["addSpeed"] || 3;
maxSpeed = window["maxSpeed"] || 40;
delay = 0;
bgSpeed = 10;
private enterFrame(e: Event): void {
if (this.paused) return;
//矫正帧率比例
var deltaTime = this.countDeltaTime();
var scale = deltaTime / this.commonDeltaTime;//获取比例系数
//真实速度
var v = this.bgSpeed * scale;
// console.log(this.score)
//分数计算根据prd公式来
var addScore = v / 60;
this.score += addScore;
if (this.data.playStatus == PlayStatus.needHelp) {
this.friScoreBar.distance = (this.score + 0.5) >> 0;
} else {
this.scoreBar.distance = (this.score + 0.5) >> 0;
}
//背景的移动
this.bg.move(v)
}
gameOver() {
this.startBtn.mouseEnable = false
this.person.slowDown()
setTimeout(() => {
this.person.stand();
this.paused = true;
this.startBtn.mouseEnable = true;
//分数固定取整
this.score = (this.score + 0.5) >> 0
//提交分数
if (this.data.playStatus == PlayStatus.needHelp) {
this.doShareComplete();
} else {
this.submit();
}
}, 1000)
}
submit() {
showWaiting();
console.log(this.score)
sendTbNet(
TbNetName.submitDistance,
{ activityId: Tool.globalData.activityId, distance: this.score },
(s, res) => {
if (s) {
showPanel(WinPanel, { distance: this.score })
}
//没有返回信息,可重来
else if (!res) {
this.submit();
} else {
//提交失败怎么办
}
}
)
}
//好友助力时的提交
doShareComplete() {
showWaiting();
console.log(this.score)
sendTbNet(
TbNetName.doShareComplete,
{
activityId: Tool.globalData.activityId,
shareId: Tool.globalData.shareId,
nickName: Tool.globalData.nickName,
avatar: Tool.globalData.avatar,
distance: this.score,
},
(s, res) => {
if (s) {
showPanel(FriendsWinPanel, { distance: this.score })
}
//没有返回信息,可重来
else if (!res) {
this.doShareComplete();
} else {
//提交失败怎么办
}
}
)
}
removeEvents() {
super.removeEvents();
this.removeEventListener(Event.ENTER_FRAME, this.enterFrame, this)
this.startBtn.removeEventListener(MouseEvent.CLICK, this.onClick_startBtn, this)
this.ruleBtn.removeEventListener(MouseEvent.CLICK, this.onClick_ruleBtn, this)
this.recordBtn.removeEventListener(MouseEvent.CLICK, this.onClick_recordBtn, this)
}
//计算间隔时间
countDeltaTime(): number {
var nowTime = Date.now();
var deltaTime = this.lastTime ? nowTime - this.lastTime : this.commonDeltaTime;
//如果超过1秒。视为后台了,
if (deltaTime > 1000) deltaTime = this.commonDeltaTime;
//重新赋值lastTime
this.lastTime = nowTime;
return deltaTime;
}
destroy() { destroy() {
...@@ -567,43 +23,4 @@ export class PlayScene extends Scene { ...@@ -567,43 +23,4 @@ export class PlayScene extends Scene {
} }
/**
* 继承下,加个属性
*/
class StartBtn extends Button {
private hand: Sprite;
private _startStatus: StartStatus;
get startStatus() {
return this._startStatus
}
set startStatus(value: StartStatus) {
this._startStatus = value;
this.changeTexture(RES.getRes(value + ".png"))
}
constructor(tUp: Texture, tDown?: Texture, tDisable?: Texture) {
super(tUp, tDown, tDisable)
//手势
var hand = new Sprite(RES.getRes("hand.png"))
hand.anchorTexture.set(1, 1);
hand.position.set(240, 220)
this.hand = hand;
this.addChild(hand)
this.hand.visible = false;
}
//显示手势
showGuide() {
this.once(MouseEvent.MOUSE_DOWN, () => {
this.hand.visible = false;
Tween.removeTweens(this.hand);
}, this)
this.hand.visible = true;
Tween.removeTweens(this.hand);
this.hand.rotation = 0;
Tween.get(this.hand, { loop: true })
.to({ rotation: 30 }, 300)
.to({ rotation: 0 }, 500)
.wait(500)
}
}
...@@ -35,6 +35,7 @@ export class StartScene extends Scene { ...@@ -35,6 +35,7 @@ export class StartScene extends Scene {
get groupNames(): string[] { return ["startScene"] } get groupNames(): string[] { return ["startScene"] }
start() { start() {
super.start(); super.start();
// this.scaleX=0.5 // this.scaleX=0.5
// showPanel(PrizePanel) // showPanel(PrizePanel)
...@@ -62,7 +63,7 @@ export class StartScene extends Scene { ...@@ -62,7 +63,7 @@ export class StartScene extends Scene {
} }
//初始化ui //初始化ui
initUi() { initUi() {
var bg = new Sprite(RES.getRes("startBg.jpg")) var bg = new Sprite(RES.getRes("startBtn.png"))
// Tween.get(bg, { loop: true }) // Tween.get(bg, { loop: true })
// .to({ tint: 0 }, 5000) // .to({ tint: 0 }, 5000)
// bg.tint=0xff0000 // bg.tint=0xff0000
......
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