#===============================================================================
# ** Pixelmovement Script
#-------------------------------------------------------------------------------
#
# f0tz!baerchen
# v1.5
# 01.11.07
#
#-------------------------------------------------------------------------------
#
# Credits:
# arevulopapo (turn toward/away player methods, stay_in_range method,
# distance method, beta tester and lots of other small things.. (;)
# Caesar (fill_circle method)
# Fanha Giang (Autotile handling)
# Caldaron (move_toward_player method)
# Drag-On (beta tester)
# Monsta (beta tester)
# Wollnashorn (beta tester)
# Abt Plout�n (beta tester, helped with many difficult codings..)
# The RMXP.org Community (for the great amount of ideas :) )
#
# please tell me if I forgot you (;
#
#-------------------------------------------------------------------------------
#
# Importance:
# This script has many more features than only Pixelmovement. Information for
# the options can be found at the end of the script. There you can also change
# the settings Sometimes you have to add a comment in an event to activate
# special features for this event. The Script checks every line for such
# comments until it finds a non comment line.
#
#-------------------------------------------------------------------------------
#
# Used Global Variables:
# $pixelmovement: Settings of the Pixelmovement Script
#
#-------------------------------------------------------------------------------
#
# What do I have to do if I would like to use this script in my game?
# If your game is not commercial its enough to credit me (f0tz!bearchen) in your
# game, if you'd like to sell you game please contact me and we can talk about
# this (but normally I only would like to have some information about your
# project and a free version of the finished game)
#
#-------------------------------------------------------------------------------
#
# New Things:
# - opacity of minimap sprites depends now on the opacity of the real sprites
# - no error because of an empty party
# - Direction fix works fine now
# - Caterpillar + Surface Maps work fine together now
# - jump not works fine now
# - char_sprite returns the real sprite now, no copy
# - if an object of the class RPG::MoveCommand is a move command
# (Move_Down, etc), @parameters[0] will contain the number of steps
# - new pathfinding:
# it works much faster and better now, because it uses pre-saved waypoints,
# which are lying on the map and contain information about connections to
# other waypoints..
# if the start/target does not lie on a waypoint the next waypoint is chosen
# of course the creating of those waypoints takes some time, but it only needs
# to be done once (if the map isnt changed anymore after this), because the
# information is stored in a file
# I already implemented a method which will create waypoints for all (or only
# some) maps.. this method can be called by the game maker once after the game
# has been finished, so the player wont have to wait too long at anytime when
# playing the game..
# when no route to the target is found, the pathfinding tries to get as near
# as possible to the target. if this is also not possible and the minimum
# distance gets too big, simply nothing happens. of course this finding of the
# way to the nearest accessible point is a bit more time consuming.
# While searching a path the game does not freeze, it just continues running
# (maybe a bit slower) until the path is found and of course the event which
# will run the path can move the whole time. By the way it is also possible
# now to run pathfinding for more than one event at the same time.
# - new methods for Game_Character: turn_toward_coords(x, y),
# direction_to(id) (returns the direction in which the event lies),
# jump_to(x, y); passable? improved; on_event? new
# - caterpillar: will stop immediately if the hero stops because of a message or
# a running event process, etc.
# - zoom level of the player sprite on the minimap can be changed now
# - 4Dir Movement possible (only diagonal OR normal),
# Input Modul: method dir4diag added
# - all turn/move methods have been simplified
# - events dont walk anymore if they are activated
# - changing the player's sprite works fine now (also on the minimap)
# - loop maps work fine now with database passability
# - the changing of the frame/direction_number is instant now
# - if the event has more than one page always the comments of the current page
# are used
# - working together with the new SDK / MCLAB // with/without Anti-Lag
# - Bugfix: event editing works now in saved games too
# - Position(0, 0) is now in the upper left corner of the map
# - events with tile graphics work fine now
# - many things have been optimized
# - caterpillar: character graphics are changed instantly now
# - event graphics can be shifted via a comment
# - frame speed of the events can be changed
# - isometric has been rebuild (more elegant now, only the update_move is used)
# - no table for a bitmap anymore
# (the passability tables are stored in $game_map and in files now)
# - When creating Waypoints, a collision table is saved in a file, too
# - passability at events has been improved (stops now at an event and does not
# walk through it, if this is in its route, but the route goes further)
# - Game_Player: update-method has been rebuilt
# - Important: Don't forget to delete all files if you change a map.. (;
# - Game_Character: move_to_place(x, y) moves straight to coordinates x, y
# - Minimap Bugfix: Chars which are on the Minimap but not on the Screen are
# moved properly now
# Minimap Bugfix: is placed corretly now, if the map is smaller than the
# general minimap settings and the position is not the upper left corner
# - Caterpillars don't move strange anymore when going across a "border" on a
# looped map
# - Passability at very small obstacles (1-2Px) has been improved
# - Collision Maps are Black / Transparent now instead of Black / White
# the bitmaps can still be Black / White but White has to be the transparent
# colour of the bitmap
# - $pixelmovement is the only used global variable
# - Erase Event Command works fine now
# - Game_Character: turn_toward_coords is much faster now
# - Obstacle Passabilities work fine now, Square Autotiles, too
#
#===============================================================================
#===============================================================================
# Class which holds all Pixelmovement settings
#===============================================================================
class Pixelmovement_Settings
attr_accessor :pixel_aliasing
attr_accessor :collision_folder
attr_accessor :height_folder
attr_accessor :swamp_folder
attr_reader :frame_number
attr_accessor :frame_array
attr_reader :stand_frame
attr_accessor :stand_array
attr_accessor :frame_speed
attr_reader :direction_number
attr_accessor :movement_type
attr_accessor :direction_array
attr_reader :isometric
attr_reader :cater_activate
attr_accessor :cater_distance
attr_reader :cater_overlap
attr_accessor :player_size
attr_reader :player_frame_number
attr_reader :player_direction_number
attr_reader :player_stand_frame
attr_accessor :player_frame_speed
attr_reader :player_shift_x
attr_reader :player_shift_y
attr_accessor :event_size_add
attr_accessor :sprint_speed
attr_accessor :sprint_key
attr_accessor :sprint_time
attr_accessor :sprint_wait
attr_reader :sprint_fix
attr_reader :minimap
attr_reader :minimap_sprites
attr_accessor :minimap_pos
attr_accessor :minimap_width
attr_accessor :minimap_height
attr_accessor :minimap_scale
attr_accessor :minimap_player_scale
attr_accessor :minimap_opacity
attr_reader :minimap_collision
attr_accessor :minimap_c_cursor
attr_accessor :minimap_c_pass
attr_accessor :minimap_c_n_pass
attr_accessor :loop_maps
attr_reader :sliding
attr_accessor :jump_key
attr_accessor :jump_height
attr_accessor :jump_length
attr_accessor :ice_tiles
attr_reader :panorama_scrolling
attr_accessor :waypoints_settings
attr_accessor :events
attr_accessor :minimaps
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize(aliasing = false)
@pixel_aliasing = aliasing # aliased methods are only aliased once
@collision_folder = 'Graphics/ZPassability/'
@height_folder = 'Graphics/ZSurface/'
@swamp_folder = 'Graphics/ZSwamps/'
@frame_number = 4
@frame_array = []
@stand_frame = 0
@stand_array = []
@direction_number = 4
@frame_speed = 1.0
@movement_type = 'dir4'
@direction_array = []
@player_size = []
@player_frame_speed = 1.0
@event_size_add = 0
@waypoints_settings = [false, []]
@cater_distance = 8
@cater_activate = true
@cater_overlap = false
@sprint_speed = 1
@sprint_key = Input::A
@sprint_time = 50
@sprint_wait = 20
@sprint_fix = true
@minimap_pos = 1
@minimap_width = 160.0
@minimap_height = 120.0
@minimap_scale = 4.0
@minimap_player_scale = 3.0
@minimap_opacity = 200
@minimap_c_cursor = Color.new(255, 0, 0)
@minimap_c_pass = Color.new (255, 255, 255)
@minimap_c_n_pass = Color.new(0, 0, 0)
@minimap = false
@minimap_sprites = false
@minimap_collision = false
@loop_maps = []
@jump_key = Input::X
@jump_height = 2
@jump_length = 64
@ice_tiles = []
@isometric = false
@sliding = false
@panorama_scrolling = false
@events = nil
@minimaps = {}
end
#-----------------------------------------------------------------------------
# switch to (de)activate caterpillars
#-----------------------------------------------------------------------------
def switch_caterpillar(value = nil)
@cater_activate = value == nil ? !@cater_activate : value
return if not $scene.is_a?(Scene_Map) or $scene.spriteset == nil or
not $game_map.is_a?(Game_Map)
$scene.spriteset.game_party_actors_sprites.each {|actor| actor.dispose}
$scene.spriteset.game_party_actors_sprites = []
$game_map.game_party_actors = []
return if not @cater_activate
for i in 1..$game_party.actors.length
$game_map.game_party_actors.push(Game_Party_Actor.new(i))
end
for i in 0..($game_map.game_party_actors.length - 1)
sprite = Sprite_Character.new($scene.spriteset.viewport1,
$game_map.game_party_actors[i])
sprite.z -= 1
$scene.spriteset.game_party_actors_sprites.push(sprite)
end
end
#-----------------------------------------------------------------------------
# switch for isometric function
#-----------------------------------------------------------------------------
def switch_isometric(value = nil)
@isometric = value == nil ? !@isometric : value
return if not @cater_activate or $game_map == nil or
$game_map.game_party_actors == nil
for actor in $game_map.game_party_actors
actor.moveto($game_player.x, $game_player.y)
end
end
#-----------------------------------------------------------------------------
# switch for caterpillar overlapping
#-----------------------------------------------------------------------------
def switch_cater_overlap(value = nil)
@cater_overlap = value == nil ? !@cater_overlap : value
end
#-----------------------------------------------------------------------------
# switch for direction fix while sprinting
#-----------------------------------------------------------------------------
def switch_sprint_fix(value = nil)
@sprint_fix = value == nil ? !@sprint_fix : value
end
#-----------------------------------------------------------------------------
# switch for the minimap
#-----------------------------------------------------------------------------
def switch_minimap(value = nil)
@minimap = value == nil ? !@minimap : value
end
#-----------------------------------------------------------------------------
# switch for the minimap character sprites
#-----------------------------------------------------------------------------
def switch_minimap_sprites(value = nil)
@minimap_sprites = value == nil ? !@minimap_sprites : value
end
#-----------------------------------------------------------------------------
# switch for the collision minimap
#-----------------------------------------------------------------------------
def switch_minimap_collision(value = nil)
@minimap_collision = value == nil ? !@minimap_collision : value
end
#-----------------------------------------------------------------------------
# switch for hero sliding
#-----------------------------------------------------------------------------
def switch_sliding(value = nil)
@sliding = value == nil ? !@sliding : value
end
#-----------------------------------------------------------------------------
# switch for special panorama scrolling
#-----------------------------------------------------------------------------
def switch_panorama_scrolling(value = nil)
@panorama_scrolling = value == nil ? !@panorama_scrolling : value
end
#-----------------------------------------------------------------------------
# changes the frame number of the player
#-----------------------------------------------------------------------------
def player_frame_number=(value)
return if value == @player_frame_number
@player_frame_number = value
return if $game_player == nil or $game_map == nil
($game_map.game_party_actors + [$game_player]).each do |event|
event.init_special_settings
end
end
#-----------------------------------------------------------------------------
# changes the direction number of the player
#-----------------------------------------------------------------------------
def player_direction_number=(value)
return if value == @player_direction_number
@player_direction_number = value
return if $game_player == nil or $game_map == nil
($game_map.game_party_actors + [$game_player]).each do |event|
event.init_special_settings
end
end
#-----------------------------------------------------------------------------
# changes the stand frame of the player
#-----------------------------------------------------------------------------
def player_stand_frame=(value)
return if value == @player_stand_frame
@player_stand_frame = value
return if $game_player == nil or $game_map == nil
($game_map.game_party_actors + [$game_player]).each do |event|
event.init_special_settings
end
end
#-----------------------------------------------------------------------------
# changes the shift in x direction of th player
#-----------------------------------------------------------------------------
def player_shift_x=(value)
return if value == @player_shift_x
@player_shift_x = value
return if $game_player == nil or $game_map == nil
($game_map.game_party_actors + [$game_player]).each do |event|
event.init_special_settings
end
end
#-----------------------------------------------------------------------------
# changes the shift in y direction of th player
#-----------------------------------------------------------------------------
def player_shift_y=(value)
return if value == @player_shift_y
@player_shift_y = value
return if $game_player == nil or $game_map == nil
($game_map.game_party_actors + [$game_player]).each do |event|
event.init_special_settings
end
end
#-----------------------------------------------------------------------------
# changes the frame number of the events
#-----------------------------------------------------------------------------
def frame_number=(value)
return if value == @frame_number
@frame_number = value
return if $game_map == nil
e = ($game_map.game_party_actors + $game_map.events.values + [$game_player])
e.each {|event| event.init_special_settings}
end
#-----------------------------------------------------------------------------
# changes the direction number of the events
#-----------------------------------------------------------------------------
def direction_number=(value)
return if value == @direction_number
@direction_number = value
return if $game_map == nil
e = ($game_map.game_party_actors + $game_map.events.values + [$game_player])
e.each {|event| event.init_special_settings}
end
#-----------------------------------------------------------------------------
# changes the stand frame of the events
#-----------------------------------------------------------------------------
def stand_frame=(value)
return if value == @stand_frame
@stand_frame = value
return if $game_map == nil
e = ($game_map.game_party_actors + $game_map.events.values + [$game_player])
e.each {|event| event.init_special_settings}
end
#-----------------------------------------------------------------------------
# creates waypoints for Pathfinding
#-----------------------------------------------------------------------------
def create_waypoints
# loading bar is loaded
$bg = Sprite.new
$bg.bitmap = Bitmap.new(640, 480)
$bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0))
$bar = Sprite.new
$bar.bitmap = Bitmap.new(640, 128)
$bar.bitmap.fill_rect(0, 0, 640, 128, Color.new(255, 0, 0))
$bar.y = 480 - 128
# loads map ids
if $pixelmovement.waypoints_settings[0]
load = []
for i in 1..999
load.push(i)
end
load -= $pixelmovement.waypoints_settings[1]
else
load = $pixelmovement.waypoints_settings[1]
end
load.each do |map_id|
name = sprintf("Map%03d.rxdata", map_id)
load -= [map_id] if not Dir.entries('Data/').include?(name)
end
# loads waypoint
load.each do |map_id|
$bar.x = -640 + (load.index(map_id) + 1) * 640 / load.length
Graphics.update
$game_map.setup(map_id)
path = Game_Pathfinding.new($game_player)
end
$scene = nil
end
end
#-------------------------------------------------------------------------------
# creates the setting object (depending on if the game has just been
# started or restarted)
#-------------------------------------------------------------------------------
$pixelmovement = Pixelmovement_Settings.new($pixelmovement != nil)
#===============================================================================
# Game_Map Class
#===============================================================================
class Game_Map
# for autotiles
INDEX =
[
26, 27, 32, 33, 4 , 27, 32, 33, 26, 5, 32, 33, 4, 5, 32, 33,
26, 27, 32, 11, 4 , 27, 32, 11, 26, 5, 32, 11, 4, 5, 32, 11,
26, 27, 10, 33, 4 , 27, 10, 33, 26, 5, 10, 33, 4, 5, 10, 33,
26, 27, 10, 11, 4 , 27, 10, 11, 26, 5, 10, 11, 4, 5, 10, 11,
24, 25, 30, 31, 24, 5, 30, 31, 24, 25, 30, 11, 24, 5, 30, 11,
14, 15, 20, 21, 14, 15, 20, 11, 14, 15, 10, 21, 14, 15, 10, 11,
28, 29, 34, 35, 28, 29, 10, 35, 4, 29, 34, 35, 4, 29, 10, 35,
38, 39, 44, 45, 4, 39, 44, 45, 38, 5, 44, 45, 4, 5, 44, 45,
24, 29, 30, 35, 14, 15, 44, 45, 12, 13, 18 ,19, 12, 13, 18, 11,
16, 17, 22, 23, 16, 17, 10, 23, 40, 41, 46, 47, 4, 41, 46, 47,
36, 37, 42, 43, 36, 5, 42, 43, 12, 17, 18, 23, 12, 13, 42, 43,
36, 41, 42, 47, 16, 17, 46, 47, 12, 17, 42, 47, 0, 1, 6, 7
]
X = [0, 1, 0, 1]
Y = [0, 0, 1, 1]
attr_accessor :collision_map # Bitmap which saves the collision map
attr_accessor :height_map # saves height-map
attr_accessor :swamp_map # saves swamp-map
attr_accessor :tileset_name
attr_accessor :autotile_names
attr_accessor :events
attr_accessor :game_party_actors # Caterpillars
attr_accessor :jump_events # for jump events
attr_accessor :ice_events # for sliding events
attr_accessor :collision_table
attr_accessor :height_table
attr_accessor :swamp_table
attr_accessor :waypoints # Waypoints for pathfinding
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_game_map_initialize initialize
alias pixelmovement_game_map_setup setup
alias pixelmovement_game_map_encounter_step encounter_step
alias pixelmovement_game_map_scroll_down scroll_down
alias pixelmovement_game_map_scroll_left scroll_left
alias pixelmovement_game_map_scroll_right scroll_right
alias pixelmovement_game_map_scroll_up scroll_up
alias pixelmovement_game_map_valid? valid?
alias pixelmovement_game_map_bush? bush?
alias pixelmovement_game_map_counter? counter?
alias pixelmovement_game_map_terrain_tag terrain_tag
alias pixelmovement_game_map_update update
end
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize
pixelmovement_game_map_initialize
@jump_events = {}
@ice_events = {}
@game_party_actors = []
end
#-----------------------------------------------------------------------------
# map setup
#-----------------------------------------------------------------------------
def setup(map_id)
# saves tables of the old map
self.save_tables
# resets other things
@jump_events = {}
@ice_events = {}
pixelmovement_game_map_setup(map_id)
# Caterpillar System
@game_party_actors_copy = $game_party.actors.clone
@game_party_actors = []
if $pixelmovement.cater_activate
for i in 1..$game_party.actors.length
@game_party_actors.push(Game_Party_Actor.new(i))
end
end
# for Loop Maps
name = (load_data('Data/MapInfos.rxdata'))[@map_id].name
if name.include?('[Loop-Map]') and
not $pixelmovement.loop_maps.include?(@map_id)
$pixelmovement.loop_maps.push(@map_id)
end
# see below
self.load_bitmaps
self.load_tables
# loads waypoints for pathfinding
self.load_waypoints
# deletes pathfinding of the player for the old map
$game_player.pathfinding = Game_Pathfinding.new($game_player)
end
#-----------------------------------------------------------------------------
# reads passability map (first tries from a map, then from a tileset,
# or nothing), height map and swamp map are initialised
#-----------------------------------------------------------------------------
def load_bitmaps
@collision_map = RPG::Cache.collision_map(map_id.to_s)
@pass_type = 'map'
if @collision_map == nil
@collision_map = []
@collision_map[0] = RPG::Cache.collision_map(@tileset_name)
@pass_type = 'tileset'
if @collision_map[0] == nil
@collision_map == nil
@pass_type = 'database'
else # Autotiles
@autotile_names.each do |name|
bitmap = RPG::Cache.collision_map(name)
if bitmap != nil and bitmap.width >= 96
gen_autotiles(@collision_map.length, bitmap)
else
@collision_map[@collision_map.length] = Bitmap.new(32 * 8, 32 * 6)
end
end
end
end
#loads height-map
@height_map = RPG::Cache.height_map(map_id.to_s)
#loads swamp-map
@swamp_map = RPG::Cache.swamp_map(map_id.to_s)
end
#-----------------------------------------------------------------------------
# saves tables
#-----------------------------------------------------------------------------
def save_tables
return if self.map_id == 0
path = sprintf("Data/Tables/Map%03dC.rxdata", self.map_id)
save_data(@collision_table, path) if @pass_type != 'database'
path = sprintf("Data/Tables/Map%03dH.rxdata", self.map_id)
save_data(@height_table, path) if @height_map != nil
path = sprintf("Data/Tables/Map%03dS.rxdata", self.map_id)
save_data(@swamp_table, path) if @swamp_map != nil
end
#-----------------------------------------------------------------------------
# loads tables
#-----------------------------------------------------------------------------
def load_tables
return if self.map_id == 0
file = sprintf("Map%03dC.rxdata", self.map_id)
if not Dir.entries('Data/Tables/').include?(file)
if @pass_type != 'database'
@collision_table = Table.new(self.width * 32, self.height * 32)
end
if @height_map != nil
@height_table = Table.new(self.width * 32, self.height * 32)
end
if @swamp_map != nil
@swamp_table = Table.new(self.width * 32, self.height * 32)
end
return
end
path = sprintf("Data/Tables/Map%03dC.rxdata", self.map_id)
@collision_table = load_data(path) if @pass_type != 'database'
path = sprintf("Data/Tables/Map%03dH.rxdata", self.map_id)
@height_table = load_data(path) if @height_map != nil
path = sprintf("Data/Tables/Map%03dS.rxdata", self.map_id)
@swamp_table = load_data(path) if @swamp_map != nil
end
#-----------------------------------------------------------------------------
# loads waypoints for pathfinding
#-----------------------------------------------------------------------------
def load_waypoints
#---------------------------------------------------------------------------
# if waypoints have already been created
#---------------------------------------------------------------------------
if Dir.entries('Data/Waypoints/').include?(sprintf("Map%03d.rxdata",
self.map_id))
@waypoints = load_data(sprintf("Data/Waypoints/Map%03d.rxdata",
self.map_id))
return
end
#---------------------------------------------------------------------------
# if no waypoints are needed
#---------------------------------------------------------------------------
if (not $pixelmovement.waypoints_settings[0] and
not $pixelmovement.waypoints_settings[1].include?(self.map_id)) or
($pixelmovement.waypoints_settings[0] and
$pixelmovement.waypoints_settings[1].include?(self.map_id))
return
end
#---------------------------------------------------------------------------
# starts to create waypoints
#---------------------------------------------------------------------------
save_events = @events.clone
@events = {}
event = $game_player
size = event.size.clone
event.size['x'] = event.size['y'] = 8
# checks every place if there can be a waypoints
@waypoints = {}
for x in 0..self.width
for y in -1..self.height
real_x = x * 32
real_y = y * 32
if event.passable?(real_x, real_y - 1, 2, 2) and
event.passable?(real_x - 1, real_y, 6, 2)
@waypoints[[real_x, real_y]] = []
elsif event.passable?(real_x - 8, real_y - 9, 2, 2) and
event.passable?(real_x - 9, real_y - 8, 6, 2)
@waypoints[[real_x - 8, real_y - 8]] = []
elsif event.passable?(real_x + 8, real_y - 9, 2, 2) and
event.passable?(real_x + 7, real_y - 8, 6, 2)
@waypoints[[real_x + 8, real_y - 8]] = []
elsif event.passable?(real_x - 8, real_y + 7, 2, 2) and
event.passable?(real_x - 9, real_y + 8, 6, 2)
@waypoints[[real_x - 8, real_y + 8]] = []
elsif event.passable?(real_x + 8, real_y + 7, 2, 2) and
event.passable?(real_x + 7, real_y + 8, 6, 2)
@waypoints[[real_x + 8, real_y + 8]] = []
end
end
end
# sets time
check_time = Time.new
# creates connectios between waypoints
@waypoints.keys.each do |coords|
# checks if graphics haven't been updated for a long time (prevents error)
if Time.new - check_time >= 5
check_time = Time.new
Graphics.update
end
@waypoints.keys.each do |coords2|
next if coords2 == coords
dist = Math.sqrt((coords[0] - coords2[0]) ** 2 +
(coords[1] - coords2[1]) ** 2).round
iso = ((coords[1] - coords2[1] == 0 and dist == 64) or
((coords[0]-coords2[0]).abs == ((coords[1]-coords2[1]).abs * 2)) and
$pixelmovement.waypoints_settings[2])
next if dist > 100 or (dist > 50 and not iso)
sx = coords[0] - coords2[0]
sy = coords[1] - coords2[1]
if sx.abs > sy.abs * 2
sx > 0 ? dir = 4 : dir = 6
elsif sy.abs > sx.abs * 2
sy > 0 ? dir = 2 : dir = 2
elsif sx == 2 and sy == 8
else
if sy > 0
sx > 0 ? dir = 3 : dir = 1
else
sx > 0 ? dir = 9 : dir = 7
end
end
if iso
self.init_waypoint_path(coords, coords2, dir, dist, 'iso', event)
elsif [1, 3, 7, 9].include?(dir)
self.init_waypoint_path(coords, coords2, dir, dist, 'diag', event)
else
self.init_waypoint_path(coords, coords2, dir, dist, 'normal', event)
end
end
end
@waypoints.values.each {|infos| infos.delete_if {|cos| cos.last == 'error'}}
@waypoints.delete_if {|cos, infos| infos == []}
@waypoints.values.each {|list| list.sort! {| a, b | a[2] <=> b[2]}}
@events = save_events
$game_player.size = size
save_data(@waypoints, sprintf("Data/Waypoints/Map%03d.rxdata", self.map_id))
self.save_tables
end
#-----------------------------------------------------------------------------
# for pathfinding:
# checks if the way from start to target is passable and add it to @waypoints
#-----------------------------------------------------------------------------
def init_waypoint_path(start, target, d, dis, type, event)
if @waypoints[target] == nil or
@waypoints[target].include?([start[0], start[1], dis, type]) or
@waypoints[target].include?([start[0], start[1], dis, 'error'])
return
end
event.pathfinding.path_fast(start[0],start[1],target[0],target[1], dis*2/3)
if event.pathfinding.coords.include?(target)
@waypoints[start].push([target[0], target[1], dis, type])
@waypoints[target].push([start[0], start[1], dis, type])
else
@waypoints[target].push([start[0], start[1], dis, 'error'])
end
end
#-----------------------------------------------------------------------------
# Autotiles
#-----------------------------------------------------------------------------
def gen_autotiles(id, bitmap)
scroll = []
frame = []
autotile = bitmap
scroll[id] = 0
frame[id] = autotile.width / 96
width = 8 * 32 * frame[id]
height = 6 * 32
@collision_map[id] = Bitmap.new(width, height)
for f in 0...frame[id]
for pos in 0...48
for corner in [0,1,2,3]
h = 4 * pos + corner
yy = INDEX[h] / 6
xx = INDEX[h] % 6 + f * 6
y = pos / 8
x = pos % 8 + f * 8
src_rect = Rect.new(xx * 16 , yy * 16 , 16, 16 )
@collision_map[id].blt(x * 32 + X[corner] * 16,
y * 32 + Y[corner] * 16 , autotile, src_rect)
end
end
end
end
#-----------------------------------------------------------------------------
# Encounter steps has been made for Pixelmovement
#-----------------------------------------------------------------------------
def encounter_step
return pixelmovement_game_map_encounter_step * 32
end
#-----------------------------------------------------------------------------
# Scroll Down, edited for Looping Maps
#-----------------------------------------------------------------------------
def scroll_down(distance)
if $pixelmovement.loop_maps.include?(@map_id)
@display_y = @display_y + distance.round
else
pixelmovement_game_map_scroll_down(distance.round)
end
end
#-----------------------------------------------------------------------------
# Scroll Left, edited for Looping Maps
#-----------------------------------------------------------------------------
def scroll_left(distance)
if $pixelmovement.loop_maps.include?(@map_id)
@display_x = @display_x - distance.round
else
pixelmovement_game_map_scroll_left(distance.round)
end
end
#-----------------------------------------------------------------------------
# Scroll Right, edited for Looping Maps
#-----------------------------------------------------------------------------
def scroll_right(distance)
if $pixelmovement.loop_maps.include?(@map_id)
@display_x = @display_x + distance.round
else
pixelmovement_game_map_scroll_right(distance.round)
end
end
#-----------------------------------------------------------------------------
# Scroll Up, edited for Looping Maps
#-----------------------------------------------------------------------------
def scroll_up(distance)
if $pixelmovement.loop_maps.include?(@map_id)
@display_y = @display_y - distance.round
else
pixelmovement_game_map_scroll_up(distance.round)
end
end
#-----------------------------------------------------------------------------
# valid? method, uses real map-size now ( * 32)
#-----------------------------------------------------------------------------
def valid?(x, y)
return ($pixelmovement.loop_maps.include?(@map_id) or
(pixelmovement_game_map_valid?(x / 32, y / 32) and y >= 24))
end
#-----------------------------------------------------------------------------
# Passable? method
# has been rebuilt for both collision maps and databse passability
#-----------------------------------------------------------------------------
def passable?(x, y, d = 0, self_event = nil)
# returns if coords are not on the map
return false if not valid?(x, y)
# if d is not 2, 4, 6 or 8
case d
when 0
return true
when 1
return (passable?(x, y, 2, self_event) and passable?(x, y, 4, self_event))
when 3
return (passable?(x, y, 2, self_event) and passable?(x, y, 6, self_event))
when 7
return (passable?(x, y, 8, self_event) and passable?(x, y, 4, self_event))
when 9
return (passable?(x, y, 8, self_event) and passable?(x, y, 6, self_event))
else
return false if not [2, 4, 6, 8].include?(d)
end
# loads size
if self_event == nil
x_size = y_size = 2
else
x_size = [self_event.size['x'], 2].max
y_size = [self_event.size['y'], 2].max
end
# checks pixel on collision map / in the database
counter = 0
case d
when 2
fix = y - 1
for i in (x - x_size / 2)..(x + x_size / 2 - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(i, fix, d, self_event)
end
return counter >= x_size / 2
when 4
fix = (x - x_size / 2)
for i in (y - y_size)..(y - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(fix, i, d, self_event)
end
return counter >= y_size / 2
when 6
fix = (x + x_size / 2 - 1)
for i in (y - y_size)..(y - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(fix, i, d, self_event)
end
return counter >= y_size / 2
when 8
fix = (y - y_size)
for i in (x - x_size / 2)..(x + x_size / 2 - 1)
counter += 1 if i%2 == 0 and self.pixel_passable?(i, fix, d, self_event)
end
return counter >= x_size / 2
end
end
#-----------------------------------------------------------------------------
# Checks passability
#-----------------------------------------------------------------------------
def pixel_passable?(x, y, d, self_event)
# returns if coords are not on the map
return false if not valid?(x, y)
# on looped maps: coords are changed eventually
if $pixelmovement.loop_maps.include?(self.map_id)
if x >= (self.width * 32)
x -= (self.width * 32)
elsif x < 0
x += (self.width * 32)
end
if y >= (self.height * 32)
y -= (self.height * 32)
elsif y < 0
y += (self.height * 32)
end
end
# checks passability with the required method
if self.send("pass_#{@pass_type}", x, y, self_event)
@collision_table[x, y] = 2 if @pass_type != 'database'
return true
else
@collision_table[x, y] = 1 if @pass_type != 'database'
return false
end
end
#-----------------------------------------------------------------------------
# Checks passability if a Map Collision-Map is used
#-----------------------------------------------------------------------------
def pass_map(x, y, self_event)
# checks events with tile graphics, Loop in all events
for event in events.values
# If tiles other than self are consistent with coordinates
next if self_event == nil or event.tile_id < 48 or event == self_event or
not self_event.in_rect?(event.x, event.y - event.size['y'] / 2,
event.size['x'] - 1, event.size['y'] - 1, x, y) or event.through
# If obstacle bit is set
if @passages[event.tile_id] != 0
return false if !self.obstacle_passable?(x, y, @passages[event.tile_id])
# If priorities other than that are 0
elsif @priorities[event.tile_id] == 0
# passable
return true
end
end
# returns from the collision table if has been set
if @collision_table[x, y] != 0
return @collision_table[x, y] == 2 ? true : false
end
# returns pixel
return @collision_map.get_pixel(x, y) != Color.new(0, 0, 0)
end
#-----------------------------------------------------------------------------
# Checks passability if a Tileset Collision-Map is used
#-----------------------------------------------------------------------------
def pass_tileset(x, y, self_event)
# checks events with tile graphics, Loop in all events
for event in events.values
# If tiles other than self are consistent with coordinates
next if self_event == nil or event.tile_id < 48 or event == self_event or
not self_event.in_rect?(event.x, event.y - event.size['y'] / 2,
event.size['x'] - 1, event.size['y'] - 1, x, y) or event.through
pos = event.tile_id
if pos >= 384
type = 0
pos -= 384
x_check = (pos % 8) * 32 + x % 32
y_check = (pos / 8) * 32 + y % 32
else
type = pos / 48
pos = pos % 48
x_check = (pos % 8) * 32 + x % 32
y_check = (pos / 8) * 32 + y % 32
end
pixel = @collision_map[type].get_pixel(x_check, y_check)
return pixel != Color.new(0, 0, 0)
end
# returns from the collision table if has been set
if @collision_table[x, y] != 0
return @collision_table[x, y] == 2 ? true : false
end
#---------------------------------------------------------------------------
# initialising
#---------------------------------------------------------------------------
ignored_layers = [] # layers which are ignored if the field is checked
# because they are passable and empty or have a
# high priority
#---------------------------------------------------------------------------
# checks every layer
#---------------------------------------------------------------------------
for layer in [2, 1, 0]
pos = self.data[x / 32, y / 32, layer]
pos = 0 if pos == nil
passable = false
#-------------------------------------------------------------------------
# calculates position on collision map
#-------------------------------------------------------------------------
if pos >= 384
type = 0
pos -= 384
x_check = (pos % 8) * 32 + x % 32
y_check = (pos / 8) * 32 + y % 32
elsif pos >= 48
type = pos / 48
pos = pos % 48
x_check = (pos % 8) * 32 + x % 32
y_check = (pos / 8) * 32 + y % 32
elsif data[x / 32, y / 32, layer] != nil and
@passages[data[x / 32, y / 32, layer]] == 0
ignored_layers.push(layer)
next
end
#-------------------------------------------------------------------------
# checks collision map and saves result into the collision table / checks
# collision table (to check a table is faster!)
#-------------------------------------------------------------------------
if x_check != nil
pixel = @collision_map[type].get_pixel(x_check, y_check)
passable = true if pixel != Color.new(0, 0, 0)
end
if passable
if @priorities[data[x / 32, y / 32, layer]] != 0
ignored_layers.push(layer)
end
else
if layer == 2 or (ignored_layers.include?(layer + 1) and
(layer == 1 or (layer == 0 and ignored_layers.include?(layer + 2))))
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# checks passability from the database
#-----------------------------------------------------------------------------
def pass_database(x, y, self_event)
# checks events with tile graphics, Loop in all events
for event in events.values
# If tiles other than self are consistent with coordinates
next if self_event == nil or event.tile_id < 48 or event == self_event or
not self_event.in_rect?(event.x, event.y - event.size['y'] / 2,
event.size['x'] - 1, event.size['y'] - 1, x, y) or event.through
# If obstacle bit is set
if @passages[event.tile_id] != 0
return false if !self.obstacle_passable?(x, y, @passages[event.tile_id])
# If priorities other than that are 0
elsif @priorities[event.tile_id] == 0
# passable
return true
end
end
# Loop searches in order from top of layer
for i in [2, 1, 0]
# Get tile ID
tile_id = data[x / 32, y / 32, i]
# Tile ID acquistion failure
if tile_id == nil
# impassable
return false
# If obstacle bit is set
elsif @passages[tile_id] != 0
return false if not self.obstacle_passable?(x, y, @passages[tile_id])
# If priorities other than that are 0
elsif @priorities[tile_id] == 0
# passable
return true
end
end
end
#-----------------------------------------------------------------------------
# returns the passability of the current position subject to the
# obstacle settings
#-----------------------------------------------------------------------------
def obstacle_passable?(x, y, obstacle)
# what's passable?
case obstacle
# left, right, up
when 1
return y % 32 < 30
# right, up, down
when 2
return x % 32 > 8
# right, up
when 3
return (y % 32 < 30 and x % 32 > 8)
# left, up, down
when 4
return x % 32 < 24
# left, up
when 5
return (y % 32 < 30 and x % 32 < 24)
# up, down
when 6
return (x % 32 < 24 and x % 32 > 8)
# up
when 7
return (y % 32 < 30 and x % 32 < 24 and x % 32 > 8)
# left, right, down
when 8
return y % 32 > 16
# left, right
when 9
return (y % 32 < 30 and y % 32 > 16)
# right, down
when 10
return (y % 32 > 16 and x % 32 > 8)
# right
when 11
return (y % 32 < 30 and y % 32 > 16 and x % 32 > 8)
# left, down
when 12
return (y % 32 > 16 and x % 32 < 24)
# left
when 13
return (y % 32 < 30 and y % 32 > 16 and x % 32 < 24)
# down
when 14
return (y % 32 > 16 and x % 32 < 24 and x % 32 > 8)
# left, right, up
when 16
return y % 32 < 30
# bush
when 64
return true
# nothing
else
return false
end
end
#-----------------------------------------------------------------------------
# bush? method, converts Px Coords to Tile Coords
#-----------------------------------------------------------------------------
def bush?(x, y)
pixelmovement_game_map_bush?(x / 32, y / 32)
end
#-----------------------------------------------------------------------------
# counter? method, converts Px Coords to Tile Coords
#-----------------------------------------------------------------------------
def counter?(x, y)
pixelmovement_game_map_counter?(x / 32, y / 32)
end
#-----------------------------------------------------------------------------
# terrain method, converts Px Coords to Tile Coords
#-----------------------------------------------------------------------------
def terrain_tag(x, y)
pixelmovement_game_map_terrain_tag(x / 32, y / 32)
end
#-----------------------------------------------------------------------------
# check_event method
#-----------------------------------------------------------------------------
def check_event(x, y)
@events.values.each do |ev|
if ev.in_rect?(x, y + ev.size['y'] / 2, ev.size['x'], ev.size['y'])
return ev.id
end
end
end
#-----------------------------------------------------------------------------
# map update
#-----------------------------------------------------------------------------
def update
pixelmovement_game_map_update
# updates Caterpillars
if @game_party_actors_copy != $game_party.actors
@game_party_actors_copy = $game_party.actors.clone
$pixelmovement.switch_caterpillar($pixelmovement.cater_activate)
end
@game_party_actors.each {|actor| actor.update}
end
end
#===============================================================================
# Game_Character Class
#===============================================================================
class Game_Character
attr_accessor :x
attr_accessor :y
attr_accessor :stop_count
attr_accessor :direction
attr_accessor :event
attr_accessor :move_speed
attr_accessor :opacity
attr_accessor :walk_anime
attr_accessor :size
attr_accessor :step_anime
attr_accessor :speed_factor
attr_accessor :frame_number
attr_accessor :direction_number
attr_accessor :stand_frame
attr_accessor :frame_speed
attr_accessor :shift_x
attr_accessor :shift_y
attr_accessor :jump_count
attr_accessor :jump_peak
attr_accessor :pathfinding
attr_reader :always_on_top
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_game_character_initialize initialize
alias pixelmovement_game_character_screen_x screen_x
alias pixelmovement_game_character_screen_y screen_y
alias pixelmovement_game_character_screen_z screen_z
alias pixelmovement_game_character_update_stop update_stop
alias pixelmovement_game_character_turn_right_90 turn_right_90
alias pixelmovement_game_character_turn_left_90 turn_left_90
alias pixelmovement_game_character_turn_180 turn_180
end
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize
pixelmovement_game_character_initialize
@move_count = 0 # counts the movement
@move_speed = @move_speed * 1.0
@max_steps = 0 # for moving commands
@size = { 'x' => 32, 'y' => 32 } # Event-Size
@speed_factor = 1.0 # factor for changing the move speed with swamps/heights
@shift_x = @shift_y = 0 # shift of the graphic
@frame_speed = 1.0 # frame speed
@pathfinding = Game_Pathfinding.new(self)
end
#-----------------------------------------------------------------------------
# checks if Pixel Setting is activated, adds every event consisting a
# "jump/ice-comment" to an array or for special frame rates, etc..
#-----------------------------------------------------------------------------
def init_special_settings
@frame_number = $pixelmovement.frame_number
@direction_number = $pixelmovement.direction_number
@stand_frame = $pixelmovement.stand_frame
@frame_speed = $pixelmovement.frame_speed
end
#-----------------------------------------------------------------------------
# moving? method, for Pixel Coordinates
#-----------------------------------------------------------------------------
def moving?
return (@real_x != @x * 4 or @real_y != @y * 4)
end
#-----------------------------------------------------------------------------
# passable? method, for pixel passability and 8 directions
#-----------------------------------------------------------------------------
def passable?(x, y, d, steps = 32)
@max_steps = 0
#---------------------------------------------------------------------------
# initialising, @max_steps save the maximum number of steps (important if
# the method returns false)
#---------------------------------------------------------------------------
# Isomteric Movement
steps_x = steps * ($pixelmovement.isometric ? 2 : 1)
steps_y = steps
new_x = x + (d == 1 ? -steps_x : d == 3 ? steps_x : d == 7 ? -steps_x :
d == 9 ? steps_x : d == 6 ? steps_x : d == 4 ? -steps_x : 0)
new_y = y + (d == 1 ? steps_y : d == 3 ? steps_y : d == 7 ? -steps_y :
d == 9 ? -steps_y : d == 2 ? steps_y : d == 8 ? -steps_y : 0)
# for passable events
if @through and $game_map.valid?(new_x, new_y)
@max_steps = steps
return true
end
#---------------------------------------------------------------------------
# checks the way to the new position if it is passable
# (on the map and for events)
#---------------------------------------------------------------------------
counter = 0
case d
when 1
for i in 1..steps_x
if $game_map.passable?(x - i, y + i * steps_y / steps_x, d, self) and
not on_events?(x - i, y + i * steps_y / steps_x)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
when 2
for i in 1..steps_y
if $game_map.passable?(x, y + i, d, self) and not on_events?(x, y + i)
counter += 1
else
break
end
end
when 3
for i in 1..steps_x
if $game_map.passable?(x + i, y + i * steps_y / steps_x, d, self) and
not on_events?(x + i, y + i * steps_y / steps_x)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
when 4
for i in 1..steps_x
if $game_map.passable?(x - i, y, d, self) and not on_events?(x - i, y)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
when 6
for i in 1..steps_x
if $game_map.passable?(x + i, y, d, self) and not on_events?(x + i, y)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
when 7
for i in 1..steps_x
if $game_map.passable?(x - i, y - i * steps_y / steps_x, d, self) and
not on_events?(x - i, y - i * steps_y / steps_x)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
when 8
for i in 1..steps_y
if $game_map.passable?(x, y - i, d, self) and not on_events?(x, y - i)
counter += 1
else
break
end
end
when 9
for i in 1..steps_x
if $game_map.passable?(x + i, y - i * steps_y / steps_x, d, self) and
not on_events?(x + i, y - i * steps_y / steps_x)
counter += 1
else
break
end
end
counter /= 2 if $pixelmovement.isometric
end
@max_steps = counter
return false if counter < steps
#---------------------------------------------------------------------------
# passable
#---------------------------------------------------------------------------
return true
end
#-----------------------------------------------------------------------------
# moveto method, for Pixel Coords
#-----------------------------------------------------------------------------
def moveto(x, y)
@x = x % ($game_map.width * 32)
@y = y % ($game_map.height * 32)
@real_x = @x * 4
@real_y = @y * 4
@prelock_direction = 0
end
#--------------------------------------------------------------------------
# Get Screen X-Coordinates
#--------------------------------------------------------------------------
def screen_x
return pixelmovement_game_character_screen_x - 16 + @shift_x
end
#--------------------------------------------------------------------------
# Get Screen Y-Coordinates
#--------------------------------------------------------------------------
def screen_y
return pixelmovement_game_character_screen_y - 32 + @shift_y
end
#--------------------------------------------------------------------------
# Get Screen Z-Coordinates
#--------------------------------------------------------------------------
def screen_z(height = 0)
return pixelmovement_game_character_screen_z(height) - 32 + @shift_y
end
#-----------------------------------------------------------------------------
# update method, has been splitted to give an easier overview
#-----------------------------------------------------------------------------
def update
#---------------------------------------------------------------------------
# updates
#---------------------------------------------------------------------------
# update special for looped maps
self.update_loop_map
# checks if the move speed changes because of hills, swamps, etc.
self.move_speed_change
# updates pathfinding (or creates new)
@pathfinding.update
if self.jumping?
self.update_jump
elsif self.moving?
self.update_move
else
self.update_stop
end
# updates shown frame
if @anime_count * @frame_speed > (18 - @move_speed * 2) * 4 /
@frame_number or (@pattern == 0 and @move_count == 1)
if not @step_anime and @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % (@frame_number - @stand_frame)
end
@anime_count = 0
end
if @wait_count > 0
@wait_count -= 1
return
end
if @move_route_forcing
self.move_type_custom
return
end
return if @starting or lock?
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
case @move_type
when 1
self.move_type_random
when 2
self.move_type_toward_player
when 3
self.move_type_custom
end
end
end
#-----------------------------------------------------------------------------
# Character is not moving
#-----------------------------------------------------------------------------
def update_stop
@move_count = 0
pixelmovement_game_character_update_stop
end
#-----------------------------------------------------------------------------
# checks if the speed has to be changed because of the ground
#-----------------------------------------------------------------------------
def move_speed_change
return if $game_map.height_map == nil and $game_map.swamp_map == nil
@move_speed /= @speed_factor
@speed_factor = 1.0 # changing factor
#---------------------------------------------------------------------------
# checks height-map
#---------------------------------------------------------------------------
if $game_map.height_map != nil
# loads x, y coordinates
x = @x
y = @y
new_x = x + (@direction == 1 ? -2 : @direction == 3 ? 2 :
@direction == 7 ? -2 : @direction == 9 ? 2 :
@direction == 6 ? 2 : @direction == 4 ? -2 : 0)
new_y = y + (@direction == 1 ? 2 : @direction == 3 ? 2 :
@direction == 7 ? -2 : @direction == 9 ? -2 :
@direction == 2 ? 2 : @direction == 8 ? -2 : 0)
# loads z coordinates
z = $game_map.height_table[x - 1, y - 1]
if z == 0
z = $game_map.height_map.get_pixel(x, y).red
$game_map.height_table[x - 1, y - 1] = z
end
new_z = $game_map.height_table[new_x - 1, new_y - 1]
if new_z == 0
new_z = $game_map.height_map.get_pixel(new_x, new_y).red
$game_map.height_table[new_x - 1, new_y - 1] = new_z
end
# changes factor
@speed_factor *= 1 + (z-new_z) / @move_speed if z != nil and new_z != nil
end
#---------------------------------------------------------------------------
# checks swamp-map
#---------------------------------------------------------------------------
if $game_map.swamp_map != nil
# loads coordinates
x = @x
y = @y - 1
# loads swamp pixel
px = $game_map.swamp_table[x, y]
if px == 0
px = $game_map.swamp_map.get_pixel(x, y).red
$game_map.swamp_table[x, y] = px
elsif px == nil
px = 255.0
end
@speed_factor *= px / 255.0
end
# changes speed
@speed_factor = [[0.1, (@speed_factor * 1000).round / 1000.0].max, 2.0].min
@move_speed *= @speed_factor
end
#-----------------------------------------------------------------------------
# Loop Map Teleport when Event reached the border, etc.
#-----------------------------------------------------------------------------
def update_loop_map
# returns if map isnt looped
return if not $pixelmovement.loop_maps.include?($game_map.map_id)
# teleports at the border
if @x > $game_map.width * 32
@x -= $game_map.width * 32
@real_x = @x * 4
elsif @x < 0
@x += $game_map.width * 32
@real_x = @x * 4
end
if @y > $game_map.height * 32
@y -= $game_map.height * 32
@real_y = @y * 4
elsif @y < 0
@y += $game_map.height * 32
@real_y = @y * 4
end
end
#-----------------------------------------------------------------------------
# update_jump, for Pixel coords
#-----------------------------------------------------------------------------
def update_jump
@jump_count -= 1
@real_x = (@real_x * @jump_count + @x * 4) / (@jump_count + 1)
@real_y = (@real_y * @jump_count + @y * 4) / (@jump_count + 1)
end
#-----------------------------------------------------------------------------
# update_move, for Pixel coords + Isometric Script, Straight Movement
#-----------------------------------------------------------------------------
def update_move
# for isometric movement
if $pixelmovement.isometric and @iso_x != nil and @iso_x != @x
@x -= @iso_x - @x
end
#---------------------------------------------------------------------------
# y movement
#---------------------------------------------------------------------------
distance = (2 ** @move_speed)
# changes distance so the event uses the straight way
if (@x * 4 - @real_x).abs != 0 and (@y * 4 - @real_y).abs <
(@x * 4 - @real_x).abs / ($pixelmovement.isometric ? 2 : 1)
distance *= ($pixelmovement.isometric ? 2.0 : 1.0) *
(@y * 4 - @real_y).abs / (@x * 4 - @real_x).abs
end
# moves the character
if @y * 4 < @real_y
@real_y = [@real_y - distance.round, @y * 4].max
elsif @y * 4 > @real_y
@real_y = [@real_y + distance.round, @y * 4].min
end
#---------------------------------------------------------------------------
# x movement
#---------------------------------------------------------------------------
distance = (2 ** @move_speed) * ($pixelmovement.isometric ? 2 : 1)
# changes distance so the event uses the straight way
if (@y*4 - @real_y).abs != 0 and (@x*4 - @real_x).abs /
($pixelmovement.isometric ? 2 : 1) < (@y*4 - @real_y).abs
distance *= ($pixelmovement.isometric ? 0.5 : 1.0) *
(@x*4 - @real_x).abs / (@y*4 - @real_y).abs
end
# moves the character
real_x = @real_x
if @x * 4 < @real_x
@real_x = [@real_x - distance.round, @x * 4].max
elsif @x * 4 > @real_x
@real_x = [@real_x + distance.round, @x * 4].min
end
# changes variables for the frames
@move_count += 1
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
# for isometric movement
@iso_x = @x if $pixelmovement.isometric
end
#-----------------------------------------------------------------------------
# New Move Toward Player (more pixellike)
#-----------------------------------------------------------------------------
def move_type_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx.abs + sy.abs >= 32 * 20
move_random(32)
elsif sx.abs > 0 or sy.abs > 0
move_toward_player(32)
end
end
#-----------------------------------------------------------------------------
# New Move Route (more pixellike)
#-----------------------------------------------------------------------------
def move_type_custom
return if jumping? or moving?
#---------------------------------------------------------------------------
# commands
#---------------------------------------------------------------------------
while @move_route_index < @move_route.list.size
command = @move_route.list[@move_route_index]
if command.code == 0
@move_route_index = 0 if @move_route.repeat
unless @move_route.repeat
if @move_route_forcing and not @move_route.repeat
@move_route_forcing = false
@move_route = @original_move_route
@move_route_index = @original_move_route_index
@original_move_route = nil
# for pathfinding
if @pathfinding.active
@pathfinding.active = false
self.turn_toward_coords(@pathfinding.target_x,
@pathfinding.target_y)
end
end
@stop_count = 0
end
return
end
if command.code <= 14
command.parameters[0] = 32 if command.parameters[0] == nil
case command.code
when 1
move_down(command.parameters[0], true)
when 2
move_left(command.parameters[0], true)
when 3
move_right(command.parameters[0], true)
when 4
move_up(command.parameters[0], true)
when 5
move_lower_left(command.parameters[0], true)
when 6
move_lower_right(command.parameters[0], true)
when 7
move_upper_left(command.parameters[0], true)
when 8
move_upper_right(command.parameters[0], true)
when 9
move_random(command.parameters[0], true)
when 10
move_toward_player(command.parameters[0])
when 11
move_away_from_player(command.parameters[0])
when 12
move_forward(command.parameters[0])
when 13
move_backward(command.parameters[0])
when 14
jump(command.parameters[0] * 32 + 16, command.parameters[1] * 32 + 30)
end
return if not @move_route.skippable and not moving? and not jumping?
@move_route_index += 1
return
end
if command.code == 15
@wait_count = command.parameters[0] * 2 - 1
@move_route_index += 1
return
end
if command.code >= 16 and command.code <= 26
case command.code
when 16
turn_down
when 17
turn_left
when 18
turn_right
when 19
turn_up
when 20
turn_right_90
when 21
turn_left_90
when 22
turn_180
when 23
turn_right_or_left_90
when 24
turn_random
when 25
turn_toward_player
when 26
turn_away_from_player
end
@move_route_index += 1
return
end
if command.code >= 27
case command.code
when 27
$game_switches[command.parameters[0]] = true
$game_map.need_refresh = true
when 28
$game_switches[command.parameters[0]] = false
$game_map.need_refresh = true
when 29
@move_speed = command.parameters[0]
when 30
@move_frequency = command.parameters[0]
when 31
@walk_anime = true
when 32
@walk_anime = false
when 33
@step_anime = true
when 34
@step_anime = false
when 35
@direction_fix = true
when 36
@direction_fix = false
when 37
@through = true
when 38
@through = false
when 39
@always_on_top = true
when 40
@always_on_top = false
when 41
@tile_id = 0
@character_name = command.parameters[0]
@character_hue = command.parameters[1]
if @original_direction != command.parameters[2]
@direction = command.parameters[2]
@original_direction = @direction
@prelock_direction = 0
end
if @original_pattern != command.parameters[3]
@pattern = command.parameters[3]
@original_pattern = @pattern
end
when 42
@opacity = command.parameters[0]
when 43
@blend_type = command.parameters[0]
when 44
$game_system.se_play(command.parameters[0])
when 45
result = eval(command.parameters[0])
end
@move_route_index += 1
end
end
end
#-----------------------------------------------------------------------------
# move_down, more pixellike
#-----------------------------------------------------------------------------
def move_down(steps = 32, turn_enabled = true)
self.turn_down if turn_enabled
# passable?
if passable?(@x, @y, 2, steps)
@y += @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x, @y + @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@y += @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_left, more pixellike
#-----------------------------------------------------------------------------
def move_left(steps = 32, turn_enabled = true)
self.turn_left if turn_enabled
# passable?
if passable?(@x, @y, 4, steps)
@x -= @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x - @max_steps, @y)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x -= @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_right, more pixellike
#-----------------------------------------------------------------------------
def move_right(steps=32, turn_enabled = true)
self.turn_right if turn_enabled
# passable?
if passable?(@x, @y, 6, steps)
@x += @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x + @max_steps, @y)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x += @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_up, more pixellike
#-----------------------------------------------------------------------------
def move_up(steps = 32, turn_enabled = true)
self.turn_up if turn_enabled
# passable?
if passable?(@x, @y, 8, steps)
@y -= @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x, @y - @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@y -= @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_lower_left, more pixellike
#-----------------------------------------------------------------------------
def move_lower_left (steps = 32, turn_enabled = true)
self.turn_lower_left if turn_enabled
# passable?
if passable?(@x, @y, 1, steps)
@x -= @max_steps
@y += @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x - @max_steps, @y + @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x -= @max_steps
@y += @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_lower_right, more pixellike
#-----------------------------------------------------------------------------
def move_lower_right(steps = 32, turn_enabled = true)
self.turn_lower_right if turn_enabled
# passable?
if passable?(@x, @y, 3, steps)
@x += @max_steps
@y += @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x + @max_steps, @y + @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x += @max_steps
@y += @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_upper_left, more pixellike
#-----------------------------------------------------------------------------
def move_upper_left(steps = 32, turn_enabled = true)
self.turn_upper_left if turn_enabled
# passable?
if passable?(@x, @y, 7, steps)
@x -= @max_steps
@y -= @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x - @max_steps, @y - @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x -= @max_steps
@y -= @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_upper_right, more pixellike
#-----------------------------------------------------------------------------
def move_upper_right(steps = 32, turn_enabled = true)
self.turn_upper_right if turn_enabled
# passable?
if passable?(@x, @y, 9, steps)
@x += @max_steps
@y -= @max_steps
increase_steps
else
# checks for event activation
check_event_trigger_touch(@x + @max_steps, @y - @max_steps)
# not passable but the character can walk (@maxsteps > 0)
if (@max_steps > 0 and @max_steps < steps)
@x += @max_steps
@y -= @max_steps
increase_steps
end
end
@max_steps = 0
end
#-----------------------------------------------------------------------------
# move_random, more pixellike
#-----------------------------------------------------------------------------
def move_random(steps = (rand(9) + 8) * 2, turn_enabled = true)
# for different movement types
add = 0
case $pixelmovement.movement_type
when 'dir8'
number = 12
when 'dir4'
number = 8
when 'dir4diag'
number = 4
add = 8
end
case rand(number) + add
when 0..1
move_down(steps, turn_enabled)
when 2..3
move_left(steps, turn_enabled)
when 4..5
move_right(steps, turn_enabled)
when 6..7
move_up(steps, turn_enabled)
when 8
move_lower_left(steps, turn_enabled)
when 9
move_lower_right(steps, turn_enabled)
when 10
move_upper_left(steps, turn_enabled)
when 11
move_upper_right(steps, turn_enabled)
end
end
#-----------------------------------------------------------------------------
# move_toward_event, more pixellike
#-----------------------------------------------------------------------------
def move_toward_event(id, steps = 32)
case rand(6)
when 0..4
self.turn_toward_event(id)
self.move_forward(steps)
when 5
if steps < 16
self.move_random(steps * 2)
else
self.move_random(steps)
end
end
end
#-----------------------------------------------------------------------------
# move_toward_player, more pixellike
#-----------------------------------------------------------------------------
def move_toward_player(steps = 32)
self.move_toward_event(0, steps)
end
#-----------------------------------------------------------------------------
# move_away_from_event, more pixellike
#-----------------------------------------------------------------------------
def move_away_from_event(id, steps = 32)
case rand(6)
when 0..4
self.turn_away_from_event(id)
self.move_forward(steps)
when 5
if steps < 16
self.move_random(steps * 2)
else
self.move_random(steps)
end
end
end
#-----------------------------------------------------------------------------
# move_away_from_player, more pixellike
#-----------------------------------------------------------------------------
def move_away_from_player(steps = 32)
self.move_away_from_event(0, steps)
end
#-----------------------------------------------------------------------------
# move_forward, more pixellike
#-----------------------------------------------------------------------------
def move_forward(steps = 32)
case @direction
when 1
move_lower_left(steps, false)
when 2
move_down(steps, false)
when 3
move_lower_right(steps, false)
when 4
move_left(steps, false)
when 6
move_right(steps, false)
when 7
move_upper_left(steps, false)
when 8
move_up(steps, false)
when 9
move_upper_right(steps, false)
end
end
#-----------------------------------------------------------------------------
# move_backward, more pixellike
#-----------------------------------------------------------------------------
def move_backward(steps = 32)
last_direction_fix = @direction_fix
@direction_fix = true
case @direction
when 1
move_upper_right(steps, false)
when 2
move_up(steps, false)
when 3
move_upper_left(steps, false)
when 4
move_right(steps, false)
when 6
move_left(steps, false)
when 7
move_lower_right(steps, false)
when 8
move_down(steps, false)
when 9
move_lower_left(steps, false)
end
@direction_fix = last_direction_fix
end
#-----------------------------------------------------------------------------
# moves straight to the coordinates x, y
# possible move forms: normal, straight, parabola, random
#-----------------------------------------------------------------------------
def move_to_place(x, y)
self.turn_toward_coords(x, y)
@x = x
@iso_x = @x if $pixelmovement.isometric
@y = y
increase_steps
end
#-----------------------------------------------------------------------------
# turn_lower_left
#-----------------------------------------------------------------------------
def turn_lower_left
return if @direction_fix
@direction = 1
@stop_count = 0
end
#-----------------------------------------------------------------------------
# turn_lower_right
#-----------------------------------------------------------------------------
def turn_lower_right
return if @direction_fix
@direction = 3
@stop_count = 0
end
#-----------------------------------------------------------------------------
# turn_upper_left
#-----------------------------------------------------------------------------
def turn_upper_left
return if @direction_fix
@direction = 7
@stop_count = 0
end
#-----------------------------------------------------------------------------
# turn_upper_right
#-----------------------------------------------------------------------------
def turn_upper_right
return if @direction_fix
@direction = 9
@stop_count = 0
end
#-----------------------------------------------------------------------------
# turn_right_90, for 8 directions
#-----------------------------------------------------------------------------
def turn_right_90
pixelmovement_game_character_turn_right_90
case @direction
when 1
turn_upper_left
when 3
turn_lower_left
when 7
turn_upper_right
when 9
turn_lower_right
end
end
#-----------------------------------------------------------------------------
# turn_left_90, for 8 directions
#-----------------------------------------------------------------------------
def turn_left_90
pixelmovement_game_character_turn_left_90
case @direction
when 1
turn_lower_right
when 3
turn_upper_right
when 7
turn_lower_left
when 9
turn_upper_left
end
end
#-----------------------------------------------------------------------------
# turn_180, for 8 directions
#-----------------------------------------------------------------------------
def turn_180
pixelmovement_game_character_turn_180
case @direction
when 1
turn_upper_right
when 3
turn_upper_left
when 7
turn_lower_right
when 9
turn_lower_left
end
end
#-----------------------------------------------------------------------------
# turn_random, for 8 directions
#-----------------------------------------------------------------------------
def turn_random
# for different movement types
add = 0
case $pixelmovement.movement_type
when 'dir8'
number = 12
when 'dir4'
number = 8
when 'dir4diag'
number = 4
add = 8
end
case rand(number) + add
when 0..1
turn_up
when 2..3
turn_right
when 4..5
turn_left
when 6..7
turn_down
when 8
turn_upper_right
when 9
turn_upper_left
when 10
turn_lower_right
when 11
turn_lower_left
end
end
#-----------------------------------------------------------------------------
# looks to x, y
#-----------------------------------------------------------------------------
def turn_toward_coords(x, y)
sx = x - @x
sy = y - @y
return if sx == 0 and sy == 0
if $pixelmovement.movement_type == 'dir8'
if sx.abs > sy.abs * 2
sx > 0 ? turn_right : turn_left
elsif sy.abs > sx.abs * 2
sy > 0 ? turn_down : turn_up
else
if sy > 0
sx > 0 ? turn_lower_right : turn_lower_left
else
sx > 0 ? turn_upper_right : turn_upper_left
end
end
elsif $pixelmovement.movement_type == 'dir4'
if sx.abs > sy.abs
sx > 0 ? turn_right : turn_left
else sy.abs > sx.abs
sy > 0 ? turn_down : turn_up
end
elsif $pixelmovement.movement_type == 'dir4diag'
if sy > 0
sx > 0 ? turn_lower_right : turn_lower_left
else
sx > 0 ? turn_upper_right : turn_upper_left
end
end
end
#-----------------------------------------------------------------------------
# turn_toward_event, for 8 directions
#-----------------------------------------------------------------------------
def turn_toward_event(id)
event = (id == 0) ? $game_player : $game_map.events[id]
self.turn_toward_coords(event.x, event.y)
end
#-----------------------------------------------------------------------------
# turn_toward_player, for 8 directions
#-----------------------------------------------------------------------------
def turn_toward_player
self.turn_toward_event(0)
end
#-----------------------------------------------------------------------------
# turn_away_from_player, for 8 directions
#-----------------------------------------------------------------------------
def turn_away_from_player
self.turn_toward_event(0)
self.turn_180
end
#-----------------------------------------------------------------------------
# turn_away_from_event, for 8 directions
#-----------------------------------------------------------------------------
def turn_away_from_event(id)
self.turn_toward_event(id)
self.turn_180
end
#-----------------------------------------------------------------------------
# returns direction in which the event[id] lies
#-----------------------------------------------------------------------------
def direction_to(id)
dir = @direction
stop = @stop_count
self.turn_toward_event(id)
result = @direction
@direction = dir
@stop_count = stop
return result
end
#-----------------------------------------------------------------------------
# returns the face direction of the sprite
#-----------------------------------------------------------------------------
def real_dir
if @direction_number == 8
return @direction
elsif @direction_number == 4
return self.char_sprite.direction if self.char_sprite.direction != nil
end
return 0
end
#-----------------------------------------------------------------------------
# returns if self looks at the event[id], if the distance is small not the
# exact direction is needed for a "true" (e.g. 3 instead 2)
#-----------------------------------------------------------------------------
def looks_at?(id)
result = self.direction_to(id)
return true if @direction == result
return false if self.distance_to_event(id) > 32
event = (id == 0) ? $game_player : $game_map.events[id]
return true if @direction == 1 and [2, 4].include?(result)
return true if @direction == 2 and [1, 3].include?(result)
return true if @direction == 3 and [2, 6].include?(result)
return true if @direction == 4 and [1, 7].include?(result)
return true if @direction == 6 and [3, 9].include?(result)
return true if @direction == 7 and [4, 8].include?(result)
return true if @direction == 8 and [7, 9].include?(result)
return (@direction == 9 and [6, 8].include?(result))
end
#-----------------------------------------------------------------------------
# new jump, height added, for Pixel Coords
#-----------------------------------------------------------------------------
def jump(x_plus, y_plus, height = 5)
new_x = @x + x_plus
new_y = @y + y_plus
if (x_plus != 0 or y_plus != 0) and $game_map.passable?(new_x,new_y,0,self)
self.turn_toward_coords(new_x, new_y) if x_plus != 0 or y_plus != 0
self.straighten
@x = new_x
@y = new_y
height_2 = 100 / height
x_plus /= height_2
y_plus /= height_2
distance = [x_plus.abs,y_plus.abs].max
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
@stop_count = 0
end
end
#-----------------------------------------------------------------------------
# jumps to coordiantes x, y
#-----------------------------------------------------------------------------
def jump_to (x, y, height = 5)
self.jump(x - @x, y - @y, height)
end
#-----------------------------------------------------------------------------
# returns if the event is inside the circle
#-----------------------------------------------------------------------------
def in_circle?(cx, cy, radius, sx = @x, sy = @y)
return Math.sqrt((cx - sx) ** 2 + (cy - sy) ** 2) <= radius
end
#-----------------------------------------------------------------------------
# returns of the event is inside the square
#-----------------------------------------------------------------------------
def in_square?(mx, my, r, sx = @x, sy = @y)
return (sx >= mx - r and sx <= mx + r and sy >= my - r and sy <= my + r)
end
#-----------------------------------------------------------------------------
# returns of the event is inside the rectangle
#-----------------------------------------------------------------------------
def in_rect?(mx, my, w, h, sx = @x, sy = @y)
return (sx >= mx-w/2 and sx <= mx+w/2 and sy >= my-h/2 and sy <= my+h/2)
end
#-----------------------------------------------------------------------------
# returns if an event is at the same place as this event
#-----------------------------------------------------------------------------
def on_event?(event, sx = @x, sy = @y, ex = event.x, ey = event.y,
w_add = 0, h_add = 0)
return (self.in_rect?(ex, ey - event.size['y'] / 2 + @size['y'] /
2, event.size['x'] + @size['x'] + w_add - 2, event.size['y'] +
@size['y'] + h_add - 2, sx, sy) and event != self)
end
#-----------------------------------------------------------------------------
# returns if the position is not passable because there is an event
#-----------------------------------------------------------------------------
def on_events?(x, y)
#---------------------------------------------------------------------------
# checks if an Event is on the same place
#---------------------------------------------------------------------------
for event in $game_map.events.values
if self.on_event?(event, x,y) and not event.through and
(self != $game_player or event.character_name != '')
return true
end
end
#---------------------------------------------------------------------------
# checks if the Player is on the same place
#---------------------------------------------------------------------------
if self.on_event?($game_player, x, y) and !$game_player.through and
@character_name != ''
return true
end
return false
end
#-----------------------------------------------------------------------------
# returns the distance to the event with id as its id, 0 means game_player
#-----------------------------------------------------------------------------
def distance_to_event(id)
ev = (id == 0) ? $game_player : $game_map.events[id]
return Math.sqrt((@x - ev.x) * (@x - ev.x) + (@y - ev.y) * (@y - ev.y))
end
#-----------------------------------------------------------------------------
# self stays in the given range of the event with id as its id, 0 means
# game_player
#-----------------------------------------------------------------------------
def stay_in_range(id, d1 = 0, d2 = 640)
if self.distance_to_event(id) < d1
self.move_away_from_event(id)
elsif self.distance_to_event(id) > d2
self.move_toward_event(id)
end
end
#-----------------------------------------------------------------------------
# returns Sprite (ID) of the event
#-----------------------------------------------------------------------------
def char_sprite(id = false)
return if not $scene.is_a?(Scene_Map)
for i in 0..$scene.spriteset.character_sprites.length - 1
if $scene.spriteset.character_sprites[i].character == self
return (id ? i : $scene.spriteset.character_sprites[i])
end
end
end
#-----------------------------------------------------------------------------
# Pathfinding to a Place / Coords
#-----------------------------------------------------------------------------
def find_path (target_x, target_y, radius = 0, walk = true)
if $game_map.valid?(target_x, target_y) and
$game_map.passable?(target_x, target_y, 0, self)
@pathfinding.find_path(target_x, target_y, walk, radius)
end
end
#-----------------------------------------------------------------------------
# Pathfinding to an Event
#-----------------------------------------------------------------------------
def find_event(id, radius = 0, walk = true)
target = (id == 0) ? $game_player : $game_map.events[id]
if target.through
@pathfinding.find_path(target.x, target.y, walk, radius)
else
radius = (radius >= @size.values.max + 4 ? radius : @size.values.max + 4)
@pathfinding.find_path(target.x, target.y, walk, radius)
end
end
#-----------------------------------------------------------------------------
# Returns true if self reached the target
#-----------------------------------------------------------------------------
def reached_target?
return (not @pathfinding.active)
end
end
#===============================================================================
# Game_Event Class
#===============================================================================
class Game_Event < Game_Character
attr_reader :page
attr_accessor :trigger_on
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_game_event_initialize initialize
alias pixelmovement_game_event_refresh refresh
alias pixelmovement_game_event_erase erase
if Object.const_defined?(:Antilag_Settings)
alias pixelmovement_game_event_in_range? in_range?
end
alias pixelmovement_game_event_update update
end
#-----------------------------------------------------------------------------
# initialsing method, Event is teleported to Pixel Coords
#-----------------------------------------------------------------------------
def initialize(map_id, event)
pixelmovement_game_event_initialize(map_id, event)
@move_count = 0 # counts the movement
@move_speed = @move_speed * 1.0
@max_steps = 0 # for moving commands
@trigger_on = false # used to prevent multi-event-activation
@size = { 'x' => 32, 'y' => 32 } # Event-Size
@frame_speed = 1.0
@speed_factor = 1.0 # factor for changing the move speed with swamps/heights
@shift_x = @shift_y = 0
@pathfinding = Game_Pathfinding.new(self)
moveto(@event.x * 32 + 16, @event.y * 32 + 30)
refresh
end
#-----------------------------------------------------------------------------
# refreshes the event
#-----------------------------------------------------------------------------
def refresh
pixelmovement_game_event_refresh
self.init_special_settings
end
#-----------------------------------------------------------------------------
# checks if Pixel Setting is activated, adds every event consisting a
# "jump/ice-comment" to an array or for special frame rates, etc..
#-----------------------------------------------------------------------------
def init_special_settings
return if @erased
super
#---------------------------------------------------------------------------
# loads comments
#---------------------------------------------------------------------------
i = 0
while @page.list[i].code == 108 or @page.list[i].code == 408
if @page.list[i].parameters[0].downcase.include?('teleport:')
bla = @page.list[i].parameters[0].split(/:/)[1].split(/,/)
self.moveto(bla[0].to_i,bla[1].to_i)
elsif @page.list[i].parameters[0].downcase.include?('jump:')
$game_map.jump_events[@id] = self
elsif @page.list[i].parameters[0].downcase.include?('ice:')
$game_map.ice_events[@id] = self
elsif @page.list[i].parameters[0].downcase.include?('frames:')
@frame_number = @page.list[i].parameters[0].split(/:/)[1].to_i
elsif @page.list[i].parameters[0].downcase.include?('stand frame:')
@stand_frame = @page.list[i].parameters[0].split(/:/)[1].to_i
elsif @page.list[i].parameters[0].downcase.include?('directions:')
@direction_number = @page.list[i].parameters[0].split(/:/)[1].to_i
elsif @page.list[i].parameters[0].downcase.include?('shift x:')
@shift_x = @page.list[i].parameters[0].split(/:/)[1].to_i
elsif @page.list[i].parameters[0].downcase.include?('shift y:')
@shift_y = @page.list[i].parameters[0].split(/:/)[1].to_i
elsif @page.list[i].parameters[0].downcase.include?('frame speed:')
@frame_speed = @page.list[i].parameters[0].split(/:/)[1].to_i
end
i += 1
end
#---------------------------------------------------------------------------
# loads event size
#---------------------------------------------------------------------------
if @character_name != ''
bit = Bitmap.new(name = 'Graphics/Characters/' + @character_name)
bla = [bit.width / @frame_number/4, bit.height / @direction_number/4].max
+ $pixelmovement.event_size_add
@size['x'] = bla
@size['y'] = bla
end
i = 0
while @page.list[i].code == 108 or @page.list[i].code == 408
if @page.list[i].parameters[0].downcase.include?('event_size:')
bla = @page.list[i].parameters[0].split(/:/)[1]
if not bla.include?(',')
@size['x'] = bla.to_i
@size['y'] = bla.to_i
else
bla = bla.split(/,/)
@size['x'] = bla[0].to_i
@size['y'] = bla[1].to_i
end
break
end
i += 1
end
end
#----------------------------------------------------------------------------
# Temporarily Erase
#----------------------------------------------------------------------------
def erase
$game_map.jump_events[@id] = nil if $game_map.jump_events.keys.include?(@id)
$game_map.ice_events[@id] = nil if $game_map.ice_events.keys.include?(@id)
pixelmovement_game_event_erase
end
#-----------------------------------------------------------------------------
# Activation: Collision, Not Passable
#-----------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
return if $game_system.map_interpreter.running?
if @trigger == 2 and !jumping? and !over_trigger? and !@trigger_on and
self.in_rect?($game_player.real_x / 4,
$game_player.real_y / 4 - $game_player.size['y'] / 2 + @size['y'] / 2,
$game_player.size['x'] + @size['x'] + 8,
$game_player.size['y'] + @size['y'] + 8, @real_x / 4, @real_y / 4)
@trigger_on = true
self.start
end
end
#-----------------------------------------------------------------------------
# Activation: Collision / Autostart, Passable
#-----------------------------------------------------------------------------
def check_event_trigger_auto
if @trigger == 2 and not jumping? and over_trigger? and not @trigger_on and
Graphics.frame_count > 0 and
(($game_player.character_name != '' and self.in_rect?($game_player.real_x/4,
$game_player.real_y / 4 - $game_player.size['y'] / 2 + @size['y'] / 2,
$game_player.size['x'] + @size['x'], $game_player.size['y'] + @size['y'],
@real_x / 4,@real_y / 4)) or
($game_player.character_name == '' and self.in_rect?($game_player.real_x/4,
$game_player.real_y / 4 - $game_player.size['y'] / 2 + @size['y'] / 2,
$game_player.size['x'] / 2, $game_player.size['y'] / 2,@real_x / 4,
@real_y / 4)))
@trigger_on = true
self.start
end
self.start if @trigger == 3
end
#-----------------------------------------------------------------------------
# for Anti_Lag, decides, if an object is on the screen or not.
# Special: Events including an ice or jump comment always return false
# only if the Anti-Lag Script is used, too
#-----------------------------------------------------------------------------
if Object.const_defined?(:Antilag_Settings)
def in_range?
if ($game_map.ice_events.keys.include?(@id) or
$game_map.jump_events.keys.include?(@id))
return false
end
result = pixelmovement_game_event_in_range?
if $pixelmovement.loop_maps.include?($game_map.map_id) and not result
screne_x = $game_map.display_x
screne_x -= 256
screne_y = $game_map.display_y
screne_y -= 256
screne_width = $game_map.display_x
screne_width += 2816
screne_height = $game_map.display_y
screne_height += 2176
o_x = @real_x
o_y = @real_y
if $game_player.x < 32 * 9 and @x > ($game_map.width * 32) - 32 * 11
o_x -= ($game_map.width * 32) * 4
end
if $game_player.x > ($game_map.width * 32) - 32 * 11 and @x < 32 * 9
o_x += ($game_map.width * 32) * 4
end
if $game_player.y < 32 * 8 and @y > ($game_map.height * 32) - 32 * 7
o_y -= ($game_map.height * 32) * 4
end
if $game_player.y > ($game_map.height * 32) - 32 * 7 and @y < 32 * 8
o_y += ($game_map.height * 32) * 4
end
if (o_x > screne_x and o_x < screne_width and o_y > screne_y and
o_y < screne_height)
return true
end
else
return result
end
end
end
#-----------------------------------------------------------------------------
# update method, changed for Anti-Lag-Script
#-----------------------------------------------------------------------------
def update
return if (Object.const_defined?(:Antilag_Settings) and not self.in_range?)
pixelmovement_game_event_update
if @trigger_on and not self.on_event?($game_player, @x, @y,
$game_player.x, $game_player.y, 4, 4)
@trigger_on = false
end
end
end
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. Refer to "$game_party" for the instance of this class.
#==============================================================================
class Game_Party
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixel_g_party_add add_actor
alias pixel_g_party_rem remove_actor
end
#--------------------------------------------------------------------------
# * Add an Actor
# actor_id : actor ID
#--------------------------------------------------------------------------
def add_actor(actor_id)
pixel_g_party_add(actor_id)
end
#--------------------------------------------------------------------------
# * Remove Actor
# actor_id : actor ID
#--------------------------------------------------------------------------
def remove_actor(actor_id)
pixel_g_party_rem(actor_id)
end
end
#===============================================================================
# Game_Player Class
#===============================================================================
class Game_Player < Game_Character
attr_accessor :sprint
attr_accessor :ice_sliding
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_game_player_initialize initialize
alias pixelmovement_game_player_increase_steps increase_steps
alias pixelmovement_game_player_moveto moveto
end
#-----------------------------------------------------------------------------
# initialize
#-----------------------------------------------------------------------------
def initialize
pixelmovement_game_player_initialize
@move_count = 0 # counts the movement
@move_speed = @move_speed * 1.0
@max_steps = 0 # for moving commands
@size = { 'x' => 32, 'y' => 32 } # Event-Size
@frame_speed = 1.0
@speed_factor = 1.0 # factor for changing the move speed with swamps/heights
@shift_x = @shift_y = 0
@pathfinding = Game_Pathfinding.new(self)
@real_steps = 0 # counts real steps, every 10 steps the step variable of
# the game is increased by 1
@no_slide = 0 # saves the not slidable direction
@sprint = false # true if sprinting
@sprint_time = 0 # time of sprinting
self.init_special_settings
end
#-----------------------------------------------------------------------------
# checks if Pixel Setting is activated, adds every event consisting a
# "jump/ice-comment" to an array or for special frame rates, etc..
#-----------------------------------------------------------------------------
def init_special_settings
super
# loads settings
if $pixelmovement.player_frame_number != nil
@frame_number = $pixelmovement.player_frame_number
end
if $pixelmovement.player_direction_number != nil
@direction_number = $pixelmovement.player_direction_number
end
if $pixelmovement.player_stand_frame != nil
@stand_frame = $pixelmovement.player_stand_frame
end
if $pixelmovement.player_shift_x != nil
@shift_x = $pixelmovement.player_shift_x
end
if $pixelmovement.player_shift_x != nil
@shift_x = $pixelmovement.player_shift_x
end
if $pixelmovement.player_frame_speed != nil
@frame_speed = $pixelmovement.player_frame_speed
end
if $pixelmovement.player_size != [] # if Player-Size is set manually
@size['x'] = $pixelmovement.player_size[0]
@size['y'] = $pixelmovement.player_size[1]
elsif @character_name != '' # else: from graphic
name='Graphics/Characters/' + @character_name
bitmap = Bitmap.new(name)
bla = [bitmap.width / @frame_number / 4,
bitmap.height / @direction_number / 4].max +
$pixelmovement.event_size_add
@size['x'] = bla
@size['y'] = bla
end
end
#-----------------------------------------------------------------------------
# returns if the coords are passable
#-----------------------------------------------------------------------------
def passable?(x, y, d, steps = 32)
# Isometric Movement
steps_x = steps * ($pixelmovement.isometric ? 2 : 1)
steps_y = steps
new_x = x + (d == 1 ? -steps_x : d == 3 ? steps_x : d == 7 ? -steps_x :
d == 9 ? steps_x : d == 6 ? steps_x : d == 4 ? -steps_x : 0)
new_y = y + (d == 1 ? steps_y : d == 3 ? steps_y : d == 7 ? -steps_y :
d == 9 ? -steps_y : d == 2 ? steps_y : d == 8 ? -steps_y : 0)
return false if not $game_map.valid?(new_x, new_y)
if $DEBUG and Input.press?(Input::CTRL)
@max_steps = steps
return true
end
super
end
#-----------------------------------------------------------------------------
# center, changed for Pixel Coords
#-----------------------------------------------------------------------------
def center(x, y)
max_x = (($game_map.width * 32) - 640) * 4
max_y = (($game_map.height * 32) - 480) * 4
if not $pixelmovement.loop_maps.include?($game_map.map_id)
$game_map.display_x = [0, [x * 4 - CENTER_X, max_x].min].max
$game_map.display_y = [0, [y * 4 - CENTER_Y, max_y].min].max
else
$game_map.display_x = x * 4 - CENTER_X
$game_map.display_y = y * 4 - CENTER_Y
end
end
#-----------------------------------------------------------------------------
# moveto, for Pixel Coords, teleports Caterpillars, too
#-----------------------------------------------------------------------------
def moveto(x, y)
pixelmovement_game_player_moveto(x, y)
$game_map.game_party_actors.each {|actor| actor.moveto(x, y)}
end
#-----------------------------------------------------------------------------
# increase_steps, improved for Pixelmovement
#-----------------------------------------------------------------------------
def increase_steps
if @real_steps >= 10
pixelmovement_game_player_increase_steps
@real_steps = 0
else
@real_steps += 1
end
end
#-----------------------------------------------------------------------------
# Activation: Passable
#-----------------------------------------------------------------------------
def check_event_trigger_here(triggers)
result = false
return result if $game_system.map_interpreter.running?
for event in $game_map.events.values
if triggers.include?(event.trigger) and not event.jumping? and
event.over_trigger? and not event.trigger_on and
((event.character_name != '' and self.in_rect?(event.real_x / 4,
event.real_y / 4 - event.size['y'] / 2 + @size['y'] / 2, event.size['x'] +
@size['x'], event.size['y'] + @size['y'], @real_x / 4,@real_y / 4)) or
(event.character_name == '' and
self.in_rect?(event.real_x / 4, event.real_y / 4 - event.size['y'] / 2 +
@size['y'] / 2, event.size['x'] - @size['x'] / 2, event.size['y'] -
@size['y'] / 2, @real_x / 4, @real_y / 4)))
event.trigger_on = true
event.start
result = true
end
end
return result
end
#-----------------------------------------------------------------------------
# Activation: Push Key, not Passable
#-----------------------------------------------------------------------------
def check_event_trigger_there(triggers)
#---------------------------------------------------------------------------
# normal
#---------------------------------------------------------------------------
result = false
return result if $game_system.map_interpreter.running?
for event in $game_map.events.values
if not event.jumping? and not event.over_trigger? and
triggers.include?(event.trigger) and self.looks_at?(event.id) and
self.in_rect?(event.real_x / 4, event.real_y / 4 - event.size['y'] / 2 +
@size['y'] / 2, event.size['x'] + @size['x'] + 8, event.size['y'] +
@size['y'] + 8, @real_x / 4, @real_y / 4)
event.trigger_on = true
event.start
result = true
end
end
#---------------------------------------------------------------------------
# counter top?
#---------------------------------------------------------------------------
if not result
new_x = @real_x / 4 + (@direction == 1 ? - 32 : @direction == 3 ? 32 :
@direction == 7 ? - 32 : @direction == 9 ? 32 :
@direction == 6 ? 32 : @direction == 4 ? - 32 : 0)
new_y = @real_y / 4 + (@direction == 1 ? 32 : @direction == 3 ? 32 :
@direction == 7 ? - 32 : @direction == 9 ? - 32 :
@direction == 2 ? 32 : @direction == 8 ? - 32 : 0)
# Counter Top?
if $game_map.counter?(new_x,new_y)
new_x += (@direction == 1 ? -@size['x'] : @direction == 3 ? @size['x'] :
@direction == 7 ? -@size['x'] : @direction == 9 ? @size['x'] :
@direction == 6 ? @size['x'] : @direction == 4 ? -@size['x'] :
0)
new_y += (@direction == 1 ? @size['y'] : @direction == 3 ? @size['y'] :
@direction == 7 ? -@size['y'] :
@direction == 9 ? -@size['y'] : @direction == 2 ? @size['y'] :
@direction == 8 ? -@size['y'] : 0)
for event in $game_map.events.values
if triggers.include?(event.trigger) and self.looks_at?(event.id) and
not event.jumping? and not event.over_trigger? and
self.in_rect?(event.real_x / 4,
event.real_y / 4 - event.size['y'] / 2 + @size['y'] / 2,
event.size['x'] + @size['x'] + 8, event.size['y'] + @size['y'] + 8,
new_x, new_y)
event.start
result = true
end
end
end
end
return result
end
#-----------------------------------------------------------------------------
# Activation: Touch, not Passable
#-----------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
result = false
return result if $game_system.map_interpreter.running?
for event in $game_map.events.values
if [1, 2].include?(event.trigger) and not event.jumping? and
not event.over_trigger? and not event.trigger_on and
self.in_rect?(event.real_x / 4, event.real_y / 4 - event.size['y'] / 2 +
@size['y'] / 2, event.size['x'] + @size['x'] + 8,event.size['y'] +
@size['y'] + 8, @real_x / 4, @real_y / 4)
event.trigger_on = true
event.start
result = true
end
end
return result
end
#-----------------------------------------------------------------------------
# update method
#-----------------------------------------------------------------------------
def update
#---------------------------------------------------------------------------
# checks input + moves
#---------------------------------------------------------------------------
if not (self.moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing or @ice_sliding)
steps = 2 ** (@move_speed > 3 ? (@move_speed.round - 2) : 1)
x = @x
y = @y
# Sprint fix?
if @sprint and $pixelmovement.sprint_fix
move_forward(steps)
else
#input
case Input.send($pixelmovement.movement_type)
when 1
move_lower_left(steps, true, true)
when 2
move_down(steps, true, true)
when 3
move_lower_right(steps, true, true)
when 4
move_left(steps, true, true)
when 6
move_right(steps, true, true)
when 7
move_upper_left(steps, true, true)
when 8
move_up(steps, true, true)
when 9
move_upper_right(steps, true, true)
end
end
#Sprint Script off
if @sprint
@move_speed -= $pixelmovement.sprint_speed
@sprint = false
end
end
last_real_x = @real_x
last_real_y = @real_y
if not moving?
if Input.trigger?(Input::C)
self.check_event_trigger_here([0])
self.check_event_trigger_there([0, 1, 2])
end
end
# checks if sprint is activated
self.check_sprint_input
# checks if player shall jump
self.check_jump_input
super
if not moving?
# Event determinant is via touch of same position event
result = check_event_trigger_here([1, 2])
# updates encounter count according to move_speed
if result == false and (@encounter_count > 0 and
not ($DEBUG and Input.press?(Input::CTRL)))
@encounter_count -= (@move_speed >= 4 ? (2**(@move_speed-2))/2 : 1)
end
end
# checks if player is sliding on ice
self.check_ice_sliding((last_real_x != @real_x or last_real_y != @real_y))
@pattern = @original_pattern if @ice_sliding
# checks if the player stands on a jump tile
self.check_jump
# updates scrolling
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
$game_map.scroll_up(last_real_y - @real_y)
end
end
#-----------------------------------------------------------------------------
# checks if Character is on a sliding tile
#-----------------------------------------------------------------------------
def check_ice_sliding(moving)
if $pixelmovement.ice_tiles == nil or $pixelmovement.ice_tiles == [] or
(moving and @ice_sliding) or ($game_map.ice_events == {} and
not $pixelmovement.ice_tiles.include?($game_map.terrain_tag(@x, @y)))
return
end
#---------------------------------------------------------------------------
# checks if an Event is on the same place
#---------------------------------------------------------------------------
for event in $game_map.ice_events.values
if self.on_event?(event, @x, @y, event.x, event.y, -8, -8)
i = 0
list = event.event.pages[0]
#-----------------------------------------------------------------------
# checks comments
#-----------------------------------------------------------------------
while list.list[i].code == 108 or list.list[i].code == 408
if not (list.list[i].parameters[0].downcase.include?('ice:'))
i += 1
next
end
ice = list.list[i].parameters[0].split(/: /)[1].downcase
i += 1
#---------------------------------------------------------------------
# slides
#---------------------------------------------------------------------
case ice
when 'face'
self.passable?(@x, @y, @direction, 32)
@ice_sliding = (@max_steps > 0)
self.move_forward(@max_steps, false, false)
when 'lower left'
self.passable?(@x, @y, 1, 32)
@ice_sliding = (@max_steps > 0)
self.move_lower_left(@max_steps, false, false)
when 'down'
self.passable?(@x, @y, 2, 32)
@ice_sliding = (@max_steps > 0)
self.move_down(@max_steps, false, false)
when 'lower right'
self.passable?(@x, @y, 3, 32)
@ice_sliding = (@max_steps > 0)
self.move_lower_right(@max_steps, false, false)
when 'left'
self.passable?(@x, @y, 4, 32)
@ice_sliding = (@max_steps > 0)
self.move_left(@max_steps, false, false)
when 'right'
self.passable?(@x, @y, 6, 32)
@ice_sliding = (@max_steps > 0)
self.move_right(@max_steps, false, false)
when 'upper left'
self.passable?(@x, @y, 7, 32)
@ice_sliding = (@max_steps > 0)
self.move_upper_left(@max_steps, false, false)
when 'up'
self.passable?(@x, @y, 8, 32)
@ice_sliding = (@max_steps > 0)
self.move_up(@max_steps, false, false)
when 'upper right'
self.passable?(@x, @y, 9, 32)
@ice_sliding = (@max_steps > 0)
self.move_upper_right(@max_steps, false, false)
end
return
end
end
end
#---------------------------------------------------------------------------
# checks for tile ids
#---------------------------------------------------------------------------
if $pixelmovement.ice_tiles.include?($game_map.terrain_tag(@x, @y))
self.passable?(@x, @y, @direction, 16)
@ice_sliding = @max_steps > 0
self.move_forward(@max_steps)
return
end
@ice_sliding = false
end
#-----------------------------------------------------------------------------
# checks if Character is on a jumping tile
#-----------------------------------------------------------------------------
def check_jump
return if $game_map.jump_events == {} or self.jumping?
#---------------------------------------------------------------------------
# checks if an Event is on the same place
#---------------------------------------------------------------------------
for event in $game_map.jump_events.values
if self.in_rect?(event.x, event.y - 16, 32, 32) and event != self
i = 0
list = event.event.pages[0]
#-----------------------------------------------------------------------
# checks comments
#-----------------------------------------------------------------------
while list.list[i].code == 108 or list.list[i].code == 408
if not (list.list[i].parameters[0].downcase.include?('jump:'))
i += 1
next
end
jump = list.list[i].parameters[0].split(/: /)[1].downcase
i += 1
#---------------------------------------------------------------------
# if jump type is face direction is changed
#---------------------------------------------------------------------
if jump == 'face'
case @direction
when 1
jump = 'lower left'
when 2
jump = 'down'
when 3
jump = 'lower right'
when 4
jump = 'left'
when 6
jump = 'right'
when 7
jump = 'upper left'
when 8
jump = 'up'
when 9
jump = 'upper right'
end
end
#---------------------------------------------------------------------
# jumps
#---------------------------------------------------------------------
case jump
when 'lower left'
add_x = -$pixelmovement.jump_length
add_y = $pixelmovement.jump_length
d = 1
when 'down'
add_x = 0
add_y = $pixelmovement.jump_length
d = 2
when 'lower right'
add_x = $pixelmovement.jump_length
add_y = $pixelmovement.jump_length
d = 3
when 'left'
add_x = -$pixelmovement.jump_length
add_y = 0
d = 4
when 'right'
add_x = $pixelmovement.jump_length
add_y = 0
d = 6
when 'upper left'
add_x = -$pixelmovement.jump_length
add_y = -$pixelmovement.jump_length
d = 7
when 'up'
add_x = 0
add_y = -$pixelmovement.jump_length
d = 8
when 'upper right'
add_x = $pixelmovement.jump_length
add_y = -$pixelmovement.jump_length
d = 9
end
if $game_map.passable?(@x + add_x, @y + add_y, @direction, self)
self.jump(add_x, add_y, $pixelmovement.jump_height)
else
self.passable?(@x, @y, @direction, $pixelmovement.jump_length)
add_x = (add_x < 0) ? -@max_steps : (add_x > 0) ? @max_steps : 0
add_y = (add_y < 0) ? -@max_steps : (add_y > 0) ? @max_steps : 0
@max_steps = 0
self.jump(add_x, add_y, $pixelmovement.jump_height)
end
return
end
end
end
end
#-----------------------------------------------------------------------------
# checks input for sprinting
#-----------------------------------------------------------------------------
def check_sprint_input
@sprint_time += 1 if @sprint_time < 0
return if not self.moving?
#---------------------------------------------------------------------------
#Sprint Script On
#---------------------------------------------------------------------------
if (Graphics.frame_count <= @sprint_time) or @sprint_time == 0
if ($pixelmovement.sprint_key == nil or
not Input.press?($pixelmovement.sprint_key) or @sprint)
return
end
if @sprint_time == 0
@sprint_time = Graphics.frame_count + $pixelmovement.sprint_time
end
@move_speed += $pixelmovement.sprint_speed
@sprint = true
elsif Graphics.frame_count == @sprint_time + 1
@sprint_time = - $pixelmovement.sprint_wait * 2
end
end
#-----------------------------------------------------------------------------
# checks input for jumps
#-----------------------------------------------------------------------------
def check_jump_input
#---------------------------------------------------------------------------
# returns if nothing has to be done
#---------------------------------------------------------------------------
if ($pixelmovement.jump_key == nil or
not Input.press?($pixelmovement.jump_key) or
self.jumping? or $pixelmovement.jump_length <= 0)
return
end
#---------------------------------------------------------------------------
# jumps in the faced direction
#---------------------------------------------------------------------------
case @direction
when 1
add_x = -$pixelmovement.jump_length
add_y = $pixelmovement.jump_length
when 2
add_x = 0
add_y = $pixelmovement.jump_length
when 3
add_x = $pixelmovement.jump_length
add_y = $pixelmovement.jump_length
when 4
add_x = -$pixelmovement.jump_length
add_y = 0
when 6
add_x = $pixelmovement.jump_length
add_y = 0
when 7
add_x = -$pixelmovement.jump_length
add_y = -$pixelmovement.jump_length
when 8
add_x = 0
add_y = -$pixelmovement.jump_length
when 9
add_x = $pixelmovement.jump_length
add_y = -$pixelmovement.jump_length
end
if $game_map.passable?(@x + add_x, @y + add_y, @direction, self)
self.jump(add_x, add_y, $pixelmovement.jump_height)
else
self.passable?(@x, @y, @direction, $pixelmovement.jump_length)
add_x = (add_x < 0) ? -@max_steps : (add_x > 0) ? @max_steps : 0
add_y = (add_y < 0) ? -@max_steps : (add_y > 0) ? @max_steps : 0
@max_steps = 0
self.jump(add_x, add_y, $pixelmovement.jump_height)
end
end
#-----------------------------------------------------------------------------
# checks if sliding is possible
#-----------------------------------------------------------------------------
def check_slide(dir)
return if not $pixelmovement.sliding
#---------------------------------------------------------------------------
# no slide at events
#---------------------------------------------------------------------------
for event in $game_map.events.values
if self.in_rect?(event.x, event.y - event.size['y'] / 2 + @size['y'] / 2,
event.size['x'] + @size['x'] + 4, event.size['y'] + @size['y'] + 4) and
event.trigger == 0 and self.looks_at?(event.id)
@no_slide = dir
return
end
end
#---------------------------------------------------------------------------
# checks every direction
#---------------------------------------------------------------------------
case dir
when 2
l = 0
r = 0
c = - @size['x']
for i in c..0
l += 1 if $game_map.passable?(@x + i, @y + 4, 2)
end
c = @size['x']
for i in 0..c
if $game_map.passable?(@x + (c - i), @y + 4, 2)
r += 1
break if r > l
end
end
if r > l and $game_map.passable?(@x + @size['x'], @y + 4, 2)
return 6
elsif l > 0 and $game_map.passable?(@x - @size['x'], @y + 4, 2)
return 4
else
@no_slide = dir
end
when 4
u = 0
d = 0
c = - @size['y'] * 2
for i in c..(- @size['y'])
u += 1 if $game_map.passable?(@x - 4 - @size['x'] / 2, @y + i, 4)
end
c = @size['y']
for i in 0..c
if $game_map.passable?(@x - 4 - @size['x'] / 2, @y + (c - i), 4)
d += 1
break if d > u
end
end
if u > d and
$game_map.passable?(@x - 4 - @size['x'] / 2, @y - @size['y'] * 2, 4)
return 8
elsif d > 0 and
$game_map.passable?(@x - 4 - @size['x'] / 2, @y + @size['y'], 4)
return 2
else
@no_slide = dir
end
when 6
u = 0
d = 0
c = - @size['y'] * 2
for i in c..(- @size['y'])
u += 1 if $game_map.passable?(@x + 4 + @size['x'] / 2, @y + i, 6)
end
c = @size['y']
for i in 0..c
if $game_map.passable?(@x + 4 + @size['x'] / 2, @y + (c - i), 6)
d += 1
break if d > u
end
end
if u > d and
$game_map.passable?(@x + 4 + @size['x'] / 2, @y - @size['y'] * 2, 6)
return 8
elsif d > 0 and
$game_map.passable?(@x + 4 + @size['x'] / 2, @y + @size['y'], 6)
return 2
else
@no_slide = dir
end
when 8
l = 0
r = 0
c = - @size['x']
for i in c..0
l += 1 if $game_map.passable?(@x + i, @y - 4 - @size['y'], 8)
end
c = @size['x']
for i in 0..c
if $game_map.passable?(@x + (c - i), @y - 4 - @size['y'], 8)
r += 1
break if r > l
end
end
if r > l and $game_map.passable?(@x + @size['x'], @y - 4 - @size['y'], 8)
return 6
elsif l > 0 and $game_map.passable?(@x-@size['x'], @y - 4 - @size['y'], 8)
return 4
else
@no_slide = dir
end
end
return
end
#-----------------------------------------------------------------------------
# move_down, more pixellike
#-----------------------------------------------------------------------------
def move_down(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if @no_slide != 2
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and @no_slide != 2 and $pixelmovement.sliding
if check_slide(2) == 4
move_left(steps, false, false)
elsif check_slide(2) == 6
move_right(steps, false, false)
else
move_lower_left(steps, false, false)
move_lower_right(steps, false, false)
end
end
end
#-----------------------------------------------------------------------------
# move_left, more pixellike
#-----------------------------------------------------------------------------
def move_left(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if @no_slide != 4
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and @no_slide != 4 and $pixelmovement.sliding
if check_slide(4) == 8
move_up(steps, false, false)
elsif check_slide(4) == 2
move_down(steps, false, false)
else
move_upper_left(steps, false, false)
move_lower_left(steps, false, false)
end
end
end
#-----------------------------------------------------------------------------
# move_right, more pixellike
#-----------------------------------------------------------------------------
def move_right(steps=32, turn_enabled = true, again = false)
@no_slide = 0 if @no_slide != 6
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and @no_slide != 6 and $pixelmovement.sliding
if check_slide(6) == 8
move_up(steps, false, false)
elsif check_slide(6) == 2
move_down(steps, false, false)
else
move_upper_right(steps, false, false)
move_lower_right(steps, false, false)
end
end
end
#-----------------------------------------------------------------------------
# move_up, more pixellike
#-----------------------------------------------------------------------------
def move_up(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if @no_slide != 8
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and @no_slide != 8 and $pixelmovement.sliding
if check_slide(8) == 4
move_left(steps, false, false)
elsif check_slide(8) == 6
move_right(steps, false, false)
else
move_upper_left(steps, false, false)
move_upper_right(steps, false, false)
end
end
end
#-----------------------------------------------------------------------------
# move_lower_left, more pixellike
#-----------------------------------------------------------------------------
def move_lower_left (steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if again
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and $pixelmovement.sliding
move_down(steps, false, false)
move_left(steps, false, false)
end
end
#-----------------------------------------------------------------------------
# move_lower_right, more pixellike
#-----------------------------------------------------------------------------
def move_lower_right(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if again
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and $pixelmovement.sliding
move_down(steps, false, false)
move_right(steps, false, false)
end
end
#-----------------------------------------------------------------------------
# move_upper_left, more pixellike
#-----------------------------------------------------------------------------
def move_upper_left(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if again
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and $pixelmovement.sliding
move_up(steps, false, false)
move_left(steps, false, false)
end
end
#-----------------------------------------------------------------------------
# move_upper_right, more pixellike
#-----------------------------------------------------------------------------
def move_upper_right(steps = 32, turn_enabled = true, again = false)
@no_slide = 0 if again
x = @x
y = @y
super(steps, turn_enabled)
if (x==@x and y==@y) and again and $pixelmovement.sliding
move_up(steps, false, false)
move_right(steps, false, false)
end
end
end
#===============================================================================
# Class for the Caterpillar Characters
#===============================================================================
class Game_Party_Actor < Game_Character
attr_accessor :move_list
attr_accessor :ice_sliding
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize(id)
@player_x = $game_player.x
@player_y = $game_player.y
super()
self.moveto($game_player.x, $game_player.y)
@through = true
@id = id
@move_list = []
@move_speed = $game_player.move_speed
@character_name = $game_party.actors[id - 1].character_name if id > 1
self.init_special_settings
end
#---------------------------------------------------------------------------
# checks if Pixel Setting is activated, adds every event consisting a
# "jump/ice-comment" to an array or for special frame rates, etc..
#---------------------------------------------------------------------------
def init_special_settings
super
if $pixelmovement.player_frame_number != nil
@frame_number = $pixelmovement.player_frame_number
end
if $pixelmovement.player_direction_number != nil
@direction_number = $pixelmovement.player_direction_number
end
if $pixelmovement.player_stand_frame != nil
@stand_frame = $pixelmovement.player_stand_frame
end
if $pixelmovement.player_shift_x != nil
@shift_x = $pixelmovement.player_shift_x
end
if $pixelmovement.player_shift_x != nil
@shift_x = $pixelmovement.player_shift_x
end
if $pixelmovement.player_frame_speed != nil
@frame_speed = $pixelmovement.player_frame_speed
end
if $pixelmovement.player_size != []
@size['x'] = $pixelmovement.player_size[0]
@size['y'] = $pixelmovement.player_size[1]
elsif @character_name != ''
name='Graphics/Characters/' + @character_name
bitmap = Bitmap.new(name)
bla = [bitmap.width / @frame_number / 4,
bitmap.height / @direction_number / 4].max +
$pixelmovement.event_size_add
@size['x'] = bla
@size['y'] = bla
end
end
#-----------------------------------------------------------------------------
# passable method, caterpillars can always walk if the new position is on
# the map
#-----------------------------------------------------------------------------
def passable?(x, y, d,steps = 32)
return true
end
#-----------------------------------------------------------------------------
# update method
#-----------------------------------------------------------------------------
def update
# no update if the game stops
if $game_system.map_interpreter.running? or @move_route_forcing or
$game_temp.message_window_showing
return
end
super
@pattern = @original_pattern if @ice_sliding # no frame change if sliding
# the "hero" caterpillar (invisible, just copies the settings of the player)
if @id == 1
self.moveto($game_player.x, $game_player.y)
@move_speed = $game_player.move_speed
@walk_anime = $game_player.walk_anime
@jump_count = $game_player.jump_count
@ice_sliding = $game_player.ice_sliding
# normal caterpillars
else
# returns if the player stops and overlapping is deactivated
if @player_x == $game_player.x and @player_y == $game_player.y
if not $pixelmovement.cater_overlap
@x = @real_x / 4
@y = @real_y / 4
return
end
check = false
else
check = true
end
@player_x = $game_player.x
@player_y = $game_player.y
# does an action of the move_list
if @move_list.length > 0
@move_speed = @move_list[0][2]
@walk_anime = @move_list[0][3]
@ice_sliding = @move_list[0][4]
if @move_list[0][4] == 'jump'
self.jump_to(@move_list[0][0], @move_list[0][1],
$pixelmovement.jump_height)
elsif not self.jumping?
self.move_to_place(@move_list[0][0], @move_list[0][1])
else
return
end
@move_list.delete_at(0)
end
# returns if the actor in front is too near
actor = $game_map.game_party_actors[@id - 2]
if check
max_dist = (@size['x'] + @size['y']) / 4 + $pixelmovement.cater_distance
dist = Math.sqrt((@x - actor.real_x / 4) * (@x - actor.real_x / 4) +
(@y - actor.real_y / 4) * (@y - actor.real_y / 4))
return if dist <= max_dist
end
# copies the last action of the caterpillar in front
if (actor.x != @x or actor.y != @y) and
not ($game_player.ice_sliding and $game_player.moving?)
if actor.jumping?
@move_list.push([actor.x, actor.y, actor.move_speed,
actor.walk_anime, 'jump'])
else
@move_list.push([actor.x, actor.y, actor.move_speed, actor.walk_anime,
actor.ice_sliding])
end
end
end
end
#-----------------------------------------------------------------------------
# Loop Map Teleport when Event reached the border
#-----------------------------------------------------------------------------
def update_loop_map
# returns if map isnt looped
if (not $pixelmovement.loop_maps.include?($game_map.map_id)) or @id == 1
return
end
#---------------------------------------------------------------------------
# teleports when is at the border
#---------------------------------------------------------------------------
actor = $game_map.game_party_actors[@id - 2]
abs_x = (@x - actor.x).abs
abs_y = (@y - actor.y).abs
if abs_x > (@x + $game_map.width * 32 - actor.x).abs
@x = @x + $game_map.width * 32
@real_x = @real_x + $game_map.width * 128
@move_list = []
elsif abs_x > (@x - $game_map.width * 32 - actor.x).abs
@x = @x - $game_map.width * 32
@real_x = @real_x - $game_map.width * 128
@move_list = []
end
if abs_y > (@y + $game_map.height * 32 - actor.y).abs
@y = @y + $game_map.height * 32
@real_y = @real_y + $game_map.height * 128
@move_list = []
elsif abs_y > (@y - $game_map.height * 32 - actor.y).abs
@y = @y - $game_map.height * 32
@real_y = @real_y - $game_map.height * 128
@move_list = []
end
end
#-----------------------------------------------------------------------------
# checks if the speed has to be changed because of the ground,
# changed because the Caterpillar speed is only changed when the game player's
# speed changes
#-----------------------------------------------------------------------------
def move_speed_change
return
end
end
#===============================================================================
# handles finding a path from a to b
#===============================================================================
class Game_Pathfinding
attr_accessor :active
attr_reader :target_x
attr_reader :target_y
attr_reader :coords
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize(event)
@walk = true
@radius = 0
@active = false
@event = event
@find_short_ways = false
@find_waypoint_ways = false
end
#-----------------------------------------------------------------------------
# starts the finding process
#-----------------------------------------------------------------------------
def find_path(target_x, target_y, walk = true, radius = 0)
if @find_waypoint_ways or @find_short_ways or $game_map.waypoints == nil
return false
end
# For Isometric Movement
div_x = $pixelmovement.isometric ? 4 : 2
@start_x = @event.x / div_x * div_x
@start_y = @event.y / 2 * 2
@target_x = target_x / div_x * div_x
@target_y = target_y / 2 * 2
@event.moveto(@start_x, @start_y)
@walk = walk
@active = true
@radius = radius.round
self.path_normal
return true
end
#-----------------------------------------------------------------------------
# fast pathfinding
#-----------------------------------------------------------------------------
def path_normal
# sorts wayponts: distance to start
cos = $game_map.waypoints.keys
cos.sort! do |a, b|
aa = Math.sqrt((@start_x - a[0])**2 + (@start_y - a[1])**2).round
bb = Math.sqrt((@start_x - b[0])**2 + (@start_y - b[1])**2).round
aa <=> bb
end
# sorts wayponts: distance to target (only the first two)
cos = cos[0..1] if cos.length > 1
cos.sort! do |a, b|
aa = Math.sqrt((@target_x - a[0])**2 + (@target_y - a[1])**2).round
bb = Math.sqrt((@target_x - b[0])**2 + (@target_y - b[1])**2).round
aa <=> bb
end
# takes the best fitting waypoint for the start
@coords_start_way = {[cos[0][0], cos[0][1]] => Game_Path.new(cos[0][0],
cos[0][1], [[cos[0][0], cos[0][1], 0, 'normal']], 0)}
@coords_start = [[cos[0][0], cos[0][1]]]
# sorts wayponts: distance to target
cos = $game_map.waypoints.keys
cos.sort! do |a, b|
aa = Math.sqrt((@target_x - a[0])**2 + (@target_y - a[1])**2).round
bb = Math.sqrt((@target_x - b[0])**2 + (@target_y - b[1])**2).round
aa <=> bb
end
# sorts wayponts: distance to start (only the first two)
cos = cos[0..1] if cos.length > 1
cos.sort! do |a, b|
aa = Math.sqrt((@start_x - a[0])**2 + (@start_y - a[1])**2).round
bb = Math.sqrt((@start_x - b[0])**2 + (@start_y - b[1])**2).round
aa <=> bb
end
# takes the best fitting waypoint for the target
@coords_target_way = {[cos[0][0], cos[0][1]] => Game_Path.new(cos[0][0],
cos[0][1], [[cos[0][0], cos[0][1], 0, 'normal']], 0)}
@coords_target = [[cos[0][0], cos[0][1]]]
@ende = false
@find_waypoint_ways = true
end
#-----------------------------------------------------------------------------
# update method
#-----------------------------------------------------------------------------
def update
self.find_waypoint_ways_update if @find_waypoint_ways
self.find_short_ways_update if @find_short_ways
end
#---------------------------------------------------------------------------
# finds a way using the waypoints
#---------------------------------------------------------------------------
def find_waypoint_ways_update(again = true)
time_start = Time.new # start time of finding ways
way_count = @coords_start.length + @coords_target.length
# structure of the coords: [x, y, length, type, dir]
while Time.new - time_start < 0.015
# for every existing way
@coords_start.each do |coords|
next if @coords_start_way[coords] == []
way = @coords_start_way[coords]
# tries every direction and adds the new position if useful
for coords in $game_map.waypoints[way.path.last[0..1]] do
next if coords[3] == 'iso' and not $pixelmovement.isometric
next if coords[3] == 'diag' and $pixelmovement.isometric
next if coords[3] == 'diag' and $pixelmovement.movement_type=='dir4'
if coords[3]=='normal' and $pixelmovement.movement_type=='dir4diag'
next
end
# if the coordinates exists: is the new way shorter than the old one?
if @coords_start.include?(coords[0..1])
next if @coords_start_way[coords[0..1]] == []
distance = way.length + coords[2]
next if @coords_start_way[coords[0..1]].length <= distance
end
# adds possible way
distance = way.length + coords[2]
@coords_start_way[coords[0..1]] = Game_Path.new(coords[0], coords[1],
way.path + [coords], distance)
# adds coordinates
if not @coords_start.include?(coords[0..1])
@coords_start.push(coords[0..1])
end
# if way has been found
if @coords_target.include?(coords[0..1]) or
(@radius >= 24 and Math.sqrt((coords[0] - @target_x) ** 2 +
(coords[1] - @target_y) ** 2) <= @radius)
@ende = true
end
end
# break?
@coords_start_way[@coords_start_way.index(way)] = []
break if @ende or Time.new - time_start >= 0.015
end
# sorts ways
@coords_start.sort! do |a, b|
@coords_start_way[a].length <=> @coords_start_way[b].length
end
if @radius < 24
# for every existing way
@coords_target.each do |coords|
next if @coords_target_way[coords] == []
way = @coords_target_way[coords]
# tries every direction and adds the new position if useful
for coords in $game_map.waypoints[way.path.last[0..1]] do
next if coords[3] == 'iso' and not $pixelmovement.isometric
next if coords[3] == 'diag' and $pixelmovement.isometric
next if coords[3] == 'diag' and $pixelmovement.movement_type=='dir4'
if coords[3]=='normal' and $pixelmovement.movement_type=='dir4diag'
next
end
# if the coordinates exists:is the new way shorter than the old one?
if @coords_target.include?(coords[0..1])
next if @coords_target_way[coords[0..1]] == []
distance = way.length + coords[2]
next if @coords_target_way[coords[0..1]].length <= distance
end
# adds possible way
distance = way.length + coords[2]
@coords_target_way[coords[0..1]] = Game_Path.new(coords[0],
coords[1], way.path + [coords], distance)
# adds coordinates
if not @coords_target.include?(coords[0..1])
@coords_target.push(coords[0..1])
end
# if way has been found
@ende = true if @coords_start.include?(coords[0..1])
end
# break?
@coords_target_way[@coords_target_way.index(way)] = []
break if @ende or Time.new - time_start >= 0.015
end
# sorts ways
@coords_target.sort! do |a, b|
@coords_target_way[a].length <=> @coords_target_way[b].length
end
end
# if way has been found
break if @ende
# if way cannot be found: new way with a bigger radius is searched
if way_count == @coords_start.length + @coords_target.length
self.find_waypoint_ways_update(false) if again
if way_count == @coords_start.length + @coords_target.length
@find_waypoint_ways = false
if @radius < 256
self.find_path(@target_x, @target_y, @walk,
(@radius < 8 ? 24 : @radius + 16))
end
end
break
end
end
#---------------------------------------------------------------------------
# puts both ways together
#---------------------------------------------------------------------------
return if not @ende
# sorts ways
@way = nil
@coords_start.sort! do |a, b|
@coords_start_way[a].length <=> @coords_start_way[b].length
end
# if the radius is big (so only one way exists start->target)
if @radius >= 24
@coords_start.each do |co|
s = @coords_start_way[co]
next if s == []
if Math.sqrt((s.path.last[0] - @target_x) ** 2 +
(s.path.last[1] - @target_y) ** 2) <= @radius
@way = [[@start_x, @start_y, 32, 'normal']] + s.path
break
end
end
#otherwise: connects the two ways (start->middle, target->middle)
else
@coords_target.sort! do |a, b|
@coords_target_way[b].length <=> @coords_target_way[a].length
end
@coords_start.each do |co|
s = @coords_start_way[co]
break if @way != nil
next if s == []
sco = []
s.path.each {|co| sco.push(co[0..1])}
@coords_target.each do |co|
z = @coords_target_way[co]
next if z == []
zco = []
z.path.each {|co| zco.push(co[0..1])}
if sco.include?(z.path.last[0..1]) or zco.include?(s.path.last[0..1])
w_s = [[@start_x, @start_y, 32, 'normal']] + s.path
w_z = [[@target_x, @target_y, 32, 'normal']] + z.path
@way = w_s - [w_s.last] + w_z.reverse
break
end
end
end
end
@find_short_ways = true
@find_waypoint_ways = false
@new_way = []
@old_way = @way
@counter = 0
end
#---------------------------------------------------------------------------
# creates connections between the waypoints
#---------------------------------------------------------------------------
def find_short_ways_update
time_start = Time.new # start time of finding ways
while @counter < @old_way.length - 1 and Time.new - time_start < 0.015
# sets maximum steps
if @counter > 0 and (@coords.last[0] != @old_way[@counter][0] or
@coords.last[1] == @old_way[@counter][1])
ms = [@old_way[@counter + 1][2] + @old_way[@counter][2] / 2, 4].max
else
ms = [@old_way[@counter + 1][2] * 3 / 4, 4].max
end
# connects two waypoints
if @counter >= @old_way.length - 2
self.path_fast(@coords.last[0], @coords.last[1], @target_x, @target_y,
ms, @radius)
elsif @counter > 0
self.path_fast(@coords.last[0], @coords.last[1],
@old_way[@counter + 1][0],
@old_way[@counter + 1][1], ms)
else
self.path_fast(@old_way[0][0], @old_way[0][1],
@old_way[1][0], @old_way[1][1], ms)
end
@new_way.push(@way)
@counter += 1
end
self.correct_short_ways if Graphics.frame_count % 4 == 0
#---------------------------------------------------------------------------
# saves the way
#---------------------------------------------------------------------------
return if @counter < @old_way.length - 1
self.correct_short_ways
@way = @new_way.flatten
@find_short_ways = false
# initializes event's move route
return if not @walk
codes = [nil, 5, 1, 6, 2, nil, 3, 7, 4, 8]
route = RPG::MoveRoute.new
route.repeat = false
route.skippable = false
i = 0
while i < @way.length
steps = 0
while @way[i] == @way[i + steps]
steps += 1
end
route.list.push(RPG::MoveCommand.new(codes[@way[i]], [steps * 2]))
i += steps
end
route.list.push(route.list[0])
route.list.delete_at(0)
@event.force_move_route(route)
end
#-----------------------------------------------------------------------------
# corrects way if the event has moved
#-----------------------------------------------------------------------------
def correct_short_ways
div_x = $pixelmovement.isometric ? 4 : 2
if @start_x == @event.x / div_x * div_x and @start_y == @event.y / 2 * 2
return
end
# sorts waypoints (so the best connection between the new start point and
# the route can be found)
start_x = @event.x / div_x * div_x
start_y = @event.y / 2 * 2
cos = @old_way.clone
cos.sort! do |a, b|
taa = Math.sqrt((@target_x - a[0])**2 + (@target_y - a[1])**2).round
tbb = Math.sqrt((@target_x - b[0])**2 + (@target_y - b[1])**2).round
taa <=> tbb
end
cos.length.times do
dist = Math.sqrt((start_x - cos[0][0])**2 + (start_y - cos[0][1])**2)
if dist <= 64
break
else
temp = cos[0]
cos.delete_at(0)
cos.push(temp)
end
end
# returns if the best waypoint hasnt been connected with a route yet
ind = @old_way.index(cos[0])
return if ind >= @counter
@start_x = @event.x / div_x * div_x
@start_y = @event.y / 2 * 2
@new_way = @new_way[ind..@new_way.length - 1]
@old_way = @old_way[ind..@old_way.length - 1]
co = @coords.clone
dist = Math.sqrt((@start_x - cos[0][0])**2 + (@start_y - cos[0][1])**2)
# if the distance the the route is short: simple connection
if dist <= 32
@old_way.unshift([@start_x, @start_y, dist.round, 'normal'])
self.path_fast(@start_x,@start_y,cos[0][0],cos[0][1],[dist*2/3,4].max)
@new_way.unshift(@way)
# if the distance is bigger: creates a waypoint between start and route
else
$game_map.waypoints.each do |coords, wps|
dist = Math.sqrt((@start_x-coords[0])**2 + (@start_y-coords[1])**2)
start_found = dist <= 32
target_found = false
target_wp = nil
wps.each do |wp|
if wp[0..1] == cos[0][0..1]
target_found = true
target_wp = wp
break
end
end
if start_found and target_found
@old_way.unshift([coords[0], coords[1], dist.round, 'normal'])
@old_way.unshift([@start_x, @start_y, dist.round, 'normal'])
self.path_fast(coords[0], coords[1], target_wp[0], target_wp[1],
target_wp[2])
@new_way.unshift(@way)
self.path_fast(@start_x, @start_y, coords[0], coords[1],
[dist * 2 / 3, 4].max)
@new_way.unshift(@way)
break
end
end
end
@counter = @new_way.length
@coords = co
end
#-----------------------------------------------------------------------------
# fast pathfinding
#-----------------------------------------------------------------------------
def path_fast(start_x = @start_x, start_y = @start_y, target_x = @target_x,
target_y = @target_y, max = 512, radius = 0)
@coords = [] # done coords
@way_old = nil
max = max.round
radius = radius.round
counter = 0
# For Isometric Movement
start_x = start_x / 4 * 4 if $pixelmovement.isometric
target_x = target_x / 4 * 4 if $pixelmovement.isometric
# creates way
@way = Game_Path.new(start_x, start_y, [])
@coords += [[start_x, start_y]]
loop do
# adds a possible way
@way_old = @way
self.add_ways(target_x, target_y)
# deletes unusable things
if @way.path.length % 128 == 0
for i in 1..9
self.delete_unusable(i, 10 - i)
end
end
# if no direction is possible anymore, one step back
if @way_old == @way
case @way.path.last
when 1
@way.x += ($pixelmovement.isometric ? 4 : 2)
@way.y -= 2
when 2
@way.y -= 2
when 3
@way.x -= ($pixelmovement.isometric ? 4 : 2)
@way.y -= 2
when 4
@way.x += ($pixelmovement.isometric ? 4 : 2)
when 6
@way.x -= ($pixelmovement.isometric ? 4 : 2)
when 7
@way.x += ($pixelmovement.isometric ? 4 : 2)
@way.y += 2
when 8
@way.y += 2
when 9
@way.x -= ($pixelmovement.isometric ? 4 : 2)
@way.y += 2
end
@way.path.pop
end
counter += 1
# If target is found
if @coords.include?([target_x, target_y]) or @way.path.length >= max or
counter >= max * 3 or
Math.sqrt((target_x - @way.x) ** 2 + (target_y - @way.y) ** 2) <= radius
for i in 1..9
self.delete_unusable(i, 10 - i, 8)
end
@way = @way.path
# if the target hasnt been found
dist2 = Math::sqrt((target_x - @coords.last[0])**2 +
(target_y - @coords.last[1])**2)
if dist2 > radius
distx = []
@coords.each do |cos|
distx.push(Math::sqrt((target_x-cos[0])**2 + (target_y-cos[1])**2))
end
distmin = (distx.sort {|a, b| a <=> b})[0]
@coords = @coords[0..distx.index(distmin)]
if distx.index(distmin) - 1 < 0
@way = []
else
@way = @way[0..distx.index(distmin) - 1]
end
end
return true
end
end
end
#-----------------------------------------------------------------------------
# deletes unusable things (like 2,8,2,8,2,8)
#-----------------------------------------------------------------------------
def delete_unusable(d1 = 2, d2 = 8, ab = 8, count = 3)
count = ab - 2 if count >= ab - 1
i = ab
while i <= @way.path.length - 1 - ab
if (@way.path[(i - ab)..(i - 1)] - [d1]).length <= count and
(@way.path[(i + 1)..(i + ab)] - [d2]).length <= count
j = 0
while @way.path[i + j] != d1
j -= 1
end
j_old = j
while @way.path[i + j] == d1
j -= 1
end
if j_old - j <= count
while @way.path[i + j] != d1
j -= 1
end
while @way.path[i + j] == d1
j -= 1
end
end
k = 0
while @way.path[i + k] != d2
k += 1
end
k_old = k
while @way.path[i + k] == d2
k += 1
end
if k - k_old <= count
while @way.path[i + k] != d2
k += 1
end
k_old = k
while @way.path[i + k] == d2
k += 1
end
end
j += 1
k -= 1
while @way.path[i + j] == d1 and @way.path[i + k] == d2
@way.path.delete_at(i + k)
@way.path.delete_at(i + j)
k -= 2
end
end
i += 1
end
end
#-----------------------------------------------------------------------------
# adds new way (fast Pathfinding)
# tries to find the direct way to the target (e.g. if the target is below the
# start point, it tries to go down
#-----------------------------------------------------------------------------
def add_ways(target_x, target_y)
if @way.y < target_y
if @way.x > target_x # left/down
if self.go_left_down(target_x, target_y)
elsif self.go_right_down(target_x, target_y)
while (not self.go_left_down(target_x, target_y)) and
self.go_right_down(target_x, target_y) do
end
elsif self.go_left_up(target_x, target_y)
while (not self.go_left_down(target_x, target_y)) and
self.go_left_up(target_x, target_y) do
end
else self.go_right_up(target_x, target_y)
while (not self.go_left_down(target_x, target_y)) and
self.go_right_up(target_x, target_y) do
end
end
elsif @way.x < target_x # right/down
if self.go_right_down(target_x, target_y)
elsif self.go_left_down(target_x, target_y)
while (not self.go_right_down(target_x, target_y)) and
self.go_left_down(target_x, target_y) do
end
elsif self.go_right_up(target_x, target_y)
while (not self.go_right_down(target_x, target_y)) and
self.go_right_up(target_x, target_y) do
end
else self.go_left_up(target_x, target_y)
while (not self.go_right_down(target_x, target_y)) and
self.go_left_up(target_x, target_y) do
end
end
else # down
if self.go_down(target_x, target_y)
elsif self.go_left(target_x, target_y)
while (not self.go_down(target_x, target_y)) and
self.go_left(target_x, target_y) do
end
elsif self.go_right(target_x, target_y)
while (not self.go_down(target_x, target_y)) and
self.go_right(target_x, target_y) do
end
else self.go_up(target_x, target_y)
while (not self.go_down(target_x, target_y)) and
self.go_up(target_x, target_y) do
end
end
end
elsif @way.y > target_y
if @way.x > target_x # left/up
if self.go_left_up(target_x, target_y)
elsif self.go_left_down(target_x, target_y)
while (not self.go_left_up(target_x, target_y)) and
self.go_left_down(target_x, target_y) do
end
elsif self.go_right_up(target_x, target_y)
while (not self.go_left_up(target_x, target_y)) and
self.go_right_up(target_x, target_y) do
end
else self.go_right_down(target_x, target_y)
while (not self.go_left_up(target_x, target_y)) and
self.go_right_down(target_x, target_y) do
end
end
elsif @way.x < target_x # right/up
if self.go_right_up(target_x, target_y)
elsif self.go_left_up(target_x, target_y)
while (not self.go_right_up(target_x, target_y)) and
self.go_left_up(target_x, target_y) do
end
elsif self.go_right_down(target_x, target_y)
while (not self.go_right_up(target_x, target_y)) and
self.go_right_down(target_x, target_y) do
end
else self.go_left_down(target_x, target_y)
while (not self.go_right_up(target_x, target_y)) and
self.go_left_down(target_x, target_y) do
end
end
else # up
if self.go_up(target_x, target_y)
elsif self.go_right(target_x, target_y)
while (not self.go_up(target_x, target_y)) and
self.go_right(target_x, target_y) do
end
elsif self.go_left(target_x, target_y)
while (not self.go_up(target_x, target_y)) and
self.go_left(target_x, target_y) do
end
else self.go_down(target_x, target_y)
while (not self.go_up(target_x, target_y)) and
self.go_down(target_x, target_y) do
end
end
end
elsif @way.x > target_x # left
if self.go_left(target_x, target_y)
elsif self.go_up(target_x, target_y)
while (not self.go_left(target_x, target_y)) and
self.go_up(target_x, target_y) do
end
elsif self.go_down(target_x, target_y)
while (not self.go_left(target_x, target_y)) and
self.go_down(target_x, target_y) do
end
else self.go_right(target_x, target_y)
while (not self.go_left(target_x, target_y)) and
self.go_right(target_x, target_y) do
end
end
elsif @way.x < target_x # right
if self.go_right(target_x, target_y)
elsif self.go_up(target_x, target_y)
while (not self.go_right(target_x, target_y)) and
self.go_up(target_x, target_y) do
end
elsif self.go_down(target_x, target_y)
while (not self.go_right(target_x, target_y)) and
self.go_down(target_x, target_y) do
end
else self.go_left(target_x, target_y)
while (not self.go_right(target_x, target_y)) and
self.go_left(target_x, target_y) do
end
end
end
end
#-----------------------------------------------------------------------------
# tries to go left and up
# if not possible: tries to go up or left
#-----------------------------------------------------------------------------
def go_left_up(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7)
if not self.add_way(@way.x - steps_x, @way.y, 4)
if not self.add_way(@way.x, @way.y - steps_y, 8)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go left and down
# if not possible: tries to go down or left
#-----------------------------------------------------------------------------
def go_left_down(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1)
if not self.add_way(@way.x - steps_x, @way.y, 4)
if not self.add_way(@way.x, @way.y + steps_y, 2)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go right and up
# if not possible: tries to go up or right
#-----------------------------------------------------------------------------
def go_right_up(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9)
if not self.add_way(@way.x + steps_x, @way.y, 6)
if not self.add_way(@way.x, @way.y - steps_y, 8)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go right and down
# if not possible: tries to go down or right
#-----------------------------------------------------------------------------
def go_right_down(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3)
if not self.add_way(@way.x + steps_x, @way.y, 6)
if not self.add_way(@way.x, @way.y + steps_y, 2)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go left
# if not possible: tries to go upper left or lower left
#-----------------------------------------------------------------------------
def go_left(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x - steps_x, @way.y, 4)
if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1)
if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go right
# if not possible: tries to go upper right or lower right
#-----------------------------------------------------------------------------
def go_right(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x + steps_x, @way.y, 6)
if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3)
if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go up
# if not possible: tries to upper left or upper right
#-----------------------------------------------------------------------------
def go_up(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x, @way.y - steps_y, 8)
if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7)
if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# tries to go down
# if not possible: tries to lower left or lower right
#-----------------------------------------------------------------------------
def go_down(target_x, target_y)
steps_x = $pixelmovement.isometric ? 4 : 2
steps_y = 2
if not self.add_way(@way.x, @way.y + steps_y, 2)
if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1)
if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3)
return false
end
end
end
return true
end
#-----------------------------------------------------------------------------
# adds new way (finally, if passable, and the new position hasnt been used
#-----------------------------------------------------------------------------
def add_way(x, y, d)
if @event.passable?(@way.x, @way.y, d, 2) and not @coords.include?([x, y])
@way = Game_Path.new(x, y, @way.path + [d])
@coords += [[x, y]]
return true
else
return false
end
end
end
#===============================================================================
# Class to save a Pathfinding path (including the path itself and the current
# position
#===============================================================================
class Game_Path
attr_accessor :x
attr_accessor :y
attr_accessor :path
attr_accessor :length
def initialize (x, y, path, length = 0)
@x = x
@y = y
@path = path
@length = length
end
end
#===============================================================================
# Sprite_Character Class
#===============================================================================
class Sprite_Character < RPG::Sprite
attr_accessor :direction
attr_accessor :_loop_animation
attr_accessor :_animation
attr_accessor :_animation_hit
attr_reader :character_name
attr_reader :ch
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_sprite_character_initialize initialize
end
#-----------------------------------------------------------------------------
# initialise method
#-----------------------------------------------------------------------------
def initialize (viewport, character = nil)
pixelmovement_sprite_character_initialize (viewport, character)
# saves the real face direction later (for 4dirs)
@direction = @character.direction
@char_x = @character.screen_x
@char_y = @character.screen_y
@frame_number = @character.frame_number
@direction_number = @character.direction_number
end
#-----------------------------------------------------------------------------
# update method, parameters added for Loop_Map, rebuild for 8dirs
#-----------------------------------------------------------------------------
def update(x_add = 0, y_add = 0,ani_add = nil, loop_ani_add = nil)
# Anti-Lag-Script
if @character.is_a?(Game_Event) and self.src_rect != Rect.new(0,0,0,0) and
(Object.const_defined?(:Antilag_Settings) and not @character.in_range?)
return
end
super()
#---------------------------------------------------------------------------
# graphic has to be changed?
#---------------------------------------------------------------------------
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue or
@frame_number != @character.frame_number or
@direction_number != @character.direction_number
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
@frame_number = @character.frame_number
@direction_number = @character.direction_number
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
else
if @character.character_name == ''
self.bitmap = Bitmap.new(128,128)
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
end
@cw = bitmap.width / @character.frame_number
@ch = bitmap.height / @character.direction_number
self.ox = @cw / 2
self.oy = @ch
end
# reloads minimap sprites
if $scene.is_a?(Scene_Map) and $scene.spriteset != nil and
$scene.spriteset.minimap != nil
$scene.spriteset.minimap.set_chars
end
end
self.visible = (not @character.transparent)
#---------------------------------------------------------------------------
# Frames
#---------------------------------------------------------------------------
if @tile_id == 0
# Standing Animation?
if @character.stand_frame == 0 or @character.stop_count == 0 or
@character.step_anime
if $pixelmovement.stand_array == []
if $pixelmovement.frame_array == []
sx = (@character.pattern + @character.stand_frame) * @cw
else
sx = ($pixelmovement.frame_array[@character.pattern] +
@character.stand_frame) * @cw
end
else
if $pixelmovement.frame_array == []
c = @character.pattern
while $pixelmovement.stand_array.include?(c)
c += 1
end
sx = c * @cw
else
sx = (($pixelmovement.frame_array -
$pixelmovement.stand_array)[@character.pattern]) * @cw
end
end
elsif $pixelmovement.stand_array == []
sx = ((@character.stop_count/4) % @character.stand_frame)* @cw
else
sx = $pixelmovement.stand_array[((@character.stop_count / 4) %
@character.stand_frame)] * @cw
end
#-------------------------------------------------------------------------
# 8 Dirs
#-------------------------------------------------------------------------
if @character.direction_number == 8
if $pixelmovement.direction_array == []
if @character.direction < 5
sy = (@character.direction - 1) * @ch
else
sy = (@character.direction - 2) * @ch
end
else
if @character.direction < 5
sy = ($pixelmovement.direction_array[@character.direction - 1]) *@ch
else
sy = ($pixelmovement.direction_array[@character.direction - 2]) *@ch
end
end
#-------------------------------------------------------------------------
# 4 Dirs
#-------------------------------------------------------------------------
elsif @direction != nil
if not [1, 3, 7, 9].include?(@character.direction)
@direction = @character.direction
elsif @character.direction == 1 and not [2, 4].include?(@direction)
@direction = 2
elsif @character.direction == 3 and not [2, 6].include?(@direction)
@direction = 2
elsif @character.direction == 7 and not [4, 8].include?(@direction)
@direction = 8
elsif @character.direction == 9 and not [6, 8].include?(@direction)
@direction = 8
end
if $pixelmovement.direction_array == [] or
$pixelmovement.direction_array.length > 4
sy = (@direction - 2) / 2 * @ch
else
sy = ($pixelmovement.direction_array[(@direction - 2) / 2]) * @ch
end
else
sy = 0
end
self.src_rect.set(sx, sy, @cw, @ch)
end
#---------------------------------------------------------------------------
# updates position, etc
#---------------------------------------------------------------------------
if @char_x != @character.screen_x + x_add
self.x = @character.screen_x + x_add
@char_x = @character.screen_x + x_add
end
if @char_y != @character.screen_y + y_add
self.y = @character.screen_y + y_add
@char_y = @character.screen_y + y_add
end
self.z = @character.screen_z(@ch) + y_add
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
#---------------------------------------------------------------------------
# Animations for Loop Map Events
#---------------------------------------------------------------------------
if x_add != 0 or y_add != 0
if ani_add != nil and @_animation == nil
animation(ani_add, true)
elsif ani_add == nil and @_animation != nil
animation(nil, true)
end
if loop_ani_add != nil and @_loop_animation == nil
loop_animation(loop_ani_add)
elsif loop_ani_add == nil and @_loop_animation != nil
loop_animation(nil)
end
end
end
end
#===============================================================================
# Scene_Save Class, deletes bitmaps in $game_map
#===============================================================================
class Scene_Save < Scene_File
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias movement_scene_save_write_save_data write_save_data
end
#-----------------------------------------------------------------------------
# saves game, bitmaps in Game_Map are deleted, pathfinding is deleted
#-----------------------------------------------------------------------------
def write_save_data(file)
# deletes bitmaps
$game_map.collision_map = nil
$game_map.height_map = nil
$game_map.swamp_map = nil
$game_map.save_tables
$game_map.collision_table = nil
$game_map.height_table = nil
$game_map.swamp_table = nil
$game_map.waypoints = nil
$game_player.pathfinding = nil
movement_scene_save_write_save_data(file)
# saves events, loads bitmaps
Marshal.dump($pixelmovement.events, file)
$game_map.load_bitmaps
$game_map.load_tables
$game_map.load_waypoints
$game_player.pathfinding = Game_Pathfinding.new(self)
end
end
#===============================================================================
# Scene_Load Class, loads deleted bitmaps again
#===============================================================================
class Scene_Load < Scene_File
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_scene_load_read_save_data read_save_data
end
#-----------------------------------------------------------------------------
# loads game, loads events & bitmaps in game_map
#-----------------------------------------------------------------------------
def read_save_data(file)
pixelmovement_scene_load_read_save_data(file)
$game_map.load_bitmaps
$game_map.load_tables
$game_map.load_waypoints
$game_player.pathfinding = Game_Pathfinding.new(self)
if $game_system.magic_number != $data_system.magic_number
$pixelmovement.events = {}
else
$pixelmovement.events = Marshal.load(file)
end
end
end
#===============================================================================
# Scene_Title Class
#===============================================================================
class Scene_Title
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_scene_title_command_new_game command_new_game
end
#-----------------------------------------------------------------------------
# starts new game, teleport hero to pixel coordinates
#-----------------------------------------------------------------------------
def command_new_game
$pixelmovement.events = {} # used later to save Events
pixelmovement_scene_title_command_new_game
# Pixel Coords
$game_player.moveto($data_system.start_x * 32 + 16,
$data_system.start_y * 32 + 30)
end
end
#===============================================================================
# Scene_Map Class
#===============================================================================
class Scene_Map
attr_accessor :spriteset
#-----------------------------------------------------------------------------
# aliasing methods
#-----------------------------------------------------------------------------
if not $pixelmovement.pixel_aliasing
alias pixelmovement_scene_map_update update
alias pixelmovement_scene_map_transfer_player transfer_player
end
#-----------------------------------------------------------------------------
# update method
#-----------------------------------------------------------------------------
def update
pixelmovement_scene_map_update
#---------------------------------------------------------------------------
# Encounter Count (had to be rebuild for Pixelmovement)
#---------------------------------------------------------------------------
if $game_player.encounter_count < 0 and $game_map.encounter_list != []
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
n = rand($game_map.encounter_list.size)
troop_id = $game_map.encounter_list[n]
if $data_troops[troop_id] != nil
$game_temp.battle_calling = true
$game_temp.battle_troop_id = troop_id
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
end
end
end
end
#-----------------------------------------------------------------------------
# transfer_player method,
#-----------------------------------------------------------------------------
def transfer_player
#---------------------------------------------------------------------------
# checks if map is changed / changes map
#---------------------------------------------------------------------------
if $game_map.map_id != $game_temp.player_new_map_id
# saves Events of the old Map
$game_map.events.values.each {|event| event.trigger_on = 0}
$pixelmovement.events[$game_map.map_id] = $game_map.events
$game_map.setup($game_temp.player_new_map_id)
# loads Events of the new Map
if $pixelmovement.events[$game_map.map_id] != nil
$pixelmovement.events[$game_map.map_id].each do |k, v|
$game_map.events[k] = v
end
$game_map.events.values.each {|event| event.refresh}
end
end
pixelmovement_scene_map_transfer_player
end
end
#===============================================================================
# Spriteset_Map Class
#===============================================================================
class Spriteset_Map
attr_accessor :character_sprites
attr_accessor :game_party_actors_sprites
attr_accessor :viewport1
attr_accessor :viewport2
attr_accessor :viewport3
attr_accessor :minimap
#-----------------------------------------------------------------------------
# initialising method, Caterpillar, Minimap + Looped Maps have been added
#-----------------------------------------------------------------------------
alias pixel_spriteset_init initialize if not $pixelmovement.pixel_aliasing
def initialize
@game_party_actors_sprites = []
#---------------------------------------------------------------------------
# Loop_Map
#---------------------------------------------------------------------------
if $pixelmovement.loop_maps.include?($game_map.map_id)
@character_sprites_2 = [[], [], [], [], [], [], [], []]
end
@minimap_check = false
pixel_spriteset_init
@minimap_check = true
#---------------------------------------------------------------------------
# Minimap
#---------------------------------------------------------------------------
if $pixelmovement.minimap
@minimap = Spriteset_Minimap.new(self)
@minimap_settings = [$pixelmovement.minimap_pos,
$pixelmovement.minimap_width,
$pixelmovement.minimap_height,
$pixelmovement.minimap_scale,
$pixelmovement.minimap_opacity,
$pixelmovement.minimap_collision,
$pixelmovement.minimap_c_cursor,
$pixelmovement.minimap_c_pass,
$pixelmovement.minimap_c_n_pass,
$pixelmovement.minimap_sprites]
end
#---------------------------------------------------------------------------
# Caterpillar
#---------------------------------------------------------------------------
for i in 0..($game_map.game_party_actors.length - 1)
sprite = Sprite_Character.new(@viewport1, $game_map.game_party_actors[i])
@game_party_actors_sprites.push(sprite)
end
end
#-----------------------------------------------------------------------------
# dispose method, Minimap + Looped Maps have been added
#-----------------------------------------------------------------------------
alias pixel_spriteset_dis dispose if not $pixelmovement.pixel_aliasing
def dispose
pixel_spriteset_dis
#---------------------------------------------------------------------------
# Caterpillar
#---------------------------------------------------------------------------
for sprite in @game_party_actors_sprites
sprite.dispose
end
#---------------------------------------------------------------------------
# Loop_Map
#---------------------------------------------------------------------------
if $pixelmovement.loop_maps.include?($game_map.map_id) and
@character_sprites_2 != nil
@character_sprites_2.each {|sprites| sprites.each {|sp| sp.dispose}}
end
#---------------------------------------------------------------------------
# Minimap
#---------------------------------------------------------------------------
@minimap.dispose if @minimap != nil
end
#-----------------------------------------------------------------------------
# update method, Minimap + Looped Maps have been added
#-----------------------------------------------------------------------------
alias pixel_spriteset_up update if not $pixelmovement.pixel_aliasing
def update
#---------------------------------------------------------------------------
# Caterpillar
#---------------------------------------------------------------------------
for sprite in @game_party_actors_sprites
sprite.update
sprite.z -= 1
end
pixel_spriteset_up
#---------------------------------------------------------------------------
# Loop-Map
#---------------------------------------------------------------------------
if $pixelmovement.loop_maps.include?($game_map.map_id)
if @character_sprites_2 == nil
@character_sprites_2 = [[], [], [], [], [], [], [], []]
end
self.clone_events_left
self.clone_events_right
self.clone_events_up
self.clone_events_down
self.clone_events_upper_left
self.clone_events_lower_left
self.clone_events_upper_right
self.clone_events_lower_right
elsif @character_sprites_2 != nil
@character_sprites_2.each {|sprites| sprites.each {|sp| sp.dispose}}
@character_sprites_2 = nil
end
#---------------------------------------------------------------------------
# updates Minimap
#---------------------------------------------------------------------------
if @minimap != nil
@minimap.update
if @minimap_settings != [$pixelmovement.minimap_pos,
$pixelmovement.minimap_width,
$pixelmovement.minimap_height,
$pixelmovement.minimap_scale,
$pixelmovement.minimap_opacity,
$pixelmovement.minimap_collision,
$pixelmovement.minimap_c_cursor,
$pixelmovement.minimap_c_pass,
$pixelmovement.minimap_c_n_pass,
$pixelmovement.minimap_sprites]
@minimap.dispose
@minimap = nil
@minimap = Spriteset_Minimap.new(self)
@minimap_settings = [$pixelmovement.minimap_pos,
$pixelmovement.minimap_width,
$pixelmovement.minimap_height,
$pixelmovement.minimap_scale,
$pixelmovement.minimap_opacity,
$pixelmovement.minimap_collision,
$pixelmovement.minimap_c_cursor,
$pixelmovement.minimap_c_pass,
$pixelmovement.minimap_c_n_pass,
$pixelmovement.minimap_sprites]
end
if not $pixelmovement.minimap
@minimap.dispose
@minimap = nil
end
elsif $pixelmovement.minimap and @minimap_check
@minimap = Spriteset_Minimap.new(self)
end
if $pixelmovement.panorama_scrolling
@panorama.ox = $game_map.display_x / 4
@panorama.oy = $game_map.display_y / 4
end
end
#-----------------------------------------------------------------------------
# clones events on the left border, for looped maps
#-----------------------------------------------------------------------------
def clone_events_left
if $game_player.x < 32 * 9
if @character_sprites_2[0] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[0].push(sprite)
end
else
for sprite in @character_sprites_2[0]
sp = @character_sprites[@character_sprites_2[0].index(sprite)]
sprite.update( - ($game_map.width * 32), 0, sp._animation,
sp._loop_animation)
end
end
return true
elsif @character_sprites_2[0] != []
@character_sprites_2[0].each {|sprite| sprite.dispose}
@character_sprites_2[0] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events on the right border, for looped maps
#-----------------------------------------------------------------------------
def clone_events_right
if $game_player.x > ($game_map.width * 32) - 32 * 11
if @character_sprites_2[1] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[1].push(sprite)
end
else
for sprite in @character_sprites_2[1]
sp = @character_sprites[@character_sprites_2[1].index(sprite)]
sprite.update(($game_map.width * 32), 0, sp._animation,
sp._loop_animation)
end
end
return true
elsif @character_sprites_2[1] != []
@character_sprites_2[1].each {|sprite| sprite.dispose}
@character_sprites_2[1] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events on the upper border, for looped maps
#-----------------------------------------------------------------------------
def clone_events_up
if $game_player.y < 32 * 8
if @character_sprites_2[2] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[2].push(sprite)
end
else
for sprite in @character_sprites_2[2]
sp = @character_sprites[@character_sprites_2[2].index(sprite)]
sprite.update(0,- ($game_map.height * 32), sp._animation,
sp._loop_animation)
end
end
return true
elsif @character_sprites_2[2] != []
@character_sprites_2[2].each {|sprite| sprite.dispose}
@character_sprites_2[2] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events on the lower border, for looped maps
#-----------------------------------------------------------------------------
def clone_events_down
if $game_player.y > ($game_map.height * 32) - 32 * 7
if @character_sprites_2[3] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[3].push(sprite)
end
else
for sprite in @character_sprites_2[3]
sp = @character_sprites[@character_sprites_2[3].index(sprite)]
sprite.update(0,($game_map.height * 32), sp._animation,
sp._loop_animation)
end
end
return true
elsif @character_sprites_2[3] != []
@character_sprites_2[3].each {|sprite| sprite.dispose}
@character_sprites_2[3] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events at the upper left corner, for looped maps
#-----------------------------------------------------------------------------
def clone_events_upper_left
if $game_player.x < 32 * 9 or $game_player.y < 32 * 8
if @character_sprites_2[4] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[4].push(sprite)
end
else
for sprite in @character_sprites_2[4]
sp = @character_sprites[@character_sprites_2[4].index(sprite)]
sprite.update(- ($game_map.width * 32), - ($game_map.height * 32),
sp._animation, sp._loop_animation)
end
end
return true
elsif @character_sprites_2[4] != []
@character_sprites_2[4].each {|sprite| sprite.dispose}
@character_sprites_2[4] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events at the upper right corner, for looped maps
#-----------------------------------------------------------------------------
def clone_events_upper_right
if $game_player.x < 32 * 9 or
$game_player.x > ($game_map.width * 32) - 32 * 11
if @character_sprites_2[5] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[5].push(sprite)
end
else
for sprite in @character_sprites_2[5]
sp = @character_sprites[@character_sprites_2[5].index(sprite)]
sprite.update(($game_map.width * 32),-($game_map.height * 32),
sp._animation, sp._loop_animation)
end
end
return true
elsif @character_sprites_2[5] != []
@character_sprites_2[5].each {|sprite| sprite.dispose}
@character_sprites_2[5] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events at the lower left corner, for looped maps
#-----------------------------------------------------------------------------
def clone_events_lower_left
if $game_player.y > ($game_map.height * 32) - 32 * 7 or
$game_player.y < 32 * 8
if @character_sprites_2[6] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[6].push(sprite)
end
else
for sprite in @character_sprites_2[6]
sp = @character_sprites[@character_sprites_2[6].index(sprite)]
sprite.update(-($game_map.width * 32),($game_map.height * 32),
sp._animation, sp._loop_animation)
end
end
return true
elsif @character_sprites_2[6] != []
@character_sprites_2[6].each {|sprite| sprite.dispose}
@character_sprites_2[6] = []
end
return false
end
#-----------------------------------------------------------------------------
# clones events at the lower right corner, for looped maps
#-----------------------------------------------------------------------------
def clone_events_lower_right
if $game_player.y > ($game_map.height * 32) - 32 * 7 or
$game_player.x > ($game_map.width * 32) - 32 * 11
if @character_sprites_2[7] == []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites_2[7].push(sprite)
end
else
for sprite in @character_sprites_2[7]
sp = @character_sprites[@character_sprites_2[7].index(sprite)]
sprite.update(($game_map.width * 32),($game_map.height * 32),
sp._animation, sp._loop_animation)
end
end
return true
elsif @character_sprites_2[7] != []
@character_sprites_2[7].each {|sprite| sprite.dispose}
@character_sprites_2[7] = []
end
return false
end
end
#===============================================================================
# Class which holds the Minimap
# the minimap is created through copying the real map and resizing it or
# creating a collision minimap through using the collision map
# the character sprites are simple small duplications of their big cousins on
# the real map
#===============================================================================
class Spriteset_Minimap
# For Autotiles
INDEX =
[
26, 27, 32, 33, 4 , 27, 32, 33, 26, 5, 32, 33, 4, 5, 32, 33,
26, 27, 32, 11, 4 , 27, 32, 11, 26, 5, 32, 11, 4, 5, 32, 11,
26, 27, 10, 33, 4 , 27, 10, 33, 26, 5, 10, 33, 4, 5, 10, 33,
26, 27, 10, 11, 4 , 27, 10, 11, 26, 5, 10, 11, 4, 5, 10, 11,
24, 25, 30, 31, 24, 5, 30, 31, 24, 25, 30, 11, 24, 5, 30, 11,
14, 15, 20, 21, 14, 15, 20, 11, 14, 15, 10, 21, 14, 15, 10, 11,
28, 29, 34, 35, 28, 29, 10, 35, 4, 29, 34, 35, 4, 29, 10, 35,
38, 39, 44, 45, 4, 39, 44, 45, 38, 5, 44, 45, 4, 5, 44, 45,
24, 29, 30, 35, 14, 15, 44, 45, 12, 13, 18 ,19, 12, 13, 18, 11,
16, 17, 22, 23, 16, 17, 10, 23, 40, 41, 46, 47, 4, 41, 46, 47,
36, 37, 42, 43, 36, 5, 42, 43, 12, 17, 18, 23, 12, 13, 42, 43,
36, 41, 42, 47, 16, 17, 46, 47, 12, 17, 42, 47, 0, 1, 6, 7
]
X = [0, 1, 0, 1]
Y = [0, 0, 1, 1]
#-----------------------------------------------------------------------------
# initialising method
#-----------------------------------------------------------------------------
def initialize(set = $scene.spriteset)
#---------------------------------------------------------------------------
# sets Corner + creates viewport
#---------------------------------------------------------------------------
width = [$pixelmovement.minimap_width,
($game_map.width * 32) / $pixelmovement.minimap_scale].min
height = [$pixelmovement.minimap_height,
($game_map.height * 32) / $pixelmovement.minimap_scale].min
case $pixelmovement.minimap_pos
when 1 #1 = upper left corner
@viewport = Viewport.new(0, 0, width, height)
when 2 #2 = upper right
@viewport = Viewport.new(640 - width, 0, width, height)
when 3 #3 = lower left
@viewport = Viewport.new(0, 480 - height, width, height)
when 4 #4 = lower right
@viewport = Viewport.new(640 - width, 480 - height, width, height)
end
#---------------------------------------------------------------------------
# initialising
#---------------------------------------------------------------------------
@minimap_collision = $pixelmovement.minimap_collision
@viewport.z = 500
@map = RPG::Sprite.new(@viewport) # the shown minimap
@map.z = 2500
@border = RPG::Sprite.new(@viewport)
@border.z = 2530
@char_coords = []
@cursor_coords = []
#---------------------------------------------------------------------------
# draws border
#---------------------------------------------------------------------------
@border.bitmap = Bitmap.new(width, height)
@border.x = 0
@border.y = 0
@cursor_zoom = $pixelmovement.minimap_player_scale
for x in 0..(@border.bitmap.width - 1)
@border.bitmap.set_pixel(x, 0, Color.new(0, 0, 0))
@border.bitmap.set_pixel(x, @border.bitmap.height - 1, Color.new(0, 0, 0))
end
for y in 0..(@border.bitmap.height - 1)
@border.bitmap.set_pixel(0, y, Color.new(0, 0, 0))
@border.bitmap.set_pixel(@border.bitmap.width - 1, y, Color.new(0, 0, 0))
end
#---------------------------------------------------------------------------
# draws minimap
#---------------------------------------------------------------------------
self.draw_minimap
#---------------------------------------------------------------------------
# specials things
#---------------------------------------------------------------------------
self.set_chars(set)
# Cursor for Collision Minimap
if @cursor.bitmap == nil
@cursor.bitmap = Bitmap.new(10, 10)
@cursor.bitmap.fill_circle(5, 5, 5, $pixelmovement.minimap_c_cursor)
end
@cursor.x = 0
@cursor.y = 0
@cursor.opacity = 0
#Colours of Collision Minimap
if @minimap_collision and
($pixelmovement.minimap_c_n_pass != Color.new(0, 0, 0) or
$pixelmovement.minimap_c_pass != Color.new(255, 255, 255))
for x in [email=0..@map.bitmap.width]0..@map.bitmap.width[/email]
for y in [email=0..@map.bitmap.height]0..@map.bitmap.height[/email]
if @map.bitmap.get_pixel(x, y) == Color.new(0, 0, 0)
@map.bitmap.set_pixel(x, y, $pixelmovement.minimap_c_n_pass)
else
@map.bitmap.set_pixel(x, y, $pixelmovement.minimap_c_pass)
end
Graphics.update if x % 200 == 0 and y % 200 == 0
end
end
end
#Loop_Map
if $pixelmovement.loop_maps.include?($game_map.map_id)
map = Bitmap.new(@map.bitmap.width * 3,@map.bitmap.height * 3)
for i in 0..2
for j in 0..2
x = @map.bitmap.width * i
y = @map.bitmap.height * j
map.blt(x, y, @map.bitmap, @map.bitmap.rect)
end
end
@map.bitmap = map
end
@cursor.opacity = 0
@map.opacity = 0
@border.opacity = 0
end
#-----------------------------------------------------------------------------
# draws the minimap
#-----------------------------------------------------------------------------
def draw_minimap
# @minimap saves the whole minimap, not resized!
tiles = []
# loads minimap from the cache if possible
if $pixelmovement.minimaps[[$game_map.map_id, @minimap_collision]] != nil
@minimap = $pixelmovement.minimaps[[$game_map.map_id, @minimap_collision]]
# Collsion Minimap from Map?
elsif @minimap_collision
@minimap = RPG::Cache.collision_map($game_map.map_id.to_s)
if @minimap != nil
$pixelmovement.minimaps[[$game_map.map_id, @minimap_collision]]=@minimap
end
end
#---------------------------------------------------------------------------
# creates minimap
#---------------------------------------------------------------------------
if @minimap == nil
@minimap = Bitmap.new(($game_map.width * 32),($game_map.height * 32))
#Collision Minimap from Tileset?
if @minimap_collision
@minimap.fill_rect(@minimap.rect, Color.new(255, 255, 255))
tiles[0] = RPG::Cache.collision_map($game_map.tileset_name)
end
# Else: Normal Minimap
if not @minimap_collision or tiles[0] == nil
@minimap_collision = false
tiles[0] = RPG::Cache.tileset($game_map.tileset_name)
end
#-------------------------------------------------------------------------
# creates Autotiles
#-------------------------------------------------------------------------
$game_map.autotile_names.each do |name|
if @minimap_collision
bitmap = RPG::Cache.collision_map(name)
else
bitmap = RPG::Cache.autotile(name)
end
if bitmap != nil and bitmap.width >= 96
id = tiles.length
scroll = []
frame = []
autotile = bitmap
scroll[id] = 0
frame[id] = autotile.width / 96
width = 8 * 32 * frame[id]
height = 6 * 32
tiles[id] = Bitmap.new(width, height)
for f in 0...frame[id]
for pos in 0...48
for corner in [0, 1, 2, 3]
h = 4 * pos + corner
yy = INDEX[h] / 6
xx = INDEX[h] % 6 + f * 6
y = pos / 8
x = pos % 8 + f * 8
src_rect = Rect.new(xx * 16 , yy * 16 , 16, 16 )
tiles[id].blt(x * 32 + X[corner] * 16,
y * 32 + Y[corner] * 16 , autotile, src_rect)
end # end for corner
end
end
else
tiles[tiles.length] = Bitmap.new(32 * 8, 32 * 6)
if @minimap_collision
tiles[tiles.length - 1].fill_rect(tiles[tiles.length - 1].rect,
Color.new(255, 255,255))
end
end
end
#-------------------------------------------------------------------------
# draws Map
#-------------------------------------------------------------------------
for x in 0..$game_map.width - 1
for y in 0..$game_map.height - 1
for layer in 0..2
nr = nil
pos = $game_map.data[x, y, layer]
pos = 0 if pos == nil
data = $game_map.data[x, y, layer]
dest_rect = Rect.new(x * 32, y * 32, 32, 32)
if pos >= 384
nr = 0
pos -= 384
elsif pos >= 48
nr = pos / 48
pos = pos % 48
elsif @minimap_collision and
(data == nil or $game_map.passages[data] != 0)
@minimap.fill_rect(dest_rect, Color.new(0,0,0))
end
if nr != nil
src_rect = Rect.new((pos % 8) * 32, (pos / 8) * 32, 32, 32)
@minimap.stretch_blt(dest_rect, tiles[nr], src_rect)
end
end
end
end
# puts minimap into the cache
$pixelmovement.minimaps[[$game_map.map_id, @minimap_collision]] = @minimap
end
# resizes minimap
@map.bitmap = Bitmap.new(@minimap.width / $pixelmovement.minimap_scale,
@minimap.height / $pixelmovement.minimap_scale)
@map.bitmap.stretch_blt(@map.bitmap.rect, @minimap, @minimap.rect)
end
#-----------------------------------------------------------------------------
# creates characters on minimap
#-----------------------------------------------------------------------------
def set_chars(set = $scene.spriteset)
#disposes chars, if they already exist
@chars.each {|cha| cha.dispose} if @chars != nil
@chars = []
@cursor.dispose if @cursor != nil
@cursor = nil
@cursor = RPG::Sprite.new(@viewport)
@cursor.z = 2520
@char_coords = []
@cursor_coords = []
# no chars on collision minimap
return if @minimap_collision
# draw Chars
set.character_sprites.each do |char|
next if char.disposed?
#Cursor
if char == set.character_sprites.last
@cursor.blink_on
@cursor.bitmap = Bitmap.new(char.bitmap.width /
$pixelmovement.minimap_scale * @cursor_zoom,
char.bitmap.height /
$pixelmovement.minimap_scale * @cursor_zoom)
@cursor.bitmap.stretch_blt(@cursor.bitmap.rect, char.bitmap,
char.bitmap.rect)
@cursor.src_rect.set(char.src_rect.x / $pixelmovement.minimap_scale *
@cursor_zoom, char.src_rect.y / $pixelmovement.minimap_scale *
@cursor_zoom, char.src_rect.width / $pixelmovement.minimap_scale *
@cursor_zoom, char.src_rect.height / $pixelmovement.minimap_scale *
@cursor_zoom)
@cursor.opacity = 0
#Chars
else
next if not $pixelmovement.minimap_sprites
@chars.push(RPG::Sprite.new(@viewport))
@chars.last.z = 2510
@chars.last.bitmap = Bitmap.new(char.bitmap.width /
$pixelmovement.minimap_scale,
char.bitmap.height /
$pixelmovement.minimap_scale)
@chars.last.bitmap.stretch_blt(@chars.last.bitmap.rect, char.bitmap,
char.bitmap.rect)
@chars.last.src_rect.set(char.src_rect.x / $pixelmovement.minimap_scale,
char.src_rect.y / $pixelmovement.minimap_scale,
char.src_rect.width / $pixelmovement.minimap_scale,
char.src_rect.height / $pixelmovement.minimap_scale)
@chars.last.opacity = 0
end
end
end
#-----------------------------------------------------------------------------
# disposes minimap
#-----------------------------------------------------------------------------
def dispose
@map.dispose
@cursor.dispose
@chars.each {|char| char.dispose}
@border.dispose
end
#-----------------------------------------------------------------------------
# updates minimap
#-----------------------------------------------------------------------------
def update
return if Graphics.frame_count % 2 != 0
#---------------------------------------------------------------------------
# Looped Maps?
#---------------------------------------------------------------------------
# if the current map is looped, but the minimap hasnt been created for
# looped maps
if $pixelmovement.loop_maps.include?($game_map.map_id)
if @map.bitmap.width == $game_map.width * 32 /
$pixelmovement.minimap_scale
map = Bitmap.new(@map.bitmap.width * 3,@map.bitmap.height * 3)
for i in 0..2
for j in 0..2
x = @map.bitmap.width * i
y = @map.bitmap.height * j
map.blt(x, y, @map.bitmap, @map.bitmap.rect)
end
end
@map.bitmap = map
end
# if minimap has been created for a looped map, but the map isnt looped
elsif @map.bitmap.width > $game_map.width * 32 /
$pixelmovement.minimap_scale
map = Bitmap.new(@map.bitmap.width / 3,@map.bitmap.height / 3)
map.blt(0, 0, @map.bitmap, @map.bitmap.rect)
@map.bitmap = map
end
# return if the minimap should not be updated anymore
if not ($scene.is_a?(Scene_Map) and $pixelmovement.minimap and
$scene.spriteset != nil)
return
end
return if $scene.spriteset.character_sprites.last.disposed?
# cursor opacity
percent = $scene.spriteset.character_sprites.last.opacity / 255.0
if @cursor.opacity / percent <
$pixelmovement.minimap_opacity - $pixelmovement.minimap_opacity / 3
@cursor.opacity += $pixelmovement.minimap_opacity * percent / 3
elsif @cursor.opacity != $pixelmovement.minimap_opacity
@cursor.opacity = $pixelmovement.minimap_opacity * percent
end
# char opacities
for i in [email=0..@chars.length]0..@chars.length[/email] - 1
percent = $scene.spriteset.character_sprites[i].opacity / 255.0
if @chars[i].opacity / percent <
$pixelmovement.minimap_opacity - $pixelmovement.minimap_opacity / 3
@chars[i].opacity += $pixelmovement.minimap_opacity * percent / 3
elsif @chars[i].opacity != $pixelmovement.minimap_opacity
@chars[i].opacity = $pixelmovement.minimap_opacity * percent
end
end
# map + border opacity
if @map.opacity <
$pixelmovement.minimap_opacity - $pixelmovement.minimap_opacity / 3
@map.opacity += $pixelmovement.minimap_opacity / 3
@border.opacity += $pixelmovement.minimap_opacity / 3
elsif @map.opacity != $pixelmovement.minimap_opacity
@map.opacity = $pixelmovement.minimap_opacity
@border.opacity = $pixelmovement.minimap_opacity
end
#---------------------------------------------------------------------------
# Map update
#---------------------------------------------------------------------------
# horizontal movement of the minimap
if @player_x != $game_player.real_x
player_x = $game_player.real_x / 4 / $pixelmovement.minimap_scale
center_x = $pixelmovement.minimap_width / 2
center_x -= 16 / $pixelmovement.minimap_scale
# looped map
if $pixelmovement.loop_maps.include?($game_map.map_id)
@map.x = - (player_x - center_x)
@map.x -= @map.bitmap.width / 3
else
max_x = (@map.bitmap.width - $pixelmovement.minimap_width)
@map.x = - [0, [player_x - center_x, max_x].min].max
end
@player_x = $game_player.real_x
end
#vertical movement of the minimap
if @player_y != $game_player.real_y
center_y = $pixelmovement.minimap_height / 2
center_y -= 16 / $pixelmovement.minimap_scale
player_y = $game_player.real_y / 4 / $pixelmovement.minimap_scale
# looped map
if $pixelmovement.loop_maps.include?($game_map.map_id)
@map.y = - (player_y - center_y)
@map.y -= @map.bitmap.height / 3
else
max_y = (@map.bitmap.height - $pixelmovement.minimap_height)
@map.y = - [0, [player_y - center_y, max_y].min].max
end
@player_y = $game_player.real_y
end
#---------------------------------------------------------------------------
# Cursor Update
#---------------------------------------------------------------------------
# returns if no chararacter sprites are drawn on the map
return if $scene.spriteset.character_sprites.last.disposed?
rect = Rect.new(@cursor.src_rect.x / $pixelmovement.minimap_scale,
@cursor.src_rect.y / $pixelmovement.minimap_scale,
@cursor.src_rect.width / $pixelmovement.minimap_scale,
@cursor.src_rect.height / $pixelmovement.minimap_scale)
if @cursor_coords != [@cursor.x, @cursor.y, rect]
# updates cursor sprite, if minimap isnt a collision map
if not @minimap_collision
@cursor.src_rect.set($scene.spriteset.character_sprites.last.src_rect.x/
$pixelmovement.minimap_scale * @cursor_zoom,
$scene.spriteset.character_sprites.last.src_rect.y /
$pixelmovement.minimap_scale * @cursor_zoom,
$scene.spriteset.character_sprites.last.src_rect.width /
$pixelmovement.minimap_scale * @cursor_zoom,
$scene.spriteset.character_sprites.last.src_rect.height/
$pixelmovement.minimap_scale * @cursor_zoom)
end
# horizontal
@cursor.x = ($game_player.real_x + 3) / 4 + $game_player.shift_x
@cursor.x /= $pixelmovement.minimap_scale
@cursor.x += @map.x
#vertical
if $game_player.jump_count >= $game_player.jump_peak
n = $game_player.jump_count - $game_player.jump_peak
else
n = $game_player.jump_peak - $game_player.jump_count
end
@cursor.y = ($game_player.real_y + 3) / 4 - ($game_player.jump_peak *
$game_player.jump_peak - n * n) / 2 + $game_player.shift_y
@cursor.y /= $pixelmovement.minimap_scale
@cursor.y += @map.y
# looped map
if $pixelmovement.loop_maps.include?($game_map.map_id)
@cursor.x += @map.bitmap.width / 3
@cursor.y += @map.bitmap.height / 3
end
# optimizes cursor position
if @minimap_collision
@cursor.x -= 5
@cursor.y -= 5
else
@cursor.x -= @cursor.src_rect.width / 2
@cursor.y -= @cursor.src_rect.height
end
@cursor_coords = [$scene.spriteset.character_sprites.last.x,
$scene.spriteset.character_sprites.last.y,
@cursor.src_rect.clone]
end
#---------------------------------------------------------------------------
# Chars are Updated
#---------------------------------------------------------------------------
return if @chars == []
for i in 0..(@chars.length - 1)
char = $scene.spriteset.character_sprites[i]
rect = Rect.new(char.src_rect.x / $pixelmovement.minimap_scale,
char.src_rect.y / $pixelmovement.minimap_scale,
char.src_rect.width / $pixelmovement.minimap_scale,
char.src_rect.height / $pixelmovement.minimap_scale)
if char == nil or (@char_coords[i] == [char.x, char.y, rect] and
(not Object.const_defined?(:Antilag_Settings) or char.character.in_range?))
next
end
# updates sprite
@chars[i].src_rect.set(char.src_rect.x / $pixelmovement.minimap_scale,
char.src_rect.y / $pixelmovement.minimap_scale,
char.src_rect.width / $pixelmovement.minimap_scale,
char.src_rect.height / $pixelmovement.minimap_scale)
char = char.character
# horizontal
@chars[i].x = (char.real_x + 3) / 4 / $pixelmovement.minimap_scale +
@map.x + char.shift_x / $pixelmovement.minimap_scale
#vertical
y = (char.real_y + 3) / 4 / $pixelmovement.minimap_scale + @map.y
if char.jump_count >= char.jump_peak
n = char.jump_count - char.jump_peak
else
n = char.jump_peak - char.jump_count
end
@chars[i].y = y - (char.jump_peak * char.jump_peak - n * n) / 2 /
$pixelmovement.minimap_scale + char.shift_y /
$pixelmovement.minimap_scale
# looped map
if $pixelmovement.loop_maps.include?($game_map.map_id)
@chars[i].x += @map.bitmap.width / 3
@chars[i].y += @map.bitmap.height / 3
end
# optimizes position
@chars[i].x -= @chars[i].src_rect.width / 2
@chars[i].y -= @chars[i].src_rect.height
# on looped maps (when character is next to the border)
if $pixelmovement.loop_maps.include?($game_map.map_id)
if @chars[i].x < 0 and @map.bitmap.width >= $pixelmovement.minimap_width
@chars[i].x += @map.bitmap.width / 3
elsif @chars[i].x > $pixelmovement.minimap_width and
@map.bitmap.width >= $pixelmovement.minimap_width
@chars[i].x -= @map.bitmap.width / 3
end
if @chars[i].y < 0 and
@map.bitmap.height >= $pixelmovement.minimap_height
@chars[i].y += @map.bitmap.height / 3
elsif @chars[i].y > $pixelmovement.minimap_height and
@map.bitmap.height >= $pixelmovement.minimap_height
@chars[i].y -= @map.bitmap.height / 3
end
end
@char_coords[i] = [$scene.spriteset.character_sprites[i].x,
$scene.spriteset.character_sprites[i].y,
@chars[i].src_rect.clone]
end
end
end
#===============================================================================
# Interpreter Class
#===============================================================================
class Interpreter
#-----------------------------------------------------------------------------
# Teleport for Pixelmovement
#-----------------------------------------------------------------------------
def command_201
return true if $game_temp.in_battle
if $game_temp.player_transferring or
$game_temp.message_window_showing or
$game_temp.transition_processing
return false
end
$game_temp.player_transferring = true
if @parameters[0] == 0
$game_temp.player_new_map_id = @parameters[1]
$game_temp.player_new_x = @parameters[2] * 32 + 16
$game_temp.player_new_y = @parameters[3] * 32 + 30
$game_temp.player_new_direction = @parameters[4]
else
$game_temp.player_new_map_id = $game_variables[@parameters[1]]
$game_temp.player_new_x = $game_variables[@parameters[2]]
$game_temp.player_new_y = $game_variables[@parameters[3]]
$game_temp.player_new_direction = @parameters[4]
end
@index += 1
if @parameters[5] == 0
Graphics.freeze
$game_temp.transition_processing = true
$game_temp.transition_name = ''
end
return false
end
#-----------------------------------------------------------------------------
# Teleport for Pixelmovement
#-----------------------------------------------------------------------------
def command_202
return true if $game_temp.in_battle
character = get_character(@parameters[0])
return true if character == nil
if @parameters[1] == 0
character.moveto(@parameters[2] * 32 + 16, @parameters[3] * 32 + 30)
elsif @parameters[1] == 1
character.moveto($game_variables[@parameters[2]],
$game_variables[@parameters[3]])
else
old_x = character.x
old_y = character.y
character2 = get_character(@parameters[2])
if character2 != nil
character.moveto(character2.x, character2.y)
character2.moveto(old_x, old_y)
end
end
case @parameters[4]
when 8
character.turn_up
when 6
character.turn_right
when 2
character.turn_down
when 4
character.turn_left
end
return true
end
end
#===============================================================================
# Bitmap Class
#===============================================================================
class Bitmap
#-----------------------------------------------------------------------------
# Draws a filled circle
#-----------------------------------------------------------------------------
def fill_circle(cx, cy, radius, color)
x = 0
y = radius
d = radius-1
while y >= x
fill_rect(cx - x, cy - y, 2 * x, 1, color)
fill_rect(cx - y, cy - x, 2 * y, 1, color)
fill_rect(cx - x, cy + y, 2 * x, 1, color)
fill_rect(cx - y, cy + x, 2 * y, 1, color)
return if y == x
if d < 0
d += 2*x + 3
else
y -= 1
d += 2 * x - 2 * y + 5
end
x += 1
end
end
end
#===============================================================================
# Range Class
#===============================================================================
class Range
#-----------------------------------------------------------------------------
# returns the length of the Range
#-----------------------------------------------------------------------------
def length
return self.last - self.first + (self.exclude_end? ? 0 : 1)
end
end
#===============================================================================
# RPG::Cache Module
#===============================================================================
module RPG
module Cache
#---------------------------------------------------------------------------
# loads a bitmap
#---------------------------------------------------------------------------
def self.load_bitmap(folder_name, filename, hue = 0)
path = folder_name + filename
if not @cache.include?(path) or @cache[path].disposed?
@cache[path] = (filename != "") ? Bitmap.new(path) : Bitmap.new(32, 32)
end
if hue == 0
@cache[path]
else
key = [path, hue]
if not @cache.include?(key) or @cache[key].disposed?
@cache[key] = @cache[path].clone
@cache[key].hue_change(hue)
end
@cache[key]
end
rescue #####
end
#---------------------------------------------------------------------------
# loads a collision map
#---------------------------------------------------------------------------
def self.collision_map(filename)
self.load_bitmap($pixelmovement.collision_folder, filename)
return @cache[$pixelmovement.collision_folder + filename]
end
#---------------------------------------------------------------------------
# loads a height map
#---------------------------------------------------------------------------
def self.height_map(filename)
self.load_bitmap($pixelmovement.height_folder, filename)
return @cache[$pixelmovement.height_folder + filename]
end
#---------------------------------------------------------------------------
# loads a swamp map
#---------------------------------------------------------------------------
def self.swamp_map(filename)
self.load_bitmap($pixelmovement.swamp_folder, filename)
return @cache[$pixelmovement.swamp_folder + filename]
end
end
end
#===============================================================================
# Input Module
#===============================================================================
module Input
#-----------------------------------------------------------------------------
# 4 Direction Diagonal movement
#-----------------------------------------------------------------------------
def self.dir4diag
if Input.press?(LEFT)
return 1
elsif Input.press?(RIGHT)
return 9
elsif Input.press?(UP)
return 7
elsif Input.press?(DOWN)
return 3
else
return 0
end
end
end
#===============================================================================
# Settings:
#-------------------------------------------------------------------------------
# the values after the '=' are the standard settings, you can use any other
# similar value. These commands can be used any time during the game.
#-------------------------------------------------------------------------------
# for methods: value can be either true or false, if value is not set the
# switch changes (e.g. from true to false)
#===============================================================================
# Collsion-Map Folder:
$pixelmovement.collision_folder = 'Graphics/ZPassability/'
# Height-Map Folder:
$pixelmovement.height_folder = 'Graphics/ZSurface/'
# Swamp-Map Folder:
$pixelmovement.swamp_folder = 'Graphics/ZSwamps/'
#-------------------------------------------------------------------------------
# Number of frames:
$pixelmovement.frame_number = 4
# Order + Numbers of the frames:
$pixelmovement.frame_array = []
# Special frame(s) only for standing animation?:
$pixelmovement.stand_frame = 0
# Order+Number(s) of the frame(s) for the standing animation:
$pixelmovement.stand_array = []
# Number of sprite directions (4/8):
$pixelmovement.direction_number = 4
# The frame speed of the events (1.0 is standard)
$pixelmovement.frame_speed = 1.0
# Movement type can be 'dir8', 'dir4' and 'dir4diag'
$pixelmovement.movement_type = 'dir8'
# Order+ Numbers of the directions:
$pixelmovement.direction_array = []
# Number of Frames for the Player Sprite, also used for Caterpillars!:
$pixelmovement.player_frame_number = nil
# Number of Directions for the Player Sprite, also used for Caterpillars!:
$pixelmovement.player_direction_number = nil
# Number of Stand Frames for the Player Sprite only used, if its != nil, also
# used for Caterpillars!
$pixelmovement.player_stand_frame = nil
# The frame speed of the player (1.0 is standard)
$pixelmovement.player_frame_speed = 1.0
#-------------------------------------------------------------------------------
# Size of Player Event:
$pixelmovement.player_size = [12, 8]
# The shift of the player in x direction
$pixelmovement.player_shift_x = 0
# The shift of the player in y direction
$pixelmovement.player_shift_y = 0
# Correction of the Event Sizes:
$pixelmovement.event_size_add = 0
#-------------------------------------------------------------------------------
# settings for creating waypoints for Pathfinding
# (all maps? , mad ids, isometric waypoints?)
$pixelmovement.waypoints_settings = [true, [8], false]
#-------------------------------------------------------------------------------
# Distance in Px:
$pixelmovement.cater_distance = 8
# Switch for the Caterpillar Script:
$pixelmovement.switch_caterpillar(true)
# Switch for Caterpillar Overlapping:
$pixelmovement.switch_cater_overlap(false)
#-------------------------------------------------------------------------------
# Sprint Speed:
$pixelmovement.sprint_speed = 1
# Sprint Key, set to nil to disable script:
$pixelmovement.sprint_key = Input::A
# Sprint Time:
$pixelmovement.sprint_time = 50
# Rest Time:
$pixelmovement.sprint_wait = 20
# Switch for direction fix while sprinting:
$pixelmovement.switch_sprint_fix(false)
#-------------------------------------------------------------------------------
# Minimap position:
# 1 = upper left corner, 2 = upper right, 3 = lower left, 4 = lower right
$pixelmovement.minimap_pos = 1
# Minimap Width:
$pixelmovement.minimap_width = 160.0
# Minimap Height:
$pixelmovement.minimap_height = 120.0
# 1 / Scale of the Minimap:
$pixelmovement.minimap_scale = 4.0
# Scale of the Player Sprite on the minimap
$pixelmovement.minimap_player_scale = 3.0
# Minimap Opacity:
$pixelmovement.minimap_opacity = 200
# Color of the cursor on the collision minimap:
$pixelmovement.minimap_c_cursor = Color.new(255, 0, 0)
# Color of passable things on the collision minimap:
$pixelmovement.minimap_c_pass = Color.new (255, 255, 255)
# Color of non-passable things on the collision minimap:
$pixelmovement.minimap_c_n_pass = Color.new(0, 0, 0)
# Switch for the Minimap Script:
$pixelmovement.switch_minimap(false)
# Switch for the Minimap Character Sprites:
$pixelmovement.switch_minimap_sprites(true)
# Switch for the Collision Minimaps:
$pixelmovement.switch_minimap_collision(false)
#-------------------------------------------------------------------------------
# Looped Maps:
$pixelmovement.loop_maps = [6]
#-------------------------------------------------------------------------------
# Key to jump, set to nil for no jumping:
$pixelmovement.jump_key = Input::X
# the height of the jump:
$pixelmovement.jump_height = 2
# the distance of the jump (in Pixel):
$pixelmovement.jump_length = 64
#-------------------------------------------------------------------------------
# slippery tiles' Terrain IDs, must be a range or an array,
# set to nil to disable:
$pixelmovement.ice_tiles = [6]
#-------------------------------------------------------------------------------
# Switch for the Isometric Script:
$pixelmovement.switch_isometric(false)
#-------------------------------------------------------------------------------
# Switch for sliding:
$pixelmovement.switch_sliding(true)
#-------------------------------------------------------------------------------
# Switch for special Panorama scrolling:
$pixelmovement.switch_panorama_scrolling(true)
#-------------------------------------------------------------------------------
# dont change this, its used to prevent that methods are aliased more than once
$pixelmovement.pixel_aliasing = true
#-------------------------------------------------------------------------------
# creates missing folders
Dir.mkdir('Data/Tables') if not Dir.entries('Data').include?('Tables')
Dir.mkdir('Data/Waypoints') if not Dir.entries('Data').include?('Waypoints')
#-------------------------------------------------------------------------------