Commit 5e9c78f6 authored by zjz1994's avatar zjz1994

代码暂存

parent 81e5868b
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* 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: 2});
}, 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": "#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/b2c76b2a753317e5ea935bab22097a43a4c9f7cb.png",
"uuid": "bg1",
"ext": ".png"
},
{
"name": "bg2",
"url": "//yun.duiba.com.cn/aurora/assets/7f8261a9dd7b83cdc3b95b6f3f385e7a91e49682.png",
"uuid": "bg2",
"ext": ".png"
},
{
"name": "bg3",
"url": "//yun.duiba.com.cn/aurora/assets/872c688f9c2f495fe234277256923804df2ab75e.png",
"uuid": "bg3",
"ext": ".png"
},
{
"name": "car1",
"url": "//yun.duiba.com.cn/aurora/assets/c1e80aee4eee3665e0f0bce08233b05be4b4ee9c.png",
"uuid": "car1",
"ext": ".png"
},
{
"name": "yindao1",
"url": "//yun.duiba.com.cn/aurora/assets/a0409ec24b35198e990c61bc7f5dc66b15a5213a.png",
"uuid": "yindao1",
"ext": ".png"
},
{
"name": "yindao2",
"url": "//yun.duiba.com.cn/aurora/assets/7ece2d8c438ec06004f7f40d9798ab72f0e6a244.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/a4ab1e1a2b49d140db4a0806562098a8b1619b06.svga",
"uuid": "10cd1fdd-4fd8-43cf-a1c7-6ff5846d8a91",
"ext": ".svga"
}
],
"events": {
"in": {
"bjxd-game-start": {
"alias": "开始",
"data": {
}
},
"bjxd-game-revive": {
"alias": "复活",
"data": {
}
},
"bjxd-game-reset": {
"alias": "重置",
"data": {
}
},
"bjxd-game-change": {
"alias": "替换显示",
"data": {
"index":1
}
}
},
"out": {
"bjxd-game-over": {
"alias": "游戏结束",
"data": {
"score":0
}
},
"bjxd-game-score": {
"alias": "分数",
"data": {
"score":0
}
}
}
}
}
\ 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} 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;
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();
}
}
//复活
revive(){
console.log("复活---------");
this._player.revive();
this._isTouchLayer = true;
this.closeStrut();
}
//新手引导
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(){
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;
// 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._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;
});
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();
}
}
}
/**
* 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-revive',this.revive,this);
engine.globalEvent.addEventListener('bjxd-game-change',this.change,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);
}
revive(){
this._gameView.revive();
}
change(event:engine.Event){
// console.log("切换图片显示");
this._gameView.changeBg(event.data.index);
}
}
/**
* 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
import { props } from './../props';
import {getTextureByName,getStage} from "./utils";
import GameView from './GameView';
export class Pier extends engine.Container {
bmp:engine.Sprite;
public haveGold;
part1tex = "zhuzi1";
part2tex = "zhuzi2";
part3tex = "zhuzi3";
texname:string = "";
constructor() {
super();
this.bmp = new engine.Sprite();
this.addChild(this.bmp);
}
zhuy:number = 1006;
init(){
const bmp = this.bmp;
bmp.alpha = 1;
this.changeBg();
bmp.x = 0;
bmp.y = this.zhuy;
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();
}
changeBg(){
let texstr;
if(GameView.bgIndex==0){
texstr = this.part1tex;
}else if(GameView.bgIndex==1){
texstr = this.part2tex;
}else{
texstr = this.part3tex;
}
if(this.texname!=texstr){
this.texname = texstr;
this.bmp.texture = getTextureByName(texstr);
}
}
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 = this.zhuy - 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;
pierWidth
playery:number = 845;
initPlayer(pierWidth){
this.pierWidth = pierWidth;
this._container = new engine.Container();
this.addChild(this._container);
this.playerNode = createSvga('walk');
this._container.addChild(this.playerNode);
this.playerNode.y = this.playery;
this.playerNode.x = pierWidth/2 - 80;
this.playerNode.play();
}
revive(){
this._container.x = 0;
this._container.y = 0;
this.playerNode.x = this.pierWidth/2 - 80;
this.playerNode.y = this.playery;
}
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 {getTextureByName,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);
pier.changeBg();
if(childrenNum == 0){
pier.x = 0;
}else{
pier.x = this.lastPos + randomPos;
}
this.lastPos = pier.x;
}
}
changeBg(){
let nume = this.children.length;
for(let i=0;i<nume;i++){
let ipier = this.getChildAt(i) as Pier;
ipier.changeBg();
}
}
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);
pier.changeBg();
}
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";
import GameView from "./GameView";
export class Strut extends engine.Container{
_strut: engine.Rect;
_distance;
_callBack;
gany = 1005;
init(){
this._strut = new engine.Rect();
this.addChild(this._strut);
this._strut.width = props.strutWidth;
this._strut.y = this.gany;
this._strut.fillColor = props.strutColor;
this._strut.rotation = 180;
}
onMouseDown(pierWidth,distance,callBack){
let paddingx = 20;
if(GameView.bgIndex==0){
paddingx = 20;
}else if(GameView.bgIndex==1){
paddingx = 30;
}else if(GameView.bgIndex==2){
paddingx = 20;
}
this._strut.x = pierWidth - paddingx;
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;
let paddingx = 20;
let chax = 20;
if(GameView.bgIndex==0){
paddingx = 20;
chax = 20;
}else if(GameView.bgIndex==1){
paddingx = 30;
chax = 60;
}else if(GameView.bgIndex==2){
paddingx = 20;
chax = 20;
}
if(this._distance[0] - this._distance[1] + chax <= this._strut.height && this._strut.height <= this._distance[0] + paddingx){
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 = this.gany;
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) {
// console.log("资源加载",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);
}
...@@ -45,7 +45,7 @@ function launchWithCustomModule(customModule) { ...@@ -45,7 +45,7 @@ function launchWithCustomModule(customModule) {
}, 100); }, 100);
setTimeout(() => { setTimeout(() => {
//engine.globalEvent.dispatchEvent('dxbcyj-game-start', {guide: 0}); engine.globalEvent.dispatchEvent('dxbcyj-game-start', {guide: 1});
}, 500); }, 500);
}); });
......
...@@ -420,6 +420,7 @@ ...@@ -420,6 +420,7 @@
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
Player.prototype.initPlayer = function (pierWidth) { Player.prototype.initPlayer = function (pierWidth) {
this.pierWidth = pierWidth;
this._container = new engine.Container(); this._container = new engine.Container();
this.addChild(this._container); this.addChild(this._container);
this.playerNode = createSvga('walk'); this.playerNode = createSvga('walk');
...@@ -428,6 +429,12 @@ ...@@ -428,6 +429,12 @@
this.playerNode.x = pierWidth / 2 - 80; this.playerNode.x = pierWidth / 2 - 80;
this.playerNode.play(); this.playerNode.play();
}; };
Player.prototype.revive = function () {
this._container.x = 0;
this._container.y = 0;
this.playerNode.x = this.pierWidth / 2 - 80;
this.playerNode.y = 675;
};
Player.prototype.setViewport = function (pos, callBack, pierWidth) { Player.prototype.setViewport = function (pos, callBack, pierWidth) {
var tmpPos = 0; var tmpPos = 0;
var isSuccess = false; var isSuccess = false;
...@@ -639,6 +646,12 @@ ...@@ -639,6 +646,12 @@
}); });
}); });
}; };
GameView.prototype.revive = function () {
console.log("复活---------");
this._player.revive();
this._isTouchLayer = true;
this.closeStrut();
};
GameView.prototype.setGuide = function () { GameView.prototype.setGuide = function () {
var _this = this; var _this = this;
this._road.setGuide(); this._road.setGuide();
...@@ -686,6 +699,14 @@ ...@@ -686,6 +699,14 @@
this._touchLayer.x = 0; this._touchLayer.x = 0;
this._touchLayer.y = 0; this._touchLayer.y = 0;
this._touchLayer.alpha = 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);
}; };
GameView.prototype.setScoreShow = function () { GameView.prototype.setScoreShow = function () {
}; };
...@@ -766,6 +787,7 @@ ...@@ -766,6 +787,7 @@
function GameWrapper() { function GameWrapper() {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('dxbcyj-game-start', _this.start, _this); engine.globalEvent.addEventListener('dxbcyj-game-start', _this.start, _this);
engine.globalEvent.addEventListener('dxbcyj-game-revive', _this.revive);
var gameView = _this._gameView = new GameView(); var gameView = _this._gameView = new GameView();
_this.addChild(gameView); _this.addChild(gameView);
return _this; return _this;
...@@ -773,6 +795,9 @@ ...@@ -773,6 +795,9 @@
GameWrapper.prototype.start = function (event) { GameWrapper.prototype.start = function (event) {
this._gameView.start(event.data.guide); this._gameView.start(event.data.guide);
}; };
GameWrapper.prototype.revive = function () {
this._gameView.revive();
};
return GameWrapper; return GameWrapper;
}(engine.Container)); }(engine.Container));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -39,6 +39,8 @@ export default class GameView extends engine.Container { ...@@ -39,6 +39,8 @@ export default class GameView extends engine.Container {
_isMouseDown; _isMouseDown;
_guide; _guide;
testrevive:engine.Label;
constructor() { constructor() {
super(); super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this); this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
...@@ -70,6 +72,7 @@ export default class GameView extends engine.Container { ...@@ -70,6 +72,7 @@ export default class GameView extends engine.Container {
this.addChild(this._scoreContainer); this.addChild(this._scoreContainer);
this.initLabScore(); this.initLabScore();
} }
async start(guide) { async start(guide) {
this._isTouchLayer = true; this._isTouchLayer = true;
...@@ -87,7 +90,14 @@ export default class GameView extends engine.Container { ...@@ -87,7 +90,14 @@ export default class GameView extends engine.Container {
this.initTouch(); this.initTouch();
this.registerEvent(); this.registerEvent();
} }
} }
//复活
revive(){
console.log("复活---------");
this._player.revive();
this._isTouchLayer = true;
this.closeStrut();
}
//新手引导 //新手引导
setGuide(){ setGuide(){
this._road.setGuide(); this._road.setGuide();
...@@ -139,7 +149,17 @@ export default class GameView extends engine.Container { ...@@ -139,7 +149,17 @@ export default class GameView extends engine.Container {
this._touchLayer.height = getStage().height; this._touchLayer.height = getStage().height;
this._touchLayer.x = 0; this._touchLayer.x = 0;
this._touchLayer.y = 0; this._touchLayer.y = 0;
this._touchLayer.alpha = 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);
} }
setScoreShow(){ setScoreShow(){
......
...@@ -13,7 +13,7 @@ export class GameWrapper extends engine.Container { ...@@ -13,7 +13,7 @@ export class GameWrapper extends engine.Container {
super(); super();
engine.globalEvent.addEventListener('dxbcyj-game-start', this.start, this); engine.globalEvent.addEventListener('dxbcyj-game-start', this.start, this);
engine.globalEvent.addEventListener('dxbcyj-game-revive',this.revive);
let gameView = this._gameView = new GameView(); let gameView = this._gameView = new GameView();
this.addChild(gameView); this.addChild(gameView);
...@@ -23,5 +23,7 @@ export class GameWrapper extends engine.Container { ...@@ -23,5 +23,7 @@ export class GameWrapper extends engine.Container {
start(event: engine.Event) { start(event: engine.Event) {
this._gameView.start(event.data.guide); this._gameView.start(event.data.guide);
} }
revive(){
this._gameView.revive();
}
} }
...@@ -4,8 +4,9 @@ export class Player extends engine.Container{ ...@@ -4,8 +4,9 @@ export class Player extends engine.Container{
_container; _container;
private playerNode: svga.Svga; private playerNode: svga.Svga;
pierWidth
initPlayer(pierWidth){ initPlayer(pierWidth){
this.pierWidth = pierWidth;
this._container = new engine.Container(); this._container = new engine.Container();
this.addChild(this._container); this.addChild(this._container);
...@@ -16,6 +17,12 @@ export class Player extends engine.Container{ ...@@ -16,6 +17,12 @@ export class Player extends engine.Container{
this.playerNode.x = pierWidth/2 - 80; this.playerNode.x = pierWidth/2 - 80;
this.playerNode.play(); this.playerNode.play();
} }
revive(){
this._container.x = 0;
this._container.y = 0;
this.playerNode.x = this.pierWidth/2 - 80;
this.playerNode.y = 675;
}
setViewport(pos,callBack,pierWidth?){ setViewport(pos,callBack,pierWidth?){
let tmpPos = 0; let tmpPos = 0;
let isSuccess = false; let isSuccess = false;
......
...@@ -45,18 +45,28 @@ function launchWithCustomModule(customModule) { ...@@ -45,18 +45,28 @@ function launchWithCustomModule(customModule) {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0)); engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100); }, 100);
setTimeout(()=>{
engine.globalEvent.dispatchEvent('pictures-initgame', {
gameUrls:[
"https://yun.duiba.com.cn/aurora/assets/1456b2a9d72e56f075abb29df99052d87a0f1e48.jpg",
"https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg",
"https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
]
})
},1000);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', { engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "//yun.duiba.com.cn/aurora/assets/eb952d8bfd900cb9367368ddf8048d66c44a52a0.png", actidx:0,
rows:3, rows:3,
cols:3, cols:3,
gametime:30 gametime:30000
}); });
// const d = engine.gameStage.sceneContainer.getChildAt(0); // const d = engine.gameStage.sceneContainer.getChildAt(0);
// engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2; // engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
// engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2; // engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000); }, 3000);
// setTimeout(() => { // setTimeout(() => {
// engine.globalEvent.dispatchEvent('pictures-start', { // engine.globalEvent.dispatchEvent('pictures-start', {
......
This diff is collapsed.
This diff is collapsed.
...@@ -65,15 +65,28 @@ ...@@ -65,15 +65,28 @@
], ],
"events": { "events": {
"in": { "in": {
"pictures-initgame": {
"alias": "初始化",
"data":{
"gameUrls":[
"https://yun.duiba.com.cn/aurora/assets/1456b2a9d72e56f075abb29df99052d87a0f1e48.jpg",
"https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg",
"https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
]
}
},
"pictures-start": { "pictures-start": {
"alias": "开始", "alias": "开始",
"data": { "data": {
"actidx":1,
"rows":3, "rows":3,
"cols":3, "cols":3,
"picUrl":"图片",
"gametime":30 "gametime":30
} }
}, },
"pictures-luanxu": {
"alias": "乱序"
},
"pictures-pause": { "pictures-pause": {
"alias": "停止" "alias": "停止"
}, },
......
...@@ -33,6 +33,14 @@ export default class GameView extends engine.Container { ...@@ -33,6 +33,14 @@ export default class GameView extends engine.Container {
blockcont:engine.Container; blockcont:engine.Container;
lineShape:engine.Shape; lineShape:engine.Shape;
mwid:number;
mhei:number;
picnames:Array<string>;
picarr;
gameUrls:Array<string> = [];
onegamePics:Array<engine.Texture> = [];
constructor() { constructor() {
super(); super();
this.once(engine.Event.ADDED_TO_STAGE, this.initScene, this); this.once(engine.Event.ADDED_TO_STAGE, this.initScene, this);
...@@ -54,13 +62,25 @@ export default class GameView extends engine.Container { ...@@ -54,13 +62,25 @@ export default class GameView extends engine.Container {
this.linecont.addChild(this.lineShape); this.linecont.addChild(this.lineShape);
} }
async initgame(){
console.log("initgame---------");
this.gameUrls = props.gameUrls;
this.onegamePics = new Array();
for(let l=0;l<this.gameUrls.length;l++){
let lurl = this.gameUrls[l];
let lt = await loadImageByUrl(lurl) as engine.Texture;
this.onegamePics.push(lt);
}
}
async start() { async start() {
this.dicont.removeChildren(); this.dicont.removeChildren();
let picUrl = props.picUrl; let actidx = props.actidx;
this.gametime = props.gametime; this.gametime = props.gametime;
this.showtime = props.gametime; this.showtime = props.gametime;
console.log("start-----------------",actidx);
this.rows = props.rows; this.rows = props.rows;
this.cols = props.cols; this.cols = props.cols;
...@@ -76,13 +96,26 @@ export default class GameView extends engine.Container { ...@@ -76,13 +96,26 @@ export default class GameView extends engine.Container {
this.selectImgArr = new Array(); this.selectImgArr = new Array();
this.sucposData = {}; this.sucposData = {};
let result = await qietu(picUrl,this.rows,this.cols,this.dicont);
let tex:any = this.onegamePics[actidx];
let type1 = 1;
if(!tex){
tex = this.gameUrls[actidx];
type1 = 2;
}
let result = await qietu(tex,type1,this.rows,this.cols,this.dicont);
let res = result.res; let res = result.res;
if(res){ if(res){
let picarr = result.picarr; let picarr = result.picarr;
let mwid = result.mwid; let mwid = result.mwid;
let mhei = result.mhei; let mhei = result.mhei;
let picnames = result.picnames; let picnames = result.picnames;
this.mwid = mwid;
this.mhei = mhei;
this.picarr = picarr;
this.picnames = picnames;
let gap = 2; let gap = 2;
for(let r=0;r<this.rows;r++){ for(let r=0;r<this.rows;r++){
for(let c=0;c<this.cols;c++){ for(let c=0;c<this.cols;c++){
...@@ -90,25 +123,25 @@ export default class GameView extends engine.Container { ...@@ -90,25 +123,25 @@ export default class GameView extends engine.Container {
let ipicy = mhei*r+gap; let ipicy = mhei*r+gap;
let npicname = "pic_"+c+"_"+r; let npicname = "pic_"+c+"_"+r;
this.sucposData[npicname] = r+"_"+c; // this.sucposData[npicname] = r+"_"+c;
let selidx = Math.floor(Math.random()*picnames.length); // let selidx = Math.floor(Math.random()*picnames.length);
let ipicname:string = picnames[selidx]; // let ipicname:string = picnames[selidx];
if(r==c&&r!=this.rows-1){ // if(r==c&&r!=this.rows-1){
while(ipicname==npicname){ // while(ipicname==npicname){
selidx = Math.floor(Math.random()*picnames.length); // selidx = Math.floor(Math.random()*picnames.length);
ipicname = picnames[selidx]; // ipicname = picnames[selidx];
} // }
} // }
let ipic = picarr[ipicname]; let ipic = picarr[npicname];
picnames.splice(selidx,1); // picnames.splice(selidx,1);
this.dicont.addChild(ipic); this.dicont.addChild(ipic);
ipic.x = ipicx; ipic.x = ipicx;
ipic.y = ipicy; ipic.y = ipicy;
ipic["postr"] = r+"_"+c; // ipic["postr"] = r+"_"+c;
ipic.addEventListener(engine.MouseEvent.MOUSE_DOWN, // ipic.addEventListener(engine.MouseEvent.MOUSE_DOWN,
this.touchPic,this); // this.touchPic,this);
} }
} }
//框线 //框线
...@@ -132,11 +165,40 @@ export default class GameView extends engine.Container { ...@@ -132,11 +165,40 @@ export default class GameView extends engine.Container {
this.lineShape.endStroke(); this.lineShape.endStroke();
this.ticker = setInterval(this.update, 30); this.ticker = setInterval(this.update, 20);
}else{ }else{
console.error("图片处理失败"); console.error("图片处理失败");
} }
} }
luanxu(){
let gap = 2;
for(let r=0;r<this.rows;r++){
for(let c=0;c<this.cols;c++){
let ipicx = this.mwid*c+gap;
let ipicy = this.mhei*r+gap;
let npicname = "pic_"+c+"_"+r;
this.sucposData[npicname] = r+"_"+c;
let selidx = Math.floor(Math.random()*this.picnames.length);
let ipicname:string = this.picnames[selidx];
if(r==c&&r!=this.rows-1){
while(ipicname==npicname){
selidx = Math.floor(Math.random()*this.picnames.length);
ipicname = this.picnames[selidx];
}
}
let ipic = this.picarr[ipicname];
this.picnames.splice(selidx,1);
ipic.x = ipicx;
ipic.y = ipicy;
ipic["postr"] = r+"_"+c;
ipic.addEventListener(engine.MouseEvent.MOUSE_DOWN,
this.touchPic,this);
}
}
}
pause(){ pause(){
this.ingame = false; this.ingame = false;
} }
......
...@@ -21,11 +21,19 @@ export class GameWrapper extends engine.Container { ...@@ -21,11 +21,19 @@ export class GameWrapper extends engine.Container {
this._gameView = new GameView(); this._gameView = new GameView();
this.addChild(this._gameView); this.addChild(this._gameView);
engine.globalEvent.addEventListener('pictures-initgame', this.initgame, this);
engine.globalEvent.addEventListener('pictures-start', this.start, this); engine.globalEvent.addEventListener('pictures-start', this.start, this);
engine.globalEvent.addEventListener('pictures-luanxu', this.luanxu, this);
engine.globalEvent.addEventListener('pictures-pause', this.pause, this); engine.globalEvent.addEventListener('pictures-pause', this.pause, this);
engine.globalEvent.addEventListener('pictures-resume', this.resume, this); engine.globalEvent.addEventListener('pictures-resume', this.resume, this);
} }
initgame(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
this._gameView.initgame();
}
start(event: engine.Event) { start(event: engine.Event) {
injectProps(event.data); injectProps(event.data);
...@@ -33,6 +41,9 @@ export class GameWrapper extends engine.Container { ...@@ -33,6 +41,9 @@ export class GameWrapper extends engine.Container {
this._gameView.start(); this._gameView.start();
} }
luanxu(){
this._gameView.luanxu();
}
pause(event: engine.Event) { pause(event: engine.Event) {
this._gameView.pause(); this._gameView.pause();
......
...@@ -3,22 +3,53 @@ import { loadImageByUrl } from "./utils"; ...@@ -3,22 +3,53 @@ import { loadImageByUrl } from "./utils";
const urls = []; const urls = [];
const picMap = {}; const picMap = {};
const posMap = {}; const posMap = {};
export default async(url:string, rows:number, cols:number,parent:engine.Container) => { export default async(url:any,type1:number, rows:number, cols:number,parent:engine.Container) => {
try{ try{
let t:engine.Texture = await loadImageByUrl(url) as engine.Texture; let t:engine.Texture;
if(type1==1){
console.log("直接使用已加载的tex");
t = url;
}else{
t = await loadImageByUrl(url) as engine.Texture;
}
let mwid = t.width/rows; let setimgwid = 612;
let mhei = t.height/cols; let mwid1 = setimgwid/rows;
let mhei1 = setimgwid/cols;
let mwid = t.width;
let mhei = t.height;
let picarr = {}; let picarr = {};
let picnames = []; let picnames = [];
let chax;
let chay;
let startlix;
let addlix;
let startliy;
let addliy;
if(mwid>mhei){
chax = (mwid-mhei)/2;
startlix = chax/mwid;
addlix = (mhei/cols)/mwid;
startliy = 0;
addliy = 1/rows;
}else{
startlix = 0;
addlix = 1/cols;
chay = (mhei-mwid)/2;
startliy = chay/mhei;
addliy = (mwid/rows)/mhei;
}
for(let r=0;r<rows;r++){ for(let r=0;r<rows;r++){
let startx = r/rows; let startx = startlix+addlix*r;
let endx = (r+1)/rows; let endx = startx + addlix;
// linedraw.moveTo()
for(let c=0;c<cols;c++){ for(let c=0;c<cols;c++){
let starty = c/cols; let starty = startliy+addliy*c;
let endy = (c+1)/cols; let endy = starty+addliy;
let uvs = new Float32Array([ let uvs = new Float32Array([
starty, starty,
...@@ -29,24 +60,24 @@ export default async(url:string, rows:number, cols:number,parent:engine.Containe ...@@ -29,24 +60,24 @@ export default async(url:string, rows:number, cols:number,parent:engine.Containe
endx, endx,
starty, starty,
endx endx
]); ])
let isprite = new engine.Sprite(t);
isprite.uvs = uvs;
let itexture = new engine.Sprite(t); isprite.width = mwid1;
itexture.uvs = uvs; isprite.height = mhei1;
itexture.width = mwid; let ispritename = "pic_"+c+"_"+r;
itexture.height = mhei; isprite.name = ispritename;
let itexname = "pic_"+c+"_"+r; picarr[ispritename] = isprite;
itexture.name = itexname; picnames.push(ispritename);
picarr[itexname] = itexture;
picnames.push(itexname);
} }
} }
return { return {
res:true, res:true,
picarr:picarr, picarr:picarr,
mwid:mwid, mwid:mwid1,
mhei:mhei, mhei:mhei1,
picnames:picnames picnames:picnames
}; };
}catch(e){ }catch(e){
......
...@@ -20,6 +20,7 @@ export function createSvga(name, anchorName?) { ...@@ -20,6 +20,7 @@ export function createSvga(name, anchorName?) {
} }
export function loadImageByUrl(url){ export function loadImageByUrl(url){
console.log('loadImageByUrl----------:',url);
return new Promise((resolve) => { return new Promise((resolve) => {
if (engine.TextureCache[url]) { if (engine.TextureCache[url]) {
resolve(engine.TextureCache[url]) resolve(engine.TextureCache[url])
......
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