Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Dynamic Weather and Time System

Dynamic Weather and Time SystemVersion: 1.0
By: ThallionDarkshine

Introduction

When the game starts, the weather system picks a random time of day. The screen tone changes as time passes, with each minute taking a certain amount of seconds specified in configuration. After a random amount of time, the weather changes, either to normal, rain, storm, snow, fog, or clouds. The storm includes random lightning as well.

Features
  • Specify if a map is indoors by placing (in) in the map name
  • Completely dynamic weather with user-defined varience and base time between switching of weather
  • Screen tint changes with time of day

Screenshots



Demo

Demo

https://rapidshare.com/files/2898565759/Weather_Demo.exe

Script

Code:
module Weather_Config

  # Config

  

  WEATHER_VARIENCE = 520

  WEATHER_BASE = 200

  RANDOM_WEATHER = true

  MIN_EQUIV = 1/40

end

 

class Weather

  attr_accessor :varience

  attr_accessor :base

  attr_accessor :rand_weather

  attr_accessor :min_equiv

  

  def initialize

    @varience = Weather_Config::WEATHER_VARIENCE

    @base = Weather_Config::WEATHER_BASE

    @rand_weather = Weather_Config::RANDOM_WEATHER

    @min_equiv = Weather_Config::MIN_EQUIV

    @counter = [0, 0]

    @time = rand(24) * 60

    @wthr = 0

    hour = @time / 60

    if hour > 13

      change = hour - 14

    else

      change = 12 - hour

    end

    red = change * -9

    green = change * -9

    blue = change * -9

    gray = change * 12

    $game_screen.start_tone_change(Tone.new(red, green, blue, gray), 0)

    @weather_change = rand(@varience) + @base

    @red = red

    @green = green

    @blue = blue

    @s_hour = hour

    @s_wthr = 0

  end

  

  def rand_weather=(bool)

    @rand_weather = bool

    if @rand_weather == false

      $game_screen.weather(0, 0, 0)

      $game_system.bgs_fade(5)

      @wthr = 0

      $game_map.fog_name = ""

    end

  end

  

  def update

    if $game_temp.inside == true

      @counter[1] = nil

      $game_screen.weather(0, 0, 0)

    else

      @counter[1] = 0 if @counter[1] == nil

    end

    @counter[0] += 1

    @counter[1] += 1 if @counter[1] != nil

    

    if @counter[0] > Graphics.frame_rate * @min_equiv

      @time = (@time + 1) % (24 * 60 + 1)

      @counter[0] = 0

      hour = @time / 60

      if hour > 13

        change = hour - 14

      else

        change = 12 - hour

      end

      red = change * -9

      green = change * -9

      blue = change * -9

      gray = change * 12

      if @rand_weather == true

        if @counter[1] != nil and @counter[1] > @weather_change

          @lightning = false

          rnd = rand(8)

          case rnd

            when 0

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

            when 1

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

              $game_screen.weather(1, rand(10), 200)

              bgs = RPG::AudioFile.new("005-Rain01", 80, 100)

              $game_system.bgs_play(bgs)

            when 2

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

              $game_screen.weather(2, rand(10), 200)

              @lightning = true

              bgs = RPG::AudioFile.new("007-Rain03", 100, 100)

              $game_system.bgs_play(bgs)

            when 3

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

              $game_screen.weather(3, rand(10), 200)

            when 4

              unless @wthr == 4

                $game_screen.weather(0, 0, 60)

                $game_system.bgs_fade(10)

                $game_map.fog_name = "001-Fog01"

                $game_map.fog_hue = 0

                @fog_opac = rand(75) + 100

                $game_map.fog_opacity = 0

                $game_map.fog_sx = (rand(5) + 1) * 2

                $game_map.fog_sy = (rand(5) + 1) * 2

              end

            when 5

              unless @wthr == 5

                $game_screen.weather(0, 0, 60)

                $game_system.bgs_fade(10)

                $game_map.fog_name = "002-Clouds01"

                $game_map.fog_hue = 0

                @fog_opac = rand(75) + 50

                $game_map.fog_opacity = 0

                $game_map.fog_sx = (rand(5) + 1) * 4

                $game_map.fog_sy = (rand(5) + 1) * 4

              end

            when 6

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

            when 7

              $game_screen.weather(0, 0, 60)

              $game_system.bgs_fade(10)

          end

          @wthr = rnd

          @weather_change = rand(@varience) + @base

          @counter[1] = 0

        end

        case @wthr

          when 1

            red -= 20

            blue -= 15

            green -= 20

          when 2

            red -= 30

            blue -= 20

            green -= 30

          when 3

            red += 5

            blue += 10

            green += 5

          when 4

            red -= 5

            green -= 5

            gray -= 20

        end

      end

      if @wthr != @s_wthr or hour != @s_hour  

        $game_screen.start_tone_change(Tone.new(red, green, blue, gray), 60)

      end

      

      if (@wthr == 4 or @wthr == 5) and $game_map.fog_opacity != @fog_opac

        $game_map.fog_opacity += 1

      else 

        if $game_map.fog_name != ""

          $game_map.fog_opacity -= 1

          if $game_map.fog_opacity == 0

            $game_map.fog_name = ""

            $game_map.fog_sx = 0

            $game_map.fog_sy = 0

          end

        end

      end

      

      if @lightning == true

        if rand(120) == 0

          $game_screen.start_flash(Color.new(255, 255, 255), rand(9) + 1)

        end

      end

    end

  end

end

 

class Scene_Map

  alias dwt_orig_update update

  

  def update

    $weather.update

    dwt_orig_update

  end

end

 

class Scene_Title

  alias dwt_orig_command_new_game command_new_game

  

  def command_new_game

    dwt_orig_command_new_game

    $weather = Weather.new

  end

end

 

class Game_Temp

  attr_accessor :inside

  

  alias dwt_orig_init initialize

  

  def initialize

    dwt_orig_init

    @inside = false

  end

end

 

class Scene_Save

  alias dwt_orig_write_save_data write_save_data

  

  def write_save_data(file)

    dwt_orig_write_save_data(file)

    Marshal.dump($weather, file)

  end

end

 

class Scene_Load

  alias dwt_orig_read_save_data read_save_data

  

  def read_save_data(file)

    dwt_orig_read_save_data(file)

    $weather = Marshal.load(file)

  end

end

Instructions

To use, place directly under main.
To turn on or off random weather (replace true with false to turn off):
Code:
$weather.rand_weather = true

$weather.update
To change the varience of weather:
Code:
$weather.varience =
To change the base time between weather changes:
Code:
$weather.base =
To change the second equivalent of one minute realtime:
Code:
$weather.min_equiv =

FAQ

No questions yet.

Compatibility

I'm trying to make this compatible with MAWS (Modified Advanced Weather System), which is a rewrite of the weather module incorporating many extra weather effects.

Credits and Thanks

Right now, I am using a rewrite of MAWS in my demo, so thank you Ccoa, ForeverZer0, and Agckuu Coceg

Author's Notes

Right now, I'm trying to add in some extra weather functions to go with the dynamic weather.

Terms and Conditions

I don't care what you use it for, just don't claim that it's yours.
 
I'm going to bookmark this and test it out when I have the time, sounds damn nice.

Can you make characters say different things based on the weather/time this script makes?
 
this is a good little script here, well done.. only problem I have with it
is that you HAVE to put IN or whatever in the maps name, where as if
your using a script that shows ur map names it will show IN on the names
too.
 
I fixed that in my test project that I was using it in, so I'll put the fix in the script.

Edit: I realized that my fix edited the actual location window script, so just post the script you're using and I'll fix it.
 
im not actually using this script yet.. but will be wen i start my new project after the one
im wrking on atm.. the last post i made was really more of a thought that.. "if ppl were
gonna use it.. it would show the IN.. if they were using a location script".
 
Oh, because to take the (in) out of the name of the map, I would have to edit the map infos file, but that would change it permanently, so I would have to change the name of the map in the location script.
 
well.. its maybe an idea for a future updated release of this script,
if you decide ever to update it that is ^^ (tho its fine as it is as a
stand-alone weather script), maybe you could..

change from having to put (in) in the map name and maybe change
the script so all you need to do is put an "event" on inside maps with
a comment, something like, "inside", and have it set to run as a..
parallel or auto event continuosly running when in an inside area.

if that makes sense, anyhows... i personally think by doing this it would
make your weather script so much more user friendly and will allow people
then to be able to use your script along with "map name/location" scripts
that use the map name to show locations.

Only downside I think by doing the way I suggested would be it would require
you to put an extra event running on all inside areas you have.
As I said tho.. maybe its something you could add in a future release if your
bored one day and got time to change ur script for an update, but as stated
before its an awesome script.

well done ^^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top