Quantum Core
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Enhanced Battle Cursors

2 posters

Go down

Enhanced Battle Cursors Empty Enhanced Battle Cursors

Post  Fantasist Tue Jan 22, 2008 9:09 pm

Enhanced Battle Cursors

Version: 2.2b


Introduction

This script packages some nifty cursor movements and effects and the ability to use animations over the cursors.

Features

  • Animations are used for the cursor, which means the scope for variety is now virtually unlimited.
  • Can use two different animations for the actors and enemies


Script

Put this just below Arrow_Actor. DON'T USE THIS if you're using Tons of Addons, it's integrated already.
Code:
#==============================================================================
# Enhanced Battle Cursors v2.2 beta
# by Fantasist
#==============================================================================
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# - code reviewed, optimized, freed from potential bugs and beta tested by Blizzard
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Note: DO NOT USE THIS if you're using Tons of Addons!
#          This is already integrated there and will cause problems.
#------------------------------------------------------------------------------
# * Config (these can't be changed in-game)
#------------------------------------------------------------------------------
# Position
#      Set the position of the cursor
#
# 1) MONSTER_OFFSET: The height of the cursor from the monster graphic's base.
# 2) ACTOR_OFFSET: The height of the cursor from the actor graphic's base.
# 3) TOP: Whether the cursor is on the top of the monster or at the bottom.
MONSTER_OFFSET = 0
ACTOR_OFFSET = 0
TOP = true
#------------------------------------------------------------------------------
# Movement Type Config
#      Configuration for the movement types used
#
# 1) Phase_Range: The distance the cursor moves away from the height while
#    phasing.
# 2) Zoom_Factor: The amount the cursor zooms in and out. Recommended range is
#    from 0 to 1, refrain from using more than 2 digits after decimal.
# 3) EBC_Type: This is the configuration of animation types
#        [Anim or not(true/false), movement type, transition type]
#      available movement types  -> phase, zoom, spin, spin2
#      available transition types -> trans, default
#    If you are using animations (first parameter is true) then use numbers
#    instead of movement and transition types to determine the animation IDs
#    of the animations used. The first is the actor, the second is the enemy
#    animation ID.
PHASE_RANGE = 16
ZOOM_FACTOR = 0.2
EBC_TYPE = [false, 'phase', 'trans']
# EBC_type can be changed ingame, refer to $game_system.battle_cursor and
# set the new values. This change is being saved with the save file.
#==============================================================================

#==============================================================================
# ** Game Battler
#==============================================================================

class Game_Battler
 
  def height
    RPG::Cache.battler(@battler_name, 0).height
  end
 
  def width
    RPG::Cache.battler(@battler_name, 0).width
  end
 
end

#==============================================================================
# ** Game System
#==============================================================================

class Game_System
 
  attr_accessor :battle_cursor
 
  alias init_battle_cursor initialize
  def initialize
    init_battle_cursor
    @battle_cursor = EBC_TYPE
  end 
 
end

#==============================================================================
# ** Arrow_Base
#==============================================================================

class Arrow_Base < RPG::Sprite

  attr_reader  :index
  attr_reader  :help_window
   
  def initialize(viewport)
    super
    if $game_system.battle_cursor[0]
      tmp, @battler = $game_system.battle_cursor, nil
      @actor_cursor = (tmp[1].is_a?(Numeric) ? tmp[1] : 98)
      @enemy_cursor = (tmp[2].is_a?(Numeric) ? tmp[2] : 99)
    else
      # Main Sprite initialization
      self.bitmap = RPG::Cache.windowskin($game_system.windowskin_name)
      self.src_rect.set(128, 96, 32, 32)
      self.ox, self.oy, self.z = 16, 64, 2501
      # Sub-sprite initialization
      if animtype('trans')
        @sp2 = Sprite.new(viewport)
        @sp2.bitmap = self.bitmap
        @sp2.src_rect.set(160, 96, 32, 32)
        @sp2.ox, @sp2.oy, @sp2.z = self.ox, self.oy, self.z-1
      end
      # Variable initialization
      @rad = 0 if animtype('trans') || ['phase', 'zoom', 'spin2'].any? {|i| movetype(i)}
      @deg = 0 if movetype('spin')
      @battler = nil
      @blink_count = 0 if animtype('default')
    end
    @y, @index, @help_window = 0, 0, nil
    update
  end
 
  def movetype(type)
    return ($game_system.battle_cursor[1] == type)
  end
 
  def animtype(type)
    return ($game_system.battle_cursor[2] == type)
  end
 
  def index=(index)
    @index = index
    update
  end

  def help_window=(help_window)
    @help_window = help_window
    # Update help text (update_help is defined by the subclasses)
    update_help if @help_window != nil
  end

  def update
    super
      if $game_system.battle_cursor[0]
        # Update animation
        id = self.is_a?(Arrow_Actor) ? @actor_cursor : @enemy_cursor
        loop_animation($data_animations[id])
      else
      if @rad
        # Cycle @rad from 0 to 2 Pi
        if @rad < 2 * Math::PI
          @rad += Math::PI/(movetype('spin2') ? 30 : 10)
        else
          @rad = 0
        end
      end
      # Animations
      trans if animtype('trans')
      default if animtype('default')
      # Movement Types
      phase if movetype('phase')
      spin if movetype('spin')
      spin2 if movetype('spin2')
      zoom if movetype('zoom')
    end
    # Update Help Window
    update_help if @help_window != nil
  end

  def dispose
    @sp2.dispose unless @sp2 == nil || @sp2.disposed?
    super
  end

  #--------------------------------------------------------------------------
  # * Cursor Animations
  #--------------------------------------------------------------------------
  def trans
    self.opacity = (Math.sin(@rad)*255).round
  end
 
  def default
    @blink_count = (@blink_count + 1) % 8
    self.src_rect.set((@blink_count < 4 ? 128 : 160), 96, 32, 32)
  end

  #--------------------------------------------------------------------------
  # * Cursor Movements
  #--------------------------------------------------------------------------
  def phase
    @y = ((Math.sin(@rad))*PHASE_RANGE).round
  end

  def spin
    # Cycle @deg from 0 to 360
    self.angle = @deg = (@deg + 18) % 360
    @sp2.angle = @deg if @sp2
  end

  def spin2
    self.angle = (Math.sin(@rad)*360).round
    @sp2.angle = self.angle if @sp2
  end
 
  def zoom
    self.zoom_x = self.zoom_y = 1 + Math.sin(@rad)*ZOOM_FACTOR
    @sp2.zoom_x = self.zoom_x if @sp2
  end
 
end

#==============================================================================
# ** Arrow_Enemy
#==============================================================================

class Arrow_Enemy < Arrow_Base
   
  def enemy
    return $game_troop.enemies[@index]
  end

  def update
    super
    # Skip if indicating a nonexistant enemy
    $game_troop.enemies.size.times do
      break if self.enemy.exist?
      @index = (@index + 1) % $game_troop.enemies.size
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index = (@index + 1) % $game_troop.enemies.size
        break if self.enemy.exist?
      end
    # Cursor left
    elsif Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index = (@index + $game_troop.enemies.size - 1) % $game_troop.enemies.size
        break if self.enemy.exist?
      end
    end
    # Set sprite coordinates
    if self.enemy != nil
      self.x = self.enemy.screen_x
      if TOP
        if self.enemy.screen_y - self.enemy.height - PHASE_RANGE < 6
          self.y = self.enemy.screen_y - self.enemy.height / 2
        else
          self.y = self.enemy.screen_y - self.enemy.height
        end
      end
      self.y += -@y - MONSTER_OFFSET
      @sp2.x, @sp2.y = self.x, self.y if @sp2
    end
  end

  def update_help
    # Display enemy name and state in the help window
    @help_window.set_enemy(self.enemy)
  end
 
end

#==============================================================================
# ** Arrow_Actor
#==============================================================================

class Arrow_Actor < Arrow_Base
 
  def actor
    return $game_party.actors[@index]
  end
 
  def update
    super
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @index = (@index + 1) % $game_party.actors.size
    # Cursor left
    elsif Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @index = (@index + $game_party.actors.size - 1) % $game_party.actors.size
    end
    # Set sprite coordinates
    if self.actor != nil
      self.x = self.actor.screen_x
      self.y = self.actor.screen_y - 160
      self.y += -@y - ACTOR_OFFSET
      @sp2.x, @sp2.y = self.x, self.y if @sp2
    end
  end
 
  def update_help
    # Display actor status in help window
    @help_window.set_actor(self.actor)
  end
 
end

