top of page
Search
cedarcantab

Side Note: Cycling through the Danmaku Patterns

Updated: Oct 2, 2021

Having spent the last post substantially re-writing the code, I was going to code a new danmaku pattern. But then, I thought it would be interesting to be able to cycle through different danmaku patterns, by taking advantage of the functionality to configure danmaku object, that I built in the last post. I could simply store a variety of danmaku configuration parameters in an array, and cycle through them, perhaps at the push of the Return button. Should be straightforward.



In reality, the exercise revealed a lot of problems in the code that required more "clean up".


Method to "reset" a live danmaku

In the previous version of the code, I had build a "reset" functionality into the "setProperties" method. However, as I was building on the cycling through patterns demo, splitting the setting up of properties and "erasing" the properties into 2 different functions felt more intuitive, and slightly easier to read.


Triggering mechanism for danmaku

For the aske of this demo, the danmaku is endless. I have re-jigged the code so that the endless timer event is set up automatically if the loop property is set to -1, hence no need to manually call the triggerRepeatFire method. For the player, we will call the trigger RepeatFire method. The bits and bobs for the intermittent firing mechanism has been removed in its entirely since it was getting too confusing. This is something that will be re-written in the future.


Setting up the array of cannon angles for N-way

There is a convoluted code for setting up an array of cannon angles for N-Way, involving number of if-statements. Although the logic has not been changed, I have moved the entire code to a separate function.

Sound parameter now included as danamku object property

The sound effect when bullets are shot are now included as a property of the danmaku object. If nothing is set, then no sound will play. It means you can implement different shooting sound effects for each danmaku class (or enemy type).


As with pretty much every post, I have changed the name of some properties, the most important one being the amendment of angleVelocity to angularVelocity. This is simply to make it more consistent with the Phaser naming convention.


For this demo, I have got rid of the explosion effects because it was too distracting when viewing the more intense danmaku patterns.


Killing of bullets off screen

I have changed the code to get rid of bullets that have flown off screen. Until now, I used to use a collider event to get rid of the bullet. However that meant that a bullet would disappear as soon as it hit the screen, ie before it was fully outside the screen. I have got rid of the collider event, and instead I now check whether a bullet is completely outside the screen in the preUpdate loop, and then disable it.

preUpdate(time, delta) {
    if (this.outOfScreen(this)) {
      this.disableBody(true, true);
    }

The function to check whether a bullet is out of the screen is below (strictly speaking, we should add or subtract half the display width/height in the criteria).

outOfScreen(bullet) {
    return (
      bullet.x < 0 || bullet.x > WIDTH || bullet.y < 0 || bullet.y > HEIGHT
    );
  } // function to detect when bullet out of screen area

At the same time, I have increased the size of the enemy bullet pool to 1000


Trigger to cycle through the danmaku patterns


Anyway, in the end I got the demo working. By clicking on the "<<PREV" and "NEXT>>" buttons on the top half of the screen, you can cycle through the following danmaku patterns, all of which have been covered in prior posts (but the underlying code now looks very different from the one at the beginning of these series):


  1. Directional

  2. Aiming Directional

  3. Directional With Accelerating Bullets

  4. Directional With Decelerating Bullets

  5. Aiming Directional With Accelerating Bullets

  6. Right Spiral

  7. Left Spiral (Tight)

  8. Right Multiple Spiral

  9. Left Multiple Spiral With Accelerating Bullets

  10. Single Right Spiral With Bending Bullets

  11. Single Left Spiral With Accelerating Bending Bullets

  12. Right Multi-Spiral With Bending Bullets

  13. Bi-Directional Multiple Spiral

  14. 7-Way

  15. 8-Way With Decelerating Bullets

  16. 6-Way With Reversing Bullets

  17. 7-Way Circle

  18. 32-Way Circle

  19. 32-Way Gap Circle

  20. 32-Way Circle With Bending Bullets

  21. 32-Way Circle With Accelerating Bending Bullets

  22. 64-Way Semi-Circle

  23. Aiming 9-Way

  24. 10-Way Randomised

  25. Rolling 5-Way

  26. Rolling 16-Way Circle

  27. Waving 5-Way

  28. Waving 8-Way Circle

As always the CodePen is available here, for your perusal and comment.




Bình luận

Không thể tải bình luận
Có vẻ như đã có sự cố kỹ thuật. Hãy thử kết nối lại hoặc làm mới trang.
記事: Blog2_Post
bottom of page