1
1
export default control ;
2
2
import { functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a } from '../project/functions'
3
3
import localforage from './thirdparty/localforage.min.js' ;
4
+ import route from '../../pixi/scenes/route' ;
4
5
/*
5
6
control.js:游戏主要逻辑控制
6
7
主要负责status相关内容,以及各种变量获取/存储
@@ -21,11 +22,11 @@ control.prototype._init = function () {
21
22
// --- 注册系统的animationFrame
22
23
this . registerAnimationFrame ( "totalTime" , false , this . _animationFrame_totalTime ) ;
23
24
this . registerAnimationFrame ( "autoSave" , true , this . _animationFrame_autoSave ) ;
24
- this . registerAnimationFrame ( "globalAnimate" , true , this . _animationFrame_globalAnimate ) ;
25
- this . registerAnimationFrame ( "animate" , true , this . _animationFrame_animate ) ;
25
+ // this.registerAnimationFrame("globalAnimate", true, this._animationFrame_globalAnimate);
26
+ // this.registerAnimationFrame("animate", true, this._animationFrame_animate);
26
27
this . registerAnimationFrame ( "heroMoving" , true , this . _animationFrame_heroMoving ) ;
27
- this . registerAnimationFrame ( "weather" , true , this . _animationFrame_weather ) ;
28
- this . registerAnimationFrame ( "tips" , true , this . _animateFrame_tips ) ;
28
+ // this.registerAnimationFrame("weather", true, this._animationFrame_weather);
29
+ // this.registerAnimationFrame("tips", true, this._animateFrame_tips);
29
30
this . registerAnimationFrame ( "parallelDo" , false , this . _animationFrame_parallelDo ) ;
30
31
this . registerAnimationFrame ( "checkConsoleOpened" , true , this . _animationFrame_checkConsoleOpened ) ;
31
32
// --- 注册系统的replay
@@ -416,9 +417,7 @@ control.prototype._initStatistics = function (totalTime) {
416
417
// ------ 自动寻路,人物行走 ------ //
417
418
418
419
////// 清除自动寻路路线 //////
419
- control . prototype . clearAutomaticRouteNode = function ( x , y ) {
420
- core . clearMap ( 'route' , x * 32 + 5 - core . status . automaticRoute . offsetX , y * 32 + 5 - core . status . automaticRoute . offsetY , 27 , 27 ) ;
421
- }
420
+
422
421
423
422
////// 停止自动寻路操作 //////
424
423
control . prototype . stopAutomaticRoute = function ( ) {
@@ -433,7 +432,7 @@ control.prototype.stopAutomaticRoute = function () {
433
432
core . status . automaticRoute . lastDirection = null ;
434
433
core . status . heroStop = true ;
435
434
if ( core . status . automaticRoute . moveStepBeforeStop . length == 0 )
436
- core . deleteCanvas ( 'route' ) ;
435
+ route . clear ( ) ;
437
436
}
438
437
439
438
////// 保存剩下的寻路,并停止 //////
@@ -463,19 +462,22 @@ control.prototype.continueAutomaticRoute = function () {
463
462
////// 清空剩下的自动寻路列表 //////
464
463
control . prototype . clearContinueAutomaticRoute = function ( callback ) {
465
464
//TODO
466
- core . deleteCanvas ( 'route' ) ;
465
+ route . clear ( ) ;
467
466
core . status . automaticRoute . moveStepBeforeStop = [ ] ;
468
467
if ( callback ) callback ( ) ;
469
468
}
470
469
471
470
////// 显示离散的寻路点 //////
472
471
// TODO
473
472
control . prototype . fillPosWithPoint = function ( pos ) {
474
- core . fillRect ( 'ui' , pos . x * 32 + 12 , pos . y * 32 + 12 , 8 , 8 , '#bfbfbf' ) ;
473
+ // core.fillRect('ui', pos.x*32+12,pos.y*32+12,8,8, '#bfbfbf');
474
+ route . fillPosWithPoint ( pos ) ;
475
475
}
476
476
477
477
////// 设置自动寻路路线 //////
478
478
control . prototype . setAutomaticRoute = function ( destX , destY , stepPostfix ) {
479
+ // 清空寻路node和 点选node
480
+ route . clear ( ) ;
479
481
if ( ! core . status . played || core . status . lockControl ) return ;
480
482
if ( this . _setAutomaticRoute_isMoving ( destX , destY ) ) return ;
481
483
if ( this . _setAutomaticRoute_isTurning ( destX , destY , stepPostfix ) ) return ;
@@ -490,7 +492,7 @@ control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
490
492
this . _setAutomaticRoute_drawRoute ( moveStep ) ;
491
493
this . _setAutomaticRoute_setAutoSteps ( moveStep ) ;
492
494
// 立刻移动
493
- core . setAutoHeroMove ( ) ;
495
+ this . setAutoHeroMove ( ) ;
494
496
}
495
497
496
498
control . prototype . _setAutomaticRoute_isMoving = function ( destX , destY ) {
@@ -544,32 +546,7 @@ control.prototype._setAutomaticRoute_clickMoveDirectly = function (destX, destY,
544
546
control . prototype . _setAutomaticRoute_drawRoute = function ( moveStep ) {
545
547
// 计算绘制区域的宽高,并尽可能小的创建route层
546
548
// TODO
547
- pixi . ui . drawRoute ( moveStep ) ;
548
- var sx = core . bigmap . width * 32 , sy = core . bigmap . height * 32 , dx = 0 , dy = 0 ;
549
- moveStep . forEach ( function ( t ) {
550
- sx = Math . min ( sx , t . x * 32 ) ; dx = Math . max ( dx , t . x * 32 ) ;
551
- sy = Math . min ( sy , t . y * 32 ) ; dy = Math . max ( dy , t . y * 32 ) ;
552
- } ) ;
553
- core . status . automaticRoute . offsetX = sx ;
554
- core . status . automaticRoute . offsetY = sy ;
555
- var ctx = core . createCanvas ( 'route' , sx - core . bigmap . offsetX , sy - core . bigmap . offsetY , dx - sx + 32 , dy - sy + 32 , 95 ) ;
556
- ctx . fillStyle = '#bfbfbf' ;
557
- ctx . strokeStyle = '#bfbfbf' ;
558
- ctx . lineWidth = 8 ;
559
- for ( var m = 0 ; m < moveStep . length ; m ++ ) {
560
- if ( m == moveStep . length - 1 ) {
561
- ctx . fillRect ( moveStep [ m ] . x * 32 + 10 - sx , moveStep [ m ] . y * 32 + 10 - sy , 12 , 12 ) ;
562
- }
563
- else {
564
- ctx . beginPath ( ) ;
565
- var cx = moveStep [ m ] . x * 32 + 16 - sx , cy = moveStep [ m ] . y * 32 + 16 - sy ;
566
- var currDir = moveStep [ m ] . direction , nextDir = moveStep [ m + 1 ] . direction ;
567
- ctx . moveTo ( cx - core . utils . scan [ currDir ] . x * 11 , cy - core . utils . scan [ currDir ] . y * 11 ) ;
568
- ctx . lineTo ( cx , cy ) ;
569
- ctx . lineTo ( cx + core . utils . scan [ nextDir ] . x * 11 , cy + core . utils . scan [ nextDir ] . y * 11 ) ;
570
- ctx . stroke ( ) ;
571
- }
572
- }
549
+ route . drawRoute ( moveStep ) ;
573
550
}
574
551
575
552
control . prototype . _setAutomaticRoute_setAutoSteps = function ( moveStep ) {
@@ -596,7 +573,7 @@ control.prototype.setAutoHeroMove = function (steps) {
596
573
core . status . automaticRoute . autoHeroMove = true ;
597
574
core . status . automaticRoute . autoStep = 1 ;
598
575
core . status . automaticRoute . destStep = steps [ 0 ] . step ;
599
- core . moveHero ( steps [ 0 ] . direction ) ;
576
+ this . moveHero ( steps [ 0 ] . direction ) ;
600
577
}
601
578
602
579
////// 设置行走的效果动画 //////
@@ -648,7 +625,7 @@ control.prototype._moveAction_noPass = function (canMove, callback) {
648
625
core . drawHero ( ) ;
649
626
650
627
if ( core . status . automaticRoute . moveStepBeforeStop . length == 0 ) {
651
- core . clearContinueAutomaticRoute ( ) ;
628
+ this . clearContinueAutomaticRoute ( ) ;
652
629
core . stopAutomaticRoute ( ) ;
653
630
}
654
631
if ( callback ) callback ( ) ;
@@ -662,6 +639,7 @@ control.prototype._moveAction_moving = function (callback) {
662
639
663
640
// 无事件的道具(如血瓶)需要优先于阻激夹域判定
664
641
var nowx = core . getHeroLoc ( 'x' ) , nowy = core . getHeroLoc ( 'y' ) ;
642
+ route . clearAutomaticRouteNode ( nowx , nowy ) ;
665
643
var block = core . getBlock ( nowx , nowy ) ;
666
644
var hasTrigger = false ;
667
645
if ( block != null && block . block . event . trigger == 'getItem' &&
@@ -817,7 +795,6 @@ control.prototype.drawHero = function (status, offset) {
817
795
var dx = way . x , dy = way . y , offsetX = dx * offset , offsetY = dy * offset ;
818
796
core . bigmap . offsetX = core . clamp ( ( x - core . __HALF_SIZE__ ) * 32 + offsetX , 0 , 32 * core . bigmap . width - core . __PIXELS__ ) ;
819
797
core . bigmap . offsetY = core . clamp ( ( y - core . __HALF_SIZE__ ) * 32 + offsetY , 0 , 32 * core . bigmap . height - core . __PIXELS__ ) ;
820
- core . clearAutomaticRouteNode ( x + dx , y + dy ) ;
821
798
core . status . heroCenter . px = 32 * x + offsetX + 16 ;
822
799
core . status . heroCenter . py = 32 * y + offsetY + 32 - core . material . icons . hero . height / 2 ;
823
800
const heroSprite = core . status . heroSprite ;
@@ -833,9 +810,7 @@ control.prototype.drawHero = function (status, offset) {
833
810
, block . posy + 32 - block . height + core . bigmap . offsetY ) ;
834
811
} ) ;
835
812
}
836
-
837
- core . control . updateViewport ( ) ;
838
- core . setGameCanvasTranslate ( 'hero' , 0 , 0 ) ;
813
+ this . updateViewport ( ) ;
839
814
}
840
815
841
816
control . prototype . _drawHero_getDrawObjs = function ( direction , x , y , status , offset ) {
@@ -870,22 +845,6 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off
870
845
// ------ 画布、位置、阻激夹域,显伤 ------ //
871
846
872
847
////// 设置画布偏移
873
- control . prototype . setGameCanvasTranslate = function ( canvas , x , y ) {
874
- return ;
875
- var c = core . dom . gameCanvas [ canvas ] ;
876
- x = x * core . domStyle . scale ;
877
- y = y * core . domStyle . scale ;
878
- c . style . transform = 'translate(' + x + 'px,' + y + 'px)' ;
879
- c . style . webkitTransform = 'translate(' + x + 'px,' + y + 'px)' ;
880
- c . style . OTransform = 'translate(' + x + 'px,' + y + 'px)' ;
881
- c . style . MozTransform = 'translate(' + x + 'px,' + y + 'px)' ;
882
- if ( main . mode === 'editor' && editor . isMobile ) {
883
- c . style . transform = 'translate(' + ( x / core . __PIXELS__ * 96 ) + 'vw,' + ( y / core . __PIXELS__ * 96 ) + 'vw)' ;
884
- c . style . webkitTransform = 'translate(' + ( x / core . __PIXELS__ * 96 ) + 'vw,' + ( y / core . __PIXELS__ * 96 ) + 'vw)' ;
885
- c . style . OTransform = 'translate(' + ( x / core . __PIXELS__ * 96 ) + 'vw,' + ( y / core . __PIXELS__ * 96 ) + 'vw)' ;
886
- c . style . MozTransform = 'translate(' + ( x / core . __PIXELS__ * 96 ) + 'vw,' + ( y / core . __PIXELS__ * 96 ) + 'vw)' ;
887
- }
888
- } ;
889
848
890
849
////// 加减画布偏移
891
850
control . prototype . addGameCanvasTranslate = function ( x , y ) {
@@ -909,9 +868,12 @@ control.prototype.updateViewport = function() {
909
868
//pixi.game.container.setTransform(- core.bigmap.offsetX,- core.bigmap.offsetY);
910
869
const container = pixi . game . container ;
911
870
const [ offsetX , offsetY ] = container . zone ;
912
- pixi . game . container . setTransform ( offsetX - core . bigmap . offsetX , offsetY - core . bigmap . offsetY ) ;
871
+ const x = offsetX - core . bigmap . offsetX ;
872
+ const y = offsetY - core . bigmap . offsetY ;
873
+ if ( container . x !== x || container . y !== y ) {
874
+ container . position . set ( x , y ) ;
875
+ }
913
876
// ------ 路线
914
- core . relocateCanvas ( 'route' , core . status . automaticRoute . offsetX - core . bigmap . offsetX , core . status . automaticRoute . offsetY - core . bigmap . offsetY ) ;
915
877
}
916
878
917
879
////// 设置视野范围 //////
@@ -920,9 +882,6 @@ control.prototype.setViewport = function (x, y) {
920
882
core . bigmap . offsetY = core . clamp ( y , 0 , 32 * core . bigmap . height - core . __PIXELS__ ) ;
921
883
this . updateViewport ( ) ;
922
884
// ------ hero层也需要!
923
- var hero_x = core . clamp ( ( core . getHeroLoc ( 'x' ) - core . __HALF_SIZE__ ) * 32 , 0 , 32 * core . bigmap . width - core . __PIXELS__ ) ;
924
- var hero_y = core . clamp ( ( core . getHeroLoc ( 'y' ) - core . __HALF_SIZE__ ) * 32 , 0 , 32 * core . bigmap . height - core . __PIXELS__ ) ;
925
- core . control . setGameCanvasTranslate ( 'hero' , hero_x - core . bigmap . offsetX , hero_y - core . bigmap . offsetY ) ;
926
885
}
927
886
928
887
////// 移动视野范围 //////
0 commit comments