1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116 |
- class Game extends egret.DisplayObjectContainer {
- public static Instance: Game = new Game();
- public levelConfig:any;
- public ballConfig:any;
- public balls_pool: Array<Ball>;
- public ballContainer: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
- public mapConfig:any;
- public mapPosition:any;
- public startIndex:number = 0;
- public startjian:boolean = false;
- //当前移动的第一个球的下标
- public index:number = 0;
- public canPlay:boolean = false;
- public playNumEnterFrame:number = 0;
- public levelIndex:number = 0;
- public targetX:number = 0;
- public targetY:number = 0;
- public isAttack:boolean = false;
- //是否通关
- public pass:boolean = false;
- public passFrame:number = 0;
- public passIndex:number = 1;
- //玩家操作的球
- public playerBall:Ball;
- public fireBalls:Ball[] = new Array();
- public nextPlayerBall:Ball;
- public cosValue:number;
- public sinValue:number;
- public boomMC:egret.MovieClip;
- //游戏是否结束
- public end:boolean = false;
- public timeIndex:number = 1;
- //每执行一次定时器球的移动速度
- public speed:number = 25;
- //回退速度
- public backSpeed:number = 25;
- //前进定时器
- public timer: egret.Timer = new egret.Timer(20);
- //插入动画定时器
- public insertTimer: egret.Timer = new egret.Timer(20);
- //插入动画的移动速度
- public insertSpeed:number = 10;
- public insertstart:number;
- public insertend:number;
- public insertCheckIndex:number;
- public insertNum:number = 0;
- //是否添加插入定时器监听
- private insertTimerInit:boolean = false;
- //回退定时器
- private backTimer: egret.Timer = new egret.Timer(20);
- //是否添加定时器监听事件
- private backTimerInit:boolean = false;
- //是否初始化
- public inited:boolean = false;
- public backIndex:number;
- public backstartIndex:number;
- public delNum:number = 0;
- public numji:number = -1;
- public canFire:boolean;
- //准线小点的个数
- public dotLength:number = 20;
- //是否有准线
- public haveDot:boolean = false;
- //玩家球的炮台
- public ballServe:egret.Bitmap;
- public gameBg:egret.Bitmap;
- public mapBg:egret.Bitmap;
- public lianjiEffect:egret.BitmapText;
- public dengji:egret.BitmapText;
- //道具
- public back:egret.Bitmap;
- public boom:egret.Bitmap;
- public propbg:egret.Bitmap;
- //结束警告
- public mapend:egret.Bitmap;
- public blast:egret.Bitmap;
- //头部背景
- public gamehead:egret.Bitmap;
- //经验条
- public experbg:egret.Bitmap;
- public exper:egret.Bitmap;
- //分数背景
- public fraction:egret.Bitmap;
- public score: egret.TextField;
- //等级
- public grade: egret.TextField;
- public gradeScore: egret.TextField;
- private power: egret.TextField;
- private percent: egret.TextField;
- private touchArea: egret.Bitmap;
- public dead: boolean = false;
- public dotContainer: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
- public throughContainer: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
- public rewardContainer: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
- public shakeTween: egret.Tween;
- //游戏定义
- public leftBullet = 0;
- private fireing: boolean = false;
- private constructor() {
- super();
- this.once(egret.Event.ADDED_TO_STAGE, (event: egret.Event) => {
- this.levelConfig = RES.getRes("level_json");
- this.ballConfig = RES.getRes("ball_json");
- this.balls_pool = new Array<Ball>();
- this.throughContainer.width = this.stage.width;
- this.throughContainer.height = this.stage.height;
- this.throughContainer.x = 0;
- this.throughContainer.y = 0;
- this.gamehead = new egret.Bitmap();
- this.gamehead.texture = RES.getRes("gamehead_jpg");
- this.gamehead.x = 0;
- this.gamehead.y = 0;
- this.gamehead.width = this.stage.width;
- this.gamehead.height = 177;
- this.addChild(this.gamehead);
- this.experbg = new egret.Bitmap();
- this.experbg.texture = RES.getRes("experiencebg_png");
- this.experbg.x = 0;
- this.experbg.y = 162;
- this.experbg.width = this.stage.width;
- this.experbg.height = 12;
- this.addChild(this.experbg);
- this.exper = new egret.Bitmap();
- this.exper.texture = RES.getRes("experience_png");
- this.exper.x = 0;
- this.exper.y = 162;
- this.exper.width = this.stage.width;
- this.exper.height = 12;
- this.exper.mask = new egret.Rectangle(0,0,0,0);
- this.addChild(this.exper);
- let course = new egret.DisplayObjectContainer();
- this.addChild(course);
- this.ballContainer.width = 600;
- this.ballContainer.height = 900;
- this.ballContainer.anchorOffsetX = 300;
- //this.ballContainer.anchorOffsetY = 450;
- this.ballContainer.x = this.stage.width / 2;
- this.ballContainer.y = 177;
- this.ballContainer.mask = new egret.Rectangle(0,0,600,900);
- this.dotContainer.width = 600;
- this.dotContainer.height = 900;
- this.dotContainer.anchorOffsetX = 300;
- //this.dotContainer.anchorOffsetY = 450;
- this.dotContainer.x = this.stage.width / 2;
- this.dotContainer.y = 177;
- this.addChild(this.ballContainer);
- this.addChild(this.dotContainer);
- let kongmingJson = RES.getRes("boom_json");
- let kongmingImg = RES.getRes("boom_png");
- let mcFactory = new egret.MovieClipDataFactory(kongmingJson,kongmingImg);
- this.boomMC = new egret.MovieClip(mcFactory.generateMovieClipData());
- this.boomMC.anchorOffsetX = this.boomMC.width /2 + 20;
- this.boomMC.anchorOffsetY = this.boomMC.height / 2 + 20;
- this.boomMC.visible = false;
- this.propbg = new egret.Bitmap();
- this.propbg.texture = RES.getRes("propbg_png");
- this.propbg.x = this.stage.width / 2 - 225;
- this.propbg.y = this.stage.height - 89;
- this.propbg.width = 450;
- this.propbg.height = 89;
- this.addChild(this.propbg);
- this.touchArea = new egret.Bitmap();
- this.touchArea.touchEnabled = true;
- this.touchArea.width = 600;
- this.touchArea.height = 900;
- this.touchArea.anchorOffsetX = 0;
- this.touchArea.anchorOffsetY = 0;
- this.touchArea.x = 0;
- this.touchArea.y = 0;
- this.ballContainer.addChild(this.touchArea);
- let offsetY = 0
- if (window.innerWidth == 375 && window.innerHeight == 812) {
- offsetY = 40;
- }
- this.fraction = new egret.Bitmap();
- this.fraction.texture = RES.getRes("fraction_png");
- this.fraction.x = this.stage.width / 2 - this.fraction.width / 2;
- this.fraction.y = 0;
- this.addChild(this.fraction);
- this.mapend = new egret.Bitmap();
- this.mapend.texture = RES.getRes("mapend_png");
- this.mapend.anchorOffsetX = this.mapend.width / 2;
- this.mapend.anchorOffsetY = this.mapend.height / 2;
- this.mapend.x = 300;
- this.mapend.y = 450;
- this.mapend.visible = false;
- this.blast = new egret.Bitmap();
- this.blast.texture = RES.getRes("blast_png");
- this.blast.anchorOffsetX = this.blast.width / 2;
- this.blast.anchorOffsetY = this.blast.height / 2;
- this.blast.x = 250;
- this.blast.y = 450;
- this.blast.visible = false;
- this.score = new egret.TextField();
- //this.score.font = RES.getRes('wwt_score_fnt');
- this.score.text = '0';
- this.score.textColor = 0x422904;
- this.score.size = 48;
- this.score.bold = true;
- this.score.anchorOffsetY = this.score.height / 2;
- //console.log(this.fraction.height);
- this.score.y = 99;
- this.score.anchorOffsetX = this.score.width / 2;
- this.score.x = this.stage.stageWidth / 2;
- this.addChild(this.score);
- this.grade = new egret.TextField();
- this.grade.text = '1';
- this.grade.textColor = 0x422904;
- this.grade.size = 30;
- this.grade.y = offsetY + 50;
- this.grade.x = 20;
- //this.addChild(this.grade);
- this.gradeScore = new egret.TextField();
- this.gradeScore.text = '0/0';
- this.gradeScore.textColor = 0x422904;
- this.gradeScore.size = 30;
- this.gradeScore.y = offsetY + 100;
- this.gradeScore.x = 20;
- //this.addChild(this.gradeScore);
- this.mapBg = new egret.Bitmap();
- this.mapBg.touchEnabled = true;
- this.mapBg.texture = RES.getRes("map_png");
- this.mapBg.width = 600;
- this.mapBg.height = 900;
- this.mapBg.anchorOffsetX = 300;
- this.mapBg.anchorOffsetY = 450;
- this.mapBg.x = 300;
- this.mapBg.y = 450;
- this.ballServe = new egret.Bitmap();
- this.ballServe.texture = RES.getRes("serve_png");
- this.ballServe.width = 141;
- this.ballServe.height = 190;
- this.ballServe.anchorOffsetX = 70.5;
- this.ballServe.anchorOffsetY = 95;
- this.ballServe.x = 300;
- this.ballServe.y = 700;
- this.boom = new egret.Bitmap();
- this.boom.texture = RES.getRes("boomprop_png");
- this.boom.width = 70;
- this.boom.height = 70;
- this.boom.anchorOffsetX = 35;
- this.boom.anchorOffsetY = 35;
- this.boom.x = this.stage.width / 2 - 85;
- this.boom.y = this.stage.height - 70;
- this.boom.touchEnabled = true;
- this.addChild(this.boom);
- this.boom.addEventListener(egret.TouchEvent.TOUCH_TAP,async()=>{
- let result: any = await Network.Instance.share(4);
- let shareConfig = DataBus.Instance.share_config['4'];
- let data = await platform.shareAppMessage(true, shareConfig.title, shareConfig.image, '');
- Network.Instance.shareSuccess();
- if(data.shareTickets){
- let rebackData= await platform.getShareInfo(data.shareTickets[0]);
- let result=await Network.Instance.checkGroupShareCount(rebackData.encryptedData,rebackData.iv);
- if(result==1){
- platform.showToast('领取道具成功',false);
- //群分享成功
- if(this.playerBall){
- if(this.playerBall.x == this.mapConfig.playerX && this.playerBall.y == this.mapConfig.playerY){
- this.playerBall.changeBoom();
- }else{
- this.nextPlayerBall.changeBoom();
- }
- }
- }else{
- platform.showToast('换个群试试~',false);
- }
- }else{
- platform.showToast('请分享到群',false);
- }
- },this);
- this.back = new egret.Bitmap();
- this.back.texture = RES.getRes("backprop_png");
- this.back.width = 70;
- this.back.height = 70;
- this.back.anchorOffsetX = 35;
- this.back.anchorOffsetY = 35;
- this.back.touchEnabled = true;
- this.back.x = this.stage.width / 2 + 65;
- this.back.y = this.stage.height - 70;
- this.addChild(this.back);
- this.back.addEventListener(egret.TouchEvent.TOUCH_TAP,async()=>{
- let result: any = await Network.Instance.share(4);
- let shareConfig = DataBus.Instance.share_config['4'];
- let data = await platform.shareAppMessage(true, shareConfig.title, shareConfig.image, '');
- Network.Instance.shareSuccess();
- if(data.shareTickets){
- let rebackData= await platform.getShareInfo(data.shareTickets[0]);
- let result=await Network.Instance.checkGroupShareCount(rebackData.encryptedData,rebackData.iv);
- if(result==1){
- //群分享成功
- platform.showToast('领取道具成功',false);
- this.timer.stop();
- this.backIndex = this.balls_pool.length - 2;
- this.backstartIndex = this.index;
- this.delNum = 10 * (~~(this.playerBall.width / this.backSpeed));
- this.startIndex -= 10;
- this.numji = 0;
- if(!this.backTimerInit){
- this.backTimer.addEventListener(egret.TimerEvent.TIMER, () => {
- this.backTween();
- }, this);
- this.backTimerInit = true;
- }
- this.backTimer.start();
- }else{
- platform.showToast('换个群试试~',false);
- }
- }else{
- platform.showToast('请分享到群',false);
- }
- },this);
- this.lianjiEffect = new egret.BitmapText();
- this.lianjiEffect.text = '';
- this.lianjiEffect.x = 100;
- this.lianjiEffect.y = 100;
- this.lianjiEffect.font = RES.getRes('lianji_fnt');
- this.dengji = new egret.BitmapText();
- this.dengji.text = '1级';
- this.dengji.x = this.stage.width / 2 - 15;
- this.dengji.y = 152;
- this.dengji.font = RES.getRes('dengji_fnt');
- this.addChild(this.dengji);
-
- this.touchArea.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (e: egret.TouchEvent) => {
- //if (this.canPlay) {
- this.targetX = e.localX;
- this.targetY = e.localY;
- this.ballServe.rotation = this.getAngle(this.nextPlayerBall.x,this.nextPlayerBall.y,this.targetX,this.targetY);
- this.cos(this.nextPlayerBall.x,this.nextPlayerBall.y,this.targetX,this.targetY);
- this.haveDot = true;
- //}
- }, this);
- this.touchArea.addEventListener(egret.TouchEvent.TOUCH_MOVE, (e: egret.TouchEvent) => {
- //if (this.canPlay) {
- this.targetX = e.localX;
- this.targetY = e.localY;
- this.ballServe.rotation = this.getAngle(this.nextPlayerBall.x,this.nextPlayerBall.y,this.targetX,this.targetY);
- this.cos(this.nextPlayerBall.x,this.nextPlayerBall.y,this.targetX,this.targetY);
- //}
- }, this);
- this.touchArea.addEventListener(egret.TouchEvent.TOUCH_END, (e: egret.TouchEvent) => {
- //if(this.canPlay){
- this.boomMC.x = 300;
- this.boomMC.y = 800;
- this.haveDot = false;
- this.targetX = e.localX;
- this.targetY = e.localY;
- if(this.canFire && this.inited){
- this.playNumEnterFrame = 0;
- this.canFire = false;
- this.playerBall = this.nextPlayerBall;
- this.cos(this.playerBall.x,this.playerBall.y,this.targetX,this.targetY);
- this.createPlayerBall();
- this.playerBall.sinValue = this.sinValue;
- this.playerBall.cosValue = this.cosValue;
- this.fireBalls.push(this.playerBall);
- this.isAttack = true;
- }
- //}
- }, this);
- this.timer.addEventListener(egret.TimerEvent.TIMER, this.moveStage, this);
- this.insertTimer.addEventListener(egret.TimerEvent.TIMER, this.insertTween, this);
- this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
- /*let blackBg = new egret.Bitmap(RES.getRes('bg_black1_png'));
- blackBg.x = 0;
- blackBg.y = 0;
- blackBg.width = this.stage.stageWidth;
- blackBg.height = this.stage.stageHeight;
- course.addChild(blackBg);
- let hand = new egret.Bitmap(RES.getRes('hand1_png'));
- hand.x = this.stage.stageWidth / 2 - 200 + 34;
- hand.y = this.stage.stageHeight / 2 - 80;
- hand.width = 80;
- hand.height = 130;
- course.addChild(hand);
- var handBg = new egret.Bitmap(RES.getRes('hand_bg_png'));
- handBg.x = this.stage.stageWidth / 2 - 200 + 34;
- handBg.y = this.stage.stageHeight / 2 - 82;
- handBg.width = 334;
- handBg.height = 32;
- course.addChild(handBg);
- course.addChild(Player.Instance);
- var textCouse = new egret.BitmapText();
- textCouse.text = '边打边躲才能取得高分哦!~';
- textCouse.font = RES.getRes('wwt_font_6_fnt');
- textCouse.x = (this.stage.stageWidth - textCouse.width) / 2;
- textCouse.y = this.stage.stageHeight / 2 - 200 + 10;
- course.addChild(textCouse);
- var textCouse1 = new egret.BitmapText();
- textCouse1.text = '滑动屏幕来射击';
- textCouse1.font = RES.getRes('wwt_font_7_fnt');
- textCouse1.x = (this.stage.stageWidth - textCouse1.width) / 2;
- textCouse1.y = this.stage.stageHeight / 2 - 140 + 6;
- course.addChild(textCouse1);
- egret.Tween.get(hand, {
- loop: true, onChange: () => {
- Player.Instance.setX(hand.x);
- Player.Instance.update();
- }
- }).to({ x: handBg.x + handBg.width - hand.width }, 1000).to({ x: handBg.x }, 1000);
- blackBg.touchEnabled = true;
- blackBg.addEventListener(egret.TouchEvent.TOUCH_TAP, (event: egret.TouchEvent) => {
- event.stopImmediatePropagation();
- egret.Tween.removeTweens(hand);
- this.removeChild(course);
- let offsetY = 0
- if (window.innerWidth == 375 && window.innerHeight == 812) {
- offsetY = 40;
- }
- let touchArea = new egret.Bitmap();
- touchArea.touchEnabled = true;
- touchArea.width = this.stage.width;
- touchArea.height = this.stage.height;
- this.addChild(touchArea);
- this.score = new egret.BitmapText();
- this.score.font = RES.getRes('wwt_score_fnt');
- this.score.text = '0';
- this.score.anchorOffsetY = this.score.height / 2;
- this.score.y = 116 + this.score.height / 2
- this.addChild(this.score);
- this.smallBg = new egret.Bitmap(RES.getRes('boll_home_smallbg_png'));
- this.smallBg.x = 28;
- this.smallBg.y = 49 + offsetY;
- this.smallBg.width = 144;
- this.smallBg.height = 34;
- this.addChild(this.smallBg);
- this.powerBg = new egret.Bitmap(RES.getRes('boll_home_energy_png'));
- this.powerBg.x = 28;
- this.powerBg.y = 44 + offsetY;
- this.powerBg.width = 44;
- this.powerBg.height = 44;
- this.addChild(this.powerBg);
- this.powerEffect = new egret.Bitmap(RES.getRes('circular_yellow_png'));
- this.powerEffect.x = 50;
- this.powerEffect.y = 66 + offsetY;
- this.powerEffect.anchorOffsetX = 22;
- this.powerEffect.anchorOffsetY = 22;
- this.powerEffect.width = 44;
- this.powerEffect.height = 44;
- // this.powerEffect.visible = false;
- this.addChild(this.powerEffect);
- this.smallBg1 = new egret.Bitmap(RES.getRes('boll_home_smallbg_png'));
- this.smallBg1.x = 190;
- this.smallBg1.y = 49 + offsetY;
- this.smallBg1.width = 144;
- this.smallBg1.height = 34;
- this.addChild(this.smallBg1);
- this.percentBg = new egret.Bitmap(RES.getRes('boll_home_fair_png'));
- this.percentBg.x = 190;
- this.percentBg.y = 44 + offsetY;
- this.percentBg.width = 44;
- this.percentBg.height = 44;
- this.addChild(this.percentBg);
- this.percentEffect = new egret.Bitmap(RES.getRes('circular_red_png'));
- this.percentEffect.x = 212;
- this.percentEffect.y = 66 + offsetY;
- this.percentEffect.anchorOffsetX = 22;
- this.percentEffect.anchorOffsetY = 22;
- this.percentEffect.width = 44;
- this.percentEffect.height = 44;
- // this.percentEffect.visible = false;
- this.addChild(this.percentEffect);
- this.power = new egret.TextField();
- this.power.size = 24;
- this.power.x = 80;
- this.power.y = 56 + offsetY;
- this.power.textColor = 0x191F48;
- this.power.fontFamily = "Arial";
- this.addChild(this.power);
- this.percent = new egret.TextField();
- this.percent.size = 24;
- this.percent.x = 242;
- this.percent.y = 56 + offsetY;
- this.percent.textColor = 0x191F48;
- this.percent.fontFamily = "Arial";
- this.addChild(this.percent);
- this.addChild(Player.Instance);
- this.addChild(this.rewardContainer);
- this.addChild(this.enemyContainer);
- this.addChild(this.bulletContainer);
- this.addChild(this.enemyContainer);
- touchArea.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (e: egret.TouchEvent) => {
- if (!this.dead) {
- this.fireing = true;
- Player.Instance.setX(e.stageX);
- Player.Instance.setFire(this.fireing);
- }
- }, this);
- touchArea.addEventListener(egret.TouchEvent.TOUCH_MOVE, (e: egret.TouchEvent) => {
- if (!this.dead) {
- this.fireing = true;
- Player.Instance.setFire(this.fireing);
- Player.Instance.setX(e.stageX);
- }
- }, this);
- touchArea.addEventListener(egret.TouchEvent.TOUCH_END, () => {
- this.fireing = false;
- Player.Instance.setFire(this.fireing);
- }, this);
- this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
- DataBus.Instance.course += 1;
- }, this);*/
- }, this);
- }
- public getAngle(px,py,mx,my){//获得人物中心和鼠标坐标连线,与y轴正半轴之间的夹角,设置炮台方向
- var x = Math.abs(px-mx);
- var y = Math.abs(py-my);
- var z = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
- var cos = y/z;
- var radina = Math.acos(cos);//用反三角函数求弧度
- var angle = Math.floor(180/(Math.PI/radina));//将弧度转换成角度
- if(mx>px&&my>py){//鼠标在第四象限
- angle = 180 - angle;
- }
- if(mx==px&&my>py){//鼠标在y轴负方向上
- angle = 180;
- }
- if(mx>px&&my==py){//鼠标在x轴正方向上
- angle = 90;
- }
- if(mx<px&&my>py){//鼠标在第三象限
- angle = 180+angle;
- }
- if(mx<px&&my==py){//鼠标在x轴负方向
- angle = 270;
- }
- if(mx<px&&my<py){//鼠标在第二象限
- angle = 360 - angle;
- }
- return angle;
- }
- public restart(reborn:number = 0,level:number = 1) {
- //每次随机一个背景
- BackGround.Instance.resetBg();
- this.ballContainer.removeChildren();
- this.balls_pool.length = 0;
- DataBus.Instance.reset(reborn);
- //this.grade.text ='等级' + DataBus.Instance.grade + '';
- this.dengji.text = DataBus.Instance.grade + '级';
- this.mapConfig = RES.getRes(this.levelConfig[this.levelIndex].map);
- this.mapBg.texture = RES.getRes(this.mapConfig.bgUrl);
- this.ballContainer.addChild(this.mapBg);
- this.ballContainer.addChild(this.mapend);
- this.ballContainer.addChild(this.blast);
- this.ballContainer.addChild(this.ballServe);
- this.ballContainer.addChild(this.touchArea);
- this.ballContainer.addChild(this.boomMC);
- this.ballContainer.addChild(this.lianjiEffect);
- this.fireBalls.length = 0;
- this.ballServe.rotation = 0;
- this.ballServe.x = this.mapConfig.playerX;
- this.ballServe.y = this.mapConfig.playerY;
- this.haveDot = false;
- for(let i = 0;i < this.levelConfig[this.levelIndex].startLength; i++){
- if(i == 0){
- this.createBall(0);
- }else if(i == this.levelConfig[this.levelIndex].startLength - 1){
- this.createBall(0);
- }
- else
- this.createBall(1);
- }
- this.playerBall = null;
- this.createPlayerBall();
- this.dotContainer.removeChildren();
- //初始化准线
- for(let i = 0;i < this.dotLength; i++){
- let dot = new Dot();
- dot.x = this.playerBall.x;
- dot.y = this.playerBall.y;
- dot.visible = false;
- this.dotContainer.addChild(dot);
- }
- this.startTween();
- this.dead = false;
- Main.Instance.addChild(this);
- this.updateScore(0);
- }
- //刷新游戏道具
- public freshProp(){
- this.back.x = this.mapConfig.backX;
- this.back.y = this.mapConfig.backY;
- this.boom.x = this.mapConfig.boomX;
- this.boom.y = this.mapConfig.boomY;
- this.ballContainer.addChild(this.back);
- this.ballContainer.addChild(this.boom);
- }
- //开始时创建球
- public createBall(id:number = 1){
- if(this.end){
- return;
- }
- let ball:Ball = new Ball();
- //ball.type = id;
- //ball.texture = RES.getRes(Game.Instance.ballConfig[id].url);
- if(this.balls_pool.length == 0){
- ball.createType(this.levelConfig[this.levelIndex].typeNum[DataBus.Instance.nanduIndex],-1);
- }else{
- ball.createType(this.levelConfig[this.levelIndex].typeNum[DataBus.Instance.nanduIndex],this.balls_pool[this.balls_pool.length - 1].type);
- }
- ball.x = this.mapConfig.startX;
- ball.y = this.mapConfig.startY;
- ball.angle = this.mapConfig.startAngle;
- this.balls_pool.push(ball);
- this.ballContainer.addChild(ball);
- }
- //创建玩家要发射的球
- public createPlayerBall(){
- this.nextPlayerBall = new Ball();
- this.nextPlayerBall.createType(this.levelConfig[this.levelIndex].typeNum[DataBus.Instance.nanduIndex],-1);
- this.nextPlayerBall.x = this.mapConfig.playerX;
- this.nextPlayerBall.y = this.mapConfig.playerY;
- this.nextPlayerBall.scaleX = 0;
- this.nextPlayerBall.scaleY = 0;
- this.ballContainer.addChild(this.nextPlayerBall);
- egret.Tween.get(this.nextPlayerBall).to({scaleX:1,scaleY:1},100).call(()=>{
- this.canFire = true;
- });
- if(this.playerBall == null){
- this.playerBall = this.nextPlayerBall;
- }
- }
- //开局动画
- public startTween(){
- this.timer.reset();
- this.timer.start();
- }
- public backStartIndex(index:number){
- let startindex:number = index;
- for(let i = startindex; i > 0 ; i--){
- //如果后面运动的球的距离与前面静止的球的距离小于球的宽度,则前面的球也要运动
- if(this.checkDifMax(this.balls_pool[i],this.balls_pool[i-1])){
- startindex = i - 1;
- continue;
- }
- break;
- }
- console.log("倒退的startindex:" + startindex);
- return startindex;
- }
- //倒退动画
- public backTween(){
- console.log("进入backtween");
- let balls_pool:Array<Ball> = this.balls_pool;
- //如果倒退的不是最后一段,也就是有间隔的地方,进行如下判定
- if(this.backIndex!= this.balls_pool.length-2 && this.checkDif(balls_pool[this.backIndex],balls_pool[this.backIndex+1])){
- this.backTimer.stop();
- GameUtil.Sound.playEffect("ball_wav");
- //如果不能消除
- if(!this.checkCanMove(this.backIndex)){
- for(let i = this.backIndex;i < this.balls_pool.length - 2; i++){
- if(this.checkDif(balls_pool[i],balls_pool[i+1])){
- this.backIndex = i + 1;
- }else{
- break;
- }
- }
- this.backTimer.start();
- DataBus.Instance.scorePower = 0;
- this.numji = 0;
- if(!this.startjian && this.backIndex == this.balls_pool.length-2){
- this.startIndex -= ~~(this.delNum / ~~(this.playerBall.width / this.backSpeed));
- this.startjian = true;
- }
- }
- //this.backSpeed = 5;
- console.log("碰到了");
- return;
- }
- if(this.numji >= 0 && this.numji <= ~~(this.playerBall.width / this.backSpeed)){
- this.numji++;
- this.delNum--;
- console.log("delNum:" + this.delNum);
- }
- //如果回退一个单位球
- if(this.numji == ~~(this.playerBall.width / this.backSpeed)){
- this.numji = 0;
- //this.startIndex--;
- }
- //倒退结束处理
- if(this.delNum == -1){
- console.log("timeIndex:" + this.timeIndex);
- this.startjian = false;
- this.backTimer.stop();
- this.timer.start();
- this.numji = -1;
- this.canPlay = true;
- if(DataBus.Instance.scorePower > 1){
- DataBus.Instance.lianjiBigTwoNum++;
- }
- DataBus.Instance.scorePower = 0;
- this.checkMin(0,this.startIndex - 1);
- return;
- }
- let endindex = this.backIndex + 1;
- for(let i = this.backstartIndex ;i < endindex ; i++){
- let ball:Ball = balls_pool[i];
- let crux:any;
- //如果在直线状态
- if(!ball.inCrux){
- //如果是起点那一段直线
- if(ball.cruxIndex == 0){
- let dif = this.diffPoint(ball.x,ball.y,this.mapConfig.startX,this.mapConfig.startY);
- ball.x += (this.backSpeed / dif) * (this.mapConfig.startX - ball.x);
- ball.y += (this.backSpeed / dif) * (this.mapConfig.startY - ball.y);
- //如果回退到开始处了
- if(Math.abs(this.mapConfig.crux[0].startpoint.x - ball.x)> Math.abs(this.mapConfig.crux[0].startpoint.x - this.mapConfig.startX)||Math.abs(this.mapConfig.crux[0].startpoint.y - ball.y)> Math.abs(this.mapConfig.crux[0].startpoint.y - this.mapConfig.startY)){
- //this.startIndex--;
- ball.x = this.mapConfig.startX;
- ball.y = this.mapConfig.startY;
- }else{
- }
- }else{
- crux = this.mapConfig.crux[ball.cruxIndex - 1];
- let dif = this.diffPoint(ball.x,ball.y,crux.endpoint.x,crux.endpoint.y);
- ball.x += (this.backSpeed / dif) * (crux.endpoint.x - ball.x);
- ball.y += (this.backSpeed / dif) * (crux.endpoint.y - ball.y);
- //如果是终点那一段直线
- if(ball.cruxIndex == this.mapConfig.crux.length){
- if(this.diffPoint(ball.x,ball.y,this.mapConfig.endX,this.mapConfig.endY) >= this.diffPoint(crux.endpoint.x,crux.endpoint.y,this.mapConfig.endX,this.mapConfig.endY)){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.inCrux = true;
- ball.cruxIndex--;
- ball.startAngle = ~~ball.angle - crux.angle;
- }
- }
- else{
- //如果移动到指定地点,则计算误差
- let difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.crux[ball.cruxIndex].startpoint.x,this.mapConfig.crux[ball.cruxIndex].startpoint.y);
- let difCon = this.diffPoint(crux.endpoint.x,crux.endpoint.y,this.mapConfig.crux[ball.cruxIndex].startpoint.x,this.mapConfig.crux[ball.cruxIndex].startpoint.y);
- if(difBall >= difCon){
- ball.difLine = difBall - difCon;
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.inCrux = true;
- ball.startAngle = ~~ball.angle - crux.angle;
- ball.cruxIndex--;
- crux = this.mapConfig.crux[ball.cruxIndex];
- //圆心的坐标
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- //要移动的弧长,根据弧长和速度计算移动时间
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.startAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / this.backSpeed;
- let difAngle = (ball.startAngle - ball.angle) / time;
- let wuAngle = ball.difLine / this.backSpeed * difAngle;
- ball.difLine = 0;
- ball.angle += wuAngle;
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }
- }
- }else{
- //如果在拐歪状态
- crux = this.mapConfig.crux[ball.cruxIndex];
- //圆心的坐标
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- //要移动的弧长,根据弧长和速度计算移动时间
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.startAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / this.backSpeed;
- let difAngle = (ball.startAngle - ball.angle) / time;
- ball.difLine = 0;
- //如果刚好到关键点的开始处就后退,处理这个误差
- if(ball.startAngle == ball.angle){
- ball.difLine = this.backSpeed;
- }else{
- ball.angle += difAngle;
- }
- if(crux.angle < 0){
- //旋转结束
- if((ball.angle - crux.angle) >= (ball.startAngle - crux.angle)){
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.startAngle - ball.angle)/360) .toFixed(2)) || ball.difLine;
- ball.inCrux = false;
- ball.angle = ball.startAngle;
- ball.targetAngle = ball.angle;
- if(ball.angle == 180){
- ball.x = crux.startpoint.x + ball.difLine;
- ball.y = crux.startpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.startpoint.x - ball.difLine;
- ball.y = crux.startpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y - ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y + ball.difLine;
- }else{
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y;
- }
- continue;
- }
- }else{
- //旋转结束
- if((ball.angle - crux.angle) <= (ball.startAngle - crux.angle)){
- ball.inCrux = false;
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.startAngle - ball.angle)/360) .toFixed(2));
- ball.angle = ball.startAngle;
- ball.targetAngle = ball.angle;
- if(ball.angle == 180){
- ball.x = crux.startpoint.x + ball.difLine;
- ball.y = crux.startpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.startpoint.x - ball.difLine;
- ball.y = crux.startpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y - ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y + ball.difLine;
- }else{
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y;
- }
- continue;
- }
- }
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }
- }
- //校验小球之间的距离过大
- public check(){
- let balls_pool:Array<Ball> = this.balls_pool;
- if(this.index > this.startIndex){
- this.index = this.startIndex;
- console.log("thisindex:" + this.index);
- }
- //如果两个小球之间的间距过大,则前面的球先停下,由于速度过快,玩家并不会有察觉
- for(let i = this.startIndex - 1; i > this.index; i--){
- let dif = this.diffPoint(balls_pool[i].x,balls_pool[i].y,balls_pool[i-1].x,balls_pool[i-1].y);
- if(dif > this.playerBall.width + 3){
- console.log("距离过大:" + i);
- this.index = i;
- break;
- }
- }
- }
- //校验两个小球之间的间距过小
- public checkMin(index:number,endindex:number){
- let balls_pool:Array<Ball> = this.balls_pool;
- //如果两个小球之间的间距小于一个球的宽度,说明两个球重合了,进行处理
- for(let i = endindex; i > index; i--){
- let dif = this.diffPoint(balls_pool[i].x,balls_pool[i].y,balls_pool[i-1].x,balls_pool[i-1].y);
- if( dif < this.playerBall.width - 5){
- console.log("距离过小" + i);
- for(let j = 0; j < (this.playerBall.width - dif) / this.speed;j++){
- this.moveTween(index,i);
- }
- }
- }
- }
- //移动动画,start为前面运动的球的下标,index为后面的球的下标
- public moveTween(start:number,index:number,inPause?:boolean){
- if(this.end){
- return;
- }
- let speed = this.speed;
- let balls_pool:Array<Ball> = this.balls_pool;
- if(!inPause){
- for(let i = start; i > 0 ; i--){
- //如果后面运动的球的距离与前面静止的球的距离小于球的宽度,则前面的球也要运动
- //console.log("start:" + start + " i:" + i);
- if(this.checkDif(balls_pool[i],balls_pool[i-1])){
- this.index = i-1;
- start = i - 1;
- continue;
- }
- break;
- }
- }
- for(let i = start ;i < index ; i++){
- let ball:Ball = balls_pool[i];
- let crux:any;
- //获取配置文件的拐点坐标
- if(ball.cruxIndex < this.mapConfig.crux.length){
- crux = this.mapConfig.crux[ball.cruxIndex];
- }else{
- //如果已经走过所有节点,则直接向终点移动
- let dif = this.diffPoint(ball.x,ball.y,this.mapConfig.endX,this.mapConfig.endY);
- ball.x += (speed / dif) * (this.mapConfig.endX - ball.x);
- ball.y += (speed / dif) * (this.mapConfig.endY - ball.y);
- let difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- let difCon = this.diffPoint(this.mapConfig.endX,this.mapConfig.endY,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- if(difBall >= difCon){
- this.end = true;
- this.canPlay = false;
- ball.x = this.mapConfig.endX;
- ball.y = this.mapConfig.endY;
- }
- continue;
- }
- //如果在直线状态
- if(!ball.inCrux ){
- let dif = this.diffPoint(ball.x,ball.y,crux.startpoint.x,crux.startpoint.y);
- ball.x += (speed / dif) * (crux.startpoint.x - ball.x);
- ball.y += (speed / dif) * (crux.startpoint.y - ball.y);
- let difBall;
- let difCon;
- //如果是刚开始那一段直线
- if(ball.cruxIndex == 0){
- difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.startX,this.mapConfig.startY);
- difCon = this.diffPoint(crux.startpoint.x,crux.startpoint.y,this.mapConfig.startX,this.mapConfig.startY);
- }
- else{
- //如果移动到指定地点,则将坐标锁定在指定地点
- difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- difCon = this.diffPoint(crux.startpoint.x,crux.startpoint.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- }
- if(difBall >= difCon){
- ball.difLine = difBall - difCon;
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y;
- ball.inCrux = true;
- ball.startAngle = ball.angle;
- ball.targetAngle = ~~ball.angle + crux.angle;
- //圆心的坐标
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- //要移动的弧长,根据弧长和速度计算移动时间
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / speed;
- let difAngle = (ball.targetAngle - ball.angle) / time;
- let wuAngle = ball.difLine / speed * difAngle;
- ball.difLine = 0;
- ball.angle += wuAngle;
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }else{
- //如果在拐歪状态
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- ball.difLine = 0;
- //如果刚好到关键点的开始处就后退,处理这个误差
- if(ball.targetAngle == ball.angle){
- ball.difLine = speed;
- }
- //要移动的弧长,根据弧长和速度计算移动时间
- if(ball.targetAngle != ball.angle){
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / speed;
- let difAngle = (ball.targetAngle - ball.angle) / time;
- ball.angle += difAngle;
- }
- if(crux.angle < 0){
- //旋转结束
- if((ball.angle - crux.angle) <= (ball.targetAngle - crux.angle)){
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2)) || ball.difLine;
- ball.inCrux = false;
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.angle = ball.targetAngle;
- ball.cruxIndex++;
- if(ball.angle == 180){
- ball.x = crux.endpoint.x - ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.endpoint.x + ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y + ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y - ball.difLine;
- }else{
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- }
- continue;
- }
- }else{
- //旋转结束
- if((ball.angle - crux.angle) >= (ball.targetAngle - crux.angle)){
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2)) || ball.difLine;
- ball.inCrux = false;
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.angle = ball.targetAngle;
- ball.cruxIndex++;
- if(ball.angle == 180){
- ball.x = crux.endpoint.x - ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.endpoint.x + ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y + ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y - ball.difLine;
- }else{
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- }
- continue;
- }
- }
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }
- if(this.end){
- this.gameOver();
- this.timer.stop();
- }
- }
- public moveStage(){
- if(this.end){
- //处理游戏结束效果
- //this.timer.stop();
- }
- this.timeIndex++;
- if(this.timer.delay == 20 && this.startIndex == this.balls_pool.length - 1){
- this.createBall();
- }
- //每执行一个球的距离,开始坐标+1
- if(this.timeIndex % (~~(this.playerBall.width / this.speed))==0 && !this.end){
- this.timeIndex = 0;
- this.startIndex ++;
- //如果还未初始化并且长度到达最后,则放慢移动速度,初始化动画播放完成
- //console.log("this.startIndex:" + this.startIndex);
- if(!this.inited && this.startIndex == this.balls_pool.length - 1){
- this.timer.delay = 20;
- this.canPlay = true;
- this.inited = true;
- this.speed = this.levelConfig[this.levelIndex].speed[DataBus.Instance.nanduIndex];
- this.timer.stop();
- this.timer.reset();
- this.timer.start();
- this.checkMin(this.index,this.balls_pool.length -2);
- }
- }
- //console.log("index:" + this.index + " startIndex:" + this.startIndex);
- if(this.startIndex < 0 ){
- this.startIndex = 0;
- }
- this.check();
- //this.checkMin();
- //最后球全部弹进去之后,进行一次矫正
- /*if(this.startIndex < this.index){
- this.startIndex++;
- }*/
- this.moveTween(this.index,this.startIndex);
-
- }
- public inserttween(start:number,index:number,inPause?:boolean){
- if(this.end){
- return;
- }
- let speed = this.insertSpeed;
- let balls_pool:Array<Ball> = this.balls_pool;
- if(!inPause){
- for(let i = start; i > 0 ; i--){
- //如果后面运动的球的距离与前面静止的球的距离小于球的宽度,则前面的球也要运动
- if(this.checkDif(balls_pool[i],balls_pool[i-1])){
- this.index = i-1;
- start = i - 1;
- continue;
- }
- break;
- }
- }
- for(let i = start ;i < index ; i++){
- let ball:Ball = balls_pool[i];
- let crux:any;
- //获取配置文件的拐点坐标
- if(ball.cruxIndex < this.mapConfig.crux.length){
- crux = this.mapConfig.crux[ball.cruxIndex];
- }else{
- //如果已经走过所有节点,则直接向终点移动
- let dif = this.diffPoint(ball.x,ball.y,this.mapConfig.endX,this.mapConfig.endY);
- ball.x += (speed / dif) * (this.mapConfig.endX - ball.x);
- ball.y += (speed / dif) * (this.mapConfig.endY - ball.y);
- let difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- let difCon = this.diffPoint(this.mapConfig.endX,this.mapConfig.endY,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- if(difBall >= difCon){
- this.end = true;
- this.canPlay = false;
- ball.x = this.mapConfig.endX;
- ball.y = this.mapConfig.endY;
- }
- continue;
- }
- //如果在直线状态
- if(!ball.inCrux ){
- let dif = this.diffPoint(ball.x,ball.y,crux.startpoint.x,crux.startpoint.y);
- ball.x += (speed / dif) * (crux.startpoint.x - ball.x);
- ball.y += (speed / dif) * (crux.startpoint.y - ball.y);
- let difBall;
- let difCon;
- //如果是刚开始那一段直线
- if(ball.cruxIndex == 0){
- difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.startX,this.mapConfig.startY);
- difCon = this.diffPoint(crux.startpoint.x,crux.startpoint.y,this.mapConfig.startX,this.mapConfig.startY);
- }
- else{
- //如果移动到指定地点,则将坐标锁定在指定地点
- difBall = this.diffPoint(ball.x,ball.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- difCon = this.diffPoint(crux.startpoint.x,crux.startpoint.y,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.x,this.mapConfig.crux[ball.cruxIndex - 1].endpoint.y);
- }
- if(difBall >= difCon){
- ball.difLine = difBall - difCon;
- ball.x = crux.startpoint.x;
- ball.y = crux.startpoint.y;
- ball.inCrux = true;
- ball.startAngle = ball.angle;
- ball.targetAngle = ~~ball.angle + crux.angle;
- //圆心的坐标
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- //要移动的弧长,根据弧长和速度计算移动时间
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / speed;
- let difAngle = (ball.targetAngle - ball.angle) / time;
- let wuAngle = ball.difLine / speed * difAngle;
- ball.difLine = 0;
- ball.angle += wuAngle;
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }else{
- //如果在拐歪状态
- let circleX = crux.circle.x;
- let circleY = crux.circle.y;
- //半径
- let radius:number = this.diffPoint(crux.startpoint.x,crux.startpoint.y,circleX,circleY);
- ball.difLine = 0;
- //如果刚好到关键点的开始处就后退,处理这个误差
- if(ball.targetAngle == ball.angle){
- ball.difLine = speed;
- }
- //要移动的弧长,根据弧长和速度计算移动时间
- if(ball.targetAngle != ball.angle){
- let perimeter:number = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2));
- let time = perimeter / speed;
- let difAngle = (ball.targetAngle - ball.angle) / time;
- ball.angle += difAngle;
- }
- if(crux.angle < 0){
- //旋转结束
- if((ball.angle - crux.angle) <= (ball.targetAngle - crux.angle)){
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2)) || ball.difLine;
- ball.inCrux = false;
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.angle = ball.targetAngle;
- ball.cruxIndex++;
- if(ball.angle == 180){
- ball.x = crux.endpoint.x - ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.endpoint.x + ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y + ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y - ball.difLine;
- }else{
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- }
- continue;
- }
- }else{
- //旋转结束
- if((ball.angle - crux.angle) >= (ball.targetAngle - crux.angle)){
- ball.difLine = parseFloat((2 * Math.PI * radius * Math.abs(ball.targetAngle - ball.angle)/360) .toFixed(2)) || ball.difLine;
- ball.inCrux = false;
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- ball.angle = ball.targetAngle;
- ball.cruxIndex++;
- if(ball.angle == 180){
- ball.x = crux.endpoint.x - ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 360){
- ball.x = crux.endpoint.x + ball.difLine;
- ball.y = crux.endpoint.y;
- }else if(ball.angle == 270){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y + ball.difLine;
- }else if(ball.angle == 450){
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y - ball.difLine;
- }else{
- ball.x = crux.endpoint.x;
- ball.y = crux.endpoint.y;
- }
- continue;
- }
- }
- let dify = radius * Math.cos(Math.PI * ball.angle / 180);
- let difx = radius * Math.sin(Math.PI * ball.angle / 180);
- if(crux.angle < 0){
- ball.y = circleY - dify;
- ball.x = circleX - difx;
- }else{
- ball.y = circleY + dify;
- ball.x = circleX + difx;
- }
- }
- }
- if(this.end){
- this.gameOver();
- this.timer.stop();
- }
- }
- public checkBack(index:number){
- console.log("insertend:" + index);
- if(index == 0 || index >= this.startIndex - 1){
- return;
- }
- //如果插入的球和前面的球有间隔,且插入的球与前面的球类型相同,则后退操作
- if(!this.checkDif(this.balls_pool[index],this.balls_pool[index - 1])){
- if(this.balls_pool[index].type == this.balls_pool[index - 1].type){
- console.log("进来了");
- this.backIndex = index - 1;
- this.timer.stop();
- this.backstartIndex = this.backStartIndex(index - 1);
- if(!this.backTimerInit){
- this.backTimer.addEventListener(egret.TimerEvent.TIMER, () => {
- this.backTween();
- }, this);
- this.backTimerInit = true;
- }
- this.delNum = Math.floor(2/2) * (~~(this.playerBall.width / this.backSpeed));
- this.backTimer.reset();
- this.backTimer.start();
- //this.isAttack = false;
- }
- }else if(!this.checkDif(this.balls_pool[index],this.balls_pool[index + 1])){
- if(this.balls_pool[index].type == this.balls_pool[index + 1].type){
- console.log("进来了");
- this.backIndex = index;
- this.timer.stop();
- this.backstartIndex = this.backStartIndex(index);
- if(!this.backTimerInit){
- this.backTimer.addEventListener(egret.TimerEvent.TIMER, () => {
- this.backTween();
- }, this);
- this.backTimerInit = true;
- }
- this.delNum = Math.floor(2/2) * (~~(this.playerBall.width / this.backSpeed));
- this.backTimer.reset();
- this.backTimer.start();
- //this.isAttack = false;
- }
- }
- }
- //插入动画
- public insertTween(){
- if(this.insertNum == ~~(this.playerBall.width / this.insertSpeed)){
- this.insertNum = 0;
- console.log("insertend:" + this.insertend);
- this.checkCanMove(this.insertCheckIndex);
- this.insertTimer.stop();
- console.log("checkminend:" + this.insertend);
- this.checkMin(this.insertstart,this.startIndex - 1);
- this.checkBack(this.insertCheckIndex);
- return;
- }
- this.insertNum++;
- this.inserttween(this.insertstart,this.insertend+1);
- }
- //将球插入到已有数组
- public insertBall(index:number,ball:Ball,isTail:boolean){
- console.log("index " + index + " insertball");
- this.balls_pool.splice(index,0,ball);
- if(isTail){
- this.balls_pool[index].moveBy(this.balls_pool[index - 1]);
- this.insertend = index - 1;
- }else{
- console.log("不是尾部");
- this.balls_pool[index].moveBy(this.balls_pool[index + 1]);
- this.insertend = index;
- }
- if(index >= this.backIndex){
- //this.backIndex--;
- }else{
- this.backIndex++;
- }
- let frontBreakIndex:number = 0;
- this.insertCheckIndex = index;
- this.insertstart = this.index;
- //this.insertend = index;
- //如果插入的是移动队列中
- console.log("this.index:" + this.index);
- if(index >= this.index){
- this.insertTimer.start();
- }
- else{
- console.log("index:" + index + " this.index:" + this.index);
- //如果插入到前面已经停止的队列上,进行如下处理
- let i;
- //计算当前这个停止队列的首个球的下标
- for(i = index; i > 0 ; i--){
- if(!this.checkDif(this.balls_pool[i],this.balls_pool[i-1])){
- frontBreakIndex = i;
- break;
- }
- }
- if(i == 0 ){
- frontBreakIndex = 0;
- }
- //如果在最前面插入
- if(index == frontBreakIndex){
- this.balls_pool[frontBreakIndex].moveBy(this.balls_pool[frontBreakIndex + 1]);
- }
- this.insertstart = frontBreakIndex;
- this.insertTimer.start();
- this.index++;
- }
- this.startIndex++;
- }
- private async gameOver() {
- //游戏结束给开放数据域发送当前用户信息进行历史最高分比较
- if (!DataBus.Instance.userInfo) {
- DataBus.Instance.power_added = 0;
- Main.Instance.login();
- return;
- }
- if (DataBus.Instance.buff_expire - new Date().getMilliseconds() < 0) {
- Network.Instance.getHelpPowerInfo().catch(e => {
- DataBus.Instance.power_added = 0;
- DataBus.Instance.percent_added = 0;
- });
- }
- await Network.Instance.gameOver().then((game_info: any) => {
- console.log(game_info);
- DataBus.Instance.game_id = game_info ? game_info.game_id : 0;
- if (game_info.user_info) {
- let uper:boolean = false;
- if(DataBus.Instance.rebornCount < 3){
- uper = true;
- }
- DataBus.Instance.userInfo = game_info.user_info;
- platform.openDataContext.postMessage({
- text: 'score',
- score: DataBus.Instance.userInfo.max_score >= DataBus.Instance.score ? DataBus.Instance.userInfo.max_score : DataBus.Instance.score,
- open_id: DataBus.Instance.userInfo.open_id,
- uper: uper,
- current_score: DataBus.Instance.score
- });
- }
- }).catch(e => { console.log(e) });
- Main.Instance.removeChild(Game.Instance);
- if (DataBus.Instance.rebornCount < 3) {
- Main.Instance.addChild(GameOver1.Instance);
- } else {
- platform.openDataContext.postMessage({
- text: 'overRank',
- });
- Main.Instance.addChild(RebackFirstPage.Instance);
- }
- }
- public cos(x,y,x1,y1){
- let difX = x1 - x;
- let difY = y1 - y;
- let z = Math.sqrt(Math.pow(difX, 2) + Math.pow(difY, 2));
- this.sinValue = difX / z;
- this.cosValue = difY / z;
- }
- //检测是否相撞
- public checkAttack(index1:number){
- let length = this.startIndex;
- let playerBall = this.fireBalls[index1];
- for(let i = 0 ; i < length ; i++){
- let dif = this.diffPoint(this.balls_pool[i].x,this.balls_pool[i].y,this.fireBalls[index1].x,this.fireBalls[index1].y);
- //如果相撞,进行碰撞处理
- if(dif < this.playerBall.width * 2 / 3){
- GameUtil.Sound.playEffect("ball_wav");
- let index = i;
- //向上运动
- if(this.balls_pool[i].angle % 360 == 90){
- if(this.playerBall.y > this.balls_pool[i].y){
- index++;
- }
- }else if(this.balls_pool[i].angle % 360 == 270){
- if(this.playerBall.y < this.balls_pool[i].y){
- index++;
- }
- }else if(this.balls_pool[i].angle % 360 > 90 && this.balls_pool[i].angle % 360 < 270){
- if(this.playerBall.x > this.balls_pool[i].x){
- index++;
- }
- }else{
- if(this.playerBall.x < this.balls_pool[i].x){
- index++;
- }
- }
- //是否是尾部插入
- let isTail:boolean = false;
- if(index == i + 1){
- //如果插入地方的两个球距离小,则不是在后面插入
- if(this.checkDif(this.balls_pool[i],this.balls_pool[index])){
- isTail = false;
- }else{
- isTail = true;
- }
- }
- this.isAttack = false;
- //如果是爆裂球
- if(playerBall.type == GameProp.propType.boom){
- this.booms(playerBall,index);
- }else{
- this.insertBall(index,playerBall,isTail);
- }
- this.fireBalls.splice(index1,1);
- //this.checkCanMove(i);
- break;
- }
- }
- }
- //爆裂球
- public booms(ball:Ball,boomindex:number){
- this.ballContainer.removeChild(ball);
- let index:number = 0;
- let idArr:number[] = new Array();
- let indexjian:number = 0;
- for(let i = 0;i < this.startIndex - 1;i++){
- if(this.diffPoint(this.balls_pool[i].x,this.balls_pool[i].y,ball.x,ball.y) < 100){
- let obj = this.balls_pool[i];
- egret.Tween.get(obj).to({scaleX:1.2,scaleY:1.2},100).to({scaleX:0.1,scaleY:0.1},100).call(() => {
- obj.visible = false;
- });
- idArr.push(i);
- index = i;
- }
- }
- this.boomEffect(boomindex,idArr.length);
- this.updateScore(idArr.length);
- for(let i = this.startIndex - 1;i > 0 ;i--){
- for(let j = 0; j < idArr.length;j++){
- if(idArr[j]==i){
- this.balls_pool.splice(i,1);
- this.startIndex--;
- if(i > this.index){
- indexjian++;
- }
- break;
- }
- }
- }
- if(index > this.index){
- this.index = index + 1;
- this.index -= indexjian;
- }
- }
- //检测两个球的距离是否相邻
- public checkDif(ball1:Ball,ball2:Ball){
- if(ball1 == null || ball2 == null){
- return false;
- }
- if(this.diffPoint(ball1.x,ball1.y,ball2.x,ball2.y) > this.playerBall.width + 3){
- return false;
- }
- return true;
- }
- public checkDifMax(ball1:Ball,ball2:Ball){
- if(this.diffPoint(ball1.x,ball1.y,ball2.x,ball2.y) > this.playerBall.width + 5){
- return false;
- }
- return true;
- }
- //检测是否可消除
- public checkCanMove(index:number){
- if(this.end){
- return;
- }
- console.log("checkCanMove");
- let i:number = index - 1;
- let j:number = index + 1;
- let startIndex:number = index;
- let num:number = 1;
- let length = this.balls_pool.length;
- for(i ; i >= 0 ;i--){
- if(this.balls_pool[i].type == this.balls_pool[index].type && this.checkDif(this.balls_pool[i],this.balls_pool[i + 1])){
- startIndex = i;
- num++;
- }else{
- break;
- }
- }
- for(j ; j < this.startIndex - 1; j++){
- if(this.balls_pool[j].type == this.balls_pool[index].type && this.checkDif(this.balls_pool[j],this.balls_pool[j - 1])){
- num++;
- }else{
- break;
- }
- }
- if(num > 2){
- console.log("xiaochu");
- //GameUtil.Sound.playEffect("glass_wav");
- this.boomEffect(index,num);
- for(let i = 0;i<num; i++){
- let obj = this.balls_pool[startIndex+i];
- egret.Tween.get(obj).to({scaleX:1.2,scaleY:1.2},100).to({scaleX:0.1,scaleY:0.1},100).call(() => {
- obj.visible = false;
- });
- console.log("startIndex:" + (startIndex+i))
- }
- //如果不是首
- //j!= this.startIndex - 1 &&
- if(i!= -1){
- //如果消除后边上的两个球要是相同颜色,则前面的球后退
- console.log("i:" + i);
- console.log("j:" + j);
- if(this.balls_pool[i].type == this.balls_pool[j].type){
- this.balls_pool.splice(startIndex,num);
- this.insertend -= num;
- this.backIndex = i;
- this.timer.stop();
- this.backstartIndex = this.backStartIndex(i);
- if(!this.backTimerInit){
- this.backTimer.addEventListener(egret.TimerEvent.TIMER, () => {
- //this.backIndex = this.balls_pool.length - 2;
- this.backTween();
- }, this);
- this.backTimerInit = true;
- }
- this.updateScore(num);
- this.delNum = Math.floor(num/2) * (~~(this.playerBall.width / this.backSpeed));
- DataBus.Instance.scorePower++;
- if(DataBus.Instance.scorePower > 1){
- DataBus.Instance.lianjiNum++;
- }
- this.backTimer.reset();
- this.backTimer.start();
- //this.isAttack = false;
- this.startIndex -= num;
- return true;
- }else{
- //前面的球不动
- console.log("qianmianbudong");
- this.balls_pool.splice(startIndex,num);
- this.insertend -= num;
- this.updateScore(num);
- //如果插入的坐标处于正在移动的对列
- if(index >= this.index){
- this.index = i + 1;
- }
- this.delNum = 1;
- //this.isAttack = false;
- this.canPlay = true;
- }
- }else if(i == -1){
- //如果是头
- this.balls_pool.splice(startIndex,num);
- this.insertend -= num;
- if(index >= this.index){
- this.index = i + 1;
- }
- this.delNum = 1;
- this.updateScore(num);
- //this.isAttack = false;
- this.canPlay = true;
- }
- this.startIndex -= num;
- this.backIndex -= num;
- //return true;
- }else{
- //this.isAttack = false;
- this.canPlay = true;
- return false;
- }
- }
- public boomByIndex(index:number){
- this.boomMC.x = this.balls_pool[index].x;
- this.boomMC.y = this.balls_pool[index].y;
- //this.ballContainer.swapChildren(this.boomMC,this.balls_pool[this.startIndex - 1]);
- this.boomMC.visible = true;
- this.boomMC.gotoAndPlay(1,1);
- }
- public boomEffect(index:number,num:number){
- this.boomMC.x = this.balls_pool[index].x;
- this.boomMC.y = this.balls_pool[index].y;
- this.ballContainer.swapChildren(this.boomMC,this.balls_pool[this.startIndex - 1]);
- this.boomMC.visible = true;
- this.boomMC.gotoAndPlay(1,1);
- if(DataBus.Instance.scorePower > 0){
- if(DataBus.Instance.shock == GameProp.shockType.on){
- platform.vibrate(false).catch((e) => { console.log(e) });
- }
- //this.ballContainer.swapChildren(this.lianjiEffect,this.balls_pool[this.startIndex]);
- this.lianjiEffect.text = "连击x" + (DataBus.Instance.scorePower + 1) + "\n +" + num *10 * Math.pow(2,DataBus.Instance.scorePower);;
- this.lianjiEffect.x = this.balls_pool[index].x;
- this.lianjiEffect.y = this.balls_pool[index].y - 20;
- this.lianjiEffect.scaleX = 0;
- this.lianjiEffect.scaleY = 0;
- egret.Tween.removeTweens(this.lianjiEffect);
- egret.Tween.get(this.lianjiEffect).to({scaleX:1.2,scaleY:1.2},200).wait(500).to({scaleX:0,scaleY:0},100);
- }else{
- this.ballContainer.swapChildren(this.lianjiEffect,this.balls_pool[this.startIndex]);
- this.lianjiEffect.text = " " + "\n+" + num *10 * Math.pow(2,DataBus.Instance.scorePower);;
- this.lianjiEffect.x = this.balls_pool[index].x;
- this.lianjiEffect.y = this.balls_pool[index].y - 20;
- this.lianjiEffect.scaleX = 0;
- this.lianjiEffect.scaleY = 0;
- egret.Tween.removeTweens(this.lianjiEffect);
- egret.Tween.get(this.lianjiEffect).to({scaleX:1.2,scaleY:1.2},200).wait(500).to({scaleX:0,scaleY:0},100);
- }
- }
- //更新游戏分数,并根据分数调整游戏难度
- public updateScore(num:number){
- DataBus.Instance.score += num *10 * Math.pow(2,DataBus.Instance.scorePower);
- DataBus.Instance.gradeScore += num *10 * Math.pow(2,DataBus.Instance.scorePower);
- DataBus.Instance.ballNum += num;
- for(let i = this.levelConfig[this.levelIndex].score.length - 1; i > 0;i--){
- if(DataBus.Instance.score > this.levelConfig[this.levelIndex].score[i]){
- DataBus.Instance.nanduIndex = i;
- if(this.inited){
- this.speed = this.levelConfig[this.levelIndex].speed[i];
- }break;
- }
- }
- this.exper.mask = new egret.Rectangle(0,0,DataBus.Instance.gradeScore/DataBus.Instance.gradeNeedScore*this.stage.width,DataBus.Instance.gradeScore/DataBus.Instance.gradeNeedScore*this.stage.width);
- this.score.text = '' + DataBus.Instance.score;
- this.gradeScore.text = DataBus.Instance.gradeScore + '/' + DataBus.Instance.gradeNeedScore;
- this.score.anchorOffsetX = this.score.width / 2;
- egret.Tween.get(this.score).to({scaleX:1.2,scaleY:1.2},100).to({scaleX:1,scaleY:1},100);
- if(DataBus.Instance.gradeScore >= DataBus.Instance.gradeNeedScore && !this.backTimer.running){
- //通关
- this.end = true;
- this.timer.stop();
- this.backTimer.stop();
- this.insertTimer.stop();
- this.pass = true;
- //this.passThrough();
- }
- }
- public passThrough(){
- /*for(let i = 1;i < this.startIndex - 1;i = i + 3){
- setTimeout(()=>{
- this.boomMC.x = this.balls_pool[1].x;
- this.boomMC.y = this.balls_pool[1].y;
- //this.ballContainer.swapChildren(this.boomMC,this.balls_pool[this.startIndex - 1]);
- this.boomMC.visible = true;
- this.boomMC.gotoAndPlay(1,1);
- },this,1000);
- }*/
- this.addChild(this.throughContainer);
- DataBus.Instance.grade++;
- //等级缓存到本地
- //egret.localStorage.setItem("grade",DataBus.Instance.grade + '');
- let blackBg = new egret.Bitmap(RES.getRes('bg_black1_png'));
- blackBg.x = 0;
- blackBg.y = 0;
- blackBg.width = this.stage.stageWidth;
- blackBg.height = this.stage.stageHeight;
- this.throughContainer.addChild(blackBg);
- blackBg.touchEnabled = true;
- blackBg.addEventListener(egret.TouchEvent.TOUCH_TAP, (event: egret.TouchEvent) => {
- event.stopImmediatePropagation();
- this.throughContainer.removeChildren();
- this.removeChild(this.throughContainer);
- this.restart(-1);
- }, this);
- let through = new egret.Bitmap(RES.getRes('through_png'));
- through.width = 640;
- through.height = 841;
- through.x = this.stage.stageWidth;
- through.y = 64;
- this.throughContainer.addChild(through);
- egret.Tween.get(through).to({x:0},1000,egret.Ease.bounceOut);
- let ball = new egret.TextField();
- ball.text = '+' + DataBus.Instance.ballNum;
- ball.y = this.stage.stageHeight;
- ball.size=25;
- ball.bold = true;
- ball.textColor=0x422904;
- ball.x = this.stage.stageWidth / 2 - 300 + 346;
- ball.fontFamily="Arial";
- this.throughContainer.addChild(ball);
- egret.Tween.get(ball).to({y:518},1200,egret.Ease.bounceInOut);
- let lianji = new egret.TextField();
- lianji.text = '+' + DataBus.Instance.lianjiNum * 10;
- lianji.y = this.stage.stageHeight;
- lianji.size=25;
- lianji.bold = true;
- lianji.textColor=0x422904;
- lianji.x = this.stage.stageWidth / 2 - 300 + 346
- lianji.fontFamily="Arial";
- this.throughContainer.addChild(lianji);
- egret.Tween.get(lianji).to({y:579},1400,egret.Ease.bounceInOut);
- let crazy = new egret.TextField();
- crazy.text = '+' + DataBus.Instance.lianjiBigTwoNum * 100;
- crazy.y = this.stage.stageHeight;
- crazy.size=25;
- crazy.bold = true;
- crazy.textColor=0x422904;
- crazy.x = this.stage.stageWidth / 2 - 300 + 346;
- crazy.fontFamily="Arial";
- this.throughContainer.addChild(crazy);
- egret.Tween.get(crazy).to({y:645},1600,egret.Ease.bounceInOut);
- let juli = new egret.TextField();
- juli.text = '+' + (this.mapConfig.crux.length - this.balls_pool[0].cruxIndex) * 10;
- juli.y = this.stage.stageHeight;
- juli.size=25;
- juli.bold = true;
- juli.textColor=0x422904;
- juli.x = this.stage.stageWidth / 2 - 300 + 346;
- juli.fontFamily="Arial";
- this.throughContainer.addChild(juli);
- egret.Tween.get(juli).to({y:709},1800,egret.Ease.bounceInOut);
- let zong = new egret.TextField();
- zong.text = '+' + (DataBus.Instance.ballNum + DataBus.Instance.lianjiNum * 10 + DataBus.Instance.lianjiBigTwoNum * 100 + (this.mapConfig.crux.length - this.balls_pool[0].cruxIndex) * 10);
- zong.y = this.stage.stageHeight;
- zong.size=30;
- zong.bold = true;
- zong.textColor=0xf9372d;
- zong.x = this.stage.stageWidth / 2 - 300 + 346;
- zong.fontFamily="Arial";
- this.throughContainer.addChild(zong);
- egret.Tween.get(zong).to({y:785},2000,egret.Ease.bounceInOut);
- let jixu = new egret.TextField();
- jixu.text = '点击任意位置继续';
- jixu.y = 900;
- jixu.size=25;
- jixu.textColor=0xffffff;
- jixu.anchorOffsetX = jixu.width / 2;
- jixu.anchorOffsetY = jixu.height / 2;
- jixu.scaleX = 1;
- jixu.scaleY = 1;
- jixu.x = this.stage.stageWidth / 2;
- jixu.fontFamily="Arial";
- this.throughContainer.addChild(jixu);
- egret.Tween.get(jixu,{loop:true}).to({scaleX:1.1,scaleY:1.1},1000).to({scaleX:1.0,scaleY:1.0},1000);
- DataBus.Instance.score += DataBus.Instance.ballNum + DataBus.Instance.lianjiNum * 10 + DataBus.Instance.lianjiBigTwoNum * 100 + (this.mapConfig.crux.length - this.balls_pool[0].cruxIndex) * 10;
- }
- //计算玩家的球与目标球的距离
- public diffPoint(x,y,x1,y1){
- let difX = x - x1;
- let difY = y - y1;
- //如果两点相同,则返回1进行误差处理
- if(difX == 0 && difY == 0){
- return 1;
- }
- return Math.sqrt(Math.pow(difX, 2) + Math.pow(difY, 2));
- }
- private enterFrame(event: egret.TouchEvent) {
- DataBus.Instance.frame++;
- this.playNumEnterFrame++;
- if(this.pass){
- this.passFrame++;
- if(this.passIndex > this.balls_pool.length - 2){
- this.pass = false;
- this.passIndex = 2;
- for(let i = 0; i < this.balls_pool.length - 1;i++){
- this.balls_pool[i].visible = false;
- }
- this.passThrough();
- return;
- }
- if(this.passFrame > 10){
- this.boomByIndex(this.passIndex);
- for(let i = 0; i < this.passIndex;i++){
- this.balls_pool[i].visible = false;
- }
- //this.balls_pool.splice(0,5);
- this.passIndex += 5;
- this.passFrame = 0;
- }
- }
- if(this.end){
- return ;
- }
- //console.log(DataBus.Instance.frame);
- //结束特效
- /*if (DataBus.Instance.frame >= 10){
- DataBus.Instance.frame = 0;
- if(this.balls_pool[0].cruxIndex == this.mapConfig.crux.length && this.balls_pool[0].x < 400){
- this.blast.visible = !this.blast.visible;
- this.mapend.visible = !this.mapend.visible;
- }else{
- this.blast.visible = false;
- this.mapend.visible = false;
- }
- }*/
- if(this.haveDot){
- this.dotContainer.getChildAt(0).visible = true;
- let sinValue = this.sinValue;
- let cosValue = this.cosValue;
- let i:number;
- for(i = 0;i < this.dotLength - 1;i++){
- this.dotContainer.getChildAt(i+1).x = this.dotContainer.getChildAt(i).x + this.playerBall.width / 3 * sinValue * 2;
- this.dotContainer.getChildAt(i+1).y = this.dotContainer.getChildAt(i).y + this.playerBall.width / 3 * cosValue * 2;
- this.dotContainer.getChildAt(i+1).visible = true;
- let j:number;
- for(j = 0; j < this.balls_pool.length;j++){
- if(this.diffPoint(this.dotContainer.getChildAt(i+1).x,this.dotContainer.getChildAt(i+1).y,this.balls_pool[j].x,this.balls_pool[j].y) < this.playerBall.width / 2
- || this.dotContainer.getChildAt(i+1).x < 0
- || this.dotContainer.getChildAt(i+1).x > this.ballContainer.width
- || this.dotContainer.getChildAt(i+1).y < 0
- || this.dotContainer.getChildAt(i+1).y > this.ballContainer.height){
- this.dotContainer.getChildAt(i+1).visible = false;
- break;
- }
- }
- if(j != this.balls_pool.length){
- break;
- }
- /*if( this.dotContainer.getChildAt(i+1).x < 0 ){
- sinValue = -this.sinValue;
- this.dotContainer.getChildAt(i+1).x = -this.dotContainer.getChildAt(i+1).x;
- }else if(this.dotContainer.getChildAt(i+1).x > this.ballContainer.width ){
- sinValue = -this.sinValue;
- this.dotContainer.getChildAt(i+1).x =this.ballContainer.width * 2 - this.dotContainer.getChildAt(i+1).x;
- }
- //边界处理
- if(this.dotContainer.getChildAt(i+1).y < 0 ){
- cosValue = -this.cosValue;
- this.dotContainer.getChildAt(i+1).y = -this.dotContainer.getChildAt(i+1).y;
- }else if(this.dotContainer.getChildAt(i+1).y > this.ballContainer.height){
- cosValue = -this.cosValue;
- this.dotContainer.getChildAt(i+1).y = this.ballContainer.height * 2 - this.dotContainer.getChildAt(i+1).y;
- }*/
- }
- //如果前面的点与球有碰撞,则后面都不显示
- for(i;i < this.dotLength - 1;i++){
- this.dotContainer.getChildAt(i+1).visible = false;
- }
- }else{
- if(this.dotContainer.getChildAt(0).visible == true){
- for(let i = 0;i < this.dotLength ;i++){
- this.dotContainer.getChildAt(i).visible = false;
- }
- }
- }
- //if(this.isAttack){
- for(let i = 0;i < this.fireBalls.length; i++){
- let playerBall = this.fireBalls[i];
- this.canPlay = false;
- playerBall.x += playerBall.speed * playerBall.sinValue;
- playerBall.y += playerBall.speed * playerBall.cosValue;
- //this.playerBall.speed = this.playerBall.speed + 0.1;
- //边界处理
- if(playerBall.x < 0 || playerBall.x > this.ballContainer.width){
- //this.sinValue = -this.sinValue;
- this.ballContainer.removeChild(playerBall);
- this.fireBalls.splice(i,1);
- this.canPlay = true;
- this.isAttack = false;
- break;
- }
- //边界处理
- if(playerBall.y < 0 || playerBall.y > this.ballContainer.height){
- //this.cosValue = -this.cosValue;
- this.ballContainer.removeChild(playerBall);
- this.fireBalls.splice(i,1);
- this.canPlay = true;
- this.isAttack = false;
- break;
- }
- this.checkAttack(i);
- }
- // }
- }
- public shakeBg(time = 0.1, rate = 60, distance = 2) {
- ShakeTool.getInstance().shakeObj(BackGround.Instance, time, rate, distance);
- }
- }
- class BgEffect extends egret.Sprite {
- private static shapes: Array<egret.Texture>;
- private static lines: Array<egret.Texture>;
- private shape: egret.Bitmap;
-
- public constructor() {
- super();
- this.once(egret.Event.ADDED_TO_STAGE, () => {
- BgEffect.shapes = new Array();
- BgEffect.lines = new Array();
- for (let i = 1; i < 7; i++) {
- BgEffect.shapes.push(RES.getRes('eff' + i + '_png'));
- BgEffect.lines.push(RES.getRes('eff' + i + '_' + i + '_png'));
- }
- let rnd = ~~(Math.random() * BgEffect.shapes.length);
- this.alpha = 0;
- this.shape = new egret.Bitmap(BgEffect.shapes[rnd]);
- this.shape.x = 140;
- this.shape.y = 140;
- this.anchorOffsetX = this.shape.anchorOffsetX = 140;
- this.anchorOffsetY = this.shape.anchorOffsetY = 140;
- this.addChild(this.shape);
- for (let i = 0; i < 8; i++) {
- let angle = Math.random() * Math.PI * 2;
- let line = new LineSprite(BgEffect.lines[rnd]);
- line.x = 140;
- line.y = 140;
- line.speedx = Math.cos(angle) * 8 * this.scaleX;
- line.speedy = Math.sin(angle) * 8 * this.scaleX;
- line.rotation = angle / Math.PI * 180;
- this.addChild(line);
- }
- }, this);
- }
- }
- class LineSprite extends egret.Bitmap {
- speedx: number;
- speedy: number;
- update() {
- this.x += this.speedx;
- this.y += this.speedy;
- this.scaleX -= 0.03;
- }
- }
- /**
- * 震动工具
- * @author chenkai
- * [url=home.php?mod=space&uid=81950]@since[/url] 2017/5/24
- *
- * Example:
- * 震动目标obj,1秒内震动10次,震动最大距离10
- * ShakeTool.getInstance().shakeObj(obj, 1, 10, 10);
- */
- class ShakeTool {
- private static instance: ShakeTool; //单例
- private initX: number; //初始位置
- private initY: number;
- private target: egret.DisplayObject; //震动目标
- private maxDis: number; //震动距离
- private count: number = 0; //计时器次数
- private rate: number; //一秒震动次数
- private timer: egret.Timer = new egret.Timer(200);
- public static getInstance(): ShakeTool {
- if (this.instance == null) {
- this.instance = new ShakeTool();
- }
- return this.instance;
- }
- /**
- * 震动显示对象
- * @param target 震动目标对象
- * @param time 震动持续时长(秒)
- * @param rate 震动频率(一秒震动多少次)
- * @param maxDis 震动最大距离
- */
- public shakeObj(target: egret.DisplayObject, time: number, rate: number, maxDis: number): void {
- if (this.target) {
- return;
- }
- this.target = target;
- this.initX = target.x;
- this.initY = target.y;
- this.maxDis = maxDis;
- this.count = time * rate;
- this.rate = rate;
- this.timer.delay = 200 / rate;
- this.timer.repeatCount = this.count;
- this.timer.addEventListener(egret.TimerEvent.TIMER, this.shaking, this);
- this.timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.shakeComplete, this);
- this.timer.reset();
- this.timer.start();
- }
- private shaking(): void {
- egret.Tween.removeTweens(this.target);
- this.target.x = this.initX - this.maxDis + Math.random() * this.maxDis * 2;
- this.target.y = this.initY - this.maxDis + Math.random() * this.maxDis * 2;
- egret.Tween.get(this.target).to({ x: this.initX, y: this.initY }, 999 / this.rate);
- }
- private shakeComplete(): void {
- if (this.target) {
- egret.Tween.removeTweens(this.target);
- this.target.x = this.initX;
- this.target.y = this.initY;
- this.target = null;
- }
- this.timer.removeEventListener(egret.TimerEvent.TIMER, this.shaking, this);
- this.timer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.shakeComplete, this);
- }
- /**停止震动 */
- public stop() {
- this.shakeComplete();
- }
- }
|