Maliki79

MalRainbowEnemies

Aug 23rd, 2025 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Tag enemies with <rainbow> to allow color hue cycleing in battle
  2.  
  3. var RainbowHueInterval = 3;  
  4. var RainbowHueStep = 2;      
  5.  
  6.  
  7. var _Sprite_Enemy_update = Sprite_Enemy.prototype.update;
  8. Sprite_Enemy.prototype.update = function() {
  9.     _Sprite_Enemy_update.call(this);
  10.  
  11. if (this._enemy && this._enemy.isRainbowEnemy()) {
  12.     if (!this._enemy._rainbowFrame) this._enemy._rainbowFrame = 0;
  13.     this._enemy._rainbowFrame++;
  14.     if (this._enemy._rainbowFrame >= RainbowHueInterval) {
  15.         this._enemy._rainbowFrame = 0;
  16.         this._enemy.testColor = (this._enemy.testColor + RainbowHueStep) % 360;
  17.         this.setHue(this._enemy.testColor);
  18.     }
  19. }
  20. };
  21.  
  22. var _Game_Enemy_initMembers = Game_Enemy.prototype.initMembers;
  23. Game_Enemy.prototype.initMembers = function() {
  24.     _Game_Enemy_initMembers.call(this);
  25.     this.testColor = Math.randomInt(360);
  26.     this._rainbowFrame = 0;
  27. };
  28.  
  29. Game_Enemy.prototype.battlerHue = function() {
  30.     return this.enemy().battlerHue;
  31. };
  32.  
  33. Game_Enemy.prototype.isRainbowEnemy = function() {
  34.     return !!$dataEnemies[this.enemy().id].meta.rainbow;
  35. };
  36.  
  37. Sprite_Enemy.prototype.setHue = function(deg) {
  38.     if (!this._rainbowColorMatrix) {
  39.         if (PIXI && PIXI.filters && PIXI.filters.ColorMatrixFilter) {
  40.             this._rainbowColorMatrix = new PIXI.filters.ColorMatrixFilter();
  41.             var list = this.filters ? this.filters.slice() : [];
  42.             list.push(this._rainbowColorMatrix);
  43.             this.filters = list;
  44.         } else {
  45.             this._rainbowColorMatrix = null;
  46.         }
  47.     }
  48.  
  49.     if (this._rainbowColorMatrix) {
  50.         this._rainbowColorMatrix.reset();
  51.         this._rainbowColorMatrix.hue(deg, false);
  52.     } else {
  53.         var rad = deg * Math.PI / 180;
  54.         var r = Math.round(60 * Math.sin(rad));
  55.         var b = Math.round(60 * Math.cos(rad));
  56.         this.setColorTone([ r, -r,  b, 0 ]);
  57.     }
  58. };
  59.  
  60. Sprite_Enemy.prototype.clearRainbowHue = function() {
  61.     if (this._rainbowColorMatrix) {
  62.         var list = (this.filters || []).filter(f => f !== this._rainbowColorMatrix);
  63.         this.filters = list.length ? list : null;
  64.         this._rainbowColorMatrix = null;
  65.     } else {
  66.         this.setColorTone([0,0,0,0]);
  67.     }
  68. };
  69.  
Advertisement
Add Comment
Please, Sign In to add comment