Lightning Dogder

7 de junho de 2013

Lightning Dogder é um script desenvolvido por SephirothSpawn e é demonstrado num minigame de mesmo nome.

O script é para o RPG Maker XP e precisa do SDK (basta adicionar o código logo acima do Main e abaixo do SDK).

Ele pode ser personalizado e demais configurações e detalhes estão nos comentários do script, logo abaixo:

#==============================================================================
# ** Lightning Dodger Mini-Game
#------------------------------------------------------------------------------
# SephirothSpawn
# 2006-03-31
# Version 1
#------------------------------------------------------------------------------
# * Instructions
#
# ~ Active Dodger Mini-Game
#   $game_temp.lightning_dodger = true
# ~ Deactivate Dodge Mini-Game
#   $game_temp.lightning_dodger = false
#
# ~ Creating Lightning Rods
#   - Make an event with Comment Line: Lightning Pole #
#   - Change Number with Number of tiles Pole Portects
#
# ~ Creating Random Strike Spot
#   - Make an event with Comment Line: Lightning Spot
#
# ~ Lightning Will Not Strike on Tiles with a 1 Rating
#------------------------------------------------------------------------------
# * Customization
# 
# ~ Deal Percent Damage
#   - Lightning_Percent_Damage = %
#
# ~ Deal Direct Damage
#   - Lightning_Direct_Damage = #
#
# ~ Setting Up Dodge Buttons
#   - Dodger_Buttons = [Input Constant, Input Constant, ...]
#   (Check the Help File for Input Constants)
#
# ~ Time Between Blast
#   - 100 + random 0...Lightning_Blast_Counter
#
# ~ Frames to Press Correct Button
#   - Reflex_Time = Frames
#
# ~ Strike Animations
#   - Dodge_Animation_ID = Animation ID for dodge Animation
#   - Hit_Animation_ID = Animation for Hit Blast
#------------------------------------------------------------------------------
# * Dodge Counter Syntax
#
# ~ Current Dodge Counter
#   - $game_party.dodge_count 
# ~ Record Dodge Count
#   - $game_party.dodge_record
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Lightning Dodger Mini-Game', 'SephirothSpawn', 1, '2006-03-31')

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Lightning Dodger Mini-Game') == true

#==============================================================================
# ** Lightning_Dodger
#==============================================================================

module Lightning_Dodger 
  #--------------------------------------------------------------------------
  # * Lightning Damage
  #   ~ To Deal Percent : LPD = %
  #   ~ To Deal Direct Amount : LDD = Amount
  #   ~ No Damage : Both = 0
  #--------------------------------------------------------------------------
  Lightning_Percent_Damage = 0
  Lightning_Direct_Damage = 100
  Leave_one_hp = false
  #--------------------------------------------------------------------------
  # * Dodger Buttons
  #   ~ Must Match with the Input Module Constants
  #--------------------------------------------------------------------------
  Dodger_Buttons = ['SHIFT', 'CTRL ']
  #--------------------------------------------------------------------------
  # * Lighting Blast Counter
  #   ~ The Number of Frames to next blast is
  #     - 100 + random number betwee 0 - LBC
  #--------------------------------------------------------------------------
  Lightning_Blast_Counter = 75
  #--------------------------------------------------------------------------
  # * Reflex Time
  #   ~ # of Frames to Push Button
  #--------------------------------------------------------------------------
  Reflex_Time = 20
  #--------------------------------------------------------------------------
  # * Animation IDs
  #--------------------------------------------------------------------------
  Dodge_Animation_ID = 34
  Hit_Animation_ID = 34
end

#==============================================================================
# ** Game_Temp
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :lightning_dodger
  attr_accessor :dodge_count
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_lightdodger_gametemp_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Adds Lightning Dodger Variable
    @lightning_dodger = false
    # Next Dodge Blast
    init_counter
    # Original Initialization
    seph_lightdodger_gametemp_init
  end
  #--------------------------------------------------------------------------
  # * Initialize Dodge Counter
  #--------------------------------------------------------------------------
  def init_counter
    # Computes next Dodge Counter
    @dodge_count = 100 + rand(Lightning_Dodger::Lightning_Blast_Counter)
  end
  #--------------------------------------------------------------------------
  # * Lightning Dodger
  #--------------------------------------------------------------------------
  def lightning_dodger=(state)
    # Change State
    @lightning_dodger = state
    return
  end
end

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :dodge_count
  attr_accessor :dodge_record
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_lightdodger_gameprty_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Sets Up Dodge Variables
    @dodge_count = 0
    @dodge_record = 0
    seph_lightdodger_gameprty_init
  end
  #--------------------------------------------------------------------------
  # * Successful Dodge
  #--------------------------------------------------------------------------
  def dodge_success
    # Increase Dodge Count
    @dodge_count += 1
    # Store Record
    if @dodge_count > @dodge_record
      @dodge_record = @dodge_count 
    end
  end
  #--------------------------------------------------------------------------
  # * Failed Dodge
  #--------------------------------------------------------------------------
  def dodge_failure
    # Resets Dodge Count
    @dodge_count = 0
  end
end

#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :damage
  attr_accessor :damage_pop
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_lightdodger_gamechr_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Sets Up Damage
    @damage = nil
    @damage_pop = false
    # Original Initialization
    seph_lightdodger_gamechr_init
  end
  #--------------------------------------------------------------------------
  # * Dodge
  #--------------------------------------------------------------------------
  def dodge
    # Gets Direction Facing
    case self.direction
    when 2 # Down
      # Directions
      directions = [8, 4, 6, 2]
      # Jump Loctions
      jump_spots = [[0, - 1], [- 1, 0], [1, 0], [0, -1]]
    when 4 # Left
      # Directions
      directions = [6, 2, 8, 4]
      # Jump Loctions
      jump_spots = [[1, 0], [0, 1], [0, - 1], [- 1, 0]]
    when 6 # Right
      # Directions
      directions = [4, 2, 8, 6]
      # Jump Loctions
      jump_spots = [[- 1, 0], [0, 1], [0, - 1], [1, 0]]
    when 8 # Up
      # Directions
      directions = [2, 4, 6, 8]
      # Jump Loctions
      jump_spots = [[0, 1], [-1, 0], [1, 0], [0, - 1]]
    end
    # Checks Moves
    for i in 0..3
      d = directions[i]
      if passable?(@x, @y, d)
        x_plus, y_plus = jump_spots[i][0], jump_spots[i][1]
        jump(x_plus, y_plus)
        return
      end
    end
  end
end

#==============================================================================
# ** Sprite_Character
#==============================================================================

class Sprite_Character < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_lightdodger_sprchar_update update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Orginal Update
    seph_lightdodger_sprchar_update
    # If Damage Pop
    return unless @character.is_a?(Game_Player)
    if @character.damage_pop
      damage(@character.damage, false)
      @character.damage = nil
      @character.damage_pop = false
    end
  end
end

#==============================================================================
# ** Window_LightningDodges
#==============================================================================

class Window_LightningDodges < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(436, 376, 196, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.visible = $game_temp.lightning_dodger
    self.opacity = 160
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 160, 32, 'Dodge Counter:')
    self.contents.draw_text(4, 32, 160, 32, 'Dodge Record:') 
    self.contents.font.color = normal_color
    self.contents.draw_text(- 4, 0, 160, 32, $game_party.dodge_count.to_s, 2)
    self.contents.draw_text(- 4, 32, 160, 32, $game_party.dodge_record.to_s, 2)
    @dodge_c, @dodge_r = $game_party.dodge_count, $game_party.dodge_record
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    unless $game_party.dodge_count == @dodge_c &&
      $game_party.dodge_record == @dodge_r
      refresh
    end
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_lightdodger_scnmap_main main
  alias seph_lightdodger_scnmap_update update
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Creates Blast Sprite
    @blast_sprite = RPG::Sprite.new
    # Creates Dodge Count Window
    @dodge_window = Window_LightningDodges.new
    # Dodging Off
    @dodging = false
    # Original Main Method
    seph_lightdodger_scnmap_main
    # Dispose Blast Sprite
    @blast_sprite.dispose
    # Dispose Dodge Count Window
    @dodge_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Dodge Count Window Visiblity
    @dodge_window.visible = $game_temp.lightning_dodger
    # If Lightning Dodger On
    if $game_temp.lightning_dodger
      # Updates Blast Sprite
      @blast_sprite.update
      # Update Dodge Window
      @dodge_window.update
      # If Dead
      if $game_party.actors[0].dead?
        $game_temp.gameover = true
      end
      # If Dodging On
      if @dodging
        update_lightning_dodging
      # Dodger Update
      else
        update_lightning_dodger
      end
    end
    # Original Update Method
    seph_lightdodger_scnmap_update
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Lightning Dodger
  #--------------------------------------------------------------------------
  def update_lightning_dodger
    # Lightning Strikes
    for event in $game_map.events.values
      unless event.list.nil?
        event_random_animation(event)
      end
    end
    # If Near Lightning Pole
    for event in $game_map.events.values
      unless event.list.nil?
        for i in 0...event.list.size
          if event.list[i].code == 108
            # Lighting Rod
            if event.list[i].parameters[0].include?('Lightning Pole')
              event.list[i].parameters[0].dup.sub(/(\d+)/, '')
              if check_range($game_player, event, $1.to_i)
                return
              end
            end
          end
        end
      end
    end
    # Terrain Tag Cover
    return if $game_player.terrain_tag == 1
    # Decrease Dodge Counter
    $game_temp.dodge_count -= 1
    # If Counter is 0
    if $game_temp.dodge_count == 0
      # Gets Random Input Button
      buttons = Lightning_Dodger::Dodger_Buttons
      button = buttons[rand(buttons.size)]
      # Does a Damage Pop
      $game_player.damage =  button
      $game_player.damage_pop = true
      # Resets Dodge Counter
      $game_temp.init_counter
      # Stores Button
      @button = button
      # Turns On Dodging Flag
      @dodging = true
      # Input Duration
      @input_duration = Lightning_Dodger::Reflex_Time
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Lightning Dodging
  #--------------------------------------------------------------------------
  def update_lightning_dodging
    # If Button is pressed
    if (eval "Input.trigger?(Input::#{@button})")
      # Show Dodge Animation
      x, y = $game_player.screen_x, $game_player.screen_y - 48
      case $game_player.direction
      when 2 ; y += 32
      when 4 ; x -= 32
      when 6 ; x += 32
      when 8 ; y -= 32
      end
      @blast_sprite.x = x
      @blast_sprite.y = y
      animation = $data_animations[Lightning_Dodger::Dodge_Animation_ID]
      @blast_sprite.animation(animation, false)
      # Dodge
      $game_player.dodge
      # Dodged Text
      $game_player.damage = 'Dodged!'
      $game_player.damage_pop = true
      # Turn Button Off
      @button = nil
      # Turn Dodging Off
      @dodging = false
      # Dodge Success
      $game_party.dodge_success
      return
    end
    # Decrease Input Duration
    @input_duration -= 1
    # If Duration is less than 0
    if @input_duration == 0
      # Turn Button Off
      @button = nil
      # Turn Dodging Off
      @dodging = false
      # Deal Player Damage
      deal_player_damage
      # Fail Dodge
      $game_party.dodge_failure
      # Show Hit Animation
      $game_player.animation_id = Lightning_Dodger::Hit_Animation_ID
    end
  end
  #--------------------------------------------------------------------------
  # * Event Random Animation
  #--------------------------------------------------------------------------
  def event_random_animation(event)
    for i in 0...event.list.size
      if event.list[i].code == 108
        # Random Lightning Spot
        if event.list[i].parameters[0] == 'Lightning Spot'
          if rand(500) == 0
            event.animation_id = Lightning_Dodger::Hit_Animation_ID
            # If Player over Event
            if $game_player.x == event.x && $game_player.y == event.y
              deal_player_damage
            end
          end
        end
        # Lighting Rod
        if event.list[i].parameters[0].include?('Lightning Pole')
          event.list[i].parameters[0].dup.sub(/(\d+)/, '')
          # Shows Random Lightning Blast
          if rand(500 / $1.to_i) == 0
            event.animation_id = Lightning_Dodger::Hit_Animation_ID
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Deal Player Damage
  #--------------------------------------------------------------------------
  def deal_player_damage
    # Deal Damage (Percent)
    percent_dmg = Lightning_Dodger::Lightning_Percent_Damage
    unless percent_dmg == 0
      damage = ($game_party.actors[0].maxhp * (percent_dmg / 100.0)).to_i
      if Lightning_Dodger::Leave_one_hp
        damage = [$game_party.actors[0].hp - 1, damage].min
      end
      $game_party.actors[0].hp -= damage
      $game_player.damage = damage
      $game_player.damage_pop = true
    end
    # Direct Damage
    direct_dmg = Lightning_Dodger::Lightning_Direct_Damage
    unless direct_dmg == 0
      if Lightning_Dodger::Leave_one_hp
        direct_dmg = [$game_party.actors[0].hp - 1, direct_dmg].min
      end
      $game_party.actors[0].hp -= direct_dmg
      $game_player.damage = direct_dmg
      $game_player.damage_pop = true
    end
  end
  #--------------------------------------------------------------------------
  # * Check Range
  #--------------------------------------------------------------------------
  def check_range(element, object, range = 1)
    x = (element.x - object.x) * (element.x - object.x)
    y = (element.y - object.y) * (element.y - object.y)
    r = x + y
    return r <= (range * range)
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

Download e ficha técnica

  • Download (clique com o botão esquerdo do mouse ou toque no link).
  • Desenvolvedores, publishers e/ou distribuidores: SephirothSpawn, 210KB
  • SO: Windows 98/98SE/Me/2000/XP/Vista/7
  • Licença: Grátis
  • Categoria: Programação XP
  • Tag: RPG Maker XP
  • Adicionado por: LichKing
  • Acessos: 47

Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Acesse aqui e saiba como. Obrigado!

Deixe um comentário

Inscreva-se na nossa newsletter!