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) {
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('bjxd-game-start', {guide: 2});
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) => {
......
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 @@
"strutUpSpeed": {
"alias": "撑杆上升速度(每帧上升增量,一秒60帧)",
"type": "number",
"default": 10
"default": 30
},
"strutWidth": {
"alias": "撑杆宽度",
......@@ -121,7 +121,7 @@
},
{
"name": "yindao1",
"url": "//yun.duiba.com.cn/aurora/assets/a0409ec24b35198e990c61bc7f5dc66b15a5213a.png",
"url": "//yun.duiba.com.cn/aurora/assets/f21d5429dbd947e66613bd6c5d864fdcfd104bd4.png",
"uuid": "yindao1",
"ext": ".png"
},
......@@ -169,9 +169,15 @@
},
{
"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",
"ext": ".svga"
},
{
"name": "xiache",
"url": "//yun.duiba.com.cn/aurora/assets/57ad75aa036c04e13abcf32c464ff5ae37419495",
"uuid": "xiache",
"ext": ".svga"
}
],
"events": {
......@@ -196,6 +202,12 @@
"data": {
"index":1
}
},
"bjxd-game-speed": {
"alias": "修改速度",
"data": {
"speed":10
}
}
},
"out": {
......
......@@ -5,7 +5,7 @@ import { Road } from './Road';
*/
import {props} from "../props";
import {getStage,getTextureByName} from "./utils";
import {getStage,getTextureByName,createSvga} from "./utils";
import {GuideLayer} from "./GuideLayer";
import { Background } from "./Background";
import ObjectPool = engine.ObjectPool;
......@@ -29,6 +29,7 @@ export default class GameView extends engine.Container {
_backgroud:Background;
_road:Road;
_player:Player;
_strut:Strut;
_touchLayer: engine.Rect;
_isTouchLayer;
......@@ -44,6 +45,13 @@ export default class GameView extends engine.Container {
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);
......@@ -67,23 +75,55 @@ export default class GameView extends engine.Container {
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 = this._road.getStartGold(0) ? props.goldScore : 0;
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();
......@@ -92,10 +132,33 @@ export default class GameView extends engine.Container {
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(){
console.log("复活---------");
// console.log("复活---------");
this._player.revive();
this.startAnm();
this._isTouchLayer = true;
this.closeStrut();
}
......@@ -166,7 +229,7 @@ export default class GameView extends engine.Container {
}
//鼠标事件
onMouseDown(){
if(this._isTouchLayer){
if(this._isTouchLayer&&!this.inani){
this._isMouseDown = true;
this._strut.onMouseDown(this._road.getFristPier(),this._road.getDistance(),this.goCallBcak.bind(this));
}
......@@ -181,7 +244,7 @@ export default class GameView extends engine.Container {
//撑杆回调
goCallBcak(isSuccess){
if(isSuccess){
console.log('成功了');
// console.log('成功了');
let movePos = this._road.getMovePos();
if(this._road.getStartGold(1,false)){
this.updateScore(props.singleScore + props.goldScore);
......@@ -192,9 +255,9 @@ export default class GameView extends engine.Container {
this._player.setViewport(movePos,this.complete.bind(this));
}else{
console.log('失败了');
// console.log('失败了');
this._player.setViewport(this._strut.getStrutHeight(),()=>{
console.log('掉下去了');
// console.log('掉下去了');
engine.globalEvent.dispatchEvent('bjxd-game-over',{score:this._sumScore});
},this._road.getFristPier())
}
......@@ -211,6 +274,17 @@ export default class GameView extends engine.Container {
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);
}
this.closeStrut();
}
//重置撑杆
......@@ -228,7 +302,7 @@ export default class GameView extends engine.Container {
// this.changeBg(2);
// }
// this.labScore.updateScore(this._sumScore);
console.log("新分数",this._sumScore);
// console.log("新分数",this._sumScore);
engine.globalEvent.dispatchEvent('bjxd-game-score',{score:this._sumScore});
}
getScore(){
......@@ -244,4 +318,10 @@ export default class GameView extends engine.Container {
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 {
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);
......@@ -24,6 +26,9 @@ export class GameWrapper extends engine.Container {
start(event: engine.Event) {
this._gameView.start(event.data.guide);
}
reset(){
this._gameView.reset();
}
revive(){
this._gameView.revive();
}
......@@ -31,4 +36,7 @@ export class GameWrapper extends engine.Container {
// console.log("切换图片显示");
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 {
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();
// 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;
......
......@@ -5,7 +5,7 @@ export class Player extends engine.Container{
private playerNode: svga.Svga;
pierWidth
playery:number = 845;
playery:number = 878;
initPlayer(pierWidth){
this.pierWidth = pierWidth;
this._container = new engine.Container();
......@@ -15,13 +15,15 @@ export class Player extends engine.Container{
this.playerNode = createSvga('walk');
this._container.addChild(this.playerNode);
this.playerNode.y = this.playery;
this.playerNode.x = pierWidth/2 - 80;
this.playerNode.x = pierWidth/2 - 50;
this.playerNode.play();
this._container.visible = false;
}
revive(){
this._container.x = 0;
this._container.y = 0;
this.playerNode.x = this.pierWidth/2 - 80;
this.playerNode.x = this.pierWidth/2 - 50;
this.playerNode.y = this.playery;
}
setViewport(pos,callBack,pierWidth?){
......
......@@ -53,14 +53,17 @@ export class Strut extends engine.Container{
paddingx = 20;
chax = 20;
}else if(GameView.bgIndex==1){
paddingx = 30;
chax = 60;
paddingx = 3;
chax = 39;
}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){
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;
}
if(this._callBack){
......@@ -68,8 +71,31 @@ export class Strut extends engine.Container{
}
}
frameStrut(){
if(this._strut.height < 1000){
this._strut.height += props.strutUpSpeed;
// let paddingx = 20;
// 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(){
......
......@@ -50,7 +50,7 @@
"strutUpSpeed": {
"alias": "撑杆上升速度(每帧上升增量,一秒60帧)",
"type": "number",
"default": 10
"default": 30
},
"strutWidth": {
"alias": "撑杆宽度",
......
......@@ -48,7 +48,7 @@ function launchWithCustomModule(customModule) {
setTimeout(()=>{
engine.globalEvent.dispatchEvent('pictures-initgame', {
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/6b70d7ec626f35f21347bf5bc3e61bedc44167be.jpg"
]
......@@ -56,12 +56,12 @@ function launchWithCustomModule(customModule) {
},1000);
setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', {
actidx:0,
rows:3,
cols:3,
gametime:30000
});
// engine.globalEvent.dispatchEvent('pictures-start', {
// actidx:0,
// rows:3,
// cols:3,
// gametime:30000
// });
// const d = engine.gameStage.sceneContainer.getChildAt(0);
// engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
......
This diff is collapsed.
This diff is collapsed.
......@@ -106,6 +106,24 @@
"data": {
"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 {
picarr;
gameUrls:Array<string> = [];
gameTimes:Array<number> = [];
onegamePics:Array<engine.Texture> = [];
movesteps:number = 0;
startime:number = 0;
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.initScene, this);
......@@ -49,6 +52,8 @@ export default class GameView extends engine.Container {
this.lineShape = new engine.Shape();
this.selectimg3 = new engine.Image(getTextureByName("框3"));
this.selectimg4 = new engine.Image(getTextureByName("框4"));
this.selectimg3.mouseEnabled = false;
this.selectimg4.mouseEnabled = false;
//底图
this.dicont = new engine.Container();
//线
......@@ -61,25 +66,132 @@ export default class GameView extends engine.Container {
this.addChild(this.blockcont);
this.linecont.addChild(this.lineShape);
console.log("拼图初始化完毕--------------");
engine.globalEvent.dispatchEvent("pictures-time-initcomp",{});
}
async initgame(){
console.log("initgame---------");
this.gameUrls = props.gameUrls;
this.gameTimes = props.gameTimes;
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);
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() {
this.dicont.removeChildren();
this.movesteps = 0;
this.startime = Date.now();
let actidx = props.actidx;
this.gametime = props.gametime;
this.showtime = props.gametime;
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 = props.rows;
this.cols = props.cols;
......@@ -92,7 +204,7 @@ export default class GameView extends engine.Container {
this.nselectimg = this.selectimg4;
}
this.passtime = 0;
this.selectImgArr = new Array();
this.sucposData = {};
......@@ -164,8 +276,8 @@ export default class GameView extends engine.Container {
}
this.lineShape.endStroke();
this.ticker = setInterval(this.update, 20);
this.ticker&&clearInterval(this.ticker);
this.ticker = setInterval(this.update, 10);
}else{
console.error("图片处理失败");
}
......@@ -201,9 +313,12 @@ export default class GameView extends engine.Container {
}
pause(){
this.ingame = false;
console.error("拼图暂停");
}
resume(){
this.lastframetime = Date.now();
this.ingame = true;
console.error("拼图继续");
}
......@@ -216,6 +331,9 @@ export default class GameView extends engine.Container {
if(this.ingame){
let passtime = (ntime - this.lastframetime)/1000;
this.passtime += passtime;
engine.globalEvent.dispatchEvent("pictures-time-passtime",{
passtime:this.passtime
});
let showtime1 = Math.round(this.gametime - this.passtime);
// console.log(passtime,this.passtime,this.gametime,this.showtime);
if(this.showtime!=showtime1){
......@@ -251,6 +369,10 @@ export default class GameView extends engine.Container {
this.selectImgArr.push(selectname);
}else if(this.selectImgArr.length==1){
if(selectname==this.selectImgArr[0]){
if(this.nselectimg){
this.blockcont.removeChild(this.nselectimg);
}
this.selectImgArr = new Array();
return;
}else{
this.selectImgArr.push(selectname);
......@@ -283,6 +405,8 @@ export default class GameView extends engine.Container {
this.selectImgArr = new Array();
this.movesteps += 1;
if(this.nselectimg){
this.blockcont.removeChild(this.nselectimg);
}
......@@ -317,9 +441,14 @@ export default class GameView extends engine.Container {
private gameover(reason:number) {
this.ingame = false;
this.ticker&&clearInterval(this.ticker);
let ntime = Date.now();
let gametime = ntime - this.startime;
engine.globalEvent.dispatchEvent('pictures-game-over', {
reason:reason,
time: this.passtime
time: this.passtime,
number:this.movesteps,
gametime:gametime
});
}
......
import { props } from "../props";
import { loadImageByUrl } from "./utils";
import qietu from "./qietu";
const urls = [];
const picMap = {};
const posMap = {};
......@@ -19,6 +20,29 @@ export default async(url:any,type1:number, rows:number, cols:number,parent:engin
let mwid = t.width;
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 picnames = [];
......
......@@ -19,7 +19,7 @@ export function createSvga(name, anchorName?) {
return inst;
}
export function loadImageByUrl(url){
export async function loadImageByUrl(url){
console.log('loadImageByUrl----------:',url);
return new Promise((resolve) => {
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