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
121
Reaction score
124
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

Thinking about picking up Luna Engine, but also wondering if I should wait to see if it goes on sale.
So looks like the last Star Wars movie sucked. We feared George would kill his own legacy after Episode 1. But look like he handed off to others to put it out of its misery. Does that count as assisted suicide?
Brother made thumbnails for my Lets Plays. He's a swood dude.
Since I'm getting so busy (the fact that I'm often here is due to the fact that this is my procrastination #1 destination), I'm trying a new system where everyday I dedicate 30 minutes to my personal game project. That way it won't fall into the abyss.

Forum statistics

Threads
93,701
Messages
914,773
Members
123,305
Latest member
Marsa16
Top