Commit d1566d32 authored by 王梦佳's avatar 王梦佳

娃娃机自定义

parent b9593434
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "拆礼盒",
"desc": "拆礼盒模块",
"props": {
"initX": {
"alias": "游戏场景初始X位置",
"type": "number",
"default": 0
},
"initY": {
"alias": "游戏场景初始Y位置",
"type": "number",
"default": 0
},
"gameStageWidth": {
"alias": "游戏场景宽度",
"type": "number",
"default": 534
},
"gameStageHeight": {
"alias": "游戏场景高度",
"type": "number",
"default": 408
}
},
"assets": [
{
"name": "底座",
"url": "//yun.duiba.com.cn/aurora/assets/d6ed718f0d236febaa4d1331950e5a190f225cb5.png",
"uuid": "7a0f8b48-449c-46d9-bd80-64455a30e641",
"ext": ".png"
},
{
"name": "点缀",
"url": "//yun.duiba.com.cn/aurora/assets/e08f680bbd26c4dcc47fd67ee2e145c46d6fcd1a.png",
"uuid": "c7426dc4-d631-4947-accc-015666277208",
"ext": ".png"
},
{
"name": "初始礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/b9bb4e52c3734025fc96a92cb574c92209927b61.svga",
"uuid": "947cb448-1992-49f1-a9ed-e359b944953a",
"ext": ".svga"
},
{
"name": "拆礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/8e86f8696710de414f0f36dc330db6e4bd0683d6.svga",
"uuid": "d9222991-064c-4816-85ee-6964ba78fbd0",
"ext": ".svga"
}
],
"events": {
"in": {
"open-gift-game-init": {
"alias": "重置"
},
"open-gift-game-start": {
"alias": "开始",
"data": {
"prize": true
}
}
},
"out": {
"open-gift-game-end": {
"alias": "动画完毕",
"data": null
}
}
},
"id": "open-gift",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof define === 'function' && define.amd ? define(['tslib'], factory) :\n\t(global = global || self, global['open-gift'] = factory(global.tslib));\n}(this, (function (tslib) { 'use strict';\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\t//# sourceMappingURL=props.js.map\n\n\tfunction getTexture(uuid) {\n\t return engine.Texture.from(getAssetByUUID(uuid).uuid);\n\t}\n\tfunction getTextureByName(name) {\n\t return getTexture(engine.getAssetByName(name).uuid);\n\t}\n\tfunction createSvga(name, anchorName) {\n\t var inst = new svga.Svga();\n\t inst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\t return inst;\n\t}\n\t//# sourceMappingURL=utils.js.map\n\n\tvar GameView = (function (_super) {\n\t tslib.__extends(GameView, _super);\n\t function GameView() {\n\t var _this = _super.call(this) || this;\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t return _this;\n\t }\n\t GameView.prototype.setup = function () {\n\t if (this._hasSetup) {\n\t return;\n\t }\n\t this._hasSetup = true;\n\t this.NpcBg = new engine.Container();\n\t this.NpcBg.x = props.initX;\n\t this.NpcBg.y = props.initY;\n\t this.addChild(this.NpcBg);\n\t this.bottomCircle = new engine.Sprite(getTextureByName('底座'));\n\t this.bottomCircle.x = 17;\n\t this.bottomCircle.y = 305;\n\t this.loveDot = new engine.Sprite(getTextureByName('点缀'));\n\t this.loveDot.x = 0;\n\t this.loveDot.y = 6;\n\t this.giftboxSvga = createSvga('初始礼盒');\n\t this.giftboxSvga.x = 105;\n\t this.giftboxSvga.y = 37;\n\t this.giftAfterSvga = createSvga(\"拆礼盒\");\n\t this.giftAfterSvga.x = 105;\n\t this.giftAfterSvga.y = 0;\n\t this.giftAfterSvga.visible = false;\n\t this.NpcBg.addChild(this.bottomCircle);\n\t this.NpcBg.addChild(this.giftboxSvga);\n\t this.NpcBg.addChild(this.giftAfterSvga);\n\t this.NpcBg.addChild(this.loveDot);\n\t this.giftboxSvga.play(false, true);\n\t };\n\t GameView.prototype.reset = function () {\n\t this.giftboxSvga.visible = true;\n\t this.giftAfterSvga.visible = false;\n\t };\n\t GameView.prototype.start = function () {\n\t this.giftAfterSvga.visible = true;\n\t this.giftboxSvga.visible = false;\n\t this.giftAfterSvga.play(false, false);\n\t this.giftAfterSvga.once(engine.Event.END_FRAME, function () {\n\t engine.globalEvent.dispatchEvent('open-gift-game-end');\n\t }, this);\n\t };\n\t GameView.prototype.resume = function () {\n\t this.reset();\n\t this.start();\n\t };\n\t return GameView;\n\t}(engine.Container));\n\n\tvar GameWrapper = (function (_super) {\n\t tslib.__extends(GameWrapper, _super);\n\t function GameWrapper() {\n\t var _this = _super.call(this) || this;\n\t engine.globalEvent.addEventListener('open-gift-game-init', _this.reset, _this);\n\t engine.globalEvent.addEventListener('open-gift-game-start', _this.start, _this);\n\t var gameView = _this._gameView = new GameView();\n\t _this.addChild(gameView);\n\t return _this;\n\t }\n\t GameWrapper.prototype.reset = function (event) {\n\t injectProps(event.data);\n\t this._gameView.visible = true;\n\t this._gameView.reset();\n\t };\n\t GameWrapper.prototype.start = function (event) {\n\t console.log('监听开始');\n\t injectProps(event.data);\n\t this._gameView.start();\n\t };\n\t GameWrapper.prototype.clear = function () {\n\t this._gameView.visible = false;\n\t };\n\t return GameWrapper;\n\t}(engine.Container));\n\t//# sourceMappingURL=GameWrapper.js.map\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new GameWrapper();\n\t return instance;\n\t}\n\t//# sourceMappingURL=index.js.map\n\n\treturn index;\n\n})));\n"
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -50,7 +50,10 @@ export default class GameView extends engine.Container { ...@@ -50,7 +50,10 @@ export default class GameView extends engine.Container {
//游戏状态 //游戏状态
private gameIng; private gameIng;
//是否已获取位移值
public startstatus=false;
//是否中奖
public ifPrize=false;
//npc出身计时器 //npc出身计时器
private timer; private timer;
//倒计时计时器 //倒计时计时器
...@@ -103,14 +106,9 @@ export default class GameView extends engine.Container { ...@@ -103,14 +106,9 @@ export default class GameView extends engine.Container {
// this.rect.width = 608; // this.rect.width = 608;
this.rect.width = 611; this.rect.width = 611;
this.rect.height = 704; this.rect.height = 704;
// this.rect.x = 71;
// this.rect.y = 263;
this.rect.x = 65; this.rect.x = 65;
this.rect.y = 267; this.rect.y = 263;
this.NpcBg = new engine.Container(); this.NpcBg = new engine.Container();
// this.NpcBg.alpha = 1;
// this.NpcBg.width = 0;
// this.NpcBg.height = 0;
this.addChild(this.NpcBg); this.addChild(this.NpcBg);
this.addChild(this.rect); this.addChild(this.rect);
...@@ -118,16 +116,16 @@ export default class GameView extends engine.Container { ...@@ -118,16 +116,16 @@ export default class GameView extends engine.Container {
let gameBg = new engine.Sprite(getTextureByName("游戏背景")); let gameBg = new engine.Sprite(getTextureByName("游戏背景"));
gameBg.x = 65; gameBg.x = 65;
gameBg.y = 267; gameBg.y = 263;
this.NpcBg.addChild(gameBg); this.NpcBg.addChild(gameBg);
this.frontDesk = new engine.Sprite(getTextureByName("前传输带")); this.frontDesk = new engine.Sprite(getTextureByName("前传输带"));
this.frontDesk.x = 60; this.frontDesk.x = 60;
this.frontDesk.y = 904; this.frontDesk.y = 781;
this.backDesk = new engine.Sprite(getTextureByName("后传输带")); this.backDesk = new engine.Sprite(getTextureByName("后传输带"));
this.backDesk.x = 60; this.backDesk.x = 60;
this.backDesk.y = 810; this.backDesk.y = 712;
this.NpcBg.addChild(this.backDesk); this.NpcBg.addChild(this.backDesk);
this.NpcBg.addChild(this.frontDesk); this.NpcBg.addChild(this.frontDesk);
...@@ -165,9 +163,9 @@ export default class GameView extends engine.Container { ...@@ -165,9 +163,9 @@ export default class GameView extends engine.Container {
*/ */
setMoveX(x, item) { setMoveX(x, item) {
this.moveTime = x; this.moveTime = x;
this.prizeBox = item; this.prizeBox = item;
this._Zhuazi.move(); this._Zhuazi.move();
} }
/** /**
* 显示隐藏盒子 * 显示隐藏盒子
*/ */
...@@ -178,9 +176,14 @@ export default class GameView extends engine.Container { ...@@ -178,9 +176,14 @@ export default class GameView extends engine.Container {
* 获取中奖盒子移动的距离 * 获取中奖盒子移动的距离
*/ */
getMoveX() { getMoveX() {
console.log(222);
return this.moveTime; return this.moveTime;
} }
/**
* 重置moveTime
*/
resetMoveX() {
this.moveTime = null;
}
/** /**
* 获取中奖盒子 * 获取中奖盒子
*/ */
...@@ -191,37 +194,40 @@ export default class GameView extends engine.Container { ...@@ -191,37 +194,40 @@ export default class GameView extends engine.Container {
* 重置场景 * 重置场景
*/ */
reset() { reset() {
this.recycleGoods(); this.startstatus = false;
this.ifPrize = false;
this._Zhuazi.getReset(); this._Zhuazi.getReset();
} }
/** /**
* 开始 * 开始
*/ */
start() { start(type=null) {
this.score = 0;
this.speed = 1; this.speed = 1;
this.gameIng = true; this.gameIng = true;
console.log('执行', type);
this.startstatus = true;
this.ifPrize = type && type.prize || false;
// this.creatNpc() // this.creatNpc()
// this.beginNpc(); // this.beginNpc();
this.countdown = props.countDown; // this.countdown = props.countDown;
this.countdownTimer = setInterval(() => { // this.countdownTimer = setInterval(() => {
if (this.gameIng) { // if (this.gameIng) {
if (this.countdown > 0) { // if (this.countdown > 0) {
engine.globalEvent.dispatchEvent("food-fell-time-update", { // engine.globalEvent.dispatchEvent("food-fell-time-update", {
time: this.countdown // time: this.countdown
}); // });
this.countdown -= 1; // this.countdown -= 1;
} else { // } else {
engine.globalEvent.dispatchEvent("food-fell-game-over", { // engine.globalEvent.dispatchEvent("food-fell-game-over", {
score: this.score, // score: this.score,
reason: 1 // reason: 1
}); // });
this.died(); // this.died();
} // }
} // }
}, 1000); // }, 1000);
} }
/** /**
......
...@@ -17,17 +17,18 @@ export class GameWrapper extends engine.Container { ...@@ -17,17 +17,18 @@ export class GameWrapper extends engine.Container {
constructor() { constructor() {
super(); super();
engine.globalEvent.addEventListener('doll-machine-reset', this.reset, this); engine.globalEvent.addEventListener('doll-machine-reset', this.reset, this);
engine.globalEvent.addEventListener('food-fell-start', this.start, this); engine.globalEvent.addEventListener('doll-machine-prize', this.start, this);
engine.globalEvent.addEventListener('food-fell-pause', this.pause, this); // engine.globalEvent.addEventListener('food-fell-start', this.start, this);
engine.globalEvent.addEventListener('food-fell-resume', this.resume, this); // engine.globalEvent.addEventListener('food-fell-pause', this.pause, this);
engine.globalEvent.addEventListener('food-fell-revive', this.revive, this); // engine.globalEvent.addEventListener('food-fell-resume', this.resume, this);
engine.globalEvent.addEventListener('food-fell-clear', this.clear, this); // engine.globalEvent.addEventListener('food-fell-revive', this.revive, this);
// engine.globalEvent.addEventListener('food-fell-clear', this.clear, this);
this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this); // this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this);
let gameView = this._gameView = new GameView(); let gameView = this._gameView = new GameView();
this.addChild(gameView); this.addChild(gameView);
// gameView.reset() // gameView.reset();
// gameView.start() // gameView.start()
} }
...@@ -38,9 +39,10 @@ export class GameWrapper extends engine.Container { ...@@ -38,9 +39,10 @@ export class GameWrapper extends engine.Container {
} }
start(event: engine.Event) { start(event: engine.Event) {
console.log('监听开始');
injectProps(event.data); injectProps(event.data);
this._status = 1; // this._status = 1;
this._gameView.start(); this._gameView.start(event.data);
} }
pause() { pause() {
......
...@@ -32,29 +32,27 @@ export class Zhuazi extends engine.Container { ...@@ -32,29 +32,27 @@ export class Zhuazi extends engine.Container {
this.ganNode = new engine.Container(); this.ganNode = new engine.Container();
this.moveNode = new engine.Container(); this.moveNode = new engine.Container();
this.ganNode.x = 280; this.ganNode.x = 280;
this.ganNode.y = 425; this.ganNode.y = 350;
this.bashouGan = new engine.Sprite(getTextureByName("把手杆子")); this.bashouGan = new engine.Sprite(getTextureByName("把手杆子"));
this.bashouGan.x = 60; this.bashouGan.x = 60;
this.bashouGan.y = 342; this.bashouGan.y = 275;
this.bashou = new engine.Sprite(getTextureByName("把手")); this.bashou = new engine.Sprite(getTextureByName("把手"));
this.bashou.x = 0; this.bashou.x = 0;
this.bashou.y = 320; this.bashou.y = 263;
this.ganzi = new engine.Sprite(getTextureByName("伸缩杆")); this.ganzi = new engine.Sprite(getTextureByName("伸缩杆"));
this.ganzi.x = 97; this.ganzi.x = 97;
this.ganzi.y = 382; this.ganzi.y = 290;
this.connect = new engine.Sprite(getTextureByName("连接点")); this.connect = new engine.Sprite(getTextureByName("连接点"));
this.connect.x = 20; this.connect.x = 18;
this.connect.y = 0; this.connect.y = -5;
this.left_zhuazi = new engine.Sprite(getTextureByName("左爪")); this.left_zhuazi = new engine.Sprite(getTextureByName("左爪"));
this.left_zhuazi.x = 0; this.left_zhuazi.x = -15;
this.left_zhuazi.y = 60; this.left_zhuazi.y = 60;
this.left_zhuazi.anchorX = this.left_zhuazi.width; this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0; this.left_zhuazi.anchorY = 0;
this.left_zhuazi.rotation = 30;
this.right_zhuazi = new engine.Sprite(getTextureByName("右爪")); this.right_zhuazi = new engine.Sprite(getTextureByName("右爪"));
this.right_zhuazi.x = 83; this.right_zhuazi.x = 98;
this.right_zhuazi.y = 60; this.right_zhuazi.y = 60;
this.right_zhuazi.rotation = -30;
this.ganNode.addChild(this.left_zhuazi); this.ganNode.addChild(this.left_zhuazi);
this.ganNode.addChild(this.right_zhuazi); this.ganNode.addChild(this.right_zhuazi);
this.ganNode.addChild(this.connect); this.ganNode.addChild(this.connect);
...@@ -78,31 +76,30 @@ export class Zhuazi extends engine.Container { ...@@ -78,31 +76,30 @@ export class Zhuazi extends engine.Container {
} }
createPrizeBox() { createPrizeBox() {
this.box1 = new engine.Sprite(getTextureByName("狗盒")); this.box1 = new engine.Sprite(getTextureByName("中奖狗盒"));
this.box1["npcType"] = "box1"; this.box1["npcType"] = "box1";
this.box2 = new engine.Sprite(getTextureByName("猫盒")); this.box2 = new engine.Sprite(getTextureByName("中奖猫盒"));
this.box2["npcType"] = "box2"; this.box2["npcType"] = "box2";
this.box3 = new engine.Sprite(getTextureByName("草泥马盒")); this.box3 = new engine.Sprite(getTextureByName("中奖草泥马盒"));
this.box3["npcType"] = "box3"; this.box3["npcType"] = "box3";
this.box4 = new engine.Sprite(getTextureByName("狗盒")); this.box4 = new engine.Sprite(getTextureByName("中奖狗盒"));
this.box4["npcType"] = "box4"; this.box4["npcType"] = "box4";
this.box5 = new engine.Sprite(getTextureByName("猫盒")); this.box5 = new engine.Sprite(getTextureByName("中奖猫盒"));
this.box5["npcType"] = "box5"; this.box5["npcType"] = "box5";
this.prizeBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5]; this.prizeBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
this.prizeBoxs.forEach(item => { this.prizeBoxs.forEach(item => {
this.ganNode.addChild(item); this.ganNode.addChild(item);
item.visible = false; item.visible = false;
item.x = -15; item.x = 15;
item.y = 48; item.y = 48;
}) })
} }
showPrizeBox() { showPrizeBox() {
this.prizeBoxs.forEach(item => { this.prizeBoxs.forEach(item => {
console.log(this.GameView.getBox()['npcType']); console.log(this.GameView.getBox()['npcType']);
if (item['npcType'] === this.GameView.getBox()['npcType']) { if (item['npcType'] === this.GameView.getBox()['npcType']) {
item.visible = true; item.visible = true;
this.itemShow = item; this.itemShow = item;
} else { } else {
item.visible = false; item.visible = false;
} }
...@@ -117,13 +114,6 @@ export class Zhuazi extends engine.Container { ...@@ -117,13 +114,6 @@ export class Zhuazi extends engine.Container {
engine.Tween.get(this.moveNode).to({ x: 370 + halfWidth - 71}, 1000).call(() => { engine.Tween.get(this.moveNode).to({ x: 370 + halfWidth - 71}, 1000).call(() => {
this.zhangkai(); this.zhangkai();
}); });
// this.moveArr.forEach((item,index) => {
// engine.Tween.get(item).to({ x: item.x +randomX}, 500).to({x: 370}, 500).call(() => {
// if (index == this.moveArr.length-1) {
// this.zhangkai();
// }
// });
// })
} }
zhangkai() { zhangkai() {
this.left_zhuazi.anchorX = this.left_zhuazi.width; this.left_zhuazi.anchorX = this.left_zhuazi.width;
...@@ -143,22 +133,27 @@ export class Zhuazi extends engine.Container { ...@@ -143,22 +133,27 @@ export class Zhuazi extends engine.Container {
console.log('node', this.zhuaziY); console.log('node', this.zhuaziY);
engine.Tween.get(this.ganNode).to({ y: props.ganMoveEndY }, droptime).call(() => { engine.Tween.get(this.ganNode).to({ y: props.ganMoveEndY }, droptime).call(() => {
this.GameView.stopMove(); this.GameView.stopMove();
this.showPrizeBox(); if (this.GameView.ifPrize) {
this.GameView.setVisible(false); this.showPrizeBox();
this.GameView.setVisible(false);
}
}).to({ y: this.zhuaziY }, droptime).call(() => { }).to({ y: this.zhuaziY }, droptime).call(() => {
engine.globalEvent.dispatchEvent('doll-mac-getprize'); // this.getReset();
this.getReset(); if (this.GameView.ifPrize) {
this.itemShow.visible = false;
}
engine.globalEvent.dispatchEvent('doll-machine-gameover');
}) })
// .to({ scaleY: 1 }, droptime)
// to({ y: this.zhuaziY }, droptime)
} }
getReset() { getReset() {
this.itemShow.visible = false; // if (this.GameView.ifPrize) {
// this.itemShow.visible = false;
// }
this.left_zhuazi.anchorX = this.left_zhuazi.width; this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0; this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.moveNode, {loop: false}).to({x: 262}, 1000); engine.Tween.get(this.moveNode, {loop: false}).to({x: 262}, 1000);
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: 0 }, 1000); engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: 0 }, 1000); engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
this.GameView.resetMoveX();
} }
} }
\ No newline at end of file
...@@ -17,18 +17,18 @@ export class BackBoxs extends engine.Container { ...@@ -17,18 +17,18 @@ export class BackBoxs extends engine.Container {
} }
setup() { setup() {
let initX , initY = 0; let initX , initY = 0;
this.box1 = new engine.Sprite(getTextureByName("狗盒")); this.box1 = new engine.Sprite(getTextureByName("狗盒"));
initX = this.box1.x = 188; initX = this.box1.x = 188;
initY = this.box1.y = 706; initY = this.box1.y = 616;
this.box2 = new engine.Sprite(getTextureByName("猫盒")); this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box3 = new engine.Sprite(getTextureByName("草泥马盒")); this.box3 = new engine.Sprite(getTextureByName("草泥马盒"));
this.box4 = new engine.Sprite(getTextureByName("狗盒")); this.box4 = new engine.Sprite(getTextureByName("狗盒"));
this.box5 = new engine.Sprite(getTextureByName("猫盒")); this.box5 = new engine.Sprite(getTextureByName("猫盒"));
this.backBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5]; this.backBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
for (let i = 0; i < this.backBoxs.length; i++) { for (let i = 0; i < this.backBoxs.length; i++) {
this.backBoxs[i].scaleX = 0.5; // this.backBoxs[i].scaleX = 0.5;
this.backBoxs[i].scaleY = 0.5; // this.backBoxs[i].scaleY = 0.5;
if(i == 0) { if(i == 0) {
this.backBoxs[i].x = initX; this.backBoxs[i].x = initX;
} else { } else {
......
...@@ -6,7 +6,7 @@ export class FrontBoxs extends engine.Container { ...@@ -6,7 +6,7 @@ export class FrontBoxs extends engine.Container {
private box1: engine.Container; private box1: engine.Container;
//盒子2 //盒子2
private box2: engine.Container; private box2: engine.Container;
//盒子3 //盒子3
private box3: engine.Container; private box3: engine.Container;
//盒子4 //盒子4
private box4: engine.Container; private box4: engine.Container;
...@@ -24,7 +24,7 @@ export class FrontBoxs extends engine.Container { ...@@ -24,7 +24,7 @@ export class FrontBoxs extends engine.Container {
this.box1 = new engine.Sprite(getTextureByName("狗盒")); this.box1 = new engine.Sprite(getTextureByName("狗盒"));
this.box1["npcType"] = "box1"; this.box1["npcType"] = "box1";
initX = this.box1.x = 435; initX = this.box1.x = 435;
initY = this.box1.y = 734; initY = this.box1.y = 614;
this.box2 = new engine.Sprite(getTextureByName("猫盒")); this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box2["npcType"] = "box2"; this.box2["npcType"] = "box2";
...@@ -57,7 +57,7 @@ export class FrontBoxs extends engine.Container { ...@@ -57,7 +57,7 @@ export class FrontBoxs extends engine.Container {
let lastitem = this.frontBoxs.shift(); let lastitem = this.frontBoxs.shift();
lastitem.x = this.frontBoxs[this.frontBoxs.length - 1].x - this.box1.width - props.frontmargin; lastitem.x = this.frontBoxs[this.frontBoxs.length - 1].x - this.box1.width - props.frontmargin;
if(!this.GameView.getMoveX() && item.x <= 0) { if (!this.GameView.getMoveX() && item.x <= 0 && this.GameView.startstatus) {
this.GameView.setMoveX((370 - item.x - 13) / props.moveSpeed, item); this.GameView.setMoveX((370 - item.x - 13) / props.moveSpeed, item);
this.hideBox = item; this.hideBox = item;
} }
......
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = "doll-machine2";
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "娃娃机2",
"desc": "娃娃机通用模块",
"props": {
"single": {
"alias": "是否是单层娃娃",
"type": "boolean",
"default": true
},
"dollNum": {
"alias": "一屏展示娃娃个数(最大为4)",
"type": "number",
"default": 4
},
"initOffsetTop": {
"alias": "整体距离上边距",
"type": "number",
"default": 0
},
"initOffsetLeft": {
"alias": "整体距离左边距",
"type": "number",
"default": 60
},
"frontDeskY": {
"alias": "前排传输带Y位置",
"type": "number",
"default": 518
},
"frontInitX": {
"alias": "前排最右侧娃娃初始X位置",
"type": "number",
"default": 600
},
"frontInitY": {
"alias": "前排最右侧娃娃初始Y位置",
"type": "number",
"default": 351
},
"backDeskY": {
"alias": "后排传输带Y位置",
"type": "number",
"default": 449
},
"backInitX": {
"alias": "后排最右侧娃娃初始X位置",
"type": "number",
"default": 188
},
"backInitY": {
"alias": "后排最右侧娃娃初始Y位置",
"type": "number",
"default": 353
},
"ganziShow": {
"alias": "是否显示杆子",
"type": "boolean",
"default": true
},
"bashouShow": {
"alias": "是否显示把手",
"type": "boolean",
"default": true
},
"gameStageWidth": {
"alias": "游戏场景宽度",
"type": "number",
"default": 611
},
"gameStageHeight": {
"alias": "游戏场景高度",
"type": "number",
"default": 704
},
"frontmargin": {
"alias": "前排娃娃的间距",
"type": "number",
"default": 13
},
"backmargin": {
"alias": "后排娃娃的间距",
"type": "number",
"default": 50
},
"moveSpeed": {
"alias": "娃娃移动的速度",
"type": "number",
"default": 3
},
"bashouMoveDist": {
"alias": "爪子整体左右移动的范围",
"type": "number",
"default": 200
},
"ganMoveEndY": {
"alias": "杆子最后需要移动到的y值位置",
"type": "number",
"default": 357
},
"leftRotation": {
"alias": "左边爪子旋转角度",
"type": "number",
"default": 20
},
"rightRotation": {
"alias": "右边爪子旋转角度",
"type": "number",
"default": -20
},
"prizeBoxInitX": {
"alias": "中奖娃娃的x位置",
"type": "number",
"default": 15
},
"prizeBoxInitY": {
"alias": "中奖娃娃的y位置",
"type": "number",
"default": 48
}
},
"assets": [
{
"name": "游戏背景",
"url": "//yun.duiba.com.cn/aurora/assets/460fd0242aada85de5554391756db6ed2a232a9b.png",
"uuid": "05c378c3-bed0-4d5c-bed8-f05ae7920931",
"ext": ".png"
},
{
"name": "frontbox_0",
"url": "//yun.duiba.com.cn/aurora/assets/fde8c60981791e5136c7914274c2a2d0936626cd.png",
"uuid": "aa30ee7c-a6ad-4e10-9b6a-13b139664ab5",
"ext": ".png"
},
{
"name": "frontbox_1",
"url": "//yun.duiba.com.cn/aurora/assets/befb2c9ddfd8a5c4acd5126b2d793f7c1bcc40f2.png",
"uuid": "4483b626-697a-4aa4-ba57-0c22ddc7c0e6",
"ext": ".png"
},
{
"name": "frontbox_2",
"url": "///yun.duiba.com.cn/aurora/assets/50991e640e6bcc2eee02ba945d48a8430ddd2bee.png",
"uuid": "b70f2980-a2b3-4ef7-b060-b14dc7a8c9c8",
"ext": ".png"
},
{
"name": "frontbox_3",
"url": "//yun.duiba.com.cn/aurora/assets/fde8c60981791e5136c7914274c2a2d0936626cd.png",
"uuid": "aa30ee7c-a6ad-4e10-9b6a-13b139664ab1",
"ext": ".png"
},
{
"name": "frontbox_4",
"url": "//yun.duiba.com.cn/aurora/assets/fde8c60981791e5136c7914274c2a2d0936626cd.png",
"uuid": "aa30ee7c-a6ad-4e10-9b6a-13b139664ab2",
"ext": ".png"
},
{
"name": "backbox_0",
"url": "//yun.duiba.com.cn/aurora/assets/94884eafc876346e283efef2aa29bd6d2c36f627.png",
"uuid": "3f3feb30-6700-4ac7-a14e-6d7e41e8d4e8",
"ext": ".png"
},
{
"name": "backbox_1",
"url": "//yun.duiba.com.cn/aurora/assets/7deaaf45e03a626efbced90e4ad3d22373b01bd3.png",
"uuid": "b1422629-55d2-4b8b-bdd0-1b043f965248",
"ext": ".png"
},
{
"name": "backbox_2",
"url": "//yun.duiba.com.cn/aurora/assets/28a5b5b04c84d6acc86b7efb81dd6d7f717e0cda.png",
"uuid": "708da046-26e1-4ff7-abb6-35bf825a5d5b",
"ext": ".png"
},
{
"name": "backbox_3",
"url": "//yun.duiba.com.cn/aurora/assets/28a5b5b04c84d6acc86b7efb81dd6d7f717e0cda.png",
"uuid": "708da046-26e1-4ff7-abb6-35bf825a5d51",
"ext": ".png"
},
{
"name": "backbox_4",
"url": "//yun.duiba.com.cn/aurora/assets/28a5b5b04c84d6acc86b7efb81dd6d7f717e0cda.png",
"uuid": "708da046-26e1-4ff7-abb6-35bf825a5d55",
"ext": ".png"
},
{
"name": "prizebox_0",
"url": "//yun.duiba.com.cn/aurora/assets/a47f438d016d1b178cdb5241651a78e4ea365e75.png",
"uuid": "c106cd1d-52a0-422a-976c-67151af0b484",
"ext": ".png"
},
{
"name": "prizebox_1",
"url": "//yun.duiba.com.cn/aurora/assets/fd60c2da0ce78f7b7bed0e9c45644882a1a40d90.png",
"uuid": "3ff6fb20-4a2f-4789-998d-6078e3b603ec",
"ext": ".png"
},
{
"name": "prizebox_2",
"url": "//yun.duiba.com.cn/aurora/assets/6211ab330a3768ff0a1920cff0ec41f29fa0903b.png",
"uuid": "04fa3325-87fc-4009-bfba-26a95d92d80c",
"ext": ".png"
},
{
"name": "prizebox_3",
"url": "//yun.duiba.com.cn/aurora/assets/6211ab330a3768ff0a1920cff0ec41f29fa0903b.png",
"uuid": "04fa3325-87fc-4009-bfba-26a95d92d800",
"ext": ".png"
},
{
"name": "prizebox_4",
"url": "//yun.duiba.com.cn/aurora/assets/6211ab330a3768ff0a1920cff0ec41f29fa0903b.png",
"uuid": "04fa3325-87fc-4009-bfba-26a95d92d80a",
"ext": ".png"
},
{
"name": "前传输带",
"url": "//yun.duiba.com.cn/aurora/assets/7bccbc67b3f896176bed7d21c5f4d4307c3919be.png",
"uuid": "06bd03a4-43c3-49bb-94c5-6ef365f70291",
"ext": ".png"
},
{
"name": "后传输带",
"url": "//yun.duiba.com.cn/aurora/assets/df9b718f80747a1e21349d2b9ac35d5e19a61dad.png",
"uuid": "aa0c6ebc-164f-4767-90ca-a79be4316365",
"ext": ".png"
},
{
"name": "把手杆子",
"url": "//yun.duiba.com.cn/aurora/assets/5a9e4ba7ca6701eae85b6d6dcb0612ecb9a3eff9.png",
"uuid": "f2f1a937-00f4-442f-af4f-0bcb00656e69",
"ext": ".png"
},
{
"name": "把手",
"url": "//yun.duiba.com.cn/aurora/assets/71255a6f3cdf9f66d53589e46d72fcd20fef468d.png",
"uuid": "d9b395b5-4e46-43a5-aa2b-bfdd81c07fa7",
"ext": ".png"
},
{
"name": "伸缩杆",
"url": "//yun.duiba.com.cn/aurora/assets/a9cf8b147c52b7d4247e80e90e098f787808bfa9.png",
"uuid": "fddb4636-9c62-47b2-ba5e-f2cd820dbccc",
"ext": ".png"
},
{
"name": "左爪",
"url": "//yun.duiba.com.cn/aurora/assets/1e8634fd94bda455d11956c2847d3823e80701d3.png",
"uuid": "739014d2-3193-4853-bf8d-349bd3e8d990",
"ext": ".png"
},
{
"name": "右爪",
"url": "//yun.duiba.com.cn/aurora/assets/4bfc510e0d1fa1db77f5effa187294af38b74ff6.png",
"uuid": "4fb43b19-67e9-42cc-b461-35c005c714fb",
"ext": ".png"
},
{
"name": "连接点",
"url": "//yun.duiba.com.cn/aurora/assets/39f39234631f739e70e9ab8b713284379f4016fb.png",
"uuid": "2021124f-ffcb-487f-a24f-a00f3d8aae95",
"ext": ".png"
}
],
"events": {
"in": {
"doll-machine2-game-init": {
"alias": "重置"
},
"doll-machine2-game-start": {
"alias": "开始",
"data": {
"prize": true
}
}
},
"out": {
"doll-machine2-game-end": {
"alias": "重置完毕",
"data": null
}
}
}
}
/**
* Created by rockyl on 2018/8/16.
*/
import { props } from "../props";
import { playSound, createSvga } from "./utils";
import ObjectPool = engine.ObjectPool;
import { getTextureByName } from "./utils";
import { Goods } from "./Goods";
import { PoolName } from "./object-pool-init";
import { FrontBoxs } from "./frontBox";
import { BackBoxs } from "./backBox";
import { Zhuazi } from './Zhuazi';
export default class GameView extends engine.Container {
private _hasSetup;
//触摸层
private rectBg: engine.Rect;
//npc层
private NpcBg: engine.Container;
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
//前传输区域
private frontTransfer: engine.Container;
//后传输区域
private backTransfer: engine.Container;
//前台板
private frontDesk: engine.Sprite;
//后台板
private backDesk: engine.Sprite;
private _frontBoxs: FrontBoxs;
private _backBoxs: BackBoxs;
private _Zhuazi: Zhuazi;
private prizeBox: engine.Container;
private rect;
//当前分数
private score;
//中奖盒子移动距离
private moveTime;
//游戏状态
private gameIng;
//是否已获取位移值
public startstatus=true;
//是否中奖
public ifPrize=true;
//npc出身计时器
private timer;
//倒计时计时器
private countdownTimer: any;
//倒计时
private countdown: number;
//当前速度
private speed: number;
// 当前场景上面的物品
private goodsItems = [];
private _goods: Goods;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
// private waterSvga;
// private boomSvga;
// private playerSvga;
setup() {
if (this._hasSetup) {
return;
}
this._hasSetup = true;
const frontBoxs = (this._frontBoxs = new FrontBoxs());
this._frontBoxs.GameView = this;
const backBoxs = (this._backBoxs = new BackBoxs());
this._Zhuazi = new Zhuazi();
this._Zhuazi.GameView = this;
this.frontTransfer = new engine.Container();
this.backTransfer = new engine.Container();
this.frontTransfer.width = 0;
this.frontTransfer.height = 0;
this.frontTransfer.alpha = 1;
// this.frontTransfer.x = 0;
// this.frontTransfer.y = 434;
this.backTransfer.width = 0;
this.backTransfer.height = 0;
this.backTransfer.alpha = 1;
// this.backTransfer.x = 0;
// this.backTransfer.y = 390;
this.rect = new engine.Rect();
this.rect.width = props.gameStageWidth;
this.rect.height = props.gameStageHeight;
this.rect.x = 65;
this.rect.y = 0;
this.NpcBg = new engine.Container();
this.NpcBg.x = 0;
this.NpcBg.y = 0;
this.addChild(this.NpcBg);
this.addChild(this.rect);
// let gameBg = new engine.Sprite(getTextureByName("游戏背景"));
// gameBg.x = 65;
// gameBg.y = 263;
// this.NpcBg.addChild(gameBg);
this.frontDesk = new engine.Sprite(getTextureByName("前传输带"));
this.frontDesk.x = props.initOffsetLeft;
this.frontDesk.y = props.frontDeskY - props.initOffsetTop;
this.backDesk = new engine.Sprite(getTextureByName("后传输带"));
this.backDesk.x = props.initOffsetLeft;
this.backDesk.y = props.backDeskY - props.initOffsetTop;
if(props.single) {
this.backDesk.visible = false;
}
let pcarr = [this.backDesk, this.frontDesk, this.backTransfer, this.frontTransfer, this._Zhuazi];
pcarr.forEach(item => {
this.NpcBg.addChild(item);
})
this.NpcBg.mask = this.rect;
this._Zhuazi.setup();
// this._Zhuazi.move();
this.backTransfer.addChild(this._backBoxs);
this._backBoxs.setup();
if (props.single) {
this.backTransfer.visible = false;
}
this.frontTransfer.addChild(this._frontBoxs);
this._frontBoxs.setup();
}
/**
*
* @param 暂停move
*/
stopMove() {
this._frontBoxs.stop();
}
/**
* 赋值x距离值
*/
setMoveX(x, item) {
this.moveTime = x;
this.prizeBox = item;
this._Zhuazi.move();
}
/**
* 显示隐藏盒子
*/
setVisible(isshow) {
this._frontBoxs.showHidePrizeBox(isshow);
}
/**
* 获取中奖盒子移动的距离
*/
getMoveX() {
return this.moveTime;
}
/**
* 重置moveTime
*/
resetMoveX() {
this.moveTime = null;
}
/**
* 获取中奖盒子
*/
getBox() {
return this.prizeBox;
}
/**
* 重置场景
*/
reset() {
this.startstatus = false;
this.ifPrize = false;
this._Zhuazi.getReset();
}
/**
* 开始
*/
start(type=null) {
this.speed = 1;
this.gameIng = true;
console.log('执行', type);
this.startstatus = true;
this.ifPrize = type && type.prize || false;
}
/**
* npc开始掉落
*/
beginNpc() {
this.timer = setTimeout(() => {
if (this.gameIng) {
// this.speed += props.acceleratedSpeed;
// this.creatNpc()
}
//递归执行
// this.beginNpc();
}, 2000 / this.speed);
}
/**
* 暂停
*/
pause() {
this.gameIng = false;
}
/**
* 恢复
*/
revive() {
this.gameIng = true;
}
/**
* 重新开始
*/
resume() {
this.reset();
this.start();
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('doll-machine2-game-init', this.reset, this);
engine.globalEvent.addEventListener('doll-machine2-game-start', this.start, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
// gameView.reset();
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
console.log('监听开始');
injectProps(event.data);
// this._status = 1;
this._gameView.start(event.data);
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
clear() {
this._gameView.visible = false;
}
private onTap(event) {
// this._gameView.tap(event);
}
}
/**
* Created by rockyl on 2020-02-02.
*
* 掉落物品
*/
import { getTextureByName } from "./utils";
import { props } from "../props";
export class Goods extends engine.Container {
private _body: engine.Rect;
private _toY;
constructor() {
super();
let body;
body = this._body = new engine.Rect();
// let rain = new engine.Sprite(getTextureByName('雨滴'));
// rain["npcType"]="rain"
// let stone = new engine.Sprite(getTextureByName('石块'));
// stone["npcType"]="stone"
// let boom = new engine.Sprite(getTextureByName('炸弹'));
// boom["npcType"]="boom"
let box1 = new engine.Sprite(getTextureByName("草泥马盒"));
box1["npcType"] = "box1";
let box2 = new engine.Sprite(getTextureByName("狗盒"));
box2["npcType"] = "box2";
let box3 = new engine.Sprite(getTextureByName("猫盒"));
box3["npcType"] = "box3";
// rain.visible=false;
// stone.visible=false;
// boom.visible=false;
// body.addChild(rain)
// body.addChild(stone)
// body.addChild(boom)
box1.visible = false;
box2.visible = false;
box3.visible = false;
body.addChild(box1);
body.addChild(box2);
body.addChild(box3);
this.addChild(body);
body.width = 0.0001;
body.height = 0.0001;
body.mouseEnabled = false;
}
getRandomNumberByRange(start, end) {
return Math.floor(Math.random() * (end - start) + start);
}
// reset() {
// this.visible = true;
// this.rotation = 0;
// this.anchorOffsetY = 0;
// this.y = 0;
// this.x = (750-120)*Math.random()+30;
// this.rotation = 0;
// let random=Math.random()
// if(random<props.goodsProbability[0]){
// this.showNpc("box1")
// }else if(random>=props.goodsProbability[0]&&random<=(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box2")
// }else if(random>(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box3")
// }
// }
reset() {
this.visible = true;
this.y = 200;
this.x = 0;
this.rotation = 0;
let random = Math.random();
if (random < 0.3) {
this.showNpc("box1");
} else if (random < 0.6) {
this.showNpc("box2");
} else {
this.showNpc("box3");
}
// this.showNpc("box1");
// this.showNpc("box2");
// this.showNpc("box3");
}
showNpc(type) {
for (let i = 0; i < this._body.children.length; i++) {
this._body.children[i].visible = false;
this._body.children[i].mouseEnabled = false;
}
for (let i = 0; i < this._body.children.length; i++) {
if (this._body.children[i]["npcType"] == type) {
this["npcType"] = type;
console.log(type);
this._body.children[i].visible = true;
this._body.children[i].mouseEnabled = false;
}
}
}
set anchorOffsetY(v) {
this._body.y = v;
}
}
import { getTextureByName } from "./utils";
import { props } from "../props";
import GameView from './GameView';
export class Zhuazi extends engine.Container {
private bashouGan: engine.Sprite;
private bashou: engine.Sprite;
private ganzi: engine.Sprite;
private left_zhuazi: engine.Sprite;
private right_zhuazi: engine.Sprite;
private connect: engine.Sprite;
private ganNode: engine.Container;
private moveNode: engine.Container;
private moveArr = [];
private zhuaziY;
private itemShow: engine.Container;
private prizeBoxs = [];
public GameView: GameView;
constructor() {
super();
}
setup() {
this.ganNode = new engine.Container();
this.moveNode = new engine.Container();
this.ganNode.x = 280;
this.ganNode.y = 350;
this.bashouGan = new engine.Sprite(getTextureByName("把手杆子"));
this.bashouGan.x = 60;
this.bashouGan.y = 12;
this.bashou = new engine.Sprite(getTextureByName("把手"));
this.bashou.x = 0;
this.bashou.y = 0;
this.ganzi = new engine.Sprite(getTextureByName("伸缩杆"));
this.ganzi.x = 97;
this.ganzi.y = 27;
this.connect = new engine.Sprite(getTextureByName("连接点"));
this.connect.x = 18;
this.connect.y = -5;
this.left_zhuazi = new engine.Sprite(getTextureByName("左爪"));
this.left_zhuazi.x = -15;
this.left_zhuazi.y = 60;
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
this.right_zhuazi = new engine.Sprite(getTextureByName("右爪"));
this.right_zhuazi.x = 98;
this.right_zhuazi.y = 60;
this.ganNode.addChild(this.left_zhuazi);
this.ganNode.addChild(this.right_zhuazi);
this.ganNode.addChild(this.connect);
this.ganNode.x = 30;
this.ganNode.y = this.ganNode.y - 263;
this.zhuaziY = this.ganNode.y;
this.moveNode.addChild(this.ganzi);
this.moveNode.addChild(this.ganNode);
this.moveNode.addChild(this.bashou);
this.moveNode.x = 262;
this.bashouGan.y = this.bashouGan.y;
this.moveNode.y = this.moveNode.y;
this.addChild(this.bashouGan);
this.addChild(this.moveNode);
if (!props.ganziShow) {
this.bashouGan.visible = false;
}
if (!props.bashouShow) {
this.bashou.visible = false;
}
this.createPrizeBox();
}
createPrizeBox() {
for (let i = 0; i < props.dollNum; i++) {
if (!new engine.Sprite(getTextureByName('prizebox_' + i))) {
return;
}
this.prizeBoxs[i] = new engine.Sprite(getTextureByName('prizebox_' + i));
this.prizeBoxs[i]['npcType'] = 'box' + i;
}
this.prizeBoxs[props.dollNum] = new engine.Sprite(getTextureByName('prizebox_0'));
this.prizeBoxs[props.dollNum]['npcType'] = 'box' + props.dollNum;
this.prizeBoxs.forEach(item => {
this.ganNode.addChild(item);
item.visible = false;
item.x = props.prizeBoxInitX;
item.y = props.prizeBoxInitY;
})
}
showPrizeBox() {
this.prizeBoxs.forEach(item => {
console.log(this.GameView.getBox()['npcType']);
if (item['npcType'] === this.GameView.getBox()['npcType']) {
item.visible = true;
this.itemShow = item;
} else {
item.visible = false;
}
})
}
move() {
let rndist = Math.random();
let halfWidth = this.bashou.width / 2;
let randomX = rndist * (rndist > 0.5 ? 1 : -1) * props.bashouMoveDist;
console.log(randomX);
engine.Tween.get(this.moveNode).to({ x: 370 + halfWidth - 71}, 1000).call(() => {
this.zhangkai();
});
}
zhangkai() {
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: props.leftRotation}, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: props.rightRotation }, 1000);
setTimeout(() => {
this.getLong();
}, 500);
}
getLong() {
let droptime = Number((this.GameView.getMoveX() / 60 - 1).toFixed(2)) * 1000;
console.log('dr', droptime);
let times = (props.ganMoveEndY - this.ganzi.y ) / this.ganzi.height;
console.log(Number(times.toFixed(2)) );
engine.Tween.get(this.ganzi).to({ scaleY: Number(times.toFixed(2)) }, droptime).to({ scaleY: 1 }, droptime)
console.log('node', this.zhuaziY);
engine.Tween.get(this.ganNode).to({ y: props.ganMoveEndY }, droptime).call(() => {
this.GameView.stopMove();
if (this.GameView.ifPrize) {
this.showPrizeBox();
this.GameView.setVisible(false);
}
}).to({ y: this.zhuaziY }, droptime).call(() => {
// this.getReset();
if (this.GameView.ifPrize) {
this.itemShow.visible = false;
}
engine.globalEvent.dispatchEvent('doll-machine2-game-end');
})
}
getReset() {
// if (this.GameView.ifPrize) {
// this.itemShow.visible = false;
// }
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.moveNode, {loop: false}).to({x: 262}, 1000);
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
this.GameView.resetMoveX();
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import { props } from "../props";
export class BackBoxs extends engine.Container {
private backBoxs=[];
constructor() {
super();
}
setup() {
let initX , initY = 0;
for (let i = 0; i < props.dollNum; i++) {
this.backBoxs[i] = new engine.Sprite(getTextureByName('backbox_' + i));
initX = this.backBoxs[0].x = props.backInitX;
initY = this.backBoxs[0].y = props.backInitY - props.initOffsetTop;
this.backBoxs[i]['npcType'] = 'box' + i;
}
this.backBoxs[props.dollNum] = new engine.Sprite(getTextureByName('backbox_0'));
this.backBoxs[props.dollNum]['npcType'] = 'box' + props.dollNum;
for (let i = 0; i < this.backBoxs.length; i++) {
if(i == 0) {
this.backBoxs[i].x = initX;
} else {
this.backBoxs[i].x = this.backBoxs[i - 1].x + this.backBoxs[i].width + props.backmargin;
}
this.backBoxs[i].y = initY;
this.addChild(this.backBoxs[i]);
}
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.backBoxs.forEach((item) => {
item.x -= props.moveSpeed;
if (item.x <= 0) {
let lastitem = this.backBoxs.shift();
lastitem.x = this.backBoxs[this.backBoxs.length - 1].x + item.width + props.backmargin;
this.backBoxs.push(lastitem);
}
})
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import GameView from './GameView';
import { props } from "../props";
export class FrontBoxs extends engine.Container {
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
// 需隐藏的盒子
private hideBox: engine.Container;
private frontBoxs=[];
public GameView: GameView;
constructor() {
super();
}
setup() {
let initX , initY = 0;
for(let i = 0; i < +props.dollNum+1; i++) {
if (!new engine.Sprite(getTextureByName('frontbox_' + i))) {
return;
}
this.frontBoxs[i] = new engine.Sprite(getTextureByName('frontbox_'+i));
initX = this.frontBoxs[0].x = props.frontInitX;
initY = this.frontBoxs[0].y = props.frontInitY;
this.frontBoxs[i]['npcType'] = 'box'+i;
}
// this.frontBoxs[props.dollNum] = new engine.Sprite(getTextureByName('frontbox_0'));
// this.frontBoxs[props.dollNum]['npcType'] = 'box' + props.dollNum;
for(let i = 0; i < this.frontBoxs.length; i++) {
if(i == 0) {
this.frontBoxs[i].x = initX ;
} else {
this.frontBoxs[i].x = this.frontBoxs[i - 1].x - this.frontBoxs[0].width - props.frontmargin;
}
console.log(this.frontBoxs[i].x);
this.frontBoxs[i].y = initY;
this.addChild(this.frontBoxs[i]);
console.log('aaa', this.frontBoxs[i].x);
}
// console.log(this.frontBoxs);
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.frontBoxs.forEach((item, index) => {
item.x += props.moveSpeed;
if(item.x <=0 && !item.visible) {
item.visible = true;
}
if(item.x >= 750) {
let lastitem = this.frontBoxs.shift();
lastitem.x = this.frontBoxs[this.frontBoxs.length - 1].x - this.frontBoxs[0].width - props.frontmargin;
if (!this.GameView.getMoveX() && item.x <= 0 && this.GameView.startstatus) {
this.GameView.setMoveX((370 - item.x - 13) / props.moveSpeed, item);
this.hideBox = item;
}
this.frontBoxs.push(lastitem);
}
})
}
stop() {
// this.removeEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
showHidePrizeBox(isshow) {
this.hideBox.visible = isshow
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = "open-gift";
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>拆礼盒</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global['open-gift'] = factory(global.tslib));
}(this, (function (tslib) { 'use strict';
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
function createSvga(name, anchorName) {
var inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
//# sourceMappingURL=utils.js.map
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
function GameView() {
var _this = _super.call(this) || this;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
GameView.prototype.setup = function () {
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this.NpcBg = new engine.Container();
this.NpcBg.x = props.initX;
this.NpcBg.y = props.initY;
this.addChild(this.NpcBg);
this.bottomCircle = new engine.Sprite(getTextureByName('底座'));
this.bottomCircle.x = 17;
this.bottomCircle.y = 305;
this.loveDot = new engine.Sprite(getTextureByName('点缀'));
this.loveDot.x = 0;
this.loveDot.y = 6;
this.giftboxSvga = createSvga('初始礼盒');
this.giftboxSvga.x = 105;
this.giftboxSvga.y = 37;
this.giftAfterSvga = createSvga("拆礼盒");
this.giftAfterSvga.x = 105;
this.giftAfterSvga.y = 0;
this.giftAfterSvga.visible = false;
this.NpcBg.addChild(this.bottomCircle);
this.NpcBg.addChild(this.giftboxSvga);
this.NpcBg.addChild(this.giftAfterSvga);
this.NpcBg.addChild(this.loveDot);
this.giftboxSvga.play(false, true);
};
GameView.prototype.reset = function () {
this.giftboxSvga.visible = true;
this.giftAfterSvga.visible = false;
};
GameView.prototype.start = function () {
this.giftAfterSvga.visible = true;
this.giftboxSvga.visible = false;
this.giftAfterSvga.play(false, false);
this.giftAfterSvga.once(engine.Event.END_FRAME, function () {
engine.globalEvent.dispatchEvent('open-gift-game-end');
}, this);
};
GameView.prototype.resume = function () {
this.reset();
this.start();
};
return GameView;
}(engine.Container));
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
function GameWrapper() {
var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('open-gift-game-init', _this.reset, _this);
engine.globalEvent.addEventListener('open-gift-game-start', _this.start, _this);
var gameView = _this._gameView = new GameView();
_this.addChild(gameView);
return _this;
}
GameWrapper.prototype.reset = function (event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
};
GameWrapper.prototype.start = function (event) {
console.log('监听开始');
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.clear = function () {
this._gameView.visible = false;
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
injectProps(props);
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
})));
//# sourceMappingURL=main.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sources":["src/custom/open-gift/src/props.ts","src/custom/open-gift/src/game/utils.ts","src/custom/open-gift/src/game/GameView.ts","src/custom/open-gift/src/game/GameWrapper.ts","src/custom/open-gift/src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport let props: any = {};\n\nexport function prepareProps() {\n\tlet metaProps = getProps();\n\n\tengine.injectProp(props, metaProps);\n}\n\nexport function injectProps(p) {\n\tengine.injectProp(props, p);\n}\n","/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport function getTexture(uuid) {\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\n}\n\nexport function getTextureByName(name) {\n\treturn getTexture(engine.getAssetByName(name).uuid);\n}\n\nexport function playSound(name) {\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\n}\nexport function createSvga(name, anchorName?) {\n\tlet inst = new svga.Svga();\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\treturn inst;\n}","/**\n * Created by rockyl on 2018/8/16.\n */\n\nimport { props } from \"../props\";\nimport ObjectPool = engine.ObjectPool;\nimport { getTextureByName, createSvga } from \"./utils\";\n\nexport default class GameView extends engine.Container {\n private _hasSetup;\n \n //npc层\n private NpcBg: engine.Container;\n //底座\n private bottomCircle: engine.Container;\n //爱心点缀\n private loveDot: engine.Container;\n //礼盒\n private giftboxSvga;\n //礼盒前动画\n private giftAfterSvga\n \n\tprivate rect;\n\n constructor() {\n super();\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\n }\n\n setup() {\n if (this._hasSetup) {\n return;\n }\n\n this._hasSetup = true;\n\n this.NpcBg = new engine.Container();\n this.NpcBg.x = props.initX;\n this.NpcBg.y = props.initY;\n this.addChild(this.NpcBg);\n this.bottomCircle = new engine.Sprite(getTextureByName('底座'));\n this.bottomCircle.x = 17;\n this.bottomCircle.y = 305;\n this.loveDot = new engine.Sprite(getTextureByName('点缀'));\n this.loveDot.x = 0;\n this.loveDot.y = 6;\n\n this.giftboxSvga = createSvga('初始礼盒');\n this.giftboxSvga.x = 105;\n this.giftboxSvga.y = 37;\n this.giftAfterSvga = createSvga(\"拆礼盒\");\n this.giftAfterSvga.x = 105;\n this.giftAfterSvga.y = 0;\n this.giftAfterSvga.visible = false;\n this.NpcBg.addChild(this.bottomCircle);\n this.NpcBg.addChild(this.giftboxSvga);\n this.NpcBg.addChild(this.giftAfterSvga);\n this.NpcBg.addChild(this.loveDot);\n this.giftboxSvga.play(false, true)\n\t\t// this.rect = new engine.Rect();\n // this.rect.width = props.gameStageWidth;\n // this.rect.height = props.gameStageHeight;\n\t\t// this.rect.x = 0;\n\t\t// this.rect.y = 0;\n\t\t// this.addChild(this.rect);\n\n // this.NpcBg.mask = this.rect;\n\t}\n /**\n * 重置场景\n */\n reset() {\n this.giftboxSvga.visible = true;\n this.giftAfterSvga.visible = false;\n }\n\n /**\n * 开始\n */\n start() {\n this.giftAfterSvga.visible = true;\n this.giftboxSvga.visible = false;\n this.giftAfterSvga.play(false, false)\n this.giftAfterSvga.once(engine.Event.END_FRAME, () => {\n engine.globalEvent.dispatchEvent('open-gift-game-end');\n }, this);\n }\n\n /**\n * 重新开始\n */\n resume() {\n this.reset();\n this.start();\n }\n}\n","/**\n * Created by rockyl on 2020-01-09.\n */\n\nimport GameView from \"./GameView\";\nimport {injectProps} from \"../props\";\n\n\nexport class GameWrapper extends engine.Container {\n\tprivate _status;\n\tprivate _gameView: GameView;\n\n\n\n\n\n\tconstructor() {\n\t\tsuper();\n\t\tengine.globalEvent.addEventListener('open-gift-game-init', this.reset, this);\n\t\tengine.globalEvent.addEventListener('open-gift-game-start', this.start, this);\n\n\t\tlet gameView = this._gameView = new GameView();\n\t\tthis.addChild(gameView);\n\t\t// gameView.reset();\n\t\t// gameView.start()\n\t}\n\n\treset(event: engine.Event) {\t\t\n\t\tinjectProps(event.data);\n\t\tthis._gameView.visible = true;\n\t\tthis._gameView.reset();\n\t}\n\n\tstart(event: engine.Event) {\n\t\tconsole.log('监听开始');\n\t\tinjectProps(event.data);\n\t\t// this._status = 1;\n\t\tthis._gameView.start();\n\t}\n\n\tclear() {\n\t\tthis._gameView.visible = false;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-20.\n */\n\nimport {GameWrapper} from \"./game/GameWrapper\";\nimport {injectProps, prepareProps} from \"./props\";\n\nexport default function (props) {\n\tprepareProps();\n\tinjectProps(props);\n\n\tlet instance = new GameWrapper();\n\treturn instance;\n}\n"],"names":["__extends"],"mappings":"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"}
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "拆礼盒",
"desc": "拆礼盒模块",
"props": {
"initX": {
"alias": "游戏场景初始X位置",
"type": "number",
"default": 0
},
"initY": {
"alias": "游戏场景初始Y位置",
"type": "number",
"default": 0
},
"gameStageWidth": {
"alias": "游戏场景宽度",
"type": "number",
"default": 534
},
"gameStageHeight": {
"alias": "游戏场景高度",
"type": "number",
"default": 408
}
},
"assets": [
{
"name": "底座",
"url": "//yun.duiba.com.cn/aurora/assets/d6ed718f0d236febaa4d1331950e5a190f225cb5.png",
"uuid": "7a0f8b48-449c-46d9-bd80-64455a30e641",
"ext": ".png"
},
{
"name": "点缀",
"url": "//yun.duiba.com.cn/aurora/assets/e08f680bbd26c4dcc47fd67ee2e145c46d6fcd1a.png",
"uuid": "c7426dc4-d631-4947-accc-015666277208",
"ext": ".png"
},
{
"name": "初始礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/b9bb4e52c3734025fc96a92cb574c92209927b61.svga",
"uuid": "947cb448-1992-49f1-a9ed-e359b944953a",
"ext": ".svga"
},
{
"name": "拆礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/8e86f8696710de414f0f36dc330db6e4bd0683d6.svga",
"uuid": "d9222991-064c-4816-85ee-6964ba78fbd0",
"ext": ".svga"
}
],
"events": {
"in": {
"open-gift-game-init": {
"alias": "重置"
},
"open-gift-game-start": {
"alias": "开始",
"data": {
"prize": true
}
}
},
"out": {
"open-gift-game-end": {
"alias": "动画完毕",
"data": null
}
}
}
}
/**
* Created by rockyl on 2018/8/16.
*/
import { props } from "../props";
import ObjectPool = engine.ObjectPool;
import { getTextureByName, createSvga } from "./utils";
export default class GameView extends engine.Container {
private _hasSetup;
//npc层
private NpcBg: engine.Container;
//底座
private bottomCircle: engine.Container;
//爱心点缀
private loveDot: engine.Container;
//礼盒
private giftboxSvga;
//礼盒前动画
private giftAfterSvga
private rect;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
setup() {
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this.NpcBg = new engine.Container();
this.NpcBg.x = props.initX;
this.NpcBg.y = props.initY;
this.addChild(this.NpcBg);
this.bottomCircle = new engine.Sprite(getTextureByName('底座'));
this.bottomCircle.x = 17;
this.bottomCircle.y = 305;
this.loveDot = new engine.Sprite(getTextureByName('点缀'));
this.loveDot.x = 0;
this.loveDot.y = 6;
this.giftboxSvga = createSvga('初始礼盒');
this.giftboxSvga.x = 105;
this.giftboxSvga.y = 37;
this.giftAfterSvga = createSvga("拆礼盒");
this.giftAfterSvga.x = 105;
this.giftAfterSvga.y = 0;
this.giftAfterSvga.visible = false;
this.NpcBg.addChild(this.bottomCircle);
this.NpcBg.addChild(this.giftboxSvga);
this.NpcBg.addChild(this.giftAfterSvga);
this.NpcBg.addChild(this.loveDot);
this.giftboxSvga.play(false, true)
// this.rect = new engine.Rect();
// this.rect.width = props.gameStageWidth;
// this.rect.height = props.gameStageHeight;
// this.rect.x = 0;
// this.rect.y = 0;
// this.addChild(this.rect);
// this.NpcBg.mask = this.rect;
}
/**
* 重置场景
*/
reset() {
this.giftboxSvga.visible = true;
this.giftAfterSvga.visible = false;
}
/**
* 开始
*/
start() {
this.giftAfterSvga.visible = true;
this.giftboxSvga.visible = false;
this.giftAfterSvga.play(false, false)
this.giftAfterSvga.once(engine.Event.END_FRAME, () => {
engine.globalEvent.dispatchEvent('open-gift-game-end');
}, this);
}
/**
* 重新开始
*/
resume() {
this.reset();
this.start();
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('open-gift-game-init', this.reset, this);
engine.globalEvent.addEventListener('open-gift-game-start', this.start, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
// gameView.reset();
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
console.log('监听开始');
injectProps(event.data);
// this._status = 1;
this._gameView.start();
}
clear() {
this._gameView.visible = false;
}
}
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
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