Help With Battle Camera

Started by Mightylink, October 30, 2008, 09:25:14 pm

Previous topic - Next topic

Mightylink

October 30, 2008, 09:25:14 pm Last Edit: October 30, 2008, 09:26:48 pm by Mightylink
I got this script and its been really awesome:

Spoiler: ShowHide
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/  ◆戦闘カメラ - KGC_BattleCamera◆
#_/----------------------------------------------------------------------------
#_/ 戦闘中の視点移動機能を導入します。
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

#==============================================================================
# ★ カスタマイズ項目 ★
#==============================================================================

module KGC
# ◆カメラ移動速度初期値
BC_SPEED_INIT = 24
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

$imported["BattleCamera"] = true
$imported["Base Reinforce"] = true

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Game_Enemy
#==============================================================================

class Game_Enemy < Game_Battler
attr_reader :origin_x, :origin_y
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KGC_BattleCamera initialize
def initialize(troop_id, member_index)
  # 元の処理を実行
  initialize_KGC_BattleCamera(troop_id, member_index)

   @origin_x = $data_troops[@troop_id].members[@member_index].x
  @origin_y = $data_troops[@troop_id].members[@member_index].y
end
#--------------------------------------------------------------------------
# ● バトル画面 X 座標の取得
#--------------------------------------------------------------------------
def screen_x
   return @origin_x - $scene.camera.x * self.zoom
end
#--------------------------------------------------------------------------
# ● バトル画面 Y 座標の取得
#--------------------------------------------------------------------------
def screen_y
   return @origin_y - $scene.camera.y * self.zoom
end
#--------------------------------------------------------------------------
# ● 倍率の取得
#--------------------------------------------------------------------------
def zoom
  if $game_variables[25] == 0
    n = (1.00 + $scene.camera.z / 512.00) * ((@origin_y - 304) / 256.00 + 1)
  else
    n = 1
  end
  return n
end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Sprite_Battler
#==============================================================================

class Sprite_Battler < RPG::Sprite
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KGC_BattleCamera update
def update
   # 元の処理を実行
    update_KGC_BattleCamera
  return if @battler == nil
   if $game_variables[25] == 0
     if @battler.is_a?(Game_Enemy)
   # 倍率調整
       self.zoom_x = self.zoom_y = @battler.zoom
     end
   end
end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Spriteset_Battle
#==============================================================================

class Spriteset_Battle
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
    alias update_KGC_BattleCamera update

def update
  # 元の処理を実行
  update_KGC_BattleCamera

  if $DEBUG
    if Input::trigger?(Input::Z)
      c = $scene.camera
      zoom = c.z / 512.00 + 1
      p "#{c.x}, #{c.y}, #{c.z}"
      p "#{@battleback_sprite.x + 320}, #{@battleback_sprite.y + 304}, #{zoom}"
    end
  end
  # カメラ移動判定
  if $game_variables[25] == 0
  cx, cy, cz = $scene.camera.x, $scene.camera.y, $scene.camera.z
  bx, by = @battleback_sprite.x + 320, @battleback_sprite.y + 304
  if bx != cx || by != cy || @bz != cz
    # 倍率調整
    zoom = cz / 512.00 + 1
    @battleback_sprite.zoom_x = zoom * 1.5
    @battleback_sprite.zoom_y = zoom * 1.5
    # 全体化判定
    if $imported["Base Reinforce"]# && KGC::BR_BATTLEBACK_FULL
      @battleback_sprite.ox = @battleback_sprite.bitmap.width * 0.52 # X OFFSET!
      @battleback_sprite.oy = @battleback_sprite.bitmap.height / 2
      mag_x = 600.0 / @battleback_sprite.bitmap.width
      mag_y = 300.0 / @battleback_sprite.bitmap.height
      @battleback_sprite.zoom_x *= mag_x
      @battleback_sprite.zoom_y *= mag_y
    end
    # 座標調整
    @battleback_sprite.x = -cx * zoom / 2 - 320 + @battleback_sprite.ox * 2
    @battleback_sprite.y = -cy * zoom / 2 - 144 + @battleback_sprite.oy * 2
    @bz = cz
  end
  end
end
end


#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Camera
#------------------------------------------------------------------------------
#  戦闘中のカメラを扱うクラスです。
#==============================================================================

class Camera
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :x, :y, :z
attr_accessor :move_speed
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
  @x, @y, @z = 0, 0, 0
  @move_x = @move_y = @move_z = 0
  @move_speed = KGC::BC_SPEED_INIT
end
#--------------------------------------------------------------------------
# ● 移動
#--------------------------------------------------------------------------
def move(x, y, z)
   @move_x, @move_y, @move_z = x - @x - 320, y - @y - 160, z - @z
end
#--------------------------------------------------------------------------
# ● 対象エネミーへ移動
#--------------------------------------------------------------------------
def move_target(target)
     return if target == nil || !target.is_a?(Game_Enemy)
  if $game_variables[25] == 0
  tx, ty = target.origin_x, target.origin_y - 144
  tz = (304 - target.origin_y) * 5
  move(tx, ty, tz)
  end
end
#--------------------------------------------------------------------------
# ● 中央へ移動
#--------------------------------------------------------------------------
def centering
  @move_x, @move_y, @move_z = -@x, -@y, -@z
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def update
  # X座標移動
   if $game_variables[25] == 0
  mv = [[@move_x.abs * @move_speed / 160, 1].max, @move_speed].min
  if @move_x > 0
    @x += mv
    @move_x = [@move_x - mv, 0].max
  elsif @move_x < 0
    @x -= mv
    @move_x = [@move_x + mv, 0].min
  end
  # Y座標移動
  mv = [[@move_y.abs * @move_speed / 160, 1].max, @move_speed].min
  if @move_y > 0
    @y += mv
    @move_y = [@move_y - mv, 0].max
  elsif @move_y < 0
    @y -= mv
    @move_y = [@move_y + mv, 0].min
  end
  # Z座標移動
  mv = [[@move_z.abs * @move_speed / 96, 1].max, @move_speed * 2].min
  if @move_z > 0
    @z += mv
    @move_z = [@move_z - mv, 0].max
  elsif @move_z < 0
    @z -= mv
    @move_z = [@move_z + mv, 0].min
  end
  end
