本文主要是介绍俄罗斯方块Laya源码(非商用未拆分无架构),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import { ui } from "./../ui/layaMaxUI";
// import Rank from "./Rank";
//重写点击拖拽事件
export default class MainGameScript extends Laya.Script{//#region 属性初始化private _scene:Laya.Scene3D;private _camera:Laya.Camera;protected lastMouseX: number;protected lastMouseY: number;static clickNum:number;//点击状态:-1:运行模式,1~4:创建按钮,0:归零模式private boxObjsPool:Array<Laya.MeshSprite3D>=new Array();// 存储物体的对象池private maxLine=11;//最大列度private deviant=5;//maxline/2 偏移值private maxRow=11;//最大行数private maxKind=12;//最大种类private currentGetKey=0;//当前获取到的指针private moveObjArray:Array<MoveBoxArray>=new Array(); // 存储移动的数组:移动完毕后进入属性private moveArrayprOperty:Array<number[]>=new Array();//存储移动数组的属性private minPosNum:number=0;//移动数组最左边的位置private maxPosNum:number=0;//移动数组最右边的位置// private eliminateArray:Array<MoveBoxArray>=new Array();//消除数组// private targetArray:Array<MoveBoxArray>=new Array();//目标数组private showObjArray:Array<MoveBoxArray>=new Array();//展示用的数组 private row:Array<number[]>=new Array();// 行列 private isMouseDown:boolean;//按钮是否被点击static isCreat:boolean=false;//是否创建static isMove:boolean=false;//是否移动private moveSpeed:number;//移速static isReset=false;//是否重置/**移动计时器更新时间*/private _time: number = 0;static land:Laya.MeshSprite3D;//地面private gradeNum:number=0;//分数private maxGradeNum:number=0;//最高分数private goldNum:number=0;//金币//#region 静态UI部分static uiMain;static img_next:Laya.Sprite;static img1:Laya.Sprite;static img2:Laya.Sprite;static img3:Laya.Sprite;static img4:Laya.Sprite; static storeBtu:Laya.Button;//打开商城按钮static cancelCreatBtu:Laya.Button;//取消点击按钮static uiReset;static resetNoThanks:Laya.Button;static resetGradeT:Laya.Text;static resetMaxGradeT:Laya.Text;static resetShare:Laya.Button;static uiHintAll;private uiHintTime:number=0;//提示显示的时间static hintText;static hintT:Laya.Text;static hintGet;static uiSignIn;private firstLoginTime:string;//首次登录时间private lastLoginTime:string;//上次登录时间private signNumber:number=0;//签到次数static clickGetSign:Laya.Button;//点击获取签到按钮static signSpecial;static signNode;private signGetSkin=4;static signedNode;static uiMessage;static mainGoldT:Laya.Text;static gradeT:Laya.Text;//分数static maxGradeT:Laya.Text;//最高分static levelT:Laya.Text;//关卡数// static mainstatic uiStore;static closeStoreBtu:Laya.Button;private _isOpenStore:boolean=false;static storeClickNum:number=1;//点击选中皮肤private actualSkinNum:number=1;//实际选中的皮肤private drawNumber:number=0;//抽奖次数private skinAllNumber:Array<number>=new Array<number>();//全部皮肤static storeClickStart:boolean=false;static storePageNum=-1;private storePage=1;static storeGoldT:Laya.Text;static storePageNode; static storePage1:Laya.Button;static storePage2:Laya.Button;static extractBtu:Laya.Button;//皮肤抽奖static extractT:Laya.Text;static storeShareBtu:Laya.Button;//商城分享private lastClickSkinNum:number=1;//上一选中ID static uiPassed;static passGoldT:Laya.Text;static passGradeT:Laya.Text;//分数static passMaxGradeT:Laya.Text;//最高分static passLevelT:Laya.Text;//关卡数static passStoreOpen:Laya.Button;//打开商店static passNextChapter:Laya.Button;//进入下一关//#endregionstatic m_sceneCfg={};//关卡表static chapter=0;//关卡private gameInning:number=0;//游戏局数(每次登陆游戏算起,失败也算)static m_difficultyCfg={};//难度表private hintArray:Array<Laya.MeshSprite3D[]>=new Array();//提示用的数组:初始化的时候布满所有的行列,并关闭,在需要显示的时候打开// private hintArrOperty:Array<Laya.MeshSprite3D>=new Array();//显示提示数组的属性组private hintArray2:Array<Laya.MeshSprite3D[]>=new Array();// private hintArrOperty2:Array<Laya.MeshSprite3D>=new Array();// private allShowArrayObj:Array<Laya.MeshSprite3D[]>=new Array();//所有正常显示的数组private isWillDie=true;//模拟的时候死亡private lastMovePos=0;//上一偏移位置private nextMovePos=0;//下一偏移位置private wx;//微信接口constructor(){super();this._scene = null; this._camera = null; this.isMouseDown=false;this.lastMouseX=0;this.lastMouseY=0; MainGameScript.clickNum=0; Laya.LocalStorage.clear();if(Laya.LocalStorage.getItem("firstLoginTime")!=null){console.log("再次登陆游戏43543");this.gradeNum= Number(Laya.LocalStorage.getItem("gradeNum"));this.maxGradeNum=Number(Laya.LocalStorage.getItem("maxGradeNum"));this.goldNum= Number( Laya.LocalStorage.getItem("goldNum") );this.firstLoginTime= Laya.LocalStorage.getItem("firstLoginTime");this.lastLoginTime= Laya.LocalStorage.getItem("lastLoginTime");this.signNumber= Number(Laya.LocalStorage.getItem("signNumber"));MainGameScript.chapter= Number(Laya.LocalStorage.getItem("chapter"));this.GetAllSkin();this.actualSkinNum= Number(Laya.LocalStorage.getItem("skinNum"));this.drawNumber= Number(Laya.LocalStorage.getItem("drawNumber"));}else{console.log("初次登陆游戏1111");// var str=Date.parse(new Date().toString());//初始化Laya.LocalStorage.setItem("gradeNum","0");Laya.LocalStorage.setItem("maxGradeNum","0");Laya.LocalStorage.setItem("goldNum","0"); Laya.LocalStorage.setItem("firstLoginTime",new Date().toString());//存储当前时间Laya.LocalStorage.setItem("lastLoginTime",new Date().toString());Laya.LocalStorage.setItem("signNumber","0");Laya.LocalStorage.setItem("chapter","0");this.SetAddSkin(1);Laya.LocalStorage.setItem("skinNum","1")}MainGameScript.extractT.text=""+(500+this.drawNumber*300);// if (Laya.Browser.onMiniGame) {// this.wx = Laya.Browser.window.wx;// }this.onStart();}onStart(){ this._scene = this.owner.parent as Laya.Scene3D;this._camera = this._scene.getChildByName("camera") as Laya.Camera;console.log("初始化asffasfrasfas");Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp);Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.mouseOut);Laya.stage.on(Laya.Event.DRAG_MOVE, this, this.mouseDrag);Laya.stage.on(Laya.Event.DRAG_END, this, this.mouseDragEnd);this.ChangSkin(this.actualSkinNum);ShowBoxArray.onLoad();this.StartBoxNature();this.onUIStart();// this.WXInterface();}onUIStart(){MainGameScript.resetNoThanks.on(Laya.Event.MOUSE_DOWN,this,this.OnResets);MainGameScript.storeBtu.on(Laya.Event.CLICK,this,this.OpenStore);MainGameScript.closeStoreBtu.on(Laya.Event.CLICK,this,this.CloseStore);MainGameScript.passStoreOpen.on(Laya.Event.CLICK,this,this.OpenStore);MainGameScript.passNextChapter.on(Laya.Event.CLICK,this,this.ClosePass);MainGameScript.storeShareBtu.on(Laya.Event.CLICK,this,this.OnShareAddGold);MainGameScript.extractBtu.on(Laya.Event.CLICK,this,this.StoreExtract);MainGameScript.clickGetSign.on(Laya.Event.CLICK,this,this.SignGet);MainGameScript.cancelCreatBtu.on(Laya.Event.MOUSE_MOVE,this,this.CancleSelect);MainGameScript.resetShare.on(Laya.Event.CLICK,this,this.OnShareReset);MainGameScript.gradeT.text=""+this.gradeNum;MainGameScript.resetGradeT.text=""+this.gradeNum;MainGameScript.passGradeT.text=""+this.gradeNum;MainGameScript.maxGradeT.text="最高分 "+this.maxGradeNum;MainGameScript.resetMaxGradeT.text="最高分 "+this.maxGradeNum;MainGameScript.passMaxGradeT.text="最高分 "+this.maxGradeNum;MainGameScript.levelT.text="关卡 "+MainGameScript.chapter;MainGameScript.passLevelT.text="关卡 "+MainGameScript.chapter;MainGameScript.mainGoldT.text=""+this.goldNum;MainGameScript.storeGoldT.text=""+this.goldNum;MainGameScript.passGoldT.text=""+this.goldNum;MainGameScript.uiHintAll._visible=false;MainGameScript.uiReset._visible=false;MainGameScript.uiSignIn._visible=false;MainGameScript.uiPassed._visible=false;MainGameScript.cancelCreatBtu.visible=false;console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");this.StartStore(1);}//#endregion//region 微信小程序部分WXInterface(){console.log("启动微信接口"); if(Laya.Browser.onMiniGame){this.wx=Laya.Browser.window.wx;this.wx.setUserCloudStorage({KVDataList: [{ key: "k", value: "v" }],success: () => {console.log("数据发送成功");},fail: () => {console.log("数据发送失败");}}); }else{console.log("启动微信接口失败"); } // if(Laya.Browser.onMiniGame){// //加载一个json和图集// Laya.loader.load(["json/reward.json","res/atlas/test.atlas"],Laya.Handler.create(null,function(){// //加载完成// //使用接口将图集透传到子域// Laya.MiniAdpter.sendAtlasToOpenDataContext("res/atlas/test.atlas"); // //使用接口将json投促函到子域// Laya.MiniAdpter.sendJsonDataToDataContext("json/reward.json");// }));// }console.log("结束调用微信");}private OnShareReset(e: Laya.Event): void {console.log("进入分享按钮");if (this.wx == null) {console.log("wx为空");return;}var canvas = this.wx.createCanvas();canvas.width = 640;canvas.height = 480;var context = canvas.getContext('2d');var bgm = this.wx.createImage();bgm.src = "jiangbei.png";bgm.onload = () => {context.drawImage(bgm, 0, 0, 640, 480);context.fillStyle = "rgba(0,0,0,1)";context.font = "bold 30px Arial";context.textAlign = "left";context.textBaseline = "middle";context.fillText("关卡", 200, 100);context.fillText( 999+ " 章节", 240, 190);this.wx.shareAppMessage({title: "小伙伴快来和我一起玩啊",imageUrl: canvas.toTempFilePathSync({destWidth: 640,destHeight: 480}),success: () => {console.log("分享成功");},fail: () => {console.log("分享失败");}})} }private OnShareAddGold(e: Laya.Event): void {this.StoreShare();console.log("进入分享按钮");if (this.wx == null) {console.log("wx为空");return;}var canvas = this.wx.createCanvas();canvas.width = 640;canvas.height = 480;var context = canvas.getContex
这篇关于俄罗斯方块Laya源码(非商用未拆分无架构)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!