Commit b5274699 authored by lujinlei's avatar lujinlei

1

parent 72c4b76a
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -407,6 +407,8 @@ var GameView = (function (_super) {
GameView.prototype.playShake = function () {
var _this = this;
var _a = this.frontContainer, x = _a.x, y = _a.y;
let a = '';
a.substr
return new Promise(function (resolve) {
var shakeOffset = 7;
var duration = 30;
......
/**
* Created by rockyl on 2019-12-16.
*/
const customId = 'dxbcyj-game';
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
//engine.globalEvent.dispatchEvent('dxbcyj-game-start', {guide: 0});
}, 500);
});
engine.globalEvent.addEventListener('dxbcyj-game-result', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>度小宝出游记</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: transparent;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script>
<!--<script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script>-->
<script src="//yun.duiba.com.cn/editor/zeroing/libs/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 = [
];
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 = {
};
{
"name": "度小宝出游记",
"desc": "度小宝出游记模块",
"props": {
"guideText1": {
"alias": "引导1的文本",
"type": "string",
"default": "长按屏幕\n杆子变长即可通过"
},
"guideText2": {
"alias": "引导2的文本",
"type": "string",
"default": "当度小宝获得金币时积分+5"
},
"pierMinDistance": {
"alias": "障碍物最小间距",
"type": "number",
"default": 350
},
"pierMaxDistance": {
"alias": "障碍物最大间距",
"type": "number",
"default": 500
},
"frontBGMoveSpeed": {
"alias": "前背影移动速度",
"type": "number",
"default": 0.5
},
"afterBGMoveSpeed": {
"alias": "后背影移动速度",
"type": "number",
"default": 0.2
},
"reward": {
"alias": "出现金币的概率(0-1区间 1为必出现 0为必不出现)",
"type": "number",
"default": 0
},
"pierCount": {
"alias": "一屏中最多出现的桥墩数量(最好默认为2)",
"type": "number",
"default": 2
},
"pierMoveTime": {
"alias": "一个周期内桥墩移动的总时长(毫秒)",
"type": "number",
"default": 1000
},
"strutUpSpeed": {
"alias": "撑杆上升速度(每帧上升增量,一秒60帧)",
"type": "number",
"default": 10
},
"strutWidth": {
"alias": "撑杆宽度",
"type": "number",
"default": 5
},
"strutColor": {
"alias": "撑杆颜色",
"type": "string",
"default": "#000000"
},
"strutRotationSpeed": {
"alias": "撑杆旋转总时长(毫秒)",
"type": "number",
"default": 300
},
"playerMoveSpeed": {
"alias": "人物移动总时长(毫秒)",
"type": "number",
"default": 1200
},
"singleScore": {
"alias": "每个桥墩分数",
"type": "number",
"default": 5
},
"goldScore": {
"alias": "每个金币分数",
"type": "number",
"default": 5
},
"bgFristScore": {
"alias": "第一张图的分数区间最大值(超过此值就更换第二张背景图)",
"type": "number",
"default": 30
},
"bgSecondScore": {
"alias": "第二张图的分数区间最大值(超过此值就更换第三张背景图)",
"type": "number",
"default": 80
}
},
"assets": [
{
"name": "hhl_after",
"url": "//yun.duiba.com.cn/aurora/assets/88252cca633a2f6d5c863d1678cb3d92c4e0e2a2.png",
"uuid": "76e73c53-d727-4746-b86e-92997af58c7f",
"ext": ".png"
},
{
"name": "hhl_front",
"url": "//yun.duiba.com.cn/aurora/assets/5c5a2581c91346de4d9fe66782aa8687cc9135e5.png",
"uuid": "848e2fdf-dcf0-44e2-b269-fdf0e2f84710",
"ext": ".png"
},
{
"name": "pier",
"url": "//yun.duiba.com.cn/aurora/assets/faf5cf941f1c3118bcf087352b812c2fb65ae992.png",
"uuid": "d784fe9f-5d1d-4522-ab4b-d6875a3da33f",
"ext": ".png"
},
{
"name": "gold",
"url": "//yun.duiba.com.cn/aurora/assets/ae210ad26cee13f8fb6e69be62f7f5498be50a5b.png",
"uuid": "7f4e19f2-c80f-4a65-bec2-1f3c3dc6d210",
"ext": ".png"
},
{
"name": "hb_after",
"url": "//yun.duiba.com.cn/aurora/assets/aaa76c50cfb00c602cc393df658670e1465a9b4e.png",
"uuid": "48a6636c-e04a-4836-8ae1-ed84db74c4f6",
"ext": ".png"
},
{
"name": "hb_front",
"url": "//yun.duiba.com.cn/aurora/assets/40d1dccd9d0c1dc1f4354d62e7c0b2eaab88457f.png",
"uuid": "b77802ea-7ee7-444e-aa11-72f85990f0c7",
"ext": ".png"
},
{
"name": "wh_after",
"url": "//yun.duiba.com.cn/aurora/assets/4e4f0adbca2b1d1e131271cc1ceddd97c3529f8b.png",
"uuid": "5efd9347-5e0d-4876-a483-7c22f3fdc3fb",
"ext": ".png"
},
{
"name": "wh_front",
"url": "//yun.duiba.com.cn/aurora/assets/b68ed0e4f49ac03736d80365e2ab66614ae97894.png",
"uuid": "8683ad45-3e7e-4944-ade0-eb4d5e48839f",
"ext": ".png"
},
{
"name": "walk",
"url": "//yun.duiba.com.cn/aurora/assets/a4ab1e1a2b49d140db4a0806562098a8b1619b06.svga",
"uuid": "10cd1fdd-4fd8-43cf-a1c7-6ff5846d8a91",
"ext": ".svga"
},
{
"name": "scoreBg",
"url": "//yun.duiba.com.cn/aurora/assets/1a61bd62c82c2ba872443fb14e0f5304d7aee224.png",
"uuid": "fb7f0d1a-c548-43ae-a86e-46ba98155813",
"ext": ".png"
},
{
"name": "scoreHint",
"url": "//yun.duiba.com.cn/aurora/assets/6bb8c64878288b074f840ea74f2956d0d0c65125.png",
"uuid": "0ab7dc8d-1388-4679-8637-54d6f3cd3a28",
"ext": ".png"
},
{
"name": "guide",
"url": "//yun.duiba.com.cn/aurora/assets/75cc4ea91654fd1e9900d071cac5ca5296b1bd19.png",
"uuid": "e904cd4e-cd87-421e-8292-25137299236e",
"ext": ".png"
},
{
"name": "guideHand",
"url": "//yun.duiba.com.cn/aurora/assets/4f014befa3c812e6882d578a6867afd3d05d7fe3.png",
"uuid": "fb1c2ead-dda8-495d-a846-7e4a26289d01",
"ext": ".png"
},
{
"name": "know",
"url": "//yun.duiba.com.cn/aurora/assets/3e695571aebebba6add5aae3d743fbd16b8ee915.png",
"uuid": "4999d4c5-507e-4ae9-8310-b90bf017a74f",
"ext": ".png"
}
],
"events": {
"in": {
"dxbcyj-game-start": {
"alias": "开始",
"data": {
}
}
},
"out": {
"dxbcyj-game-result": {
"alias": "游戏结束",
"data": {
}
}
}
}
}
\ No newline at end of file
import {getTextureByName} from "./utils";
import {getStage} from "./utils";
import {LoopComponent} from "./LoopComponent";
import { props } from './../props';
export class Background extends engine.Container{
partResHHL = ['hhl_after', 'hhl_front'];
partResHB = ['hb_after','hb_front'];
partResWH = ['wh_after','wh_front'];
speeds = [];
resArray=[];
frameMovePos = 0;
frameIndex;
sumMovePos;
_bgIndex;
//需要的总帧数
needFrameSum;
initBg(){
this.sumMovePos = 0;
this.speeds.push(props.afterBGMoveSpeed);
this.speeds.push(props.frontBGMoveSpeed);
let bottomBg = new engine.Rect();
bottomBg.x = 0;
bottomBg.y = 0;
bottomBg.width = getStage().width;
bottomBg.height = 0;
bottomBg.fillColor = 0x75c9f5;
this.addChild(bottomBg);
this.resArray.push(this.partResHHL)
this.resArray.push(this.partResHB)
this.resArray.push(this.partResWH)
this._bgIndex = 0;
const parts = [];
for(let i = 0; i < 2; i++){
let part = new LoopComponent();
part.setupLoop([
this.resArray[0][i],
this.resArray[0][i],
]);
parts.push(part);
this.addChild(part);
}
//(height - parts[1].height) / 2 - 200
parts[1].y = 200;
}
setViewport(pos) {
this.needFrameSum = (props.pierMoveTime/1000)*60;
this.frameMovePos = pos/this.needFrameSum;
this.frameIndex = 0;
this.addEventListener(engine.Event.ENTER_FRAME,this.frameBack,this);
}
frameBack(){
if( this.frameIndex < this.needFrameSum){
for (let i = 0; i < 2; i++) {
const part = <LoopComponent>this.getChildAt(i + 1);
const speed = this.speeds[i];
let tmpPos = ((this.frameMovePos * this.frameIndex) + this.sumMovePos ) * speed;
part.setViewport(tmpPos)
}
this.frameIndex++
}else{
this.sumMovePos += this.frameMovePos * this.needFrameSum;
this.frameIndex = 0
this.removeEventListener(engine.Event.ENTER_FRAME,this.frameBack,this);
}
}
changeBg(index){
for (let i = 0; i < 2; i++) {
const part = <LoopComponent>this.getChildAt(i + 1);
part.changeBg(this.resArray[index][i]);
if(i == 1 && index ==1){
part.y = 400;
}
if(i == 1 && index ==2){
part.y = 250;
}
}
this._bgIndex = index;
}
getBgIndex(){
return this._bgIndex;
}
}
\ No newline at end of file
import { Road } from './Road';
/**
* Created by rockyl on 2018/8/16.
*/
import {props} from "../props";
import {getStage,getTextureByName} from "./utils";
import {GuideLayer} from "./GuideLayer";
import { Background } from "./Background";
import ObjectPool = engine.ObjectPool;
import { Pier } from './Pier';
import { Player } from './Player';
import { Strut } from './Strut';
import { ScoreLabel } from './ScoreLabel';
export const PoolName: string = 'pier';
ObjectPool.registerPool(PoolName, function () {
return new Pier();
}, function (item: Pier, data) {
item.init();
});
export default class GameView extends engine.Container {
guideLayer: GuideLayer;
private _hasSetup;
_backgroud:Background;
_road:Road;
_player:Player;
_strut:Strut;
_touchLayer: engine.Rect;
_isTouchLayer;
_scoreContainer;
moveX = 0;
labScore:ScoreLabel;
_sumScore;
_isMouseDown;
_guide;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
setup(){
if (this._hasSetup) {
return;
}
this._hasSetup = true;
this._backgroud = new Background();
this.addChild(this._backgroud);
this._backgroud.initBg();
const road = this._road = new Road();
this.addChild(road);
road.setup();
let pierWidth = this._road.getFristPier();
const player = this._player = new Player();
this.addChild(player);
player.initPlayer(pierWidth);
const strut = this._strut = new Strut();
this.addChild(strut);
strut.init();
this._scoreContainer = new engine.Container();
this.addChild(this._scoreContainer);
this.initLabScore();
}
async start(guide) {
this._isTouchLayer = true;
this._sumScore = 0;
this._isMouseDown = false;
this._guide = guide;
let initScore = this._road.getStartGold(0) ? props.goldScore : 0;
this.updateScore(initScore);
//是否是新手
if(this._guide == '1'){
this.setGuide();
}else{
this.initTouch();
this.registerEvent();
}
}
//新手引导
setGuide(){
this._road.setGuide();
const guideLayer = this.guideLayer = new GuideLayer();
this.addChild(guideLayer);
this.guideLayer.show(1, {x:20,y: 650,guideText:props.guideText1},()=>{
let posX = this._road.getMovePos();
this.guideLayer.show(2, {x:posX + 20,y: 620,guideText:props.guideText2},()=>{
this.initTouch();
this.registerEvent();
})
});
}
//分数显示
initLabScore(){
const scoreBg = new engine.Sprite(getTextureByName('scoreBg'));
scoreBg.x = getStage().width/2 - scoreBg.width/2;
scoreBg.y = 80;
//this._scoreContainer.addChild(scoreBg);
const scoreHint = new engine.Sprite(getTextureByName('scoreHint'));
scoreHint.x = getStage().width/2 - scoreHint.width/2;
scoreHint.y = 40;
this._scoreContainer.addChild(scoreHint);
this.labScore = new ScoreLabel();
this.labScore.fillColor = 0xff7646;
this.labScore.size = 70;
this.labScore.width = getStage().width;
this.labScore.height = scoreBg.height;
this.labScore.textAlign = engine.TEXT_ALIGN.CENTER;
this.labScore.x = 0;
this.labScore.y = scoreBg.y+10;
this._scoreContainer.addChild(this.labScore);
}
registerEvent(){
this._touchLayer.addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onMouseDown,this);
this._touchLayer.addEventListener(engine.MouseEvent.MOUSE_UP,this.onMouseUp,this);
}
removeListener(){
this._touchLayer.removeEventListener(engine.MouseEvent.MOUSE_DOWN,this.onMouseDown,this);
this._touchLayer.removeEventListener(engine.MouseEvent.MOUSE_UP,this.onMouseUp,this);
}
//触碰层
initTouch(){
this._touchLayer = new engine.Rect();
this.addChild(this._touchLayer);
this._touchLayer.width = getStage().width;
this._touchLayer.height = getStage().height;
this._touchLayer.x = 0;
this._touchLayer.y = 0;
this._touchLayer.alpha = 0;
}
setScoreShow(){
}
//鼠标事件
onMouseDown(){
if(this._isTouchLayer){
this._isMouseDown = true;
this._strut.onMouseDown(this._road.getFristPier(),this._road.getDistance(),this.goCallBcak.bind(this));
}
}
onMouseUp(){
if(this._isTouchLayer && this._isMouseDown){
this._strut.onMouseUp();
this._isMouseDown = false;
this._isTouchLayer = false;
}
}
//撑杆回调
goCallBcak(isSuccess){
if(isSuccess){
console.log('成功了');
let movePos = this._road.getMovePos();
if(this._road.getStartGold(1,false)){
this.updateScore(props.singleScore + props.goldScore);
}else{
this.updateScore(props.singleScore);
}
//人物前行
this._player.setViewport(movePos,this.complete.bind(this));
}else{
console.log('失败了');
this._player.setViewport(this._strut.getStrutHeight(),()=>{
console.log('掉下去了');
engine.globalEvent.dispatchEvent('dxbcyj-game-result',{score:this._sumScore});
},this._road.getFristPier())
}
}
//人物前行结束回调
complete(){
//关闭金币
this._road.getStartGold(1);
//获得位移距离
let movePos = this._road.getMovePos();
this._road.setViewport();
this._backgroud.setViewport(movePos);
//移动完成 可以再次操作
this._player.setBackViewport(()=>{
this._isTouchLayer = true;
});
this.closeStrut();
}
//重置撑杆
closeStrut(){
this._strut.rest();
}
//分数更新
updateScore(score){
this._sumScore += score;
if(0 <= this._sumScore && this._sumScore <= props.bgFristScore){
this.changeBg(0);
}else if(props.bgFristScore < this._sumScore && this._sumScore <= props.bgSecondScore){
this.changeBg(1);
}else{
this.changeBg(2);
}
this.labScore.updateScore(this._sumScore);
}
getScore(){
return this._sumScore;
}
changeBg(index){
if(this._backgroud.getBgIndex() != index){
this._backgroud.changeBg(index);
}
}
}
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
export class GameWrapper extends engine.Container {
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('dxbcyj-game-start', this.start, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
//this.once(engine.Event.ENTER_FRAME, this.onAddedToStage, this);
}
start(event: engine.Event) {
this._gameView.start(event.data.guide);
}
}
/**
* 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 _options;
_guideHole;
_canClear:any = [];
_callBack;
private label: engine.Label;
constructor() {
super();
this.setup();
}
private setup() {
}
show(id, options,callback?) {
this.visible = true;
this._callBack = callback?callback:null;
if (!this.guideMask) {
this._options = options;
const {width, height} = this.stage;
let guideMask = this.guideMask = new engine.Container();
let guideHole = this._guideHole= new engine.Image(getTextureByName('guide'));
guideHole.x = options.x;
guideHole.y = options.y;
guideHole.width = 250;
guideHole.height = 250;
guideHole.name = 'guideHole';
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);
this.guideStep(id);
let label = this.label = new engine.Label();
label.fillColor = 'white';
label.size = 30;
label.text = options.guideText;
label.x = (width - label.width) / 2;
label.y = guideHole.y + guideHole.height + 50;
label.textAlign = engine.TEXT_ALIGN.CENTER;
label.name = 'labHint';
guideMask.addChild(label);
this.addChild(guideMask);
}
this.once(engine.MouseEvent.CLICK, function(){
this.removeChild(this.guideMask);
this.guideMask = null;
if(this._callBack){
this._callBack();
}
}, 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);
}
guideStep(id){
if(id == 1){
let guideHand = new engine.Image(getTextureByName('guideHand'));
guideHand.x = this._options.x + 300;
guideHand.y = this._options.y + 100;
this.guideMask.addChild(guideHand);
let rect = new engine.Rect();
rect.x = this._options.x + 200;
rect.y = this._options.y - 15;
rect.width = props.strutWidth;
rect.height = 200;
rect.fillColor = props.strutColor;
this.guideMask.addChild(rect);
this._canClear.push(guideHand);
this._canClear.push(rect);
}
if(id == 2){
let know = new engine.Image(getTextureByName('know'));
know.x = (this.stage.width - know.width) / 2;
know.y = this._options.y + 400;
this.guideMask.addChild(know);
this._canClear.push(know);
}
}
}
import {getTextureByName} from "./utils";
export class LoopComponent extends engine.Container{
parts: any[];
onceInfo: any = {width: 0, height: 0, count: 0};
loopInfo: any = {width: 0, height: 0, count: 0};
constructor() {
super();
this.parts = [];
}
private setup(parts, info) {
parts.forEach((item, index) => {
let part;
if(typeof item == 'string'){
part = new engine.Sprite(getTextureByName(item));
}else if(item instanceof engine.Texture){
part = new engine.Sprite(item);
}else {
part = item;
}
this.addChild(part);
this.parts.push(part);
if (index == 0) {
info.width = part.width;
info.height = part.height;
}
});
info.count = parts.length;
this.setViewport(0, 0)
}
changeBg(changName){
this.parts.forEach((item, index) => {
item.texture = getTextureByName(changName)
});
}
setupLoop(resArr) {
this.setup(resArr, this.loopInfo);
}
setViewport(x, y = 0) {
const sizeField = y == 0 ? 'width' : 'height';
const posField = y == 0 ? 'x' : 'y';
const pos = y == 0 ? x : y;
let index;
const onceSize = this.onceInfo[sizeField];
const onceCount = this.onceInfo.count;
const loopCount = this.loopInfo.count;
const loopSize = this.loopInfo[sizeField];
index = onceSize == 0 ? -1 : Math.floor(pos / onceSize);
if (index < 0 || index >= onceCount) {
const loopIndex = Math.floor((pos - onceCount * onceSize) / this.loopInfo[sizeField]);
index = onceCount + loopIndex;
}
let formerIndex = index < onceCount ? index : (index) % loopCount + onceCount;
let latterIndex = index < onceCount ? index + 1 : (index - onceCount + 1) % loopCount + onceCount;
let former = this.parts[formerIndex];
let latter = this.parts[latterIndex];
if(!former || !latter){
console.log(formerIndex, latterIndex);
}
former[posField] = -(pos - loopSize * (index < onceCount ? index : index - onceCount) - (index < onceCount ? 0 : onceCount * onceSize));
latter[posField] = former.x + (index < onceCount ? onceSize : loopSize);
}
}
\ No newline at end of file
import { props } from './../props';
import {getTextureByName,getStage} from "./utils";
export class Pier extends engine.Container {
bmp;
public haveGold;
constructor() {
super();
this.bmp = new engine.Sprite();
this.addChild(this.bmp);
}
init(){
const bmp = this.bmp;
bmp.alpha = 1;
bmp.texture = getTextureByName('pier');
bmp.x = 0;
bmp.y = bmp.height ;
if(this.children.length < 2){
const gold = new engine.Sprite();
gold.texture = getTextureByName('gold');
gold.name = 'gold';
this.addChild(gold);
}
this.setGoldPosX(bmp);
this.setShowGold();
}
setShowGold(){
let nodeGold = this.getChildByName('gold');
let randomWard = Math.random();
nodeGold.alpha = 1;
let isShow = randomWard < props.reward ? true : false ;
nodeGold.visible = isShow;
this.haveGold = isShow;
}
setGoldPosX(bmp){
let nodeGold = this.getChildByName('gold');
let pos = bmp.width / 2 - nodeGold.width/2;
nodeGold.x = pos
nodeGold.y = bmp.height - nodeGold.height - 50;
nodeGold.visible = false;
}
closeGold(){
this.children.forEach((item) => {
if(item.name == 'gold')
{
item.anchorX = item.width/2;
item.anchorY = item.height/2;
engine.Tween.get(item,{loop:false})
.to({scaleX:2.5,scaleY:2.5},200,engine.Ease.cubicOut)
.to({scaleX:1,scaleY:1,alpha:0},200,engine.Ease.cubicIn)
.call(()=>{
item.visible = false;
this.haveGold = false;
})
}
})
}
}
\ No newline at end of file
import {props} from "../props";
import {createSvga, playSound} from "./utils";
export class Player extends engine.Container{
_container;
private playerNode: svga.Svga;
initPlayer(pierWidth){
this._container = new engine.Container();
this.addChild(this._container);
this.playerNode = createSvga('walk');
this._container.addChild(this.playerNode);
this.playerNode.y = 675;
this.playerNode.x = pierWidth/2 - 80;
this.playerNode.play();
}
setViewport(pos,callBack,pierWidth?){
let tmpPos = 0;
let isSuccess = false;
if(!pierWidth){
tmpPos = pos;
isSuccess = true;
}else{
tmpPos = pierWidth - this.playerNode.x + pos - 60;
}
this.playGoTween(tmpPos,callBack,isSuccess)
}
playGoTween(pos,callBack,isSuccess){
engine.Tween.get(this._container,{loop:false})
.to({x : pos},props.playerMoveSpeed)
.call(()=>{
engine.Tween.removeTweens(this._container);
if(isSuccess){
if(callBack){
callBack();
}
}else{
this.playDropTween(callBack);
}
})
}
playDropTween(callBack){
engine.Tween.get(this._container,{loop:false})
.to({y : 2000},1000)
.call(()=>{
engine.Tween.removeTweens(this._container);
if(callBack){
callBack();
}
})
}
setBackViewport(callBack){
engine.Tween.get(this._container,{loop:false})
.to({x : 0},props.pierMoveTime)
.call(()=>{
engine.Tween.removeTweens(this._container);
if(callBack){
callBack();
}
})
}
}
\ No newline at end of file
import { props } from './../props';
import ObjectPool = engine.ObjectPool;
import {getStage} from "./utils";
import { Pier } from './Pier';
import GameView from './GameView';
export class Road extends engine.Container{
//container: engine.Container;
lastPos;
setup(){
// this.container = new engine.Container();
// this.addChild(this.container);
this.lastPos = 0;
this.addPier();
}
getFristPier(){
return this.getChildAt(0).width;
}
getDistance(){
let distance = [];
let pier1 = this.getChildAt(0);
let pier2 = this.getChildAt(1);
distance.push(pier2.x - pier1.x);
distance.push(pier2.width);
return distance;
}
addPier(){
while(this.children.length < props.pierCount + 1){
let childrenNum = this.children.length;
let randomPos = this.makeRandomFloat(props.pierMaxDistance,props.pierMinDistance);
const pier: Pier = ObjectPool.getObject('pier');
this.addChild(pier);
if(childrenNum == 0){
pier.x = 0;
}else{
pier.x = this.lastPos + randomPos;
}
this.lastPos = pier.x;
}
}
moveAddPier(){
let randomPos = this.makeRandomFloat(props.pierMaxDistance,props.pierMinDistance);
const pier: Pier = ObjectPool.getObject('pier');
let lastChild = this.getChildAt(this.children.length -1);
pier.x = lastChild.x + randomPos;
this.addChild(pier);
}
makeRandomFloat(max: number, min: number = 0): number {
return Math.random() * (max - min) + min;
}
setViewport(){
let tmpMovepos = this.getMovePos();
this.children.forEach((item,index) => {
this.playTween(item,index,tmpMovepos);
})
}
//获得移动位移
getMovePos(){
let movePos:any = this.getChildAt(1);
return movePos.x;
}
playTween(item,index,tmpMovepos){
engine.Tween.get(item,{loop:false})
.to({x : item.x - tmpMovepos},props.pierMoveTime)
.call(()=>{
if(this.getChildIndex(item) == 0){
engine.Tween.removeTweens(item);
this.removeChild(item);
ObjectPool.recycleObject('pier',item);
}
if(index == 0){
this.moveAddPier();
}
})
}
//桥墩是否有金币
getStartGold(index,isClose = true){
let tmpNode:any = this.getChildAt(index);
let haveGold = tmpNode.haveGold;
if(haveGold && isClose){
tmpNode.closeGold();
}
return haveGold;
}
//设置新手引导 第二个桥墩要有金币
setGuide(){
let tmpNode:any = this.getChildAt(1);
if(!tmpNode.haveGold){
tmpNode.children.forEach((item) => {
if(item.name == 'gold'){
item.visible = true;
}
})
tmpNode.haveGold = true;
}
}
}
\ No newline at end of file
/**
* Created by rockyl on 2018/9/10.
*
* 分数标签
*/
export class ScoreLabel extends engine.Label {
_value;
_tmp;
updateScore(score,animation = true) {
this._value = score;
if (animation && this._tmp) {
this.animationUpdate();
} else {
this.updateLocal(score);
}
}
animationUpdate(){
let tmpInterval = setInterval(()=>{
this._tmp += 1;
if(this._tmp <= this._value){
this.text = this._tmp
}else{
this._tmp = this._value;
clearInterval(tmpInterval);
}
},50)
}
updateLocal(v){
this._tmp = v;
this.text = v;
}
}
import { props } from "../props";
export class Strut extends engine.Container{
_strut: engine.Rect;
_distance;
_callBack;
init(){
this._strut = new engine.Rect();
this.addChild(this._strut);
this._strut.width = props.strutWidth;
this._strut.y = 833;
this._strut.fillColor = props.strutColor;
this._strut.rotation = 180;
}
onMouseDown(pierWidth,distance,callBack){
this._strut.x = pierWidth - 60;
this._distance = distance;
this._callBack = callBack;
this._strut.visible = true;
this.addEventListener(engine.Event.ENTER_FRAME,this.frameStrut,this);
}
onMouseUp(){
this.removeEventListener(engine.Event.ENTER_FRAME,this.frameStrut,this);
setTimeout(() => {
this.strutRotation();
}, 200);
}
strutRotation(){
engine.Tween.get(this._strut,{loop:false})
.to({rotation:270},props.strutRotationSpeed)
.call(()=>{
this.judgeResult();
engine.Tween.removeTweens(this._strut);
})
}
judgeResult(){
let isSuccess = false;
if(this._distance[0] - this._distance[1] + 100 <= this._strut.height && this._strut.height <= this._distance[0] + 20){
isSuccess = true;
}
if(this._callBack){
this._callBack(isSuccess);
}
}
frameStrut(){
if(this._strut.height < 1000){
this._strut.height += props.strutUpSpeed;
}
}
rest(){
this._strut.width = props.strutWidth;
this._strut.y = 833;
this._strut.fillColor = props.strutColor;
this._strut.rotation = 180;
this._strut.height = 0;
this._strut.visible = false;
}
getStrutHeight(){
let distance = this._strut.height > 1000 ? 1000 :this._strut.height;
return distance;
}
}
\ No newline at end of file
import { Pier } from './Pier';
/**
* Created by rockyl on 2020-02-03.
*/
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'pier';
ObjectPool.registerPool(PoolName, function () {
return new Pier();
}, function (item: Pier, data) {
item.init();
});
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function getStage(){
return engine.gameStage.stage;
}
export function createSvga(name) {
let inst = new svga.Svga();
inst.source = engine.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;
}
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
......@@ -20,6 +20,7 @@ class AnimationPool extends Pool<PoolFrameAnimation> {
} else {
let anim = new PoolFrameAnimation(key);
this.layer.addChild(anim);
return anim;
}
}
......
/**
* Created by rockyl on 2019-12-16.
*/
const customId = 'walking-cat';
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
//console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
// engine.globalEvent.dispatchEvent('lipstick-turntable-reset', {
// turntableAssetName: '橘色转盘',
// countDown: 5,
// });
engine.globalEvent.dispatchEvent('walking-cat-start');
}, 500);
});
engine.globalEvent.addEventListener('walking-cat-game-end', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('walking-cat-game-changScore', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('lipstick-turntable-hit', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('lipstick-turntable-countdown', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>猫步前行</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: transparent;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script>
<script src="//yun.duiba.com.cn/js-libs/p2.js/0.7.1/p2.min.js"></script>
<!--<script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script>-->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "橘色转盘",
"url": "//yun.duiba.com.cn/aurora/assets/9dfdf39ce4f4693c336cbdd996e05bd392921e0e.png",
"uuid": "b6ed99bc-2da1-4e6d-840e-54371be041aa",
"ext": '.png'
},
{
"name": "蓝色转盘",
"url": "//yun.duiba.com.cn/aurora/assets/088cff75c4035b87ff421c2dd87391c6a7bea607.png",
"uuid": "4d8e2af4-4f8e-4f84-ab05-8ae172bbf8a6",
"ext": '.png'
},
{
"name": "紫色转盘",
"url": "//yun.duiba.com.cn/aurora/assets/e0ac6904227d8e3878ed23be33e58d3ce2180f2d.png",
"uuid": "c3dd14af-1b98-4cb8-b725-fa75cf15e96d",
"ext": '.png'
},
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
import {getTextureByName} from "./utils";
import {LoopComponent} from "./LoopComponent";
import {getStage} from "./utils";
import {props} from "../props";
export class Background extends engine.Container {
//static stageWidth = engine.gameStage.stage.width;
partRes = ['bg_far', 'bg_mid', 'bg_near'];
speeds = [0.05, 0.5, 1];
setup() {
let bottomBg = new engine.Rect();
bottomBg.x = 0;
bottomBg.y = 0;
bottomBg.width = getStage().width;
bottomBg.height = 0;
bottomBg.fillColor = 0x75c9f5;
this.addChild(bottomBg);
const parts = [];
for(let i = 0; i < 3; i++){
let part = new LoopComponent();
part.setupLoop([
this.partRes[i],
this.partRes[i],
]);
parts.push(part);
this.addChild(part);
}
const {height} = getStage();
parts[0].y = (height - parts[0].height) / 2 - 400;
parts[1].y = (height - parts[1].height) / 2 - 120;
parts[2].y = (height - parts[2].height) / 2 + 300;
bottomBg.y = parts[2].y;
bottomBg.height = height - parts[2].y;
const moon = new engine.Sprite(getTextureByName('moon'));
moon.x = 100;
moon.y = 100;
this.addChild(moon);
}
setViewport(pos) {
for (let i = 0; i < 3; i++) {
const part = <LoopComponent>this.getChildAt(i + 1);
const speed = this.speeds[i];
part.setViewport(pos * speed)
}
}
reset(revive = false){
}
}
/**
* 障碍物
*/
import {getStage, getTextureByName} from "./utils";
export class Block extends engine.Container {
static configs = [
{ratio: 0.6, width: 15, off: 32, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0.1, width: 10, off: 18, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0.15, width: 30, off: 32, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0.1, width: 86, off: 28, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0.5, width: 70, off: 20, effect: '', effect_offset: {x: 0, y: -20}},
{ratio: 0, width: 0, off: 0, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0, width: 0, off: 0, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0, width: 0, off: 0, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0, width: 0, off: 0, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0, width: 0, off: 0, effect: '', effect_offset: {x: 0, y: 0}},
{ratio: 0, width: 123, off: 23, effect: '', effect_offset: {x: 0, y: 0}},
];
type;
bmp;
//effectMC: engine.MovieClip;
effectResolve;
constructor() {
super();
this.bmp = new engine.Sprite();
this.addChild(this.bmp = new engine.Sprite());
}
//
reset({type,}) {
this.type = type;
let bmp = this.bmp;
bmp.alpha = 1;
bmp.texture = this.getBlock();
const {width, off} = Block.configs[type];
bmp.x = -(off + width / 2);
bmp.y = -(bmp.height / 2);
}
getBlock(){
return getTextureByName('block_' + this.type);
}
playEffect() {
//const {effect, effect_offset} = Block.configs[this.type];
// if (effect) {
// if (!this.effectMC) {
// const mc = this.effectMC = Effects.instance.makeMovieClip(effect);
// const {x, y} = effect_offset;
// mc.x = x;
// mc.y = y;
// this.addChild(mc);
// mc.addEventListener(egret.Event.COMPLETE, this.onEffectComplete, this);
// }
// this.effectMC.gotoAndPlay(0, 1);
// return new Promise(resolve => {
// this.effectResolve = resolve;
// })
// } else {
// return Promise.resolve();
// }
}
playFadeOut() {
return this.getTweenPromise(
engine.Tween.get(this.bmp)
.to({alpha: 0}, 100)
.to({alpha: 1}, 100)
.to({alpha: 0}, 100)
)
}
private onEffectComplete(event) {
this.effectResolve && this.effectResolve();
this.effectResolve = null;
}
getTweenPromise(tween: engine.Tween): Promise<any> {
return new Promise((resolve) => {
tween.call(resolve);
});
}
}
This diff is collapsed.
import { props } from './../props';
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
import { PlayGame } from './PlayGame';
export class GameWrapper extends engine.Container {
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('walking-cat-start', this.start, this);
engine.globalEvent.addEventListener('walking-cat-revive', this.revive, this);
engine.globalEvent.addEventListener('walking-cat-showScore', this.revive, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
//this.once(engine.Event.ADDED_TO_STAGE, this.start, this);
}
start(event: engine.Event) {
injectProps(event.data);
this._gameView.eventStart();
}
revive() {
console.log('复活');
this._gameView.reset(true);
this._gameView.start(true);
}
}
import {getTextureByName} from "./utils";
export class LoopComponent extends engine.Container{
parts: any[];
onceInfo: any = {width: 0, height: 0, count: 0};
loopInfo: any = {width: 0, height: 0, count: 0};
constructor() {
super();
this.parts = [];
}
private setup(parts, info) {
parts.forEach((item, index) => {
let part;
if(typeof item == 'string'){
part = new engine.Sprite(getTextureByName(item));
}else if(item instanceof engine.Texture){
part = new engine.Sprite(item);
}else {
part = item;
}
this.addChild(part);
this.parts.push(part);
if (index == 0) {
info.width = part.width;
info.height = part.height;
}
});
info.count = parts.length;
this.setViewport(0, 0)
}
setupOnce(resArr) {
this.setup(resArr, this.onceInfo);
}
setupLoop(resArr) {
this.setup(resArr, this.loopInfo);
}
setViewport(x, y = 0) {
const sizeField = y == 0 ? 'width' : 'height';
const posField = y == 0 ? 'x' : 'y';
const pos = y == 0 ? x : y;
let index;
const onceSize = this.onceInfo[sizeField];
const onceCount = this.onceInfo.count;
const loopCount = this.loopInfo.count;
const loopSize = this.loopInfo[sizeField];
index = onceSize == 0 ? -1 : Math.floor(pos / onceSize);
if (index < 0 || index >= onceCount) {
const loopIndex = Math.floor((pos - onceCount * onceSize) / this.loopInfo[sizeField]);
index = onceCount + loopIndex;
}
let formerIndex = index < onceCount ? index : (index) % loopCount + onceCount;
let latterIndex = index < onceCount ? index + 1 : (index - onceCount + 1) % loopCount + onceCount;
let former = this.parts[formerIndex];
let latter = this.parts[latterIndex];
if(!former || !latter){
console.log(formerIndex, latterIndex);
}
former[posField] = -(pos - loopSize * (index < onceCount ? index : index - onceCount) - (index < onceCount ? 0 : onceCount * onceSize));
latter[posField] = former.x + (index < onceCount ? onceSize : loopSize);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2018/9/10.
*
* 分数标签
*/
export class ScoreLabel extends engine.Label {
formatFun: Function;
_value;
_temp;
updateScore(score, formatFun = null, animation = true) {
this.formatFun = formatFun;
this._value = score;
if (animation) {
engine.Tween.get(this, null, null, true)
.to({temp: score}, 300);
} else {
this.updateLocal(score);
}
}
get score() {
return this._value;
}
private get temp() {
return this._temp;
}
private set temp(v) {
this._temp = v;
this.updateLocal(v);
}
updateLocal(v) {
this.text = this.formatFun && this.formatFun(v) || v;
}
}
This diff is collapsed.
This diff is collapsed.
interface IPlayerPart {
localUpdate(x, y, rotation, sleeping);
}
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