Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Better (heavier + new) Weather
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.


Copy and paste this above Game_Temp

p.s. i combined 2 topics so you have all the info in one topic... (instead of 9 pages diveded over 2 topics...)


Code:
module RPG
class Weather
def initialize(viewport = nil)
  @type = 0
  @max = 0
  @ox = 0
  @oy = 0
  color1 = Color.new(255, 255, 255, 255)
  color2 = Color.new(255, 255, 255, 128)
  @rain_bitmap = Bitmap.new(7, 56)
  for i in 0..6
    @rain_bitmap.fill_rect(6-i, i*8, 1, 8, color1)
  end
  @storm_bitmap = Bitmap.new(34, 64)
  for i in 0..31
    @storm_bitmap.fill_rect(33-i, i*2, 1, 2, color2)
    @storm_bitmap.fill_rect(32-i, i*2, 1, 2, color1)
    @storm_bitmap.fill_rect(31-i, i*2, 1, 2, color2)
  end
  @snow_bitmap = Bitmap.new(6, 6)
  @snow_bitmap.fill_rect(0, 1, 6, 4, color2)
  @snow_bitmap.fill_rect(1, 0, 4, 6, color2)
  @snow_bitmap.fill_rect(1, 2, 4, 2, color1)
  @snow_bitmap.fill_rect(2, 1, 2, 4, color1)
  @sprites = []
  # **** ccoa ****
  for i in 1..500
    sprite = Sprite.new(viewport)
    sprite.z = 1000
    sprite.visible = false
    sprite.opacity = 0
    @sprites.push(sprite)
  end
end
def dispose
  for sprite in @sprites
    sprite.dispose
  end
  @rain_bitmap.dispose
  @storm_bitmap.dispose
  @snow_bitmap.dispose
end
def type=(type)
  return if @type == type
  @type = type
  case @type
  when 1
    bitmap = @rain_bitmap
  when 2
    bitmap = @storm_bitmap
  when 3
    bitmap = @snow_bitmap
  else
    bitmap = nil
  end
  # **** ccoa ****
  for i in 1..500
    sprite = @sprites[i]
    if sprite != nil
      sprite.visible = (i <= @max)
      sprite.bitmap = bitmap
    end
  end
end
def ox=(ox)
  return if @ox == ox;
  @ox = ox
  for sprite in @sprites
    sprite.ox = @ox
  end
end
def oy=(oy)
  return if @oy == oy;
  @oy = oy
  for sprite in @sprites
    sprite.oy = @oy
  end
end
def max=(max)
  return if @max == max;
  # **** ccoa ****
  @max = [[max, 0].max, 500].min
  for i in 1..500
    sprite = @sprites[i]
    if sprite != nil
      sprite.visible = (i <= @max)
    end
  end
end
def update
  return if @type == 0
  for i in 1..@max
    sprite = @sprites[i]
    if sprite == nil
      break
    end
    if @type == 1
      sprite.x -= 2
      sprite.y += 16
      sprite.opacity -= 8
    end
    if @type == 2
      sprite.x -= 8
      sprite.y += 16
      sprite.opacity -= 12
    end
    if @type == 3
      sprite.x -= 2
      sprite.y += 8
      sprite.opacity -= 8
    end
    x = sprite.x - @ox
    y = sprite.y - @oy
    if sprite.opacity < 64 or x < -50 or x > 750 or y < -300 or y > 500
      sprite.x = rand(800) - 50 + @ox
      sprite.y = rand(800) - 200 + @oy
      sprite.opacity = 255
    end
  end
end
attr_reader :type
attr_reader :max
attr_reader :ox
attr_reader :oy
end
end



Then go to Game_Screen and replace this line:


Code:
@weather_max_target = (power + 1) * 4.0


with (something like...): #this wil change the *4 sprites to *50 sprites


Code:
@weather_max_target = (power + 1) * 50.0



This is how many sprites will appear at each power level. So currently, 100 sprites at level 1 and 500 sprites at level 9.

Changes are preceded by #**** ccoa ****, so if it's too heavy (or too light), then you can find them to fiddle with them. Hope that helped!

-----------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------

1. If you want too let the rain fall straight...

Look at this code:
Code:
if @type == 1
     sprite.x -= 2
     sprite.y += 16
     sprite.opacity -= 8
   end


remove the line changing the x coordinates of the rain, like so:


Code:
if @type == 1
     sprite.y += 16
     sprite.opacity -= 8
   end

And the rain should fall straight down.


-----------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------

2.Example how too created NEW weathers or make others different...

Code:
...@snow_bitmap.fill_rect(2, 1, 2, 4, color1)

