@litecanvas/utils 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actor.js +16 -9
- package/dist/actor.min.js +1 -1
- package/dist/all.js +142 -89
- package/dist/all.min.js +2 -2
- package/dist/vector.js +140 -87
- package/dist/vector.min.js +1 -1
- package/package.json +1 -1
- package/src/actor/index.js +9 -9
- package/src/vector/README.md +62 -75
- package/src/vector/index.js +196 -73
package/dist/actor.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// src/vector/index.js
|
|
29
|
+
var PI2 = 2 * Math.PI;
|
|
29
30
|
var Vector = class {
|
|
30
31
|
/** @type {number} */
|
|
31
32
|
x;
|
|
@@ -46,8 +47,14 @@
|
|
|
46
47
|
return `Vector (${this.x}, ${this.y})`;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
var
|
|
50
|
-
var
|
|
50
|
+
var isVector = (v) => v instanceof Vector;
|
|
51
|
+
var vec = (x = 0, y = x) => {
|
|
52
|
+
if (isVector(x)) {
|
|
53
|
+
y = x.y;
|
|
54
|
+
x = x.x;
|
|
55
|
+
}
|
|
56
|
+
return new Vector(x, y);
|
|
57
|
+
};
|
|
51
58
|
|
|
52
59
|
// src/actor/index.js
|
|
53
60
|
var ANCHOR_CENTER = vec(0.5, 0.5);
|
|
@@ -78,7 +85,7 @@
|
|
|
78
85
|
constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
|
|
79
86
|
this.sprite = sprite;
|
|
80
87
|
this.pos = position || vec(0);
|
|
81
|
-
this._o =
|
|
88
|
+
this._o = vec(anchor);
|
|
82
89
|
this._s = vec(1, 1);
|
|
83
90
|
}
|
|
84
91
|
/**
|
|
@@ -130,6 +137,12 @@
|
|
|
130
137
|
get height() {
|
|
131
138
|
return this.sprite.height * this._s.y;
|
|
132
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* @retuns {Vector}
|
|
142
|
+
*/
|
|
143
|
+
get scale() {
|
|
144
|
+
return this._s;
|
|
145
|
+
}
|
|
133
146
|
/**
|
|
134
147
|
* @returns {number[]}
|
|
135
148
|
*/
|
|
@@ -140,12 +153,6 @@
|
|
|
140
153
|
const y = this.pos.y - h * this.anchor.y;
|
|
141
154
|
return [x, y, w, h];
|
|
142
155
|
}
|
|
143
|
-
/**
|
|
144
|
-
* @retuns {Vector}
|
|
145
|
-
*/
|
|
146
|
-
get scale() {
|
|
147
|
-
return this._s;
|
|
148
|
-
}
|
|
149
156
|
/**
|
|
150
157
|
* Update the transformation matrix, sets the opacity and draw the actor sprite image.
|
|
151
158
|
*
|
package/dist/actor.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var p=Object.defineProperty;var u=(e,t)=>{for(var o in t)p(e,o,{get:t[o],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var a={};u(a,{ANCHOR_BOT_LEFT:()=>y,ANCHOR_BOT_RIGHT:()=>g,ANCHOR_CENTER:()=>x,ANCHOR_TOP_LEFT:()=>c,ANCHOR_TOP_RIGHT:()=>d,Actor:()=>i});var m=2*Math.PI,n=class{x;y;constructor(t=0,o=t){this.x=t,this.y=o}toString(){return`Vector (${this.x}, ${this.y})`}},h=e=>e instanceof n,r=(e=0,t=e)=>(h(e)&&(t=e.y,e=e.x),new n(e,t));var x=r(.5,.5),c=r(0,0),d=r(1,0),y=r(0,1),g=r(1,1),i=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,o,s=c){this.sprite=t,this.pos=o||r(0),this._o=r(s),this._s=r(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}getBounds(t=!0){let o=this.sprite.width*(t?this._s.x:1),s=this.sprite.height*(t?this._s.y:1),l=this.pos.x-o*this.anchor.x,f=this.pos.y-s*this.anchor.y;return[l,f,o,s]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let o=this.sprite.width*this.anchor.x,s=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-o,-s,this.sprite)}};globalThis.utils=Object.assign(globalThis.utils||{},a);})();
|
package/dist/all.js
CHANGED
|
@@ -36,30 +36,36 @@
|
|
|
36
36
|
diff: () => diff_default,
|
|
37
37
|
fract: () => fract_default,
|
|
38
38
|
intersection: () => intersection_default,
|
|
39
|
-
isvector: () => isvector,
|
|
40
39
|
range: () => range_default,
|
|
41
40
|
resolve: () => resolve_default,
|
|
42
41
|
vec: () => vec,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
vecAbs: () => vecAbs,
|
|
43
|
+
vecAdd: () => vecAdd,
|
|
44
|
+
vecAngle: () => vecAngle,
|
|
45
|
+
vecCeil: () => vecCeil,
|
|
46
|
+
vecClamp: () => vecClamp,
|
|
47
|
+
vecCross: () => vecCross,
|
|
48
|
+
vecDist: () => vecDist,
|
|
49
|
+
vecDist2: () => vecDist2,
|
|
50
|
+
vecDiv: () => vecDiv,
|
|
51
|
+
vecDot: () => vecDot,
|
|
52
|
+
vecEq: () => vecEq,
|
|
53
|
+
vecFloor: () => vecFloor,
|
|
54
|
+
vecIsZero: () => vecIsZero,
|
|
55
|
+
vecLerp: () => vecLerp,
|
|
56
|
+
vecLimit: () => vecLimit,
|
|
57
|
+
vecMag: () => vecMag,
|
|
58
|
+
vecMag2: () => vecMag2,
|
|
59
|
+
vecMove: () => vecMove,
|
|
60
|
+
vecMult: () => vecMult,
|
|
61
|
+
vecNorm: () => vecNorm,
|
|
62
|
+
vecRand: () => vecRand,
|
|
63
|
+
vecReflect: () => vecReflect,
|
|
64
|
+
vecRotate: () => vecRotate,
|
|
65
|
+
vecRound: () => vecRound,
|
|
66
|
+
vecSet: () => vecSet,
|
|
67
|
+
vecSetMag: () => vecSetMag,
|
|
68
|
+
vecSub: () => vecSub,
|
|
63
69
|
wave: () => wave_default
|
|
64
70
|
});
|
|
65
71
|
|
|
@@ -509,6 +515,10 @@
|
|
|
509
515
|
}
|
|
510
516
|
|
|
511
517
|
// src/vector/index.js
|
|
518
|
+
var sqrt = Math.sqrt;
|
|
519
|
+
var cos = Math.cos;
|
|
520
|
+
var sin = Math.sin;
|
|
521
|
+
var PI2 = 2 * Math.PI;
|
|
512
522
|
var Vector = class {
|
|
513
523
|
/** @type {number} */
|
|
514
524
|
x;
|
|
@@ -529,102 +539,145 @@
|
|
|
529
539
|
return `Vector (${this.x}, ${this.y})`;
|
|
530
540
|
}
|
|
531
541
|
};
|
|
532
|
-
var
|
|
533
|
-
var
|
|
534
|
-
if (
|
|
535
|
-
|
|
542
|
+
var isVector = (v) => v instanceof Vector;
|
|
543
|
+
var vec = (x = 0, y = x) => {
|
|
544
|
+
if (isVector(x)) {
|
|
545
|
+
y = x.y;
|
|
546
|
+
x = x.x;
|
|
547
|
+
}
|
|
548
|
+
return new Vector(x, y);
|
|
549
|
+
};
|
|
550
|
+
var vecEq = (v, x, y = x) => {
|
|
551
|
+
if (isVector(x)) {
|
|
552
|
+
return vecEq(v, x.x, x.y);
|
|
536
553
|
}
|
|
537
554
|
return v.x === x && v.y === y;
|
|
538
555
|
};
|
|
539
|
-
var
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
vecset(v, x.x, x.y);
|
|
556
|
+
var vecSet = (v, x, y = x) => {
|
|
557
|
+
if (isVector(x)) {
|
|
558
|
+
vecSet(v, x.x, x.y);
|
|
543
559
|
} else {
|
|
544
560
|
v.x = x;
|
|
545
561
|
v.y = y;
|
|
546
562
|
}
|
|
563
|
+
return v;
|
|
547
564
|
};
|
|
548
|
-
var
|
|
549
|
-
if (
|
|
550
|
-
|
|
551
|
-
} else {
|
|
552
|
-
v.x += x;
|
|
553
|
-
v.y += y;
|
|
565
|
+
var vecAdd = (v, x, y = x) => {
|
|
566
|
+
if (isVector(x)) {
|
|
567
|
+
return vecAdd(v, x.x, x.y);
|
|
554
568
|
}
|
|
569
|
+
v.x += x;
|
|
570
|
+
v.y += y;
|
|
571
|
+
return v;
|
|
555
572
|
};
|
|
556
|
-
var
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
} else {
|
|
560
|
-
v.x -= x;
|
|
561
|
-
v.y -= y;
|
|
573
|
+
var vecSub = (v, x, y = x) => {
|
|
574
|
+
if (isVector(x)) {
|
|
575
|
+
return vecSub(v, x.x, x.y);
|
|
562
576
|
}
|
|
577
|
+
v.x -= x;
|
|
578
|
+
v.y -= y;
|
|
579
|
+
return v;
|
|
563
580
|
};
|
|
564
|
-
var
|
|
565
|
-
if (
|
|
566
|
-
|
|
567
|
-
} else {
|
|
568
|
-
v.x *= x;
|
|
569
|
-
v.y *= y;
|
|
581
|
+
var vecMult = (v, x, y = x) => {
|
|
582
|
+
if (isVector(x)) {
|
|
583
|
+
return vecMult(v, x.x, x.y);
|
|
570
584
|
}
|
|
585
|
+
v.x *= x;
|
|
586
|
+
v.y *= y;
|
|
587
|
+
return v;
|
|
571
588
|
};
|
|
572
|
-
var
|
|
573
|
-
if (
|
|
574
|
-
|
|
575
|
-
} else {
|
|
576
|
-
v.x /= x;
|
|
577
|
-
v.y /= y;
|
|
589
|
+
var vecDiv = (v, x, y = x) => {
|
|
590
|
+
if (isVector(x)) {
|
|
591
|
+
return vecDiv(v, x.x, x.y);
|
|
578
592
|
}
|
|
593
|
+
v.x /= x;
|
|
594
|
+
v.y /= y;
|
|
595
|
+
return v;
|
|
596
|
+
};
|
|
597
|
+
var vecRotate = (v, radians) => {
|
|
598
|
+
const c = cos(radians), s = sin(radians);
|
|
599
|
+
v.x = c * v.x - s * v.y;
|
|
600
|
+
v.y = s * v.x + c * v.y;
|
|
601
|
+
return v;
|
|
579
602
|
};
|
|
580
|
-
var
|
|
581
|
-
const
|
|
582
|
-
v
|
|
583
|
-
v.y = sin * v.x + cos * v.y;
|
|
603
|
+
var vecReflect = (v, normal) => {
|
|
604
|
+
const normalCopy = vecNorm(vec(normal));
|
|
605
|
+
return vecSub(v, vecMult(normalCopy, 2 * vecDot(v, normalCopy)));
|
|
584
606
|
};
|
|
585
|
-
var
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
607
|
+
var vecSetMag = (v, value) => {
|
|
608
|
+
vecNorm(v);
|
|
609
|
+
vecMult(v, value);
|
|
610
|
+
return v;
|
|
611
|
+
};
|
|
612
|
+
var vecMag = (v) => sqrt(v.x * v.x + v.y * v.y);
|
|
613
|
+
var vecMag2 = (v) => v.x * v.x + v.y * v.y;
|
|
614
|
+
var vecNorm = (v) => {
|
|
615
|
+
const length = vecMag(v);
|
|
589
616
|
if (length > 0) {
|
|
590
|
-
|
|
617
|
+
vecDiv(v, length);
|
|
591
618
|
}
|
|
619
|
+
return v;
|
|
592
620
|
};
|
|
593
|
-
var
|
|
594
|
-
const sq =
|
|
621
|
+
var vecLimit = (v, max = 1) => {
|
|
622
|
+
const sq = vecMag2(v);
|
|
595
623
|
if (sq > max * max) {
|
|
596
|
-
|
|
597
|
-
|
|
624
|
+
vecDiv(v, sqrt(sq));
|
|
625
|
+
vecMult(v, max);
|
|
598
626
|
}
|
|
627
|
+
return v;
|
|
599
628
|
};
|
|
600
|
-
var
|
|
629
|
+
var vecDist = (a, b) => {
|
|
601
630
|
const dx = a.x - b.x;
|
|
602
631
|
const dy = a.y - b.y;
|
|
603
|
-
return
|
|
632
|
+
return sqrt(dx * dx + dy * dy);
|
|
604
633
|
};
|
|
605
|
-
var
|
|
634
|
+
var vecDist2 = (a, b) => {
|
|
606
635
|
const dx = a.x - b.x;
|
|
607
636
|
const dy = a.y - b.y;
|
|
608
637
|
return dx * dx + dy * dy;
|
|
609
638
|
};
|
|
610
|
-
var
|
|
611
|
-
var
|
|
612
|
-
var
|
|
613
|
-
var
|
|
639
|
+
var vecAngle = (v) => Math.atan2(v.y, v.x);
|
|
640
|
+
var vecDot = (a, b) => a.x * b.x + a.y * b.y;
|
|
641
|
+
var vecCross = (a, b) => a.x * b.y - a.y * b.x;
|
|
642
|
+
var vecLerp = (a, b, t) => {
|
|
614
643
|
a.x += (b.x - a.x) * t || 0;
|
|
615
644
|
a.y += (b.y - a.y) * t || 0;
|
|
645
|
+
return a;
|
|
616
646
|
};
|
|
617
|
-
var
|
|
618
|
-
const angle =
|
|
619
|
-
const radius =
|
|
620
|
-
return vec(
|
|
647
|
+
var vecRand = (minlength = 1, maxlength = minlength, randomFn = globalThis.rand || Math.random) => {
|
|
648
|
+
const angle = randomFn() * PI2;
|
|
649
|
+
const radius = randomFn() * (maxlength - minlength) + minlength;
|
|
650
|
+
return vec(cos(angle) * radius, sin(angle) * radius);
|
|
621
651
|
};
|
|
622
|
-
var
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
652
|
+
var vecAbs = (v) => {
|
|
653
|
+
v.x = Math.abs(v.x);
|
|
654
|
+
v.y = Math.abs(v.y);
|
|
655
|
+
return v;
|
|
656
|
+
};
|
|
657
|
+
var vecCeil = (v) => {
|
|
658
|
+
v.x = Math.ceil(v.x);
|
|
659
|
+
v.y = Math.ceil(v.y);
|
|
660
|
+
return v;
|
|
661
|
+
};
|
|
662
|
+
var vecFloor = (v) => {
|
|
663
|
+
v.x = Math.floor(v.x);
|
|
664
|
+
v.y = Math.floor(v.y);
|
|
665
|
+
return v;
|
|
666
|
+
};
|
|
667
|
+
var vecRound = (v) => {
|
|
668
|
+
v.x = Math.round(v.x);
|
|
669
|
+
v.y = Math.round(v.y);
|
|
670
|
+
return v;
|
|
671
|
+
};
|
|
672
|
+
var vecClamp = (v, min, max) => {
|
|
673
|
+
if (v.x < min.x) v.x = min.x;
|
|
674
|
+
if (v.x > max.x) v.x = max.x;
|
|
675
|
+
if (v.y < min.y) v.y = min.y;
|
|
676
|
+
if (v.y > max.y) v.y = max.y;
|
|
677
|
+
return v;
|
|
627
678
|
};
|
|
679
|
+
var vecMove = (v, to, delta = 1) => vecAdd(v, to.x * delta, to.y * delta);
|
|
680
|
+
var vecIsZero = (v) => vecEq(v, ZERO);
|
|
628
681
|
var ZERO = /* @__PURE__ */ vec(0, 0);
|
|
629
682
|
var ONE = /* @__PURE__ */ vec(1, 1);
|
|
630
683
|
var UP = /* @__PURE__ */ vec(0, -1);
|
|
@@ -661,7 +714,7 @@
|
|
|
661
714
|
constructor(sprite, position, anchor = ANCHOR_TOP_LEFT) {
|
|
662
715
|
this.sprite = sprite;
|
|
663
716
|
this.pos = position || vec(0);
|
|
664
|
-
this._o =
|
|
717
|
+
this._o = vec(anchor);
|
|
665
718
|
this._s = vec(1, 1);
|
|
666
719
|
}
|
|
667
720
|
/**
|
|
@@ -713,6 +766,12 @@
|
|
|
713
766
|
get height() {
|
|
714
767
|
return this.sprite.height * this._s.y;
|
|
715
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* @retuns {Vector}
|
|
771
|
+
*/
|
|
772
|
+
get scale() {
|
|
773
|
+
return this._s;
|
|
774
|
+
}
|
|
716
775
|
/**
|
|
717
776
|
* @returns {number[]}
|
|
718
777
|
*/
|
|
@@ -723,12 +782,6 @@
|
|
|
723
782
|
const y = this.pos.y - h * this.anchor.y;
|
|
724
783
|
return [x, y, w, h];
|
|
725
784
|
}
|
|
726
|
-
/**
|
|
727
|
-
* @retuns {Vector}
|
|
728
|
-
*/
|
|
729
|
-
get scale() {
|
|
730
|
-
return this._s;
|
|
731
|
-
}
|
|
732
785
|
/**
|
|
733
786
|
* Update the transformation matrix, sets the opacity and draw the actor sprite image.
|
|
734
787
|
*
|
package/dist/all.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`)}},
|
|
1
|
+
(()=>{var $=Object.defineProperty;var V=(e,t)=>{for(var s in t)$(e,s,{get:t[s],enumerable:!0})};globalThis.utils=globalThis.utils||{};globalThis.utils.global=()=>{for(let e in globalThis.utils)e!=="global"&&(globalThis[e]=globalThis.utils[e])};var P={};V(P,{ANCHOR_BOT_LEFT:()=>yt,ANCHOR_BOT_RIGHT:()=>mt,ANCHOR_CENTER:()=>gt,ANCHOR_TOP_LEFT:()=>B,ANCHOR_TOP_RIGHT:()=>_t,Actor:()=>D,Camera:()=>u,DOWN:()=>xt,Grid:()=>_,LEFT:()=>dt,ONE:()=>ft,RIGHT:()=>pt,TypedGrid:()=>H,UP:()=>ut,Vector:()=>p,ZERO:()=>L,diff:()=>F,fract:()=>j,intersection:()=>g,range:()=>N,resolve:()=>O,vec:()=>n,vecAbs:()=>ot,vecAdd:()=>b,vecAngle:()=>tt,vecCeil:()=>rt,vecClamp:()=>ht,vecCross:()=>et,vecDist:()=>Q,vecDist2:()=>v,vecDiv:()=>y,vecDot:()=>W,vecEq:()=>M,vecFloor:()=>nt,vecIsZero:()=>lt,vecLerp:()=>st,vecLimit:()=>K,vecMag:()=>z,vecMag2:()=>Y,vecMove:()=>ct,vecMult:()=>x,vecNorm:()=>A,vecRand:()=>it,vecReflect:()=>Z,vecRotate:()=>U,vecRound:()=>at,vecSet:()=>X,vecSetMag:()=>J,vecSub:()=>I,wave:()=>G});var g=(e,t,s,i,o,r,a,h)=>{let c=Math.max(e,o),C=Math.min(e+s,o+a)-c,d=Math.max(t,r),m=Math.min(t+i,r+h)-d;return[c,d,C,m]};var O=(e,t,s,i,o,r,a,h)=>{let[c,C,d,m]=g(e,t,s,i,o,r,a,h),f="",T=e,w=t;return d<m?e<o?(f="right",T=o-s):(f="left",T=o+a):t<r?(f="bottom",w=r-i):(f="top",w=r+h),{direction:f,x:T,y:w}};var u=class{_engine=null;x=0;y=0;ox=0;oy=0;width=0;height=0;rotation=0;scale=1;_shake={x:0,y:0,removeListener:null};constructor(t=null,s=0,i=0,o=null,r=null){this._engine=t||globalThis,this.ox=s,this.oy=i,this.resize(o||this._engine.WIDTH-s,r||this._engine.HEIGHT-i),this.x=this.width/2,this.y=this.height/2}resize(t,s){this.width=t,this.height=s,this._engine.emit("camera-resized",this)}start(t=!1){this._engine.push(),t&&this._engine.cliprect(this.ox,this.oy,this.width,this.height);let s=this.ox+this.width/2,i=this.oy+this.height/2;this._engine.translate(s,i),this._engine.scale(this.scale),this._engine.rotate(this.rotation),this._engine.translate(-this.x+this._shake.x,-this.y+this._shake.y)}end(){this._engine.pop()}lookAt(t,s){this.x=t,this.y=s}move(t,s){this.x+=t,this.y+=s}zoom(t){this.scale*=t}zoomTo(t){this.scale=t}rotate(t){this.rotation+=t}rotateTo(t){this.rotation=t}getWorldPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=Math.sin(-this.rotation);return t=(t-this.width/2-this.ox)/this.scale,s=(s-this.height/2-this.oy)/this.scale,i.x=o*t-r*s+this.x,i.y=r*t+o*s+this.y,i}getCameraPoint(t,s,i={}){let o=Math.cos(-this.rotation),r=Math.sin(-this.rotation);return t=t-this.x,s=s-this.y,t=o*t-r*s,s=r*t+o*s,i.x=t*this.scale+this.width/2+this.ox,i.y=s*this.scale+this.height/2+this.oy,i}getBounds(){return[this.ox,this.oy,this.width,this.height]}viewing(t,s,i,o){let r=this.width/2-this.x,a=this.height/2-this.y,h=this.width/this.scale,c=this.height/this.scale;return this._engine.colrect(t,s,i,o,r,a,h,c)}shake(t=1,s=.3){this.shaking||(this._shake.removeListener=this._engine.listen("update",i=>{this._shake.x=this._engine.randi(-t,t),this._shake.y=this._engine.randi(-t,t),s-=i,s<=0&&this.unshake()}))}unshake(){this.shaking&&(this._shake.removeListener(),this._shake.removeListener=null,this._shake.x=this._shake.y=0)}get shaking(){return this._shake.removeListener!==null}};var _=class e{_w;_h;_c;constructor(t,s,i=[]){this._w=Math.max(1,~~t),this._h=Math.max(1,~~s),this._c=i}clear(){this.forEach((t,s)=>this.set(t,s,void 0))}get width(){return this._w}get height(){return this._h}set(t,s,i){this._c[this.pointToIndex(t,s)]=i}get(t,s){return this._c[this.pointToIndex(t,s)]}has(t,s){return this.get(t,s)!=null}get length(){return this._w*this._h}pointToIndex(t,s){return this.clampX(~~t)+this.clampY(~~s)*this._w}indexToPointX(t){return t%this._w}indexToPointY(t){return Math.floor(t/this._w)}forEach(t,s=!1){let i=s?this.length-1:0,o=s?-1:this.length,r=s?-1:1;for(;i!==o;){let a=this.indexToPointX(i),h=this.indexToPointY(i),c=this._c[i];if(t(a,h,c,this)===!1)break;i+=r}}fill(t){this.forEach((s,i)=>{this.set(s,i,t)})}clone(){return e.fromArray(this._w,this._h,this._c)}clampX(t){return k(t,0,this._w-1)}clampY(t){return k(t,0,this._h-1)}toArray(){return this._c.slice()}toString(t=" ",s=!0){if(!s)return this._c.join(t);let i=[];return this.forEach((o,r,a)=>{i[r]=i[r]||"",i[r]+=a+t}),i.join(`
|
|
2
|
+
`)}},H=class e extends _{constructor(t,s,i=Uint8Array){super(t,s,null),this._c=new i(this._w*this._h)}has(t,s){return this.get(t,s)!==0}clone(){let t=new e(this._w,this._h,this._c.constructor);return this.forEach((s,i,o)=>{t.set(s,i,o)}),t}};function k(e,t,s){return e<t?t:e>s?s:e}var E=Math.sqrt,R=Math.cos,S=Math.sin,q=2*Math.PI,p=class{x;y;constructor(t=0,s=t){this.x=t,this.y=s}toString(){return`Vector (${this.x}, ${this.y})`}},l=e=>e instanceof p,n=(e=0,t=e)=>(l(e)&&(t=e.y,e=e.x),new p(e,t)),M=(e,t,s=t)=>l(t)?M(e,t.x,t.y):e.x===t&&e.y===s,X=(e,t,s=t)=>(l(t)?X(e,t.x,t.y):(e.x=t,e.y=s),e),b=(e,t,s=t)=>l(t)?b(e,t.x,t.y):(e.x+=t,e.y+=s,e),I=(e,t,s=t)=>l(t)?I(e,t.x,t.y):(e.x-=t,e.y-=s,e),x=(e,t,s=t)=>l(t)?x(e,t.x,t.y):(e.x*=t,e.y*=s,e),y=(e,t,s=t)=>l(t)?y(e,t.x,t.y):(e.x/=t,e.y/=s,e),U=(e,t)=>{let s=R(t),i=S(t);return e.x=s*e.x-i*e.y,e.y=i*e.x+s*e.y,e},Z=(e,t)=>{let s=A(n(t));return I(e,x(s,2*W(e,s)))},J=(e,t)=>(A(e),x(e,t),e),z=e=>E(e.x*e.x+e.y*e.y),Y=e=>e.x*e.x+e.y*e.y,A=e=>{let t=z(e);return t>0&&y(e,t),e},K=(e,t=1)=>{let s=Y(e);return s>t*t&&(y(e,E(s)),x(e,t)),e},Q=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return E(s*s+i*i)},v=(e,t)=>{let s=e.x-t.x,i=e.y-t.y;return s*s+i*i},tt=e=>Math.atan2(e.y,e.x),W=(e,t)=>e.x*t.x+e.y*t.y,et=(e,t)=>e.x*t.y-e.y*t.x,st=(e,t,s)=>(e.x+=(t.x-e.x)*s||0,e.y+=(t.y-e.y)*s||0,e),it=(e=1,t=e,s=globalThis.rand||Math.random)=>{let i=s()*q,o=s()*(t-e)+e;return n(R(i)*o,S(i)*o)},ot=e=>(e.x=Math.abs(e.x),e.y=Math.abs(e.y),e),rt=e=>(e.x=Math.ceil(e.x),e.y=Math.ceil(e.y),e),nt=e=>(e.x=Math.floor(e.x),e.y=Math.floor(e.y),e),at=e=>(e.x=Math.round(e.x),e.y=Math.round(e.y),e),ht=(e,t,s)=>(e.x<t.x&&(e.x=t.x),e.x>s.x&&(e.x=s.x),e.y<t.y&&(e.y=t.y),e.y>s.y&&(e.y=s.y),e),ct=(e,t,s=1)=>b(e,t.x*s,t.y*s),lt=e=>M(e,L),L=n(0,0),ft=n(1,1),ut=n(0,-1),pt=n(1,0),xt=n(0,1),dt=n(-1,0);var gt=n(.5,.5),B=n(0,0),_t=n(1,0),yt=n(0,1),mt=n(1,1),D=class{sprite;pos;_o;_s;angle=0;opacity=1;hidden=!1;constructor(t,s,i=B){this.sprite=t,this.pos=s||n(0),this._o=n(i),this._s=n(1,1)}set x(t){this.pos.x=t}get x(){return this.pos.x}set y(t){this.pos.y=t}get y(){return this.pos.y}set anchor(t){this._o.x=t.x,this._o.y=t.y}get anchor(){return this._o}get width(){return this.sprite.width*this._s.x}get height(){return this.sprite.height*this._s.y}get scale(){return this._s}getBounds(t=!0){let s=this.sprite.width*(t?this._s.x:1),i=this.sprite.height*(t?this._s.y:1),o=this.pos.x-s*this.anchor.x,r=this.pos.y-i*this.anchor.y;return[o,r,s,i]}draw(t=globalThis){this.hidden||this.opacity<=0||(t.push(),this.transform(t),this.drawImage(t),t.pop())}transform(t){t.translate(this.pos.x,this.pos.y),t.rotate(this.angle),t.scale(this._s.x,this._s.y)}drawImage(t){let s=this.sprite.width*this.anchor.x,i=this.sprite.height*this.anchor.y;t.alpha(this.opacity),t.image(-s,-i,this.sprite)}};var F=(e,t)=>Math.abs(t-e)||0;var G=(e,t,s,i=Math.sin)=>e+(i(s)+1)/2*(t-e);var j=e=>e%1||0;var N=e=>Array.from(Array(e).keys());globalThis.utils=Object.assign(globalThis.utils||{},P);})();
|