The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: cozziekuns on July 26, 2011, 04:32:19 AM

Title: Pseudo 3D Battlebacks
Post by: cozziekuns on July 26, 2011, 04:32:19 AM
Pseudo 3D Battlebacks
Version: 1.1
Author: cozziekuns
Date: July 25, 2011

Version History



Planned Future Versions


Description


This script is a completely plug and play solution to the aesthetically dull default, wavy looking battle background. It instead takes a snapshot of the screen and then renders a Pseudo 3D image that varies depending on your settings.

Features


Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi52.tinypic.com%2F2ry3vyw.png&hash=a323171d7e3d8a58edf5d3c056fa7dab80c3c966)

Regular Map (in Map Editor)

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi53.tinypic.com%2Fmwqng5.png&hash=81bd7a934707e9eba89f0fefe76842ee38a2e37b)

Mode7 Version

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi56.tinypic.com%2F2cwndwp.png&hash=c3063a65a9b11d02f9c03b73d1c98dfbc5356ca1)

Pseudo 3D Version

Instructions

See script. Pretty much plug and play.

Script


Code: [Select]
#===============================================================================
# Pseudo 3D Battlebacks
#-------------------------------------------------------------------------------
# Version: 1.1
# Author: cozziekuns (rmrk)
# Last Date Updated: 7/25/2011
#===============================================================================
# Description:
#-------------------------------------------------------------------------------
# This script is a completely plug and play solution to the aesthetically dull
# default, wavy looking battle background. It instead takes a snapshot of the
# screen and then renders a Pseudo 3D image that varies depending on your settings.
#===============================================================================
# Updates
#-------------------------------------------------------------------------------
# o 7/31/2011 - Updated with some fixes.
# o 7/25/2011 - Started Script
#===============================================================================
# To-do List
#-------------------------------------------------------------------------------
# o More Modes.
#===============================================================================
# Instructions
#-------------------------------------------------------------------------------
# Copy and paste this script above ? Main Process but below ? Materials, and
# edit the modules to your liking. Some difficult modules have links to the
# instructions.
#===============================================================================
# Mode
#-------------------------------------------------------------------------------
# MODE:
#  0 => A Mode7 like feature that changes the zoom values of Tiles B through E
#       as well as A.
#  1 => A more realistic 3D like feature that only changes the zoom values of
#       TileA.
#===============================================================================

module COZZIEKUNS
  module P3D_BATTLE_BACKGROUNDS
   
    MODE = 0
    BLUR = false # Do you want to blur the background?
   
    FLOOR_X = 0 # X value of Battlefloor
    FLOOR_Y = 192 # Y value of BattleFloor
    FLOOR_OPACITY = 0 # Opacity of BattleFloor
   
    ZOOM = 2 # Zoom value
   
  end
end

#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :layer1_vis
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias coz_gt_3d_battleback_initialize initialize
  def initialize
    coz_gt_3d_battleback_initialize
    @layer1_vis = false
  end
end

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

