Commit c7d2c572 authored by 王炽's avatar 王炽

66666666

parent 91229572
No preview for this file type
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'rockji';
(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,
}
}],
customs: []
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
engine.globalEvent.dispatchEvent('rock-info', {prizes:[
{
"icon":"//yun.duiba.com.cn/aurora/assets/88d89ba9c3ddac732f2e017023a216be915655e4.png",
"id":"o58df634f",
"index":1,
"name":"一等奖",
"prizeId":"sss_3",
"prizeType":2,
"refId":"49781",
"refType":"virtual"
},
{
"icon":"//yun.duiba.com.cn/aurora/assets/1c0e0fcb192b2e0772bd555c3aae1c86621ccb09.png",
"id":"o4a578392",
"index":2,
"name":"二等奖",
"prizeId":"sss_2",
"prizeType":2,
"refId":"49780",
"refType":"virtual"
},
{
"icon":"//yun.duiba.com.cn/aurora/assets/bc23cd948cdd20467af9abc1f65e08e4f1e9bf30.png",
"id":"o26efbbeb",
"index":3,
"name":"三等奖",
"prizeId":"sss_1",
"prizeType":2,
"refId":"49779",
"refType":"virtual"
}]
});
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('rock-start',{
prizeId:"sss_3"
});
}, 5000);
});
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: white;
}
.game-container{
width: 100%;
height: 100%;
line-height:0;
font-size:0;
}
</style>
</head>
<body>
<div id="game-container" class="game-container"></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/engine.fbc60c6d3cb30e5ab97e82d392d9efeee91b8581.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": "雨滴0",
"url": "//yun.duiba.com.cn/aurora/assets/badb3627bbcc75276a3eed53daa8b0a454ced6eb.png",
"uuid": "d3ce99da-89e1-447d-8c52-b3f391925c3c",
"ext": ".png"
},
{
"name": "雨滴1",
"url": "//yun.duiba.com.cn/aurora/assets/5cc0092913c571eeb52317b8e1e0dc715793049c.png",
"uuid": "02f17008-1d8d-4108-a0fc-03fbc71fd118",
"ext": ".png"
},
{
"name": "雨滴2",
"url": "//yun.duiba.com.cn/aurora/assets/4b938949b85d50b36ef0f66450643495efbf7580.png",
"uuid": "46aa4f8a-9a6c-4210-8ffd-92da0dd3bc75",
"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/11b1f49fa3afa3a48f1dd3e3c1eb294e3fa9d886.svga",
"uuid": "cdd2268f-ad65-4b5e-a965-ee61b730da21",
"ext": ".svga"
},
{
"name": "石头svga",
"url": "//yun.duiba.com.cn/aurora/assets/01aa6fcb33aa8231f075257026eab2f0aeb3c27a.svga",
"uuid": "846a139d-0990-4db4-a323-f22379932ee4",
"ext": ".svga"
},
{
"name": "炸弹svga",
"url": "//yun.duiba.com.cn/aurora/assets/3b58e7ace031b09c651cf8e7202f9c86e86852c9.svga",
"uuid": "d7a3947b-7fcb-48f2-9ddf-2f075d37a619",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/db0130d36ef79865be9c753ea0627027f16341d8.png",
"uuid": "4931d296-4421-4a2f-8299-7bab87407c72",
"ext": ".png"
}
];
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.rockji = 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
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);
_this.prizeId = props.prizeId;
_this.prizes = props.prizes;
_this.countdown = 150;
_this.timeSpace = 500;
return _this;
}
GameView.prototype.setup = function () {
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this.itemInfo = {};
this.mainContainer = new engine.Container();
this.viewContainer = new engine.Container();
this.addChild(this.viewContainer);
this.viewContainer.width = props.viewWidth;
this.viewContainer.height = props.viewHeight;
this.bgImg = new engine.Image();
this.bgImg.source = getAssetByName("rock-背景").url;
this.viewContainer.addChild(this.bgImg);
this.container0 = new engine.Container();
this.container1 = new engine.Container();
this.container2 = new engine.Container();
this.mainContainer.addChild(this.container0);
this.mainContainer.addChild(this.container1);
this.mainContainer.addChild(this.container2);
this.viewContainer.addChild(this.mainContainer);
this.mainContainer.x = props.cOriginSizeX;
this.mainContainer.y = props.cOriginSizeY;
var mask = new engine.Rect();
mask.x = props.cOriginSizeX;
mask.y = props.cOriginSizeY;
mask.fillColor = 0xffff00;
mask.width = props.maskSizeW;
mask.height = props.maskSizeH;
this.addChild(mask);
this.mainContainer.mask = mask;
if (this.prizes.length > 3) {
this.createItem(2);
this.prizeMaxH = this.prizes.length * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;
}
else {
this.createItem(1);
this.prizeMaxH = 4 * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;
}
this.orgY = -(this.prizeMaxH - props.maskSizeH) + props.imgSizeH * 0.5;
for (var i = 0; i < 3; i++) {
this['container' + i].x = i * (props.cSpaceSizeX * 2 + props.imgSizeW);
this['container' + i].y = this.orgY;
}
};
GameView.prototype.createItem = function (type) {
var len = 4;
if (type == 1) {
len = 4;
}
else if (type == 2) {
len = this.prizes.length;
}
for (var j = 0; j < 3; j++) {
this.itemInfo["items" + j] = [];
for (var i = 0; i < len; i++) {
var url = this.prizes[i % this.prizes.length].icon;
var item = new engine.Image();
item.source = url;
this.itemInfo["items" + j][i] = item;
this["container" + j].addChild(item);
item.width = props.imgSizeW;
item.height = props.imgSizeH;
item.x = props.spaceSizeX;
item.y = props.spaceSizeY + i * (props.imgSizeH + props.spaceSizeY);
console.log('i=', i);
}
}
};
GameView.prototype.reset = function () {
for (var i = 0; i < 3; i++) {
this["container" + i].y = this.orgY;
}
};
GameView.prototype.start = function () {
var _this = this;
this.prizeId = props.prizeId;
var _loop_1 = function (i) {
engine.Tween.removeTweens(this_1["container" + i]);
setTimeout(function () {
engine.Tween.get(_this["container" + i], { loop: true }).to({ y: 0 }, _this.countdown).call(function () {
_this["container" + i].y = _this.orgY;
});
}, this_1.timeSpace * i);
};
var this_1 = this;
for (var i = 0; i < 3; i++) {
_loop_1(i);
}
setTimeout(function () {
var _loop_2 = function (i) {
setTimeout(function () {
_this["container" + i].y = _this.orgY;
engine.Tween.removeTweens(_this["container" + i]);
engine.Tween.get(_this["container" + i]).to({ y: -(props.imgSizeH * 0.5 + props.spaceSizeY) }, 1500);
}, _this.timeSpace * i);
};
for (var i = 0; i < 3; i++) {
_loop_2(i);
}
_this.setPrizePos();
setTimeout(function () {
engine.globalEvent.dispatchEvent('rock-gameover');
}, _this.timeSpace * 2 + 2000);
}, 2500);
};
GameView.prototype.setPrizePos = function () {
var direct = Math.random() > 0.5 ? 1 : -1;
for (var j = 0; j < 3; j++) {
var len = this.itemInfo["items" + j].length;
direct *= -1;
for (var i = 0; i < len; i++) {
var plen = this.prizes.length;
if (direct > 0) {
this.itemInfo["items" + j][i].source = this.prizes[(plen - 1) - (i % plen)].icon;
}
else {
this.itemInfo["items" + j][i].source = this.prizes[(i % plen)].icon;
}
}
}
for (var i = 0; i < 3; i++) {
this.itemInfo["items" + i][1].source = this.getPrizeUrl(this.prizeId);
}
};
GameView.prototype.getPrizeUrl = function (pid) {
var purl = "";
for (var i = 0; i < 3; i++) {
if (this.prizes[i].prizeId == pid) {
return this.prizes[i].icon;
}
}
return purl;
};
GameView.prototype.pause = function () {
};
GameView.prototype.revive = function () {
};
GameView.prototype.resume = function () {
};
GameView.prototype.died = function () {
this.pause();
};
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
function GameWrapper() {
var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('rock-reset', _this.reset, _this);
engine.globalEvent.addEventListener('rock-start', _this.start, _this);
engine.globalEvent.addEventListener('rock-info', _this.rinfo, _this);
return _this;
}
GameWrapper.prototype.reset = function (event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
};
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._status = 1;
this._gameView.start();
};
GameWrapper.prototype.rinfo = function (event) {
injectProps(event.data);
console.log("event=", event);
console.log("event.data = ", event.data);
var gameView = this._gameView = new GameView();
this.addChild(gameView);
};
GameWrapper.prototype.pause = function () {
this._gameView.pause();
};
GameWrapper.prototype.resume = function () {
this._gameView.resume();
};
GameWrapper.prototype.revive = function () {
this._gameView.revive();
};
GameWrapper.prototype.clear = function () {
this._gameView.visible = false;
};
GameWrapper.prototype.onTap = function (event) {
};
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
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "摇奖机",
"desc": "摇奖机",
"props": {
"imgSizeW": {
"alias": "奖品图片宽",
"type": "number",
"default": 99
},
"imgSizeH": {
"alias": "奖品图片高",
"type": "number",
"default": 99
},
"spaceSizeX": {
"alias": "奖品横向间隙",
"type": "number",
"default": 20
},
"spaceSizeY": {
"alias": "奖品纵向间隙",
"type": "number",
"default": 20
},
"cOriginSizeX": {
"alias": "遮罩左边顶点坐标",
"type": "number",
"default": 22
},
"cOriginSizeY": {
"alias": "遮罩左边顶点坐标",
"type": "number",
"default": 19
},
"cSpaceSizeX": {
"alias": "每列奖品容器的横向间隙",
"type": "number",
"default": 23
},
"maskSizeW": {
"alias": "遮罩宽",
"type": "number",
"default": 428
},
"maskSizeH": {
"alias": "遮罩高",
"type": "number",
"default": 221
},
"viewWidth": {
"alias": "模块宽",
"type": "number",
"default": 472
},
"viewHeight": {
"alias": "模块高",
"type": "number",
"default": 256
}
},
"assets": [
{
"name": "rock-背景",
"url": "//yun.duiba.com.cn/aurora/assets/877058dcced99e42ddd2ccf19c2bce189fa45d5c.png",
"uuid": "7baa74f5-e057-4fd3-846f-f58ff7a92c3d",
"ext": ".png"
}
],
"events": {
"in": {
"rock-info": {
"alias": "初始化进入页面调用",
"data": [{
"icon":"//yun.duiba.com.cn/aurora/assets/88d89ba9c3ddac732f2e017023a216be915655e4.png",
"id":"o58df634f",
"index":1,
"name":"一等奖",
"prizeId":"sss_3",
"prizeType":2,
"refId":"49781",
"refType":"virtual"
},
{
"icon":"//yun.duiba.com.cn/aurora/assets/1c0e0fcb192b2e0772bd555c3aae1c86621ccb09.png",
"id":"o4a578392",
"index":2,
"name":"二等奖",
"prizeId":"sss_2",
"prizeType":2,
"refId":"49780",
"refType":"virtual"
},
{
"icon":"//yun.duiba.com.cn/aurora/assets/bc23cd948cdd20467af9abc1f65e08e4f1e9bf30.png",
"id":"o26efbbeb",
"index":3,
"name":"三等奖",
"prizeId":"sss_1",
"prizeType":2,
"refId":"49779",
"refType":"virtual"
}]
},
"rock-start": {
"alias": "开始摇奖,透传中奖id",
"data":{
"prizeId":"sss_3"
}
},
"rock-reset": {
"alias": "关闭中奖弹窗时调用"
}
},
"out": {
"rock-gameover": {
"alias": "摇奖机停止是派发"
}
}
}
}
\ No newline at end of file
/**
* 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";
export default class GameView extends engine.Container {
private _hasSetup;
//玩家
private player: engine.Container;
//触摸层
// private rectBg: engine.Rect;
private rectBg: engine.Container;
//npc层
private NpcBg: engine.Container;
//倒计时
private countdown: number;
//每列滚动时间间隔
private timeSpace: number;
private prizes;
private bgImg:engine.Image;
private bgImgUrl:string;
private itemInfo:any;
private prizeMaxH:number;
private orgY:number;
private prizeId:string;
private container0:engine.Container;
private container1:engine.Container;
private container2:engine.Container;
private mainContainer:engine.Container;
private viewContainer:engine.Container;
private configInfo:any;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
// this.configInfo = {
// prizes:[
// {type:0, url:'//yun.duiba.com.cn/aurora/assets/88d89ba9c3ddac732f2e017023a216be915655e4.png'},
// {type:1, url:'//yun.duiba.com.cn/aurora/assets/1c0e0fcb192b2e0772bd555c3aae1c86621ccb09.png'},
// {type:2, url:'//yun.duiba.com.cn/aurora/assets/bc23cd948cdd20467af9abc1f65e08e4f1e9bf30.png'}
// ],//奖品链接列表
// bgImgUrl:'//yun.duiba.com.cn/aurora/assets/877058dcced99e42ddd2ccf19c2bce189fa45d5c.png',
// imgSize:{w:99,h:103},//奖品尺寸
// spaceSize:{x:20, y:20},//奖品横向和纵向间隙
// cOriginSize:{x:22, y:19},//遮罩左边定点位置
// cSpaceSize:{x:23, y:0},//每列奖品的间隙
// }
// this.bgImgUrl = '//yun.duiba.com.cn/aurora/assets/877058dcced99e42ddd2ccf19c2bce189fa45d5c.png';
// this.maskSize = {w:428, h:221};
// this.imgSize = {w:99,h:103};
// this.spaceSize = {x:20, y:20};
// // this.originSize = {x:0, y:0}
// this.cOriginSize = {x:22, y:19};//遮罩的初始坐标
// this.cSpaceSize = {x:23, y:0};//奖品容器横向纵向的边距
// this.prizes = [
// {
// "icon":"//yun.duiba.com.cn/aurora/assets/88d89ba9c3ddac732f2e017023a216be915655e4.png",
// "id":"o58df634f",
// "index":1,
// "name":"一等奖",
// "prizeId":"sss_3",
// "prizeType":2,
// "refId":"49781",
// "refType":"virtual"
// },
// {
// "icon":"//yun.duiba.com.cn/aurora/assets/1c0e0fcb192b2e0772bd555c3aae1c86621ccb09.png",
// "id":"o4a578392",
// "index":2,
// "name":"二等奖",
// "prizeId":"sss_2",
// "prizeType":2,
// "refId":"49780",
// "refType":"virtual"
// },
// {
// "icon":"//yun.duiba.com.cn/aurora/assets/bc23cd948cdd20467af9abc1f65e08e4f1e9bf30.png",
// "id":"o26efbbeb",
// "index":3,
// "name":"三等奖",
// "prizeId":"sss_1",
// "prizeType":2,
// "refId":"49779",
// "refType":"virtual"
// }];
this.prizeId = props.prizeId;
this.prizes = props.prizes;
this.countdown = 150;
this.timeSpace = 500;
}
private waterSvga
private stoneSvga
private boomSvga
private playerSvga
setup() {
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this.itemInfo = {};
// this.bgImg = new engine.Image();
// this.bgImg.source = this.bgImgUrl;
this.mainContainer = new engine.Container();
this.viewContainer = new engine.Container();
this.addChild(this.viewContainer);
this.viewContainer.width = props.viewWidth;
this.viewContainer.height = props.viewHeight;
// this.bgImg = new engine.Sprite(getTextureByName('rock-背景'));
this.bgImg = new engine.Image();
this.bgImg.source = getAssetByName("rock-背景").url;
this.viewContainer.addChild(this.bgImg);
this.container0 = new engine.Container();
this.container1 = new engine.Container();
this.container2 = new engine.Container();
this.mainContainer.addChild(this.container0);
this.mainContainer.addChild(this.container1);
this.mainContainer.addChild(this.container2);
this.viewContainer.addChild(this.mainContainer);
this.mainContainer.x = props.cOriginSizeX;
this.mainContainer.y = props.cOriginSizeY;
let mask = new engine.Rect();
mask.x = props.cOriginSizeX;
mask.y = props.cOriginSizeY;
mask.fillColor = 0xffff00;
mask.width = props.maskSizeW;
mask.height = props.maskSizeH;
this.addChild(mask);
this.mainContainer.mask = mask;
// this.container0.width = 140;
// this.container0.height = 221;
// this.container1.width = 140()
// this.container1.height = 221;
// this.container2.width = 140;
// this.container2.height = 221;
if(this.prizes.length > 3){
this.createItem(2);
this.prizeMaxH = this.prizes.length * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;
}else{
this.createItem(1);
this.prizeMaxH = 4 * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;
}
this.orgY = -(this.prizeMaxH - props.maskSizeH) + props.imgSizeH * 0.5;
for(let i = 0; i < 3; i++){
this['container' + i].x = i * (props.cSpaceSizeX * 2 + props.imgSizeW);
// this['container' + i].y = this.orgY;
this['container' + i].y = this.orgY;
}
//mask 438 221
}
/**
* type 1.小于4个奖品 2.4个及以上奖品
*/
private createItem(type:number):void{
let len = 4;
if(type == 1){
len = 4;
}else if(type == 2){
len = this.prizes.length;
}
for(let j = 0; j < 3; j++){
this.itemInfo["items" + j] = [];
for(let i = 0; i < len; i++){
let url = this.prizes[i % this.prizes.length].icon;
let item = new engine.Image();
item.source = url;
this.itemInfo["items" + j][i] = item;
this["container" + j].addChild(item);
item.width = props.imgSizeW;
item.height = props.imgSizeH;
item.x = props.spaceSizeX;
item.y = props.spaceSizeY + i * (props.imgSizeH + props.spaceSizeY);
console.log('i=', i)
}
}
}
/**
* 重置场景
*/
reset() {
for(let i = 0; i < 3; i++){
this["container" + i].y = this.orgY;
}
}
/**
* 开始
*/
start() {
this.prizeId = props.prizeId;
for(let i = 0; i < 3; i++){
engine.Tween.removeTweens(this["container" + i]);
setTimeout(() => {
engine.Tween.get(this["container" + i],{loop:true}).to({y:0}, this.countdown).call(()=>{
this["container" + i].y = this.orgY;
});
}, this.timeSpace * i);
}
setTimeout(() => {
for(let i = 0; i < 3; i++){
// this["container" + i].y = 0;//this.orgY;
setTimeout(() => {
this["container" + i].y = this.orgY;
engine.Tween.removeTweens(this["container" + i]);
engine.Tween.get(this["container" + i]).to({y:-(props.imgSizeH * 0.5 + props.spaceSizeY)}, 1500);
}, this.timeSpace * i);
}
this.setPrizePos();
setTimeout(() => {
engine.globalEvent.dispatchEvent('rock-gameover');
}, this.timeSpace * 2 + 2000);
}, 2500);
}
private setPrizePos():void{
let direct = Math.random() > 0.5 ? 1 : -1;
for(let j = 0; j < 3; j++){
let len = this.itemInfo["items" + j].length;
direct *= -1;
for(let i = 0; i < len; i++){
let plen = this.prizes.length;
if(direct > 0){
this.itemInfo["items" + j][i].source = this.prizes[(plen - 1) - (i % plen)].icon;
}else{
this.itemInfo["items" + j][i].source = this.prizes[(i % plen)].icon;
}
}
}
for(let i = 0; i < 3; i++){
// this.prizeId = "sss_3";
this.itemInfo["items" + i][1].source = this.getPrizeUrl(this.prizeId);
}
}
private getPrizeUrl(pid:string):string{
let purl = "";
for(let i = 0; i < 3; i++){
if(this.prizes[i].prizeId == pid){
return this.prizes[i].icon;
}
}
return purl;
}
/**
* 暂停
*/
pause() {
}
/**
* 恢复
*/
revive() {
}
/**
* 重新开始
*/
resume() {
// this.reset()
// this.start()
}
/**
* 玩家死亡
*/
private died() {
this.pause()
}
}
/**
* 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('rock-reset', this.reset, this);
engine.globalEvent.addEventListener('rock-start', this.start, this);
engine.globalEvent.addEventListener('rock-info', this.rinfo, this);
// this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this);
// gameView.reset()
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
injectProps(event.data);
this._status = 1;
this._gameView.start();
}
private rinfo(event: engine.Event):void{
injectProps(event.data);
console.log("event=",event)
console.log("event.data = ",event.data);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
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 randomNum = Math.floor(Math.random() * 3)
// console.log('雨滴' + randomNum);
let rain = new engine.Sprite(getTextureByName('雨滴0'));
let rain1 = new engine.Sprite(getTextureByName('雨滴1'));
let rain2 = new engine.Sprite(getTextureByName('雨滴2'));
rain["npcType"]="rain0"
rain1["npcType"]="rain1"
rain2["npcType"]="rain2"
let stone = new engine.Sprite(getTextureByName('石块'));
stone["npcType"]="stone"
let boom = new engine.Sprite(getTextureByName('炸弹'));
boom["npcType"]="boom"
rain.visible=false;
rain1.visible=false;
rain2.visible=false;
stone.visible=false;
boom.visible=false;
body.addChild(rain)
body.addChild(rain1)
body.addChild(rain2)
body.addChild(stone)
body.addChild(boom)
this.addChild(body);
body.width=.0001;
body.height=.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(typeof (props.goodsProbability) == 'string'){
props.goodsProbability=props.goodsProbability.split(',').map((i: string) => +i)
console.log(props.goodsProbability);
}
if(random<props.goodsProbability[0]){
let randomNum = Math.floor(Math.random() * 3)
this.showNpc("rain" + randomNum)
}else if(random>=props.goodsProbability[0]&&random<=(props.goodsProbability[0]+props.goodsProbability[1])){
this.showNpc("stone")
}else if(random>(props.goodsProbability[0]+props.goodsProbability[1])){
this.showNpc("boom")
}
}
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
this._body.children[i].visible=true;
this._body.children[i].mouseEnabled=false;
}
}
}
set anchorOffsetY(v) {
this._body.y = v;
}
}
/**
* 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 engine.Texture.from(getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + 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);
}
...@@ -313,8 +313,8 @@ rollup-plugin-commonjs@^10.1.0: ...@@ -313,8 +313,8 @@ rollup-plugin-commonjs@^10.1.0:
rollup-plugin-node-resolve@^5.2.0: rollup-plugin-node-resolve@^5.2.0:
version "5.2.0" version "5.2.0"
resolved "https://registry.npm.taobao.org/rollup-plugin-node-resolve/download/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523" resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523"
integrity sha1-cw+T0Q7SAkc7H7VKWZen24xthSM= integrity sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==
dependencies: dependencies:
"@types/resolve" "0.0.8" "@types/resolve" "0.0.8"
builtin-modules "^3.1.0" builtin-modules "^3.1.0"
......
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