A lot of FPS agnosticism, added def lerp

This commit is contained in:
Maruno17
2023-05-20 18:37:54 +01:00
parent 62e372f4d7
commit d112e2361a
38 changed files with 619 additions and 628 deletions

View File

@@ -2,6 +2,9 @@
# Location signpost
#===============================================================================
class LocationWindow
APPEAR_TIME = 0.4 # In seconds; is also the disappear time
LINGER_TIME = 1.6 # In seconds; time during which self is fully visible
def initialize(name)
@window = Window_AdvancedTextPokemon.new(name)
@window.resizeToFit(name, Graphics.width)
@@ -10,11 +13,11 @@ class LocationWindow
@window.viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@window.viewport.z = 99999
@currentmap = $game_map.map_id
@frames = 0
@timer_start = System.uptime
end
def disposed?
@window.disposed?
return @window.disposed?
end
def dispose
@@ -28,12 +31,11 @@ class LocationWindow
@window.dispose
return
end
if @frames > Graphics.frame_rate * 2
@window.y -= 4
@window.dispose if @window.y + @window.height < 0
if System.uptime - @timer_start >= APPEAR_TIME + LINGER_TIME
@window.y = lerp(0, -@window.height, APPEAR_TIME, @timer_start + APPEAR_TIME + LINGER_TIME, System.uptime)
@window.dispose if @window.y + @window.height <= 0
else
@window.y += 4 if @window.y < 0
@frames += 1
@window.y = lerp(-@window.height, 0, APPEAR_TIME, @timer_start, System.uptime)
end
end
end
@@ -62,7 +64,7 @@ class DarknessSprite < Sprite
def radiusMax; return 176; end # After using Flash
def radius=(value)
@radius = value
@radius = value.round
refresh
end

View File

@@ -6,24 +6,22 @@ def pbCaveEntranceEx(exiting)
sprite = BitmapSprite.new(Graphics.width, Graphics.height)
sprite.z = 100000
# Define values used for the animation
totalFrames = (Graphics.frame_rate * 0.4).floor
increment = (255.0 / totalFrames).ceil
duration = 0.4
totalBands = 15
bandheight = ((Graphics.height / 2.0) - 10) / totalBands
bandwidth = ((Graphics.width / 2.0) - 12) / totalBands
start_gray = (exiting) ? 0 : 255
end_gray = (exiting) ? 255 : 0
# Create initial array of band colors (black if exiting, white if entering)
grays = Array.new(totalBands) { |i| (exiting) ? 0 : 255 }
grays = Array.new(totalBands) { |i| start_gray }
# Animate bands changing color
totalFrames.times do |j|
timer_start = System.uptime
until System.uptime - timer_start >= duration
x = 0
y = 0
# Calculate color of each band
totalBands.times do |k|
next if k >= totalBands * j / totalFrames
inc = increment
inc *= -1 if exiting
grays[k] -= inc
grays[k] = 0 if grays[k] < 0
grays[k] = lerp(start_gray, end_gray, duration, timer_start + k * duration / totalBands, System.uptime)
end
# Draw gray rectangles
rectwidth = Graphics.width
@@ -47,19 +45,19 @@ def pbCaveEntranceEx(exiting)
pbToneChangeAll(Tone.new(-255, -255, -255), 0)
end
# Animate fade to white (if exiting) or black (if entering)
totalFrames.times do |j|
if exiting
sprite.color = Color.new(255, 255, 255, j * increment)
else
sprite.color = Color.new(0, 0, 0, j * increment)
end
timer_start = System.uptime
loop do
sprite.color = Color.new(end_gray, end_gray, end_gray,
lerp(0, 255, duration, timer_start, System.uptime))
Graphics.update
Input.update
break if sprite.color.alpha >= 255
end
# Set the tone at end of fading animation
pbToneChangeAll(Tone.new(0, 0, 0), 8)
# Pause briefly
(Graphics.frame_rate / 10).times do
timer_start = System.uptime
until System.uptime - timer_start >= 0.1
Graphics.update
Input.update
end