Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-libs
Commits
91229572
Commit
91229572
authored
Jun 18, 2020
by
任建锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--
parent
c1376683
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
2 deletions
+7
-2
dragon-boat-race.json
dist/customs/dragon-boat-race.json
+6
-1
food-fell2.json
dist/customs/food-fell2.json
+1
-1
No files found.
dist/customs/dragon-boat-race.json
View file @
91229572
...
...
@@ -7,6 +7,11 @@
"type"
:
"number"
,
"default"
:
900
},
"playerPositionX"
:
{
"alias"
:
"玩家Y轴位置"
,
"type"
:
"number"
,
"default"
:
300
},
"runScore"
:
{
"alias"
:
"每前进1米加分(不能小于1)"
,
"type"
:
"number"
,
...
...
@@ -206,5 +211,5 @@
}
},
"id"
:
"dragon-boat-race"
,
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global['dragon-boat-race'] = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\t
//# sourceMappingURL=props.js.map
\n\n\t
function getTexture(uuid) {
\n\t
return engine.Texture.from(getAssetByUUID(uuid).uuid);
\n\t
}
\n\t
function getTextureByName(name) {
\n\t
return getTexture(getAssetByName(name).uuid);
\n\t
}
\n\t
function createSvga(name, anchorName) {
\n\t
var inst = new svga.Svga();
\n\t
inst.source = 'asset://' + getAssetByName(name).uuid;
\n\t
return inst;
\n\t
}
\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var Goods = (function (_super) {
\n\t
tslib.__extends(Goods, _super);
\n\t
function Goods() {
\n\t
var _this = _super.call(this) || this;
\n\t
var body;
\n\t
body = _this._body = new engine.Rect();
\n\t
var rain = new engine.Sprite(getTextureByName('金币'));
\n\t
var rain1 = new engine.Sprite(getTextureByName('粽子'));
\n\t
rain[
\"
npcType
\"
] =
\"
rain0
\"
;
\n\t
rain1[
\"
npcType
\"
] =
\"
rain1
\"
;
\n\t
var stone = new engine.Sprite(getTextureByName('木头'));
\n\t
stone[
\"
npcType
\"
] =
\"
stone
\"
;
\n\t
var boom = new engine.Sprite(getTextureByName('石块'));
\n\t
boom[
\"
npcType
\"
] =
\"
boom
\"
;
\n\t
rain.visible = false;
\n\t
rain1.visible = false;
\n\t
stone.visible = false;
\n\t
boom.visible = false;
\n\t
rain.anchorX = rain.width / 2;
\n\t
rain1.anchorX = rain1.width / 2;
\n\t
stone.anchorX = stone.width / 2;
\n\t
boom.anchorX = boom.width / 2;
\n\t
rain.anchorY = rain.height / 2;
\n\t
rain1.anchorY = rain1.height / 2;
\n\t
stone.anchorY = stone.height / 2;
\n\t
boom.anchorY = boom.height / 2;
\n\t
body.addChild(rain);
\n\t
body.addChild(rain1);
\n\t
body.addChild(stone);
\n\t
body.addChild(boom);
\n\t
_this.addChild(body);
\n\t
body.width = .0001;
\n\t
body.height = .0001;
\n\t
body.mouseEnabled = false;
\n\t
return _this;
\n\t
}
\n\t
Goods.prototype.getRandomNumberByRange = function (start, end) {
\n\t
return Math.floor(Math.random() * (end - start) + start);
\n\t
};
\n\t
Goods.prototype.reset = function () {
\n\t
this[
\"
lifeState
\"
] = true;
\n\t
this.visible = true;
\n\t
this.rotation = 0;
\n\t
this.anchorOffsetY = 0;
\n\t
if (this.width <= 0) {
\n\t
this.anchorX = 50;
\n\t
}
\n\t
else {
\n\t
this.anchorX = this.width / 2;
\n\t
}
\n\t
this.anchorY = this.height / 2;
\n\t
this.scaleX = this.scaleY = 1;
\n\t
this.y = 0;
\n\t
this.x = ((750 - props.maxNpcBound) - 120) * Math.random() + 30 + props.maxNpcBound;
\n\t
this.rotation = 0;
\n\t
var random = Math.random();
\n\t
if (typeof (props.goodsProbability) == 'string') {
\n\t
props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; });
\n\t
console.log(props.goodsProbability);
\n\t
}
\n\t
if (random < props.goodsProbability[0]) {
\n\t
this.showNpc(
\"
rain0
\"
);
\n\t
}
\n\t
else if (random >= props.goodsProbability[0] && random <= (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
rain1
\"
);
\n\t
}
\n\t
else if (random >= (props.goodsProbability[0] + props.goodsProbability[1]) && random <= (props.goodsProbability[0] + props.goodsProbability[1] + props.goodsProbability[2])) {
\n\t
this.showNpc(
\"
stone
\"
);
\n\t
}
\n\t
else if (random > (props.goodsProbability[0] + props.goodsProbability[1] + props.goodsProbability[2])) {
\n\t
this.showNpc(
\"
boom
\"
);
\n\t
}
\n\t
};
\n\t
Goods.prototype.showNpc = function (type) {
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
this._body.children[i].visible = false;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
if (this._body.children[i][
\"
npcType
\"
] == type) {
\n\t
this[
\"
npcType
\"
] = type;
\n\t
this._body.children[i].visible = true;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
}
\n\t
};
\n\t
Object.defineProperty(Goods.prototype,
\"
anchorOffsetY
\"
, {
\n\t
set: function (v) {
\n\t
this._body.y = v;
\n\t
},
\n\t
enumerable: true,
\n\t
configurable: true
\n\t
});
\n\t
return Goods;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=Goods.js.map
\n\n\t
var ObjectPool = engine.ObjectPool;
\n\t
var PoolName = 'goods';
\n\t
ObjectPool.registerPool(PoolName, function () {
\n\t
return new Goods();
\n\t
}, function (item, data) {
\n\t
item.reset();
\n\t
});
\n\t
//# sourceMappingURL=object-pool-init.js.map
\n\n\t
var ObjectPool$1 = engine.ObjectPool;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this.goodsItems = [];
\n\t
_this.moveCatchX = 0;
\n\t
_this.playerCatchX = 0;
\n\t
_this.onDownStage = function (e) {
\n\t
_this.moveCatchX = e.localX;
\n\t
_this.playerCatchX = _this.player.x;
\n\t
};
\n\t
_this.onMoveStage = function (e) {
\n\t
var maxStageBound = props.maxStageBound;
\n\t
if (_this.gameIng) {
\n\t
var playerX = _this.playerCatchX + (e.localX - _this.moveCatchX);
\n\t
if (playerX < maxStageBound) {
\n\t
_this.player.x = maxStageBound;
\n\t
}
\n\t
else if (playerX + _this.player.width + maxStageBound > 750) {
\n\t
_this.player.x = 750 - maxStageBound - _this.player.width;
\n\t
}
\n\t
else {
\n\t
_this.player.x = playerX;
\n\t
}
\n\t
}
\n\t
};
\n\t
_this.onOutStage = function (e) {
\n\t
_this.moveCatchX = 0;
\n\t
};
\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
var _this = this;
\n\t
if (this._hasSetup) {
\n\t
return;
\n\t
}
\n\t
this._hasSetup = true;
\n\t
this.bg = new engine.Container();
\n\t
this.bg.mouseEnabled = false;
\n\t
this.addChild(this.bg);
\n\t
this.NpcBg = new engine.Container();
\n\t
this.NpcBg.alpha = 1;
\n\t
this.NpcBg.width = 0;
\n\t
this.NpcBg.height = 0;
\n\t
this.addChild(this.NpcBg);
\n\t
this.player = new engine.Container();
\n\t
this.player.mouseEnabled = false;
\n\t
this.player.mouseChildren = false;
\n\t
this.labelScore = new engine.BitmapText();
\n\t
this.labelScore.font = props.fontName;
\n\t
this.labelScore.scaleX = this.labelScore.scaleY = 1;
\n\t
this.addChild(this.labelScore);
\n\t
this.waterSvga = createSvga(
\"
碰到金币svga
\"
);
\n\t
this.water2Svga = createSvga(
\"
碰到粽子svga
\"
);
\n\t
this.boomSvga = createSvga(
\"
碰到石头svga
\"
);
\n\t
this.playerSvgaReset = new engine.Sprite(getTextureByName('玩家静止'));
\n\t
this.playerSvgaRun = createSvga(
\"
玩家滑动
\"
);
\n\t
this.playerSvgaOver = createSvga(
\"
玩家翻船
\"
);
\n\t
this.bg1 = new engine.Sprite(getTextureByName('循环背景1'));
\n\t
this.bg2 = new engine.Sprite(getTextureByName('循环背景2'));
\n\t
this.bg3 = new engine.Sprite(getTextureByName('循环背景1'));
\n\t
this.bg4 = new engine.Sprite(getTextureByName('循环背景2'));
\n\t
this.player.addChild(this.playerSvgaReset);
\n\t
this.player.addChild(this.playerSvgaRun);
\n\t
this.player.addChild(this.playerSvgaOver);
\n\t
this.addChild(this.waterSvga);
\n\t
this.addChild(this.water2Svga);
\n\t
this.addChild(this.boomSvga);
\n\t
this.addChild(this.player);
\n\t
this.bg.addChild(this.bg1);
\n\t
this.bg.addChild(this.bg2);
\n\t
this.bg.addChild(this.bg3);
\n\t
this.bg.addChild(this.bg4);
\n\t
this.waterSvga.visible = false;
\n\t
this.water2Svga.visible = false;
\n\t
this.boomSvga.visible = false;
\n\t
this.setPlayState(this.playerSvgaReset);
\n\t
this.visible = false;
\n\t
setTimeout(function () {
\n\t
_this.visible = true;
\n\t
_this.player.x =
375 - _this.player.width / 2;
\n\t
_this.player.y = props.playerPositionY;
\n\t
_this.playerSvgaRun.x = props.playerRunPosition3Offset[0];
\n\t
_this.playerSvgaRun.y = props.playerRunPosition3Offset[1];
\n\t
_this.playerSvgaOver.x = props.playerOverPosition3Offset[0];
\n\t
_this.playerSvgaOver.y = props.playerOverPosition3Offset[1];
\n\t
_this.bg1.y = 0;
\n\t
_this.bg2.y = _this.bg1.height;
\n\t
_this.bg3.y = _this.bg1.height + _this.bg2.height;
\n\t
_this.bg4.y = _this.bg1.height + _this.bg2.height + _this.bg3.height;
\n\t
engine.Tween.get(_this.playerSvgaReset, { loop: true })
\n\t
.to({ y: 10 }, 500)
\n\t
.to({ y: 0 }, 500)
\n\t
.to({ y: 10 }, 500)
\n\t
.call(function () { });
\n\t
}, 300);
\n\t
this.rectBg = new engine.Container();
\n\t
this.rectBg.alpha = 0;
\n\t
this.rectBg.width = 750;
\n\t
this.rectBg.height = 1624;
\n\t
this.addChild(this.rectBg);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
\n\t
this.rectBg.addEventListener(engine.Event.ENTER_FRAME, this.enterFrame, this);
\n\t
};
\n\t
GameView.prototype.setBoomPosition = function (svga, callback) {
\n\t
svga.x = this.player.x;
\n\t
svga.y = this.player.y;
\n\t
if (svga == this.waterSvga) {
\n\t
svga.x += props.boomPosition1Offset[0];
\n\t
svga.y += props.boomPosition1Offset[1];
\n\t
}
\n\t
else if (svga == this.water2Svga) {
\n\t
svga.x += props.boomPosition2Offset[0];
\n\t
svga.y += props.boomPosition2Offset[1];
\n\t
}
\n\t
else if (svga == this.boomSvga) {
\n\t
svga.x += props.boomPosition3Offset[0];
\n\t
svga.y += props.boomPosition3Offset[1];
\n\t
}
\n\t
svga.visible = true;
\n\t
svga.play(true, false);
\n\t
svga.once(engine.Event.END_FRAME, function () {
\n\t
svga.visible = false;
\n\t
if (callback) {
\n\t
callback();
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.enterFrame = function () {
\n\t
if (this.bg.y >= 0) {
\n\t
this.bg.y = -this.bg3.y;
\n\t
}
\n\t
if (this.gameIng) {
\n\t
this.bg.y += (4 * this.speed);
\n\t
}
\n\t
};
\n\t
GameView.prototype.reset = function () {
\n\t
this.recycleGoods();
\n\t
this.score = 0;
\n\t
this.speed = props.speed;
\n\t
this.bg.y = -1624;
\n\t
this.player.anchorY = this.player.height / 2;
\n\t
this.player.anchorX = this.player.width / 2;
\n\t
this.player.x = 375 - this.player.width / 2
;
\n\t
this.player.y = props.playerPositionY;
\n\t
this.setPlayState(this.playerSvgaReset);
\n\t
};
\n\t
GameView.prototype.setPlayState = function (svga) {
\n\t
this.playerSvgaReset.visible = false;
\n\t
this.playerSvgaRun.visible = false;
\n\t
this.playerSvgaOver.visible = false;
\n\t
console.log(svga);
\n\t
svga.visible = true;
\n\t
if (svga == this.playerSvgaOver) {
\n\t
svga.play(false, false);
\n\t
svga.once(engine.Event.END_FRAME, function () {
\n\t
}, this);
\n\t
}
\n\t
else if (svga == this.playerSvgaRun) {
\n\t
svga.play();
\n\t
}
\n\t
};
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
this.gameIng = true;
\n\t
this.creatNpc();
\n\t
this.beginNpc();
\n\t
this.countdown = props.countDown;
\n\t
this.setPlayState(this.playerSvgaRun);
\n\t
this.countdownTimer = setInterval(function () {
\n\t
if (_this.gameIng) {
\n\t
if (_this.countdown > 0) {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-time-update', {
\n\t
time: _this.countdown,
\n\t
});
\n\t
_this.countdown -= 1;
\n\t
}
\n\t
else {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-game-over', {
\n\t
score: _this.score,
\n\t
reason: 1
\n\t
});
\n\t
_this.died();
\n\t
}
\n\t
_this.score += Math.round(_this.speed * props.runScore);
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
}
\n\t
}, 1000);
\n\t
};
\n\t
GameView.prototype.beginNpc = function () {
\n\t
var _this = this;
\n\t
this.timer = setTimeout(function () {
\n\t
if (_this.gameIng) {
\n\t
_this.speed += props.acceleratedSpeed;
\n\t
_this.speed += props.acceleratedSpeed;
\n\t
if (_this.speed > props.maxSpeed) {
\n\t
_this.speed = props.maxSpeed;
\n\t
}
\n\t
_this.creatNpc();
\n\t
}
\n\t
_this.beginNpc();
\n\t
}, 2000 / this.speed);
\n\t
};
\n\t
GameView.prototype.pause = function () {
\n\t
this.gameIng = false;
\n\t
};
\n\t
GameView.prototype.revive = function () {
\n\t
this.gameIng = true;
\n\t
};
\n\t
GameView.prototype.resume = function () {
\n\t
this.reset();
\n\t
this.start();
\n\t
};
\n\t
GameView.prototype.creatNpc = function () {
\n\t
var _this = this;
\n\t
var goods = this._goods = ObjectPool$1.getObject(PoolName);
\n\t
this.goodsItems.push(goods);
\n\t
this.NpcBg.addChild(goods);
\n\t
goods.addEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
] = function () {
\n\t
if (goods.y > 1624) {
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
else {
\n\t
if (_this.gameIng) {
\n\t
goods.y += (4 * _this.speed);
\n\t
if (goods[
\"
lifeState
\"
] && _this.hasHit(_this.player, goods)) {
\n\t
goods[
\"
lifeState
\"
] = false;
\n\t
if (goods[
\"
npcType
\"
] ==
\"
rain0
\"
) {
\n\t
console.log(
\"
碰到雨滴
\"
);
\n\t
_this.score += props.rainScore;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.setBoomPosition(_this.waterSvga);
\n\t
engine.Tween.get(goods, null, null, true)
\n\t
.to({ scaleX: 0, scaleY: 0 }, 200)
\n\t
.call(function () { _this.removeNpc(goods); });
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
rain1
\"
) {
\n\t
console.log(
\"
碰到雨滴
\"
);
\n\t
_this.score += props.rain2Score;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.setBoomPosition(_this.water2Svga);
\n\t
engine.Tween.get(goods, null, null, true)
\n\t
.to({ scaleX: 0, scaleY: 0 }, 200)
\n\t
.call(function () { _this.removeNpc(goods); });
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
boom
\"
|| goods[
\"
npcType
\"
] ==
\"
stone
\"
) {
\n\t
console.log(
\"
碰到炸弹
\"
);
\n\t
_this.setBoomPosition(_this.boomSvga, function () {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-game-over', {
\n\t
score: _this.score,
\n\t
reason: 2
\n\t
});
\n\t
_this.died();
\n\t
});
\n\t
_this.setPlayState(_this.playerSvgaOver);
\n\t
_this.pause();
\n\t
}
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
}
\n\t
}
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.died = function () {
\n\t
this.score = 0;
\n\t
this.pause();
\n\t
};
\n\t
GameView.prototype.removeNpc = function (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
var index = this.goodsItems.indexOf(goods);
\n\t
if (index > -1) {
\n\t
this.goodsItems.splice(index, 1);
\n\t
}
\n\t
};
\n\t
GameView.prototype.recycleGoods = function () {
\n\t
clearTimeout(this.timer);
\n\t
clearInterval(this.countdownTimer);
\n\t
for (var _i = 0, _a = this.goodsItems; _i < _a.length; _i++) {
\n\t
var goods = _a[_i];
\n\t
if (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
}
\n\t
}
\n\t
this.goodsItems = [];
\n\t
};
\n\t
GameView.prototype.hasHit = function (a, b) {
\n\t
var playerH = a.height;
\n\t
var playerW = a.width;
\n\t
var playerX = a.x;
\n\t
if (props.playerHeight) {
\n\t
playerH = props.playerHeight;
\n\t
}
\n\t
if (props.playerWidth) {
\n\t
playerW = props.playerWidth;
\n\t
playerX = a.x + (a.width - props.playerWidth) / 2;
\n\t
}
\n\t
if (Math.abs((playerX + playerW / 2) - (b.x + b.width / 2)) < playerW / 2 + b.width / 2
\n\t
&&
\n\t
Math.abs((a.y + playerH / 1.3) - (b.y + b.height / 2)) < playerH / 2 + b.height / 2) {
\n\t
return true;
\n\t
}
\n\t
else {
\n\t
return false;
\n\t
}
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var 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('dragon-boat-race-reset', _this.reset, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-pause', _this.pause, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-resume', _this.resume, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-revive', _this.revive, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-clear', _this.clear, _this);
\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.onTap, _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
injectProps(event.data);
\n\t
this._status = 1;
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.pause = function () {
\n\t
this._gameView.pause();
\n\t
};
\n\t
GameWrapper.prototype.resume = function () {
\n\t
this._gameView.resume();
\n\t
};
\n\t
GameWrapper.prototype.revive = function () {
\n\t
this._gameView.revive();
\n\t
};
\n\t
GameWrapper.prototype.clear = function () {
\n\t
this._gameView.visible = false;
\n\t
};
\n\t
GameWrapper.prototype.onTap = function (event) {
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
function 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\t
return index;
\n\n
})));
\n
"
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global['dragon-boat-race'] = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\t
//# sourceMappingURL=props.js.map
\n\n\t
function getTexture(uuid) {
\n\t
return engine.Texture.from(getAssetByUUID(uuid).uuid);
\n\t
}
\n\t
function getTextureByName(name) {
\n\t
return getTexture(getAssetByName(name).uuid);
\n\t
}
\n\t
function createSvga(name, anchorName) {
\n\t
var inst = new svga.Svga();
\n\t
inst.source = 'asset://' + getAssetByName(name).uuid;
\n\t
return inst;
\n\t
}
\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var Goods = (function (_super) {
\n\t
tslib.__extends(Goods, _super);
\n\t
function Goods() {
\n\t
var _this = _super.call(this) || this;
\n\t
var body;
\n\t
body = _this._body = new engine.Rect();
\n\t
var rain = new engine.Sprite(getTextureByName('金币'));
\n\t
var rain1 = new engine.Sprite(getTextureByName('粽子'));
\n\t
rain[
\"
npcType
\"
] =
\"
rain0
\"
;
\n\t
rain1[
\"
npcType
\"
] =
\"
rain1
\"
;
\n\t
var stone = new engine.Sprite(getTextureByName('木头'));
\n\t
stone[
\"
npcType
\"
] =
\"
stone
\"
;
\n\t
var boom = new engine.Sprite(getTextureByName('石块'));
\n\t
boom[
\"
npcType
\"
] =
\"
boom
\"
;
\n\t
rain.visible = false;
\n\t
rain1.visible = false;
\n\t
stone.visible = false;
\n\t
boom.visible = false;
\n\t
rain.anchorX = rain.width / 2;
\n\t
rain1.anchorX = rain1.width / 2;
\n\t
stone.anchorX = stone.width / 2;
\n\t
boom.anchorX = boom.width / 2;
\n\t
rain.anchorY = rain.height / 2;
\n\t
rain1.anchorY = rain1.height / 2;
\n\t
stone.anchorY = stone.height / 2;
\n\t
boom.anchorY = boom.height / 2;
\n\t
body.addChild(rain);
\n\t
body.addChild(rain1);
\n\t
body.addChild(stone);
\n\t
body.addChild(boom);
\n\t
_this.addChild(body);
\n\t
body.width = .0001;
\n\t
body.height = .0001;
\n\t
body.mouseEnabled = false;
\n\t
return _this;
\n\t
}
\n\t
Goods.prototype.getRandomNumberByRange = function (start, end) {
\n\t
return Math.floor(Math.random() * (end - start) + start);
\n\t
};
\n\t
Goods.prototype.reset = function () {
\n\t
this[
\"
lifeState
\"
] = true;
\n\t
this.visible = true;
\n\t
this.rotation = 0;
\n\t
this.anchorOffsetY = 0;
\n\t
if (this.width <= 0) {
\n\t
this.anchorX = 50;
\n\t
}
\n\t
else {
\n\t
this.anchorX = this.width / 2;
\n\t
}
\n\t
this.anchorY = this.height / 2;
\n\t
this.scaleX = this.scaleY = 1;
\n\t
this.y = 0;
\n\t
this.x = ((750 - props.maxNpcBound) - 120) * Math.random() + 30 + props.maxNpcBound;
\n\t
this.rotation = 0;
\n\t
var random = Math.random();
\n\t
if (typeof (props.goodsProbability) == 'string') {
\n\t
props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; });
\n\t
console.log(props.goodsProbability);
\n\t
}
\n\t
if (random < props.goodsProbability[0]) {
\n\t
this.showNpc(
\"
rain0
\"
);
\n\t
}
\n\t
else if (random >= props.goodsProbability[0] && random <= (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
rain1
\"
);
\n\t
}
\n\t
else if (random >= (props.goodsProbability[0] + props.goodsProbability[1]) && random <= (props.goodsProbability[0] + props.goodsProbability[1] + props.goodsProbability[2])) {
\n\t
this.showNpc(
\"
stone
\"
);
\n\t
}
\n\t
else if (random > (props.goodsProbability[0] + props.goodsProbability[1] + props.goodsProbability[2])) {
\n\t
this.showNpc(
\"
boom
\"
);
\n\t
}
\n\t
};
\n\t
Goods.prototype.showNpc = function (type) {
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
this._body.children[i].visible = false;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
if (this._body.children[i][
\"
npcType
\"
] == type) {
\n\t
this[
\"
npcType
\"
] = type;
\n\t
this._body.children[i].visible = true;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
}
\n\t
};
\n\t
Object.defineProperty(Goods.prototype,
\"
anchorOffsetY
\"
, {
\n\t
set: function (v) {
\n\t
this._body.y = v;
\n\t
},
\n\t
enumerable: true,
\n\t
configurable: true
\n\t
});
\n\t
return Goods;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=Goods.js.map
\n\n\t
var ObjectPool = engine.ObjectPool;
\n\t
var PoolName = 'goods';
\n\t
ObjectPool.registerPool(PoolName, function () {
\n\t
return new Goods();
\n\t
}, function (item, data) {
\n\t
item.reset();
\n\t
});
\n\t
//# sourceMappingURL=object-pool-init.js.map
\n\n\t
var ObjectPool$1 = engine.ObjectPool;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this.goodsItems = [];
\n\t
_this.moveCatchX = 0;
\n\t
_this.playerCatchX = 0;
\n\t
_this.onDownStage = function (e) {
\n\t
_this.moveCatchX = e.localX;
\n\t
_this.playerCatchX = _this.player.x;
\n\t
};
\n\t
_this.onMoveStage = function (e) {
\n\t
var maxStageBound = props.maxStageBound;
\n\t
if (_this.gameIng) {
\n\t
var playerX = _this.playerCatchX + (e.localX - _this.moveCatchX);
\n\t
if (playerX < maxStageBound) {
\n\t
_this.player.x = maxStageBound;
\n\t
}
\n\t
else if (playerX + _this.player.width + maxStageBound > 750) {
\n\t
_this.player.x = 750 - maxStageBound - _this.player.width;
\n\t
}
\n\t
else {
\n\t
_this.player.x = playerX;
\n\t
}
\n\t
}
\n\t
};
\n\t
_this.onOutStage = function (e) {
\n\t
_this.moveCatchX = 0;
\n\t
};
\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
var _this = this;
\n\t
if (this._hasSetup) {
\n\t
return;
\n\t
}
\n\t
this._hasSetup = true;
\n\t
this.bg = new engine.Container();
\n\t
this.bg.mouseEnabled = false;
\n\t
this.addChild(this.bg);
\n\t
this.NpcBg = new engine.Container();
\n\t
this.NpcBg.alpha = 1;
\n\t
this.NpcBg.width = 0;
\n\t
this.NpcBg.height = 0;
\n\t
this.addChild(this.NpcBg);
\n\t
this.player = new engine.Container();
\n\t
this.player.mouseEnabled = false;
\n\t
this.player.mouseChildren = false;
\n\t
this.labelScore = new engine.BitmapText();
\n\t
this.labelScore.font = props.fontName;
\n\t
this.labelScore.scaleX = this.labelScore.scaleY = 1;
\n\t
this.addChild(this.labelScore);
\n\t
this.waterSvga = createSvga(
\"
碰到金币svga
\"
);
\n\t
this.water2Svga = createSvga(
\"
碰到粽子svga
\"
);
\n\t
this.boomSvga = createSvga(
\"
碰到石头svga
\"
);
\n\t
this.playerSvgaReset = new engine.Sprite(getTextureByName('玩家静止'));
\n\t
this.playerSvgaRun = createSvga(
\"
玩家滑动
\"
);
\n\t
this.playerSvgaOver = createSvga(
\"
玩家翻船
\"
);
\n\t
this.bg1 = new engine.Sprite(getTextureByName('循环背景1'));
\n\t
this.bg2 = new engine.Sprite(getTextureByName('循环背景2'));
\n\t
this.bg3 = new engine.Sprite(getTextureByName('循环背景1'));
\n\t
this.bg4 = new engine.Sprite(getTextureByName('循环背景2'));
\n\t
this.player.addChild(this.playerSvgaReset);
\n\t
this.player.addChild(this.playerSvgaRun);
\n\t
this.player.addChild(this.playerSvgaOver);
\n\t
this.addChild(this.waterSvga);
\n\t
this.addChild(this.water2Svga);
\n\t
this.addChild(this.boomSvga);
\n\t
this.addChild(this.player);
\n\t
this.bg.addChild(this.bg1);
\n\t
this.bg.addChild(this.bg2);
\n\t
this.bg.addChild(this.bg3);
\n\t
this.bg.addChild(this.bg4);
\n\t
this.waterSvga.visible = false;
\n\t
this.water2Svga.visible = false;
\n\t
this.boomSvga.visible = false;
\n\t
this.setPlayState(this.playerSvgaReset);
\n\t
this.visible = false;
\n\t
setTimeout(function () {
\n\t
_this.visible = true;
\n\t
_this.player.x =
props.playerPositionX;
\n\t
_this.player.y = props.playerPositionY;
\n\t
_this.playerSvgaRun.x = props.playerRunPosition3Offset[0];
\n\t
_this.playerSvgaRun.y = props.playerRunPosition3Offset[1];
\n\t
_this.playerSvgaOver.x = props.playerOverPosition3Offset[0];
\n\t
_this.playerSvgaOver.y = props.playerOverPosition3Offset[1];
\n\t
_this.bg1.y = 0;
\n\t
_this.bg2.y = _this.bg1.height;
\n\t
_this.bg3.y = _this.bg1.height + _this.bg2.height;
\n\t
_this.bg4.y = _this.bg1.height + _this.bg2.height + _this.bg3.height;
\n\t
engine.Tween.get(_this.playerSvgaReset, { loop: true })
\n\t
.to({ y: 10 }, 500)
\n\t
.to({ y: 0 }, 500)
\n\t
.to({ y: 10 }, 500)
\n\t
.call(function () { });
\n\t
}, 300);
\n\t
this.rectBg = new engine.Container();
\n\t
this.rectBg.alpha = 0;
\n\t
this.rectBg.width = 750;
\n\t
this.rectBg.height = 1624;
\n\t
this.addChild(this.rectBg);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
\n\t
this.rectBg.addEventListener(engine.Event.ENTER_FRAME, this.enterFrame, this);
\n\t
};
\n\t
GameView.prototype.setBoomPosition = function (svga, callback) {
\n\t
svga.x = this.player.x;
\n\t
svga.y = this.player.y;
\n\t
if (svga == this.waterSvga) {
\n\t
svga.x += props.boomPosition1Offset[0];
\n\t
svga.y += props.boomPosition1Offset[1];
\n\t
}
\n\t
else if (svga == this.water2Svga) {
\n\t
svga.x += props.boomPosition2Offset[0];
\n\t
svga.y += props.boomPosition2Offset[1];
\n\t
}
\n\t
else if (svga == this.boomSvga) {
\n\t
svga.x += props.boomPosition3Offset[0];
\n\t
svga.y += props.boomPosition3Offset[1];
\n\t
}
\n\t
svga.visible = true;
\n\t
svga.play(true, false);
\n\t
svga.once(engine.Event.END_FRAME, function () {
\n\t
svga.visible = false;
\n\t
if (callback) {
\n\t
callback();
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.enterFrame = function () {
\n\t
if (this.bg.y >= 0) {
\n\t
this.bg.y = -this.bg3.y;
\n\t
}
\n\t
if (this.gameIng) {
\n\t
this.bg.y += (4 * this.speed);
\n\t
}
\n\t
};
\n\t
GameView.prototype.reset = function () {
\n\t
this.recycleGoods();
\n\t
this.score = 0;
\n\t
this.speed = props.speed;
\n\t
this.bg.y = -this.bg3.y;
\n\t
this.player.anchorY = this.player.height / 2;
\n\t
this.player.anchorX = this.player.width / 2;
\n\t
this.player.x = props.playerPositionX
;
\n\t
this.player.y = props.playerPositionY;
\n\t
this.setPlayState(this.playerSvgaReset);
\n\t
};
\n\t
GameView.prototype.setPlayState = function (svga) {
\n\t
this.playerSvgaReset.visible = false;
\n\t
this.playerSvgaRun.visible = false;
\n\t
this.playerSvgaOver.visible = false;
\n\t
console.log(svga);
\n\t
svga.visible = true;
\n\t
if (svga == this.playerSvgaOver) {
\n\t
svga.play(false, false);
\n\t
svga.once(engine.Event.END_FRAME, function () {
\n\t
}, this);
\n\t
}
\n\t
else if (svga == this.playerSvgaRun) {
\n\t
svga.play();
\n\t
}
\n\t
};
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
this.gameIng = true;
\n\t
this.creatNpc();
\n\t
this.beginNpc();
\n\t
this.countdown = props.countDown;
\n\t
this.setPlayState(this.playerSvgaRun);
\n\t
this.countdownTimer = setInterval(function () {
\n\t
if (_this.gameIng) {
\n\t
if (_this.countdown > 0) {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-time-update', {
\n\t
time: _this.countdown,
\n\t
});
\n\t
_this.countdown -= 1;
\n\t
}
\n\t
else {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-game-over', {
\n\t
score: _this.score,
\n\t
reason: 1
\n\t
});
\n\t
_this.died();
\n\t
}
\n\t
_this.score += Math.round(_this.speed * props.runScore);
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
}
\n\t
}, 1000);
\n\t
};
\n\t
GameView.prototype.beginNpc = function () {
\n\t
var _this = this;
\n\t
this.timer = setTimeout(function () {
\n\t
if (_this.gameIng) {
\n\t
_this.speed += props.acceleratedSpeed;
\n\t
_this.speed += props.acceleratedSpeed;
\n\t
if (_this.speed > props.maxSpeed) {
\n\t
_this.speed = props.maxSpeed;
\n\t
}
\n\t
_this.creatNpc();
\n\t
}
\n\t
_this.beginNpc();
\n\t
}, 2000 / this.speed);
\n\t
};
\n\t
GameView.prototype.pause = function () {
\n\t
this.gameIng = false;
\n\t
};
\n\t
GameView.prototype.revive = function () {
\n\t
this.gameIng = true;
\n\t
};
\n\t
GameView.prototype.resume = function () {
\n\t
this.reset();
\n\t
this.start();
\n\t
};
\n\t
GameView.prototype.creatNpc = function () {
\n\t
var _this = this;
\n\t
var goods = this._goods = ObjectPool$1.getObject(PoolName);
\n\t
this.goodsItems.push(goods);
\n\t
this.NpcBg.addChild(goods);
\n\t
goods.addEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
] = function () {
\n\t
if (goods.y > 1624) {
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
else {
\n\t
if (_this.gameIng) {
\n\t
goods.y += (4 * _this.speed);
\n\t
if (goods[
\"
lifeState
\"
] && _this.hasHit(_this.player, goods)) {
\n\t
goods[
\"
lifeState
\"
] = false;
\n\t
if (goods[
\"
npcType
\"
] ==
\"
rain0
\"
) {
\n\t
console.log(
\"
碰到雨滴
\"
);
\n\t
_this.score += props.rainScore;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.setBoomPosition(_this.waterSvga);
\n\t
engine.Tween.get(goods, null, null, true)
\n\t
.to({ scaleX: 0, scaleY: 0 }, 200)
\n\t
.call(function () { _this.removeNpc(goods); });
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
rain1
\"
) {
\n\t
console.log(
\"
碰到雨滴
\"
);
\n\t
_this.score += props.rain2Score;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.setBoomPosition(_this.water2Svga);
\n\t
engine.Tween.get(goods, null, null, true)
\n\t
.to({ scaleX: 0, scaleY: 0 }, 200)
\n\t
.call(function () { _this.removeNpc(goods); });
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
boom
\"
|| goods[
\"
npcType
\"
] ==
\"
stone
\"
) {
\n\t
console.log(
\"
碰到炸弹
\"
);
\n\t
_this.setBoomPosition(_this.boomSvga, function () {
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-game-over', {
\n\t
score: _this.score,
\n\t
reason: 2
\n\t
});
\n\t
_this.died();
\n\t
});
\n\t
_this.setPlayState(_this.playerSvgaOver);
\n\t
_this.pause();
\n\t
}
\n\t
engine.globalEvent.dispatchEvent('dragon-boat-race-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
}
\n\t
}
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.died = function () {
\n\t
this.score = 0;
\n\t
this.pause();
\n\t
};
\n\t
GameView.prototype.removeNpc = function (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
var index = this.goodsItems.indexOf(goods);
\n\t
if (index > -1) {
\n\t
this.goodsItems.splice(index, 1);
\n\t
}
\n\t
};
\n\t
GameView.prototype.recycleGoods = function () {
\n\t
clearTimeout(this.timer);
\n\t
clearInterval(this.countdownTimer);
\n\t
for (var _i = 0, _a = this.goodsItems; _i < _a.length; _i++) {
\n\t
var goods = _a[_i];
\n\t
if (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
}
\n\t
}
\n\t
this.goodsItems = [];
\n\t
};
\n\t
GameView.prototype.hasHit = function (a, b) {
\n\t
var playerH = a.height;
\n\t
var playerW = a.width;
\n\t
var playerX = a.x;
\n\t
if (props.playerHeight) {
\n\t
playerH = props.playerHeight;
\n\t
}
\n\t
if (props.playerWidth) {
\n\t
playerW = props.playerWidth;
\n\t
playerX = a.x + (a.width - props.playerWidth) / 2;
\n\t
}
\n\t
if (Math.abs((playerX + playerW / 2) - (b.x + b.width / 2)) < playerW / 2 + b.width / 2
\n\t
&&
\n\t
Math.abs((a.y + playerH / 1.3) - (b.y + b.height / 2)) < playerH / 2 + b.height / 2) {
\n\t
return true;
\n\t
}
\n\t
else {
\n\t
return false;
\n\t
}
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var 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('dragon-boat-race-reset', _this.reset, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-pause', _this.pause, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-resume', _this.resume, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-revive', _this.revive, _this);
\n\t
engine.globalEvent.addEventListener('dragon-boat-race-clear', _this.clear, _this);
\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.onTap, _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
injectProps(event.data);
\n\t
this._status = 1;
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.pause = function () {
\n\t
this._gameView.pause();
\n\t
};
\n\t
GameWrapper.prototype.resume = function () {
\n\t
this._gameView.resume();
\n\t
};
\n\t
GameWrapper.prototype.revive = function () {
\n\t
this._gameView.revive();
\n\t
};
\n\t
GameWrapper.prototype.clear = function () {
\n\t
this._gameView.visible = false;
\n\t
};
\n\t
GameWrapper.prototype.onTap = function (event) {
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
function 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\t
return index;
\n\n
})));
\n
"
}
dist/customs/food-fell2.json
View file @
91229572
...
...
@@ -168,5 +168,5 @@
}
},
"id"
:
"food-fell2"
,
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global['food-fell2'] = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\t
//# sourceMappingURL=props.js.map
\n\n\t
function getTextureByName(name) {
\n\t
return engine.Texture.from(
getAssetByName(name).uuid);
\n\t
}
\n\t
function createSvga(name, anchorName) {
\n\t
var inst = new svga.Svga();
\n\t
inst.source = 'asset://' + getAssetByName(name).uuid;
\n\t
return inst;
\n\t
}
\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var Goods = (function (_super) {
\n\t
tslib.__extends(Goods, _super);
\n\t
function Goods() {
\n\t
var _this = _super.call(this) || this;
\n\t
var body;
\n\t
body = _this._body = new engine.Rect();
\n\t
var rain = new engine.Sprite(getTextureByName('雨滴0'));
\n\t
var rain1 = new engine.Sprite(getTextureByName('雨滴1'));
\n\t
var rain2 = new engine.Sprite(getTextureByName('雨滴2'));
\n\t
rain[
\"
npcType
\"
] =
\"
rain0
\"
;
\n\t
rain1[
\"
npcType
\"
] =
\"
rain1
\"
;
\n\t
rain2[
\"
npcType
\"
] =
\"
rain2
\"
;
\n\t
var stone = new engine.Sprite(getTextureByName('石块'));
\n\t
stone[
\"
npcType
\"
] =
\"
stone
\"
;
\n\t
var boom = new engine.Sprite(getTextureByName('炸弹'));
\n\t
boom[
\"
npcType
\"
] =
\"
boom
\"
;
\n\t
rain.visible = false;
\n\t
rain1.visible = false;
\n\t
rain2.visible = false;
\n\t
stone.visible = false;
\n\t
boom.visible = false;
\n\t
body.addChild(rain);
\n\t
body.addChild(rain1);
\n\t
body.addChild(rain2);
\n\t
body.addChild(stone);
\n\t
body.addChild(boom);
\n\t
_this.addChild(body);
\n\t
body.width = .0001;
\n\t
body.height = .0001;
\n\t
body.mouseEnabled = false;
\n\t
return _this;
\n\t
}
\n\t
Goods.prototype.getRandomNumberByRange = function (start, end) {
\n\t
return Math.floor(Math.random() * (end - start) + start);
\n\t
};
\n\t
Goods.prototype.reset = function () {
\n\t
this.visible = true;
\n\t
this.rotation = 0;
\n\t
this.anchorOffsetY = 0;
\n\t
this.y = 0;
\n\t
this.x = (750 - 120) * Math.random() + 30;
\n\t
this.rotation = 0;
\n\t
var random = Math.random();
\n\t
if (typeof (props.goodsProbability) == 'string') {
\n\t
props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; });
\n\t
}
\n\t
if (random < props.goodsProbability[0]) {
\n\t
var randomNum = Math.floor(Math.random() * 3);
\n\t
this.showNpc(
\"
rain
\"
+ randomNum);
\n\t
}
\n\t
else if (random >= props.goodsProbability[0] && random <= (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
stone
\"
);
\n\t
}
\n\t
else if (random > (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
boom
\"
);
\n\t
}
\n\t
};
\n\t
Goods.prototype.showNpc = function (type) {
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
this._body.children[i].visible = false;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
if (this._body.children[i][
\"
npcType
\"
] == type) {
\n\t
this[
\"
npcType
\"
] = type;
\n\t
this._body.children[i].visible = true;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
}
\n\t
};
\n\t
Object.defineProperty(Goods.prototype,
\"
anchorOffsetY
\"
, {
\n\t
set: function (v) {
\n\t
this._body.y = v;
\n\t
},
\n\t
enumerable: true,
\n\t
configurable: true
\n\t
});
\n\t
return Goods;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=Goods.js.map
\n\n\t
var ObjectPool = engine.ObjectPool;
\n\t
var PoolName = 'goods';
\n\t
ObjectPool.registerPool(PoolName, function () {
\n\t
return new Goods();
\n\t
}, function (item, data) {
\n\t
item.reset();
\n\t
});
\n\t
//# sourceMappingURL=object-pool-init.js.map
\n\n\t
var ObjectPool$1 = engine.ObjectPool;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this.goodsItems = [];
\n\t
_this.moveCatchX = 0;
\n\t
_this.playerCatchX = 0;
\n\t
_this.onDownStage = function (e) {
\n\t
_this.moveCatchX = e.localX;
\n\t
_this.playerCatchX = _this.player.x;
\n\t
};
\n\t
_this.onMoveStage = function (e) {
\n\t
var maxStageBound = props.maxStageBound;
\n\t
if (_this.gameIng) {
\n\t
var playerX = _this.playerCatchX + (e.localX - _this.moveCatchX);
\n\t
if (playerX < maxStageBound) {
\n\t
_this.player.x = maxStageBound;
\n\t
}
\n\t
else if (playerX + _this.player.width + maxStageBound > 750) {
\n\t
_this.player.x = 750 - maxStageBound - _this.player.width;
\n\t
}
\n\t
else {
\n\t
_this.player.x = playerX;
\n\t
}
\n\t
}
\n\t
};
\n\t
_this.onOutStage = function (e) {
\n\t
_this.moveCatchX = 0;
\n\t
};
\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
var _this = this;
\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.alpha = 1;
\n\t
this.NpcBg.width = 0;
\n\t
this.NpcBg.height = 0;
\n\t
this.addChild(this.NpcBg);
\n\t
this.player = new engine.Container();
\n\t
this.player.mouseEnabled = false;
\n\t
this.addChild(this.player);
\n\t
this.waterSvga = createSvga(
\"
水花
\"
);
\n\t
this.stoneSvga = createSvga(
\"
石头svga
\"
);
\n\t
this.playerSvga = new engine.Sprite(getTextureByName('玩家'));
\n\t
this.boomSvga = createSvga(
\"
炸弹svga
\"
);
\n\t
this.player.addChild(this.playerSvga);
\n\t
this.player.addChild(this.stoneSvga);
\n\t
this.player.addChild(this.waterSvga);
\n\t
this.player.addChild(this.boomSvga);
\n\t
this.waterSvga.visible = false;
\n\t
this.stoneSvga.visible = false;
\n\t
this.boomSvga.visible = false;
\n\t
this.visible = false;
\n\t
setTimeout(function () {
\n\t
_this.visible = true;
\n\t
_this.player.anchorY = _this.player.height / 2;
\n\t
_this.player.anchorX = _this.player.width / 2;
\n\t
_this.player.x = 375 - _this.player.width / 2;
\n\t
_this.player.y = props.playerPositionY;
\n\t
_this.stoneSvga.x = _this.player.width / 2 - _this.stoneSvga.width / 2 + props.boomPosition1Offset[0];
\n\t
_this.stoneSvga.y = _this.player.height / 2 - _this.stoneSvga.height / 2 + props.boomPosition1Offset[1];
\n\t
_this.waterSvga.x = _this.player.width / 2 - _this.waterSvga.width / 2 + props.boomPosition2Offset[0];
\n\t
_this.waterSvga.y = _this.player.height / 2 - _this.waterSvga.height / 2 + props.boomPosition2Offset[1];
\n\t
_this.boomSvga.x = _this.player.width / 2 - _this.boomSvga.width / 2 + props.boomPosition3Offset[0];
\n\t
_this.boomSvga.y = _this.player.height / 2 - _this.boomSvga.height / 2 + props.boomPosition3Offset[1];
\n\t
}, 300);
\n\t
this.rectBg = new engine.Container();
\n\t
this.rectBg.alpha = 0;
\n\t
this.rectBg.width = 750;
\n\t
this.rectBg.height = 1624;
\n\t
this.addChild(this.rectBg);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
\n\t
};
\n\t
GameView.prototype.reset = function () {
\n\t
this.score = props.speed;
\n\t
this.recycleGoods();
\n\t
this.player.x = 375 - this.player.width / 2;
\n\t
};
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
this.score = 0;
\n\t
this.speed = 1;
\n\t
this.gameIng = true;
\n\t
this.creatNpc();
\n\t
this.beginNpc();
\n\t
this.countdown = props.countDown;
\n\t
this.countdownTimer = setInterval(function () {
\n\t
if (_this.gameIng) {
\n\t
if (_this.countdown > 0) {
\n\t
engine.globalEvent.dispatchEvent('food-fell-time-update', {
\n\t
time: _this.countdown,
\n\t
});
\n\t
_this.countdown -= 1;
\n\t
}
\n\t
else {
\n\t
engine.globalEvent.dispatchEvent('food-fell-game-over', {
\n\t
score: _this.score,
\n\t
reason: 1
\n\t
});
\n\t
_this.died();
\n\t
}
\n\t
}
\n\t
}, 1000);
\n\t
};
\n\t
GameView.prototype.beginNpc = function () {
\n\t
var _this = this;
\n\t
this.timer = setTimeout(function () {
\n\t
if (_this.gameIng) {
\n\t
_this.speed += props.acceleratedSpeed;
\n\t
if (_this.speed >= props.maxSpeed) {
\n\t
_this.speed = props.maxSpeed;
\n\t
}
\n\t
_this.creatNpc();
\n\t
}
\n\t
_this.beginNpc();
\n\t
}, 2000 / this.speed);
\n\t
};
\n\t
GameView.prototype.pause = function () {
\n\t
this.gameIng = false;
\n\t
};
\n\t
GameView.prototype.revive = function () {
\n\t
this.gameIng = true;
\n\t
};
\n\t
GameView.prototype.resume = function () {
\n\t
this.reset();
\n\t
this.start();
\n\t
};
\n\t
GameView.prototype.creatNpc = function () {
\n\t
var _this = this;
\n\t
var goods = this._goods = ObjectPool$1.getObject(PoolName);
\n\t
this.goodsItems.push(goods);
\n\t
this.NpcBg.addChild(goods);
\n\t
goods.addEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
] = function () {
\n\t
if (goods.y > 1624) {
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
else {
\n\t
if (_this.gameIng) {
\n\t
goods.y += (4 * _this.speed);
\n\t
if (_this.hasHit(_this.player, goods)) {
\n\t
if (goods[
\"
npcType
\"
].indexOf(
\"
rain
\"
) > -1) {
\n\t
_this.score += props.rainScore;
\n\t
_this.waterSvga.visible = true;
\n\t
_this.waterSvga.play(false, false);
\n\t
_this.waterSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.waterSvga.visible = false;
\n\t
}, _this);
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
stone
\"
) {
\n\t
_this.score += props.stoneScore;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.stoneSvga.visible = true;
\n\t
_this.stoneSvga.play(false, false);
\n\t
_this.stoneSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.stoneSvga.visible = false;
\n\t
}, _this);
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
boom
\"
) {
\n\t
_this.boomSvga.visible = true;
\n\t
_this.boomSvga.play(false, false);
\n\t
_this.died();
\n\t
_this.boomSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.boomSvga.visible = false;
\n\t
engine.globalEvent.dispatchEvent('food-fell-game-over', {
\n\t
score: _this.score,
\n\t
reason: 2
\n\t
});
\n\t
}, _this);
\n\t
}
\n\t
engine.globalEvent.dispatchEvent('food-fell-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
}
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.died = function () {
\n\t
this.pause(
);
\n\t
};
\n\t
GameView.prototype.removeNpc = function (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
var index = this.goodsItems.indexOf(goods);
\n\t
if (index > -1) {
\n\t
this.goodsItems.splice(index, 1);
\n\t
}
\n\t
};
\n\t
GameView.prototype.recycleGoods = function () {
\n\t
clearTimeout(this.timer);
\n\t
clearInterval(this.countdownTimer);
\n\t
for (var _i = 0, _a = this.goodsItems; _i < _a.length; _i++) {
\n\t
var goods = _a[_i];
\n\t
if (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
}
\n\t
}
\n\t
this.goodsItems = [];
\n\t
};
\n\t
GameView.prototype.hasHit = function (a, b) {
\n\t
var playerH = a.height;
\n\t
var playerW = a.width;
\n\t
var playerX = a.x;
\n\t
if (props.playerHeight) {
\n\t
playerH = props.playerHeight;
\n\t
}
\n\t
if (props.playerWidth) {
\n\t
playerW = props.playerWidth;
\n\t
playerX = a.x + (a.width - props.playerWidth) / 2;
\n\t
}
\n\t
if (Math.abs((playerX + playerW / 2) - (b.x + b.width / 2)) < playerW / 2 + b.width / 2
\n\t
&&
\n\t
Math.abs((a.y + playerH / 1.3) - (b.y + b.height / 2)) < playerH / 2 + b.height / 2) {
\n\t
return true;
\n\t
}
\n\t
else {
\n\t
return false;
\n\t
}
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var 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('food-fell-reset', _this.reset, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-pause', _this.pause, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-resume', _this.resume, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-revive', _this.revive, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-clear', _this.clear, _this);
\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.onTap, _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
injectProps(event.data);
\n\t
this._status = 1;
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.pause = function () {
\n\t
this._gameView.pause();
\n\t
};
\n\t
GameWrapper.prototype.resume = function () {
\n\t
this._gameView.resume();
\n\t
};
\n\t
GameWrapper.prototype.revive = function () {
\n\t
this._gameView.revive();
\n\t
};
\n\t
GameWrapper.prototype.clear = function () {
\n\t
this._gameView.visible = false;
\n\t
};
\n\t
GameWrapper.prototype.onTap = function (event) {
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
function 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\t
return index;
\n\n
})));
\n
"
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global['food-fell2'] = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\t
//# sourceMappingURL=props.js.map
\n\n\t
function getTextureByName(name) {
\n\t
return engine.Texture.from(
engine.getAssetByName(name).uuid);
\n\t
}
\n\t
function 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\t
var Goods = (function (_super) {
\n\t
tslib.__extends(Goods, _super);
\n\t
function Goods() {
\n\t
var _this = _super.call(this) || this;
\n\t
var body;
\n\t
body = _this._body = new engine.Rect();
\n\t
var rain = new engine.Sprite(getTextureByName('雨滴0'));
\n\t
var rain1 = new engine.Sprite(getTextureByName('雨滴1'));
\n\t
var rain2 = new engine.Sprite(getTextureByName('雨滴2'));
\n\t
rain[
\"
npcType
\"
] =
\"
rain0
\"
;
\n\t
rain1[
\"
npcType
\"
] =
\"
rain1
\"
;
\n\t
rain2[
\"
npcType
\"
] =
\"
rain2
\"
;
\n\t
var stone = new engine.Sprite(getTextureByName('石块'));
\n\t
stone[
\"
npcType
\"
] =
\"
stone
\"
;
\n\t
var boom = new engine.Sprite(getTextureByName('炸弹'));
\n\t
boom[
\"
npcType
\"
] =
\"
boom
\"
;
\n\t
rain.visible = false;
\n\t
rain1.visible = false;
\n\t
rain2.visible = false;
\n\t
stone.visible = false;
\n\t
boom.visible = false;
\n\t
body.addChild(rain);
\n\t
body.addChild(rain1);
\n\t
body.addChild(rain2);
\n\t
body.addChild(stone);
\n\t
body.addChild(boom);
\n\t
_this.addChild(body);
\n\t
body.width = .0001;
\n\t
body.height = .0001;
\n\t
body.mouseEnabled = false;
\n\t
return _this;
\n\t
}
\n\t
Goods.prototype.getRandomNumberByRange = function (start, end) {
\n\t
return Math.floor(Math.random() * (end - start) + start);
\n\t
};
\n\t
Goods.prototype.reset = function () {
\n\t
this.visible = true;
\n\t
this.rotation = 0;
\n\t
this.anchorOffsetY = 0;
\n\t
this.y = 0;
\n\t
this.x = (750 - 120) * Math.random() + 30;
\n\t
this.rotation = 0;
\n\t
var random = Math.random();
\n\t
if (typeof (props.goodsProbability) == 'string') {
\n\t
props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; });
\n\t
}
\n\t
if (random < props.goodsProbability[0]) {
\n\t
var randomNum = Math.floor(Math.random() * 3);
\n\t
this.showNpc(
\"
rain
\"
+ randomNum);
\n\t
}
\n\t
else if (random >= props.goodsProbability[0] && random <= (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
stone
\"
);
\n\t
}
\n\t
else if (random > (props.goodsProbability[0] + props.goodsProbability[1])) {
\n\t
this.showNpc(
\"
boom
\"
);
\n\t
}
\n\t
};
\n\t
Goods.prototype.showNpc = function (type) {
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
this._body.children[i].visible = false;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
for (var i = 0; i < this._body.children.length; i++) {
\n\t
if (this._body.children[i][
\"
npcType
\"
] == type) {
\n\t
this[
\"
npcType
\"
] = type;
\n\t
this._body.children[i].visible = true;
\n\t
this._body.children[i].mouseEnabled = false;
\n\t
}
\n\t
}
\n\t
};
\n\t
Object.defineProperty(Goods.prototype,
\"
anchorOffsetY
\"
, {
\n\t
set: function (v) {
\n\t
this._body.y = v;
\n\t
},
\n\t
enumerable: true,
\n\t
configurable: true
\n\t
});
\n\t
return Goods;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=Goods.js.map
\n\n\t
var ObjectPool = engine.ObjectPool;
\n\t
var PoolName = 'goods';
\n\t
ObjectPool.registerPool(PoolName, function () {
\n\t
return new Goods();
\n\t
}, function (item, data) {
\n\t
item.reset();
\n\t
});
\n\t
//# sourceMappingURL=object-pool-init.js.map
\n\n\t
var ObjectPool$1 = engine.ObjectPool;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this.goodsItems = [];
\n\t
_this.viewVisible = true;
\n\t
_this.cacheTime = 0;
\n\t
_this.cacheTime2 = 0;
\n\t
_this.moveCatchX = 0;
\n\t
_this.playerCatchX = 0;
\n\t
_this.onDownStage = function (e) {
\n\t
_this.moveCatchX = e.localX;
\n\t
_this.playerCatchX = _this.player.x;
\n\t
};
\n\t
_this.onMoveStage = function (e) {
\n\t
var maxStageBound = props.maxStageBound;
\n\t
if (_this.gameIng) {
\n\t
var playerX = _this.playerCatchX + (e.localX - _this.moveCatchX);
\n\t
if (playerX < maxStageBound) {
\n\t
_this.player.x = maxStageBound;
\n\t
}
\n\t
else if (playerX + _this.player.width + maxStageBound > 750) {
\n\t
_this.player.x = 750 - maxStageBound - _this.player.width;
\n\t
}
\n\t
else {
\n\t
_this.player.x = playerX;
\n\t
}
\n\t
}
\n\t
};
\n\t
_this.onOutStage = function (e) {
\n\t
_this.moveCatchX = 0;
\n\t
};
\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
var _this = this;
\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.alpha = 1;
\n\t
this.NpcBg.width = 0;
\n\t
this.NpcBg.height = 0;
\n\t
this.addChild(this.NpcBg);
\n\t
this.player = new engine.Container();
\n\t
this.player.mouseEnabled = false;
\n\t
this.addChild(this.player);
\n\t
this.waterSvga = createSvga(
\"
水花
\"
);
\n\t
this.stoneSvga = createSvga(
\"
石头svga
\"
);
\n\t
this.playerSvga = new engine.Sprite(getTextureByName('玩家'));
\n\t
this.boomSvga = createSvga(
\"
炸弹svga
\"
);
\n\t
this.player.addChild(this.playerSvga);
\n\t
this.player.addChild(this.stoneSvga);
\n\t
this.player.addChild(this.waterSvga);
\n\t
this.player.addChild(this.boomSvga);
\n\t
this.waterSvga.visible = false;
\n\t
this.stoneSvga.visible = false;
\n\t
this.boomSvga.visible = false;
\n\t
this.visible = false;
\n\t
setTimeout(function () {
\n\t
_this.visible = true;
\n\t
_this.player.anchorY = _this.player.height / 2;
\n\t
_this.player.anchorX = _this.player.width / 2;
\n\t
_this.player.x = 375 - _this.player.width / 2;
\n\t
_this.player.y = props.playerPositionY;
\n\t
_this.stoneSvga.x = _this.player.width / 2 - _this.stoneSvga.width / 2 + props.boomPosition1Offset[0];
\n\t
_this.stoneSvga.y = _this.player.height / 2 - _this.stoneSvga.height / 2 + props.boomPosition1Offset[1];
\n\t
_this.waterSvga.x = _this.player.width / 2 - _this.waterSvga.width / 2 + props.boomPosition2Offset[0];
\n\t
_this.waterSvga.y = _this.player.height / 2 - _this.waterSvga.height / 2 + props.boomPosition2Offset[1];
\n\t
_this.boomSvga.x = _this.player.width / 2 - _this.boomSvga.width / 2 + props.boomPosition3Offset[0];
\n\t
_this.boomSvga.y = _this.player.height / 2 - _this.boomSvga.height / 2 + props.boomPosition3Offset[1];
\n\t
}, 300);
\n\t
this.rectBg = new engine.Container();
\n\t
this.rectBg.alpha = 0;
\n\t
this.rectBg.width = 750;
\n\t
this.rectBg.height = 1624;
\n\t
this.addChild(this.rectBg);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
\n\t
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
\n\t
document.addEventListener(
\"
visibilitychange
\"
, function () {
\n\t
if (document.visibilityState ==
\"
visible
\"
) {
\n\t
_this.viewVisible = true;
\n\t
}
\n\t
if (document.visibilityState ==
\"
hidden
\"
) {
\n\t
_this.viewVisible = false;
\n\t
}
\n\t
});
\n\t
this.addEventListener(engine.Event.ENTER_FRAME, this.enterFrame, this);
\n\t
};
\n\t
GameView.prototype.enterFrame = function () {
\n\t
this.updateTime();
\n\t
this.updateTimeBeginNpc();
\n\t
};
\n\t
GameView.prototype.reset = function () {
\n\t
this.score = props.speed;
\n\t
this.recycleGoods();
\n\t
this.player.x = 375 - this.player.width / 2;
\n\t
};
\n\t
GameView.prototype.start = function () {
\n\t
this.score = 0;
\n\t
this.speed = 1;
\n\t
this.gameIng = true;
\n\t
this.beginNpc();
\n\t
this.countdown = props.countDown;
\n\t
};
\n\t
GameView.prototype.updateTime = function () {
\n\t
if (Date.now() - this.cacheTime > 1000) {
\n\t
this.cacheTime = Date.now();
\n\t
}
\n\t
else {
\n\t
return;
\n\t
}
\n\t
if (this.gameIng) {
\n\t
if (this.countdown > 0) {
\n\t
engine.globalEvent.dispatchEvent('food-fell-time-update', {
\n\t
time: this.countdown,
\n\t
});
\n\t
this.countdown -= 1;
\n\t
}
\n\t
else {
\n\t
engine.globalEvent.dispatchEvent('food-fell-game-over', {
\n\t
score: this.score,
\n\t
reason: 1
\n\t
});
\n\t
this.died();
\n\t
}
\n\t
}
\n\t
};
\n\t
GameView.prototype.beginNpc = function () {
\n\t
};
\n\t
GameView.prototype.updateTimeBeginNpc = function () {
\n\t
if (Date.now() - this.cacheTime2 > (2000 / this.speed)) {
\n\t
this.cacheTime2 = Date.now();
\n\t
}
\n\t
else {
\n\t
return;
\n\t
}
\n\t
if (this.gameIng) {
\n\t
this.speed += props.acceleratedSpeed;
\n\t
if (this.speed >= props.maxSpeed) {
\n\t
this.speed = props.maxSpeed;
\n\t
}
\n\t
this.creatNpc();
\n\t
}
\n\t
};
\n\t
GameView.prototype.pause = function () {
\n\t
this.gameIng = false;
\n\t
};
\n\t
GameView.prototype.revive = function () {
\n\t
this.gameIng = true;
\n\t
};
\n\t
GameView.prototype.resume = function () {
\n\t
this.reset();
\n\t
this.start();
\n\t
};
\n\t
GameView.prototype.creatNpc = function () {
\n\t
var _this = this;
\n\t
var goods = this._goods = ObjectPool$1.getObject(PoolName);
\n\t
this.goodsItems.push(goods);
\n\t
this.NpcBg.addChild(goods);
\n\t
goods.addEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
] = function () {
\n\t
if (goods.y > 1624) {
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
else {
\n\t
if (_this.gameIng) {
\n\t
goods.y += (4 * _this.speed);
\n\t
if (_this.hasHit(_this.player, goods)) {
\n\t
if (goods[
\"
npcType
\"
].indexOf(
\"
rain
\"
) > -1) {
\n\t
_this.score += props.rainScore;
\n\t
_this.waterSvga.visible = true;
\n\t
_this.waterSvga.play(false, false);
\n\t
_this.waterSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.waterSvga.visible = false;
\n\t
}, _this);
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
stone
\"
) {
\n\t
_this.score += props.stoneScore;
\n\t
if (_this.score < 0) {
\n\t
_this.score = 0;
\n\t
}
\n\t
_this.stoneSvga.visible = true;
\n\t
_this.stoneSvga.play(false, false);
\n\t
_this.stoneSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.stoneSvga.visible = false;
\n\t
}, _this);
\n\t
}
\n\t
else if (goods[
\"
npcType
\"
] ==
\"
boom
\"
) {
\n\t
_this.boomSvga.visible = true;
\n\t
_this.boomSvga.play(false, false);
\n\t
_this.died();
\n\t
_this.boomSvga.once(engine.Event.END_FRAME, function () {
\n\t
_this.boomSvga.visible = false;
\n\t
engine.globalEvent.dispatchEvent('food-fell-game-over', {
\n\t
score: _this.score,
\n\t
reason: 2
\n\t
});
\n\t
}, _this);
\n\t
}
\n\t
engine.globalEvent.dispatchEvent('food-fell-score-update', {
\n\t
score: _this.score,
\n\t
});
\n\t
_this.removeNpc(goods);
\n\t
}
\n\t
}
\n\t
}
\n\t
}, this);
\n\t
};
\n\t
GameView.prototype.died = function () {
\n\t
this.pause();
\n\t
setTimeout(function () {
\n\t
engine.globalEvent.dispatchEvent('food-fell-reset', {
\n\t
\"
goodsProbability
\"
:
\"
0.8,0.1,0.1
\"
,
\n\t
\"
countDown
\"
: 30,
\n\t
\"
acceleratedSpeed
\"
: 0.1
\n\t
});
\n\t
engine.globalEvent.dispatchEvent('food-fell-start');
\n\t
}, 2000
);
\n\t
};
\n\t
GameView.prototype.removeNpc = function (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
var index = this.goodsItems.indexOf(goods);
\n\t
if (index > -1) {
\n\t
this.goodsItems.splice(index, 1);
\n\t
}
\n\t
};
\n\t
GameView.prototype.recycleGoods = function () {
\n\t
clearTimeout(this.timer);
\n\t
clearInterval(this.countdownTimer);
\n\t
for (var _i = 0, _a = this.goodsItems; _i < _a.length; _i++) {
\n\t
var goods = _a[_i];
\n\t
if (goods) {
\n\t
this.NpcBg.removeChild(goods);
\n\t
ObjectPool$1.recycleObject(PoolName, goods);
\n\t
goods.removeEventListener(engine.Event.ENTER_FRAME, goods[
\"
onGoodsEnter
\"
], this);
\n\t
}
\n\t
}
\n\t
this.goodsItems = [];
\n\t
};
\n\t
GameView.prototype.hasHit = function (a, b) {
\n\t
var playerH = a.height;
\n\t
var playerW = a.width;
\n\t
var playerX = a.x;
\n\t
if (props.playerHeight) {
\n\t
playerH = props.playerHeight;
\n\t
}
\n\t
if (props.playerWidth) {
\n\t
playerW = props.playerWidth;
\n\t
playerX = a.x + (a.width - props.playerWidth) / 2;
\n\t
}
\n\t
if (Math.abs((playerX + playerW / 2) - (b.x + b.width / 2)) < playerW / 2 + b.width / 2
\n\t
&&
\n\t
Math.abs((a.y + playerH / 1.3) - (b.y + b.height / 2)) < playerH / 2 + b.height / 2) {
\n\t
return true;
\n\t
}
\n\t
else {
\n\t
return false;
\n\t
}
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var 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('food-fell-reset', _this.reset, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-pause', _this.pause, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-resume', _this.resume, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-revive', _this.revive, _this);
\n\t
engine.globalEvent.addEventListener('food-fell-clear', _this.clear, _this);
\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.onTap, _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
injectProps(event.data);
\n\t
this._status = 1;
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.pause = function () {
\n\t
this._gameView.pause();
\n\t
};
\n\t
GameWrapper.prototype.resume = function () {
\n\t
this._gameView.resume();
\n\t
};
\n\t
GameWrapper.prototype.revive = function () {
\n\t
this._gameView.revive();
\n\t
};
\n\t
GameWrapper.prototype.clear = function () {
\n\t
this._gameView.visible = false;
\n\t
};
\n\t
GameWrapper.prototype.onTap = function (event) {
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
function 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\t
return index;
\n\n
})));
\n
"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment