Diagonal Flashlight

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
138
Reaction score
148
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

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?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Turns out 4 layers is A LOT.
I noticed random Japanese dialogue in the FF7 remake while playing in English. More than once. Just now I saved a vid where Tifa spoke Japanese after a battle. We all make mistakes lol, this is kinda funny though
I wonder if the new RPG Maker will have a built-in ABS for maps or a light effect system plugin out of the box.
Not having false expectations, but if it has both, then wow. I am gonna party all night. Nah I lie. I will party all night anyway, just searching for a good excuse. :stickytongue:
And BAM!, the moment you do understand Python setters by studying JS prototypes. That's called SERENDIPITY, coming with something when you was searching for something else. From "The three Princes of Serendib", a persian novel.
The sinking feeling when you realize your grandmother probably isn't long for this world, and the frustration when you know that this pandemic will take her away...not because she has Covid, but because no doctor is willing to see a patient to even run simple diagnostics anymore if one of her symptoms happens to be a recurring fever, even if her primary care physician gives her the test and it comes back negative.

Forum statistics

Threads
99,618
Messages
967,360
Members
131,293
Latest member
florencesnow
Top