@@ -80,33 +80,29 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
80
80
/**
81
81
* The parent sprite of this weapon. Only accessible when `fireFrom == PARENT`.
82
82
*/
83
- public var parent (default , null ): FlxSprite ;
83
+ @:deprecated (" use FlxWeaponFireFrom.PARENT's parent param, instead" )
84
+ public var parent (get , set ): FlxSprite ;
84
85
85
86
/**
86
87
* Whether to fire bullets in the direction of the `parent`'s angle. Only accessible when `fireFrom == PARENT`.
87
88
*/
88
- public var useParentDirection (default , set ): Bool ;
89
+ @:deprecated (" use FlxWeaponFireFrom.PARENT's useParentAngle param, instead" )
90
+ public var useParentDirection (get , set ): Bool ;
89
91
90
92
/**
91
93
* A fixed position from which to fire the weapon, like in the game Missile Command. Only accessible when `fireFrom == POSITION`.
92
94
*/
93
- public var firePosition (default , null ): FlxBounds <FlxPoint >;
95
+ @:deprecated (" use FlxWeaponFireFrom.PARENT's useParentAngle param, instead" )
96
+ public var firePosition (get , set ): FlxBounds <FlxPoint >;
94
97
95
98
/**
96
99
* A value used to offset a bullet's position when it is fired. Can be used to, for example, line a bullet up with the "nose" of a space ship.
97
100
* Only accessible when `fireFrom == PARENT`.
98
101
*/
99
- @:deprecated (" Use positionOffsetBounds instead" )
100
- public var positionOffset (default , null ): FlxPoint ;
102
+ @:deprecated (" use FlxWeaponFireFrom.PARENT's offset param, instead" )
103
+ public var positionOffset (get , set ): FlxPoint ;
101
104
102
- /**
103
- * A value used to offset a bullet's position when it is fired. Can be used to, for example,
104
- * line a bullet up with the "nose" of a space ship. Only accessible when `fireFrom == PARENT`.
105
- * @since 3.2.0
106
- */
107
- public var positionOffsetBounds (default , null ): FlxBounds <FlxPoint >;
108
-
109
- public var fireFrom (default , set ): FlxWeaponFireFrom ;
105
+ public var fireFrom : FlxWeaponFireFrom ;
110
106
public var speedMode : FlxWeaponSpeedMode ;
111
107
112
108
/**
@@ -223,9 +219,14 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
223
219
// Clear any velocity that may have been previously set from the pool
224
220
currentBullet .velocity .zero (); // TODO is this really necessary?
225
221
222
+ final parentAngleOffset : Float = null
223
+ final parent : FlxSprite = null ;
224
+
226
225
switch (fireFrom )
227
226
{
228
- case PARENT (parent , offset , useParentAngle , angleOffset ):
227
+ case PARENT (enumParent , offset , useParentAngle , angleOffset ):
228
+ parent = enumParent ;
229
+ parentAngleOffset = angleOffset ;
229
230
// store new offset in a new variable
230
231
var actualOffset = FlxPoint .get (FlxG .random .float (offset .min .x , offset .max .x ), FlxG .random .float (offset .min .y , offset .max .y ));
231
232
if (useParentAngle )
@@ -253,6 +254,9 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
253
254
currentBullet .elasticity = bulletElasticity ;
254
255
currentBullet .lifespan = FlxG .random .float (bulletLifeSpan .min , bulletLifeSpan .max );
255
256
257
+ inline function randomFloat (range : FlxBounds <Float >)
258
+ return FlxG .random .float (range .min , range .max );
259
+
256
260
switch (mode )
257
261
{
258
262
case FIRE_AT_POSITION (x , y ):
@@ -262,13 +266,25 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
262
266
internalFireAtPoint (currentBullet , target .getPosition (FlxPoint .weak ()));
263
267
264
268
case FIRE_FROM_ANGLE (angle ):
265
- internalFireFromAngle (currentBullet , FlxG . random . float (angle . min , angle . max ));
269
+ internalFireFromAngle (currentBullet , randomFloat (angle ));
266
270
267
- case FIRE_FROM_PARENT_ANGLE (angle ):
268
- internalFireFromAngle (currentBullet , parent .angle + FlxG .random .float (angle .min , angle .max ));
271
+ case FIRE_FROM_PARENT_ANGLE (angleNoise ):
272
+ if (parent != null )
273
+ {
274
+ final angleOffset = parentAngleOffset + (angleNoise == null ? 0 : randomFloat (angleNoise ));
275
+ internalFireFromAngle (currentBullet , parent .angle + angleOffset );
276
+ }
277
+ else
278
+ FlxG .log .warn (" cannot use fireFromParentAngle" );
269
279
270
- case FIRE_FROM_PARENT_FACING (angle ):
271
- internalFireFromAngle (currentBullet , parent .facing .degrees + FlxG .random .float (angle .min , angle .max ));
280
+ case FIRE_FROM_PARENT_FACING (angleNoise ):
281
+ if (parent != null )
282
+ {
283
+ final angleOffset = parentAngleOffset + (angleNoise == null ? 0 : randomFloat (angleNoise ));
284
+ internalFireFromAngle (currentBullet , parent .facing .degrees + angleOffset );
285
+ }
286
+ else
287
+ FlxG .log .warn (" cannot use fireFromParentFacing" );
272
288
273
289
#if FLX_TOUCH
274
290
case FIRE_AT_TOUCH (touch ):
@@ -414,7 +430,7 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
414
430
* @return `true` if a bullet was fired, or `false` if one wasn't available.
415
431
* A reference to the last fired bullet is stored in `currentBullet`.
416
432
*/
417
- public inline function fireFromParentAngle (angle : FlxBounds <Float >): Bool
433
+ public inline function fireFromParentAngle (? angle : FlxBounds <Float >): Bool
418
434
{
419
435
return runFire (FIRE_FROM_PARENT_ANGLE (angle ));
420
436
}
@@ -461,9 +477,15 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
461
477
462
478
function shouldBulletHit (object : FlxObject , bullet : FlxObject ): Bool
463
479
{
464
- if (parent == object && skipParentCollision )
480
+ if (skipParentCollision )
465
481
{
466
- return false ;
482
+ switch (fireFrom )
483
+ {
484
+ case PARENT (parent , _ , _ , _ ):
485
+ if (parent == object )
486
+ return false ;
487
+ default :
488
+ }
467
489
}
468
490
469
491
if ((object is FlxTilemap ))
@@ -529,39 +551,21 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
529
551
name = null ;
530
552
group = FlxDestroyUtil .destroy (group );
531
553
bounds = FlxDestroyUtil .put (bounds );
532
- parent = null ; // Don't destroy the parent
533
- positionOffset = FlxDestroyUtil .put (positionOffset );
534
- if (positionOffsetBounds != null )
535
- {
536
- positionOffsetBounds .min = FlxDestroyUtil .put (positionOffsetBounds .min );
537
- positionOffsetBounds .max = FlxDestroyUtil .put (positionOffsetBounds .max );
538
- positionOffsetBounds = null ;
539
- }
540
- if (firePosition != null )
541
- {
542
- firePosition .min = FlxDestroyUtil .put (firePosition .min );
543
- firePosition .max = FlxDestroyUtil .put (firePosition .max );
544
- firePosition = null ;
545
- }
546
554
if (fireFrom != null )
547
555
{
548
556
switch (fireFrom )
549
557
{
550
558
case PARENT (parent , offset , useParentAngle , angleOffset ):
551
- parent = null ;
552
559
if (offset != null )
553
560
{
554
561
offset .min = FlxDestroyUtil .put (offset .min );
555
562
offset .max = FlxDestroyUtil .put (offset .max );
556
- offset = null ;
557
563
}
558
- angleOffset = null ;
559
564
case POSITION (position ):
560
565
if (position != null )
561
566
{
562
567
position .min = FlxDestroyUtil .put (position .min );
563
568
position .max = FlxDestroyUtil .put (position .max );
564
- position = null ;
565
569
}
566
570
}
567
571
// fireFrom = null; // Can't do this because sending null to set_fireFrom() causes an NPE
@@ -588,45 +592,89 @@ class FlxTypedWeapon<TBullet:FlxBullet> implements IFlxDestroyable
588
592
bulletFactory = null ;
589
593
}
590
594
591
- function set_useParentDirection (v : Bool ): Bool
595
+ function get_parent (): FlxSprite
596
+ {
597
+ return switch (fireFrom )
598
+ {
599
+ case PARENT (parent , _ , _ , _ ):parent ;
600
+ default : null ;
601
+ }
602
+ }
603
+
604
+ function set_parent (value : FlxSprite ): FlxSprite
592
605
{
593
606
switch (fireFrom )
594
607
{
595
- case PARENT (parent , offset , useParentAngle , angleOffset ):
596
- @ :bypassAccessor fireFrom = PARENT (parent , offset , v , angleOffset );
608
+ case PARENT (_ , offset , useParentAngle , angleOffset ):
609
+ fireFrom = PARENT (value , offset , useParentAngle , angleOffset );
597
610
default :
611
+ FlxG .log .warn (" Cannot set parent unless fireFrom is PARENT" );
598
612
}
599
- return v ;
613
+ return value ;
600
614
}
601
615
602
- function set_fireFrom ( v : FlxWeaponFireFrom ) : FlxWeaponFireFrom
616
+ function get_useParentDirection () : Bool
603
617
{
604
- switch (v )
618
+ switch (fireFrom )
605
619
{
606
- case PARENT (parent , offset , useParentAngle , angleOffset ):
607
- this .parent = parent ;
608
- // this.positionOffset = offset;
609
- this .positionOffsetBounds = offset ;
610
- this .useParentDirection = useParentAngle ;
611
- if (angleOffset != null )
612
- this .angleOffset = angleOffset ;
620
+ case PARENT (_ , _ , useParentAngle , _ ):
621
+ return useParentAngle ;
622
+ default :
623
+ return null ;
624
+ }
625
+ }
626
+
627
+ function set_useParentDirection (value : Bool ): Bool
628
+ {
629
+ switch (fireFrom )
630
+ {
631
+ case PARENT (parent , offset , _ , angleOffset ):
632
+ fireFrom = PARENT (parent , offset , value , angleOffset );
633
+ default :
634
+ FlxG .log .warn (" Cannot set useParentDirection unless fireFrom is PARENT" );
635
+ }
636
+ return value ;
637
+ }
613
638
614
- this .firePosition = null ;
615
639
640
+ function get_positionOffset (): FlxPoint
641
+ {
642
+ switch (fireFrom )
643
+ {
616
644
case POSITION (position ):
617
- this .firePosition = position ;
645
+ return position .min ;
646
+ default :
647
+ return null ;
648
+ }
649
+ }
618
650
619
- this .parent = null ;
620
- this .positionOffset = null ;
621
- this .positionOffsetBounds = null ;
651
+ function set_positionOffset (value : FlxPoint ): FlxPoint
652
+ {
653
+ switch (fireFrom )
654
+ {
655
+ case PARENT (parent , _ , useParentAngle , angleOffset ):
656
+ fireFrom = PARENT (parent , new FlxBounds (value , value ), useParentAngle , angleOffset );
657
+ default :
658
+ FlxG .log .warn (" Cannot set positionOffset unless fireFrom is PARENT" );
659
+ }
660
+ return value ;
661
+ }
622
662
663
+ function get_firePosition (): FlxBounds <FlxPoint >
664
+ {
665
+ switch (fireFrom )
666
+ {
667
+ case POSITION (position ):
668
+ return position ;
623
669
default :
624
- this .parent = null ;
625
- this .positionOffset = null ;
626
- this .positionOffsetBounds = null ;
627
- this .firePosition = null ;
670
+ return null ;
628
671
}
629
- return fireFrom = v ;
672
+ }
673
+
674
+ function set_firePosition (value : FlxBounds <FlxPoint >): FlxBounds <FlxPoint >
675
+ {
676
+ fireFrom = POSITION (value );
677
+ return value ;
630
678
}
631
679
}
632
680
@@ -653,8 +701,8 @@ enum FlxWeaponFireMode
653
701
FIRE_AT_POSITION (x : Float , y : Float );
654
702
FIRE_AT_TARGET (target : FlxSprite );
655
703
FIRE_FROM_ANGLE (angle : FlxBounds <Float >);
656
- FIRE_FROM_PARENT_ANGLE (angleNoise : FlxBounds <Float >);
657
- FIRE_FROM_PARENT_FACING (angleNoise : FlxBounds <Float >);
704
+ FIRE_FROM_PARENT_ANGLE (? angleNoise : FlxBounds <Float >);
705
+ FIRE_FROM_PARENT_FACING (? angleNoise : FlxBounds <Float >);
658
706
659
707
#if FLX_TOUCH
660
708
FIRE_AT_TOUCH (touch : FlxTouch );
0 commit comments