Commit 82fce8f0 authored by 邱旭's avatar 邱旭

1

parent 67a0af56
......@@ -41,7 +41,7 @@
<body>
<div style="margin: auto;width: 100%;height: 100%;" class="egret-player" data-entry-class="Main"
data-orientation="auto" data-scale-mode="showAll" data-frame-rate="60" data-content-width="750"
data-content-height="1624" data-multi-fingered="2" data-show-fps="false" data-show-log="true"
data-content-height="1624" data-multi-fingered="2" data-show-fps="true" data-show-log="true"
data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
</div>
......
{"file":"hbGameNumFont.png","frames":{
{"file":"hbGameScoreFont.png","frames":{
"0":{"x":0,"y":0,"w":35,"h":45,"offX":0,"offY":0,"sourceW":35,"sourceH":45},
"1":{"x":70,"y":138,"w":23,"h":43,"offX":0,"offY":0,"sourceW":23,"sourceH":43},
"2 ":{"x":0,"y":93,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"3":{"x":35,"y":93,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"2":{"x":35,"y":93,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"3":{"x":0,"y":47,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"4":{"x":37,"y":0,"w":35,"h":44,"offX":0,"offY":0,"sourceW":35,"sourceH":44},
"5":{"x":0,"y":47,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"6":{"x":72,"y":47,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"5":{"x":72,"y":47,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"6":{"x":0,"y":93,"w":33,"h":44,"offX":0,"offY":0,"sourceW":33,"sourceH":44},
"7":{"x":70,"y":93,"w":33,"h":43,"offX":0,"offY":0,"sourceW":33,"sourceH":43},
"8":{"x":74,"y":0,"w":33,"h":45,"offX":0,"offY":0,"sourceW":33,"sourceH":45},
"9":{"x":37,"y":46,"w":33,"h":45,"offX":0,"offY":0,"sourceW":33,"sourceH":45}}}
\ No newline at end of file
......@@ -189,7 +189,7 @@
"name": "hbnoprize"
},
{
"keys": "hbGameCutTimeFont_fnt,hbGameCutTimeFont_png,hbGameNumFont_fnt,hbGameNumFont_png,hbGame_CutTime_bg_png,hbGame_CutTime_progress_png,hbGame_num_bg_png,hbGame_tips_png,hbGame_1_png,hbGame_2_png,hbGame_3_png,hbGame_+1_png,hbGame_bird_touch_png,hbGame_bird_png,hbGame_cattle_png,hbGame_cattle_touch_png,hbGame_hongbao_touch_png,hbGame_+2_png,hbGame_hongbao_png,hbGame_lion_png,hbGame_lion_touch_png,hbGame_pig_touch_png,hbGame_pig_png,hbGame_rabbit_touch_png,hbGame_rabbit_png",
"keys": "hbGameCutTimeFont_fnt,hbGameCutTimeFont_png,hbGame_CutTime_bg_png,hbGame_CutTime_progress_png,hbGame_num_bg_png,hbGame_tips_png,hbGame_1_png,hbGame_2_png,hbGame_3_png,hbGame_+1_png,hbGame_bird_touch_png,hbGame_bird_png,hbGame_cattle_png,hbGame_cattle_touch_png,hbGame_hongbao_touch_png,hbGame_+2_png,hbGame_hongbao_png,hbGame_lion_png,hbGame_lion_touch_png,hbGame_pig_touch_png,hbGame_pig_png,hbGame_rabbit_touch_png,hbGame_rabbit_png,hbGameScoreFont_fnt,hbGameScoreFont_png",
"name": "hbgame"
},
{
......@@ -3008,16 +3008,6 @@
"type": "image",
"name": "hbGameCutTimeFont_png"
},
{
"url": "assets/hbGame/hbGameNumFont.fnt",
"type": "font",
"name": "hbGameNumFont_fnt"
},
{
"url": "assets/hbGame/hbGameNumFont.png",
"type": "image",
"name": "hbGameNumFont_png"
},
{
"url": "assets/hbGame/hbGame_CutTime_bg.png",
"type": "image",
......@@ -3242,6 +3232,16 @@
"url": "assets/map/icongray.png",
"type": "image",
"name": "icongray_png"
},
{
"url": "assets/hbGame/hbGameScoreFont.fnt",
"type": "font",
"name": "hbGameScoreFont_fnt"
},
{
"url": "assets/hbGame/hbGameScoreFont.png",
"type": "image",
"name": "hbGameScoreFont_png"
}
]
}
\ No newline at end of file
......@@ -2,9 +2,9 @@
<e:Skin class="HbGame" width="750" height="1206" xmlns:e="http://ns.egret.com/eui"
xmlns:w="http://ns.egret.com/wing">
<e:Group id="rainGroup" left="0" right="0" top="0" height="1206"/>
<e:Group right="40" top="45">
<e:Group id="scoreGroup" top="45" horizontalCenter="283.5">
<e:Image y="0" source="hbGame_num_bg_png" horizontalCenter="0"/>
<e:BitmapLabel id="numLabel" y="33" font="hbGameNumFont_fnt" text="0" horizontalCenter="0"/>
<e:BitmapLabel id="scoreLabel" y="33" text="0" horizontalCenter="0" font="hbGameScoreFont_fnt"/>
</e:Group>
<e:Group y="45" horizontalCenter="0">
<e:Image y="0" horizontalCenter="0" source="hbGame_CutTime_bg_png"/>
......
......@@ -91,7 +91,7 @@ export default class MapScene extends Scene {
this.sendInvite();
// PanelCtrl.instance.show("HbGame");
PanelCtrl.instance.show("HbGame");
this.updateMyInfo();
this.updateAdData();
......
import Panel from "../../../libs/new_wx/components/Panel";
import RainMgr from "./RainMgr";
import CutTimer from "../../CutTimer";
import { GDispatcher } from "../../../libs/tc/util/GDispatcher";
/**
* 红包雨主游戏
*/
export default class HbGame extends Panel {
public numLabel: eui.BitmapLabel;
public rainGroup: eui.Group;
public scoreGroup: eui.Group;
public scoreLabel: eui.BitmapLabel;
public cutTimeLabel: eui.BitmapLabel;
public readyGroup: eui.Group;
public readyTips: eui.Image;
public readyCutTime: eui.Image;
public rainGroup: eui.Group;
private rainMgr: RainMgr = null;
private cutTime: CutTimer = null;
private cutTime: egret.Timer = null;
private time: number = 0;
private score = 0;
constructor(data) {
super();
......@@ -22,11 +27,48 @@ export default class HbGame extends Panel {
}
onLoad() {
this.readyGroup.visible = false;
setTimeout(() => this.readyTipsEffect(), 500);
this.initUI();
}
initUI() {
this.rainGroup.height = this.width / window.innerWidth * window.innerHeight;
this.time = 60;
this.cutTimeLabel.text =`${this.time}`
}
// 加分
private addScore(score: number) {
egret.Tween.get(this.scoreGroup).to({scaleX: 1.3, scaleY: 1.3}, 100).call(() => {
this.score += score;
this.scoreLabel.text = `${this.score}`;
egret.Tween.get(this.scoreGroup).to({scaleX: 1, scaleY: 1}, 100);
});
}
private gameOver() {
this.cutTime.stop();
this.cutTime.removeEventListener(egret.TimerEvent.TIMER,this.timeCallFun, this);
GDispatcher.dispatchEvent('hbRainGameOver');
}
private startGame() {
this.rainMgr = new RainMgr({
parent: this,
rainGroup: this.rainGroup,
});
this.cutTime = new egret.Timer(1000, 0);
this.cutTime.addEventListener(egret.TimerEvent.TIMER, this.timeCallFun, this);
this.cutTime.start();
}
private timeCallFun(){
this.cutTimeLabel.text = `${--this.time}`;
if(this.time <= 0){
this.gameOver();
}
}
private readyTimeEffect() {
......@@ -57,36 +99,23 @@ export default class HbGame extends Panel {
});
}
private startGame() {
this.rainMgr = new RainMgr({
parent: this,
rainGroup: this.rainGroup,
});
this.cutTime = new CutTimer(this.cutTimeLabel, 'ss', () => this.gameOver());
this.cutTime.start(59 * 1000);
}
private gameOver() {
}
private readyTipsEffect() {
this.readyTips.alpha = 0;
egret.Tween.get(this.readyTips).to({alpha: 1}, 300).call(() => this.readyTimeEffect());
}
protected onSkinComplete() {
this.readyGroup.visible = false;
setTimeout(() => this.readyTipsEffect(), 1000);
this.onLoad();
}
initEvents() {
super.initEvents();
GDispatcher.addEvent('hbGameAddScore', this.addScore, this);
}
removeEvents() {
super.removeEvents();
GDispatcher.removeEvent('hbGameAddScore', this.addScore, this);
}
protected get closeBtns(): eui.Button[] {
......
/**
* 简单对象池
*/
export default class Polling {
private pool: any[] = [];
constructor() {
}
/**
* 存入对象
* @param obj - 要存入的对象
*/
public push(obj: any) {
this.pool.push(obj);
}
/**
* 返回对象池中的随机对象
* @returns 返回获得的对象 null 对象用完了
*/
public get() {
if (this.pool.length <= 0) { // 如果对象池用完了就返回 null
return null;
}
// 返回随机对象
let index = ~~(Math.random() * this.pool.length);
let obj = this.pool[index];
this.pool.splice(index, 1);
return obj
}
/**
* 清空对象池
*/
public clear() {
for (let i = 0; i < this.pool.length; i++) {
delete this.pool[i];
}
this.pool = [];
}
}
\ No newline at end of file
let RainData = {
key:[
key: [
'bird',
'cattle',
'lion',
......@@ -7,30 +7,50 @@ let RainData = {
'rabbit',
'hongbao'
],
// bird:{
// default:"hbGame_bird_png",
// touch:"hbGame_bird_touch_png",
// },
// cattle:{
// default:"hbGame_cattle_png",
// touch:"hbGame_cattle_touch_png",
// },
// lion:{
// default:"hbGame_lion_png",
// touch:"hbGame_lion_touch_png",
// },
// pig:{
// default:"hbGame_pig_png",
// touch:"hbGame_pig_touch_png",
// },
// rabbit:{
// default:"hbGame_rabbit_png",
// touch:"hbGame_rabbit_touch_png",
// },
// hongbao:{
// default:"hbGame_hongbao_png",
// touch:"hbGame_hongbao_touch_png",
// },
data: {
bird: {
score: 2,
},
cattle: {
score: 2,
},
lion: {
score: 2,
},
pig: {
score: 2,
},
rabbit: {
score: 2,
},
hongbao: {
score: 1,
},
// bird:{
// default:"hbGame_bird_png",
// touch:"hbGame_bird_touch_png",
// },
// cattle:{
// default:"hbGame_cattle_png",
// touch:"hbGame_cattle_touch_png",
// },
// lion:{
// default:"hbGame_lion_png",
// touch:"hbGame_lion_touch_png",
// },
// pig:{
// default:"hbGame_pig_png",
// touch:"hbGame_pig_touch_png",
// },
// rabbit:{
// default:"hbGame_rabbit_png",
// touch:"hbGame_rabbit_touch_png",
// },
// hongbao:{
// default:"hbGame_hongbao_png",
// touch:"hbGame_hongbao_touch_png",
// },
}
};
export default RainData;
\ No newline at end of file
import RainObj from "./RainObj";
import RainData from "./RainData";
import { GDispatcher } from "../../../libs/tc/util/GDispatcher";
import Pooling from "./Pooling";
import Utils from "../../Utils";
export default class RainMgr {
private rainPool: Pooling = null;
private data;
private parent;
private rainGroup;
private readonly rainGroup;
private timer: egret.Timer = null;
constructor(data){
constructor(data) {
this.data = data;
this.parent = this.data.parent;
this.rainGroup = this.data.rainGroup;
......@@ -14,13 +21,51 @@ export default class RainMgr {
this.start();
}
private start(){
let s = new RainObj({
key:RainData.key[~~(Math.random() * RainData.key.length)],
scale: 1,
rainGroup: this.rainGroup,
});
private gameOver() {
this.timer.stop(); // 停止计时器
// 隐藏全部掉落物品
for(let v of this.rainGroup.$children) {
v.visible = false;
}
}
private start() {
this.addPool();
GDispatcher.addEvent('hbRainGameOver', this.gameOver, this);
this.timer = new egret.Timer(1500, 0);
this.timer.addEventListener(egret.TimerEvent.TIMER, this.addRain, this);
this.timer.start();
}
private addRain() {
let num = Utils.RandomInt(3, 5);
for(let i = 0; i < Utils.RandomInt(3, 5); i++) {
let newRainObj = this.rainPool.get();
if(!newRainObj) {
newRainObj = new RainObj({
key: RainData[~~(Math.random() * RainData.key.length)],
rainGroup: this.rainGroup,
pool:this.rainPool,
});
}
newRainObj.addStage((this.rainGroup.width - 200) / num * i + 100, Utils.RandomInt(7, 10) / 10);
}
}
private addPool() {
this.rainPool = new Pooling();
for(let v of RainData.key) {
for(let i = 0; i < 10; i++) {
let newObj = new RainObj({
key: v,
rainGroup: this.rainGroup,
pool:this.rainPool,
});
this.rainPool.push(newObj);
}
}
}
}
\ No newline at end of file
import { GDispatcher } from "../../../libs/tc/util/GDispatcher";
import RainData from "./RainData";
export default class RainObj {
private data = null;
private module: eui.Image = null;
......@@ -6,35 +9,42 @@ export default class RainObj {
constructor(data) {
this.data = data;
console.log(this.data);
this.module = new eui.Image(`hbGame_${this.data.key}_png`);
this.module.scaleX = this.module.scaleY = this.data.scale;
this.module.anchorOffsetX = 75;
this.module.anchorOffsetY = 70;
this.rainGroup = this.data.rainGroup;
this.module.x = 100;
this.module.y = -100;
this.rainGroup.addChild(this.module);
}
public addStage(x, scale) {
this.module.x = x;
this.module.y = -200;
this.module.scaleX = this.module.scaleY = scale;
this.module.visible = true;
this.rainGroup.addChild(this.module);
this.start();
}
private start() {
this.module.touchEnabled = true;
this.module.source = `hbGame_${this.data.key}_png`;
this.module.addEventListener(egret.TouchEvent.TOUCH_TAP, this.touchTap, this);
egret.Tween.get(this.module, {loop: true}).to({rotation: ~~(Math.random() * 2) ? 360 : -360}, 18000);
egret.Tween.get(this.module).to({y: this.rainGroup.height}, 10000).call(() => this.destroy());
egret.Tween.get(this.module).to({y: this.rainGroup.height + 200}, 5000).call(() => this.destroy());
}
private touchTap() {
GDispatcher.dispatchEvent('hbGameAddScore', RainData.data[this.data.key].score);
this.module.source = `hbGame_${this.data.key}_touch_png`;
this.destroy();
}
private destroy() {
egret.Tween.removeTweens(this.module);
this.module.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.touchTap, this);
this.module.source = `hbGame_${this.data.key}_touch_png`;
setTimeout(()=>{
this.module.touchEnabled = false;
setTimeout(() => {
this.rainGroup.removeChild(this.module);
this.data.pool.push(this);
}, 1000);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment