Commit cbcb78af authored by lujinlei's avatar lujinlei

Merge branch 'dev' of http://gitlab2.dui88.com/laoqifeng/zeroing-libs into dev

parents 7dc16f58 55a77ca7
No preview for this file type
No preview for this file type
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "大转盘",
"desc": "大转盘模块",
"props": {
"iconSize": {
"alias": "奖品图的大小",
"type": "array<number>",
"default": "80,80"
},
"diameter": {
"alias": "圆盘直径",
"type": "number",
"default": "600"
},
"prizesRadius": {
"alias": "奖品距离圆心的距离",
"type": "number",
"default": 250
},
"nameColor": {
"alias": "奖品名称的字体颜色",
"type": "string",
"default": "#444444"
},
"nameSize": {
"alias": "奖品名称的字体大小",
"type": "number",
"default": 20
},
"iconY": {
"alias": "奖品名称的Y轴偏移",
"type": "number",
"default": 30
},
"rotationBg": {
"alias": "背景旋转",
"type": "number",
"default": 30
}
},
"assets": [
{
"name": "大转盘背景",
"url": "//yun.duiba.com.cn/aurora/assets/559177b3c0d4245d245b5cdfa31ba9d9dc20223c.png",
"uuid": "d3ce99da-89e1-447d-8c52-b3f391925c3c",
"ext": ".png"
}
],
"events": {
"in": {
"turnplate-reset": {
"alias": "重置",
"data": {
"prizes": "所有奖品"
}
},
"turnplate-start": {
"alias": "开始",
"data": {
"prizeId": "中奖的奖品id"
}
}
},
"out": {
"turnplate-over": {
"alias": "转盘停止",
"data": {
"prizeId": "中奖的奖品id"
}
}
}
},
"id": "turnplate",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof define === 'function' && define.amd ? define(['tslib'], factory) :\n\t(global = global || self, global.turnplate = factory(global.tslib));\n}(this, (function (tslib) { 'use strict';\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\n\tfunction getTextureByName(name) {\n\t return engine.Texture.from(getAssetByName(name).uuid);\n\t}\n\n\tvar GameWrapper = (function (_super) {\n\t tslib.__extends(GameWrapper, _super);\n\t function GameWrapper() {\n\t var _this = _super.call(this) || this;\n\t _this.wheelPrizeRotation = [];\n\t _this.items = [];\n\t _this.itemsCon = [];\n\t _this.itemsLabel = [];\n\t _this.itemsIcon = [];\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t engine.globalEvent.addEventListener('turnplate-reset', _this.reset, _this);\n\t engine.globalEvent.addEventListener('turnplate-start', _this.start, _this);\n\t return _this;\n\t }\n\t GameWrapper.prototype.setup = function () {\n\t this.turnplate = new engine.Container();\n\t this.turnplate.x = 0;\n\t this.turnplate.y = 0;\n\t this.turnplate.rotation = -90;\n\t this.turnplate.width = props.diameter;\n\t this.turnplate.height = props.diameter;\n\t this.turnplate.anchorX = this.turnplate.width / 2;\n\t this.turnplate.anchorY = this.turnplate.height / 2;\n\t this.addChild(this.turnplate);\n\t this._turnplateBG = new engine.Container();\n\t this._turnplateBG.width = props.diameter;\n\t this._turnplateBG.height = props.diameter;\n\t this._turnplateBG.anchorX = this.turnplate.width / 2;\n\t this._turnplateBG.anchorY = this.turnplate.height / 2;\n\t this._turnplateBG.rotation = props.rotationBg;\n\t this.turnplate.addChild(this._turnplateBG);\n\t this.turnplateBg = new engine.Sprite(getTextureByName('大转盘背景'));\n\t this.turnplateBg.x = 0;\n\t this.turnplateBg.y = 0;\n\t this.turnplateBg.width = this.turnplate.width;\n\t this.turnplateBg.height = this.turnplate.height;\n\t this._turnplateBG.addChild(this.turnplateBg);\n\t };\n\t GameWrapper.prototype.reset = function (event) {\n\t injectProps(event.data);\n\t this.prizes = event.data.prizes;\n\t console.log(this.prizes);\n\t for (var i = 0; i < this.items.length; i++) {\n\t this.itemsCon[i].removeChild(this.itemsLabel[i]);\n\t this.itemsCon[i].removeChild(this.itemsIcon[i]);\n\t this.items[i].removeChild(this.itemsCon[i]);\n\t this.turnplate.removeChild(this.items[i]);\n\t }\n\t for (var i = 0; i < this.prizes.length; i++) {\n\t this.items[i] = new engine.Container();\n\t this.itemsCon[i] = new engine.Container();\n\t this.itemsCon[i].x = props.prizesRadius;\n\t this.itemsCon[i].rotation = 90;\n\t this.items[i].x = this.turnplate.width / 2;\n\t this.items[i].y = this.turnplate.height / 2;\n\t this.turnplate.addChild(this.items[i]);\n\t this.itemsLabel[i] = new engine.Label();\n\t this.itemsLabel[i].text = this.prizes[i].name;\n\t this.itemsLabel[i].width = 200;\n\t this.itemsLabel[i].x = -this.itemsLabel[i].width / 2;\n\t this.itemsLabel[i].textAlign = \"center\";\n\t this.itemsLabel[i].fillColor = props.nameColor;\n\t this.itemsLabel[i].size = props.nameSize;\n\t this.itemsIcon[i] = new engine.Sprite();\n\t this.itemsIcon[i].width = props.iconSize[0];\n\t this.itemsIcon[i].height = props.iconSize[1];\n\t this.itemsIcon[i].x = -this.itemsIcon[i].width / 2;\n\t this.itemsIcon[i].y = props.iconY;\n\t this.itemsIcon[i].texture = engine.Texture.from(this.prizes[i].icon);\n\t this.itemsCon[i].addChild(this.itemsLabel[i]);\n\t this.itemsCon[i].addChild(this.itemsIcon[i]);\n\t this.items[i].addChild(this.itemsCon[i]);\n\t var _rotation = (i) * (360 / this.prizes.length);\n\t this.items[i].rotation = _rotation;\n\t this.wheelPrizeRotation[this.prizes[i].prizeId] = _rotation;\n\t }\n\t this.turnplate.rotation = -90;\n\t engine.Tween.removeTweens(this.turnplate);\n\t engine.Tween.get(this.turnplate, { loop: true })\n\t .to({ rotation: 360 - 90 }, 5000);\n\t };\n\t GameWrapper.prototype.start = function (event) {\n\t var _this = this;\n\t injectProps(event.data);\n\t engine.Tween.removeTweens(this.turnplate);\n\t var prizeId = event.data.prizeId;\n\t engine.Tween.get(this.turnplate)\n\t .to({ rotation: 7200 - this.wheelPrizeRotation[prizeId] - 90 }, 8000, engine.Ease.circInOut)\n\t .wait(500)\n\t .call(function () {\n\t _this.turnplate.rotation = 360 - _this.wheelPrizeRotation[prizeId] + 0.001 - 90;\n\t engine.globalEvent.dispatchEvent('turnplate-over', {\n\t prizeId: prizeId\n\t });\n\t });\n\t };\n\t return GameWrapper;\n\t}(engine.Container));\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new GameWrapper();\n\t return instance;\n\t}\n\n\treturn index;\n\n})));\n"
}
This diff is collapsed.
This diff is collapsed.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"typescript": "^3.7.2" "typescript": "^3.7.2"
}, },
"dependencies": { "dependencies": {
"cnpm": "^6.1.1",
"commander": "^4.1.0", "commander": "^4.1.0",
"watchr": "^5.6.0" "watchr": "^5.6.0"
} }
......
/**
* Created by rockyl on 2019-12-16.
*/
const customId = 'bjxd-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('bjxd-game-start', {guide: 1});
}, 500);
setTimeout(() => {
engine.globalEvent.dispatchEvent('bjxd-game-reset', {guide: 2});
}, 600);
});
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": 30
},
"strutWidth": {
"alias": "撑杆宽度",
"type": "number",
"default": 5
},
"strutColor": {
"alias": "撑杆颜色",
"type": "string",
"default": "#ffffff"
},
"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": "bg1",
"url": "//yun.duiba.com.cn/aurora/assets/f3fda198741657d9cab9418bd5d47248af065487.jpg",
"uuid": "bg1",
"ext": ".jpg"
},
{
"name": "bg2",
"url": "//yun.duiba.com.cn/aurora/assets/8fa1de1570023f21b676a8602ec9315cee83a99b.jpg",
"uuid": "bg2",
"ext": ".jpg"
},
{
"name": "bg3",
"url": "//yun.duiba.com.cn/aurora/assets/517fc529c79b18ff4881d206c942c8f2888ad6fd.jpg",
"uuid": "bg3",
"ext": ".jpg"
},
{
"name": "car1",
"url": "//yun.duiba.com.cn/aurora/assets/c1e80aee4eee3665e0f0bce08233b05be4b4ee9c.png",
"uuid": "car1",
"ext": ".png"
},
{
"name": "yindao1",
"url": "//yun.duiba.com.cn/aurora/assets/4449285320882460ae0dd0b59b3c73e0bb92def6.png",
"uuid": "yindao1",
"ext": ".png"
},
{
"name": "yindao2",
"url": "//yun.duiba.com.cn/aurora/assets/1c914031834736b93e9b2a94a4e8a643871795f7.png",
"uuid": "yindao2",
"ext": ".png"
},
{
"name": "shouzhi",
"url": "//yun.duiba.com.cn/aurora/assets/fd62b438bfd67345fe441f5e68e4394d650fac8d.png",
"uuid": "shouzhi",
"ext": ".png"
},
{
"name": "zhuzi1",
"url": "//yun.duiba.com.cn/aurora/assets/cb779c9ebf4bfbd5bec1d817a6ef824d4ae5d751.png",
"uuid": "zhuzi1",
"ext": ".png"
},
{
"name": "zhuzi2",
"url": "//yun.duiba.com.cn/aurora/assets/c5187595bec08c211c8e45bf5f163ff02fd659ab.png",
"uuid": "zhuzi2",
"ext": ".png"
},
{
"name": "zhuzi3",
"url": "//yun.duiba.com.cn/aurora/assets/08dc255864c2af52dac7a993a4c62b1970dd6db4.png",
"uuid": "zhuzi3",
"ext": ".png"
},
{
"name": "person",
"url": "//yun.duiba.com.cn/aurora/assets/094526243496c8ebf1002f73f3cbbf3c9e12892a.png",
"uuid": "person",
"ext": ".png"
},
{
"name": "gold",
"url": "//yun.duiba.com.cn/aurora/assets/ae210ad26cee13f8fb6e69be62f7f5498be50a5b.png",
"uuid": "7f4e19f2-c80f-4a65-bec2-1f3c3dc6d210",
"ext": ".png"
},
{
"name": "walk",
"url": "//yun.duiba.com.cn/aurora/assets/5b31481f8d5669213da518b156aac7cadf5d9374",
"uuid": "10cd1fdd-4fd8-43cf-a1c7-6ff5846d8a91",
"ext": ".svga"
},
{
"name": "xiache",
"url": "//yun.duiba.com.cn/aurora/assets/57ad75aa036c04e13abcf32c464ff5ae37419495",
"uuid": "xiache",
"ext": ".svga"
},
{
"name": "ganzi",
"url": "//yun.duiba.com.cn/aurora/assets/501972d5960c29b7db1e476422e6fd3cb3a92c8f.png",
"uuid": "ganzi",
"ext": ".png"
}
],
"events": {
"in": {
"bjxd-game-start": {
"alias": "开始",
"data": {
}
},
"bjxd-game-revive": {
"alias": "复活",
"data": {
}
},
"bjxd-game-reset": {
"alias": "重置",
"data": {
}
},
"bjxd-game-change": {
"alias": "替换显示",
"data": {
"index":1
}
},
"bjxd-game-speed": {
"alias": "修改速度",
"data": {
"speed":10
}
}
},
"out": {
"bjxd-game-over": {
"alias": "游戏结束",
"data": {
"score":0
}
},
"bjxd-game-score": {
"alias": "分数",
"data": {
"score":0
}
},
"bjxd-game-inmove": {
"alias": "游戏进行状态",
"data": {
"canstop":false
}
}
}
}
}
\ 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 = ['bg1',''];
partResHB = ['bg2',''];
partResWH = ['bg3',''];
speeds = [];
resArray=[];
frameMovePos = 0;
frameIndex;
sumMovePos;
//需要的总帧数
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)
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;
}
}
}
}
\ No newline at end of file
import { Road } from './Road';
/**
* Created by rockyl on 2018/8/16.
*/
import {props} from "../props";
import {getStage,getTextureByName,createSvga} 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;
testrevive:engine.Label;
testchange:engine.Label;
static bgIndex:number = 0;
private xiacheNode:svga.Svga;
playery:number = 878;
inani:boolean = true;
pierWidth;
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);
this.pierWidth = pierWidth;
this.xiacheNode = createSvga("xiache");
this.addChild(this.xiacheNode);
this.xiacheNode.y = this.playery-35;
this.xiacheNode.x = this.pierWidth/2 - 100;
this.xiacheNode.stop();
this.xiacheNode.name = "xiacheanm";
console.log("下车动画帧数",this.xiacheNode.totalFrames,this.xiacheNode);
// this.xiacheNode.addEventListener(engine.Event.ENTER_FRAME,this.playComp,this);
this.xiacheNode.visible = false;
const strut = this._strut = new Strut();
this.addChild(strut);
strut.init();
// this.startAnm();
// this._scoreContainer = new engine.Container();
// this.addChild(this._scoreContainer);
// this.initLabScore();
}
playComp(){
let curframe = this.xiacheNode.currentFrame;
if(curframe==this.xiacheNode.totalFrames){
this.inani = false;
// console.log("下车动画播放完毕",curframe,this.xiacheNode);
this.xiacheNode.stop();
this.xiacheNode.removeEventListener(engine.Event.ENTER_FRAME,this.playComp,this);
for(let i=0;i<15;i++){
if(i<12){
this.xiacheNode.getChildAt(i).visible = false;
}
}
this._player._container.visible = true;
}
}
async start(guide) {
this._isTouchLayer = true;
this._sumScore = 0;
this._isMouseDown = false;
this._guide = guide;
this._player.revive();
this.closeStrut();
let initScore = 0;//this._road.getStartGold(0) ? props.goldScore : 0;
this.updateScore(initScore);
if(this.xiacheNode.x<this.pierWidth/2-105){
this.startAnm();
}
//是否是新手
if(this._guide == '1'){
this.setGuide();
}else{
this.initTouch();
this.registerEvent();
}
engine.globalEvent.dispatchEvent("bjxd-game-inmove",{
"canstop":true
});
}
startAnm(){
this.inani = true;
this.xiacheNode.visible = true;
for(let i=0;i<15;i++){
if(i<12){
this.xiacheNode.getChildAt(i).visible = true;
}
}
this.xiacheNode.x = this.pierWidth/2 - 100;
this._player._container.visible = false;
this.xiacheNode.gotoAndPlay(1);
this.xiacheNode.addEventListener(engine.Event.ENTER_FRAME,this.playComp,this);
}
//重置
reset(){
this._sumScore = 0;
engine.globalEvent.dispatchEvent('bjxd-game-score',{score:this._sumScore});
this._player.revive();
this.closeStrut();
this.changeBg(GameView.bgIndex);
this.startAnm();
engine.globalEvent.dispatchEvent("bjxd-game-inmove",{
"canstop":true
});
}
//复活
revive(){
// console.log("复活---------");
this._player.revive();
this.startAnm();
this._isTouchLayer = true;
this.closeStrut();
engine.globalEvent.dispatchEvent("bjxd-game-inmove",{
"canstop":true
});
}
//新手引导
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(){
// this.labScore = new ScoreLabel();
// this.labScore.fillColor = 0xff7646;
// this.labScore.size = 70;
// this.labScore.width = getStage().width;
// this.labScore.textAlign = engine.TEXT_ALIGN.CENTER;
// this.labScore.x = 0;
// this._scoreContainer.addChild(this.labScore);
}
registerEvent(){
// console.log("注册mouse监听1");
this.removeListener();
// if(!this.hasEventListener(engine.MouseEvent.MOUSE_DOWN)){
// console.log("注册mouse监听2");
this.addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onMouseDown,this);
// }
// if(!this.hasEventListener(engine.MouseEvent.MOUSE_UP)){
// console.log("注册mouse监听3");
this.addEventListener(engine.MouseEvent.MOUSE_UP,this.onMouseUp,this);
// }
// this._touchLayer.addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onMouseDown,this);
// this._touchLayer.addEventListener(engine.MouseEvent.MOUSE_UP,this.onMouseUp,this);
}
removeListener(){
this.removeEventListener(engine.MouseEvent.MOUSE_DOWN,this.onMouseDown,this);
this.removeEventListener(engine.MouseEvent.MOUSE_UP,this.onMouseUp,this);
// 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;
// this.testrevive = new engine.Label();
// this.addChild(this.testrevive);
// this.testrevive.size = 55;
// this.testrevive.text = "复活";
// this.testrevive.width = 500;
// this.testrevive.height = 200;
// this.testrevive.mouseEnabled = true;
// this.testrevive.addEventListener(engine.MouseEvent.CLICK,this.revive,this);
// this.testchange = new engine.Label();
// this.addChild(this.testchange);
// this.testchange.size = 55;
// this.testchange.text = "复活";
// this.testchange.width = 500;
// this.testchange.height = 200;
// this.testchange.mouseEnabled = true;
// this.testchange.addEventListener(engine.MouseEvent.CLICK,this.changeBg,this);
}
setScoreShow(){
}
//鼠标事件
onMouseDown(){
if(this._isTouchLayer&&!this.inani){
engine.globalEvent.dispatchEvent("bjxd-game-inmove",{
"canstop":false
});
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('bjxd-game-over',{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;
});
let carx = this.xiacheNode.x;
if(carx>-200){
carx -= movePos;
engine.Tween.get(this.xiacheNode,{loop:false})
.to({
x:carx
},props.pierMoveTime)
}
engine.globalEvent.dispatchEvent("bjxd-game-inmove",{
"canstop":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);
// console.log("新分数",this._sumScore);
engine.globalEvent.dispatchEvent('bjxd-game-score',{score:this._sumScore});
}
getScore(){
return this._sumScore;
}
changeBg(index){
// index = (GameView.bgIndex +1)%3;
// console.log("切换图片",index);
if(GameView.bgIndex != index){
GameView.bgIndex = index;
this._backgroud.changeBg(index);
this._road.changeBg();
}
}
static speed = 20;
changeSpeed(speed){
if(GameView.speed!=speed){
GameView.speed = speed;
}
}
}
/**
* 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('bjxd-game-start', this.start, this);
engine.globalEvent.addEventListener('bjxd-game-reset', this.reset, this);
engine.globalEvent.addEventListener('bjxd-game-revive',this.revive,this);
engine.globalEvent.addEventListener('bjxd-game-change',this.change,this);
engine.globalEvent.addEventListener('bjxd-game-speed',this.speed,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);
}
reset(){
this._gameView.reset();
}
revive(){
this._gameView.revive();
}
change(event:engine.Event){
// console.log("切换图片显示");
this._gameView.changeBg(event.data.index);
}
speed(event:engine.Event){
this._gameView.changeSpeed(event.data.speed);
}
}
/**
* 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;
guideImg:engine.Image;
shouzhi:engine.Image;
_options;
_callBack;
constructor() {
super();
this.setup();
}
private setup() {
}
show(id, options,callback?) {
this.visible = true;
this._callBack = callback?callback:null;
if (!this.guideMask) {
const {width, height} = this.stage;
this.guideMask = new engine.Container();
this.addChild(this.guideMask);
this.guideImg = new engine.Image();
this.guideMask.addChild(this.guideImg);
this.shouzhi = new engine.Image(getTextureByName("shouzhi"));
this.guideMask.addChild(this.shouzhi);
}
this.guideImg.texture = getTextureByName("yindao"+id);
this.guideStep(id);
this.once(engine.MouseEvent.CLICK, function(){
this.visible = false;
if(this._callBack){
this._callBack();
}
}, this);
}
guideStep(id){
if(id == 1){
this.shouzhi.x = 244;
this.shouzhi.y = 812;
}
if(id == 2){
this.shouzhi.x = 346;
this.shouzhi.y = 1108;
}
}
}
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'){
if(item.length>0){
part = new engine.Sprite(getTextureByName(item));
}else{
part = new engine.Sprite();
}
}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) => {
if(changName&&changName.length>0){
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
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 {
_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;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* 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;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
"strutUpSpeed": { "strutUpSpeed": {
"alias": "撑杆上升速度(每帧上升增量,一秒60帧)", "alias": "撑杆上升速度(每帧上升增量,一秒60帧)",
"type": "number", "type": "number",
"default": 10 "default": 30
}, },
"strutWidth": { "strutWidth": {
"alias": "撑杆宽度", "alias": "撑杆宽度",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 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);
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
This diff is collapsed.
/**
* 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();
});
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment