Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Pacman Advanced Creative (PAC) Engine - Core engine 1.6
- # 23/6/2011
- # Type: Core
- # Installation: Various. See instructions.
- # Level: Simple, Average, Difficult
- #
- #===============================================================================
- #
- # HELLO! Welcome to PAC Core engine 1.6. This is a collection of, count it, 4
- # scripts that will be dedicated toward improving and fixing the VX engine and
- # adding core features and helpful utilities to your game.
- # ---------------------------------------------------------------------------- #
- # Description:
- # This pack contains 4 functions; Movement Upgrades and Fixes, Lag Reduction,
- # Backup and 1-Direction. Instructions for each are found below, as are their
- # descriptions. Read them if you want to use this script to its fullest
- # potential.
- #
- #===============================================================================
- #
- # PAC MOVEMENT
- # Description:
- # There are always bound to be bugs of some kind in a program, though not as
- # noticeable and numerous as the ones found in VX. This script will fix several
- # bugs with movement commands and add new features to the currently existing
- # ones.
- #
- # FIXES
- # Jump: Event will no longer jump if its destination is outside the screen or
- # not passable.
- # Random move: Event will now find the movable direction before it moves.
- # Collide With Characters Check: Events with priority 'Same as Characters' will
- # be able to walk on 'Below Characters' priority setting.
- # Each of these have a boolean which you can change if you wish.
- # SCRIPT CALLS
- # Open event command 'Set Move Route', click 'Script...' and type the desired
- # custom command.
- # move_toward_pos(x, y) - Will move toward co-ordinates x and y.
- # move_away_from_post(x, y) - Will move away from co-ordinates x and y.
- # move_toward_event(x) - Will move toward the event with ID x.
- # move_away_from_event(x) - Will move away from event with ID x.
- # turn_toward_pos(x, y) - Will turn toward co-ordinates x and y.
- # turn_away_from_pos(x, y) - Will turn away from co-ordinates x and y.
- # turn_toward_event(x) - Will turn toward the event with ID x.
- # turn_away_from_event(x) - Will turn away from the event with ID x.
- #
- #===============================================================================
- #
- # PAC LAG REDUCTION
- # Description:
- # Got a tonne of events running on your maps? Causes a lot of lag, doesn't it?
- # This is a lag reduction script to make your game run not as bad-like.
- #
- # CONFIGURATION
- # Set UPDATE_RANGE to any value between 20 and 120. It generally sits well at
- # around 80. If this is too low or high, the script will give you a friendly
- # reminder that will make your game look really bad.
- #
- #===============================================================================
- #
- # PAC BACKUP
- # Description:
- # This script will automatically back up your data files upon startup. You are
- # given an option to make a window pop-up letting you know how long it took to
- # do so.
- #
- # CONFIGURATION
- # BACKUP_WHEN_TEST is a boolean to check whether or not to backup the data even
- # when running in test play.
- # BACKUP_REPORT is a boolean to check whether or not to display the report
- # window.
- # DIRNAME is the name of the directory the backup files will be saved to. If it
- # does not exist, then the script will make it exist. It's that boss.
- #
- #===============================================================================
- #
- # PAC 1-DIRECTION
- # Description:
- # Want to give some originality to your game? Want to confuse the player in some
- # freaky-deaky puzzle with some weird gimmick? Do you just want to be a titanic
- # tool to the players? With this script, you can activate a 1-Directional
- # movement system with a flick of a metaphorical switch.
- #
- # CONFIGURATION
- # PAC_UP, PAC_DOWN, PAC_LEFT and PAC_RIGHT are the buttons the will be pressed
- # to go up, down, left and right respectively. This applies to 1-Directional
- # and convential movement.
- # PAC_BACK_DASH is a boolean to check if you can dash backwards during 1-Dir
- # movement.
- # PAC_1DIR_SWITCH is the ID of the switch used to activate 1-Dir movement.
- # When it is off conventional movement is used.
- #
- #===============================================================================
- #
- # BEGIN EDITING
- #
- #===============================================================================
- module PAC
- module CORE
- SAFE_JUMP = true
- RANDOM_MOVE_FIX = true
- COLLIDE_FIX = true
- UPDATE_RANGE = 80
- BACKUP_WHEN_TEST = true
- BACKUP_REPORT = false
- DIRNAME = 'Backup Data'
- PAC_UP = Input::UP
- PAC_DOWN = Input::DOWN
- PAC_LEFT = Input::LEFT
- PAC_RIGHT = Input::RIGHT
- PAC_BACK_DASH = false
- PAC_1DIR_SWITCH = 1
- #===============================================================================
- #
- # DO NOT EDIT ANYTHING ELSE UNLESS YOU ARE MODERN ALGEBRA.
- #
- #===============================================================================
- end
- end
- $imported = {} if $imported == nil
- $imported["PAC_Core1.6"] = true
- #===============================================================================
- #
- # PAC MOVEMENT UPGRADES AND FIXES
- #
- #===============================================================================
- #==============================================================================
- # ** Game_Character
- #------------------------------------------------------------------------------
- # This class deals with characters. It's used as a superclass of the
- # Game_Player and Game_Event classes.
- #==============================================================================
- class Game_Character
- #--------------------------------------------------------------------------
- # * Jump
- #--------------------------------------------------------------------------
- if PAC::CORE::SAFE_JUMP
- def jump(x_plus, y_plus)
- if x_plus.abs > y_plus.abs
- x_plus < 0 ? turn_left : turn_right
- elsif x_plus.abs > y_plus.abs
- y_plus < 0 ? turn_up : turn_down
- end
- new_x = @x + x_plus
- new_y = @y + y_plus
- if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y)
- @x += x_plus
- @y += y_plus
- distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
- @jump_peak = 10 + distance - @move_speed
- @jump_count = @jump_peak * 2
- @stop_count = 0
- straighten
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Random move
- #--------------------------------------------------------------------------
- if PAC::CORE::RANDOM_MOVE_FIX
- def move_random
- safe = false
- checked = []
- while safe == false
- break if checked.include?(0) and checked.include?(1) and
- checked.include?(2) and checked.include?(3)
- case rand(4)
- when 0; return if checked.include?(0); checked.push 0
- if passable?(@x, @y + 1)
- safe = true; move_down(false)
- end
- when 1; return if checked.include?(1); checked.push 1
- if passable?(@x - 1, @y)
- safe = true; move_left(false)
- end
- when 2; return if checked.include?(2); checked.push 2
- if passable?(@x + 1, @y)
- safe = true; move_right(false)
- end
- when 3; return if checked.include?(3); checked.push 3
- if passable?(@x - 1, @y)
- safe = true; move_up(false)
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Collide with characters
- #--------------------------------------------------------------------------
- if PAC::CORE::COLLIDE_FIX
- def collide_with_characters?(x, y)
- for event in $game_map.events_xy(x, y)
- unless event.through
- return true if event.priority_type == 1
- end
- end
- if @priority_type == 1
- return true if $game_player.pos_nt?(x, y)
- return true if $game_map.boat.pos_nt?(x, y)
- return true if $game_map.ship.pos_nt?(x, y)
- end
- return false
- end
- def move_toward_pos(x,y)
- sx = distance_x_from_pos(x)
- sy = distance_y_from_pos(y)
- if sx != 0 or sy != 0
- if sx.abs > sy.abs
- sx > 0 ? move_left : move_right
- if @move_failed and sy != 0
- sy > 0 ? move_up : move_down
- end
- else
- sy > 0 ? move_up : move_down
- if @move_failed and sx != 0
- sx > 0 ? move_left : move_right
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Move away from Position
- #--------------------------------------------------------------------------
- def move_away_from_pos(x,y)
- sx = distance_x_from_pos(x)
- sy = distance_y_from_pos(y)
- if sx != 0 or sy != 0
- if sx.abs > sy.abs
- sx > 0 ? move_right : move_left
- if @move_failed and sy != 0
- sy > 0 ? move_down : move_up
- end
- else
- sy > 0 ? move_down : move_up
- if @move_failed and sx != 0
- sx > 0 ? move_right : move_left
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Move toward Event
- #--------------------------------------------------------------------------
- def move_toward_event(id)
- move_toward_pos($game_map.events[id].x,$game_map.events[id].y)
- end
- #--------------------------------------------------------------------------
- # * Move away from Event
- #--------------------------------------------------------------------------
- def move_away_from_event(id)
- move_away_from_pos($game_map.events[id].x,$game_map.events[id].y)
- end
- #--------------------------------------------------------------------------
- # * Turn toward Position
- #--------------------------------------------------------------------------
- def turn_toward_pos(x,y)
- sx = distance_x_from_pos(x)
- sy = distance_y_from_pos(y)
- if sx.abs > sy.abs
- sx > 0 ? turn_left : turn_right
- elsif sx.abs < sy.abs
- sy > 0 ? turn_up : turn_down
- end
- end
- #--------------------------------------------------------------------------
- # * Turn away from Position
- #--------------------------------------------------------------------------
- def turn_away_from_pos(x,y)
- sx = distance_x_from_pos(x)
- sy = distance_y_from_pos(y)
- if sx.abs > sy.abs # Horizontal distance is longer
- sx > 0 ? turn_right : turn_left
- elsif sx.abs < sy.abs # Vertical distance is longer
- sy > 0 ? turn_down : turn_up
- end
- end
- #--------------------------------------------------------------------------
- # * Turn toward Event
- #--------------------------------------------------------------------------
- def turn_toward_event(id)
- turn_toward_pos($game_map.events[id].x,$game_map.events[id].y)
- end
- #--------------------------------------------------------------------------
- # * Turn away from Event
- #--------------------------------------------------------------------------
- def turn_away_from_event(id)
- turn_away_from_pos($game_map.events[id].x,$game_map.events[id].y)
- end
- #--------------------------------------------------------------------------
- # * Calculate X Distance From Event
- #--------------------------------------------------------------------------
- def distance_x_from_pos(x)
- sx = @x - x
- if $game_map.loop_horizontal?
- if sx.abs > $game_map.width / 2
- sx -= $game_map.width
- end
- end
- return sx
- end
- #--------------------------------------------------------------------------
- # * Calculate Y Distance From Event
- #--------------------------------------------------------------------------
- def distance_y_from_pos(y)
- sy = @y - y
- if $game_map.loop_vertical?
- if sy.abs > $game_map.height / 2
- sy -= $game_map.height
- end
- end
- return sy
- end
- end
- #===============================================================================
- #
- # PAC LAG REDUCTION
- #
- #===============================================================================
- PAC::CORE::UPDATE_RANGE = PAC::CORE::UPDATE_RANGE
- module Graphics
- unless method_defined?(:resize_screen_pac_lag)
- class << Graphics
- alias resize_screen_pac_lag resize_screen
- end
- def self.resize_screen(width, height)
- resize_screen_pac_lag(width, height)
- if $game_temp != nil
- $game_temp.setup_lightening_value
- end
- end
- 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
- attr_accessor :valid_common_event_check
- attr_reader :display_center_x
- attr_reader :display_center_y
- attr_reader :map_sprite_update_width
- attr_reader :map_sprite_update_height
- #--------------------------------------------------------------------------
- # alias listing
- #--------------------------------------------------------------------------
- alias initialize_pac_lag initialize
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- initialize_pac_lag
- @valid_common_event_check = true
- setup_lightening_value
- end
- #--------------------------------------------------------------------------
- # * Setup Lightening Value
- #--------------------------------------------------------------------------
- def setup_lightening_value
- @display_center_x = Graphics.width / 2
- @display_center_y = Graphics.height / 2
- @map_sprite_update_width = Graphics.width * PAC::CORE::UPDATE_RANGE / 100
- @map_sprite_update_height = Graphics.height * PAC::CORE::UPDATE_RANGE / 100
- end
- end
- if PAC::CORE::UPDATE_RANGE < 20
- p "Your lag reduction is incredibly low. Raise it."
- elsif PAC::CORE::UPDATE_RANGE < 50
- p "Your lag reduction isn't very high. Consider raising it."
- elsif PAC::CORE::UPDATE_RANGE > 120
- p "Your lag reduction is quite high. Consider lowering it."
- end
- #==============================================================================
- # ** Game_Switches
- #------------------------------------------------------------------------------
- # This class handles switches. It's a wrapper for the built-in class "Array."
- # The instance of this class is referenced by $game_switches.
- #==============================================================================
- class Game_Switches
- #--------------------------------------------------------------------------
- # alias listing
- #--------------------------------------------------------------------------
- alias indexer_equal_pac_lag []=
- #--------------------------------------------------------------------------
- # * Set Switch
- #--------------------------------------------------------------------------
- def []=(switch_id, value)
- indexer_equal_pac_lag(switch_id, value)
- $game_temp.valid_common_event_check = true
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # This class handles maps. It includes scrolling and passage determination
- # functions. The instance of this class is referenced by $game_map.
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # alias listing
- #--------------------------------------------------------------------------
- alias setup_pac_lag setup
- #--------------------------------------------------------------------------
- # * Setup
- #--------------------------------------------------------------------------
- def setup(map_id)
- setup_pac_lag(map_id)
- update_valid_common_event_list
- end
- #--------------------------------------------------------------------------
- # * Update Valid Common Event List
- #--------------------------------------------------------------------------
- def update_valid_common_event_list
- @valid_common_events = {}
- @common_events.each { |event_id, event|
- if event.trigger == 2 && $game_switches[event.switch_id]
- @valid_common_events[event_id] = event
- end
- }
- $game_temp.valid_common_event_check = false
- end
- #--------------------------------------------------------------------------
- # * Update Events
- #--------------------------------------------------------------------------
- def update_events
- for event in @events.values
- event.update
- end
- if $game_temp.valid_common_event_check
- update_valid_common_event_list
- end
- for common_event in @valid_common_events.values
- common_event.update
- end
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #------------------------------------------------------------------------------
- # An interpreter for executing event commands. This class is used within the
- # Game_Map, Game_Troop, and Game_Event classes.
- #==============================================================================
- class Game_Interpreter
- @@_auto_start_common_event_list = nil
- #--------------------------------------------------------------------------
- # alias listing
- #--------------------------------------------------------------------------
- alias clear_pac_lag clear
- #--------------------------------------------------------------------------
- # * Clear
- #--------------------------------------------------------------------------
- def clear
- clear_pac_lag
- if @@_auto_start_common_event_list == nil
- create_auto_start_common_event_list
- end
- end
- #--------------------------------------------------------------------------
- # * Create Auto Start Common Event List
- #--------------------------------------------------------------------------
- def create_auto_start_common_event_list
- @@_auto_start_common_event_list = []
- $data_common_events.compact.each { |event|
- @@_auto_start_common_event_list << event if event.trigger == 1
- }
- end
- #--------------------------------------------------------------------------
- # * Setup Starting Event
- #--------------------------------------------------------------------------
- def setup_starting_event
- if $game_map.need_refresh
- $game_map.refresh
- end
- if $game_temp.common_event_id > 0
- list = $data_common_events[$game_temp.common_event_id].list
- setup(list)
- $game_temp.common_event_id = 0
- return
- end
- for event in $game_map.events.values
- if event.starting
- event.clear_starting
- setup(event.list, event.id)
- return
- end
- end
- for event in @@_auto_start_common_event_list
- if $game_switches[event.switch_id]
- setup(event.list)
- end
- end
- end
- end
- #==============================================================================
- # ** Sprite_Character
- #------------------------------------------------------------------------------
- # This sprite is used to display characters. It observes a instance of the
- # Game_Character class and automatically changes sprite conditions.
- #==============================================================================
- class Sprite_Character < Sprite_Base
- #--------------------------------------------------------------------------
- # * Within Update Range
- #--------------------------------------------------------------------------
- def within_update_range?
- sx = @character.screen_x - $game_temp.display_center_x
- sy = @character.screen_y - $game_temp.display_center_y
- return (sx.abs <= $game_temp.map_sprite_update_width &&
- sy.abs <= $game_temp.map_sprite_update_height)
- end
- end
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc. It's used
- # within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Update Characters
- #--------------------------------------------------------------------------
- def update_characters
- for sprite in @character_sprites
- sprite.update if sprite.within_update_range?
- end
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs the map screen processing.
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- $game_map.interpreter.update
- $game_map.update
- $game_player.update
- $game_system.update
- @spriteset.update
- @message_window.update
- unless $game_message.visible
- update_transfer_player
- update_encounter
- update_call_menu
- update_call_debug
- if $game_temp.next_scene != nil
- update_scene_change
- end
- end
- end
- end
- #===============================================================================
- #
- # PAC BACKUP
- #
- #===============================================================================
- module PAC
- module CORE
- SCRIPT = <<_SCRIPT_
- if (BACKUP_WHEN_TEST && #{defined?(Graphics.wait) ? '$TEST' : '$DEBUG'}) ||
- !BACKUP_WHEN_TEST
- time = Time.now
- Dir.mkdir(DIRNAME) unless File.directory?(DIRNAME)
- ftype = "#{defined?(Graphics.wait) ? 'rvdata' : 'rxdata'}"
- flist = Dir.glob('./Data/*.{' + ftype + '}')
- flist.each_index do |i|
- flist[i] = flist[i].split('/').last
- save_data(load_data('Data/' + flist[i]), DIRNAME + '/' + flist[i])
- end
- if BACKUP_REPORT
- p('The PAC says: Backup Complete - ' + (Time.now - time).to_s + ' sec')
- end
- end
- _SCRIPT_
- eval(SCRIPT) unless $@
- end
- end
- if PAC::CORE::BACKUP_WHEN_TEST != true || false
- p "The PAC says: Backup when test constant set to invalid value."
- p "Check your core script."
- end
- #===============================================================================
- #
- # PAC 1-DIRECTION
- #
- #===============================================================================
- if PAC::CORE::PAC_BACK_DASH != true and PAC::CORE::PAC_BACK_DASH != false
- p "The PAC says: Back dash constant set to invalid value."
- p "Check your Core script."
- end
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # This class handles maps. It includes event starting determinants and map
- # scrolling functions. The instance of this class is referenced by $game_map.
- #==============================================================================
- class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # alias listing
- #--------------------------------------------------------------------------
- alias pac_1dir_backdash dash?
- #--------------------------------------------------------------------------
- # * Move by Input
- #--------------------------------------------------------------------------
- def move_by_input
- return unless movable?
- return if $game_map.interpreter.running?
- if $game_switches[PAC::CORE::PAC_1DIR_SWITCH]
- if Input.press?(PAC::CORE::PAC_UP)
- move_forward
- elsif Input.repeat?(PAC::CORE::PAC_LEFT)
- turn_left_90
- elsif Input.repeat?(PAC::CORE::PAC_RIGHT)
- turn_right_90
- elsif Input.press?(PAC::CORE::PAC_DOWN)
- move_backward
- end
- else
- if Input.press?(PAC::CORE::PAC_UP)
- move_up
- elsif Input.press?(PAC::CORE::PAC_LEFT)
- move_left
- elsif Input.press?(PAC::CORE::PAC_RIGHT)
- move_right
- elsif Input.press?(PAC::CORE::PAC_DOWN)
- move_down
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Dash?
- #--------------------------------------------------------------------------
- def dash?
- return false if $game_switches[PAC::CORE::PAC_1DIR_SWITCH] and
- Input.press?(PAC::CORE::PAC_DOWN) and !PAC::CORE::PAC_BACK_DASH
- pac_1dir_backdash # The usual.
- end
- end
- #===============================================================================
- #
- # END OF SCRIPT
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement