Class: Spriteset_Weather

Inherits:
Object
  • Object
show all
Defined in:
Spriteset_Weather.rb

Overview

** Spriteset_Weather


A class for weather effects (rain, storm, and snow). It is used within the

Spriteset_Map class.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Spriteset_Weather) initialize(viewport = nil)


  • Object Initialization




19
20
21
22
23
24
25
# File 'Spriteset_Weather.rb', line 19

def initialize(viewport = nil)
  @viewport = viewport
  init_members
  create_rain_bitmap
  create_storm_bitmap
  create_snow_bitmap
end

Instance Attribute Details

- (Object) ox

X coordinate of origin



13
14
15
# File 'Spriteset_Weather.rb', line 13

def ox
  @ox
end

- (Object) oy

Y coordinate of orgin



14
15
16
# File 'Spriteset_Weather.rb', line 14

def oy
  @oy
end

- (Object) power

Intensity



15
16
17
# File 'Spriteset_Weather.rb', line 15

def power
  @power
end

- (Object) type


  • Public Instance Variables




12
13
14
# File 'Spriteset_Weather.rb', line 12

def type
  @type
end

Instance Method Details

- (Object) add_sprite


  • Add Sprite




102
103
104
105
106
# File 'Spriteset_Weather.rb', line 102

def add_sprite
  sprite = Sprite.new(@viewport)
  sprite.opacity = 0
  @sprites.push(sprite)
end

- (Object) create_new_particle(sprite)


  • Create New Particle




179
180
181
182
183
# File 'Spriteset_Weather.rb', line 179

def create_new_particle(sprite)
  sprite.x = rand(Graphics.width + 100) - 100 + @ox
  sprite.y = rand(Graphics.height + 200) - 200 + @oy
  sprite.opacity = 160 + rand(96)
end

- (Object) create_rain_bitmap


  • Create [Rain] Weather Bitmap




60
61
62
63
# File 'Spriteset_Weather.rb', line 60

def create_rain_bitmap
  @rain_bitmap = Bitmap.new(7, 42)
  7.times {|i| @rain_bitmap.fill_rect(6-i, i*6, 1, 6, particle_color1) }
end

- (Object) create_snow_bitmap


  • Create [Snow] Weather Bitmap




78
79
80
81
82
83
84
# File 'Spriteset_Weather.rb', line 78

def create_snow_bitmap
  @snow_bitmap = Bitmap.new(6, 6)
  @snow_bitmap.fill_rect(0, 1, 6, 4, particle_color2)
  @snow_bitmap.fill_rect(1, 0, 4, 6, particle_color2)
  @snow_bitmap.fill_rect(1, 2, 4, 2, particle_color1)
  @snow_bitmap.fill_rect(2, 1, 2, 4, particle_color1)
end

- (Object) create_storm_bitmap


  • Create [Storm] Weather Bitmap




67
68
69
70
71
72
73
74
# File 'Spriteset_Weather.rb', line 67

def create_storm_bitmap
  @storm_bitmap = Bitmap.new(34, 64)
  32.times do |i|
    @storm_bitmap.fill_rect(33-i, i*2, 1, 2, particle_color2)
    @storm_bitmap.fill_rect(32-i, i*2, 1, 2, particle_color1)
    @storm_bitmap.fill_rect(31-i, i*2, 1, 2, particle_color2)
  end
end

- (Object) dimness


  • Get Dimness




130
131
132
# File 'Spriteset_Weather.rb', line 130

def dimness
  (@power * 6).to_i
end

- (Object) dispose


  • Free




39
40
41
42
43
44
# File 'Spriteset_Weather.rb', line 39

def dispose
  @sprites.each {|sprite| sprite.dispose }
  @rain_bitmap.dispose
  @storm_bitmap.dispose
  @snow_bitmap.dispose
end

- (Object) init_members


  • Initialize Member Variables




29
30
31
32
33
34
35
# File 'Spriteset_Weather.rb', line 29

def init_members
  @type = :none
  @ox = 0
  @oy = 0
  @power = 0
  @sprites = []
end

- (Object) particle_color1


  • Particle Color 1




48
49
50
# File 'Spriteset_Weather.rb', line 48

def particle_color1
  Color.new(255, 255, 255, 192)
end

- (Object) particle_color2


  • Particle Color 2




54
55
56
# File 'Spriteset_Weather.rb', line 54

def particle_color2
  Color.new(255, 255, 255, 96)
end

- (Object) remove_sprite


  • Delete Sprite




110
111
112
113
# File 'Spriteset_Weather.rb', line 110

def remove_sprite
  sprite = @sprites.pop
  sprite.dispose if sprite
end

- (Object) sprite_max


  • Get Maximum Number of Sprites




96
97
98
# File 'Spriteset_Weather.rb', line 96

def sprite_max
  (@power * 10).to_i
end

- (Object) update


  • Frame Update




117
118
119
120
# File 'Spriteset_Weather.rb', line 117

def update
  update_screen
  @sprites.each {|sprite| update_sprite(sprite) }
end

- (Object) update_screen


  • Update Screen




124
125
126
# File 'Spriteset_Weather.rb', line 124

def update_screen
  @viewport.tone.set(-dimness, -dimness, -dimness)
end

- (Object) update_sprite(sprite)


  • Update Sprite




136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'Spriteset_Weather.rb', line 136

def update_sprite(sprite)
  sprite.ox = @ox
  sprite.oy = @oy
  case @type
  when :rain
    update_sprite_rain(sprite)
  when :storm
    update_sprite_storm(sprite)
  when :snow
    update_sprite_snow(sprite)
  end
  create_new_particle(sprite) if sprite.opacity < 64
end

- (Object) update_sprite_rain(sprite)


  • Update Sprite [Rain]




152
153
154
155
156
157
# File 'Spriteset_Weather.rb', line 152

def update_sprite_rain(sprite)
  sprite.bitmap = @rain_bitmap
  sprite.x -= 1
  sprite.y += 6
  sprite.opacity -= 12
end

- (Object) update_sprite_snow(sprite)


  • Update Sprite [Snow]




170
171
172
173
174
175
# File 'Spriteset_Weather.rb', line 170

def update_sprite_snow(sprite)
  sprite.bitmap = @snow_bitmap
  sprite.x -= 1
  sprite.y += 3
  sprite.opacity -= 12
end

- (Object) update_sprite_storm(sprite)


  • Update Sprite [Storm]




161
162
163
164
165
166
# File 'Spriteset_Weather.rb', line 161

def update_sprite_storm(sprite)
  sprite.bitmap = @storm_bitmap
  sprite.x -= 3
  sprite.y += 6
  sprite.opacity -= 12
end