Commit 26cfedda authored by zjz1994's avatar zjz1994

发布暂存

parent e0f02468
This source diff could not be displayed because it is too large. You can view the blob instead.
(function (global, factory) { "use strict";var tslib=require("tslib"),props={};function prepareProps(){var e=getProps();engine.injectProp(props,e)}function injectProps(e){engine.injectProp(props,e)}function getTexture(e){return engine.Texture.from(getAssetByUUID(e).uuid)}function getTextureByName(e){return getTexture(engine.getAssetByName(e).uuid)}function createSvga(e,t){var o=new svga.Svga;return o.source="asset://"+engine.getAssetByName(e).uuid,o}var Goods=function(s){function e(){var e,t=s.call(this)||this;e=t._body=new engine.Rect;var o=new engine.Sprite(getTextureByName("雨滴"));o.npcType="rain";var n=new engine.Sprite(getTextureByName("石块"));n.npcType="stone";var i=new engine.Sprite(getTextureByName("炸弹"));return i.npcType="boom",o.visible=!1,n.visible=!1,i.visible=!1,e.addChild(o),e.addChild(n),e.addChild(i),t.addChild(e),e.width=1e-4,e.height=1e-4,e.mouseEnabled=!1,t}return tslib.__extends(e,s),e.prototype.getRandomNumberByRange=function(e,t){return Math.floor(Math.random()*(t-e)+e)},e.prototype.reset=function(){this.visible=!0,this.rotation=0,this.anchorOffsetY=0,this.y=0,this.x=630*Math.random()+30,this.rotation=0;var e=Math.random();e<props.goodsProbability[0]?this.showNpc("rain"):e>=props.goodsProbability[0]&&e<=props.goodsProbability[0]+props.goodsProbability[1]?this.showNpc("stone"):e>props.goodsProbability[0]+props.goodsProbability[1]&&this.showNpc("boom")},e.prototype.showNpc=function(e){for(var t=0;t<this._body.children.length;t++)this._body.children[t].visible=!1,this._body.children[t].mouseEnabled=!1;for(t=0;t<this._body.children.length;t++)this._body.children[t].npcType==e&&(this.npcType=e,this._body.children[t].visible=!0,this._body.children[t].mouseEnabled=!1)},Object.defineProperty(e.prototype,"anchorOffsetY",{set:function(e){this._body.y=e},enumerable:!0,configurable:!0}),e}(engine.Container),ObjectPool=engine.ObjectPool,PoolName="goods";ObjectPool.registerPool(PoolName,function(){return new Goods},function(e,t){e.reset()});var ObjectPool$1=engine.ObjectPool,GameView=function(e){function t(){var t=e.call(this)||this;return t.goodsItems=[],t.moveCatchX=0,t.playerCatchX=0,t.onDownStage=function(e){t.moveCatchX=e.localX,t.playerCatchX=t.player.x},t.onMoveStage=function(e){t.gameIng&&(t.player.x=t.playerCatchX+(e.localX-t.moveCatchX))},t.onOutStage=function(e){t.moveCatchX=0},t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.setup=function(){var e=this;this._hasSetup||(this._hasSetup=!0,this.NpcBg=new engine.Container,this.NpcBg.alpha=1,this.NpcBg.width=0,this.NpcBg.height=0,this.addChild(this.NpcBg),this.player=new engine.Container,this.player.mouseEnabled=!1,this.addChild(this.player),this.waterSvga=createSvga("水花"),this.playerSvga=createSvga("玩家"),this.boomSvga=createSvga("炸弹svga"),this.player.addChild(this.playerSvga),this.player.addChild(this.waterSvga),this.player.addChild(this.boomSvga),this.playerSvga.gotoAndPlay(1),this.visible=!1,setTimeout(function(){e.visible=!0,e.player.anchorY=e.player.height/2,e.player.anchorX=e.player.width/2,console.log(e.player.width),console.log(e.playerSvga.width),e.player.x=375-e.player.width/2,e.player.y=props.playerPositionY},300),this.rectBg=new engine.Rect,this.rectBg.alpha=0,this.rectBg.width=750,this.rectBg.height=1624,this.addChild(this.rectBg),this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDownStage,this),this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMoveStage,this),this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT,this.onOutStage,this))},t.prototype.reset=function(){this.recycleGoods()},t.prototype.start=function(){var e=this;this.score=0,this.speed=1,this.gameIng=!0,this.creatNpc(),this.beginNpc(),this.countdown=props.countDown,this.countdownTimer=setInterval(function(){e.gameIng&&(0<e.countdown?(engine.globalEvent.dispatchEvent("food-fell-time-update",{time:e.countdown}),e.countdown-=1):(engine.globalEvent.dispatchEvent("food-fell-game-over",{score:e.score,reason:1}),e.died()))},1e3)},t.prototype.beginNpc=function(){var e=this;this.timer=setTimeout(function(){e.gameIng&&(e.speed+=props.acceleratedSpeed,e.creatNpc()),e.beginNpc()},2e3/this.speed)},t.prototype.pause=function(){this.gameIng=!1},t.prototype.revive=function(){this.gameIng=!0},t.prototype.resume=function(){this.reset(),this.start()},t.prototype.creatNpc=function(){var e=this,t=this._goods=ObjectPool$1.getObject(PoolName);this.goodsItems.push(t),this.NpcBg.addChild(t),t.addEventListener(engine.Event.ENTER_FRAME,t.onGoodsEnter=function(){1624<t.y?e.removeNpc(t):e.gameIng&&(t.y+=4*e.speed,e.hasHit(e.player,t)&&("rain"==t.npcType?(console.log("碰到雨滴"),e.score+=props.rainScore,e.waterSvga.visible=!0,e.waterSvga.play(!1,!1),e.waterSvga.once(engine.Event.END_FRAME,function(){e.waterSvga.visible=!1},e)):"stone"==t.npcType?(console.log("碰到石头"),e.score+=props.stoneScore):"boom"==t.npcType&&(console.log("碰到炸弹"),e.boomSvga.visible=!0,e.boomSvga.play(!1,!1),e.boomSvga.once(engine.Event.END_FRAME,function(){e.boomSvga.visible=!1},e),engine.globalEvent.dispatchEvent("food-fell-game-over",{score:e.score,reason:2}),e.died()),engine.globalEvent.dispatchEvent("food-fell-score-update",{score:e.score}),e.removeNpc(t)))},this)},t.prototype.died=function(){this.score=0,this.pause()},t.prototype.removeNpc=function(e){this.NpcBg.removeChild(e),ObjectPool$1.recycleObject(PoolName,e),e.removeEventListener(engine.Event.ENTER_FRAME,e.onGoodsEnter,this);var t=this.goodsItems.indexOf(e);-1<t&&this.goodsItems.splice(t,1)},t.prototype.recycleGoods=function(){clearTimeout(this.timer),clearInterval(this.countdownTimer);for(var e=0,t=this.goodsItems;e<t.length;e++){var o=t[e];o&&(this.removeChild(o),ObjectPool$1.recycleObject(PoolName,o),o.removeEventListener(engine.Event.ENTER_FRAME,o.onGoodsEnter,this))}this.goodsItems=[]},t.prototype.hasHit=function(e,t){return Math.abs(e.x+e.width/2-(t.x+t.width/2))<e.width/2+t.width/2&&Math.abs(e.y+e.height/2-(t.y+t.height/2))<e.height/2+t.height/2},t}(engine.Container),GameWrapper=function(o){function e(){var e=o.call(this)||this;engine.globalEvent.addEventListener("food-fell-reset",e.reset,e),engine.globalEvent.addEventListener("food-fell-start",e.start,e),engine.globalEvent.addEventListener("food-fell-pause",e.pause,e),engine.globalEvent.addEventListener("food-fell-resume",e.resume,e),engine.globalEvent.addEventListener("food-fell-revive",e.revive,e),engine.globalEvent.addEventListener("food-fell-clear",e.clear,e),e.addEventListener(engine.MouseEvent.CLICK,e.onTap,e);var t=e._gameView=new GameView;return e.addChild(t),e}return tslib.__extends(e,o),e.prototype.reset=function(e){injectProps(e.data),this._gameView.visible=!0,this._gameView.reset()},e.prototype.start=function(e){injectProps(e.data),this._status=1,this._gameView.start()},e.prototype.pause=function(){this._gameView.pause()},e.prototype.resume=function(){this._gameView.resume()},e.prototype.revive=function(){this._gameView.revive()},e.prototype.clear=function(){this._gameView.visible=!1},e.prototype.onTap=function(e){},e}(engine.Container);function index(e){return prepareProps(),injectProps(e),new GameWrapper}module.exports=index;
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global['food-fell'] = 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 Goods = (function (_super) {
tslib.__extends(Goods, _super);
function Goods() {
var _this = _super.call(this) || this;
var body;
body = _this._body = new engine.Rect();
var rain = new engine.Sprite(getTextureByName('雨滴'));
rain["npcType"] = "rain";
var stone = new engine.Sprite(getTextureByName('石块'));
stone["npcType"] = "stone";
var boom = new engine.Sprite(getTextureByName('炸弹'));
boom["npcType"] = "boom";
rain.visible = false;
stone.visible = false;
boom.visible = false;
body.addChild(rain);
body.addChild(stone);
body.addChild(boom);
_this.addChild(body);
body.width = .0001;
body.height = .0001;
body.mouseEnabled = false;
return _this;
}
Goods.prototype.getRandomNumberByRange = function (start, end) {
return Math.floor(Math.random() * (end - start) + start);
};
Goods.prototype.reset = function () {
this.visible = true;
this.rotation = 0;
this.anchorOffsetY = 0;
this.y = 0;
this.x = (750 - 120) * Math.random() + 30;
this.rotation = 0;
var random = Math.random();
if (random < props.goodsProbability[0]) {
this.showNpc("rain");
}
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");
}
};
Goods.prototype.showNpc = function (type) {
for (var i = 0; i < this._body.children.length; i++) {
this._body.children[i].visible = false;
this._body.children[i].mouseEnabled = false;
}
for (var 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;
}
}
};
Object.defineProperty(Goods.prototype, "anchorOffsetY", {
set: function (v) {
this._body.y = v;
},
enumerable: true,
configurable: true
});
return Goods;
}(engine.Container));
//# sourceMappingURL=Goods.js.map
var ObjectPool = engine.ObjectPool;
var PoolName = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item, data) {
item.reset();
});
//# sourceMappingURL=object-pool-init.js.map
var ObjectPool$1 = engine.ObjectPool;
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
function GameView() {
var _this = _super.call(this) || this;
_this.goodsItems = [];
_this.moveCatchX = 0;
_this.playerCatchX = 0;
_this.onDownStage = function (e) {
_this.moveCatchX = e.localX;
_this.playerCatchX = _this.player.x;
};
_this.onMoveStage = function (e) {
if (_this.gameIng) {
_this.player.x = _this.playerCatchX + (e.localX - _this.moveCatchX);
}
};
_this.onOutStage = function (e) {
_this.moveCatchX = 0;
};
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
GameView.prototype.setup = function () {
var _this = this;
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this.NpcBg = new engine.Container();
this.NpcBg.alpha = 1;
this.NpcBg.width = 0;
this.NpcBg.height = 0;
this.addChild(this.NpcBg);
this.player = new engine.Container();
this.player.mouseEnabled = false;
this.addChild(this.player);
this.waterSvga = createSvga("水花");
this.playerSvga = createSvga("玩家");
this.boomSvga = createSvga("炸弹svga");
this.player.addChild(this.playerSvga);
this.player.addChild(this.waterSvga);
this.player.addChild(this.boomSvga);
this.playerSvga.gotoAndPlay(1);
this.visible = false;
setTimeout(function () {
_this.visible = true;
_this.player.anchorY = _this.player.height / 2;
_this.player.anchorX = _this.player.width / 2;
console.log(_this.player.width);
console.log(_this.playerSvga.width);
_this.player.x = 375 - _this.player.width / 2;
_this.player.y = props.playerPositionY;
}, 300);
this.rectBg = new engine.Rect();
this.rectBg.alpha = 0;
this.rectBg.width = 750;
this.rectBg.height = 1624;
this.addChild(this.rectBg);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
};
GameView.prototype.reset = function () {
this.recycleGoods();
};
GameView.prototype.start = function () {
var _this = this;
this.score = 0;
this.speed = 1;
this.gameIng = true;
this.creatNpc();
this.beginNpc();
this.countdown = props.countDown;
this.countdownTimer = setInterval(function () {
if (_this.gameIng) {
if (_this.countdown > 0) {
engine.globalEvent.dispatchEvent('food-fell-time-update', {
time: _this.countdown,
});
_this.countdown -= 1;
}
else {
engine.globalEvent.dispatchEvent('food-fell-game-over', {
score: _this.score,
reason: 1
});
_this.died();
}
}
}, 1000);
};
GameView.prototype.beginNpc = function () {
var _this = this;
this.timer = setTimeout(function () {
if (_this.gameIng) {
_this.speed += props.acceleratedSpeed;
_this.creatNpc();
}
_this.beginNpc();
}, 2000 / this.speed);
};
GameView.prototype.pause = function () {
this.gameIng = false;
};
GameView.prototype.revive = function () {
this.gameIng = true;
};
GameView.prototype.resume = function () {
this.reset();
this.start();
};
GameView.prototype.creatNpc = function () {
var _this = this;
var goods = this._goods = ObjectPool$1.getObject(PoolName);
this.goodsItems.push(goods);
this.NpcBg.addChild(goods);
goods.addEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"] = function () {
if (goods.y > 1624) {
_this.removeNpc(goods);
}
else {
if (_this.gameIng) {
goods.y += (4 * _this.speed);
if (_this.hasHit(_this.player, goods)) {
if (goods["npcType"] == "rain") {
console.log("碰到雨滴");
_this.score += props.rainScore;
_this.waterSvga.visible = true;
_this.waterSvga.play(false, false);
_this.waterSvga.once(engine.Event.END_FRAME, function () {
_this.waterSvga.visible = false;
}, _this);
}
else if (goods["npcType"] == "stone") {
console.log("碰到石头");
_this.score += props.stoneScore;
}
else if (goods["npcType"] == "boom") {
console.log("碰到炸弹");
_this.boomSvga.visible = true;
_this.boomSvga.play(false, false);
_this.boomSvga.once(engine.Event.END_FRAME, function () {
_this.boomSvga.visible = false;
}, _this);
engine.globalEvent.dispatchEvent('food-fell-game-over', {
score: _this.score,
reason: 2
});
_this.died();
}
engine.globalEvent.dispatchEvent('food-fell-score-update', {
score: _this.score,
});
_this.removeNpc(goods);
}
}
}
}, this);
};
GameView.prototype.died = function () {
this.score = 0;
this.pause();
};
GameView.prototype.removeNpc = function (goods) {
this.NpcBg.removeChild(goods);
ObjectPool$1.recycleObject(PoolName, goods);
goods.removeEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"], this);
var index = this.goodsItems.indexOf(goods);
if (index > -1) {
this.goodsItems.splice(index, 1);
}
};
GameView.prototype.recycleGoods = function () {
clearTimeout(this.timer);
clearInterval(this.countdownTimer);
for (var _i = 0, _a = this.goodsItems; _i < _a.length; _i++) {
var goods = _a[_i];
if (goods) {
this.removeChild(goods);
ObjectPool$1.recycleObject(PoolName, goods);
goods.removeEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"], this);
}
}
this.goodsItems = [];
};
GameView.prototype.hasHit = function (a, b) {
if (Math.abs((a.x + a.width / 2) - (b.x + b.width / 2)) < a.width / 2 + b.width / 2
&&
Math.abs((a.y + a.height / 2) - (b.y + b.height / 2)) < a.height / 2 + b.height / 2) {
return true;
}
else {
return false;
}
};
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('food-fell-reset', _this.reset, _this);
engine.globalEvent.addEventListener('food-fell-start', _this.start, _this);
engine.globalEvent.addEventListener('food-fell-pause', _this.pause, _this);
engine.globalEvent.addEventListener('food-fell-resume', _this.resume, _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);
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) {
injectProps(event.data);
this._status = 1;
this._gameView.start();
};
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 source diff could not be displayed because it is too large. You can view the blob instead.
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