class Scene_Map
  #--------------------------------------------------------------------------
  # * Create Snapshot for Using as Background of Another Screen
  #--------------------------------------------------------------------------
  alias coz_fixed3d_snapshot_for_background snapshot_for_background
  def snapshot_for_background
    if $scene.is_a?(Scene_Battle)
      case COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::MODE
      when 0
        $game_temp.background_bitmap.dispose
        $game_temp.background_bitmap = Graphics.snap_to_bitmap
        @spriteset.dispose_layer_all
        $game_temp.background_bitmap = Graphics.snap_to_bitmap
      when 1
        @spriteset.dispose_layer2
        $game_temp.background_bitmap.dispose
        $game_temp.background_bitmap = Graphics.snap_to_bitmap
        @spriteset.dispose_layer1
        $game_temp.background_bitmap = Graphics.snap_to_bitmap
      end
    end
  else
    coz_fixed3d_snapshot_for_background
  end
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Create Dummy Sprite
  #--------------------------------------------------------------------------
  def create_dummy_sprite
    zoom = COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::ZOOM - 1
    source = $game_temp.background_bitmap
    bitmap = source
    @battleback_sprites = []
    for i in 0...416
      battleback_sprite = Sprite.new(@viewport1)
      battleback_sprite.bitmap = bitmap
      battleback_sprite.src_rect.set(0, i, 544, 1)
      battleback_sprite.x = -(i / (2).to_f) * zoom
      battleback_sprite.y = i
      battleback_sprite.z = -1
      battleback_sprite.zoom_x = (i * (zoom / (416).to_f)) + 1
      @battleback_sprites.push(battleback_sprite)
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias coz_spm_3d_battleback_dispose dispose
  def dispose
    dispose_dummy_sprite if @battleback_sprites != nil
    coz_spm_3d_battleback_dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose Layer1 Tilemap
  #--------------------------------------------------------------------------
  def dispose_layer1
    @tilemap.bitmaps[0] = nil
    @tilemap.bitmaps[1] = nil
    @tilemap.bitmaps[2] = Cache.system("TileA3")
    @tilemap.bitmaps[3] = Cache.system("TileA4")
    @tilemap.bitmaps[4] = nil
    @tilemap.bitmaps[5] = Cache.system("TileB")
    @tilemap.bitmaps[6] = Cache.system("TileC")
    @tilemap.bitmaps[7] = Cache.system("TileD")
    @tilemap.bitmaps[8] = Cache.system("TileE")
    create_dummy_sprite
    @tilemap.update
  end
  #--------------------------------------------------------------------------
  # * Dispose Layer 2
  #--------------------------------------------------------------------------
  def dispose_layer2
    @tilemap.bitmaps[0] = Cache.system("TileA1")
    @tilemap.bitmaps[1] = Cache.system("TileA2")
    @tilemap.bitmaps[2] = nil
    @tilemap.bitmaps[3] = nil
    @tilemap.bitmaps[4] = Cache.system("TileA5")
    @tilemap.bitmaps[5] = nil
    @tilemap.bitmaps[6] = nil
    @tilemap.bitmaps[7] = nil
    @tilemap.bitmaps[8] = nil
    @tilemap.update
  end
  #--------------------------------------------------------------------------
  # * Dispose Layer All
  #--------------------------------------------------------------------------
  def dispose_layer_all
    create_dummy_sprite
    @tilemap.bitmaps[0] = nil
    @tilemap.bitmaps[1] = nil
    @tilemap.bitmaps[2] = nil
    @tilemap.bitmaps[3] = nil
    @tilemap.bitmaps[4] = nil
    @tilemap.bitmaps[5] = nil
    @tilemap.bitmaps[6] = nil
    @tilemap.bitmaps[7] = nil
    @tilemap.bitmaps[8] = nil
    @tilemap.update
  end
  #--------------------------------------------------------------------------
  # * Dispose Dummy Sprite
  #--------------------------------------------------------------------------
  def dispose_dummy_sprite
    for sprite in @battleback_sprites
      sprite.dispose
    end
  end
end

#==============================================================================
# ** Spriteset_Battle
#==============================================================================

class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Create Battleback Sprite
  #--------------------------------------------------------------------------
  def create_battleback
    @battleback_sprite = Sprite.new(@viewport1)
    @battleback_sprite.bitmap = $game_temp.background_bitmap.clone
    @battleback_sprite.bitmap.blur if COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::BLUR
  end
  #--------------------------------------------------------------------------
  # * Create Battlefloor Sprite
  #--------------------------------------------------------------------------
  def create_battlefloor
    @battlefloor_sprite = Sprite.new(@viewport1)
    @battlefloor_sprite.bitmap = Cache.system("BattleFloor")
    @battlefloor_sprite.x = COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::FLOOR_X
    @battlefloor_sprite.y = COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::FLOOR_Y
    @battlefloor_sprite.z = 1
    @battlefloor_sprite.opacity = COZZIEKUNS::P3D_BATTLE_BACKGROUNDS::FLOOR_OPACITY
  end
end

Credit



Support


Post down below.

Known Compatibility Issues

Will not work with Parallax Maps.
Title: Re: Pseudo 3D Battlebacks
Post by: pacdiggity on July 26, 2011, 12:02:29 PM
Something to add to your Future Versions: making it work with parallax maps. It should be pretty easy, really. Except the Mode 7 bit D:
Otherwise, snappy work. Good stuff.
Title: Re: Pseudo 3D Battlebacks
Post by: modern algebra on July 26, 2011, 08:18:13 PM
Good idea cozzie :)
Title: Re: Pseudo 3D Battlebacks
Post by: M@pple on July 31, 2011, 09:15:31 AM
Very good! Im sticking with it!
Title: Re: Pseudo 3D Battlebacks
Post by: cozziekuns on July 31, 2011, 11:38:14 PM
Thanks for the support guys. I updated it with a little bugfix and a feature that allows you to change the final zoom value of the background. Nothing big.
Title: Re: Pseudo 3D Battlebacks
Post by: Revtattertot on May 12, 2012, 08:04:55 PM
I apologize for necroposting, but I found a minor graphics bug.

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi1153.photobucket.com%2Falbums%2Fp516%2FTatton_Ray%2FGlitch.png&hash=6fd22f74b5154e665bb4924eb43f6639f9800d69)

If you notice the shadows are copying themselves and creating a very wierd pattern. One blends normally with the map, which is good, but the other isn't adhering, and that is what is creating the glitch. If it can be fixed, I appreciate it.