Home > RGSS Script Reference > Game_Screen
Game_Screen
Inherits from: None
Description: This class holds information and has methods for managing information that is relative to the game screen, rather than relative to the entire map, such as weather effects, screen flashes, and screen shakes.
class Game_Screen
# ------------------------------------
attr_reader :tone
attr_reader :flash_color
attr_reader :shake
attr_reader :pictures
attr_reader :weather_type
attr_reader :weather_max
# ------------------------------------
def initialize
@tone = Tone.new(0, 0, 0, 0)
@tone_target = Tone.new(0, 0, 0, 0)
@tone_duration = 0
@flash_color = Color.new(0, 0, 0, 0)
@flash_duration = 0
@shake_power = 0
@shake_speed = 0
@shake_duration = 0
@shake_direction = 1
@shake = 0
@pictures = [nil]
for i in 1..100
@pictures.push(Game_Picture.new(i))
end
@weather_type = 0
@weather_max = 0.0
@weather_type_target = 0
@weather_max_target = 0.0
@weather_duration = 0
end
# ------------------------------------
def start_tone_change(tone, duration)
@tone_target = tone.clone
@tone_duration = duration
if @tone_duration == 0
@tone = @tone_target.clone
end
end
# ------------------------------------
def start_flash(color, duration)
@flash_color = color.clone
@flash_duration = duration
end
# ------------------------------------
def start_shake(power, speed, duration)
@shake_power = power
@shake_speed = speed
@shake_duration = duration
end
# ------------------------------------
def weather(type, power, duration)
@weather_type_target = type
if @weather_type_target != 0
@weather_type = @weather_type_target
end
if @weather_type_target == 0
@weather_max_target = 0.0
else
@weather_max_target = (power + 1) * 4.0
end
@weather_duration = duration
if @weather_duration == 0
@weather_type = @weather_type_target
@weather_max = @weather_max_target
end
end
# ------------------------------------
def update
if @tone_duration >= 1
d = @tone_duration
@tone.red = (@tone.red * (d - 1) + @tone_target.red) / d
@tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
@tone.blue = (@tone.blue * (d - 1) + @tone_target.blue) / d
@tone.gray = (@tone.gray * (d - 1) + @tone_target.gray) / d
@tone_duration -= 1
end
if @flash_duration >= 1
d = @flash_duration
@flash_color.alpha = @flash_color.alpha * (d - 1) / d
@flash_duration -= 1
end
if @shake_duration >= 1 or @shake != 0
delta = (@shake_power * @shake_speed * @shake_direction) / 10.0
if @shake_duration <= 1 and @shake * (@shake + delta) < 0
@shake = 0
else
@shake += delta
end
if @shake > @shake_power * 2
@shake_direction = -1
end
if @shake < - @shake_power * 2
@shake_direction = 1
end
if @shake_duration >= 1
@shake_duration -= 1
end
end
if @weather_duration >= 1
d = @weather_duration
@weather_max = (@weather_max * (d - 1) + @weather_max_target) / d
@weather_duration -= 1
if @weather_duration == 0
@weather_type = @weather_type_target
end
end
if $game_temp.in_battle
for i in 51..100
@pictures[i].update
end
else
for i in 1..50
@pictures[i].update
end
end
end
end
|
Tone: The current screen tone.
Tone_Target: The new tone for a "Tint Screen" operation.
Tone_Duration: The time remaining in a tone change, in frames.
Flash_Color: The current flash color for the screen.
Flash_Duration: The time remaining in a screen flash, in frames.
Shake_Power: The power of a "Shake Screen" operation. A larger value means the screen displacement per shake will be larger.
Shake_Speed: The speed of a "Shake Screen" operation. A larger value means a larger number of shakes per unit time.
Shake_Duration: The time remaining in a screen shake, in frames.
Shake_Direction: The direction the screen is currently being displaced as a result of a "Shake Screen" operation (-1 = Down, 0 = Not Shaking, 1 = Up).
Shake: The current screen displacement as a result of a "Shake Screen" command. If the value is 0, then the screen is not displaced at all. If the value is positive, then the screen has been displaced upward. If the value is negative, then the screen has been displaced downward.
Pictures: An array of Game_Picture objects that represent the pictures currently showing onscreen.
Weather_Type: The type of weather currently showing onscreen (0 = None, 1 = Rain, 2 = Storm, 3 = Snow)
Weather_Max: An internal value associated with the weather effect's power. This allows the engine to handle the transition to a new weather effect in a more fine-grained manner than just the raw power value would.
Weather_Type_Target: The new weather effect to which to transition.
Weather_Max_Target: The new maximum intensity to which to transition.
Weather_Duration: The time remaining in a weather effect, in frames.
Initialize
Arguments: None
Local Variables: None
How it Works: Initializes the screen information to its default values.
Start_Tone_Change
Arguments:
Tone: The new screen tone.
Duration: The amount of frames it will take to complete the tinting.
Local Variables: None
How it Works: This method sets up a "Tint Screen" command. This method sets the @tone_target and @tone_duration instance variables. If the value of @tone_duration is 0, the method sets the screen tone to directly to the new tone. Otherwise, the Update method carries out the frame-by-frame updating of the tinting effect.
Start_Flash
Arguments:
Color: The flash color.
Duration: The amount of frames for which to flash the screen.
Local Variables: None
How it Works: This method sets up a "Flash Screen" command. This method sets the @flash_color and @flash_duration instance variables. This method sets the flash color directly, and the Update method does the countdown to determine when the flash should end.
Start_Shake
Arguments:
Power: The shake power.
Speed: The shake speed.
Duration: The amount of frames for which to shake the screen.
Local Variables: None
How it Works: This method sets up a "Shake Screen" command. This method sets the @shake_power, @shake_speed and @shake_duration instance variables. The Update method
handles the frame-by-frame graphical updating of the shake effect.
Weather
Arguments:
Type: The type of weather effect (0 = None, 1 = Rain, 2 = Storm, 3 = Snow).
Power: The weather effect's power.
Duration: The weather effect's transition time, in frames.
Local Variables: None
How it Works: This method sets up a "Weather Effect" operation. First, the @weather_type_target value is set to the type passed to this method. If @weather_type_target is 0 (that is, the weather effect is being cancelled rather than changed), then the value of @weather_max_target is set to 0.0, to signal that the current weather effect should fade out over the course of a number of frames equal to duration. If the weather effect is being changed, then the value of @weather_max_target is set to the weather effect's power level, plus 1, then multipled by 4. Finally, the value of @weather_duration is set to the number of frames for the transition. If that number is 0, then the weather type and intensity are set directly to their target values by this method. Otherwise, the Update method handles the frame-by-frame transition.
Update
Arguments: None
Local Variables: None
How it Works: This method does the frame-by-frame transition updates for "Tint Screen", "Flash Screen", "Shake Screen", and "Weather Effect" as well as updating the state of the pictures being shown on the screen. The if @tone_duration >= 1 clause handles screen tone changes in progress, updating each of the four tone components (red, green, blue, gray) by an amount equal to ((target value - previous value) / total duration). The if @tone_duration >= 1 clause updates a screen flash in progress, by making its alpha value smaller and smaller as the flash nears its ending frame. The if @shake_duration >= 1 or @shake != 0 clause handles the frame-by-frame updating of a screen shake effect. The local variable delta determines how far the screen will be displaced by multiplying the shake power by the shake speed and then dividing by 10. This value is then multiplied by the value of @shake_direction to determine which direction to shake. A positive value indicates shaking upward, while a negative value indicates shaking downward. Next, the method checks to see if the screen displacement should be removed due to the shake being over. If it shouldn't, then the next two checks are executed. These checks bound the displacement at twice the power value. If the shake would exceed this bound, then the shaking direction is reversed. Finally, the shake duration is decremented. The if @weather_duration >= 1 clause handles weather effect transitions by changing the value of @weather_max by an amount equal to ((target value - previous value) / total duration). If this is the final frame of the transition, the value of @weather_type is updated to reflect the fact that the transition has ended. The last part of the method calls the Game_Picture#Update method for pictures 51-100 if a battle is currently running, or pictures 1-50 if the player is currently walking around on the map.
|
|