Commit dbe171a4 authored by rockyl's avatar rockyl

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	dist/customs/jump-high.json
#	src/custom/jump-high/debug/main.js.map
parents d914feca a4973078
/**
* 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 getProps() {
return engine.getProps(customId);
}
/**
* Created by rockyl on 2019-12-16.
*/
const customId = 'jump-high-2';
(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 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 src="http://localhost:4003/debug/engine-svga.js"></script>
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
<!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 crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "方块素材0",
"url": "//yun.duiba.com.cn/aurora/assets/0307ca8906e9f553e6873c346ae5c6ec3655db59.svga",
"uuid": "4e31f5d7-bd03-41a3-873c-3755fe4862e6",
"ext": '.svga'
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
/**
* 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.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* 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;
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();
} else {
ani.once(engine.Event.END_FRAME, resolve);
}
} else {
ani.gotoAndStop(1);
resolve();
}
}
})
}
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();
}, this);
})
}
private onEnterFrame(event) {
if (!this.playing) {
return;
}
this.vy += this.g;
this.y += this.vy;
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;
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)
});
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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