top of page
Search
cedarcantab

Danmaku using Phaser 3 (lesson 40 part 5): Number of Parallel Cannons as Arrays

Updated: Dec 10, 2021

Just as I was about to close off the current series of accepting various danmaku properties as arrays, I remembered another property that could do with accepting arrays - this.danmakuCountB, which is used to set the number of cannons per "PARALLEL" line of cannons at the end of each Nway spoke.



Accepting this.danmakuCountB as arrays

CountB is the parameter used to the number of cannons for each of the parallel set of cannons at the end of each nway spoke. By utilising the readParam function, the required functionality to accept arrays for this paramter is straightforward, requiring only a slight modification to the danmakuSpokes function. Specifically, the red highlighted sections are the amended code.


  // do a bit more processing for PARALLEL and BI-DIRECTIONAL danmaku
  switch (danmakuType) {
    case "PARALLEL":
      const line = createLine(0, width); 
      directions.forEach((angle, i) => {
        const shift = new Phaser.Math.Vector2(vOffset, hOffset).rotate(angle);
        for (let j =0; j < readParam(numberOfPoints,i); j++) {
          const point = line.getPoint(j / (readParam(numberOfPoints,i) - 1)).rotate(angle).add(shift);
          originsArray.push(point);
          spokesArray.push(angle);
        }
      });
      break;  

width, vOffset and hOffset

I have also amended the section of the code that calls the danmakuSpokes function from fireShot method, so that arrays can be passed for this.danmakuWidth, this.danmakuVOffset and this.danmakuHOffset. For the moment I cannot think of a creative enough danmaku to illustrate the usefulness of this change.


   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: this.danmakuAOffset,
      width: readParam(this.danmakuWidth, this.danmakuCounter),
      spokesArray: cannonIndex,
      originsArray: cannonOrigin
    });

Simulating Toho's famous bullet hell patterns

In lesson 37, after the major re-write of the Nway code, I attempted to simulate one of the famous Toho bullet hell patterns. Specifically the spell card in question was 秘弾 「そして誰もいなくなるか?」from the game 東方紅魔郷. I soon realised that I could not implement one important aspect of the game which was that the number of bullets criss-crossing were different - this made quite a big change to the visual effect - impact, it made the pattern quite unpleasant when the bullets crossed each other.


Now with the ability to set this.danmakuCountB as an array, I can overcome the limitation and create a closer imitation with the following parameter set. If you look carefully at the generated danmaku pattern at the top of this page, you will note that the number of bullets flying from the bottom and the top are different; hence they fly "past" each other, as opposed to "overlap" each otehr.


  danmakuPattern.push({
    name: "x10 PARALLE BULLETS SHOOTING UP FROM ALL SIDES",
    danmakuConfig: {
      countA: 4, // 2 cannons (ie 2-way)
      type: "PARALLEL", countB: [10,10,9,9], // 15 parallel cannons at end of each of the 2-way spokes
      vOffset: -WIDTH/2+10,
      width: 500,
    },
    cannonConfig: {
      shotType: "OVERTAKE", acceleration: 20,
      numberOfShots: 2,
      stopShotsTime: 8000,
      fireRate: 100, // time between bullets in ms
    },
    bulletConfig: {
      speed: 50,
      texture: "roundMID", frame: 5
    },
  });

And that's it. Here is the CodePen, if you are interested to see what I have done.




3 views0 comments

Recent Posts

See All

p2 naive broadphase

var Broadphase = require('../collision/Broadphase'); module.exports = NaiveBroadphase; /** * Naive broadphase implementation. Does N^2...

sopiro motor constranit

import { Matrix2, Vector2 } from "./math.js"; import { RigidBody } from "./rigidbody.js"; import { Settings } from "./settings.js";...

Comments


記事: Blog2_Post
bottom of page