top of page
Search
cedarcantab

Danmaku using Phaser 3 (lesson 40 part 6): Angle Offset as Arrays


We continue our series of accepting arrays as parameters - in this post, it is the angle offset paramter.



Changing the angle of the primary cannon with angle offset

In part 2 of this series, I made quite substantial changes in order to accept arrays for the angle range parameter. Conceptually it would make sense to be able to pass arrays for the this.danmakuAngle parameter, which controls the angle of the primary cannon. However, this parameter is accessed by so many different parts of the code so fiddling with that would have required a fundamental re-write. Then I remembered there is an parameter to optionally "rotate" the entire nway; used just for the GAP-CIRCLE danmaku (where we set the this.danmakuAOffset to PI/2 in order to flip it upside down. Playing around with this code is easy.


As with the other parameters, the key is to use the readParam function to read the parameter which may be passed as a single number of an array.

   danmakuSpokes({
      danmakuType: this.danmakuType,
      heading: this.referenceAngle,
      vOffset: readParam(this.danmakuVOffset, this.danmakuCounter),
      hOffset: readParam(this.danmakuHOffset, this.danmakuCounter),
      cannonsInNway: readParam(this.danmakuCountA,this.danmakuCounter),
      nwayRange: this.cannonAngleRangeRef,
      numberOfPoints: this.danmakuCountB, // number of cannons in PARALLEL      
      nways: this.danmakuMultiple, totalRange: this.danmakuAngleRange,
      offset: readParam(this.danmakuAOffset,this.danmakuCounter),
      width: this.danmakuWidth,
      spokesArray: cannonIndex,
      originsArray: cannonOrigin
    });

With angle related parameters though if they are arrays they need to be "preprocessed", ie the array elements need to be converted to radians from degrees, with the following code in the setProperties method.

if (Array.isArray(danmakuConfig.aOffset)) {
      this.danmakuAOffset = danmakuConfig.aOffset.map(x=>Phaser.Math.DegToRad(x));
    } else {
      this.danmakuAOffset = Phaser.Math.DegToRad(danmakuConfig.aOffset) || 0;
    }

And that's it.


The danmaku at the top of the page was created with the following parameter set.


  danmakuPattern.push({
    name: "20-WAY OFFSET ANGLE MULTI-COLOR",
    danmakuConfig: {
      countA: 20,
      angle: 90, aOffset: [0,9],
    },
    cannonConfig: {
      numberOfShots: 5,
      stopShotsTime: 2000,
      fireRate: 500,
   },
    bulletConfig: {
      class: "NORMAL" ,
      speed: 50,
      texture: "ribbonMID", frame: [4,5],
    },
  });  

The CodePen is available below for your perusal and comment.




Commenti


記事: Blog2_Post
bottom of page