Instructions

  • Make a new page in the script editor just below Arrow_Actor and paste this script into it. DON'T USE THIS if you're using Tons of Addons. This is already integrated and will cause problems.
  • Other instructions in script header.


Version History

Moving Battle Cursor
1.0 (06-27-2007)
- The original script
1.1 (06-29-2007)
- Aliased everything which increases compatibility
- Used sin function to get smoother movement
2.0 (06-30-2007)
- Thanks to Blizzard the code is really optimized
- Doesn't rewrite anything, it aliases itself into Arrow_Base
- Almost non-existent lag unlike previous versions
2.1 (07-02-2007)
- Adds flashing to the cursor
- The last of this series

Enhanced Battle Cursors
Alpha 1 (16-08-2007) (Not released)
- Added more movement types
- Use of too many variables
Alpha 2 (17-08-2007) (Not released)
- Organized the code a bit
- Tried using lots of 'if' statements everywhere to increase speed
1.0 (17-08-2007)
- Optimized to the best extent I could
- Added Cursor Presets 'CP(Chaos Project)' and 'SC(Super Crosshair)'
1.1 (17-08-2007)
- Compatibility with Tons of Add-ons v4.98
- Added movement type 'Spin2'
1.2 (18-08-2007)
- Fixed the update problem of Window_Help
1.3 (03-09-2007) (Not released)
- Used the y of the sprite class instead of offset oy
- Removed Cursor Presets
- Added an option to set cursor height
1.4 (05-09-2007)
- Added an option to set different heights for enemies and actors
- Added customization options for Phase and Zoom
2.0 (Alpha 1) (22-09-2007)
- Completely overworked, and used animations for the cursor(rendering the cursor in the windowskin useless)
2.1 (Alpha) (??-??-2007)
- Integrated v2.0 and v1.4, but very buggy
2.1 (Beta) (??-??-2007)
- Code reviewed, optimized integrated into Tons and freed from potential bugs by Blizzard
2.2 (Beta) (22-01-2008)
- Made it so that if the cursor is above the screen, it's brought down a bit. THIS IS INDEPENDANT FROM TONS.


Credits and Thanks

Thanks:
Blizzard, for helping me and sharing his knowledge with me.
Credits:
Fantasist, for making.

Fantasist
Admin

Posts : 53
Join date : 2008-01-13

https://quantumcore.forumotion.com

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Nortos Wed Jan 23, 2008 6:29 am

this is one I think only enhanced battle cursors I've seen and it was one your first scripts I was really impressed Smile

Nortos

Posts : 32
Join date : 2008-01-22

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Fantasist Wed Jan 23, 2008 8:07 pm

ty Very Happy
Thanks to Bliz it's optimized. I have a next version in mind, but I'm just too lazy, it's still half way and it's been more than a month since I started working on it. I wanted to post the new version in neoCP, that's why I didn't post this yet. But for this forum, I need content, so I seperated it from Tons and added a few features. Just so you know, here are the new features from the one in Tons:

1) You can chose if the cursor is on the monster's top, it recognises the height and positions itself. The offset option still works perfectly.
2) Many times, the cursor goes above the screen if TOP is enabled, especially if the battler is large or the monster is at the top. But I discovered it because I was using 3DPBC, a camera script. So if there is a chance the cursor goes above the screen, it's brought down a bit so that it's not on the top, but half of the battler's height.

Fantasist
Admin

Posts : 53
Join date : 2008-01-13

https://quantumcore.forumotion.com

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Nortos Wed Jan 23, 2008 8:18 pm

cool I'm looking forward to an update Smile. P.S know anywhere I can learn how to implement event switches into a script? I think would be valuable for me

Nortos

Posts : 32
Join date : 2008-01-22

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Fantasist Wed Jan 23, 2008 8:47 pm

Refering to a switch is just like refering to variable:

To refer to switch 24, it's like this:

$game_switches[24] = true/false

A switch can be either true(ON) or false(OFF). Simple enough, right?

Fantasist
Admin

Posts : 53
Join date : 2008-01-13

https://quantumcore.forumotion.com

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Nortos Thu Jan 24, 2008 5:21 am

k ty than I think I got it how to do a journal with indexed pages and switches

Nortos

Posts : 32
Join date : 2008-01-22

Back to top Go down

Enhanced Battle Cursors Empty Re: Enhanced Battle Cursors

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum