Commit a699f487 authored by 13732208043's avatar 13732208043

采茶叶

parent f0684238
This diff is collapsed.
...@@ -407,6 +407,8 @@ var GameView = (function (_super) { ...@@ -407,6 +407,8 @@ var GameView = (function (_super) {
GameView.prototype.playShake = function () { GameView.prototype.playShake = function () {
var _this = this; var _this = this;
var _a = this.frontContainer, x = _a.x, y = _a.y; var _a = this.frontContainer, x = _a.x, y = _a.y;
let a = '';
a.substr
return new Promise(function (resolve) { return new Promise(function (resolve) {
var shakeOffset = 7; var shakeOffset = 7;
var duration = 30; 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": 400
},
"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": 20
},
"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.frame,this);
}
frame(){
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.frame,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;
constructor() {
super();
}
async start(guide) {
this._isTouchLayer = true;
this._sumScore = 0;
this._isMouseDown = false;
this._backgroud = new Background();
this._backgroud.initBg();
this.addChild(this._backgroud);
const road = this._road = new Road();
road.setup();
this.addChild(road);
let pierWidth = this._road.getFristPier();
const player = this._player = new Player();
player.initPlayer(pierWidth);
this.addChild(player);
const strut = this._strut = new Strut();
strut.init();
this.addChild(strut);
this._scoreContainer = new engine.Container();
this.addChild(this._scoreContainer);
this.initLabScore();
let initScore = this._road.getStartGold(0) ? props.goldScore : 0;
this.updateScore(initScore);
//是否是新手
if(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";
import {injectProps} from "../props";
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 = 25;
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.frame,this);
}
onMouseUp(){
this.removeEventListener(engine.Event.ENTER_FRAME,this.frame,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] + 60 <= this._strut.height && this._strut.height <= this._distance[0] + 30){
isSuccess = true;
}
if(this._callBack){
this._callBack(isSuccess);
}
}
frame(){
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);
}
/**
* Created by renjianfeng on 2020-03-13.
*/
/*
event-pickTeaGame-init //游戏初始化
event-getchange-TeaNum //茶叶数量{初始值totalNum,总量nowNum} 改变svga动画
event-getBasket-Type //获得篮子类型 设置篮子类型 纸篮子 布篮子 竹篮子 木篮子 0 1 2 3
event-hand-grasp //手抓去点击
//event-wait-uplevel //待升级
event-add-oneScore //+1
event-pick-tea //采茶叶
event-tea-skyup //茶叶向上飞
event-setchange-TeaNum
event-setBasket-Type //设置篮子类型
*/
const customId = 'pick-tea';
(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('event-pickTeaGame-init');
//获得引用端的篮子类型event-setBasket-Type event-setchange-TeaNum
engine.globalEvent.dispatchEvent('event-setBasket-Type');
engine.globalEvent.dispatchEvent('event-setchange-TeaNum');
}, 500);
});
// +1显示
engine.globalEvent.addEventListener('event-add-oneScore', (e) => {
console.log(e.type, e.data);
});
// 收集茶叶
engine.globalEvent.addEventListener('event-pick-tea', (e) => {
console.log(e.type, e.data);
});
// 茶叶散开
engine.globalEvent.addEventListener('event-tea-skyup', (e) => {
console.log(e.type, e.data);
});
// 茶叶上升
engine.globalEvent.addEventListener('event-hand-grasp', (e) => {
console.log(e.type, e.data);
});
// 改变篮子里的茶叶
engine.globalEvent.addEventListener('event-change-TeaNum', (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 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.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/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/e394fce3576ddeed52fa4dceededc98820318f15.png",
"uuid": "7436ffbc-8906-4cdc-9e9a-80a3f7126e30",
"ext": ".png"
},
{
"name": "进度",
"url": "//yun.duiba.com.cn/aurora/assets/047218962662ed238192f211719c109fa107e8e1.png",
"uuid": "23e7861c-75a9-46bd-93f8-2825d4810d31",
"ext": ".png"
},
{
"name": "茶叶进度缺",
"url": "//yun.duiba.com.cn/aurora/assets/a99ad1582f44237f9391aeffa53b72c316a8ea83.png",
"uuid": "cc4f6b6c-0542-4b8d-b83d-1ee31e9c0e39",
"ext": ".png"
},
{
"name": "茶叶进度满",
"url": "//yun.duiba.com.cn/aurora/assets/7b1ac4e33309adfde360c92c1cdc8299a3e1efd0.png",
"uuid": "81728f22-c616-4133-8c78-c041cde68b79",
"ext": ".png"
},
{
"name": "小茶叶",
"url": "//yun.duiba.com.cn/aurora/assets/e938df1513919985c573128e1ed8074c9cc19dd5.png",
"uuid": "b30b3093-6097-4cc5-9364-ad1050f86c6e",
"ext": ".png"
},
{
"name": "茶叶-满",
"url": "//yun.duiba.com.cn/aurora/assets/acd219c8c8d472a3469183ba8d32568372e75797.png",
"uuid": "41431fe5-523c-4e21-a2bc-9dc4641d27e8",
"ext": ".png"
},
{
"name": "茶叶-少",
"url": "//yun.duiba.com.cn/aurora/assets/38f1874d0688fb8b621dfb1d3028d6f8ac61374d.png",
"uuid": "5765bb2b-3e7b-48fe-9e06-3c76a78c92dc",
"ext": ".png"
},
{
"name": "采茶童-纸篮子",
"url": "//yun.duiba.com.cn/aurora/assets/52f24f84d31709faea0fc35193692b134fe2e40d.svga",
"uuid": "8a7801dd-b802-4571-9f8e-e9acfb9c4527",
"ext": ".svga"
},
{
"name": "采茶童-布篮子",
"url": "//yun.duiba.com.cn/aurora/assets/7ca607d0fd5471d33a4bb58c0d92122fe4ae425f.svga",
"uuid": "ba183e10-4059-4c3e-b9ec-c78192d5e980",
"ext": ".svga"
},
{
"name": "采茶童-竹编篮",
"url": "//yun.duiba.com.cn/aurora/assets/91b8f35ce06b9c65cb504c59ac6c3961f625fb2e.svga",
"uuid": "c7414e60-5312-4586-984a-d8b45a614621",
"ext": ".svga"
},
{
"name": "采茶童-木篮子",
"url": "//yun.duiba.com.cn/aurora/assets/de210099641d4d4fb2d323cc9da17f2f4e48a038.svga",
"uuid": "c492cbd4-aa42-4425-846f-86a91fd3f198",
"ext": ".svga"
},
{
"name": "待升级",
"url": "//yun.duiba.com.cn/aurora/assets/80834a2a25aca30b79dae655003fb7d6b8dc1b49.svga",
"uuid": "eb1f7929-f812-4b88-8345-5d61977fce39",
"ext": ".svga"
},
{
"name": "+1",
"url": "//yun.duiba.com.cn/aurora/assets/72c631a1da7b7969b7995fa16ccc1f435b9b57db.svga",
"uuid": "16a57950-0201-4904-8c65-6378fab65f59",
"ext": ".svga"
},
{
"name": "采茶叶",
"url": "//yun.duiba.com.cn/aurora/assets/6b89b11a26d0f91f1dad9e14b2d099e0d8450032.svga",
"uuid": " 81428208-0274-4e73-9f5e-27bb4a57f80a",
"ext": ".svga"
},
{
"name": "茶叶向上飞",
"url": "//yun.duiba.com.cn/aurora/assets/676ff9aabe60a49ca92f6ade26e62c6bb76be922.svga",
"uuid": "de7273ab-41be-4248-9f05-cdf8a7e3585b",
"ext": ".svga"
},
{
"name": "手抓去",
"url": "//yun.duiba.com.cn/aurora/assets/6b774da91be08d1c9f773d88ace4927c3c5de583.svga",
"uuid": "f1e7a7cf-95c7-4c91-a30b-935e31ea0084",
"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 = {
};
{
"name": "采茶叶",
"desc": "采茶叶模块",
"props": {
"versePos": {
"alias": "诗句的起始位置",
"type": "array<number>",
"default": "160,360"
},
"verses": {
"alias": "诗句",
"type": "array<string>",
"default": "今朝有酒今朝醉,今宵更有湘江月,雨过林霏清石气,秋将山翠入诗心,生怕芳丛鹰嘴芽,老郎封寄谪仙家"
},
"verseLabel": {
"alias": "提示语框xys",
"type": "array<number>",
"default": "396,50,22"
},
"verseColor": {
"alias": "颜色描边",
"type": "array<string>",
"default": "#33628b,#99b1c5"
},
"pickTeaSpeed": {
"alias": "采集茶叶的速度ms",
"type": "number",
"default": 1000
},
"basketSvgaPos": {
"alias": "人物的位置",
"type": "array<number>",
"default": "110,420"
},
"addOneSvgaPos": {
"alias": "+1SVGA的位置",
"type": "array<number>",
"default": "70,720"
},
"pickTeaSvgaPos": {
"alias": "采茶叶SVGA的位置",
"type": "array<number>",
"default": "377,530"
},
"teaSkyUpSvgaPos": {
"alias": "收集茶叶SVGA的位置",
"type": "array<number>",
"default": "320,192"
},
"handGraspSvgaPos": {
"alias": "手点击SVGA的位置",
"type": "array<number>",
"default": "543,791"
},
"handGraspMovePos": {
"alias": "手点击移动的位置",
"type": "array<number>",
"default": "460,700"
},
"progressbarBgImgPos": {
"alias": "进度条底图的位置",
"type": "array<number>",
"default": "69,818"
},
"progressbarImgPos": {
"alias": "进度条的位置",
"type": "array<number>",
"default": "-443,4"
},
"teaStarImgPos": {
"alias": "小茶叶的位置",
"type": "array<number>",
"default": "9,7"
},
"teaHalfFlagImgPos": {
"alias": "满缺的位置",
"type": "array<number>",
"default": "-15,-15"
},
"pickTeaCountPos": {
"alias": "文本进度的位置",
"type": "array<number>",
"default": "180,10"
}
},
"assets": [
{
"name": "气泡框",
"url": "//yun.duiba.com.cn/aurora/assets/585743f25262b6992ac97015e22d91054d506821.png",
"uuid": "1e6c4615-e1f4-43fe-b5de-9bfdaa27888c",
"ext": ".png"
},
{
"name": "进度条底框",
"url": "//yun.duiba.com.cn/aurora/assets/e394fce3576ddeed52fa4dceededc98820318f15.png",
"uuid": "7436ffbc-8906-4cdc-9e9a-80a3f7126e30",
"ext": ".png"
},
{
"name": "进度",
"url": "//yun.duiba.com.cn/aurora/assets/047218962662ed238192f211719c109fa107e8e1.png",
"uuid": "23e7861c-75a9-46bd-93f8-2825d4810d31",
"ext": ".png"
},
{
"name": "茶叶进度缺",
"url": "//yun.duiba.com.cn/aurora/assets/a99ad1582f44237f9391aeffa53b72c316a8ea83.png",
"uuid": "cc4f6b6c-0542-4b8d-b83d-1ee31e9c0e39",
"ext": ".png"
},
{
"name": "茶叶进度满",
"url": "//yun.duiba.com.cn/aurora/assets/7b1ac4e33309adfde360c92c1cdc8299a3e1efd0.png",
"uuid": "81728f22-c616-4133-8c78-c041cde68b79",
"ext": ".png"
},
{
"name": "小茶叶",
"url": "//yun.duiba.com.cn/aurora/assets/e938df1513919985c573128e1ed8074c9cc19dd5.png",
"uuid": "b30b3093-6097-4cc5-9364-ad1050f86c6e",
"ext": ".png"
},
{
"name": "茶叶-满",
"url": "//yun.duiba.com.cn/aurora/assets/acd219c8c8d472a3469183ba8d32568372e75797.png",
"uuid": "41431fe5-523c-4e21-a2bc-9dc4641d27e8",
"ext": ".png"
},
{
"name": "茶叶-少",
"url": "//yun.duiba.com.cn/aurora/assets/38f1874d0688fb8b621dfb1d3028d6f8ac61374d.png",
"uuid": "5765bb2b-3e7b-48fe-9e06-3c76a78c92dc",
"ext": ".png"
},
{
"name": "采茶童-纸篮子",
"url": "//yun.duiba.com.cn/aurora/assets/52f24f84d31709faea0fc35193692b134fe2e40d.svga",
"uuid": "8a7801dd-b802-4571-9f8e-e9acfb9c4527",
"ext": ".svga"
},
{
"name": "采茶童-布篮子",
"url": "//yun.duiba.com.cn/aurora/assets/7ca607d0fd5471d33a4bb58c0d92122fe4ae425f.svga",
"uuid": "ba183e10-4059-4c3e-b9ec-c78192d5e980",
"ext": ".svga"
},
{
"name": "采茶童-竹编篮",
"url": "//yun.duiba.com.cn/aurora/assets/91b8f35ce06b9c65cb504c59ac6c3961f625fb2e.svga",
"uuid": "c7414e60-5312-4586-984a-d8b45a614621",
"ext": ".svga"
},
{
"name": "采茶童-木篮子",
"url": "//yun.duiba.com.cn/aurora/assets/de210099641d4d4fb2d323cc9da17f2f4e48a038.svga",
"uuid": "c492cbd4-aa42-4425-846f-86a91fd3f198",
"ext": ".svga"
},
{
"name": "待升级",
"url": "//yun.duiba.com.cn/aurora/assets/80834a2a25aca30b79dae655003fb7d6b8dc1b49.svga",
"uuid": "eb1f7929-f812-4b88-8345-5d61977fce39",
"ext": ".svga"
},
{
"name": "+1",
"url": "//yun.duiba.com.cn/aurora/assets/72c631a1da7b7969b7995fa16ccc1f435b9b57db.svga",
"uuid": "16a57950-0201-4904-8c65-6378fab65f59",
"ext": ".svga"
},
{
"name": "采茶叶",
"url": "//yun.duiba.com.cn/aurora/assets/6b89b11a26d0f91f1dad9e14b2d099e0d8450032.svga",
"uuid": " 81428208-0274-4e73-9f5e-27bb4a57f80a",
"ext": ".svga"
},
{
"name": "茶叶向上飞",
"url": "//yun.duiba.com.cn/aurora/assets/676ff9aabe60a49ca92f6ade26e62c6bb76be922.svga",
"uuid": "de7273ab-41be-4248-9f05-cdf8a7e3585b",
"ext": ".svga"
},
{
"name": "手抓去",
"url": "//yun.duiba.com.cn/aurora/assets/6b774da91be08d1c9f773d88ace4927c3c5de583.svga",
"uuid": "f1e7a7cf-95c7-4c91-a30b-935e31ea0084",
"ext": ".svga"
}
],
"events": {
"in": {
"event-getchange-TeaNum": {
"alias": "茶叶数量{初始值totalNum,总量nowNum} "
},
"event-getBasket-Type": {
"alias": "获得篮子类型"
},
"event-hand-grasp": {
"alias": "手抓去"
}
},
"out": {
"event-setchange-TeaNum": {
"alias": "",
"data": {}
},
"event-setBasket-Typ": {
"alias": "",
"data": {}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
/*
event-pickTeaGame-init //游戏初始化
//event-wait-uplevel //待升级
event-add-oneScore //+1
event-pick-tea //采茶叶
event-tea-skyup //茶叶向上飞
event-hand-grasp //手抓去
event-change-TeaNum //茶叶数量 改变svga动画
event-getBasket-Type //获得篮子类型
event-setBasket-Type //设置篮子类型
*/
// event-getchange-TeaNum //茶叶数量{初始值totalNum,总量nowNum} 改变svga动画
// event-getBasket-Type //获得篮子类型
// event-hand-grasp //手抓去
//event-pickTeaGame-init 游戏初始化
engine.globalEvent.addEventListener('event-pickTeaGame-init', this.reset, this);
engine.globalEvent.addEventListener('event-hand-grasp', this.handGrasp, this);
engine.globalEvent.addEventListener('event-getchange-TeaNum', this.setTeaNum, this);
engine.globalEvent.addEventListener('event-getBasket-Type', this.setPickTeaLevel, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
}
//设置茶叶数量
setTeaNum(event: engine.Event) {
injectProps(event.data);
this._gameView.setTeaNum(event.data);
}
//设置茶蓝等级
setPickTeaLevel(event: engine.Event) {
injectProps(event.data);
this._gameView.setPickTeaLevel(event.data);
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
injectProps(event.data);
this._status = 1;
this._gameView.start();
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
clear() {
this._gameView.visible = false;
}
handGrasp() {
this._gameView.handGrasp();
}
private onTap(event) {
// this._gameView.tap(event);
}
}
/**
* Created by rockyl on 2020-02-02.
*
* 掉落物品
*/
import {getTextureByName} from "./utils";
import {props} from "../props";
export class Goods extends engine.Container {
private _body:engine.Rect
private _toY;
constructor() {
super();
let body
body = this._body =new engine.Rect()
let rain = new engine.Sprite(getTextureByName('雨滴'));
rain["npcType"]="rain"
let stone = new engine.Sprite(getTextureByName('石块'));
stone["npcType"]="stone"
let boom = new engine.Sprite(getTextureByName('炸弹'));
boom["npcType"]="boom"
rain.visible=false;
stone.visible=false;
boom.visible=false;
body.addChild(rain)
body.addChild(stone)
body.addChild(boom)
this.addChild(body);
body.width=.0001;
body.height=.0001;
body.mouseEnabled=false;
}
getRandomNumberByRange(start, end) {
return Math.floor(Math.random() * (end - start) + start)
}
reset() {
this.visible = true;
this.rotation = 0;
this.anchorOffsetY = 0;
this.y = 0;
this.x = (750-120)*Math.random()+30;
this.rotation = 0;
let random=Math.random()
if(random<props.goodsProbability[0]){
this.showNpc("rain")
}else if(random>=props.goodsProbability[0]&&random<=(props.goodsProbability[0]+props.goodsProbability[1])){
this.showNpc("stone")
}else if(random>(props.goodsProbability[0]+props.goodsProbability[1])){
this.showNpc("boom")
}
}
showNpc(type){
for(let i=0;i<this._body.children.length;i++){
this._body.children[i].visible=false;
this._body.children[i].mouseEnabled=false;
}
for(let i=0;i<this._body.children.length;i++){
if(this._body.children[i]["npcType"]==type){
this["npcType"]=type
this._body.children[i].visible=true;
this._body.children[i].mouseEnabled=false;
}
}
}
set anchorOffsetY(v) {
this._body.y = v;
}
}
import { getTextureByName } from "./utils";
export class Tealeaf extends engine.Container {
private _teaFull: engine.Image;
private _teaHalfFull: engine.Image;
private _teaImages: any
constructor() {
super();
this._teaFull = new engine.Image(getTextureByName('茶叶-满'));
this._teaHalfFull = new engine.Image(getTextureByName('茶叶-少'));
this._teaImages = [this._teaFull, this._teaHalfFull]
this.addChild(this._teaFull);
this.addChild(this._teaHalfFull);
}
reset() {
this.visible = true;
}
getSpriteUrl(index) {
let url = this._teaImages[index].url;
return url;
}
}
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
/**
* 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 createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
\ No newline at end of file
/**
* 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> { ...@@ -20,6 +20,7 @@ class AnimationPool extends Pool<PoolFrameAnimation> {
} else { } else {
let anim = new PoolFrameAnimation(key); let anim = new PoolFrameAnimation(key);
this.layer.addChild(anim); this.layer.addChild(anim);
return 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);
});
}
}
import { PlayGame } from './PlayGame';
import { Background } from "./Background";
import {Road} from './Road'
import {Player} from "./player/Player";
import {getStage,getfactor} from "./utils";
import {Block} from "./Block";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'block';
ObjectPool.registerPool(PoolName, function () {
return new Block();
}, function (item: Block, data) {
item.reset(data);
});
export default class GameView extends engine.Container {
private static _instance: GameView;
public static get instance(): GameView {
if (this._instance == undefined) {
this._instance = new GameView();
}
return this._instance;
}
offset = {x: -100, y: 320};
background: Background;
road: Road;
playGame:PlayGame;
world: p2.World;
player: Player;
revivePos;
playing;
lock;
worldFPS = 60;
private _block:Block;
_touchEnabled;
_viewport: any = {
x: 0,
y: 0,
};
constructor() {
super();
}
hasPreSetup;
eventStart() {
if(this.hasPreSetup){
return;
}
this.hasPreSetup = true;
let background = this.background = new Background();
background.setup();
this.addChild(background);
let road = this.road = new Road();
road.y = getStage().height / 2 + 310;
this.addChild(road);
this.road.preSetup();
this.setupWorld();
this.player.fade(0, false);
this.viewport = 0;
this.startWorld();
this.reset();
this.setup();
const playHint = new engine.Label();
playHint.fillColor = 'block';
playHint.size = 30;
playHint.text = '注意不要踩到线和陷阱哦,后果很严重哦~';
playHint.x = (getStage().width-playHint.width)/2;
playHint.y = getStage().height / 2 + 500;
this.addChild(playHint);
this.playGame = new PlayGame();
setTimeout(() => {
this.playGame.GameView = this;
this.addChild(this.playGame);
this.start();
}, 500);
}
hasSetup;
setup() {
if(this.hasSetup){
return;
}
this.hasSetup = true;
this.road.setup();
}
setupWorld() {
let OTHER = Math.pow(2, 1),
BODYPARTS = Math.pow(2, 2),
GROUND = Math.pow(2, 3);
const world = this.world = new p2.World({
//gravity: [0, 0],
});
world.sleepMode = p2.World.BODY_SLEEPING;
let planeShape = new p2.Plane();
let ground = new p2.Body({
position: [0, 0],
});
ground.addShape(planeShape);
planeShape.collisionGroup = GROUND;
planeShape.collisionMask = BODYPARTS | OTHER;
world.addBody(ground);
let player = this.player = new Player();
player.setup({
collisionGroup: BODYPARTS,
collisionMask: GROUND | OTHER,
world,
ground,
});
player.addEventListener('move', this.onMove, this);
player.addEventListener('foot_down', this.onFootDown, this);
}
onTicker(dt: number): boolean {
const world = this.world;
this.world.step(this.worldFPS / 1000);
let l = world.bodies.length;
for (let i: number = 0; i < l; i++) {
let body: p2.Body = world.bodies[i];
let display: any = body.displays ? body.displays[0] : null;
if (display) {
if (!this.contains(display)) {
this.addChild(display);
}
display.localUpdate(
body.position[0] * getfactor() + getStage().width / 2 + this.offset.x - this.viewport,
getStage().height / 2 - body.position[1] * getfactor() + this.offset.y,
360 - (body.angle + body.shapes[0].angle) * 180 / Math.PI,
body.sleepState == p2.Body.SLEEPING
)
}
}
return false;
}
reset(revive = false) {
this.background.reset(revive);
this.road.reset(revive);
this.player.reset(revive);
this.player.fade(0);
// if(!revive){
// this.score = 0;
// }
this.viewport = revive ? this.revivePos : 0;
}
start(revive = false){
this.road.start(revive);
this.player.fade(1);
this.playGame.start(revive);
}
startWorld() {
if(this.playing){
return;
}
this.playing = true;
//engine.startTick(this.onTicker, this);
engine.gameStage.addEventListener(engine.Event.ENTER_FRAME,this.onTicker,this)
}
stopWorld() {
if(!this.playing){
return;
}
this.playing = false;
//egret.stopTick(this.onTicker, this);
engine.gameStage.removeEventListener(engine.Event.ENTER_FRAME,this.onTicker,this)
}
get viewport() {
return this._viewport.x;
}
set viewport(v) {
this._viewport.x = v;
this.updateViewport();
}
updateViewport() {
const {x, y} = this._viewport;
const pos = Math.max(0, x);
this.background.setViewport(pos);
this.road.setViewport(pos);
}
private onMove(event) {
const {pos, bodyPos} = event.data;
this.viewport = pos;
if(this.road.hitReward(bodyPos)){
this.dispatchEvent('scoreChange', {
rewardScore: 100,
passType: 10,
}, true);
}
}
down() {
if(this.lock){
return;
}
this.player.down();
}
up() {
if(this.lock){
return;
}
this.player.up();
}
private onFootDown(event){
const {mileage, pos} = event.data;
this.revivePos = pos;
const {target, lastTarget} = this.road.hitBlock(pos);
this.road.playDust(pos);
if(target){
this.lock = true;
this.stopWorld();
this.dispatchEvent(engine.Event.COMPLETE,null,true);
target.playFadeOut();
target.playEffect();
if(target.type == 4){ //explosion
this.player.setSkin('gray');
}
this.road.removeBlock(target);
this.player.switchFace(target.type);
if(target.type == 0){
this.player.fall();
}
this.lock = false;
this.startWorld();
}else{
const score = Math.floor(mileage / 50 * 5);
this.dispatchEvent('scoreChange', {
score,
passType: lastTarget ? lastTarget.type : -1,
}, true);
}
}
}
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);
}
}
This diff is collapsed.
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