Commit d0b28e59 authored by zjz1994's avatar zjz1994

北京现代过桥墩,拼图

parent 5e9c78f6
This diff is collapsed.
This diff is collapsed.
...@@ -45,8 +45,11 @@ function launchWithCustomModule(customModule) { ...@@ -45,8 +45,11 @@ function launchWithCustomModule(customModule) {
}, 100); }, 100);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('bjxd-game-start', {guide: 2}); engine.globalEvent.dispatchEvent('bjxd-game-start', {guide: 1});
}, 500); }, 500);
setTimeout(() => {
engine.globalEvent.dispatchEvent('bjxd-game-reset', {guide: 2});
}, 600);
}); });
engine.globalEvent.addEventListener('dxbcyj-game-result', (e) => { engine.globalEvent.addEventListener('dxbcyj-game-result', (e) => {
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -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": "撑杆宽度",
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
}, },
{ {
"name": "yindao1", "name": "yindao1",
"url": "//yun.duiba.com.cn/aurora/assets/a0409ec24b35198e990c61bc7f5dc66b15a5213a.png", "url": "//yun.duiba.com.cn/aurora/assets/f21d5429dbd947e66613bd6c5d864fdcfd104bd4.png",
"uuid": "yindao1", "uuid": "yindao1",
"ext": ".png" "ext": ".png"
}, },
...@@ -169,9 +169,15 @@ ...@@ -169,9 +169,15 @@
}, },
{ {
"name": "walk", "name": "walk",
"url": "//yun.duiba.com.cn/aurora/assets/a4ab1e1a2b49d140db4a0806562098a8b1619b06.svga", "url": "//yun.duiba.com.cn/aurora/assets/5b31481f8d5669213da518b156aac7cadf5d9374",
"uuid": "10cd1fdd-4fd8-43cf-a1c7-6ff5846d8a91", "uuid": "10cd1fdd-4fd8-43cf-a1c7-6ff5846d8a91",
"ext": ".svga" "ext": ".svga"
},
{
"name": "xiache",
"url": "//yun.duiba.com.cn/aurora/assets/57ad75aa036c04e13abcf32c464ff5ae37419495",
"uuid": "xiache",
"ext": ".svga"
} }
], ],
"events": { "events": {
...@@ -196,6 +202,12 @@ ...@@ -196,6 +202,12 @@
"data": { "data": {
"index":1 "index":1
} }
},
"bjxd-game-speed": {
"alias": "修改速度",
"data": {
"speed":10
}
} }
}, },
"out": { "out": {
......
...@@ -5,7 +5,7 @@ import { Road } from './Road'; ...@@ -5,7 +5,7 @@ import { Road } from './Road';
*/ */
import {props} from "../props"; import {props} from "../props";
import {getStage,getTextureByName} from "./utils"; import {getStage,getTextureByName,createSvga} from "./utils";
import {GuideLayer} from "./GuideLayer"; import {GuideLayer} from "./GuideLayer";
import { Background } from "./Background"; import { Background } from "./Background";
import ObjectPool = engine.ObjectPool; import ObjectPool = engine.ObjectPool;
...@@ -29,6 +29,7 @@ export default class GameView extends engine.Container { ...@@ -29,6 +29,7 @@ export default class GameView extends engine.Container {
_backgroud:Background; _backgroud:Background;
_road:Road; _road:Road;
_player:Player; _player:Player;
_strut:Strut; _strut:Strut;
_touchLayer: engine.Rect; _touchLayer: engine.Rect;
_isTouchLayer; _isTouchLayer;
...@@ -44,6 +45,13 @@ export default class GameView extends engine.Container { ...@@ -44,6 +45,13 @@ export default class GameView extends engine.Container {
testchange:engine.Label; testchange:engine.Label;
static bgIndex:number = 0; static bgIndex:number = 0;
private xiacheNode:svga.Svga;
playery:number = 878;
inani:boolean = true;
pierWidth;
constructor() { constructor() {
super(); super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this); this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
...@@ -67,23 +75,55 @@ export default class GameView extends engine.Container { ...@@ -67,23 +75,55 @@ export default class GameView extends engine.Container {
this.addChild(player); this.addChild(player);
player.initPlayer(pierWidth); 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(); const strut = this._strut = new Strut();
this.addChild(strut); this.addChild(strut);
strut.init(); strut.init();
// this.startAnm();
// this._scoreContainer = new engine.Container(); // this._scoreContainer = new engine.Container();
// this.addChild(this._scoreContainer); // this.addChild(this._scoreContainer);
// this.initLabScore(); // 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) { async start(guide) {
this._isTouchLayer = true; this._isTouchLayer = true;
this._sumScore = 0; this._sumScore = 0;
this._isMouseDown = false; this._isMouseDown = false;
this._guide = guide; this._guide = guide;
this._player.revive();
this.closeStrut();
let initScore = this._road.getStartGold(0) ? props.goldScore : 0; let initScore = 0;//this._road.getStartGold(0) ? props.goldScore : 0;
this.updateScore(initScore); this.updateScore(initScore);
if(this.xiacheNode.x<this.pierWidth/2-105){
this.startAnm();
}
//是否是新手 //是否是新手
if(this._guide == '1'){ if(this._guide == '1'){
this.setGuide(); this.setGuide();
...@@ -92,10 +132,33 @@ export default class GameView extends engine.Container { ...@@ -92,10 +132,33 @@ export default class GameView extends engine.Container {
this.registerEvent(); this.registerEvent();
} }
} }
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();
}
//复活 //复活
revive(){ revive(){
console.log("复活---------"); // console.log("复活---------");
this._player.revive(); this._player.revive();
this.startAnm();
this._isTouchLayer = true; this._isTouchLayer = true;
this.closeStrut(); this.closeStrut();
} }
...@@ -166,7 +229,7 @@ export default class GameView extends engine.Container { ...@@ -166,7 +229,7 @@ export default class GameView extends engine.Container {
} }
//鼠标事件 //鼠标事件
onMouseDown(){ onMouseDown(){
if(this._isTouchLayer){ if(this._isTouchLayer&&!this.inani){
this._isMouseDown = true; this._isMouseDown = true;
this._strut.onMouseDown(this._road.getFristPier(),this._road.getDistance(),this.goCallBcak.bind(this)); this._strut.onMouseDown(this._road.getFristPier(),this._road.getDistance(),this.goCallBcak.bind(this));
} }
...@@ -181,7 +244,7 @@ export default class GameView extends engine.Container { ...@@ -181,7 +244,7 @@ export default class GameView extends engine.Container {
//撑杆回调 //撑杆回调
goCallBcak(isSuccess){ goCallBcak(isSuccess){
if(isSuccess){ if(isSuccess){
console.log('成功了'); // console.log('成功了');
let movePos = this._road.getMovePos(); let movePos = this._road.getMovePos();
if(this._road.getStartGold(1,false)){ if(this._road.getStartGold(1,false)){
this.updateScore(props.singleScore + props.goldScore); this.updateScore(props.singleScore + props.goldScore);
...@@ -192,9 +255,9 @@ export default class GameView extends engine.Container { ...@@ -192,9 +255,9 @@ export default class GameView extends engine.Container {
this._player.setViewport(movePos,this.complete.bind(this)); this._player.setViewport(movePos,this.complete.bind(this));
}else{ }else{
console.log('失败了'); // console.log('失败了');
this._player.setViewport(this._strut.getStrutHeight(),()=>{ this._player.setViewport(this._strut.getStrutHeight(),()=>{
console.log('掉下去了'); // console.log('掉下去了');
engine.globalEvent.dispatchEvent('bjxd-game-over',{score:this._sumScore}); engine.globalEvent.dispatchEvent('bjxd-game-over',{score:this._sumScore});
},this._road.getFristPier()) },this._road.getFristPier())
} }
...@@ -211,6 +274,17 @@ export default class GameView extends engine.Container { ...@@ -211,6 +274,17 @@ export default class GameView extends engine.Container {
this._player.setBackViewport(()=>{ this._player.setBackViewport(()=>{
this._isTouchLayer = true; 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);
}
this.closeStrut(); this.closeStrut();
} }
//重置撑杆 //重置撑杆
...@@ -228,7 +302,7 @@ export default class GameView extends engine.Container { ...@@ -228,7 +302,7 @@ export default class GameView extends engine.Container {
// this.changeBg(2); // this.changeBg(2);
// } // }
// this.labScore.updateScore(this._sumScore); // this.labScore.updateScore(this._sumScore);
console.log("新分数",this._sumScore); // console.log("新分数",this._sumScore);
engine.globalEvent.dispatchEvent('bjxd-game-score',{score:this._sumScore}); engine.globalEvent.dispatchEvent('bjxd-game-score',{score:this._sumScore});
} }
getScore(){ getScore(){
...@@ -244,4 +318,10 @@ export default class GameView extends engine.Container { ...@@ -244,4 +318,10 @@ export default class GameView extends engine.Container {
this._road.changeBg(); this._road.changeBg();
} }
} }
static speed = 10;
changeSpeed(speed){
if(GameView.speed!=speed){
GameView.speed = speed;
}
}
} }
...@@ -13,8 +13,10 @@ export class GameWrapper extends engine.Container { ...@@ -13,8 +13,10 @@ export class GameWrapper extends engine.Container {
super(); super();
engine.globalEvent.addEventListener('bjxd-game-start', this.start, this); 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-revive',this.revive,this);
engine.globalEvent.addEventListener('bjxd-game-change',this.change,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(); let gameView = this._gameView = new GameView();
this.addChild(gameView); this.addChild(gameView);
...@@ -24,6 +26,9 @@ export class GameWrapper extends engine.Container { ...@@ -24,6 +26,9 @@ 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);
} }
reset(){
this._gameView.reset();
}
revive(){ revive(){
this._gameView.revive(); this._gameView.revive();
} }
...@@ -31,4 +36,7 @@ export class GameWrapper extends engine.Container { ...@@ -31,4 +36,7 @@ export class GameWrapper extends engine.Container {
// console.log("切换图片显示"); // console.log("切换图片显示");
this._gameView.changeBg(event.data.index); this._gameView.changeBg(event.data.index);
} }
speed(event:engine.Event){
this._gameView.changeSpeed(event.data.speed);
}
} }
...@@ -22,14 +22,14 @@ export class Pier extends engine.Container { ...@@ -22,14 +22,14 @@ export class Pier extends engine.Container {
bmp.x = 0; bmp.x = 0;
bmp.y = this.zhuy; bmp.y = this.zhuy;
if(this.children.length < 2){ // if(this.children.length < 2){
const gold = new engine.Sprite(); // const gold = new engine.Sprite();
gold.texture = getTextureByName('gold'); // gold.texture = getTextureByName('gold');
gold.name = 'gold'; // gold.name = 'gold';
this.addChild(gold); // this.addChild(gold);
} // }
this.setGoldPosX(bmp); // this.setGoldPosX(bmp);
this.setShowGold(); // this.setShowGold();
} }
changeBg(){ changeBg(){
let texstr; let texstr;
......
...@@ -5,7 +5,7 @@ export class Player extends engine.Container{ ...@@ -5,7 +5,7 @@ export class Player extends engine.Container{
private playerNode: svga.Svga; private playerNode: svga.Svga;
pierWidth pierWidth
playery:number = 845; playery:number = 878;
initPlayer(pierWidth){ initPlayer(pierWidth){
this.pierWidth = pierWidth; this.pierWidth = pierWidth;
this._container = new engine.Container(); this._container = new engine.Container();
...@@ -15,13 +15,15 @@ export class Player extends engine.Container{ ...@@ -15,13 +15,15 @@ export class Player extends engine.Container{
this.playerNode = createSvga('walk'); this.playerNode = createSvga('walk');
this._container.addChild(this.playerNode); this._container.addChild(this.playerNode);
this.playerNode.y = this.playery; this.playerNode.y = this.playery;
this.playerNode.x = pierWidth/2 - 80; this.playerNode.x = pierWidth/2 - 50;
this.playerNode.play(); this.playerNode.play();
this._container.visible = false;
} }
revive(){ revive(){
this._container.x = 0; this._container.x = 0;
this._container.y = 0; this._container.y = 0;
this.playerNode.x = this.pierWidth/2 - 80; this.playerNode.x = this.pierWidth/2 - 50;
this.playerNode.y = this.playery; this.playerNode.y = this.playery;
} }
setViewport(pos,callBack,pierWidth?){ setViewport(pos,callBack,pierWidth?){
......
...@@ -53,14 +53,17 @@ export class Strut extends engine.Container{ ...@@ -53,14 +53,17 @@ export class Strut extends engine.Container{
paddingx = 20; paddingx = 20;
chax = 20; chax = 20;
}else if(GameView.bgIndex==1){ }else if(GameView.bgIndex==1){
paddingx = 30; paddingx = 3;
chax = 60; chax = 39;
}else if(GameView.bgIndex==2){ }else if(GameView.bgIndex==2){
paddingx = 20; paddingx = 20;
chax = 20; chax = 20;
} }
if(this._distance[0] - this._distance[1] + chax <= this._strut.height && this._strut.height <= this._distance[0] + paddingx){ let mindis = this._distance[0] - this._distance[1] + chax;
let maxdis = this._distance[0] + paddingx;
// console.log("成功失败判断",mindis,this._strut.height,maxdis);
if(mindis <= this._strut.height && this._strut.height <= maxdis){
isSuccess = true; isSuccess = true;
} }
if(this._callBack){ if(this._callBack){
...@@ -68,8 +71,31 @@ export class Strut extends engine.Container{ ...@@ -68,8 +71,31 @@ export class Strut extends engine.Container{
} }
} }
frameStrut(){ frameStrut(){
if(this._strut.height < 1000){ // let paddingx = 20;
this._strut.height += props.strutUpSpeed; // let chax = 20;
// if(GameView.bgIndex==0){
// paddingx = 20;
// chax = 20;
// }else if(GameView.bgIndex==1){
// paddingx = 3;
// chax = 39;
// }else if(GameView.bgIndex==2){
// paddingx = 20;
// chax = 20;
// }
// let tmindis = this._distance[0] - this._distance[1] + chax;
// let tmaxdis = this._distance[0] + paddingx;
let maxdis = 700;
// maxdis = 700;
// console.log("测试杆长",maxdis);
if(this._strut.height < maxdis){
if(this._strut.height+GameView.speed>maxdis){
this._strut.height = maxdis
}else{
this._strut.height += GameView.speed;
}
} }
} }
rest(){ rest(){
......
...@@ -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": "撑杆宽度",
......
...@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) { ...@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) {
setTimeout(()=>{ setTimeout(()=>{
engine.globalEvent.dispatchEvent('pictures-initgame', { engine.globalEvent.dispatchEvent('pictures-initgame', {
gameUrls:[ gameUrls:[
"https://yun.duiba.com.cn/aurora/assets/1456b2a9d72e56f075abb29df99052d87a0f1e48.jpg", "https://yun.duiba.com.cn/aurora/assets/7a9960acd582bb0b41bcfcdb24da68f354ccb1ff.jpg",
"https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg", "https://yun.duiba.com.cn/aurora/assets/61fd0754d7924305fd2851be86a480d71d2c2981.jpg",
"https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg" "https://yun.duiba.com.cn/aurora/assets/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
] ]
...@@ -56,12 +56,12 @@ function launchWithCustomModule(customModule) { ...@@ -56,12 +56,12 @@ function launchWithCustomModule(customModule) {
},1000); },1000);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', { // engine.globalEvent.dispatchEvent('pictures-start', {
actidx:0, // actidx:0,
rows:3, // rows:3,
cols:3, // cols:3,
gametime:30000 // 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;
......
This diff is collapsed.
This diff is collapsed.
...@@ -106,6 +106,24 @@ ...@@ -106,6 +106,24 @@
"data": { "data": {
"reason": "结束(1:成功,2失败)" "reason": "结束(1:成功,2失败)"
} }
},
"pictures-load-complete": {
"alias": "图片加载完毕",
"data": {
"reason": "结束(1:成功,2失败)"
}
},
"pictures-time-passtime": {
"alias": "倒计时进度条",
"data": {
"passtime": 0
}
},
"pictures-time-initcomp": {
"alias": "倒计时进度条",
"data": {
"passtime": 0
}
} }
} }
} }
......
...@@ -40,7 +40,10 @@ export default class GameView extends engine.Container { ...@@ -40,7 +40,10 @@ export default class GameView extends engine.Container {
picarr; picarr;
gameUrls:Array<string> = []; gameUrls:Array<string> = [];
gameTimes:Array<number> = [];
onegamePics:Array<engine.Texture> = []; onegamePics:Array<engine.Texture> = [];
movesteps:number = 0;
startime:number = 0;
constructor() { constructor() {
super(); super();
this.once(engine.Event.ADDED_TO_STAGE, this.initScene, this); this.once(engine.Event.ADDED_TO_STAGE, this.initScene, this);
...@@ -49,6 +52,8 @@ export default class GameView extends engine.Container { ...@@ -49,6 +52,8 @@ export default class GameView extends engine.Container {
this.lineShape = new engine.Shape(); this.lineShape = new engine.Shape();
this.selectimg3 = new engine.Image(getTextureByName("框3")); this.selectimg3 = new engine.Image(getTextureByName("框3"));
this.selectimg4 = new engine.Image(getTextureByName("框4")); this.selectimg4 = new engine.Image(getTextureByName("框4"));
this.selectimg3.mouseEnabled = false;
this.selectimg4.mouseEnabled = false;
//底图 //底图
this.dicont = new engine.Container(); this.dicont = new engine.Container();
//线 //线
...@@ -61,25 +66,132 @@ export default class GameView extends engine.Container { ...@@ -61,25 +66,132 @@ export default class GameView extends engine.Container {
this.addChild(this.blockcont); this.addChild(this.blockcont);
this.linecont.addChild(this.lineShape); this.linecont.addChild(this.lineShape);
console.log("拼图初始化完毕--------------");
engine.globalEvent.dispatchEvent("pictures-time-initcomp",{});
} }
async initgame(){ async initgame(){
console.log("initgame---------"); console.log("initgame---------");
this.gameUrls = props.gameUrls; this.gameUrls = props.gameUrls;
this.gameTimes = props.gameTimes;
this.onegamePics = new Array(); this.onegamePics = new Array();
for(let l=0;l<this.gameUrls.length;l++){ for(let l=0;l<this.gameUrls.length;l++){
let lurl = this.gameUrls[l]; let lurl = this.gameUrls[l];
let lt = await loadImageByUrl(lurl) as engine.Texture; let lt = await loadImageByUrl(lurl) as engine.Texture;
this.onegamePics.push(lt); this.onegamePics.push(lt);
if(this.onegamePics.length==1){//第一张图加载完毕,自动填充
this.startfirst();
}
}
}
async startfirst(){
this.dicont.removeChildren();
this.movesteps = 0;
this.startime = Date.now();
let actidx = 0;
this.gametime = this.gameTimes[actidx];
this.showtime = this.gameTimes[actidx];
this.passtime = 0;
engine.globalEvent.dispatchEvent("pictures-time-update",{
time:this.showtime,
});
engine.globalEvent.dispatchEvent("pictures-time-passtime",{
passtime:this.passtime
});
console.log("start-----------------",actidx);
this.rows = 3;
this.cols = 3;
this.nselectimg = null;
if(this.rows==3){
this.nselectimg = this.selectimg3;
}
if(this.rows==4){
this.nselectimg = this.selectimg4;
}
this.selectImgArr = new Array();
this.sucposData = {};
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;
if(res){
let picarr = result.picarr;
let mwid = result.mwid;
let mhei = result.mhei;
let picnames = result.picnames;
this.mwid = mwid;
this.mhei = mhei;
this.picarr = picarr;
this.picnames = picnames;
let gap = 2;
for(let r=0;r<this.rows;r++){
for(let c=0;c<this.cols;c++){
let ipicx = mwid*c+gap;
let ipicy = mhei*r+gap;
let npicname = "pic_"+c+"_"+r;
let ipic = picarr[npicname];
this.dicont.addChild(ipic);
ipic.x = ipicx;
ipic.y = ipicy;
}
}
//框线
this.lineShape.clear();
this.lineShape.beginStroke(0x0069df,4,engine.LINE_CAP.BUTT,engine.LINE_JOIN.BEVEL,100);
this.lineShape.moveTo(0+gap,0+gap);
this.lineShape.lineTo(mhei*this.cols+gap,0+gap);
this.lineShape.lineTo(mhei*this.cols+gap,mwid*this.rows+gap);
this.lineShape.lineTo(0+gap,mwid*this.rows+gap);
this.lineShape.lineTo(0+gap,0+gap);
for(let rl=1;rl<this.rows;rl++){
this.lineShape.moveTo(0+gap,rl*mhei+gap);
this.lineShape.lineTo(mwid*this.cols+gap,rl*mhei+gap);
}
for(let cl=1;cl<this.cols;cl++){
this.lineShape.moveTo(cl*mwid+gap,0+gap);
this.lineShape.lineTo(cl*mwid+gap,this.rows*mhei+gap);
}
this.lineShape.endStroke();
engine.globalEvent.dispatchEvent("pictures-load-complete");
this.ticker&&clearInterval(this.ticker);
this.ticker = setInterval(this.update, 10);
}else{
console.error("图片处理失败");
} }
} }
async start() { async start() {
this.dicont.removeChildren(); this.dicont.removeChildren();
this.movesteps = 0;
this.startime = Date.now();
let actidx = props.actidx; let actidx = props.actidx;
this.gametime = props.gametime; this.gametime = this.gameTimes[actidx];
this.showtime = props.gametime; this.showtime = this.gameTimes[actidx];
this.passtime = 0;
engine.globalEvent.dispatchEvent("pictures-time-update",{
time:this.showtime,
});
engine.globalEvent.dispatchEvent("pictures-time-passtime",{
passtime:this.passtime
});
console.log("start-----------------",actidx); console.log("start-----------------",actidx);
this.rows = props.rows; this.rows = props.rows;
this.cols = props.cols; this.cols = props.cols;
...@@ -92,7 +204,7 @@ export default class GameView extends engine.Container { ...@@ -92,7 +204,7 @@ export default class GameView extends engine.Container {
this.nselectimg = this.selectimg4; this.nselectimg = this.selectimg4;
} }
this.passtime = 0;
this.selectImgArr = new Array(); this.selectImgArr = new Array();
this.sucposData = {}; this.sucposData = {};
...@@ -164,8 +276,8 @@ export default class GameView extends engine.Container { ...@@ -164,8 +276,8 @@ export default class GameView extends engine.Container {
} }
this.lineShape.endStroke(); this.lineShape.endStroke();
this.ticker&&clearInterval(this.ticker);
this.ticker = setInterval(this.update, 20); this.ticker = setInterval(this.update, 10);
}else{ }else{
console.error("图片处理失败"); console.error("图片处理失败");
} }
...@@ -201,9 +313,12 @@ export default class GameView extends engine.Container { ...@@ -201,9 +313,12 @@ export default class GameView extends engine.Container {
} }
pause(){ pause(){
this.ingame = false; this.ingame = false;
console.error("拼图暂停");
} }
resume(){ resume(){
this.lastframetime = Date.now();
this.ingame = true; this.ingame = true;
console.error("拼图继续");
} }
...@@ -216,6 +331,9 @@ export default class GameView extends engine.Container { ...@@ -216,6 +331,9 @@ export default class GameView extends engine.Container {
if(this.ingame){ if(this.ingame){
let passtime = (ntime - this.lastframetime)/1000; let passtime = (ntime - this.lastframetime)/1000;
this.passtime += passtime; this.passtime += passtime;
engine.globalEvent.dispatchEvent("pictures-time-passtime",{
passtime:this.passtime
});
let showtime1 = Math.round(this.gametime - this.passtime); let showtime1 = Math.round(this.gametime - this.passtime);
// console.log(passtime,this.passtime,this.gametime,this.showtime); // console.log(passtime,this.passtime,this.gametime,this.showtime);
if(this.showtime!=showtime1){ if(this.showtime!=showtime1){
...@@ -251,6 +369,10 @@ export default class GameView extends engine.Container { ...@@ -251,6 +369,10 @@ export default class GameView extends engine.Container {
this.selectImgArr.push(selectname); this.selectImgArr.push(selectname);
}else if(this.selectImgArr.length==1){ }else if(this.selectImgArr.length==1){
if(selectname==this.selectImgArr[0]){ if(selectname==this.selectImgArr[0]){
if(this.nselectimg){
this.blockcont.removeChild(this.nselectimg);
}
this.selectImgArr = new Array();
return; return;
}else{ }else{
this.selectImgArr.push(selectname); this.selectImgArr.push(selectname);
...@@ -283,6 +405,8 @@ export default class GameView extends engine.Container { ...@@ -283,6 +405,8 @@ export default class GameView extends engine.Container {
this.selectImgArr = new Array(); this.selectImgArr = new Array();
this.movesteps += 1;
if(this.nselectimg){ if(this.nselectimg){
this.blockcont.removeChild(this.nselectimg); this.blockcont.removeChild(this.nselectimg);
} }
...@@ -317,9 +441,14 @@ export default class GameView extends engine.Container { ...@@ -317,9 +441,14 @@ export default class GameView extends engine.Container {
private gameover(reason:number) { private gameover(reason:number) {
this.ingame = false; this.ingame = false;
this.ticker&&clearInterval(this.ticker); this.ticker&&clearInterval(this.ticker);
let ntime = Date.now();
let gametime = ntime - this.startime;
engine.globalEvent.dispatchEvent('pictures-game-over', { engine.globalEvent.dispatchEvent('pictures-game-over', {
reason:reason, reason:reason,
time: this.passtime time: this.passtime,
number:this.movesteps,
gametime:gametime
}); });
} }
......
import { props } from "../props"; import { props } from "../props";
import { loadImageByUrl } from "./utils"; import { loadImageByUrl } from "./utils";
import qietu from "./qietu";
const urls = []; const urls = [];
const picMap = {}; const picMap = {};
const posMap = {}; const posMap = {};
...@@ -19,6 +20,29 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin ...@@ -19,6 +20,29 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let mwid = t.width; let mwid = t.width;
let mhei = t.height; let mhei = t.height;
if(mwid<10||mhei<10){
console.log("调整222222222222");
await new Promise(res=>{
setTimeout(function(){
res();
},200);
})
return qietu(t,1,rows,cols,parent);
}
console.log('图片',t);
console.log("图片获取尺寸",mwid,mhei);
if(mwid>mhei){
if(mhei<setimgwid){
mwid = mwid*setimgwid/mhei;
mhei = setimgwid;
}
}else{
if(mwid<setimgwid){
mhei = mhei*setimgwid/mwid;
mwid = setimgwid;
}
}
console.log("适配后的图片尺寸",mwid,mhei);
let picarr = {}; let picarr = {};
let picnames = []; let picnames = [];
......
...@@ -19,7 +19,7 @@ export function createSvga(name, anchorName?) { ...@@ -19,7 +19,7 @@ export function createSvga(name, anchorName?) {
return inst; return inst;
} }
export function loadImageByUrl(url){ export async function loadImageByUrl(url){
console.log('loadImageByUrl----------:',url); console.log('loadImageByUrl----------:',url);
return new Promise((resolve) => { return new Promise((resolve) => {
if (engine.TextureCache[url]) { if (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