ishikyo

ONI
Member
Joined
Sep 15, 2016
Messages
2
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
Hello, I'm using this two scripts:

TerraxLighting
GALV_DiagonalMovement

And I'd like to know if there is a way to make the light of the flashlight face diagonal when the sprite is facing diagonal. I need this because I have a diagonal charset and the flashlight effect is very important on my game, but it looks weird when the character turn diagonal and the light is still straight up/down/left/right.

 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
149
Reaction score
173
First Language
Danish
Primarily Uses
RMMV
I did not play around too much with TerraxLighting and honestly I don't know the proper way to make a flashlight follow the player around. So in my tests the movement was a bit chunky.

Anyway, I made this. To use it just add the following script to the event that handles the flashlight's movement:
Code:
this._direction = $gamePlayer._diagDir ? $gamePlayer._diagDir : $gamePlayer._direction;
This will change it to face the same direction as the player.

If you have any problems with this plugin feel free to message me. :)

Code:
//=============================================================================
// Diagnoal Movement with TerraxLighting
// MRP_GALV_DiagonalMovement_TerraxLighting.js
// By Magnus0808 || Magnus Rubin Peterson
//=============================================================================

/*:
 * @plugindesc Allows for diagional facing flashlight.
 * @author Magnus0808
 *
 * @help In the event that handles the flashlight add the following script to
 * its movement:
 *
 *        this._direction = $gamePlayer._diagDir ? $gamePlayer._diagDir : $gamePlayer._direction;
 *
 * This will change it to face in the same direction as the player.
 */
 (function(){
  
    var flashlightoffset = Number(PluginManager.parameters('TerraxLighting')['Flashlight offset'] || 0);
  
    Bitmap.prototype.radialgradientFillRect2 = function(x1, y1, r1, r2, color1, color2, direction, flashlength, flashwidth) {
        x1=x1+20;

        var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
        if (!isValidColor) {
            color1 = '#000000'
        }
        var isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
        if (!isValidColor2) {
            color2 = '#000000'
        }

        var context = this._context;
        var grad; 
      
        // smal dim glove around player
           context.save();
        y1 = y1 - flashlightoffset;
      
        r1 = 1;
          r2 = 40;
        grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
        grad.addColorStop(0, '#999999');
        grad.addColorStop(1, color2);
  
        context.fillStyle = grad;
        context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
      
        // flashlight
      
        for (var cone = 0; cone < flashlength; cone++) {
            var flashlightdensity =  $gameVariables.GetFlashlightDensity();
               r1 = cone * flashlightdensity;
              r2 = cone * flashwidth;
            
            console.log(direction);
              switch(direction) {
                case 1:
                    x1 = x1 - cone*4.24;
                    y1 = y1 + cone*4.24;
                    break;
                case 3:
                    x1 = x1 + cone*4.24;
                    y1 = y1 + cone*4.24;
                    break;
                case 7:
                    x1 = x1 - cone*4.24;
                    y1 = y1 - cone*4.24;
                    break;
                case 9:
                    x1 = x1 + cone*4.24;
                    y1 = y1 - cone*4.24;
                    break;
                case 6:
                    x1 = x1 + cone*6;
                       break;
                   case 4:
                       x1 = x1 - cone*6;
                       break;
                   case 2:
                       y1 = y1 + cone*6;
                       break;
                case 8:
                    y1 = y1 - cone*6;
                       break;
            }
                      

              grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
            grad.addColorStop(0, color1);
            grad.addColorStop(1, color2);
  
            context.fillStyle = grad;
            context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
        }
        context.fillStyle = grad;
        context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
      
        context.restore();     
        this._setDirty();
    };
  
 })();
 

Attachments

  • MRP_GALV_DiagonalMovement_TerraxLighting.js
    2.8 KB · Views: 7

MadMaurix

Villager
Member
Joined
Apr 4, 2018
Messages
5
Reaction score
0
First Language
Español
Primarily Uses
RMMV
Hi, how i make this work with the player?
 

Latest Threads

Latest Profile Posts

I find great satisfaction in smiting spambots. I'm not really sure why.
I finally added my newly updated demo back to the website! It only took like 4 weeks of work...
Where is the "world-weary sigh" comment response when you need it? I need that one more than anything, but the closest we have is "wow" or "angry".
My apologies if it's out-of-place for my goyim-lookin' ass to be the one to say it, but the mythology of "Golems" is that they were created by Rabbis to protect Jewish villages from Anti-semetic attacks.

Forum statistics

Threads
107,775
Messages
1,032,064
Members
139,919
Latest member
cabanacatalogs
Top