===Input here!!!===

  @sprites = []...



Here's a very simple cherry blossom petal:
Code:
color3 = Color.new(255, 167, 192, 255) # light pink
  color4 = Color.new(213, 106, 136, 255) # dark pink
  @petal_bitmap = Bitmap.new(4, 4) #This creates a new bitmap that is 4 x 4 pixels
  @petal_bitmap.fill_rect(0, 3, 1, 1, color3) # this makes a 1x1 pixel "rectangle" at the 0, 3 pixel of the image (upper left corner is 0, 0)
  @petal_bitmap.fill_rect(1, 2, 1, 1, color3)
  @petal_bitmap.fill_rect(2, 1, 1, 1, color3)
  @petal_bitmap.fill_rect(3, 0, 1, 1, color3)
  @petal_bitmap.fill_rect(1, 3, 1, 1, color4)
  @petal_bitmap.fill_rect(2, 2, 1, 1, color4)
  @petal_bitmap.fill_rect(3, 1, 1, 1, color4)



Should make: [Image: petal.png]<---It's tiny, but there's an image there...

Now look at this case statement:


Code:
case @type
   when 1
     bitmap = @rain_bitmap
   when 2
     bitmap = @storm_bitmap
   when 3
     bitmap = @snow_bitmap
   else
     bitmap = nil
   end



add a new case, like so:

Code:
case @type
   when 1
     bitmap = @rain_bitmap
   when 2
     bitmap = @storm_bitmap
   when 3
     bitmap = @snow_bitmap
   when 4
     bitmap = @petal_bitmap
   else
     bitmap = nil
   end


Under this:
Code:
if @type == 3
       sprite.x -= 2
       sprite.y += 8
       sprite.opacity -= 8
     end


add:
Code:
if @type == 4
      if (rand(2) == 1)
        sprite.x -= 2 + rand(2)
      else
        sprite.x += 2 + rand(2)
      end
      sprite.y += rand(5)
    end



Now, to call a sakura shower, do a Call Script with the following:


Code:
$game_screen.weather(4, intensity, transition_time)



Where intensity is a number from 0 to 9 (0 is no weather), and transition_time is the transition, in frames, between the current weather and the new weather.

-----------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------


3. To add lighting too storm...

search for
Code:
if @type == 2
       sprite.x -= 8
       sprite.y += 16
       sprite.opacity -= 12
end



replace with

Code:
#==============
#ProneAccident
#==============
if @type == 2
       sprite.x -= 8
       sprite.y += 16
       sprite.opacity -= 12
       # Adjust this number to suit your needs. :)
       if rand(8000) == 0
         $game_screen.start_flash(Color.new(255, 255, 255, 255), 6)
         Audio.se_play("Audio/SE/061-Thunderclap01", @max * 2.5)
       end
     end
#==============




-----------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------


4.mixed weather

Now, to mix weather effect, you'll need to set it up so that some of the sprites' bitmaps are set to one type, and one to another. To make mixed rain and snow, for example, add a new case to the switch statement, and edit it like so:


Code:
case @type
  when 1
    bitmap = @rain_bitmap
    @mixed_weather = false
  when 2
    bitmap = @storm_bitmap
    @mixed_weather = false
  when 3
    bitmap = @snow_bitmap
    @mixed_weather = false
  when 4
     @mixed_weather = true
  else
    bitmap = nil
    @mixed_weather = false
  end



Now go to this for statement:

Code:
for i in 1..500
     sprite = @sprites[i]
     if sprite != nil
       sprite.visible = (i <= @max)
       sprite.bitmap = bitmap
     end
   end



The 500 may be a different number, depending on if you've changed this line.

Rewrite it like this:

Code:
count = 0
  for i in 1..500
     sprite = @sprites[i]
     if sprite != nil
       sprite.visible = (i <= @max)
       if @mixed_weather
         if count % 2 == 0  # every other sprite is rain.
           sprite.bitmap = @rain_bitmap
         else
           sprite.bitmap = @snow_bitmap
         end
         count += 1
      else
         sprite.bitmap = bitmap
      end
     end
   end



This will produce half rain and half snow. For 1/3 rain, 2/3 snow, change the line



Code:
if count % 2 == 0  # every other sprite is rain.



to:



Code:
if count % 3 == 0  # every third sprite is rain.



This is just hard-coded for rain and snow, but hopefully it gives you an idea for other things. Now, to call mixed rain and snow, do a Call Script with the following:



Code:
$game_screen.weather(4, intensity, transition_time)



-----------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------


Mr. DJ
}




Users browsing this thread: