Ogłoszenie 

Uwaga! To forum jest w trybie offline.
Wszelką pomoc uzyskasz pod adresem
forum.ultimateam.pl


Administracja Forum


Poprzedni temat «» Następny temat
Char/Battler Sprite a'la RPG Maker VX
Autor Wiadomość
Mateusz SSJ8 




Preferowany:
RPG Maker XP

Pomógł: 1 raz
Dołączył: 07 Sty 2012
Posty: 46
Skąd: Polska
Wysłany: Wto 21 Lut, 2012 09:35
Char/Battler Sprite a'la RPG Maker VX
~ Charsety/ Battlery jak w RPG Makerze VX ~


Krótki opis:
Skrypt nie zmienia sposobu wyświetlania Charów/Battlerów, ale wprowadza klasę, którą można zastąpić domyślną klasę RPG::Sprite. Ułatwia to port skryptów z RPG Makera XP do nowszego.

Autor:
Mateusz SSJ8, cogwheel, Enterbrain

Kompatybilność:
RPG Maker XP

Skrypt:
Spoiler:

Kod:
class Sprite_Base < Sprite
  CollapseDuration = 40
  EscapeDuration = 40
  AppearDuration = 40
  WhitenDuration = 40
  def self.collapse_color
    return text_color(25)
  end
 
  def initialize(viewport=nil)
    super(viewport)
    @loop_animations = []
    @animations = []
    @damages = []
    @whiten_duration = 0
    @appear_duration = 0
    @escape_duration = 0
    @collapse_duration = 0
    @blink = false
    @blink_count = 0
  end
 
  def dispose
    super
    dispose_animations
  end
 
  def update
    super
    update_whiten
    update_appear
    update_escape
    update_collapse
    update_damages
    update_animations
    update_loop_animation
    update_blink
  end
 
  def update_whiten
    if @whiten_duration > 0
      @whiten_duration -= 1
      self.color.alpha = 128 - (16 - @whiten_duration) * 10
    end
  end
  def update_appear
    if @appear_duration > 0
      @appear_duration -= 1
      self.opacity = (16 - @appear_duration) * 16
    end
  end
  def update_escape
    if @escape_duration > 0
      @escape_duration -= 1
      self.opacity = 256 - ((32 - @escape_duration) * 10)
    end
  end
  def update_collapse
    if @collapse_duration > 0
      @collapse_duration -= 1
      self.opacity = 256 - (48 - @collapse_duration) * 6
    end
  end
  def update_damages
    for damage in @damages
      damage.update
    end
    dispose_invalid_damages
  end
  def update_animations
    for anime in @animations
      anime.update
    end
    dispose_invalid_animations
  end
  def update_loop_animation
    for i in @loop_animations
      i.update
    end
  end
  def update_blink
    if @blink == true
      @blink_count = (@blink_count + 1) % 32
      alpha = [16 - @blink_count, @blink_count - 16].min * 6
      self.color.set(255, 255, 255, alpha)
    end
  end
 
 
 
  def loop_animation(animations)
    result = false
    for a in animations
      result = true unless @loop_animations.include?(a)
    end
    @loop_animations.clear
    for a in animations
      @loop_animations[a] = Sprite_Animation.new(self, a, false, true)
    end
  end
 
  def animation(anime)
    @animations.push(Sprite_Animation.new(self, anime[0], anime[1], false))
  end
  def damage(num, crit, color=0)
    @damages.push(Sprite_Damage.new(self, num, crit, color))
  end
 
  def self.skin
    return Cache.windowskin($game_window.skin_name, $game_window.skin_hue)
  end
  def self.text_color(n)
    x = 156 + (n % 8)
    y = 28 + (n / 8)
    return self.skin.get_pixel(x, y)
  end
 
 
 
  def dispose_invalid_animations
    for anime in @animations.clone
      next if anime.duration > 0
      anime.dispose
      @animations.delete(anime)
    end
  end
  def dispose_animations
    for anime in @animations.clone
      @animations.delete(anime)
      anime.dispose
    end
  end
 
 
 
  def dispose_invalid_damages
    for damage in @damages.clone
      next if damage.duration > 0
      damage.dispose
      @damages.delete(damage)
    end
  end
 
  def effect?
    return (!@damages.empty? or !@animations.empty? or @collapse_duration > 0)
  end
  def array_effect
    return true unless @animations.empty?
  end
 
  def collapse
    nc = Sprite_Base.collapse_color
    self.color.set(nc.red, nc.green, nc.blue, nc.alpha)
    @collapse_duration = CollapseDuration
  end
 
 
  def blink_on
    @blink_count = 0
    @blink = true
  end
  def blink_off
    @blink = false
    @blink_count = 0
  end
 
end




class Sprite_Animation < Sprite_Base
  attr_reader :duration
  def initialize(pose, id, hit, loop)
    super(pose.viewport)
    @pose = pose
    @id = id
    @hit = hit
    @loop = loop
    @index = 0
    @mirror = false
    self.z = 5000
    start
    start_default
  end
  def data
    return $data_animations[@id]
  end
  def start
    @duration = 0
    return unless self.data.is_a?(RPG::Animation)
    @frames = self.data.frames
    @sprites = []
    @duration = (self.data.frame_max * 2)
    for i in 0...15
      sprite = Sprite.new
      sprite.bitmap = Cache.animation(self.data.animation_name, self.data.animation_hue)
      sprite.visible = false
      @sprites.push(sprite)
    end
  end
  def start_default
    if self.data.position == 3
      if self.viewport == nil
        self.ox = 640 / 2
        self.oy = 480 / 2
      else
        self.ox = self.viewport.rect.width / 2
        self.oy = self.viewport.rect.height / 2
      end
    else
      self.ox = @pose.x - @pose.ox + (@pose.width / 2)
      self.oy = @pose.y - @pose.oy + (@pose.height / 2)
      case self.data.position
      when 0
        self.oy -= @pose.height / 2
      when 2
        self.oy += @pose.height / 2
      end
    end
  end
 
  def dispose
    for sprite in @sprites
      sprite.bitmap.dispose
      sprite.dispose
    end
    super
  end
 
  def update
    super
    return if self.data == nil
    if @loop
      update_loop
    else
      update_once
    end
  end
  def update_once
    frame_index = Integer(((self.data.frame_max * 2) - @duration) / 2)
    update_frames(frame_index)
    update_timing(frame_index)
    @duration -= 1 if @duration > 0
  end
  def update_loop
    frame_index = Integer(@index / 2)
    update_frames(frame_index)
    update_timing(frame_index)
    @index += 1
    @index %= (self.data.frame_max * 2)
  end
 
  def update_frames(frame_index)
    frame = self.data.frames[frame_index]
    return hide_sprites if frame == nil
    cell_data = frame.cell_data
    for i in 0...15
      sprite = @sprites[i]
      next if sprite == nil
      pattern = cell_data[i, 0]
      if pattern == nil or pattern == -1
        sprite.visible = false
        next
      end
      sprite.visible = true
      sprite.src_rect.set(pattern % 5 * 192, pattern % 100 / 5 * 192, 192, 192)
      update_mirror(sprite, i, cell_data)
      update_position(sprite, i, cell_data)
    end
  end
 
  def update_mirror(sprite, index, sdata)
    if @mirror
      sprite.x = self.ox - sdata[index, 1]
      sprite.y = self.oy - sdata[index, 2]
      sprite.angle = (360 - sdata[index, 4])
      sprite.mirror = (sdata[index, 5] == 0)
    else
      sprite.x = self.ox + sdata[index, 1]
      sprite.y = self.oy + sdata[index, 2]
      sprite.angle = sdata[index, 4]
      sprite.mirror = (sdata[index, 5] == 1)
    end
  end
 
  def update_position(sprite, index, sd)
      sprite.z = self.z + 300
      sprite.ox = 96
      sprite.oy = 96
      sprite.zoom_x = sd[index, 3] / 100.0
      sprite.zoom_y = sd[index, 3] / 100.0
      sprite.opacity = sd[index, 6] * self.opacity / 255.0
      sprite.blend_type = sd[index, 7]
  end
 
  def hide_sprites
    for sprite in @sprites
      sprite.visible = false
    end
  end
 
  def update_timing(frame_index)
    for timing in self.data.timings
      process_time(timing, frame_index) if (@duration % 2 == 0)
    end
  end
 
  def process_time(timing, frame)
    return unless frame == timing.frame
    $game_system.se_play(timing.se)
    case timing.flash_scope
    when 1
      @pose.flash(timing.flash_color, timing.flash_duration * 2)
    when 2
      self.viewport.flash(timing.flash_color, timing.flash_duration * 2) if self.viewport.is_a?(Viewport)
    when 3
     @pose.flash(nil, flash_duration * 2)
    end
  end

end







class Sprite_Damage < Sprite_Base
 
  def actor_damage_hp
    return Color.new(255, 255, 255, 255)
  end
  def actor_damage_sp
    return Color.new(255, 160, 160, 255)
  end
  def actor_damage_st
    return Color.new(255, 255, 0, 255)
  end
  def actor_heal_hp
    return Color.new(0, 210, 0, 255)
  end
  def actor_heal_sp
    return Color.new(0, 160, 255, 255)
  end
  def actor_heal_st
    return Color.new(0, 192, 255, 255)
  end
  def enemy_damage_hp
    return Color.new(255, 0, 0, 255)
  end
  def enemy_damage_sp
    return Color.new(0, 192, 255, 255)
  end
  def enemy_damage_st
    return Color.new(0, 255, 0, 255)
  end
  def enemy_heal_hp
    return Color.new(0, 0, 255, 255)
  end
  def enemy_heal_sp
    return Color.new(200, 200, 0, 255)
  end
  def enemy_heal_st
    return Color.new(255, 160, 0, 255)
  end
  def text
    return Color.new(255, 200, 0, 255)
  end
 
 attr_reader :duration
  def initialize(pose, num, crit, color)
    @pose = pose
    super(@pose.viewport)
    @num = num
    @crit = crit
    self.z = 1000
    self.bitmap = Bitmap.new(128, 64)
    @color = color
    @duration = 40
    @plus_x = 0
    @plus_y = -20
    @adjust_x = 0
    @adjust_y = 0
    initialize_display
    update_display
  end
  def initialize_display
    txt = ""
    for i in 0...@crit.size
      case @crit[i]
      when -1 then txt += "Pudło!"
      when 0 then txt += "Unik!"
      when 2 then txt += "Podwójne"
      when 3 then txt += "Super"
      when 15 then txt += "Zabójczy"
      end
      txt += " + " if [-1, 0, 2, 3, 15].include?(@crit[i+1])
    end
    self.bitmap.font.name = "Arial Black"
    self.bitmap.font.size = 24
    self.bitmap.font.color = Color.new(0, 0, 0, 255)
    self.bitmap.draw_text(0, 0, 126, 32, txt, 1)
    self.bitmap.draw_text(2, 0, 126, 32, txt, 1)
    self.bitmap.draw_text(0, 2, 126, 32, txt, 1)
    self.bitmap.draw_text(2, 2, 126, 32, txt, 1)
    self.bitmap.font.color = search_color
    self.bitmap.draw_text(1, 1, 126, 32, txt, 1)
    self.bitmap.font.size = 28
    self.bitmap.font.color = Color.new(0, 0, 0, 255)
    self.bitmap.draw_text(0, 32, 126, 32, @num.abs.to_s, 1)
    self.bitmap.draw_text(2, 32, 126, 32, @num.abs.to_s, 1)
    self.bitmap.draw_text(0, 34, 126, 32, @num.abs.to_s, 1)
    self.bitmap.draw_text(2, 34, 126, 32, @num.abs.to_s, 1)
    self.bitmap.font.color = search_color
    self.bitmap.draw_text(1, 33, 126, 32, @num.abs.to_s, 1)
  end
 
  def search_color
    case @color
    when 0 then colors1 = [[actor_damage_hp, actor_heal_hp],
      [enemy_damage_hp, enemy_heal_hp]]
    when 1 then colors1 = [[actor_damage_sp, actor_heal_sp],
      [enemy_damage_sp, enemy_heal_sp]]
    when 2 then colors1 = [[actor_damage_st, actor_heal_st],
      [enemy_damage_st, enemy_heal_st]]
    when 4 then return Text
    end
    case @pose.battler
    when Game_Actor then colors2 = colors1[0]
    when Game_Enemy then colors2 = colors1[1]
    else
      return Window_Base.text_color(0)
    end
    if @num.is_a?(Numeric)
      return colors2[0] if @num >= 0
      return colors2[1]
    end
  end
 
  def dispose
    self.bitmap.dispose
    super
  end
  def update
    super
    update_display
    @duration -= 1 if @duration > 0
  end
  def update_display
    self.x = @pose.x
    self.y = @pose.y
    @adjust_x += @plus_x
    @adjust_y += @plus_y
    self.ox = (self.bitmap.width / 2)
    self.oy = @pose.oy + (self.bitmap.height / 2)
    if @duration > 20
      self.x += (@adjust_x / 10)
      @plus_x += 0
      self.y += (@adjust_y / 10)
      @plus_y += 2
    end
    if @duration > 10
      self.opacity = 255 * @pose.opacity / 255
    else
      self.opacity = [0, 255 * @duration / 10].max * @pose.opacity / 255
    end
  end
 
end


Dodatkowe informacje:
Skrypt pomaga w tworzeniu interfejsu jak w "F-Zero GX", co NIE jest wymagane go korzystania z niego.
________________________
Ryzykując, że zrobisz super gniota, możesz zrobić super hit lub super gniota.
 
 
 
shiwt 




Preferowany:
RPG Maker XP

Pomógł: 13 razy
Dołączył: 02 Lip 2010
Posty: 131
Skąd: z Polski
Wysłany: Wto 21 Lut, 2012 17:45
Kolejny skrypt Mateusza, którego nie wiem jak używać x_X
________________________

http://www.ultimateam.pl/viewtopic.php?t=6177

http://www.ultimateam.pl/...p?p=61308#61308

http://www.ultimateam.pl/...p?p=73767#73767
 
 
Wyświetl posty z ostatnich:   
Odpowiedz do tematu
Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Nie możesz załączać plików na tym forum
Możesz ściągać załączniki na tym forum
Dodaj temat do Ulubionych
Wersja do druku

Skocz do:  

Powered by phpBB modified by Przemo © 2003 phpBB Group | Template Klam by Ayene