end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Scene_Battle (分割定義 1)
#==============================================================================

class Scene_Battle
attr_reader :camera
#--------------------------------------------------------------------------
# ● メイン処理
#--------------------------------------------------------------------------
alias main_KGC_BattleCamera main
def main
  # カメラ作成
    @camera = Camera.new
    # 元の処理を実行
    main_KGC_BattleCamera
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KGC_BattleCamera update
def update
   @camera.update

  # 元の処理を実行
  update_KGC_BattleCamera
end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Scene_Battle (分割定義 3)
#==============================================================================

class Scene_Battle
#--------------------------------------------------------------------------
# ● フレーム更新 (アクターコマンドフェーズ : エネミー選択)
#--------------------------------------------------------------------------
alias update_phase3_enemy_select_KGC_BattleCamera update_phase3_enemy_select
def update_phase3_enemy_select
  # 選択対象をズームアップ
  if $game_variables[25] == 0
  if !$imported["ActiveCountBattle"] || @action_battler == nil
    @camera.move_target(@enemy_arrow.enemy)
  end
  end
  # 元の処理を実行
  update_phase3_enemy_select_KGC_BattleCamera
end
#--------------------------------------------------------------------------
# ● エネミー選択終了
#--------------------------------------------------------------------------
alias end_enemy_select_KGC_BattleCamera end_enemy_select
def end_enemy_select
  # カメラを中央へ戻す
  if $game_variables[25] == 0
  if !$imported["ActiveCountBattle"] || @action_battler == nil
    @camera.move(320, 160, 0)
  end
end
# 元の処理を実行
  end_enemy_select_KGC_BattleCamera
end
end
#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Scene_Battle (分割定義 4)
#==============================================================================

class Scene_Battle
#--------------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 3 : 行動側アニメーション)
#--------------------------------------------------------------------------
alias update_phase4_step3_KGC_BattleCamera update_phase4_step3
def update_phase4_step3
  # カメラ移動
   if $game_variables[25] == 0
  if @active_battler.is_a?(Game_Actor) && @target_battlers != []
    if @target_battlers.size > 1
      @camera.move(320, 160, -96)
    else
      @camera.move_target(@target_battlers[0])
    end
  elsif @active_battler.is_a?(Game_Enemy)
    @camera.move_target(@active_battler)
  end
  end
  # 元の処理を実行
  update_phase4_step3_KGC_BattleCamera
end

#--------------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ)
#--------------------------------------------------------------------------
alias update_phase4_step6_KGC_BattleCamera update_phase4_step6
def update_phase4_step6
  # カメラを初期位置へ移動
     @camera.centering

  # 元の処理を実行
  update_phase4_step6_KGC_BattleCamera
end
end


It works fine but now that I got into the habbit of making my own battlebacks I was wondering if it was possible to edit this script to allow 1024x640 size battle backs, currently when I use them the background shifts down right and doesnt strech properly, I was hoping to make high res battlebacks so it wouldnt look so pixelated when it zooms in.

Sorry the comments are not in english v_v

I am starting to learn this but im still doing basic window and cms tutorials, I have no idea what to fix in this script or even if its possible.

Fantasist

I've been trying to do the exact same thing for the exact same reason, but I couldn't figure out the numbers in the script. They're hard-coded for the default 640x320 resolution. I should try REALLY hard yet again, or someone more experienced should do it for us noobs -_-
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

Mess around with the zoom factors, that's what needs to be changed. i.e. increasing the factors by 100% will require 1280x640 sized backgrounds.
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.

Mightylink

so basicly just double all the zooms?

Blizzard

Not double, halve them. o.o Sorry, my bad.
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.

bnecitizen

When I try running the game with this script, I get an error.

Script 'Battle Cam' line18: NoMethodError occurred.
undefined method'[]=' for nil:NilClass

Why is this happening?? Such a shame :(

KK20

Holy crap, someone threw a Phoenix Down here!

What RM engine are you using? I believe $imported is meant for VX or VXA.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

bnecitizen

April 11, 2013, 12:10:53 am #7 Last Edit: April 11, 2013, 12:29:02 am by KK20
Quote from: bnecitizen on April 10, 2013, 11:32:39 pm
Quote from: KK20 on April 10, 2013, 11:18:35 pm
Holy crap, someone threw a Phoenix Down here!

What RM engine are you using? I believe $imported is meant for VX or VXA.

I'm using RMXP, is $imported in the script?


Edit: Nevermind  :O.o:

So the script is not for RMXP? just VX and ACE?

KK20

I forgot if SDK used that $imported gimmick (never used it, never studied it). After actually researching, it seems this was built with RMXP in mind. Just curious, have you tried deleting those $imported lines?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

bnecitizen

Yes I just tried to delete the line that use imported, the script then works, but i dont think it works as well as it should. Its quite dramatic and strange.

bigace

Quote from: KK20 on April 11, 2013, 12:28:22 am
I forgot if SDK used that $imported gimmick (never used it, never studied it). After actually researching, it seems this was built with RMXP in mind. Just curious, have you tried deleting those $imported lines?


actually my RMXP scripts use them as well:

($ace_script ||= {})[:ace_stuff] = 1.00


I use it to tell if the script needs to be put above or below another script and for if then statements, etc...


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.