[XP] 3D Battle Camera

Started by ThallionDarkshine, February 15, 2013, 07:50:29 pm

Previous topic - Next topic

ThallionDarkshine

February 15, 2013, 07:50:29 pm Last Edit: April 25, 2013, 08:30:27 pm by ThallionDarkshine
3D Battle Camera
Authors: ThallionDarkshine
Version: 0.4
Type: Battle Add-on
Key Term: Battle Add-on



Introduction

The default battle system is extremely boring and not dynamic at all. And so, here's a script that zooms in on the currently targeted enemy, using a parallax effect to make it appear somewhat 3D.


Features


  • Liven up the DBS with a 3D battle camera.

  • Customize zoom values and parallax amount.




Screenshots

Spoiler: ShowHide



Demo

None yet.


Script

Spoiler: ShowHide

#__END__
module Battle_Cam
  # the power of the parallax effect (0 - 1)
  #   note - don't use anything too high or it will look a bit weird
  PARALLAX_AMOUNT = 0.3
  # how fast to transition between targets (1 - 10)
  TRANSITION_SPEED = 7
  # how much to zoom in on the currently targeted battler
  TARGET_ZOOM = 1.3
  # how much to zoom in on the active battler
  ACTIVE_ZOOM = 1.2
  # how much to zoom in if there are multiple targets
  MULTI_ZOOM = 1.1
end

class Spriteset_Battle
  alias tdks_3d_cam_init initialize
  def initialize
    @cx = 320
    @cy = 160
    @zoom = 1
    @frames = 0
    @target_ind = -1
    tdks_3d_cam_init
  end
 
  def set_battler(battler = nil, tz = Battle_Cam::ACTIVE_ZOOM, speed = Battle_Cam::TRANSITION_SPEED)
    @target_pos = nil
    pind = @target_ind
    if battler.nil?
      @target_ind = -1
      @tz = 1
    else
      sprite = @enemy_sprites.detect { |i| i.battler == battler }
      @target_ind = @enemy_sprites.index(sprite)
    end
    unless @target_ind == pind and @tz == tz and @target_pos.nil?
      @tz = tz
      @frames = 100 / speed
    end
  end
 
  def set_index(ind = nil, tz = Battle_Cam::ACTIVE_ZOOM, speed = Battle_Cam::TRANSITION_SPEED)
    @target_pos = nil
    unless @target_ind == ind and @tz == tz and @target_pos.nil?
      @target_ind = ind.nil? ? -1 : ind
      @tz = tz
      @frames = 100 / speed
    end
    @tz = 1 if ind.nil?
  end
 
  def set_pos(tx = 320, ty = 160, tz = Battle_Cam::ACTIVE_ZOOM, speed = Battle_Cam::TRANSITION_SPEED)
    unless tx == @target_pos[0] and ty == @target_pos[1] and tz == @target_pos[2]
      @target_pos = [tx, ty]
      @tz = tz
      @frames = 100 / speed
    end
  end
 
  def effect?
    return true if @frames > 0
    # Return true if even 1 effect is being displayed
    for sprite in @enemy_sprites + @actor_sprites
      return true if sprite.effect?
    end
    return false
  end
 
  alias tdks_3d_cam_updt update
  def update
    tdks_3d_cam_updt
    update_3d_camera
  end
 
  def update_3d_camera
    unless @battleback_sprite.bitmap.nil?
      amnt = Battle_Cam::PARALLAX_AMOUNT
      @battleback_sprite.ox = @cx
      @battleback_sprite.oy = @cy
      @battleback_sprite.x, @battleback_sprite.y = 320, 160
      @battleback_sprite.x += (@cx - 320) * amnt * @zoom
      @battleback_sprite.y += (@cy - 160) * amnt * @zoom
      @battleback_sprite.zoom_x = @battleback_sprite.zoom_y = @zoom
    end
    pframes = @frames
    if @frames > 0 and !@target_ind.nil?
      if @target_ind == -1
        tx = 320
        ty = 160
      else
        sprite = @enemy_sprites[@target_ind]
        tx = sprite.battler.screen_x
        height = sprite.bitmap.nil? ? 0 : sprite.bitmap.height
        ty = sprite.battler.screen_y - height / 2
      end
      @frames -= 1
      @cx = @cx * @frames / (@frames + 1.0) + tx / (@frames + 1.0)
      @cy = @cy * @frames / (@frames + 1.0) + ty / (@frames + 1.0)
      @zoom = @zoom * @frames / (@frames + 1.0) + @tz / (@frames + 1.0)
    end
    @enemy_sprites.each { |sprite|
      height = sprite.bitmap.nil? ? 0 : sprite.bitmap.height
      width = sprite.bitmap.nil? ? 0 : sprite.bitmap.width
      tmpz = @zoom
      tmpy = (sprite.battler.screen_y - height / 2 - @cy) * @zoom + 160
      tmpx = (sprite.battler.screen_x - @cx) * @zoom + 320
      tmpoy = height / 2
      tmpox = width / 2
      if Module.constants.include?("Transitions") and Transitions.transitioning_out?(sprite)
        type = Transitions.transition_type(sprite)[1]
        if [3, 4].include?(type) or (type == 2 and Transitions.sprite(sprite)[7])
          sprite.zoom_x *= tmpz
          sprite.zoom_y *= tmpz
        else
          sprite.zoom_x = sprite.zoom_y = tmpz
        end
        if [0, 7].include?(type)
          sprite.ox += tmpox
          sprite.oy += tmpoy
        elsif type == 8
          sprite.ox = tmpox
          sprite.oy = (Transitions.sprite(sprite)[3].height - height) * @zoom / 2 + height / 2.0
        else
          sprite.ox, sprite.oy = tmpox, tmpoy
        end
        sprite.x, sprite.y = tmpx, tmpy
      else
        sprite.zoom_x = sprite.zoom_y = tmpz
        sprite.x, sprite.y = tmpx, tmpy
        sprite.ox, sprite.oy = tmpox, tmpoy
      end
    }
    if $scene.instance_variables.include?('@enemy_arrow') and pframes > 0
      arrow = $scene.instance_variable_get(:@enemy_arrow)
      arrow.update unless arrow.nil?
    end
  end
end

class Sprite_Battler
  alias tdks_3d_cam_updt update
  def update
    tdks_3d_cam_updt
  end
end

class Arrow_Enemy
  alias tdks_3d_cam_updt update
  def update
    tdks_3d_cam_updt
    unless self.enemy.nil?
      sprite = $scene.instance_variable_get(:@spriteset).instance_variable_get(:@enemy_sprites)
      sprite = sprite.detect { |i| i.battler == self.enemy }
      self.x, self.y = sprite.x, sprite.y + sprite.bitmap.height / 2
    end
  end
end

class Scene_Battle
  alias tdks_3d_cam_strt_p2 start_phase2
  def start_phase2
    @spriteset.set_index()
    tdks_3d_cam_strt_p2
  end
 
  alias tdks_3d_cam_strt_p5 start_phase5
  def start_phase5
    @spriteset.set_index()
    tdks_3d_cam_strt_p5
  end
 
  alias tdks_3d_cam_updt_p3_eslct update_phase3_enemy_select
  def update_phase3_enemy_select
    @spriteset.set_battler($game_troop.enemies[@enemy_arrow.index], Battle_Cam::TARGET_ZOOM)
    tdks_3d_cam_updt_p3_eslct
  end
 
  alias tdks_3d_cam_end_eslct end_enemy_select
  def end_enemy_select
    @spriteset.set_index() if Input.trigger?(Input::B)
    tdks_3d_cam_end_eslct
  end
 
  alias tdks_3d_cam_p3_setup_cmd_wndw phase3_setup_command_window
  def phase3_setup_command_window
    tdks_3d_cam_p3_setup_cmd_wndw
    @spriteset.set_index()
  end
 
  alias tdks_3d_cam_updt_p4_s2 update_phase4_step2
  def update_phase4_step2
    tdks_3d_cam_updt_p4_s2
    if @target_battlers.length == 1 and @target_battlers[0].is_a?(Game_Enemy)
      @spriteset.set_battler(@target_battlers[0], Battle_Cam::TARGET_ZOOM)
    elsif @target_battlers.length > 1 and @target_battlers.any? { |i| i.is_a?(Game_Enemy) }
      @spriteset.set_index(-1, Battle_Cam::MULTI_ZOOM)
    elsif @active_battler.is_a?(Game_Enemy)
      @spriteset.set_battler(@active_battler) unless @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 3
    else
      @spriteset.set_index()
    end
  end
end



Instructions

In the script.


Compatibility

Could have compatibility issues with some custom battle systems.


Credits and Thanks


  • ThallionDarkshine

  • Blizz for giving me the idea




Author's Notes

None

bigace

I don't really think that screenshot gives it justice. Maybe if it was a video it would look better, but as a still, all it look like is that you enlarged an enemy with zoom which doesn't really look 3D at all. Or am I miss understanding the concept?


Use Dropbox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account.

Blizzard

I think he was trying to make it work like in my game LL4. Keep in mind that I am using KGC's Pseudo 3D Camera script for that (I only tweaked the parameters a bit).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ThallionDarkshine

Blizz, you lied to me. Actually, I just assumed that you had made it yourself.
@bigace - The camera focuses on the currently targeted enemy and does a parallax effect with the battleback to give the illusion of depth.

Blizzard

That's the only script in my game that I didn't make myself. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ThallionDarkshine

The only script? When I saw a few other scripts in the database, I thought that they looked like they had been used in CP. Such as, Aqua's HP states script. I had never noticed that, and then I made a script that basically did the same thing, only not using states, to replicate the feature from CP.

Edit - And what about Fantasist's transition pack? Or did you only use your own transitions?

Blizzard

Yup, I did my own ones. In fact, Fantasist was the one who was inspired by my game to make the transitions pack. xD There are actually a lot of scripts that have been inspired by CP. Since I didn't want to release the scripts, people made their own versions.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ThallionDarkshine

February 16, 2013, 10:47:04 am #7 Last Edit: February 17, 2013, 11:53:13 am by ThallionDarkshine
Of course you made it first. That's what's been inspiring all my battle-related scripts, and the next script up is auras on the person that's speaking.

Edit - Update to version 0.2. This script is now compatible with my battler transitions script.

Mightylink

I am getting an error on line 109 with this script, I tried throwing it on a default new project in xp and it still wont work.

More specifically:
NameError Occured
uninitialized constant Spriteset_Battle::Transitions

Any idea whats going on here?

ThallionDarkshine

Fixed. It was having an error with my compatibility code with my battler transitions script.

Tapout

Awesome script! Works like a charm. Thank you for this.

ThallionDarkshine

April 24, 2013, 01:48:28 pm #11 Last Edit: April 25, 2013, 08:11:40 pm by ThallionDarkshine
Update to v 0.3. Fixed one little bug with the compatibility code for my Battler Transitions script.

Edit - Update to v0.4. Fixed another little bug with the compatibility code.