Class: RPG::Weather
- Inherits:
-
Object
- Object
- RPG::Weather
- Defined in:
- lib/rpg/weather.rb
Overview
Class for weather effects (rain, storm, snow) displayed via RPGXP’s Event command.
Instance Attribute Summary collapse
-
#max ⇒ Object
Amount of weather to be shown at once (0..40).
-
#ox ⇒ Object
The X-coordinate of the effect’s starting point.
-
#oy ⇒ Object
The Y-coordinate of the effect’s starting point.
-
#type ⇒ Object
- Weather type: 0
- none 1
- rain 2
- storm 3
-
snow.
Instance Method Summary collapse
-
#dispose ⇒ Object
Frees a weather effect.
-
#initialize(viewport = nil) ⇒ Weather
constructor
A new instance of Weather.
-
#update ⇒ Object
Advances the weather effect.
Constructor Details
#initialize(viewport = nil) ⇒ Weather
Returns a new instance of Weather.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rpg/weather.rb', line 27 def initialize( = 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 = [] for i in 1..40 sprite = Sprite.new() sprite.z = 1000 sprite.visible = false sprite.opacity = 0 @sprites.push(sprite) end end |
Instance Attribute Details
#max ⇒ Object
Amount of weather to be shown at once (0..40).
17 18 19 |
# File 'lib/rpg/weather.rb', line 17 def max @max end |
#ox ⇒ Object
The X-coordinate of the effect’s starting point. Correlates with the tilemap starting point and scrolls.
21 22 23 |
# File 'lib/rpg/weather.rb', line 21 def ox @ox end |
#oy ⇒ Object
The Y-coordinate of the effect’s starting point. Correlates with the tilemap starting point and scrolls.
25 26 27 |
# File 'lib/rpg/weather.rb', line 25 def oy @oy end |
#type ⇒ Object
Weather type:
- 0
-
none
- 1
-
rain
- 2
-
storm
- 3
-
snow
14 15 16 |
# File 'lib/rpg/weather.rb', line 14 def type @type end |
Instance Method Details
#dispose ⇒ Object
Frees a weather effect.
60 61 62 63 64 65 66 67 |
# File 'lib/rpg/weather.rb', line 60 def dispose for sprite in @sprites sprite.dispose end @rain_bitmap.dispose @storm_bitmap.dispose @snow_bitmap.dispose end |
#update ⇒ Object
Advances the weather effect. As a rule, this method is called once per frame.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rpg/weather.rb', line 130 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 |