Commit 088c4d2b authored by spc's avatar spc

modified: dist/customs/answer-game.json

parent 2c83eaea
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "套圈",
"desc": "套圈模块",
"props": {
"ferruleModuleGlobalPosition": {
"alias": "套圈模块的位置",
"type": "array<number>",
"default": "0,0"
},
"ferruleModuleWidthHeight": {
"alias": "套圈模块的宽高",
"type": "array<number>",
"default": "750,450"
}
},
"assets": [
{
"name": "圈",
"url": "//yun.duiba.com.cn/aurora/assets/668313c9b296603cbfd24f92c3683c41df0aa1e9.png",
"uuid": "c1fc9984-900f-44e0-87e5-128e7ccdfb62",
"ext": ".png"
},
{
"name": "礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/3b13cb2a324c05e3bef2c27f1fd27b5fe49a0ea3.png",
"uuid": "e3ee8791-880f-4408-9f31-2f5faa75d044",
"ext": ".png"
},
{
"name": "套中动效",
"url": "//yun.duiba.com.cn/aurora/assets/8b650dd07a82a1357f0572e1201a9834e8b7d302.svga",
"uuid": "5e569c9c-a1e4-44df-83eb-9249e00e228b",
"ext": ".svga"
}
],
"events": {
"in": {
"circle-game-start": {
"alias": "开始"
},
"circle-game-init": {
"alias": "初始化"
}
},
"out": {
"circle-game-end": {
"alias": "套圈完毕",
"data": {
"reason": "套圈结束,执行抽奖"
}
}
}
},
"id": "circle",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof define === 'function' && define.amd ? define(['tslib'], factory) :\n\t(global = global || self, global.circle = factory(global.tslib));\n}(this, (function (tslib) { 'use strict';\n\n\tfunction getTexture(uuid) {\n\t return engine.Texture.from(getAssetByUUID(uuid).uuid);\n\t}\n\tfunction getTextureByName(name) {\n\t console.log('name', engine.getAssetByName(name));\n\t return getTexture(engine.getAssetByName(name).uuid);\n\t}\n\tfunction createSvga(name, anchorName) {\n\t var inst = new svga.Svga();\n\t inst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\t return inst;\n\t}\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\n\tvar Gameinit = (function (_super) {\n\t tslib.__extends(Gameinit, _super);\n\t function Gameinit() {\n\t var _this = _super.call(this) || this;\n\t _this._isSetUp = false;\n\t _this.totleY = 1200;\n\t _this.isMove = false;\n\t _this.isChoose = true;\n\t _this.isDid = true;\n\t _this.listGift = [];\n\t console.log(\"11111111111111\");\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t return _this;\n\t }\n\t Gameinit.prototype.setup = function () {\n\t console.log(\"初始化加载000000000000000000000000!\");\n\t if (this._isSetUp) {\n\t return;\n\t }\n\t else {\n\t this.loadThings();\n\t console.log(\"this._isSetUp=\", this._isSetUp, '<<<<');\n\t }\n\t };\n\t Gameinit.prototype.loadThings = function () {\n\t var self = this;\n\t var body;\n\t body = this._body = new engine.Rect;\n\t body.width = 0.0001;\n\t body.height = 0.0001;\n\t this.addChild(body);\n\t var gift0 = this.addRes(body, '礼盒', 250, 100, 247, 188);\n\t var gift1 = this.addRes(body, '礼盒', 485, 85, 247, 190);\n\t var gift2 = this.addRes(body, '礼盒', 385, -15, 222, 170);\n\t var gift3 = this.addRes(body, '礼盒', 165, -15, 222, 170);\n\t var gift4 = this.addRes(body, '礼盒', 20, 85, 247, 190);\n\t this.listGift = [gift0, gift1, gift2, gift3, gift4];\n\t var circle = this.addRes(body, '圈', 260, 350, 240, 80);\n\t var giftSvga = createSvga(\"套中动效\");\n\t giftSvga.visible = false;\n\t body.addChild(giftSvga);\n\t var _a = props.ferruleModuleGlobalPosition, v2X = _a[0], v2Y = _a[1];\n\t body.x = v2X;\n\t body.y = v2Y;\n\t engine.globalEvent.addEventListener(\"circle-game-start\", function () {\n\t self.isMove = true;\n\t console.log('this.isMove===', self.isMove);\n\t }, this);\n\t engine.globalEvent.addEventListener(\"circle-game-init\", function () {\n\t self.isChoose = true;\n\t giftSvga.visible = false;\n\t body.children[self.num].visible = true;\n\t circle.x = 260;\n\t circle.y = 350;\n\t circle.width = 240;\n\t circle.height = 80;\n\t circle.visible = true;\n\t }, this);\n\t circle.addEventListener(engine.Event.ENTER_FRAME, function () {\n\t if (self.isMove) {\n\t console.log(\"物体移动\");\n\t if (self.isChoose) {\n\t self.num = Math.floor(Math.random() * self.listGift.length);\n\t self.isChoose = false;\n\t }\n\t self.nodeMove(circle, self.listGift[self.num], giftSvga);\n\t }\n\t });\n\t };\n\t Gameinit.prototype.aniPlay = function (node0, targetNode, bool) {\n\t node0.scaleX = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);\n\t node0.scaleY = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);\n\t node0.x = targetNode.x;\n\t node0.y = targetNode.y;\n\t node0.visible = true;\n\t node0.play(false, false);\n\t node0.addEventListener(engine.Event.END_FRAME, function () {\n\t console.log(\"播放到最后一帧\", bool, '<<<');\n\t engine.globalEvent.dispatchEvent(\"circle-game-end\");\n\t bool = false;\n\t });\n\t };\n\t Gameinit.prototype.addRes = function (fatherNode, resName, v2X, v2Y, resW, resH) {\n\t console.log(\"进行资源的添加\");\n\t var thing = new engine.Sprite(getTextureByName(resName));\n\t thing.x = v2X;\n\t thing.y = v2Y;\n\t thing.width = resW;\n\t thing.height = resH;\n\t return fatherNode.addChild(thing);\n\t };\n\t Gameinit.prototype.nodeMove = function (moveNode, targetNode, nodePlay) {\n\t console.log(\"moveNode.x=\", moveNode.x, \"targetNode.x=\", targetNode.x);\n\t var moveX = targetNode.x - moveNode.x;\n\t var moveY = targetNode.y - moveNode.y;\n\t console.log('moveX=', moveX, 'moveY=', moveY);\n\t if (this.isDid) {\n\t if (Math.abs(moveX) > 2) {\n\t moveNode.x += moveX / Math.abs(moveX) * 5;\n\t }\n\t if (Math.abs(moveY) > 2) {\n\t moveNode.y += moveY / Math.abs(moveY) * 5;\n\t moveNode.scaleX = this.currentScale(moveNode.y, this.totleY) + 0.2;\n\t moveNode.scaleY = moveNode.scaleX;\n\t }\n\t if (Math.abs(moveX) < 3 && Math.abs(moveY) < 3) {\n\t targetNode.visible = false;\n\t moveNode.visible = false;\n\t this.aniPlay(nodePlay, targetNode, this.isDid);\n\t this.isMove = false;\n\t }\n\t }\n\t };\n\t Gameinit.prototype.currentScale = function (currentY, totoleDisY) {\n\t return (currentY + 830) / totoleDisY;\n\t };\n\t return Gameinit;\n\t}(engine.Container));\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new Gameinit();\n\t return instance;\n\t}\n\n\treturn index;\n\n})));\n"
}
This diff is collapsed.
......@@ -12,7 +12,6 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var SubjectManager = (function () {
function SubjectManager() {
......@@ -64,7 +63,6 @@
};
return SubjectManager;
}());
//# sourceMappingURL=SubjectManager.js.map
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
......@@ -86,7 +84,6 @@
GameState[GameState["STATE_START"] = 0] = "STATE_START";
GameState[GameState["STATE_END"] = 1] = "STATE_END";
})(GameState || (GameState = {}));
//# sourceMappingURL=utils.js.map
var Background = (function (_super) {
tslib.__extends(Background, _super);
......@@ -133,7 +130,6 @@
};
return Background;
}(engine.Container));
//# sourceMappingURL=Background.js.map
var SvgaManager = (function () {
function SvgaManager() {
......@@ -167,7 +163,6 @@
};
return SvgaManager;
}());
//# sourceMappingURL=SvgaManager.js.map
var SubjectTitle = (function (_super) {
tslib.__extends(SubjectTitle, _super);
......@@ -435,7 +430,6 @@
};
return SubjectTitle;
}(engine.Container));
//# sourceMappingURL=SubjectTitle.js.map
var AnswerArea = (function (_super) {
tslib.__extends(AnswerArea, _super);
......@@ -812,7 +806,6 @@
};
return AnswerArea;
}(engine.Container));
//# sourceMappingURL=answerArea.js.map
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
......@@ -849,7 +842,6 @@
};
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
......@@ -891,7 +883,6 @@
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
......@@ -899,7 +890,6 @@
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -10,7 +10,6 @@
function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
//# sourceMappingURL=utils.js.map
var GameTest = (function (_super) {
tslib.__extends(GameTest, _super);
......@@ -100,8 +99,10 @@
radius: 1 / this.factor,
});
var boardPointBody = new p2.Body({
position: [100 / this.factor,]
position: [100 / this.factor, 800 / this.factor]
});
boardPointBody.addShape(boardPoint);
boardPointBody.displays = [];
var boxShape = new p2.Circle({ radius: 60 / this.factor });
this.boxBody = new p2.Body({
mass: 0.1,
......@@ -192,7 +193,6 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
......@@ -213,7 +213,6 @@
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
......@@ -221,7 +220,6 @@
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This diff is collapsed.
......@@ -12,7 +12,6 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var ObjectPool = engine.ObjectPool;
var Road = (function (_super) {
......@@ -118,7 +117,6 @@
};
return Road;
}(engine.Container));
//# sourceMappingURL=Road.js.map
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
......@@ -134,7 +132,6 @@
inst.source = engine.getAssetByName(name).uuid;
return inst;
}
//# sourceMappingURL=utils.js.map
var GuideLayer = (function (_super) {
tslib.__extends(GuideLayer, _super);
......@@ -178,7 +175,6 @@
};
return GuideLayer;
}(engine.Container));
//# sourceMappingURL=GuideLayer.js.map
var LoopComponent = (function (_super) {
tslib.__extends(LoopComponent, _super);
......@@ -254,7 +250,6 @@
};
return LoopComponent;
}(engine.Container));
//# sourceMappingURL=LoopComponent.js.map
var Background = (function (_super) {
tslib.__extends(Background, _super);
......@@ -330,7 +325,6 @@
};
return Background;
}(engine.Container));
//# sourceMappingURL=Background.js.map
var Pier = (function (_super) {
tslib.__extends(Pier, _super);
......@@ -401,7 +395,6 @@
};
return Pier;
}(engine.Container));
//# sourceMappingURL=Pier.js.map
var Player = (function (_super) {
tslib.__extends(Player, _super);
......@@ -479,7 +472,6 @@
};
return Player;
}(engine.Container));
//# sourceMappingURL=Player.js.map
var Strut = (function (_super) {
tslib.__extends(Strut, _super);
......@@ -575,7 +567,6 @@
};
return Strut;
}(engine.Container));
//# sourceMappingURL=Strut.js.map
var ObjectPool$1 = engine.ObjectPool;
var PoolName = 'pier';
......@@ -808,7 +799,6 @@
GameView.speed = 20;
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
......@@ -840,7 +830,6 @@
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
......@@ -848,7 +837,6 @@
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,7 +16,6 @@
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
//# sourceMappingURL=utils.js.map
var props = {};
function prepareProps() {
......@@ -26,7 +25,6 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var Gameinit = (function (_super) {
tslib.__extends(Gameinit, _super);
......@@ -153,7 +151,6 @@
var instance = new Gameinit();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This diff is collapsed.
......@@ -29,9 +29,9 @@
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<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="http://localhost:4002/debug/engine.js"></script> -->
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
......
......@@ -12,6 +12,7 @@
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
function getTextureByName(name) {
return engine.Texture.from(getAssetByName(name).uuid);
......@@ -34,16 +35,23 @@
function playSound(name) {
engine.playSound(getAssetByName(name).uuid, { keep: true });
}
//# sourceMappingURL=utils.js.map
var Block = (function (_super) {
tslib.__extends(Block, _super);
function Block() {
var _this = _super.call(this) || this;
var body = _this.body = new svga.Svga();
var _this_1 = _super.call(this) || this;
_this_1._deltaTime = 0;
_this_1.startTime = 0;
_this_1.lastTime = 0;
_this_1.curTime = 0;
_this_1.per = 0;
var body = _this_1.body = new svga.Svga();
body.x = -props.blockWidth / 2;
body.y = -props.blockHitHeight - props.blockPaddingTop;
_this.addChild(body);
return _this;
_this_1.addChild(body);
_this_1.addEventListener(engine.Event.ENTER_FRAME, _this_1.onEnterFrame, _this_1);
return _this_1;
}
Block.prototype.reset = function (_a) {
var type = _a.type;
......@@ -56,25 +64,52 @@
this.scaleX = this.dir;
this.body.gotoAndStop(1);
};
Block.prototype.onEnterFrame = function () {
this.lastTime = this.curTime;
this.curTime = Date.now() - this.startTime;
this._deltaTime = this.curTime - this.lastTime;
this._deltaTime = this._deltaTime < 0 ? 0 : this._deltaTime;
var offMoveX = this.per * this._deltaTime;
if (this.per < 0) {
if (this.x + offMoveX > 0) {
this.x += offMoveX;
}
else {
this.x = 0;
}
}
else {
if (this.x + offMoveX < 0) {
this.x += offMoveX;
}
else {
this.x = 0;
}
}
};
Block.prototype.playEnter = function (index, animation) {
var _this_1 = this;
var _this = this;
this.visible = true;
this.x = this.dir * this.stage.width;
var _a = props.blockDurationRange, min = _a[0], max = _a[1];
var duration = Math.max(max - index * props.blockDurationStep, min);
duration = duration + max * Math.random() * props.blockDurationRandom * (Math.random() > 0.5 ? 1 : -1);
var offX = 0 - this.x;
this.per = offX / duration;
return new Promise(function (resolve) {
if (animation) {
engine.Tween.get(_this, null, null, true)
.to({ x: 0, }, duration)
.call(resolve);
_this.startTime = Date.now();
setTimeout(function () {
resolve(1);
}, duration);
}
else {
_this.x = 0;
_this_1.x = 0;
setTimeout(function () {
console.log(_this.body);
console.log(_this_1.body);
}, 200);
resolve();
resolve(1);
}
});
};
......@@ -89,10 +124,11 @@
}, this);
};
Block.prototype.stop = function () {
engine.Tween.removeTweens(this);
this.removeEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
};
return Block;
}(engine.Container));
//# sourceMappingURL=Block.js.map
var Background = (function (_super) {
tslib.__extends(Background, _super);
......@@ -121,6 +157,7 @@
};
return Background;
}(engine.Container));
//# sourceMappingURL=Background.js.map
var svgaAssets = {
aniReady: { name: '准备立正', dir: 1 },
......@@ -136,6 +173,10 @@
function Player() {
var _this = _super.call(this) || this;
_this.g = props.gravity;
_this._deltaTime = 0;
_this.startTime = 0;
_this.lastTime = 0;
_this.curTime = 0;
_this.addEventListener(engine.Event.ENTER_FRAME, _this.onEnterFrame, _this);
return _this;
}
......@@ -157,7 +198,7 @@
if (play) {
ani.play(false, loop);
if (loop) {
resolve();
resolve(1);
}
else {
ani.once(engine.Event.END_FRAME, resolve);
......@@ -165,7 +206,7 @@
}
else {
ani.gotoAndStop(1);
resolve();
resolve(1);
}
}
});
......@@ -196,7 +237,7 @@
_this.switchAni('Ready', 1);
_this._currentAni.once(engine.Event.END_FRAME, function () {
this.switchAni('Jump', 1, false);
resolve();
resolve(1);
}, _this);
});
};
......@@ -204,8 +245,12 @@
if (!this.playing) {
return;
}
this.vy += this.g;
this.y += this.vy;
this.lastTime = this.curTime;
this.curTime = Date.now() - this.startTime;
this._deltaTime = this.curTime - this.lastTime;
this._deltaTime = this._deltaTime < 0 ? 0 : this._deltaTime;
this.vy += this.g * this._deltaTime / 16;
this.y += this.vy * this._deltaTime / 16;
if (this.vy > 0 && this._aniName !== 'Fall') {
this.dispatchEvent('jump-on-top');
this.switchAni('Fall');
......@@ -235,6 +280,7 @@
this.playing = true;
this.baseY = this.y;
this.vy = -props.jumpSpeed;
this.startTime = Date.now();
return new Promise(function (resolve) {
_this.jumpPromise = resolve;
});
......@@ -333,6 +379,7 @@
};
return Player;
}(engine.Container));
//# sourceMappingURL=Player.js.map
var Base = (function (_super) {
tslib.__extends(Base, _super);
......@@ -347,6 +394,7 @@
};
return Base;
}(engine.Image));
//# sourceMappingURL=Base.js.map
var GuideLayer = (function (_super) {
tslib.__extends(GuideLayer, _super);
......@@ -399,6 +447,7 @@
};
return GuideLayer;
}(engine.Container));
//# sourceMappingURL=GuideLayer.js.map
var GoldBag = (function (_super) {
tslib.__extends(GoldBag, _super);
......@@ -437,6 +486,7 @@
};
return GoldBag;
}(engine.Container));
//# sourceMappingURL=GoldBag.js.map
var ObjectPool = engine.ObjectPool;
var PoolName = 'gold-bag';
......@@ -678,7 +728,7 @@
get: function () {
return this.index - props.initBlockCount + 1;
},
enumerable: true,
enumerable: false,
configurable: true
});
Object.defineProperty(GameView.prototype, "pos", {
......@@ -689,7 +739,7 @@
this._pos = v;
this.updatePos();
},
enumerable: true,
enumerable: false,
configurable: true
});
GameView.prototype.updatePos = function () {
......@@ -850,6 +900,7 @@
};
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var JumpHigh = (function (_super) {
tslib.__extends(JumpHigh, _super);
......@@ -889,6 +940,7 @@
};
return JumpHigh;
}(engine.Container));
//# sourceMappingURL=JumpHigh.js.map
function index (props) {
prepareProps();
......@@ -896,6 +948,7 @@
var instance = new JumpHigh();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* Created by rockyl on 2019-12-16.
*/
const customId = 'jump-high';
(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.globalEvent.addEventListener('update-game-status', (e) => {
console.log(e.type, e.data);
});
//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',
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('jump-high-start', {level: 1});
}, 500);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getAssetByName(name){
return getAssetByUUID(engine.getAssetByName(name).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: transparent;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<!-- <script src="http://localhost:4002/debug/engine.js"></script> -->
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<script src="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/0307ca8906e9f553e6873c346ae5c6ec3655db59.svga",
"uuid": "4e31f5d7-bd03-41a3-873c-3755fe4862e6",
"ext": '.svga'
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
import {getTextureByName} from "./utils";
export class Background extends engine.Container {
private _bg: engine.Image;
private _minScale: number;
constructor() {
super();
}
setup() {
const {width, height} = this.stage;
let bg = this._bg = new engine.Image(getTextureByName('背景图'));
bg.anchorX = bg.width / 2;
bg.anchorY = bg.height / 2;
bg.x = -(bg.width - width) / 2;
bg.y = -(bg.height - height) / 2;
this.addChild(bg);
this._minScale = width / bg.width;
}
playZoom(type: 'in' | 'out', duration = 700) {
return new Promise(resolve => {
let scale = type === 'in' ? 1 : this._minScale;
engine.Tween.get(this._bg, null, null, true)
.to({scaleX: scale, scaleY: scale}, duration, engine.Ease.cubicInOut)
.call(resolve);
})
}
}
/**
* Created by rockyl on 2020-01-21.
*/
import {getTextureByName} from "./utils";
import {props} from "../props";
export class Base extends engine.Image{
constructor(){
super(getTextureByName('底座'));
}
setup(){
this.x = -(this.width) / 2;
}
reset(){
this.y = - props.baseOffset;
}
}
/**
* Created by rockyl on 2018/8/17.
* 障碍块
*/
import { getBlockAsset } from "./utils";
import { props } from "../props";
export default class Block extends engine.Container {
private body: svga.Svga;
private _deltaTime = 0;
private startTime = 0;
private lastTime = 0;
private curTime = 0;
private per = 0;
type;
dir;
constructor() {
super();
let body = this.body = new svga.Svga();
body.x = -props.blockWidth / 2;
body.y = -props.blockHitHeight - props.blockPaddingTop;
this.addChild(body);
this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
}
reset({ type, }) {
this.dir = Math.random() > 0.5 ? 1 : -1;
if (this.type != type) {
this.type = type;
let asset = getBlockAsset(type);
this.body.source = 'asset://' + asset.uuid;
}
this.scaleX = this.dir;
this.body.gotoAndStop(1);
}
onEnterFrame() {
this.lastTime = this.curTime;
this.curTime = Date.now() - this.startTime;
this._deltaTime = this.curTime - this.lastTime;
this._deltaTime = this._deltaTime < 0 ? 0 : this._deltaTime;
var offMoveX = this.per * this._deltaTime;
if (this.per < 0) {
if (this.x + offMoveX > 0) {
this.x += offMoveX;
}
else {
this.x = 0;
}
}
else {
if (this.x + offMoveX < 0) {
this.x += offMoveX;
}
else {
this.x = 0;
}
}
}
playEnter(index, animation) {
let _this = this;
this.visible = true;
this.x = this.dir * this.stage.width;
const [min, max] = props.blockDurationRange;
let duration = Math.max(max - index * props.blockDurationStep, min);
duration = duration + max * Math.random() * props.blockDurationRandom * (Math.random() > 0.5 ? 1 : -1);
let offX = 0 - this.x;
this.per = offX / duration;
return new Promise(resolve => {
if (animation) {
_this.startTime = Date.now();
setTimeout(function () {
resolve(1);
}, duration);
} else {
this.x = 0;
setTimeout(() => {
console.log(this.body);
}, 200);
resolve(1);
}
})
}
playLeave() {
this.visible = false;
}
playEffect() {
let body = this.body;
body.play(true, false);
body.once(engine.Event.END_FRAME, function () {
body.gotoAndStop(1);
}, this);
}
stop() {
this.removeEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
}
}
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
import {props} from '../props'
import {createSvga, getTextureByName} from "./utils";
export class GoldBag extends engine.Container {
private svga: svga.Svga;
private avatar: engine.Sprite;
remain: number;
constructor() {
super();
this.setup();
}
setup() {
let avatar = this.avatar = new engine.Sprite(getTextureByName('钱袋-静态'));
avatar.x = -props.goldPackAvatarAnchor.x;
avatar.y = -props.goldPackAvatarAnchor.y;
this.addChild(avatar);
let svga = this.svga = createSvga('钱袋', 'goldPackAnchor');
svga.visible = false;
this.addChild(svga);
}
reset(data) {
this.y = data.y;
this.avatar.visible = true;
this.svga.visible = false;
this.svga.gotoAndStop(1);
this.remain = data.remain;
}
playOpen() {
this.avatar.visible = false;
this.svga.visible = true;
return new Promise(resolve => {
this.svga.play(true, false);
this.svga.once(engine.Event.END_FRAME, function () {
this.svga.visible = false;
resolve();
}, this);
})
}
}
/**
* Created by rockyl on 2020-01-30.
*/
import {props} from "../props";
import {getTextureByName} from "./utils";
export class GuideLayer extends engine.Container {
private guideMask: engine.Container;
private label: engine.Label;
constructor() {
super();
this.setup();
}
private setup() {
}
show(id, options) {
return new Promise(resolve => {
this.visible = true;
if (!this.guideMask) {
const {width, height} = this.stage;
let guideMask = this.guideMask = new engine.Container();
let guideHole = new engine.Image(getTextureByName('引导遮罩'));
guideHole.x = (width - guideHole.width) / 2;
guideHole.y = options.y;
guideMask.addChild(guideHole);
this.createRect(guideMask, 0, 0, width, guideHole.y);
this.createRect(guideMask, 0, guideHole.y, guideHole.x, guideHole.height);
this.createRect(guideMask, guideHole.x + guideHole.width, guideHole.y, width - guideHole.x - guideHole.width, guideHole.height);
this.createRect(guideMask, 0, guideHole.y + guideHole.height, width, height - guideHole.y - guideHole.height);
let label = this.label = new engine.Label();
label.fillColor = 'white';
label.size = 25;
label.text = props.guideText;
label.x = (width - label.width) / 2;
label.y = guideHole.y + guideHole.height + 50;
guideMask.addChild(label);
this.addChild(guideMask);
}
this.once(engine.MouseEvent.CLICK, function(){
this.visible = false;
resolve();
}, this);
})
}
createRect(container, x, y, width, height) {
let rect = new engine.Rect();
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height;
rect.fillColor = 'black';
rect.alpha = 0.7;
container.addChild(rect);
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class JumpHigh extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('jump-high-reset', this.reset, this);
engine.globalEvent.addEventListener('jump-high-start', this.start, this);
engine.globalEvent.addEventListener('jump-high-pause', this.pause, this);
engine.globalEvent.addEventListener('jump-high-resume', this.resume, this);
engine.globalEvent.addEventListener('jump-high-revive', this.revive, this);
this.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onTap, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
reset() {
this._gameView.reset();
}
start(event: engine.Event) {
if ('jump-high-start') {
injectProps(event.data);
}
this._status = 1;
this._gameView.start();
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
private onTap(event) {
this._gameView.jump();
}
}
/**
* Created by rockyl on 2018/8/17.
*/
import { props } from "../props";
import { createSvga, playSound } from "./utils";
const svgaAssets = {
aniReady: { name: '准备立正', dir: 1 },
aniJump: { name: '跳上升', dir: 1 },
aniFall: { name: '跳下落', dir: 1 },
aniLandNormal: { name: '普通着地', dir: 1 },
aniLandSide: { name: '边缘着地', dir: -1 },
aniHit: { name: '被撞开', dir: -1 },
aniParachute: { name: '降落', dir: -1 },
};
export default class Player extends engine.Container {
private jumpPromise;
private playing;
private vy;
private g = props.gravity;
private baseY;
private aboveBlock;
private _aniName;
private _currentAni: svga.Svga;
private _prefectLandCounting;
private aniJump: svga.Svga;
private aniFall: svga.Svga;
private aniLandNormal: svga.Svga;
private aniLandSide: svga.Svga;
private aniHit: svga.Svga;
private aniParachute: svga.Svga;
private prefectEffect: svga.Svga;
private landEffect: svga.Svga;
private _deltaTime = 0
private startTime = 0
private lastTime = 0
private curTime = 0
constructor() {
super();
this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
}
switchAni(name, dir = 1, play = true, loop = false) {
return new Promise(resolve => {
this.scaleX = dir;
if (this._aniName !== name) {
this._aniName = name;
let oldAni = <svga.Svga>this.removeChild(this.getChildByName('body'));
if (oldAni) {
oldAni.stop();
}
let ani: svga.Svga = this._currentAni = this['ani' + name];
this.addChild(ani);
if (play) {
ani.play(false, loop);
if (loop) {
resolve(1);
} else {
ani.once(engine.Event.END_FRAME, resolve);
}
} else {
ani.gotoAndStop(1);
resolve(1);
}
}
})
}
setup() {
this.prefectEffect = createSvga('完美着地特效', 'playerLandPrefectAnchor');
this.landEffect = createSvga('着地特效', 'playerLandEffectAnchor');
for (let key in svgaAssets) {
let { name, dir } = svgaAssets[key];
let body = this[key] = createSvga(name, key.replace('ani', 'player') + 'Anchor');
body.name = 'body';
body.scaleX = dir;
}
}
reset(revive) {
this.x = 0;
this.rotation = 0;
this.scaleX = this.scaleY = 1;
this._prefectLandCounting = 0;
engine.Tween.removeTweens(this);
if (revive) {
this.switchAni('Jump', 1, false);
}
}
playReady() {
return new Promise(resolve => {
this.switchAni('Ready', 1);
this._currentAni.once(engine.Event.END_FRAME, function () {
this.switchAni('Jump', 1, false);
resolve(1);
}, this);
})
}
private onEnterFrame(event) {
if (!this.playing) {
return;
}
this.lastTime = this.curTime;
this.curTime = Date.now() - this.startTime;
this._deltaTime = this.curTime - this.lastTime;
this._deltaTime = this._deltaTime < 0 ? 0 : this._deltaTime;
this.vy += this.g * this._deltaTime / 16;
this.y += this.vy * this._deltaTime / 16;
if (this.vy > 0 && this._aniName !== 'Fall') {
this.dispatchEvent('jump-on-top');
this.switchAni('Fall');
}
if (this.y > this.baseY) {
this.y = this.baseY;
this.playing = false;
//this.aniDown.play(0);
this.jumpPromise && this.jumpPromise({
aboveBlock: this.aboveBlock,
});
this.jumpPromise = null;
}
}
changeBaseY(v) {
if (this.baseY == v) {
return;
}
this.aboveBlock = true;
this.baseY = v;
}
jump() {
playSound('跳起音效');
this.switchAni('Jump', 1, false);
this._currentAni.play(false, false);
this.aboveBlock = false;
this.playing = true;
this.baseY = this.y;
this.vy = -props.jumpSpeed;
this.startTime = Date.now();
return new Promise(resolve => {
this.jumpPromise = resolve;
})
}
async playLand(type, dir) {
switch (type) {
case 0:
this._prefectLandCounting++;
playSound('完美落地音效' + Math.min(4, this._prefectLandCounting));
let prefectEffect = this.prefectEffect;
this.addChildAt(prefectEffect, 0);
prefectEffect.gotoAndPlay(1);
prefectEffect.once(engine.Event.END_FRAME, function () {
this.removeChild(prefectEffect);
}, this);
let landEffect = this.landEffect;
this.addChildAt(landEffect, 0);
landEffect.gotoAndPlay(1);
landEffect.once(engine.Event.END_FRAME, function () {
this.removeChild(landEffect);
}, this);
await this.switchAni('LandNormal');
break;
case 1:
case 2:
this._prefectLandCounting = 0;
playSound('普通落地音效');
this.switchAni('LandNormal');
break;
case 3:
this._prefectLandCounting = 0;
playSound('边缘落地音效');
this.switchAni('LandSide', dir);
break;
}
}
async hitAway(dir) {
this.jumpPromise && this.jumpPromise();
this.jumpPromise = null;
playSound('被撞开音效');
this.switchAni('Hit', dir);
this.vy = 0;
await new Promise(resolve => {
engine.Tween.get(this)
.to({
x: -dir * props.hitAwayDistance.x,
}, props.hitAwayDuration, engine.Ease.quartOut);
engine.Tween.get(this)
.to({
y: this.y + props.hitAwayDistance.y,
}, props.hitAwayDuration, engine.Ease.cubicOut)
.call(resolve)
});
}
parachute(dir) {
this.switchAni('Parachute', dir);
return new Promise(resolve => {
engine.Tween.get(this)
.wait(200)
.call(function () {
playSound('降落伞下落音效');
})
.wait(300)
.to({ y: this.y + props.parachuteDistance }, props.parachuteDuration)
.set({ anchorOffsetY: 0 })
.call(resolve)
});
}
}
/**
* Created by rockyl on 2020-01-21.
*/
import {props} from "../props";
export function getTexture(uuid) {
return engine.Texture.from(uuid);
}
export function getTextureByName(name) {
return engine.Texture.from(getAssetByName(name).uuid);
}
export function getBlockAsset(type) {
return engine.getAssetByName(props.blockAssets[type]);
}
export function createSvga(name, anchorName) {
let inst = new svga.Svga();
inst.source = 'asset://' + getAssetByName(name).uuid;
let anchor = props[anchorName];
if (anchor) {
inst.x = -anchor.x;
inst.y = -anchor.y;
inst.anchorX = anchor.x;
inst.anchorY = anchor.y;
}
return inst;
}
export function playSound(name) {
engine.playSound(getAssetByName(name).uuid, {keep: true});
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {JumpHigh} from "./game/JumpHigh";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new JumpHigh();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment