Finished FPS agnosticism, removed particle engine

This commit is contained in:
Maruno17
2023-06-03 21:55:02 +01:00
parent 68de25562a
commit 1901675e33
39 changed files with 652 additions and 1504 deletions

View File

@@ -1,4 +1,5 @@
# Using mkxp-z v2.4.2/b0d8e0b - https://github.com/mkxp-z/mkxp-z/actions/runs/5033679007
# Using mkxp-z v2.4.2/ee8dc7e - built 2023-05-28
# https://github.com/mkxp-z/mkxp-z/actions/runs/5107184579
$VERBOSE = nil
Font.default_shadow = false if Font.respond_to?(:default_shadow)
Graphics.frame_rate = 40

View File

@@ -389,3 +389,17 @@ end
def nil_or_empty?(string)
return string.nil? || !string.is_a?(String) || string.size == 0
end
#===============================================================================
# Linear interpolation between two values, given the duration of the change and
# either:
# - the time passed since the start of the change (delta), or
# - the start time of the change (delta) and the current time (now)
#===============================================================================
def lerp(start_val, end_val, duration, delta, now = nil)
return end_val if duration <= 0
delta = now - delta if now
return start_val if delta <= 0
return end_val if delta >= duration
return start_val + (end_val - start_val) * delta / duration.to_f
end

View File

@@ -260,100 +260,38 @@ module RPG
class Sprite < ::Sprite
def initialize(viewport = nil)
super(viewport)
@_whiten_duration = 0
@_appear_duration = 0
@_escape_duration = 0
@_collapse_duration = 0
@_damage_duration = 0
@_animation_duration = 0
@_animation_frame = 0
@_blink = false
@animations = []
@_animation_frame = 0
@animations = []
@loopAnimations = []
end
def dispose
dispose_damage
dispose_animation
dispose_loop_animation
super
end
def whiten
self.blend_type = 0
self.color.set(255, 255, 255, 128)
self.opacity = 255
@_whiten_duration = 16
@_appear_duration = 0
@_escape_duration = 0
@_collapse_duration = 0
def dispose_animation
@animations.each { |a| a&.dispose_animation }
@animations.clear
end
def appear
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = 0
@_appear_duration = 16
@_whiten_duration = 0
@_escape_duration = 0
@_collapse_duration = 0
def dispose_loop_animation
@loopAnimations.each { |a| a&.dispose_loop_animation }
@loopAnimations.clear
end
def escape
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = 255
@_escape_duration = 32
@_whiten_duration = 0
@_appear_duration = 0
@_collapse_duration = 0
def x=(x)
@animations.each { |a| a.x = x if a }
@loopAnimations.each { |a| a.x = x if a }
super
end
def collapse
self.blend_type = 1
self.color.set(255, 64, 64, 255)
self.opacity = 255
@_collapse_duration = 48
@_whiten_duration = 0
@_appear_duration = 0
@_escape_duration = 0
end
def damage(value, critical)
dispose_damage
damage_string = (value.is_a?(Numeric)) ? value.abs.to_s : value.to_s
bitmap = Bitmap.new(160, 48)
bitmap.font.name = "Arial Black"
bitmap.font.size = 32
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, 12 - 1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12 - 1, 160, 36, damage_string, 1)
bitmap.draw_text(-1, 12 + 1, 160, 36, damage_string, 1)
bitmap.draw_text(+1, 12 + 1, 160, 36, damage_string, 1)
if value.is_a?(Numeric) && value < 0
bitmap.font.color.set(176, 255, 144)
else
bitmap.font.color.set(255, 255, 255)
end
bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
if critical
bitmap.font.size = 20
bitmap.font.color.set(0, 0, 0)
bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
end
@_damage_sprite = ::Sprite.new(self.viewport)
@_damage_sprite.bitmap = bitmap
@_damage_sprite.ox = 80
@_damage_sprite.oy = 20
@_damage_sprite.x = self.x
@_damage_sprite.y = self.y - (self.oy / 2)
@_damage_sprite.z = 3000
@_damage_duration = 40
def y=(y)
@animations.each { |a| a.y = y if a }
@loopAnimations.each { |a| a.y = y if a }
super
end
def pushAnimation(array, anim)
@@ -377,97 +315,11 @@ module RPG
pushAnimation(@loopAnimations, anim)
end
def dispose_damage
return if @_damage_sprite.nil?
@_damage_sprite.bitmap.dispose
@_damage_sprite.dispose
@_damage_sprite = nil
@_damage_duration = 0
end
def dispose_animation
@animations.each { |a| a&.dispose_animation }
@animations.clear
end
def dispose_loop_animation
@loopAnimations.each { |a| a&.dispose_loop_animation }
@loopAnimations.clear
end
def blink_on
return if @_blink
@_blink = true
@_blink_count = 0
end
def blink_off
return unless @_blink
@_blink = false
self.color.set(0, 0, 0, 0)
end
def blink?
return @_blink
end
def effect?
return true if @_whiten_duration > 0
return true if @_appear_duration > 0
return true if @_escape_duration > 0
return true if @_collapse_duration > 0
return true if @_damage_duration > 0
@animations.each { |a| return true if a.effect? }
return false
end
def update
super
if @_whiten_duration > 0
@_whiten_duration -= 1
self.color.alpha = 128 - ((16 - @_whiten_duration) * 10)
end
if @_appear_duration > 0
@_appear_duration -= 1
self.opacity = (16 - @_appear_duration) * 16
end
if @_escape_duration > 0
@_escape_duration -= 1
self.opacity = 256 - ((32 - @_escape_duration) * 10)
end
if @_collapse_duration > 0
@_collapse_duration -= 1
self.opacity = 256 - ((48 - @_collapse_duration) * 6)
end
if @_damage_duration > 0
@_damage_duration -= 1
case @_damage_duration
when 38..39
@_damage_sprite.y -= 4
when 36..37
@_damage_sprite.y -= 2
when 34..35
@_damage_sprite.y += 2
when 28..33
@_damage_sprite.y += 4
end
@_damage_sprite.opacity = 256 - ((12 - @_damage_duration) * 32)
dispose_damage if @_damage_duration == 0
end
@animations.each { |a| a.update }
@loopAnimations.each { |a| a.update }
if @_blink
@_blink_count = (@_blink_count + 1) % 32
if @_blink_count < 16
alpha = (16 - @_blink_count) * 6
else
alpha = (@_blink_count - 16) * 6
end
self.color.set(255, 255, 255, alpha)
end
SpriteAnimation.clear
end
def update_animation
@animations.each { |a| a.update_animation if a&.active? }
end
@@ -476,16 +328,11 @@ module RPG
@loopAnimations.each { |a| a.update_loop_animation if a&.active? }
end
def x=(x)
@animations.each { |a| a.x = x if a }
@loopAnimations.each { |a| a.x = x if a }
super
end
def y=(y)
@animations.each { |a| a.y = y if a }
@loopAnimations.each { |a| a.y = y if a }
def update
super
@animations.each { |a| a.update }
@loopAnimations.each { |a| a.update }
SpriteAnimation.clear
end
end
end

View File

@@ -1,186 +0,0 @@
#===============================================================================
# Linear interpolation between two values, given the duration of the change and
# either:
# - the time passed since the start of the change (delta), or
# - the start time of the change (delta) and the current time (now)
#===============================================================================
def lerp(start_val, end_val, duration, delta, now = nil)
delta = now - delta if now
return start_val if delta <= 0
return end_val if delta >= duration
return start_val + (end_val - start_val) * delta / duration.to_f
end
#===============================================================================
#
#===============================================================================
class PointInterpolator
attr_reader :x
attr_reader :y
def initialize(oldx, oldy, newx, newy, frames)
restart(oldx, oldy, newx, newy, frames)
end
def restart(oldx, oldy, newx, newy, frames)
@oldx = oldx
@oldy = oldy
@newx = newx
@newy = newy
@frames = frames
@curframe = 0
@x = oldx
@y = oldy
end
def done?
@curframe > @frames
end
def update
return if done?
t = @curframe.to_f / @frames
rx1 = @oldx
rx2 = @newx
@x = rx1 + (t * (rx2 - rx1))
ry1 = @oldy
ry2 = @newy
@y = ry1 + (t * (ry2 - ry1))
@curframe += 1
end
end
#===============================================================================
#
#===============================================================================
class RectInterpolator
def initialize(oldrect, newrect, frames)
restart(oldrect, newrect, frames)
end
def restart(oldrect, newrect, frames)
@oldrect = oldrect
@newrect = newrect
@frames = [frames, 1].max
@curframe = 0
@rect = oldrect.clone
end
def set(rect)
rect.set(@rect.x, @rect.y, @rect.width, @rect.height)
end
def done?
@curframe > @frames
end
def update
return if done?
t = @curframe.to_f / @frames
x1 = @oldrect.x
x2 = @newrect.x
x = x1 + (t * (x2 - x1))
y1 = @oldrect.y
y2 = @newrect.y
y = y1 + (t * (y2 - y1))
rx1 = @oldrect.x + @oldrect.width
rx2 = @newrect.x + @newrect.width
rx = rx1 + (t * (rx2 - rx1))
ry1 = @oldrect.y + @oldrect.height
ry2 = @newrect.y + @newrect.height
ry = ry1 + (t * (ry2 - ry1))
minx = x < rx ? x : rx
maxx = x > rx ? x : rx
miny = y < ry ? y : ry
maxy = y > ry ? y : ry
@rect.set(minx, miny, maxx - minx, maxy - miny)
@curframe += 1
end
end
#===============================================================================
#
#===============================================================================
class SpriteInterpolator
X = 1
Y = 2
ZOOM_X = 3
ZOOM_Y = 4
COLOR = 5
OPACITY = 6
def initialize
@tweening = false
@tweensteps = []
@sprite = nil
@frames = 0
@step = 0
end
def tweening?
return @tweening
end
def tween(sprite, items, frames)
@tweensteps = []
if sprite && !sprite.disposed? && frames > 0
@frames = frames
@step = 0
@sprite = sprite
items.each do |item|
case item[0]
when X
@tweensteps[item[0]] = [sprite.x, item[1] - sprite.x]
when Y
@tweensteps[item[0]] = [sprite.y, item[1] - sprite.y]
when ZOOM_X
@tweensteps[item[0]] = [sprite.zoom_x, item[1] - sprite.zoom_x]
when ZOOM_Y
@tweensteps[item[0]] = [sprite.zoom_y, item[1] - sprite.zoom_y]
when COLOR
@tweensteps[item[0]] = [sprite.color.clone,
Color.new(item[1].red - sprite.color.red,
item[1].green - sprite.color.green,
item[1].blue - sprite.color.blue,
item[1].alpha - sprite.color.alpha)]
when OPACITY
@tweensteps[item[0]] = [sprite.opacity, item[1] - sprite.opacity]
end
end
@tweening = true
end
end
def update
if @tweening
t = @step.to_f / @frames
@tweensteps.length.times do |i|
item = @tweensteps[i]
next if !item
case i
when X
@sprite.x = item[0] + (item[1] * t)
when Y
@sprite.y = item[0] + (item[1] * t)
when ZOOM_X
@sprite.zoom_x = item[0] + (item[1] * t)
when ZOOM_Y
@sprite.zoom_y = item[0] + (item[1] * t)
when COLOR
@sprite.color = Color.new(item[0].red + (item[1].red * t),
item[0].green + (item[1].green * t),
item[0].blue + (item[1].blue * t),
item[0].alpha + (item[1].alpha * t))
when OPACITY
@sprite.opacity = item[0] + (item[1] * t)
end
end
@step += 1
if @step == @frames
@step = 0
@frames = 0
@tweening = false
end
end
end
end