Sunrays (eye candy for good mappers)

Draws triangles on the screen of random sizes/opacities and fades them in & out. I made it for an underwater area, but the moonlight weather effects from Warcraft 3 are fairly similar if you've played that.

Here are some screenshots on really bad maps. You are not supposed to use this script on a bad map, they are examples to show you why. :P

Screenshots Spoiler
http://www.gamebaker.com/junk/sunray4.bmp[/IMG]http://www.gamebaker.com/junk/sunray2.bmp[/IMG]http://www.gamebaker.com/junk/sunray1.bmp[/IMG]
^ It looks a lot better on the flowers & over the rocks. Used badly on purpose, don't do this. :)


Works best when they are subtle. Not recommended with panoramas or enclosed spaces unless you integrate it into Spriteset_Map and play with z coordinates/priorities. I won't help you with that, but it's not difficult if you know how. :)

Instructions Spoiler
Sunray.create (uses default RGB settings at top of script)
Sunray.create(R,G,B)

To create a sunray, use parallel process events:

http://www.gamebaker.com/junk/sunray3.bmp[/IMG]
(2nd screenshot's example)

http://www.gamebaker.com/junk/sunray5.bmp[/IMG]
(1st screenshot's example)

Max Width Base = How many pixels out it can stretch from the top to the right


Script Spoiler
# Sunray script (beta version) by sandgolem
# For use only with good mapping :>

SG_Sunray_MaxStartOpacity = 15
SG_Sunray_MaxOpacity = 160
SG_Sunray_MaxHeight = 340
SG_Sunray_MaxWidth = 70
SG_Sunray_AppearTime = 150
SG_Sunray_FadeTime = 275
SG_Sunray_MaxWidthBase = 8
SG_Sunray_RGB = [155,220,255]

class SG_Sunray
  def initialize
    reset
  end
 
  def reset
    @sunrays.each{|i| i.dispose if !i.disposed?} if @sunrays && @sunrays != []
    @sunrays = []
    @duration = []
  end
 
#  def pause
#    return if @sunrays == []
#    for i in [email hidden]
#      @sunrays[i].visible = false
#    end
#  end
 
#  def resume
#    return if @sunrays == []
#    for i in [email hidden]
#      @sunrays[i].visible = true
#    end
#  end
 
  def create(r = SG_Sunray_RGB[0],g = SG_Sunray_RGB[1],b = SG_Sunray_RGB[2])
    @r = r; @g = g; @b = b
    this = @sunrays.size
    @sunrays += [Sprite.new]
    ray_height = 100 + rand(SG_Sunray_MaxHeight - 99)
    ray_width = 12 + rand(SG_Sunray_MaxWidth - 11)
    @sunrays[this].bitmap = Bitmap.new(ray_width,ray_height)
    @opacity = 180 + rand(76)
    basex = 2 + rand(SG_Sunray_MaxWidthBase - 2)
    for i in 0...ray_height
      opacity = (@opacity * ((ray_height - i) * 100 / ray_height) / 100) + 10
      color = Color.new(@r,@g,@b,opacity)
      k = (ray_width * (i * 100 / ray_height) / 100) + basex
      for j in 0...k
        @sunrays[this].bitmap.set_pixel(j,i,color)
      end
    end
    @sunrays[this].x = rand(640 - ray_width)
    @sunrays[this].y = rand(480 - ray_height)
    @duration[this] = rand(60)
    @sunrays[this].opacity = 2 + rand(SG_Sunray_MaxStartOpacity - 2)
  end
 
  def move(x,y)
    return if @sunrays == []
    for i in [email hidden]
      @sunrays[i].x += x
      @sunrays[i].y += y
    end
  end

  def update
    return if @sunrays == [] or !$scene.is_a?(Scene_Map)
    for i in [email hidden]
      @duration[i] += 1
      if @duration[i] < SG_Sunray_AppearTime
        x = rand(2)
        if x == 1 && @sunrays[i].opacity < SG_Sunray_MaxOpacity
          @sunrays[i].opacity += 1
        end
      elsif @duration[i] > SG_Sunray_FadeTime
        @sunrays[i].opacity -= 1
        if @sunrays[i].opacity == 0
          @sunrays[i] = nil
          @duration[i] = nil
        end
      end
    end
    @sunrays.compact!
    @duration.compact!
  end
end

class Game_Player
  alias sandgolem_sunray_down move_down
  alias sandgolem_sunray_up move_up
  alias sandgolem_sunray_left move_left
  alias sandgolem_sunray_right move_right
 
  def move_down
    sandgolem_sunray_down
    Sunray.move(0,-1) if moving? && @y % 2 == 0
  end
 
  def move_up
    sandgolem_sunray_up
    Sunray.move(0,1) if moving? && @y % 2 == 0
  end
 
  def move_left
    sandgolem_sunray_left
    Sunray.move(1,0) if moving? && @x % 2 == 0
  end
 
  def move_right
    sandgolem_sunray_right
    Sunray.move(-1,0) if moving? && @x % 2 == 0
  end
end

class Game_Map
  alias sandgolem_sunray_update update
  alias sandgolem_sunray_setup setup
 
  def setup(map_id)
    sandgolem_sunray_setup(map_id)
    Sunray.reset
  end
 
  def update
    Sunray.update
    sandgolem_sunray_update
  end
end

#class Scene_Map
#  alias sandgolem_sunray_main main
 
#  def main
#    Sunray.resume
#    sandgolem_sunray_main
#    Sunray.pause
#  end
#end

Sunray = SG_Sunray.new
Expand to see the code.


Play with the numbers in the script as well as changing how the opacity/colors/triangle work and you can get some really neat results. I use it with a different angle and whiter at the top, but that wouldn't suit the RTP maps well.

If you have problems PLEASE DO NOT BUG OTHER SCRIPTERS TO HELP YOU
Send me a private message and maybe I'll help. :)

This is a prototype version I later integrated into rewritten systems. Again, depending on what you're trying to do, you might want to stick it into Spriteset_Map or something.

Troubleshooting Halp:

- Use Sunray.reset if you want to get rid of them warping around the same map.
- This version's disappear if you change scenes. You can see how I tried to fix that (commented out), but it doesn't work.
- If you have conflicts with other scripts, try getting rid of the whole Game_Player section.
- Lagging? Make sure you have waits in your parallel processes. 25+ is highly recommended
This is pretty sweet. This could add some great ambience to a celestial type of place. Maybe a crystal cave, or heavenly temple.

I love it ^-^
So what all can you do with this? Because i dont get it because you only showed a screen what not to do...It looks good btw
Someone had sent me a private message with a very, very odd bug & info I wanted to attempt to reproduce that might've been the very rare one that can affect a lot of scripts. Unfortunately, the board change lost private messages. If that was you please send me more info again.

Quote:
Because i dont get it because you only showed a screen what not to do


Hehe, that was the point. The 3rd screenshot shows how it could look on a good map, the 1st & 3rd rays (counting right to left). I don't want to be another of those people who write an eye candy script that a lot of people throw in their games for no reason. :)

But I will post some "OMFG awesome" screenshots later from my super polished pet project & a very edited script. I'll also post an enhanced version of it that allows for more effects, multiple sunrays at a time that can be switched from, no more parallel triggers and remembers settings. People who aren't already good at scripting or willing to spend a lot of time with it won't be able to do the really cool effects though.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=29432