Jump to content
New account registrations are disabed. This website is now an archive. Read more here.

Teddysharons

Member
  • Content Count

    8
  • Joined

  • Last visited

About Teddysharons

  • Rank
    Newbie

Other

  • Referer
    Google

Profile Information

  • Gender
    Male
  • Location
    Midgar (Houston, TX)

Engines

  • Prefered Engine
    RPG Maker XP
  • Engine Level
    Good
  • Class Title
    Level Designer
  • Other Skills
    I can Event pretty decently.
  • Project(s)
    Epic Try Hard Adventures
  1. Flawless victory. Thanks all for everything. I don't mind the players being added right under my character I can cope with that and probably event enough to make it look decent. Thank you again for all your help. I owe you one.
  2. It didn't work... it did the same thing; not update, but once I zone the member showed and was stuck wherever I set the transfer player location to. There's gotta be a way to do this? It shouldn't be Anti-lag because it is exactly what you said.
  3. Maybe the cause of the caterpillar not updating is because of an Anti-lag script?
  4. http://www.youtube.com/watch?v=AS0b7ALXuL0&feature=player_embedded How do I make it so that the party is updated as soon as a party member comes in or out (add or removed) if you watch the video you'll see. [spoiler]#=============================================================================== # ** Pixelmovement Script #------------------------------------------------------------------------------- # # f0tz!baerchen # v1.3 # 10.12.2006 # #------------------------------------------------------------------------------- # # Credits: # arevulopapo (turn toward/away player methods, # stay_in_range method, distance method) # Caesar (fill_circle method) # Fanha Giang (Autotile handling) # Caldaron (move_toward_player method) # #------------------------------------------------------------------------------- # # Importance: # This script already uses an own (optimized) Anti-Lag-Script and has many more # features than only Pixelmovement. Information for the options can be found at # the end of the script. Sometimes you have to add a comment in an event # to activate special features for this event. Except for the Anti-Lag the # comment can be anywhere at the beginning of the first event's page. The Script # checks every line for such comments until it finds a non comment line. # #------------------------------------------------------------------------------- # # 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) # # #=============================================================================== #------------------------------------------------------------------------------- # * SDK Log Script #------------------------------------------------------------------------------- SDK.log('Pixelmovement', 'f0tz!baerchen', 1.3, '29.10.06') #------------------------------------------------------------------------------- # Begin SDK Enabled Check #------------------------------------------------------------------------------- if SDK.state('Pixelmovement') == true #=============================================================================== # 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_accessor :frame_number attr_accessor :frame_array attr_accessor :stand_frame attr_accessor :stand_array attr_accessor :direction_number attr_accessor :direction_array attr_reader :isometric attr_reader :cater_activate attr_accessor :cater_distance attr_reader :cater_overlap attr_accessor :player_size attr_accessor :player_frame_number attr_accessor :player_direction_number attr_accessor :player_stand_frame 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_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 #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- def initialize(aliasing = false) @pixel_aliasing = aliasing # aliased methods are only aliased once end #----------------------------------------------------------------------------- # methods to prevent errors with boolean settings #----------------------------------------------------------------------------- def switch_caterpillar(value = nil) if value == nil @cater_activate = !@cater_activate else @cater_activate = value end return end #----------------------------------------------------------------------------- # switch for isometric function #----------------------------------------------------------------------------- def switch_isometric(value = nil) if value == nil @isometric = !@isometric else @isometric = value end if @cater_activate and $game_map != nil for actor in $game_map.game_party_actors actor.way = [] actor.path_steps = 0 actor.move_list = [] actor.moveto($game_player.x, $game_player.y) end end return end #----------------------------------------------------------------------------- # switch for caterpillar overlapping #----------------------------------------------------------------------------- def switch_cater_overlap(value = nil) if value == nil @cater_overlap = !@cater_overlap else @cater_overlap = value end return end #----------------------------------------------------------------------------- # switch for direction fix while sprinting #----------------------------------------------------------------------------- def switch_sprint_fix(value = nil) if value == nil @sprint_fix = !@sprint_fix else @sprint_fix = value end return end #----------------------------------------------------------------------------- # switch for the minimap #----------------------------------------------------------------------------- def switch_minimap(value = nil) if value == nil @minimap = !@minimap else @minimap = value end return end #----------------------------------------------------------------------------- # switch for the minimap character sprites #----------------------------------------------------------------------------- def switch_minimap_sprites(value = nil) if value == nil @minimap_sprites = !@minimap_sprites else @minimap_sprites = value end return end #----------------------------------------------------------------------------- # switch for the collision minimap #----------------------------------------------------------------------------- def switch_minimap_collision(value = nil) if value == nil @minimap_collision = !@minimap_collision else @minimap_collision = value end return end #----------------------------------------------------------------------------- # switch for hero sliding #----------------------------------------------------------------------------- def switch_sliding(value = nil) if value == nil @sliding = !@sliding else @sliding = value end return end #----------------------------------------------------------------------------- # switch for special panorama scrolling #----------------------------------------------------------------------------- def switch_panorama_scrolling(value = nil) if value == nil @panorama_scrolling = !@panorama_scrolling else @panorama_scrolling = value end return end end #------------------------------------------------------------------------------- # creates the setting object (depending on if the game has just been # started or restarted) #------------------------------------------------------------------------------- if $pixelmovement == nil $pixelmovement = Pixelmovement_Settings.new else $pixelmovement = Pixelmovement_Settings.new(true) end #=============================================================================== # 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 :char_graphic_changing # saves chars which changed their graphic 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_reader :jump_events # for jump events attr_reader :ice_events # for sliding events #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- alias pixel_initialize initialize if not $pixelmovement.pixel_aliasing def initialize pixel_initialize @char_graphic_changing = [] # contains characters which graphics changed end #----------------------------------------------------------------------------- # map setup #----------------------------------------------------------------------------- alias pixel_set setup if not $pixelmovement.pixel_aliasing def setup(map_id) pixel_set(map_id) #--------------------------------------------------------------------------- # Caterpillar System #--------------------------------------------------------------------------- @game_party_actors = [] if $pixelmovement.cater_activate for i in 1..$game_party.actors.length @game_party_actors += [Game_Party_Actor.new(i)] end end #--------------------------------------------------------------------------- # checks if Pixel Setting is activated, adds every event consisting a # "jump/ice-comment" to an array or for special frame rates, etc.. #--------------------------------------------------------------------------- @jump_events = {} @ice_events = {} for event in @events.values i = 0 list = event.event.pages[0] while list.list[i].code == 108 or list.list[i].code == 408 if list.list[i].parameters[0].downcase.include?('teleport:') bla = list.list[i].parameters[0].split(/:/)[1].split(/,/) event.moveto(bla[0].to_i,bla[1].to_i) elsif list.list[i].parameters[0].downcase.include?('jump:') @jump_events[event.id] = event elsif list.list[i].parameters[0].downcase.include?('ice:') @ice_events[event.id] = event elsif list.list[i].parameters[0].downcase.include?('frames:') event.frame_number = list.list[i].parameters[0].split(/:/)[1].to_i elsif list.list[i].parameters[0].downcase.include?('stand frame:') event.stand_frame = list.list[i].parameters[0].split(/:/)[1].to_i elsif list.list[i].parameters[0].downcase.include?('directions:') event.direction_number = list.list[i].parameters[0].split(/:/)[1].to_i end i += 1 end end #--------------------------------------------------------------------------- # frame rate etc. for Player #--------------------------------------------------------------------------- if $pixelmovement.player_frame_number != nil $game_player.frame_number = $pixelmovement.player_frame_number else $game_player.frame_number = $pixelmovement.frame_number end if $pixelmovement.player_direction_number != nil $game_player.direction_number = $pixelmovement.player_direction_number else $game_player.direction_number = $pixelmovement.direction_number end if $pixelmovement.player_stand_frame != nil $game_player.stand_frame = $pixelmovement.player_stand_frame else $game_player.stand_frame = $pixelmovement.stand_frame 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 += [@map_id] end #--------------------------------------------------------------------------- # see below #--------------------------------------------------------------------------- self.init_bitmaps self.event_sizes end #----------------------------------------------------------------------------- # reads passability map (first tries from a map, then from a tileset, # or nothing) #----------------------------------------------------------------------------- def init_bitmaps @collision_map = nil @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 = nil 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 Event-Sizes #--------------------------------------------------------------------------- def event_sizes @char_bits = [] @char_names = [] #--------------------------------------------------------------------------- # Hero #--------------------------------------------------------------------------- if $game_party.actors != [] and $game_party.actors[0].character_name != '' if $pixelmovement.player_size != [] # if Player-Size is set manually $game_player.size['x'] = $pixelmovement.player_size[0] $game_player.size['y'] = $pixelmovement.player_size[1] else # else: from graphic name='Graphics/Characters/' + $game_party.actors[0].character_name @char_bits[0] = Bitmap.new(name) bla = [@char_bits[0].width/$game_player.frame_number/4, @char_bits[0].height/$game_player.direction_number/4].max + $pixelmovement.event_size_add $game_player.size['x'] = bla $game_player.size['y'] = bla end end @char_names[0] = $game_party.actors[0].character_name #--------------------------------------------------------------------------- #Events #--------------------------------------------------------------------------- if @events.keys.length > 0 @events.keys.each do |id| # uses graphic if @events[id].character_name != '' @char_bits[id] = Bitmap.new(name = 'Graphics/Characters/' + @events[id].character_name) bla = [@char_bits[id].width/@events[id].frame_number/4, @char_bits[id].height/@events[id].direction_number/4].max + $pixelmovement.event_size_add @events[id].size['x'] = bla @events[id].size['y'] = bla end # checks if a comment is in the first lines i = 0 list = @events[id].event.pages[0] while list.list[i].code == 108 or list.list[i].code == 408 if list.list[i].parameters[0].downcase.include?('event_size:') bla = list.list[i].parameters[0].split(/:/)[1] if not bla.include?(',') @events[id].size['x'] = bla.to_i @events[id].size['y'] = bla.to_i else bla = bla.split(/,/) @events[id].size['x'] = bla[0].to_i @events[id].size['y'] = bla[1].to_i end break end i += 1 end @char_names[id] = @events[id].character_name end end @char_bits = [] 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 #----------------------------------------------------------------------------- alias pixel_encounter_step encounter_step if not $pixelmovement.pixel_aliasing def encounter_step return pixel_encounter_step * 32 end #----------------------------------------------------------------------------- # Scroll Down, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_down scroll_down if not $pixelmovement.pixel_aliasing def scroll_down(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_y = @display_y + distance.round else pixel_scr_down(distance.round) end end #----------------------------------------------------------------------------- # Scroll Left, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_left scroll_left if not $pixelmovement.pixel_aliasing def scroll_left(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_x = @display_x - distance.round else pixel_scr_left(distance.round) end end #----------------------------------------------------------------------------- # Scroll Right, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_right scroll_right if not $pixelmovement.pixel_aliasing def scroll_right(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_x = @display_x + distance.round else pixel_scr_right(distance.round) end end #----------------------------------------------------------------------------- # Scroll Up, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_up scroll_up if not $pixelmovement.pixel_aliasing def scroll_up(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_y = @display_y - distance.round else pixel_scr_up(distance.round) end end #----------------------------------------------------------------------------- # valid? method, uses real map-size now (*32) #----------------------------------------------------------------------------- alias pixel_valid? valid? if not $pixelmovement.pixel_aliasing def valid?(x, y) return (pixel_valid?(x / 32 + 1,(y + 30) / 32) or $pixelmovement.loop_maps.include?(@map_id)) end #----------------------------------------------------------------------------- # Passable? method # has been rebuilt for both collision maps and databse passability #----------------------------------------------------------------------------- def passable?(x, y, d, self_event = nil) # returns if coords are not on the map return false if not valid?(x, y) # return true if self_event is a Caterpillar return true if self_event.is_a?(Game_Party_Actor) # changes d if neccessary if d == 1 or d == 3 or d == 0 d = 2 elsif d == 7 or d == 9 d = 8 end #--------------------------------------------------------------------------- # collision map exists? #--------------------------------------------------------------------------- if @pass_type == 'Map' or @pass_type == 'Tileset' return pixel_passable?(x, y, d, self_event, @pass_type) #--------------------------------------------------------------------------- # without Collision Map, database passability is used #--------------------------------------------------------------------------- else #------------------------------------------------------------------------- # creates rectangle which has to be checked #------------------------------------------------------------------------- if self_event == nil x_size = y_size = 0 else x_size = self_event.size['x'] y_size = self_event.size['y'] end x = x + 16 y = y + 30 case d when 2 x = (x - x_size / 2)..(x + x_size / 2) y = [y] when 4 x = [x - x_size / 2] y = (y - y_size)..y when 6 x = [x + x_size / 2] y = (y - y_size)..y when 8 x = (x - x_size / 2)..(x + x_size / 2) y = [y - y_size] end #------------------------------------------------------------------------- # checks this rectangle if it is passable #------------------------------------------------------------------------- bit = (1 << (d / 2 - 1)) & 0x0f bit_i = (1 << ((10 - d) / 2 - 1)) & 0x0f for x_i in x for y_i in y for i in [2, 1, 0] tile_id = data[x_i / 32, y_i / 32, i] #------------------------------------------------------------------- # impassable #------------------------------------------------------------------- if tile_id == nil or # impassable @passages[tile_id] & 0x0f == 0x0f or # If you can move on the tile but not over the tile to another one (@passages[tile_id] & bit != 0 and # needed for a small border (((x_i - 8) % 32 == 0 and bit == 2) or # Face Left ((x_i + 8) % 32 == 0 and bit == 4) or # Face Right ((y_i + 8) % 32 == 0 and bit == 1) or # Face Down ((y_i - 8) % 32 == 0 and bit == 8))) # Face Up return false #------------------------------------------------------------------- # only one direction is passable #------------------------------------------------------------------- elsif [7, 11, 14, 13].include?(@passages[tile_id]) # Tile next to the obstacle (maybe more Tiles have to be set, # e.g. if an obstacle is both on the left and on the right side) x_t = 0 x_t2 = 0 y_t = 0 y_t2 = 0 x_t -= 24 if [7, 13, 14].include?(@passages[tile_id]) # RIGHT if x_t == 0 x_t += 24 if [7, 11, 14].include?(@passages[tile_id]) #LEFT else x_t2 += 24 if [7, 11, 14].include?(@passages[tile_id]) end y_t -= 24 if [7, 11, 13].include?(@passages[tile_id]) # DOWN if y_t == 0 y_t += 24 if [11, 13, 14].include?(@passages[tile_id]) # UP else y_t2 += 24 if [11, 13, 14].include?(@passages[tile_id]) end tile_id_1 = data[(x_i + x_t) / 32, y_i / 32, i] if x_t != 0 tile_id_2 = data[x_i / 32, (y_i + y_t) / 32, i] if y_t != 0 tile_id_3 = data[(x_i + x_t2) / 32, y_i / 32, i] if x_t2 != 0 tile_id_4 = data[x_i / 32, (y_i + y_t2) / 32, i] if y_t2 != 0 # If obstacle is set, and you cannot move on the tile if @passages[tile_id] >= bit_i and ((tile_id_1 != nil and @passages[tile_id_1] != 0) or (tile_id_2 != nil and @passages[tile_id_2] != 0) or (tile_id_3 != nil and @passages[tile_id_3] != 0) or (tile_id_4 != nil and @passages[tile_id_4] != 0)) return false end #------------------------------------------------------------------- # more than one direction is passable #------------------------------------------------------------------- else # Tile next to the obstacle (maybe more Tiles have to be set, # e.g. if an obstacle is both on the left and on the right side) x_t = 0 x_t2 = 0 y_t = 0 y_t2 = 0 x_t -= 24 if [4, 5, 6, 12].include?(@passages[tile_id]) # RIGHT if x_t == 0 x_t += 24 if [2, 3, 6, 10].include?(@passages[tile_id]) #LEFT else x_t2 += 24 if [2, 3, 6, 10].include?(@passages[tile_id]) end y_t -= 24 if [1, 3, 5, 9].include?(@passages[tile_id]) # DOWN if y_t == 0 y_t += 24 if [8, 9, 10, 12].include?(@passages[tile_id]) # UP else y_t2 += 24 if [8, 9, 10, 12].include?(@passages[tile_id]) end if x_t != 0 or y_t != 0 tile_id_1 = data[(x_i + x_t) / 32, (y_i + y_t) / 32, i] end if x_t2 != 0 or y_t2 != 0 tile_id_2 = data[(x_i + x_t2) / 32, (y_i + y_t2) / 32, i] end # If obstacle is set, and you cannot move on the tile if @passages[tile_id] >= bit_i and ((tile_id_1 != nil and @passages[tile_id_1] != 0) or (tile_id_2 != nil and @passages[tile_id_2] != 0)) return false end end end end end end return true end #----------------------------------------------------------------------------- # checks if passable, initialises pixel to be checked #----------------------------------------------------------------------------- def pixel_passable?(x, y, d, event, type) if event == nil x_size = y_size = 2 else x_size = event.size['x'] y_size = event.size['y'] end x_size = 2 if x_size < 2 y_size = 2 if y_size < 2 x = x + 16 y = y + 30 counter = 0 #--------------------------------------------------------------------------- # checks pixel on collision map #--------------------------------------------------------------------------- case d when 2 for i in (x - x_size / 2)..(x + x_size / 2) if i % 2 == 0 and ((type == 'Map' and self.pass_map(i, y)) or ( type == 'Tileset' and self.pass_tileset(i, y))) counter += 1 end end return true if counter >= ((x + x_size / 2) - (x - x_size / 2)) / 2 when 4 for i in (y - y_size)..(y) if i % 2 == 0 and ((type == 'Map' and self.pass_map(x - x_size / 2, i)) or (type == 'Tileset' and self.pass_tileset(x - x_size / 2, i))) counter += 1 end end return true if counter >= ((y) - (y - y_size)) / 2 when 6 for i in (y - y_size)..(y) if i % 2 == 0 and ((type == 'Map' and self.pass_map(x + x_size / 2, i)) or ( type == 'Tileset' and self.pass_tileset(x + x_size / 2, i))) counter += 1 end end return true if counter >= ((y) - (y - y_size)) / 2 when 8 for i in (x - x_size / 2)..(x + x_size / 2) if i % 2 == 0 and ((type == 'Map' and self.pass_map(i, y - y_size)) or ( type == 'Tileset' and self.pass_tileset(i, y - y_size))) counter += 1 end end return true if counter >= ((x + x_size / 2) - (x - x_size / 2)) / 2 end return false end #----------------------------------------------------------------------------- # Checks passability if a Tileset Collision-Map is used #----------------------------------------------------------------------------- def pass_tileset(x, y) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # on looped maps: coords are changed eventually if $pixelmovement.loop_maps.include?($game_map.map_id) if x >= ($game_map.width * 32) x -= ($game_map.width * 32) elsif x < 0 x += ($game_map.width * 32) end if y >= ($game_map.height * 32) y -= ($game_map.height * 32) elsif y < 0 y += ($game_map.height * 32) end end layer = 0 # current layer passed = [] # saves which layers are passable empty = 0 # saves which layers do not contain a tile on this position type = 0 # saves which autotile set has to be saved (or normal tileset) x_s = x # sabes original x coord y_s = y # sabes original y coord #--------------------------------------------------------------------------- # checks every layer #--------------------------------------------------------------------------- while layer <= 2 pruefe = true x = x_s y = y_s pos = self.data[x / 32, y / 32, layer] pos = 0 if pos == nil #------------------------------------------------------------------------- # calculates position on collision map #------------------------------------------------------------------------- if pos >= 384 pos -= 384 sy = (pos / 8) * 32 sx = (pos % 8) * 32 x = sx + x % 32 y = sy + y % 32 type = 0 elsif pos >= 48 type = pos / 48 pos = pos % 48 sy = (pos / 8) * 32 sx = (pos % 8)* 32 x = sx + x % 32 y = sy + y % 32 else passed[layer] = 1 empty += 1 pruefe = false end #------------------------------------------------------------------------- # checks collision map and saves result into the collision table / checks # collision table (to check a table is faster!) #------------------------------------------------------------------------- if pruefe table = RPG::Cache.read_table(@collision_map[type], x, y) if table == 2 passed[layer] = 1 elsif table == 1 passed[layer] = 0 else if @collision_map[type].get_pixel(x, y) != Color.new(0, 0, 0) passed[layer] = 1 RPG::Cache.write_table(@collision_map[type], x, y, 2) else passed[layer] = 0 RPG::Cache.write_table(@collision_map[type], x, y, 1) end end end layer += 1 end #--------------------------------------------------------------------------- # 'Bridges' or free space = true #--------------------------------------------------------------------------- return ((passed[0] == 1 and passed[1] == 1 and passed[2] == 1) or (passed[0] == 0 and passed[1] == 1 and passed[2] == 1 and ((data[x_s / 32, y_s / 32, 1] != 0 and @priorities[data[x_s / 32, y_s / 32, 1]] == 0) or (data[x_s / 32, y_s / 32, 2] != 0 and @priorities[data[x_s / 32, y_s / 32, 2]] == 0)) and empty < 2)) end #----------------------------------------------------------------------------- # Checks passability if a Map Collision-Map is used #----------------------------------------------------------------------------- def pass_map(x, y) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # on looped maps: coords are changed eventually if $pixelmovement.loop_maps.include?($game_map.map_id) if x >= ($game_map.width * 32) x -= ($game_map.width * 32) elsif x < 0 x += ($game_map.width * 32) end if y >= ($game_map.height * 32) y -= ($game_map.height * 32) elsif y < 0 y += ($game_map.height * 32) end end #--------------------------------------------------------------------------- # checks collision map and saves result into the collision table / checks # collision table (to check a table is faster!) #--------------------------------------------------------------------------- table = RPG::Cache.read_table(@collision_map, x, y) if table == 2 return true elsif table == 1 return false else if @collision_map.get_pixel(x, y) != Color.new(0, 0, 0) RPG::Cache.write_table(@collision_map, x, y, 2) return true else RPG::Cache.write_table(@collision_map, x, y, 1) return false end end end #----------------------------------------------------------------------------- # bush? method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_bush? bush? if not $pixelmovement.pixel_aliasing def bush?(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_bush?(x, y) end #----------------------------------------------------------------------------- # counter? method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_counter? counter? if not $pixelmovement.pixel_aliasing def counter?(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_counter?(x, y) end #----------------------------------------------------------------------------- # terrain method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_terrain terrain_tag if not $pixelmovement.pixel_aliasing def terrain_tag(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_terrain(x, y) end #----------------------------------------------------------------------------- # returns the id on the position x,y #----------------------------------------------------------------------------- def tile_id(x, y, i = 0) x = (x + 16) / 32 y = (y - 8) / 32 + 1 return data[x, y, i] end #----------------------------------------------------------------------------- # check_event method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_check_event check_event if not $pixelmovement.pixel_aliasing def check_event(x, y) return pixel_check_event(x, y) if pixel_check_event != nil for event in $game_map.events.values if event.in_rect?(x, y, 32, 32) return event.id end end end #----------------------------------------------------------------------------- # map update #----------------------------------------------------------------------------- alias pixel_map_up update if not $pixelmovement.pixel_aliasing def update #--------------------------------------------------------------------------- # if an event changes its graphic the size will be calculated again #--------------------------------------------------------------------------- if @char_graphic_changing != [] if $scene.is_a?(Scene_Map) and $scene.spriteset != nil and $scene.spriteset.minimap != nil $scene.spriteset.minimap.set_chars($scene.spriteset) end do_it = 0 @events.keys.each do |id| if @char_graphic_changing.include?(id) and not @events[id].in_rect?($game_player.x, $game_player.y + @events[id].size['y'] / 2 - $game_player.size['y'] / 2, [$game_player.size['x'], @events[id].size['x']].max * 2, [$game_player.size['y'], @events[id].size['y']].max * 2) do_it += 1 end end if do_it == @char_graphic_changing.length self.event_sizes @char_graphic_changing = [] end else @events.keys.each do |id| if @events[id].character_name != @char_names[id] @char_graphic_changing += [id] end end if $game_player.character_name != @char_names[0] @char_graphic_changing += [0] end end #--------------------------------------------------------------------------- # normal update #--------------------------------------------------------------------------- pixel_map_up #--------------------------------------------------------------------------- # updates Caterpillars (and (de)activates them, if neccessary) #--------------------------------------------------------------------------- if @game_party_actors != [] @game_party_actors.each do |actor| actor.update end if not $pixelmovement.cater_activate for sprite in $scene.spriteset.game_party_actors_sprites sprite.dispose end $scene.spriteset.game_party_actors_sprites = [] @game_party_actors = [] end elsif $pixelmovement.cater_activate @game_party_actors = [] for i in 1..$game_party.actors.length @game_party_actors += [Game_Party_Actor.new(i)] end for i in 0..@game_party_actors.length - 1 sprite = Sprite_Character.new($scene.spriteset.viewport1, @game_party_actors[i]) $scene.spriteset.game_party_actors_sprites.push(sprite) end end end end #=============================================================================== # Game_Character Class #=============================================================================== class Game_Character attr_accessor :x attr_accessor :y attr_accessor :stop_count attr_accessor :direction attr_accessor :trigger_on attr_accessor :event attr_accessor :move_speed attr_accessor :opacity attr_accessor :walk_anime attr_accessor :size attr_accessor :step_anime attr_accessor :z attr_accessor :last_moving attr_accessor :way attr_accessor :path_steps attr_accessor :speed_factor attr_accessor :frame_number attr_accessor :direction_number attr_accessor :stand_frame #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- alias pixel_cha_init initialize if not $pixelmovement.pixel_aliasing def initialize pixel_cha_init @last_moving = false # saves if Character was moving at the last update @move_speed = @move_speed * 1.0 @walk = false # used to prevent sliding when the event starts walking @path_steps = 0 # saves step-size after pathfinding @trigger_on = 0 # used to prevent multi-event-activation @way = nil # saved Path found with pathfinding @speed_factor = 1.0 # for height/swamp maps @z = 0 # z-coordinate @size = { # Event-Size 'x' => 32, 'y' => 32 } @frame_number = $pixelmovement.frame_number @direction_number = $pixelmovement.direction_number @stand_frame = $pixelmovement.stand_frame 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) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # for Isometric script if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end 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) return true if @through # help variables help_x = new_x help_y = new_y counter = 0 #--------------------------------------------------------------------------- # checks the way to the new position if it is passable #--------------------------------------------------------------------------- case d when 1 y+=1 x-=1 while (help_y >= y) and (help_x <= x) and ($game_map.passable?(help_x,help_y, 2, self)) and ($game_map.passable?(help_x,help_y, 4, self)) counter += 2 help_y -= 2 help_x += 2 end return false if counter < new_y - y + 1 and counter < x - new_x + 1 when 2 y += 1 while (help_y >= y) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_y -= 2 end return false if counter < new_y - y + 1 when 3 y += 1 x += 1 while (help_y >= y) and (help_x >= x) and ($game_map.passable?(help_x, help_y, 2, self)) and ($game_map.passable?(help_x, help_y, 6, self)) counter += 2 help_y -= 2 help_x -= 2 end return false if counter < new_y - y + 1 and counter < new_x - x + 1 when 4 x -= 1 while (help_x <= x) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_x += 2 end return false if counter < x - new_x + 1 when 6 x += 1 while (help_x >= x) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_x -= 2 end return false if counter < new_x - x + 1 when 7 y -= 1 x -= 1 while (help_y <= y) and (help_x <= x) and ($game_map.passable?(help_x, help_y, 8, self)) and ($game_map.passable?(help_x, help_y, 4, self)) counter += 2 help_y += 2 help_x += 2 end return false if counter < y - new_y + 1 and counter < x - new_x + 1 when 8 y -= 1 while (help_y <= y) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_y += 2 end return false if counter < y - new_y + 1 when 9 y -= 1 x += 1 while (help_y <= y) and (help_x >= x) and ($game_map.passable?(help_x, help_y, 8, self)) and ($game_map.passable?(help_x, help_y, 6, self)) counter += 2 help_y += 2 help_x -= 2 end return false if counter < y - new_y + 1 and counter < new_x - x + 1 end #--------------------------------------------------------------------------- # checks if an Event is on the same place #--------------------------------------------------------------------------- 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'], event.size['y'] + @size['y'], new_x, new_y) and event != self and not event.through and (event.character_name != '' or event.tile_id != 0) return false end end #--------------------------------------------------------------------------- # checks if the Player is on the same place #--------------------------------------------------------------------------- if self != $game_player and not $game_player.through and (@character_name != '' or $game_player.tile_id != 0) and self.in_rect?($game_player.x, $game_player.y - $game_player.size['y'] / 2 + @size['y'] / 2, $game_player.size['x'] + @size['x'], $game_player.size['y'] + @size['y'], new_x, new_y) return false end #--------------------------------------------------------------------------- # 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 #----------------------------------------------------------------------------- # update method, has been splitted to give an easier overview #----------------------------------------------------------------------------- def update #--------------------------------------------------------------------------- # updates #--------------------------------------------------------------------------- # update special for looped maps self.update_loop_map # checks for events self.check_event_trigger_touch if (self.moving? and not @through) # walks Pathfinding route self.go_path # checks if the move speed changes because of hills, swamps, etc. if not self.is_a?(Game_Party_Actor) @move_speed /= @speed_factor @speed_factor = [[0.1, self.move_speed_change].max, 2.0].min @move_speed *= @speed_factor end @last_moving = false if jumping? update_jump elsif moving? update_move @last_moving = true else update_stop end #--------------------------------------------------------------------------- # updates shown frame # has been improved, now the event doesnt slide at the beginning anymore #--------------------------------------------------------------------------- if @anime_count > (18 - @move_speed * 2) * 4 / @direction_number or (@pattern == 0 and not @walk) if not @step_anime and @stop_count > 0 @walk = false @pattern = @original_pattern else @walk = true @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 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 move_type_random when 2 move_type_toward_player when 3 move_type_custom end end end #----------------------------------------------------------------------------- # checks if the speed has to be changed because of the ground #----------------------------------------------------------------------------- def move_speed_change #--------------------------------------------------------------------------- # returns if nothing has to be checked #--------------------------------------------------------------------------- return 1.0 if ($game_map.swamp_map == nil and $game_map.height_map == nil) add = 1.0 # changing factor #--------------------------------------------------------------------------- # checks height-map #--------------------------------------------------------------------------- if $game_map.height_map != nil 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) x_su = @x + 16 y_su = @y + 32 xn_su = new_x + 16 yn_su = new_y + 32 @z = RPG::Cache.read_table($game_map.height_map, x_su - 1, y_su - 1) if @z == 0 @z = $game_map.height_map.get_pixel(x_su, y_su).red RPG::Cache.write_table($game_map.height_map, x_su - 1, y_su - 1, @z) end p = (@z - $game_map.height_map.get_pixel(xn_su, yn_su).red) * 2 if (xn_su >= $game_map.height_map.width or yn_su >= $game_map.height_map.height or x_su >= $game_map.height_map.width or y_su >= $game_map.height_map.height) p = 0 end if p > 0 p = p * 3 / 4 end add /= @move_speed / (@move_speed + p / 2) end #--------------------------------------------------------------------------- # checks swamp-map #--------------------------------------------------------------------------- if $game_map.swamp_map != nil x_sw = @x + 16 y_sw = @y + 32 - 1 if (x_sw >= $game_map.swamp_map.width or y_sw >= $game_map.swamp_map.height or x_sw < 0 or y_sw < 0) add *= 1.0 else px = RPG::Cache.read_table($game_map.swamp_map, x_sw, y_sw) if px == 0 px = $game_map.swamp_map.get_pixel(x_sw, y_sw).red RPG::Cache.write_table($game_map.swamp_map, x_sw, y_sw, px) end add *= px / 255.0 end end # returns speed return add end #----------------------------------------------------------------------------- #Loop Map Teleport when Event reached the border, etc. #----------------------------------------------------------------------------- def update_loop_map #--------------------------------------------------------------------------- # returns if map isnt looped (and changes coords of neccessary) #--------------------------------------------------------------------------- unless $pixelmovement.loop_maps.include?($game_map.map_id) @x = 0 if @x < 0 @y = 0 if @y < 0 return end #--------------------------------------------------------------------------- # returns if self is a caterpillar #--------------------------------------------------------------------------- return if self.is_a?(Game_Party_Actor) x_l = 0 # changing horizontal y_l = 0 # changing vertical #--------------------------------------------------------------------------- # teleports at the border #--------------------------------------------------------------------------- if @x > ($game_map.width * 32) x_l = - ($game_map.width * 32) @x += x_l @real_x = (@x) * 4 elsif @x < 0 x_l = ($game_map.width * 32) @x += x_l @real_x = (@x) * 4 end if @y > ($game_map.height * 32) y_l = - ($game_map.height * 32) @y += y_l @real_y = (@y) * 4 elsif @y < 0 y_l = ($game_map.height * 32) @y += y_l @real_y = (@y) * 4 end #--------------------------------------------------------------------------- # If the Player reached the border, the Caterpillars are teleported, too #--------------------------------------------------------------------------- return if not (self == $game_player and (x_l != 0 or y_l != 0)) $game_map.game_party_actors.each do |actor| actor.x += x_l actor.y += y_l actor.real_x = (actor.x) * 4 actor.real_y = (actor.y) * 4 actor.move_list.each do |ko| ko[0] += x_l ko[1] += y_l end 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 #----------------------------------------------------------------------------- def update_move distance = (2 ** @move_speed).round if @y * 4 < @real_y @real_y = [@real_y - distance, @y * 4].max elsif @y * 4 > @real_y @real_y = [@real_y + distance, @y * 4].min end if @x * 4 < @real_x if $pixelmovement.isometric @real_x = [@real_x - distance * 2, @x * 4].max else @real_x = [@real_x - distance, @x * 4].max end elsif @x * 4 > @real_x if $pixelmovement.isometric @real_x = [@real_x + distance * 2, @x * 4].min else @real_x = [@real_x + distance, @x * 4].min end end if @walk_anime @anime_count += 1.5 elsif @step_anime @anime_count += 1 end end #----------------------------------------------------------------------------- # New Move Random (more pixellike) #----------------------------------------------------------------------------- def move_type_random case rand(12) when 0..7 (rand(9) + 8).times do move_random(2) end when 8..9 (rand(9) + 8).times do move_forward(2) end end end #----------------------------------------------------------------------------- # New Move Toward Player (more pixellike) #----------------------------------------------------------------------------- def move_type_toward_player sx = @x - $game_player.x sy = @y - $game_player.y abs_sx = sx > 0 ? sx : -sx abs_sy = sy > 0 ? sy : -sy if sx.abs + sy.abs >= 32 * 20 8.times do move_random(4) end elsif sx.abs > 0 or sy.abs > 0 8.times do move_toward_player(4) end end end #----------------------------------------------------------------------------- # New Move Route (more pixellike) #----------------------------------------------------------------------------- def move_type_custom if jumping? or moving? return end #--------------------------------------------------------------------------- # commands #--------------------------------------------------------------------------- while @move_route_index < @move_route.list.size command = @move_route.list[@move_route_index] if command.code == 0 if @move_route.repeat @move_route_index = 0 end 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 end @stop_count = 0 end return end if command.code <= 14 case command.code when 1 16.times do move_down(2, true, false) end when 2 16.times do move_left(2, true, false) end when 3 16.times do move_right(2, true, false) end when 4 16.times do move_up(2, true, false) end when 5 16.times do move_lower_left(2,true,false) end when 6 16.times do move_lower_right(2, true, false) end when 7 16.times do move_upper_left(2, true, false) end when 8 16.times do move_upper_right(2, true, false) end when 9 16.times do move_random(2, true, false) end when 10 16.times do move_toward_player(2) end when 11 16.times do move_away_from_player(2) end when 12 16.times do move_forward(2) end when 13 16.times do move_backward(2) end when 14 jump(command.parameters[0] * 32, command.parameters[1] * 32) end if not @move_route.skippable and not moving? and not jumping? return end @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, again = true) if @no_slide != 2 @no_slide = 0 end if turn_enabled turn_down end if passable?(@x, @y, 2, steps) @y += steps increase_steps else if 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 end #----------------------------------------------------------------------------- # move_left, more pixellike #----------------------------------------------------------------------------- def move_left(steps = 32, turn_enabled = true, again = true) if @no_slide != 4 @no_slide = 0 end if turn_enabled turn_left end if passable?(@x, @y, 4, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end increase_steps else if 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 end #----------------------------------------------------------------------------- # move_right, more pixellike #----------------------------------------------------------------------------- def move_right(steps=32, turn_enabled = true, again = true) if @no_slide != 6 @no_slide = 0 end if turn_enabled turn_right end if passable?(@x, @y, 6, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end increase_steps else if 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 end #----------------------------------------------------------------------------- # move_up, more pixellike #----------------------------------------------------------------------------- def move_up(steps = 32, turn_enabled = true, again = true) if @no_slide != 8 @no_slide = 0 end if turn_enabled turn_up end if passable?(@x, @y, 8, steps) @y -= steps increase_steps else if 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 end #----------------------------------------------------------------------------- # move_lower_left, more pixellike #----------------------------------------------------------------------------- def move_lower_left (steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_lower_left end if passable?(@x, @y, 1, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end @y += steps increase_steps else if again and $pixelmovement.sliding move_down(steps, false, false) move_left(steps, false, false) end end end #----------------------------------------------------------------------------- # move_lower_right, more pixellike #----------------------------------------------------------------------------- def move_lower_right(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_lower_right end if passable?(@x, @y, 3, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end @y += steps increase_steps else if again and $pixelmovement.sliding move_down(steps, false, false) move_right(steps, false, false) end end end #----------------------------------------------------------------------------- # move_upper_left, more pixellike #----------------------------------------------------------------------------- def move_upper_left(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_upper_left end if passable?(@x, @y, 7, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end @y -= steps increase_steps else if again and $pixelmovement.sliding move_up(steps, false, false) move_left(steps, false, false) end end end #----------------------------------------------------------------------------- # move_upper_right, more pixellike #----------------------------------------------------------------------------- def move_upper_right(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_upper_right end if passable?(@x, @y, 9, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end @y -= steps increase_steps else if again and $pixelmovement.sliding move_up(steps, false, false) move_right(steps, false, false) end end end #----------------------------------------------------------------------------- # move_random, more pixellike #----------------------------------------------------------------------------- def move_random(steps = 32, turn_enabled = true, again = true) case rand(12) when 0..1 move_down(steps, turn_enabled, again) when 2..3 move_left(steps, turn_enabled, again) when 4..5 move_right(steps, turn_enabled, again) when 6..7 move_up(steps, turn_enabled, again) when 8 move_lower_left(steps, turn_enabled, again) when 9 move_lower_right(steps, turn_enabled, again) when 10 move_upper_left(steps, turn_enabled, again) when 11 move_upper_right(steps, turn_enabled, again) end end #----------------------------------------------------------------------------- # move_toward_player, more pixellike #----------------------------------------------------------------------------- def move_toward_player(steps = 32) case rand(6) when 0..4 self.turn_toward_player self.move_forward(steps) when 5 if steps != 32 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) case rand(6) when 0..4 self.turn_away_from_player self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_toward_event, more pixellike #----------------------------------------------------------------------------- def move_toward_event(id, steps = 32) case rand(6) when 0..4 if id == 0 self.turn_toward_player else self.turn_toward_event(id) end self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_away_from_event, more pixellike #----------------------------------------------------------------------------- def move_away_from_event(id, steps = 32) case rand(6) when 0..4 if id == 0 self.turn_away_from_player else self.turn_away_from_event(id) end self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_forward, more pixellike #----------------------------------------------------------------------------- def move_forward(steps = 32) case @direction when 1 move_lower_left(steps, false, false) when 2 move_down(steps, false, false) when 3 move_lower_right(steps, false, false) when 4 move_left(steps, false, false) when 6 move_right(steps, false, false) when 7 move_upper_left(steps, false, false) when 8 move_up(steps, false, false) when 9 move_upper_right(steps, false, 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, false) when 2 move_up(steps, false, false) when 3 move_upper_left(steps, false, false) when 4 move_right(steps, false, false) when 6 move_left(steps, false, false) when 7 move_lower_right(steps, false, false) when 8 move_down(steps, false, false) when 9 move_lower_left(steps, false, false) end @direction_fix = last_direction_fix end #----------------------------------------------------------------------------- # turn_lower_left #----------------------------------------------------------------------------- def turn_lower_left unless @direction_fix @direction = 1 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_lower_right #----------------------------------------------------------------------------- def turn_lower_right unless @direction_fix @direction = 3 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_upper_left #----------------------------------------------------------------------------- def turn_upper_left unless @direction_fix @direction = 7 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_upper_right #----------------------------------------------------------------------------- def turn_upper_right unless @direction_fix @direction = 9 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_right_90, for 8 directions #----------------------------------------------------------------------------- def turn_right_90 case @direction when 1 turn_upper_left when 2 turn_left when 3 turn_lower_left when 4 turn_up when 6 turn_down when 7 turn_upper_right when 8 turn_right when 9 turn_lower_right end end #----------------------------------------------------------------------------- # turn_left_90, for 8 directions #----------------------------------------------------------------------------- def turn_left_90 case @direction when 1 turn_lower_right when 2 turn_right when 3 turn_upper_right when 4 turn_down when 6 turn_up when 7 turn_lower_left when 8 turn_left when 9 turn_upper_left end end #----------------------------------------------------------------------------- # turn_180, for 8 directions #----------------------------------------------------------------------------- def turn_180 case @direction when 1 turn_upper_right when 2 turn_up when 3 turn_upper_left when 4 turn_right when 6 turn_left when 7 turn_lower_right when 8 turn_down when 9 turn_lower_left end end #----------------------------------------------------------------------------- # turn_random, for 8 directions #----------------------------------------------------------------------------- def turn_random case rand(12) 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 #----------------------------------------------------------------------------- # turn_toward_player, for 8 directions #----------------------------------------------------------------------------- def turn_toward_player vector = Math.atan2(($game_player.y - @y), ($game_player.x - @x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_toward_event, for 8 directions #----------------------------------------------------------------------------- def turn_toward_event(id) vector = Math.atan2(($game_map.events[id].y - @y), ($game_map.events[id].x - @x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_away_from_player, for 8 directions #----------------------------------------------------------------------------- def turn_away_from_player vector = Math.atan2((@y - $game_player.y), (@x - $game_player.x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_away_from_event, for 8 directions #----------------------------------------------------------------------------- def turn_away_from_event(id) vector = Math.atan2((@y - $game_map.events[id].y), (@x - $game_map.events[id].x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 4 when 22.5..67.49 @direction = 7 when 67.5..112.49 @direction = 8 when 112.5..157.49 @direction = 9 when 157.5..180 @direction = 6 when -180..-157.5 @direction = 6 when -157.49..-112.5 @direction = 3 when -112.49..-67.5 @direction = 2 when -67.49..-22.5 @direction = 1 end 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] #----------------------------------------------------------------------------- def looks_at?(id) sx = @x - $game_map.events[id].x sy = @y - $game_map.events[id].y return true if (sx == 0 and sy == 0) if sx.abs > sy.abs if sx > 0 and (@direction == 4 or @direction == 1 or @direction == 7) return true elsif sx < 0 and (@direction == 6 or @direction == 3 or @direction == 9) return true end else if sy > 0 and (@direction == 8 or @direction == 7 or @direction == 9) return true elsif sy < 0 and (@direction == 2 or @direction == 1 or @direction == 3) return true end end return false end #----------------------------------------------------------------------------- # new jump, height added, for Pixel Coords #----------------------------------------------------------------------------- def jump(x_plus, y_plus, high=5) new_x = @x + x_plus new_y = @y + y_plus if (x_plus == 0 and y_plus == 0) or self.passable?(new_x, new_y, @direction, 1) if x_plus != 0 or y_plus != 0 if x_plus.abs > y_plus.abs x_plus < 0 ? turn_left : turn_right else y_plus < 0 ? turn_up : turn_down end end straighten @x = new_x @y = new_y high_2 = 40 / high x_plus /= high_2 y_plus /= high_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 #----------------------------------------------------------------------------- # checks if Player shall slide #----------------------------------------------------------------------------- def check_slide(dir) return if not ($pixelmovement.sliding and self.is_a?(Game_Player)) #--------------------------------------------------------------------------- # 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 + 2, 2) end c = @size['x'] for i in 0..c if $game_map.passable?(@x + (c - i), @y + 2, 2) r += 1 break if r > l end end if r > l and $game_map.passable?(@x + @size['x'], @y + 2, 2) return 6 elsif l > 0 and $game_map.passable?(@x - @size['x'], @y + 2, 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 - 2 - @size['x'] / 2, @y + i, 4) end c = @size['y'] for i in 0..c if $game_map.passable?(@x - 2 - @size['x'] / 2, @y + (c - i), 4) d += 1 break if d > u end end if u > d and $game_map.passable?(@x - 2 - @size['x'] / 2, @y - @size['y'] * 2, 4) return 8 elsif d > 0 and $game_map.passable?(@x - 2 - @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 + 2 + @size['x'] / 2, @y + i, 6) end c = @size['y'] for i in 0..c if $game_map.passable?(@x + 2 + @size['x'] / 2, @y + (c - i), 6) d += 1 break if d > u end end if u > d and $game_map.passable?(@x + 2 + @size['x'] / 2, @y - @size['y'] * 2, 6) return 8 elsif d > 0 and $game_map.passable?(@x + 2 + @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 - 2 - @size['y'], 8) end c = @size['x'] for i in 0..c if $game_map.passable?(@x + (c - i), @y - 2 - @size['y'], 8) r += 1 break if r > l end end if r > l and $game_map.passable?(@x + @size['x'], @y - 2, 8) return 6 elsif l > 0 and $game_map.passable?(@x - @size['x'], @y - 2, 8) return 4 else @no_slide = dir end end return 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) x_s = mx - r x_e = mx + r y_s = my - r y_e = my + r return (sx >= x_s and sx <= x_e and sy >= y_s and sy <= y_e) end #----------------------------------------------------------------------------- # returns of the event is inside the rectangle #----------------------------------------------------------------------------- def in_rect?(mx, my, width, height, sx = @x, sy = @y) x_s = mx - width / 2 x_e = mx + width / 2 y_s = my - height / 2 y_e = my + height / 2 return (sx >= x_s and sx <= x_e and sy >= y_s and sy <= y_e) end #----------------------------------------------------------------------------- # returns the distance to the event with id as its id, 0 means game_player #----------------------------------------------------------------------------- def distance_to_event(id) if id == 0 return Math.sqrt((@x - $game_player.x) * (@x - $game_player.x) + (@y - $game_player.y) * (@y - $game_player.y)) else return Math.sqrt((@x - $game_map.events[id].x) * (@x - $game_map.events[id].x) + (@y - $game_map.events[id].y) * (@y - $game_map.events[id].y)) end 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 id == 0 if self.dtp < d1 self.move_away_from_player elsif self.dtp > d2 self.move_toward_player end else if self.dtp < d1 self.move_away_from_event(id) elsif self.dtp > d2 self.move_toward_event(id) end end 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 #----------------------------------------------------------------------------- def in_range? return true if not self.is_a?(Game_Event) if ($game_map.ice_events.keys.include?(@id) or $game_map.jump_events.keys.include?(@id)) return false end if (@trigger == 3 or @trigger == 4 or (@list!=nil and @list[0].code == 108 and @list[0].parameters == [''])) return true end 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 return true if (@real_x > screne_x and @real_x < screne_width and @real_y > screne_y and @real_y < screne_height) if $pixelmovement.loop_maps.include?($game_map.map_id) o_x = @real_x o_y = @real_y if $game_player.x - 16 < 32 * 9 and @x - 16 > ($game_map.width * 32) - 32 * 11 #Left o_x -= ($game_map.width * 32) * 4 end if $game_player.x - 16 > ($game_map.width * 32) - 32 * 11 and @x - 16 < 32 * 9 #Right o_x += ($game_map.width * 32) * 4 end if $game_player.y + 32 < 32 * 8 and @y + 32 > ($game_map.height * 32) - 32 * 7 #Up o_y -= ($game_map.height*32)*4 end if $game_player.y + 32 > ($game_map.height * 32) - 32 * 7 and @y + 32 < 32 * 8 #Down 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 end return false end #----------------------------------------------------------------------------- # returns Sprite (ID) of the event #----------------------------------------------------------------------------- def char_sprite(id = false) return if self == nil $scene.spriteset.character_sprites.each do |sprite| if sprite.character == self if id return $scene.spriteset.character_sprites.index(sprite) else return sprite end end end return end end #=============================================================================== # Game_Event Class #=============================================================================== class Game_Event < Game_Character #----------------------------------------------------------------------------- # initialsing method, Event is teleported to Pixel Coords #----------------------------------------------------------------------------- alias pixel_event_init initialize if not $pixelmovement.pixel_aliasing def initialize(map_id, event) pixel_event_init(map_id, event) moveto(@event.x * 32, @event.y * 32) refresh end #----------------------------------------------------------------------------- # returns if the Event is passable #----------------------------------------------------------------------------- def over_trigger? return (@through or (@character_name == '' and (@tile_id == nil or @tile_id == 0))) end #----------------------------------------------------------------------------- # Collision, Not Passable #----------------------------------------------------------------------------- def check_event_trigger_touch(x = 0,y = 0) return if $game_system.map_interpreter.running? if @trigger == 2 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) or 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)) if not jumping? and not over_trigger? and @trigger_on == 0 @trigger_on = 3 start end else @trigger_on = 0 if @trigger_on == 3 end end #----------------------------------------------------------------------------- # Collision/Autostart, Passable #----------------------------------------------------------------------------- def check_event_trigger_auto if @trigger == 2 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']) or 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) or 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))) if not jumping? and over_trigger? and @trigger_on == 0 and Graphics.frame_count > 0 @trigger_on = 4 start end else @trigger_on = 0 if @trigger_on == 4 end start if @trigger == 3 end #----------------------------------------------------------------------------- # update method, changed for Anti-Lag-Script #----------------------------------------------------------------------------- alias pixel_ev_up update if not $pixelmovement.pixel_aliasing def update return if not self.in_range? pixel_ev_up end end #=============================================================================== # Game_Player Class #=============================================================================== class Game_Player < Game_Character attr_accessor :sprint alias pixel_player_init initialize if not $pixelmovement.pixel_aliasing def initialize pixel_player_init @steps_done = 0 # counts how many steps are done after standing @schritte_zaehl = 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 end #----------------------------------------------------------------------------- # new pasable method, for 8 directions, isometric and pixelmovement #----------------------------------------------------------------------------- def passable?(x, y, d, steps = 32) # for Isometric script if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end 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) return true if $DEBUG and Input.press?(Input::CTRL) 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) super(x, y) $game_map.game_party_actors.each do |actor| actor.moveto(x, y) actor.move_list = [] actor.way = [] actor.path_steps = 0 end center(x, y) make_encounter_count end #----------------------------------------------------------------------------- # increase_steps, improved for Pixelmovement #----------------------------------------------------------------------------- alias pixel_inc_s increase_steps if not $pixelmovement.pixel_aliasing def increase_steps if @schritte_zaehl >= 10 pixel_inc_s @schritte_zaehl = 0 else @schritte_zaehl +=1 end end #----------------------------------------------------------------------------- # 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 ((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']) or 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) or 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)))) and triggers.include?(event.trigger) if not event.jumping? and event.over_trigger? and event.trigger_on == 0 event.trigger_on = 1 event.start result = true end else event.trigger_on = 0 if event.trigger_on == 1 end end return result end #----------------------------------------------------------------------------- # 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 event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if (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) or 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)) and triggers.include?(event.trigger) and self.looks_at?(event.id) if not event.jumping? and not event.over_trigger? event.start result = true end end end #--------------------------------------------------------------------------- # counter top? #--------------------------------------------------------------------------- if not result new_x = @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 = @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) # 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) new_x += (@direction == 1 ? -32 : @direction == 3 ? 32 : @direction == 7 ? -32 : @direction == 9 ? 32 : @direction == 6 ? 32 : @direction == 4 ? -32 : 0) new_y += (@direction == 1 ? 32 : @direction == 3 ? 32 : @direction == 7 ? -32 : @direction == 9 ? -32 : @direction == 2 ? 32 : @direction == 8 ? -32 : 0) for event in $game_map.events.values if event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if 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) and triggers.include?(event.trigger) and self.looks_at?(event.id) if not event.jumping? and not event.over_trigger? event.start result = true end end end end end return result end #----------------------------------------------------------------------------- # Touch, not Passable #----------------------------------------------------------------------------- def check_event_trigger_touch(x = 0,y = 0) result = false return result if $game_system.map_interpreter.running? for event in $game_map.events.values if event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if (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) or 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)) and [1, 2].include?(event.trigger) if not event.jumping? and not event.over_trigger? and event.trigger_on == 0 event.trigger_on = 2 event.start result = true end else event.trigger_on = 0 if event.trigger_on == 2 end end return result end #----------------------------------------------------------------------------- # update method, has been splitted #----------------------------------------------------------------------------- def update # updates movement and input self.update_movement last_real_x = @real_x last_real_y = @real_y # checks if sprint is activated self.check_sprint_input # checks if player shall jump self.check_jump_input if Input.trigger?(Input::C) check_event_trigger_here([0]) check_event_trigger_there([0, 1, 2]) end super # changes var for steps if last_real_x != @real_x or last_real_y != @real_y @steps_done += 1 else @steps_done = 0 end # updates encounter self.update_encounter(last_real_x, last_real_y) # updates scrolling self.update_scroll(last_real_x, last_real_y) # checks if the player stands on a jump tile self.check_jump end #----------------------------------------------------------------------------- # checks if Character is on a sliding tile #----------------------------------------------------------------------------- def check_ice return if $pixelmovement.ice_tiles == nil or $pixelmovement.ice_tiles == [] @walk_anime = true #--------------------------------------------------------------------------- # checks if an Event is on the same place #--------------------------------------------------------------------------- # more steps if player moves fast if @move_speed > 3 steps=2**(@move_speed.round-2) else steps=2 end for event in $game_map.ice_events.values if self.in_rect?(event.x, event.y - 11, 23, 23) 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?('ice:')) i += 1 next end ice = list.list[i].parameters[0].split(/: /)[1].downcase i += 1 #--------------------------------------------------------------------- # if ice type is face direction is changed #--------------------------------------------------------------------- if ice == 'face' case @direction when 1 ice = 'lower left' when 2 ice = 'down' when 3 ice = 'lower right' when 4 ice = 'left' when 6 ice = 'right' when 7 ice = 'upper left' when 8 ice = 'up' when 9 ice = 'upper right' end end #--------------------------------------------------------------------- # slides #--------------------------------------------------------------------- case ice when 'lower left' self.move_lower_left(steps) when 'down' self.move_down(steps) when 'lower right' self.move_lower_right(steps) when 'left' self.move_left(steps) when 'right' self.move_right(steps) when 'upper left' self.move_upper_left(steps) when 'up' self.move_up(steps) when 'upper right' self.move_upper_right(steps) end @walk_anime = false #--------------------------------------------------------------------- # caterpillars slide #--------------------------------------------------------------------- $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y,'sl']] if actor.id != 1 end return true end end end #--------------------------------------------------------------------------- # checks for tile ids #--------------------------------------------------------------------------- # more steps if player moves fast if @move_speed > 3 steps=2**(@move_speed.round-2) else steps=2 end if $pixelmovement.ice_tiles.include?($game_map.terrain_tag(@x, @y)) and self.passable?(@x, @y, @direction, 4) self.move_forward(steps) @walk_anime = false #--------------------------------------------------------------------- # caterpillars slide #--------------------------------------------------------------------- $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y,'sl']] if actor.id != 1 end return true end return false end #----------------------------------------------------------------------------- # checks if Character is on a jumping tile #----------------------------------------------------------------------------- def check_jump #--------------------------------------------------------------------------- # 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' x = -$pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'down' x = 0 y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'lower right' x = $pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'left' x = -$pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 'right' x = $pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 'upper left' x = -$pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 'up' x = 0 y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 'upper right' x = $pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height end self.jump(x,y,h) #--------------------------------------------------------------------- # caterpillars jump #--------------------------------------------------------------------- if self.jumping? $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_list += [[@x, @y, h]] end end end return end end end end #----------------------------------------------------------------------------- # updates movement and input #----------------------------------------------------------------------------- def update_movement #--------------------------------------------------------------------------- # checks input + moves #--------------------------------------------------------------------------- # return if no update return if (moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing or @path_steps != 0) return if self.check_ice # more steps if player moves fast if @steps_done >= 2 and @move_speed > 3 steps=2 ** (@move_speed.round - 2) else steps = 2 end x = @x y = @y # Sprint fix? if @sprint and $pixelmovement.sprint_fix (steps / 2).times do move_forward(2) end else #input case Input.dir8 when 1 (steps / 2).times do move_lower_left(2) end when 2 (steps / 2).times do move_down(2) end when 3 (steps / 2).times do move_lower_right(2) end when 4 (steps / 2).times do move_left(2) end when 6 (steps / 2).times do move_right(2) end when 7 (steps / 2).times do move_upper_left(2) end when 8 (steps / 2).times do move_up(2) end when 9 (steps / 2).times do move_upper_right(2) end end end #--------------------------------------------------------------------------- # other things #--------------------------------------------------------------------------- # saves Caterpillar Route $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y]] if actor.id != 1 end #Sprint Script off return if not @sprint @move_speed -= $pixelmovement.sprint_speed @sprint = false # Sprint of for Caterpillar? $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_speed -= $pixelmovement.sprint_speed end end end #----------------------------------------------------------------------------- # checks input for sprinting #----------------------------------------------------------------------------- def check_sprint_input @sprint_time += 1 if @sprint_time < 0 return if not self.moving? result = check_event_trigger_here([1, 2]) #--------------------------------------------------------------------------- #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 # Sprint for Caterpillar $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_speed += $pixelmovement.sprint_speed end end 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 x = -$pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 2 x = 0 y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 3 x = $pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 4 x = -$pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 6 x = $pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 7 x = -$pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 8 x = 0 y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 9 x = $pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height end self.jump(x,y,h) # jump for caterpillar return if not self.jumping? $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y, h]] if actor.id != 1 end end #----------------------------------------------------------------------------- # updates encounter count #----------------------------------------------------------------------------- def update_encounter(last_real_x, last_real_y) # returns if no steps were made return if @steps_done == 0 if not (@encounter_count > 0 and not ($DEBUG and Input.press?(Input::CTRL))) return end # changes encounter count according to move_speed if @steps_done >= 2 and @move_speed >= 4 @encounter_count -= (2 ** (@move_speed - 2)) / 2 else @encounter_count -= 1 end end #----------------------------------------------------------------------------- # updates scrolling #----------------------------------------------------------------------------- def update_scroll(last_real_x, last_real_y) 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 end #=============================================================================== # Scene_Save Class, deletes bitmaps in $game_map #=============================================================================== class Scene_Save < Scene_File alias pixel_write_s write_save_data if not $pixelmovement.pixel_aliasing def write_save_data(file) $game_map.collision_map = nil $game_map.height_map = nil $game_map.swamp_map = nil pixel_write_s(file) Marshal.dump($events, file) $game_map.init_bitmaps end end #=============================================================================== # Scene_Load Class, loads deleted bitmaps again #=============================================================================== class Scene_Load < Scene_File alias pixel_read_s read_save_data if not $pixelmovement.pixel_aliasing def read_save_data(file) pixel_read_s(file) $game_map.init_bitmaps $events = Marshal.load(file) end end #=============================================================================== # Scene_Title Class #=============================================================================== class Scene_Title alias pixel_command_n command_new_game if not $pixelmovement.pixel_aliasing def command_new_game $events = {} # used later to save Events pixel_command_n # Pixel Coords $game_player.moveto($data_system.start_x * 32, $data_system.start_y * 32) end end #=============================================================================== # Sprite_Character Class #=============================================================================== class Sprite_Character < RPG::Sprite attr_accessor :direction attr_accessor :_loop_animation attr_accessor :_animation attr_accessor :_animation_hit #----------------------------------------------------------------------------- # initialise method #----------------------------------------------------------------------------- alias pixel_sp_cha_init initialize if not $pixelmovement.pixel_aliasing def initialize (viewport, character = nil) pixel_sp_cha_init (viewport, character) # saves the real face direction later (for 4dirs) @direction = @character.direction 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 return if not @character.in_range? and self.src_rect != Rect.new(0, 0, 0, 0) super() #--------------------------------------------------------------------------- # tile graphic #--------------------------------------------------------------------------- if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue 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 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 == [] sy = (@direction - 2) / 2 * @ch else sy = ($pixelmovement.direction_array[@direction/2 - 1]) * @ch end else sy = 0 end self.src_rect.set(sx, sy, @cw, @ch) end #--------------------------------------------------------------------------- # updates position, etc #--------------------------------------------------------------------------- self.x = @character.screen_x + x_add self.y = @character.screen_y + y_add 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_Map Class #=============================================================================== class Scene_Map attr_accessor :spriteset #----------------------------------------------------------------------------- # update method #----------------------------------------------------------------------------- alias pixel_sc_map_up update if not $pixelmovement.pixel_aliasing def update pixel_sc_map_up #--------------------------------------------------------------------------- # 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 $game_temp.player_transferring = false #--------------------------------------------------------------------------- # checks if map is changed / changes map #--------------------------------------------------------------------------- if $game_map.map_id != $game_temp.player_new_map_id id = true $game_map.events.values.each {|ev| ev.trigger_on = 0} $events[$game_map.map_id] = $game_map.events # saves Events of the old Map $game_map.setup($game_temp.player_new_map_id) # loads Events of the new Map if $events[$game_map.map_id] != nil $game_map.events = $events[$game_map.map_id] $game_map.events.values.each {|event| event.refresh} end end #--------------------------------------------------------------------------- # moves + turns player #--------------------------------------------------------------------------- $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y) case $game_temp.player_new_direction when 2 $game_player.turn_down when 4 $game_player.turn_left when 6 $game_player.turn_right when 8 $game_player.turn_up end $game_player.straighten $game_map.update #--------------------------------------------------------------------------- # draws a new minimap only if the map was changed #--------------------------------------------------------------------------- if id @spriteset.dispose @spriteset = Spriteset_Map.new else @spriteset.dispose(false) # false because the minimap mustnt # be disposed (to prevent lag) @spriteset = Spriteset_Map.new(@spriteset.minimap) end if $game_temp.transition_processing $game_temp.transition_processing = false Graphics.transition(20) end $game_map.autoplay Graphics.frame_reset Input.update 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(mimap = nil) @game_party_actors_sprites = [] @minimap_check = false #--------------------------------------------------------------------------- # Loop_Map #--------------------------------------------------------------------------- if $pixelmovement.loop_maps.include?($game_map.map_id) @character_sprites_2 = [[], [], [], [], [], [], [], []] end pixel_spriteset_init() #--------------------------------------------------------------------------- # Minimap #--------------------------------------------------------------------------- @minimap_check = true if $pixelmovement.minimap if mimap == nil @minimap = Spriteset_Minimap.new(self) else @minimap = mimap end @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]) sprite.z -= 1 @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(mimap = true) 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 do |sprites| sprites.each do |sprite| sprite.dispose end end end #--------------------------------------------------------------------------- # Minimap #--------------------------------------------------------------------------- if @minimap != nil if mimap @minimap.dispose end end 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 do |sp_s| sp_s.each do |sp| sp.dispose end end @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 - 16 < 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] != [] for sprite in @character_sprites_2[0] sprite.dispose end @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 - 16 > ($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] != [] for sprite in @character_sprites_2[1] sprite.dispose end @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 < 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] != [] for sprite in @character_sprites_2[2] sprite.dispose end @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 + 32 > ($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] != [] for sprite in @character_sprites_2[3] sprite.dispose end @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 - 16 < 32 * 9 or $game_player.y + 32 < 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] != [] for sprite in @character_sprites_2[4] sprite.dispose end @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 - 16 < 32 * 9 or $game_player.x - 16 > ($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] != [] for sprite in @character_sprites_2[5] sprite.dispose end @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 + 32 > ($game_map.height * 32) - 32 * 7 or $game_player.y + 32 < 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] != [] for sprite in @character_sprites_2[6] sprite.dispose end @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 + 32 > ($game_map.height * 32) - 32 * 7 or $game_player.x - 16 > ($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] != [] for sprite in @character_sprites_2[7] sprite.dispose end @character_sprites_2[7] = [] end return false 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 $game_temp.player_new_y = @parameters[3] * 32 $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, @parameters[3] * 32) 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 #=============================================================================== # RPG::Cache Module #=============================================================================== module RPG module Cache #--------------------------------------------------------------------------- # self.load_bitmap method, prevents errors when no file is found #--------------------------------------------------------------------------- def self.load_bitmap(folder_name, filename, hue = 0) path = folder_name + filename if not @cache.include?(path) or @cache[path].disposed? if filename != '' @cache[path] = Bitmap.new(path) else @cache[path] = Bitmap.new(32, 32) end 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) self.init_table($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) self.init_table($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) self.init_table($pixelmovement.swamp_folder, filename) return @cache[$pixelmovement.swamp_folder + filename] end #--------------------------------------------------------------------------- # new methods for tables, for every bitmap a table can be created which # can contain information for every pixel #--------------------------------------------------------------------------- @tables = {} #--------------------------------------------------------------------------- # creates a table #--------------------------------------------------------------------------- def self.init_table(folder_name, filename) path = folder_name + filename return if (@cache[path] == nil) @tables[@cache[path]] = Table.new(@cache[path].width, @cache[path].height) end #--------------------------------------------------------------------------- # reads a table #--------------------------------------------------------------------------- def self.read_table(bitmap, x, y) return 0 if (@tables[bitmap] == nil) return @tables[bitmap][x, y] end #--------------------------------------------------------------------------- # writes into a table #--------------------------------------------------------------------------- def self.write_table(bitmap, x, y, value) if (@tables[bitmap] == nil) @tables[bitmap] = Table.new(bitmap.width, bitmap.height) end @tables[bitmap][x, y] = value return @tables[bitmap][x, y] end end end #=============================================================================== # Game_Character Class #=============================================================================== class Game_Character attr_accessor :through #----------------------------------------------------------------------------- # Returns true if self reached the target #----------------------------------------------------------------------------- def reached_target? return (@way != nil and @way.length == 0) end #----------------------------------------------------------------------------- # walks Pathfinding route #----------------------------------------------------------------------------- def go_path # returns if self should not walk return if not (@path_steps > 0 and not self.moving? and not self.jumping?) # moves if @way.length > 0 if @move_speed >= 4 ((@path_steps ** (@move_speed.round - 2)) / @path_steps).times do if @way[0] != nil @direction = @way[0] @way.delete_at(0) self.move_forward(@path_steps) end end else @direction = @way[0] @way.delete_at(0) self.move_forward(@path_steps) end # target has been found else @way = nil @path_steps = 0 end end #----------------------------------------------------------------------------- # Path to a Place / Coords #----------------------------------------------------------------------------- def find_path (target_x, target_y, walk = true, fast = false) if $game_map.valid?(target_x, target_y) and $game_map.passable?(target_x, target_y, 0, self) return self.go_to_place(target_x, target_y, walk, fast) end end #----------------------------------------------------------------------------- # Path to an Event #----------------------------------------------------------------------------- def find_event (id, walk = true, fast = false) if id == 0 target = $game_player elsif id > 0 target = $game_map.events[id] end new_through = target.through target.through = true ret = self.go_to_place(target.x, target.y, walk, fast) target.through = new_through Graphics.update return ret end #----------------------------------------------------------------------------- # basic pathfinding method # fast pathfing: simply tries to find a direct way to connect to points # normal pf: tries to find waypoints between two points and connects these # waypoints with fast pf #----------------------------------------------------------------------------- def go_to_place (target_x, target_y, walk = true, fast = false) #--------------------------------------------------------------------------- # these variables should not be changed! #--------------------------------------------------------------------------- steps = 2 # steps for fast pathfinding raster = 32 # raster for normal pathfinding dist = 2 # the higher this value the more waypoints are ignored at # normal pathfinding time_start = Time.new # start time of pathfnding #--------------------------------------------------------------------------- # uses normal pathfinding #--------------------------------------------------------------------------- if not fast # creates waypoints way = self.path_a(target_x, target_y, raster) # deletes every second step, so the movement doesnt look that raster-like j = 0 for i in 1..(way.length - 2) if (i) % dist != 0 way.delete_at(i + j) j -= 1 end end # creates connections between the waypoints @way = [] for i in 0..way.length - 2 @way += self.path_fast(way[i][0], way[i][1], way[i+1][0], way[i+1][1], steps) end #--------------------------------------------------------------------------- # fast pathfinding #--------------------------------------------------------------------------- else @way = self.path_fast(@x, @y, target_x, target_y, steps) end @path_steps = steps if walk #--------------------------------------------------------------------------- # saves Caterpillar Route #--------------------------------------------------------------------------- if self == $game_player $game_map.game_party_actors.each do |actor| if actor.id != 1 way = [] for i in 0..(actor.move_list.length - 2) way += actor.path_fast(actor.move_list[i][0], actor.move_list[i][1], actor.move_list[i + 1][0], actor.move_list[i + 1][1], @path_steps) end actor.way = way + @way.clone actor.path_steps = @path_steps actor.start_time = Graphics.frame_count + (actor.id - 1) * $pixelmovement.cater_distance / $game_player.move_speed - way.length / @path_steps actor.move_list = [] end end end time_end = Time.new # Time when pathfinding has been finished #p time_end - time_start # prints duration of pathfinding return @way end #----------------------------------------------------------------------------- # basic A* Pathfinding # Note: This isnt a simple pathfinding, which finds a way from a to b # it tries to find a way from a to b AND from b to a, until the ways meet # each other in the middle of the way itself. #----------------------------------------------------------------------------- def path_a(target_x, target_y, raster) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- ende = false # path has been completed? coords_s = [] # used coords for the way from a to b coords_z = [] # used coords for the way from b to a target_x_o = target_x # original target x-coord target_y_o = target_y # original target y-coord target_x = target_x / raster * raster # target x-coord is rastered target_y = target_y / raster * raster # target y-coord is rastered x = @x / raster * raster # rastered start x-coord y = @y / raster * raster # rastered start y-coord way_s = [[[x, y]]] # waypoints for the way from a to b way_z = [[[target_x, target_y]]] # waypoints for the way from b to a # double x speed for isometric if $pixelmovement.isometric steps_x = raster * 2 else steps_x = raster end steps_y = raster #--------------------------------------------------------------------------- # searches the way, until its found #--------------------------------------------------------------------------- loop do # start at the start point # for every existing way way_s.each do |way| # tries every direction and adds the new position if useful for d in [2, 4, 6, 8] do new_x = way.last[0] + (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 = way.last[1] + (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) next if coords_s.include?([new_x, new_y]) coords_s += [[new_x, new_y]] next if not self.passable?(way.last[0], way.last[1], d, raster) way_s += [way + [[new_x, new_y]]] ende = true if coords_z.include?([new_x, new_y]) end end # only the newest ways will be used l = way_s.last.length way_s.each do |way| way_s -= [way] if way.length < l end break if ende # start at the target # for every existing way way_z.each do |way| # tries every direction and adds the new position if useful for d in [2, 4, 6, 8] do new_x = way.last[0] + (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 = way.last[1] + (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) next if coords_z.include?([new_x, new_y]) coords_z += [[new_x, new_y]] next if not self.passable?(way.last[0], way.last[1], d, raster) way_z += [way+[[new_x, new_y]]] ende = true if coords_s.include?([new_x, new_y]) end end # only the newest ways will be used l = way_z.last.length way_z.each do |way| way_z -= [way] if way.length < l end break if ende end #--------------------------------------------------------------------------- # puts both ways together #--------------------------------------------------------------------------- way_s.each do |s| way_z.each do |z| if s.include?(z.last) if $pixelmovement.isometric w_s = [[@x / 2 * 2, @y]] + s w_z = [[target_x_o / 2 * 2, target_y_o]] + z else w_s = [[@x, @y]] + s w_z = [[target_x_o, target_y_o]] + z end return w_s - [w_s.last] + w_z.reverse end end end end #----------------------------------------------------------------------------- # fast Pathfinding (see below to get how it works exactly) #----------------------------------------------------------------------------- def path_fast (start_x, start_y, target_x, target_y, steps) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- @coords = [] # waypoint way_old = nil start_x = start_x / steps * steps start_y = start_y / steps * steps target_x = target_x / steps * steps target_y = target_y / steps * steps # creates way if $pixelmovement.isometric target_x = target_x / 2 * 2 @way = Path.new(start_x / 2 * 2, start_y, []) @coords += [[start_x / 2 * 2, start_y]] else @way = Path.new(start_x, start_y, []) @coords += [[start_x, start_y]] end #--------------------------------------------------------------------------- # Loops until target is found #--------------------------------------------------------------------------- counter = 0 loop do # adds a possible way way_old = @way self.add_ways(steps, target_x, target_y) counter += 1 if counter % 128 == 0 Graphics.update # deletes unusable things for i in 1..9 self.delete_unusable(i,10 - i, 8) end end # if no direction is possible anymore, one step back if way_old == @way if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps 1.times do case @way.path.last when 1 @way.x += steps_x @way.y -= steps_y when 2 @way.y -= steps_y when 3 @way.x -= steps_x @way.y -= steps_y when 4 @way.x += steps_x when 6 @way.x -= steps_x when 7 @way.x += steps_x @way.y += steps_y when 8 @way.y += steps_y when 9 @way.x -= steps_x @way.y += steps_y end @way.path.pop end end # If target is found if @coords.include?([target_x, target_y]) or counter == 512 return @way.path 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(steps, 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, steps) elsif self.go_right_down(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end elsif self.go_left_up(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end else self.go_right_up(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end end elsif @way.x < target_x # right/down if self.go_right_down(target_x, target_y, steps) elsif self.go_left_down(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end elsif self.go_right_up(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end else self.go_left_up(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end end else # down if self.go_down(target_x, target_y, steps) elsif self.go_left(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) do end elsif self.go_right(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end else self.go_up(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_up(target_x, target_y, steps) 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, steps) elsif self.go_left_down(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end elsif self.go_right_up(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end else self.go_right_down(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end end elsif @way.x < target_x # right/up if self.go_right_up(target_x, target_y, steps) elsif self.go_left_up(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end elsif self.go_right_down(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end else self.go_left_down(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end end else # up if self.go_up(target_x, target_y, steps) elsif self.go_right(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end elsif self.go_left(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) do end else self.go_down(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end end end elsif @way.x > target_x # left if self.go_left(target_x, target_y, steps) elsif self.go_up(target_x, target_y, steps) while (not self.go_left(target_x, target_y,steps)) and self.go_up(target_x, target_y, steps) do end elsif self.go_down(target_x, target_y, steps) while (not self.go_left(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end else self.go_right(target_x, target_y, steps) while (not self.go_left(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end end elsif @way.x < target_x # right if self.go_right(target_x, target_y, steps) elsif self.go_up(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_up(target_x, target_y, steps) do end elsif self.go_down(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end else self.go_left(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x, @way.y - steps_y, 8, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x, @way.y + steps_y, 2, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x, @way.y - steps_y, 8, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x, @way.y + steps_y, 2, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x, @way.y - steps_y, 8, steps) if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x, @way.y + steps_y, 2, steps) if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) 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, steps) if self.passable?(@way.x, @way.y, d, steps) and not @coords.include?([x, y]) @way = 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 Path attr_accessor :x attr_accessor :y attr_accessor :path def initialize (x, y, path) @x = x @y = y @path = path end end #=============================================================================== # Class for the Caterpillar Characters #=============================================================================== class Game_Party_Actor < Game_Character attr_accessor :sprite attr_accessor :real_x attr_accessor :real_y attr_accessor :move_list attr_accessor :start_time #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- def initialize(id) super() self.moveto($game_player.x, $game_player.y) @through = true @start_time = 0 @id = id @move_list = [] @character_name = $game_party.actors[id - 1].character_name if @id > 1 # sets size if @character_name != '' char_bit = Bitmap.new(name = 'Graphics/Characters/' + @character_name) bla = [char_bit.width / $game_player.frame_number / 4, char_bit.height / $game_player.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 $game_map.valid?(x, y) end #----------------------------------------------------------------------------- # update method #----------------------------------------------------------------------------- def update super @walk_anime = true # move speed is equal to players move speed @move_speed = $game_player.move_speed # first caterpillar is equal to the hero if @id > 1 # Moves if not self.moving? and not self.jumping? and @move_list.length > 0 and @start_time <= Graphics.frame_count if @move_list[0][2] != nil if @move_list[0][2] == 'sl' self.find_path (@move_list[0][0], @move_list[0][1], true, true) @walk_anime = false else self.jump(@move_list[0][0] - @x, @move_list[0][1] - @y, @move_list[0][2] / 2) end elsif @move_list[0][0] != @x or @move_list[0][1] != @y self.find_path (@move_list[0][0],@move_list[0][1], true, true) end @move_list.delete_at(0) end #stops if (@move_list == [] and $game_player.path_steps == 0) @start_time = Graphics.frame_count + (@id - 1) * $pixelmovement.cater_distance / @move_speed end else @x = $game_player.x @y = $game_player.y end end alias pixel_cater_go_path go_path if not $pixelmovement.pixel_aliasing def go_path if @start_time > Graphics.frame_count or (not $game_player.last_moving and @start_time != 0 and @start_time != (@id - 1) * $pixelmovement.cater_distance / @move_speed and not $pixelmovement.cater_overlap) return end pixel_cater_go_path 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) #--------------------------------------------------------------------------- # sets Corner + creates viewport #--------------------------------------------------------------------------- case $pixelmovement.minimap_pos when 1 #1 = upper left corner @viewport = Viewport.new(0, 0, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 2 #2 = upper right @viewport = Viewport.new(640 - $pixelmovement.minimap_width, 0, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 3 #3 = lower left @viewport = Viewport.new(0, 480 - $pixelmovement.minimap_height, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 4 #4 = lower right @viewport = Viewport.new(640 - $pixelmovement.minimap_width, 480 - $pixelmovement.minimap_height, $pixelmovement.minimap_width, $pixelmovement.minimap_height) end #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- @minimap_collision = $pixelmovement.minimap_collision @viewport.z = 500 @map = RPG::Sprite.new(@viewport) @map.z = 2500 @cursor = RPG::Sprite.new(@viewport) @cursor.z = 2520 @rahmen = RPG::Sprite.new(@viewport) @rahmen.z = 2530 tiles = [] width = [$pixelmovement.minimap_width, ($game_map.width * 32) / $pixelmovement.minimap_scale].min height = [$pixelmovement.minimap_height, ($game_map.height * 32) / $pixelmovement.minimap_scale].min @rahmen.bitmap = Bitmap.new(width, height) @rahmen.x = 0 @rahmen.y = 0 @cursor_zoom = ($pixelmovement.minimap_scale + 1) / 2 # draws border for x in 0..(@rahmen.bitmap.width - 1) @rahmen.bitmap.set_pixel(x, 0, Color.new(0, 0, 0)) @rahmen.bitmap.set_pixel(x, @rahmen.bitmap.height - 1, Color.new(0, 0, 0)) end for y in 0..(@rahmen.bitmap.height - 1) @rahmen.bitmap.set_pixel(0, y, Color.new(0, 0, 0)) @rahmen.bitmap.set_pixel(@rahmen.bitmap.width - 1, y, Color.new(0, 0, 0)) end if @minimap != nil @map.bitmap = @minimap # Collsion Minimap from Map? elsif @minimap_collision @map.bitmap = RPG::Cache.collision_map($game_map.map_id.to_s) end #--------------------------------------------------------------------------- # creates minimap? #--------------------------------------------------------------------------- # Collision Minimap from Map! if @map.bitmap != nil bit = Bitmap.new(@map.bitmap.width / $pixelmovement.minimap_scale, @map.bitmap.height / $pixelmovement.minimap_scale) bit.stretch_blt(bit.rect, @map.bitmap, @map.bitmap.rect) @map.bitmap = bit # Else else @map.bitmap = Bitmap.new(($game_map.width * 32) / $pixelmovement.minimap_scale, ($game_map.height * 32) / $pixelmovement.minimap_scale) #Collision Minimap from Tileset? if @minimap_collision 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 #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 for y in 0..$game_map.height for layer in 0..2 pos = $game_map.data[x, y, layer] pos = 0 if pos == nil if pos >= 384 pos -= 384 sy = (pos / 8) * 32 sx = (pos % 8) * 32 src_rect = Rect.new(sx, sy, 32, 32) dest_rect = Rect.new(x * 32 / $pixelmovement.minimap_scale, y * 32/ $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale) if (not @minimap_collision) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) != Color.new(0, 0, 0) and $game_map.priorities[$game_map.data[x, y, layer]] == 0) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) == Color.new(0, 0, 0) and layer == 1 and $game_map.data[x, y, layer] != 0 and $game_map.priorities[$game_map.data[x, y, layer]] == 0) @map.bitmap.stretch_blt(dest_rect, tiles[0], src_rect) end elsif pos >= 48 nr = pos / 48 pos = pos % 48 sy = (pos / 8) * 32 sx = (pos % 8) * 32 src_rect = Rect.new(sx, sy, 32, 32) dest_rect = Rect.new(x * 32 / $pixelmovement.minimap_scale, y * 32/ $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale) if (not @minimap_collision) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) != Color.new(0, 0, 0, 255) and $game_map.priorities[$game_map.data[x, y, layer]] == 0) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) == Color.new(0, 0, 0, 255) and layer == 1 and $game_map.data[x, y, layer] != 0 and $game_map.priorities[$game_map.data[x, y, layer]] == 0) @map.bitmap.stretch_blt(dest_rect, tiles[nr], src_rect) end end end end end end #--------------------------------------------------------------------------- # colours, etc. #--------------------------------------------------------------------------- @map.opacity = 0 @rahmen.opacity = 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 0..@map.bitmap.width for y in 0..@map.bitmap.height 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 self.set_chars(set) #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 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 end #----------------------------------------------------------------------------- # creates characters on minimap #----------------------------------------------------------------------------- def set_chars(set) #disposes chars, if they already exist @chars.each {|cha| cha.dispose} if @chars != nil @chars = [] # no chars on collision minimap return if @minimap_collision # draw Chars set.character_sprites.each do |char| #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(0,0,char.src_rect.width / $pixelmovement.minimap_scale * @cursor_zoom, char.src_rect.height / $pixelmovement.minimap_scale * @cursor_zoom) #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(0, 0, 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 do |char| char.dispose end @rahmen.dispose end #----------------------------------------------------------------------------- # updates minimap #----------------------------------------------------------------------------- def update #--------------------------------------------------------------------------- # 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 #--------------------------------------------------------------------------- # Map update #--------------------------------------------------------------------------- # horizontal movement of the minimap # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @map.x = 0 else @map.x = - $game_map.display_x / 4 / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width @map.x -= (304 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2)) / $pixelmovement.minimap_scale if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @map.x = 0 elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @map.x = - @map.bitmap.width + $pixelmovement.minimap_width end end end #vertical movement of the minimap # Map is smaller than Minimap if @map.bitmap.height <= $pixelmovement.minimap_height @map.y = 0 else @map.y = - $game_map.display_y / 4 / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height @map.y -= (224 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2))/ $pixelmovement.minimap_scale if $game_player.y <= 480 * ($pixelmovement.minimap_scale/ (480.0 / $pixelmovement.minimap_height) / 2) @map.y = 0 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @map.y = - @map.bitmap.height + $pixelmovement.minimap_height end end end # looped map if $pixelmovement.loop_maps.include?($game_map.map_id) @map.x -= @map.bitmap.width / 3 @map.y -= @map.bitmap.height / 3 end #--------------------------------------------------------------------------- # Cursor Update #--------------------------------------------------------------------------- # returns if no chararacter sprites are drawn on the map return if $scene.spriteset.character_sprites.last.disposed? # 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 # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @cursor.x = ($game_player.x + 16) / $pixelmovement.minimap_scale else @cursor.x = $game_player.screen_x/ (640 / $pixelmovement.minimap_width) unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @cursor.x = $game_player.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width)) elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @cursor.x = $pixelmovement.minimap_width - (@map.bitmap.width - $game_player.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width))) end end end #vertical # Map is smaller than minimap if @map.bitmap.height <= $pixelmovement.minimap_height @cursor.y = ($game_player.y + 32) / $pixelmovement.minimap_scale else @cursor.y = $game_player.screen_y / (480 / $pixelmovement.minimap_height) unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height if $game_player.y <= 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @cursor.y = $game_player.y / (480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height)) + @cursor.src_rect.height / 2 + 4 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale/ (480.0 / $pixelmovement.minimap_height) / 2) @cursor.y = $pixelmovement.minimap_height - (@map.bitmap.height - $game_player.y/(480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height))) + 6 end end 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 #--------------------------------------------------------------------------- # Chars are Updated #--------------------------------------------------------------------------- for i in 0..(@chars.length - 1) # sprite isnt update if character isnt on the screen next if not $scene.spriteset.character_sprites[i].character.in_range? # updates sprite @chars[i].src_rect.set($scene.spriteset.character_sprites[i].src_rect.x / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.y / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.width / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.height / $pixelmovement.minimap_scale) char = $scene.spriteset.character_sprites[i] if char == nil next else char = char.character end # horizontal # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @chars[i].x = (char.x + 16) / $pixelmovement.minimap_scale else @chars[i].x = char.screen_x / $pixelmovement.minimap_scale unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width @chars[i].x -= (304 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2))/ $pixelmovement.minimap_scale if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @chars[i].x = char.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width)) + @chars[i].src_rect.width / 2 elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale/ (640.0 / $pixelmovement.minimap_width) / 2) @chars[i].x = $pixelmovement.minimap_width - (@map.bitmap.width - char.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width))) + @chars[i].src_rect.width / 2 end end end # vertical # Map is smaller than minimap if @map.bitmap.height <= $pixelmovement.minimap_height @chars[i].y = (char.y + 32) / $pixelmovement.minimap_scale else @chars[i].y = char.screen_y / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height @chars[i].y -= (224 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2)) / $pixelmovement.minimap_scale if $game_player.y <= 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @chars[i].y = char.y/(480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height)) + @chars[i].src_rect.height - 4 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @chars[i].y = $pixelmovement.minimap_height - (@map.bitmap.height - char.y/ (480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height))) + @chars[i].src_rect.height - 4 end end 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 @chars[i].opacity = $pixelmovement.minimap_opacity end @map.opacity = $pixelmovement.minimap_opacity @rahmen.opacity = $pixelmovement.minimap_opacity @cursor.opacity = $pixelmovement.minimap_opacity 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 the directions (4/8): $pixelmovement.direction_number = 4 # Order+ Numbers of the directions: $pixelmovement.direction_array = [] # Number of Frames for the Player Sprite: $pixelmovement.player_frame_number = nil # Number of Directions for the Player Sprite: $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 #------------------------------------------------------------------------------- # Distance in Px: $pixelmovement.cater_distance = 32 # Switch for the Caterpillar Script: $pixelmovement.switch_caterpillar(true) # Switch for Caterpillar Overlapping: $pixelmovement.switch_cater_overlap(false) #------------------------------------------------------------------------------- # Size of Player Event: $pixelmovement.player_size = [12, 8] # Correction of the Event Sizes: $pixelmovement.event_size_add = 0 #------------------------------------------------------------------------------- # 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 # Scale: $pixelmovement.minimap_scale = 4.0 # Minimap Opacity: $pixelmovement.minimap_opacity = 0 # 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(true) # 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(false) #------------------------------------------------------------------------------- # dont change this, its used to prevent that methods are aliased more than once $pixelmovement.pixel_aliasing = true end #------------------------------------------------------------------------------- # End SDK Enabled Test #-------------------------------------------------------------------------------[/spoiler]
  5. I did that, but it says Script 'Pixelmovement Script v 1.3' line 3837: SyntaxError occurred which is
  6. vvvv The Pixel+caterpillar script vvvv [spoiler]#=============================================================================== # ** Pixelmovement Script #------------------------------------------------------------------------------- # # f0tz!baerchen # v1.3 # 10.12.2006 # #------------------------------------------------------------------------------- # # Credits: # arevulopapo (turn toward/away player methods, # stay_in_range method, distance method) # Caesar (fill_circle method) # Fanha Giang (Autotile handling) # Caldaron (move_toward_player method) # #------------------------------------------------------------------------------- # # Importance: # This script already uses an own (optimized) Anti-Lag-Script and has many more # features than only Pixelmovement. Information for the options can be found at # the end of the script. Sometimes you have to add a comment in an event # to activate special features for this event. Except for the Anti-Lag the # comment can be anywhere at the beginning of the first event's page. The Script # checks every line for such comments until it finds a non comment line. # #------------------------------------------------------------------------------- # # 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) # # #=============================================================================== #------------------------------------------------------------------------------- # * SDK Log Script #------------------------------------------------------------------------------- SDK.log('Pixelmovement', 'f0tz!baerchen', 1.3, '29.10.06') #------------------------------------------------------------------------------- # Begin SDK Enabled Check #------------------------------------------------------------------------------- if SDK.state('Pixelmovement') == true #=============================================================================== # 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_accessor :frame_number attr_accessor :frame_array attr_accessor :stand_frame attr_accessor :stand_array attr_accessor :direction_number attr_accessor :direction_array attr_reader :isometric attr_reader :cater_activate attr_accessor :cater_distance attr_reader :cater_overlap attr_accessor :player_size attr_accessor :player_frame_number attr_accessor :player_direction_number attr_accessor :player_stand_frame 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_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 #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- def initialize(aliasing = false) @pixel_aliasing = aliasing # aliased methods are only aliased once end #----------------------------------------------------------------------------- # methods to prevent errors with boolean settings #----------------------------------------------------------------------------- def switch_caterpillar(value = nil) if value == nil @cater_activate = !@cater_activate else @cater_activate = value end return end #----------------------------------------------------------------------------- # switch for isometric function #----------------------------------------------------------------------------- def switch_isometric(value = nil) if value == nil @isometric = !@isometric else @isometric = value end if @cater_activate and $game_map != nil for actor in $game_map.game_party_actors actor.way = [] actor.path_steps = 0 actor.move_list = [] actor.moveto($game_player.x, $game_player.y) end end return end #----------------------------------------------------------------------------- # switch for caterpillar overlapping #----------------------------------------------------------------------------- def switch_cater_overlap(value = nil) if value == nil @cater_overlap = !@cater_overlap else @cater_overlap = value end return end #----------------------------------------------------------------------------- # switch for direction fix while sprinting #----------------------------------------------------------------------------- def switch_sprint_fix(value = nil) if value == nil @sprint_fix = !@sprint_fix else @sprint_fix = value end return end #----------------------------------------------------------------------------- # switch for the minimap #----------------------------------------------------------------------------- def switch_minimap(value = nil) if value == nil @minimap = !@minimap else @minimap = value end return end #----------------------------------------------------------------------------- # switch for the minimap character sprites #----------------------------------------------------------------------------- def switch_minimap_sprites(value = nil) if value == nil @minimap_sprites = !@minimap_sprites else @minimap_sprites = value end return end #----------------------------------------------------------------------------- # switch for the collision minimap #----------------------------------------------------------------------------- def switch_minimap_collision(value = nil) if value == nil @minimap_collision = !@minimap_collision else @minimap_collision = value end return end #----------------------------------------------------------------------------- # switch for hero sliding #----------------------------------------------------------------------------- def switch_sliding(value = nil) if value == nil @sliding = !@sliding else @sliding = value end return end #----------------------------------------------------------------------------- # switch for special panorama scrolling #----------------------------------------------------------------------------- def switch_panorama_scrolling(value = nil) if value == nil @panorama_scrolling = !@panorama_scrolling else @panorama_scrolling = value end return end end #------------------------------------------------------------------------------- # creates the setting object (depending on if the game has just been # started or restarted) #------------------------------------------------------------------------------- if $pixelmovement == nil $pixelmovement = Pixelmovement_Settings.new else $pixelmovement = Pixelmovement_Settings.new(true) end #=============================================================================== # 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 :char_graphic_changing # saves chars which changed their graphic 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_reader :jump_events # for jump events attr_reader :ice_events # for sliding events #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- alias pixel_initialize initialize if not $pixelmovement.pixel_aliasing def initialize pixel_initialize @char_graphic_changing = [] # contains characters which graphics changed end #----------------------------------------------------------------------------- # map setup #----------------------------------------------------------------------------- alias pixel_set setup if not $pixelmovement.pixel_aliasing def setup(map_id) pixel_set(map_id) #--------------------------------------------------------------------------- # Caterpillar System #--------------------------------------------------------------------------- @game_party_actors = [] if $pixelmovement.cater_activate for i in 1..$game_party.actors.length @game_party_actors += [Game_Party_Actor.new(i)] end end #--------------------------------------------------------------------------- # checks if Pixel Setting is activated, adds every event consisting a # "jump/ice-comment" to an array or for special frame rates, etc.. #--------------------------------------------------------------------------- @jump_events = {} @ice_events = {} for event in @events.values i = 0 list = event.event.pages[0] while list.list[i].code == 108 or list.list[i].code == 408 if list.list[i].parameters[0].downcase.include?('teleport:') bla = list.list[i].parameters[0].split(/:/)[1].split(/,/) event.moveto(bla[0].to_i,bla[1].to_i) elsif list.list[i].parameters[0].downcase.include?('jump:') @jump_events[event.id] = event elsif list.list[i].parameters[0].downcase.include?('ice:') @ice_events[event.id] = event elsif list.list[i].parameters[0].downcase.include?('frames:') event.frame_number = list.list[i].parameters[0].split(/:/)[1].to_i elsif list.list[i].parameters[0].downcase.include?('stand frame:') event.stand_frame = list.list[i].parameters[0].split(/:/)[1].to_i elsif list.list[i].parameters[0].downcase.include?('directions:') event.direction_number = list.list[i].parameters[0].split(/:/)[1].to_i end i += 1 end end #--------------------------------------------------------------------------- # frame rate etc. for Player #--------------------------------------------------------------------------- if $pixelmovement.player_frame_number != nil $game_player.frame_number = $pixelmovement.player_frame_number else $game_player.frame_number = $pixelmovement.frame_number end if $pixelmovement.player_direction_number != nil $game_player.direction_number = $pixelmovement.player_direction_number else $game_player.direction_number = $pixelmovement.direction_number end if $pixelmovement.player_stand_frame != nil $game_player.stand_frame = $pixelmovement.player_stand_frame else $game_player.stand_frame = $pixelmovement.stand_frame 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 += [@map_id] end #--------------------------------------------------------------------------- # see below #--------------------------------------------------------------------------- self.init_bitmaps self.event_sizes end #----------------------------------------------------------------------------- # reads passability map (first tries from a map, then from a tileset, # or nothing) #----------------------------------------------------------------------------- def init_bitmaps @collision_map = nil @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 = nil 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 Event-Sizes #--------------------------------------------------------------------------- def event_sizes @char_bits = [] @char_names = [] #--------------------------------------------------------------------------- # Hero #--------------------------------------------------------------------------- if $game_party.actors != [] and $game_party.actors[0].character_name != '' if $pixelmovement.player_size != [] # if Player-Size is set manually $game_player.size['x'] = $pixelmovement.player_size[0] $game_player.size['y'] = $pixelmovement.player_size[1] else # else: from graphic name='Graphics/Characters/' + $game_party.actors[0].character_name @char_bits[0] = Bitmap.new(name) bla = [@char_bits[0].width/$game_player.frame_number/4, @char_bits[0].height/$game_player.direction_number/4].max + $pixelmovement.event_size_add $game_player.size['x'] = bla $game_player.size['y'] = bla end end @char_names[0] = $game_party.actors[0].character_name #--------------------------------------------------------------------------- #Events #--------------------------------------------------------------------------- if @events.keys.length > 0 @events.keys.each do |id| # uses graphic if @events[id].character_name != '' @char_bits[id] = Bitmap.new(name = 'Graphics/Characters/' + @events[id].character_name) bla = [@char_bits[id].width/@events[id].frame_number/4, @char_bits[id].height/@events[id].direction_number/4].max + $pixelmovement.event_size_add @events[id].size['x'] = bla @events[id].size['y'] = bla end # checks if a comment is in the first lines i = 0 list = @events[id].event.pages[0] while list.list[i].code == 108 or list.list[i].code == 408 if list.list[i].parameters[0].downcase.include?('event_size:') bla = list.list[i].parameters[0].split(/:/)[1] if not bla.include?(',') @events[id].size['x'] = bla.to_i @events[id].size['y'] = bla.to_i else bla = bla.split(/,/) @events[id].size['x'] = bla[0].to_i @events[id].size['y'] = bla[1].to_i end break end i += 1 end @char_names[id] = @events[id].character_name end end @char_bits = [] 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 #----------------------------------------------------------------------------- alias pixel_encounter_step encounter_step if not $pixelmovement.pixel_aliasing def encounter_step return pixel_encounter_step * 32 end #----------------------------------------------------------------------------- # Scroll Down, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_down scroll_down if not $pixelmovement.pixel_aliasing def scroll_down(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_y = @display_y + distance.round else pixel_scr_down(distance.round) end end #----------------------------------------------------------------------------- # Scroll Left, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_left scroll_left if not $pixelmovement.pixel_aliasing def scroll_left(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_x = @display_x - distance.round else pixel_scr_left(distance.round) end end #----------------------------------------------------------------------------- # Scroll Right, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_right scroll_right if not $pixelmovement.pixel_aliasing def scroll_right(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_x = @display_x + distance.round else pixel_scr_right(distance.round) end end #----------------------------------------------------------------------------- # Scroll Up, edited for Looping Maps #----------------------------------------------------------------------------- alias pixel_scr_up scroll_up if not $pixelmovement.pixel_aliasing def scroll_up(distance) if $pixelmovement.loop_maps.include?(@map_id) @display_y = @display_y - distance.round else pixel_scr_up(distance.round) end end #----------------------------------------------------------------------------- # valid? method, uses real map-size now (*32) #----------------------------------------------------------------------------- alias pixel_valid? valid? if not $pixelmovement.pixel_aliasing def valid?(x, y) return (pixel_valid?(x / 32 + 1,(y + 30) / 32) or $pixelmovement.loop_maps.include?(@map_id)) end #----------------------------------------------------------------------------- # Passable? method # has been rebuilt for both collision maps and databse passability #----------------------------------------------------------------------------- def passable?(x, y, d, self_event = nil) # returns if coords are not on the map return false if not valid?(x, y) # return true if self_event is a Caterpillar return true if self_event.is_a?(Game_Party_Actor) # changes d if neccessary if d == 1 or d == 3 or d == 0 d = 2 elsif d == 7 or d == 9 d = 8 end #--------------------------------------------------------------------------- # collision map exists? #--------------------------------------------------------------------------- if @pass_type == 'Map' or @pass_type == 'Tileset' return pixel_passable?(x, y, d, self_event, @pass_type) #--------------------------------------------------------------------------- # without Collision Map, database passability is used #--------------------------------------------------------------------------- else #------------------------------------------------------------------------- # creates rectangle which has to be checked #------------------------------------------------------------------------- if self_event == nil x_size = y_size = 0 else x_size = self_event.size['x'] y_size = self_event.size['y'] end x = x + 16 y = y + 30 case d when 2 x = (x - x_size / 2)..(x + x_size / 2) y = [y] when 4 x = [x - x_size / 2] y = (y - y_size)..y when 6 x = [x + x_size / 2] y = (y - y_size)..y when 8 x = (x - x_size / 2)..(x + x_size / 2) y = [y - y_size] end #------------------------------------------------------------------------- # checks this rectangle if it is passable #------------------------------------------------------------------------- bit = (1 << (d / 2 - 1)) & 0x0f bit_i = (1 << ((10 - d) / 2 - 1)) & 0x0f for x_i in x for y_i in y for i in [2, 1, 0] tile_id = data[x_i / 32, y_i / 32, i] #------------------------------------------------------------------- # impassable #------------------------------------------------------------------- if tile_id == nil or # impassable @passages[tile_id] & 0x0f == 0x0f or # If you can move on the tile but not over the tile to another one (@passages[tile_id] & bit != 0 and # needed for a small border (((x_i - 8) % 32 == 0 and bit == 2) or # Face Left ((x_i + 8) % 32 == 0 and bit == 4) or # Face Right ((y_i + 8) % 32 == 0 and bit == 1) or # Face Down ((y_i - 8) % 32 == 0 and bit == 8))) # Face Up return false #------------------------------------------------------------------- # only one direction is passable #------------------------------------------------------------------- elsif [7, 11, 14, 13].include?(@passages[tile_id]) # Tile next to the obstacle (maybe more Tiles have to be set, # e.g. if an obstacle is both on the left and on the right side) x_t = 0 x_t2 = 0 y_t = 0 y_t2 = 0 x_t -= 24 if [7, 13, 14].include?(@passages[tile_id]) # RIGHT if x_t == 0 x_t += 24 if [7, 11, 14].include?(@passages[tile_id]) #LEFT else x_t2 += 24 if [7, 11, 14].include?(@passages[tile_id]) end y_t -= 24 if [7, 11, 13].include?(@passages[tile_id]) # DOWN if y_t == 0 y_t += 24 if [11, 13, 14].include?(@passages[tile_id]) # UP else y_t2 += 24 if [11, 13, 14].include?(@passages[tile_id]) end tile_id_1 = data[(x_i + x_t) / 32, y_i / 32, i] if x_t != 0 tile_id_2 = data[x_i / 32, (y_i + y_t) / 32, i] if y_t != 0 tile_id_3 = data[(x_i + x_t2) / 32, y_i / 32, i] if x_t2 != 0 tile_id_4 = data[x_i / 32, (y_i + y_t2) / 32, i] if y_t2 != 0 # If obstacle is set, and you cannot move on the tile if @passages[tile_id] >= bit_i and ((tile_id_1 != nil and @passages[tile_id_1] != 0) or (tile_id_2 != nil and @passages[tile_id_2] != 0) or (tile_id_3 != nil and @passages[tile_id_3] != 0) or (tile_id_4 != nil and @passages[tile_id_4] != 0)) return false end #------------------------------------------------------------------- # more than one direction is passable #------------------------------------------------------------------- else # Tile next to the obstacle (maybe more Tiles have to be set, # e.g. if an obstacle is both on the left and on the right side) x_t = 0 x_t2 = 0 y_t = 0 y_t2 = 0 x_t -= 24 if [4, 5, 6, 12].include?(@passages[tile_id]) # RIGHT if x_t == 0 x_t += 24 if [2, 3, 6, 10].include?(@passages[tile_id]) #LEFT else x_t2 += 24 if [2, 3, 6, 10].include?(@passages[tile_id]) end y_t -= 24 if [1, 3, 5, 9].include?(@passages[tile_id]) # DOWN if y_t == 0 y_t += 24 if [8, 9, 10, 12].include?(@passages[tile_id]) # UP else y_t2 += 24 if [8, 9, 10, 12].include?(@passages[tile_id]) end if x_t != 0 or y_t != 0 tile_id_1 = data[(x_i + x_t) / 32, (y_i + y_t) / 32, i] end if x_t2 != 0 or y_t2 != 0 tile_id_2 = data[(x_i + x_t2) / 32, (y_i + y_t2) / 32, i] end # If obstacle is set, and you cannot move on the tile if @passages[tile_id] >= bit_i and ((tile_id_1 != nil and @passages[tile_id_1] != 0) or (tile_id_2 != nil and @passages[tile_id_2] != 0)) return false end end end end end end return true end #----------------------------------------------------------------------------- # checks if passable, initialises pixel to be checked #----------------------------------------------------------------------------- def pixel_passable?(x, y, d, event, type) if event == nil x_size = y_size = 2 else x_size = event.size['x'] y_size = event.size['y'] end x_size = 2 if x_size < 2 y_size = 2 if y_size < 2 x = x + 16 y = y + 30 counter = 0 #--------------------------------------------------------------------------- # checks pixel on collision map #--------------------------------------------------------------------------- case d when 2 for i in (x - x_size / 2)..(x + x_size / 2) if i % 2 == 0 and ((type == 'Map' and self.pass_map(i, y)) or ( type == 'Tileset' and self.pass_tileset(i, y))) counter += 1 end end return true if counter >= ((x + x_size / 2) - (x - x_size / 2)) / 2 when 4 for i in (y - y_size)..(y) if i % 2 == 0 and ((type == 'Map' and self.pass_map(x - x_size / 2, i)) or (type == 'Tileset' and self.pass_tileset(x - x_size / 2, i))) counter += 1 end end return true if counter >= ((y) - (y - y_size)) / 2 when 6 for i in (y - y_size)..(y) if i % 2 == 0 and ((type == 'Map' and self.pass_map(x + x_size / 2, i)) or ( type == 'Tileset' and self.pass_tileset(x + x_size / 2, i))) counter += 1 end end return true if counter >= ((y) - (y - y_size)) / 2 when 8 for i in (x - x_size / 2)..(x + x_size / 2) if i % 2 == 0 and ((type == 'Map' and self.pass_map(i, y - y_size)) or ( type == 'Tileset' and self.pass_tileset(i, y - y_size))) counter += 1 end end return true if counter >= ((x + x_size / 2) - (x - x_size / 2)) / 2 end return false end #----------------------------------------------------------------------------- # Checks passability if a Tileset Collision-Map is used #----------------------------------------------------------------------------- def pass_tileset(x, y) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # on looped maps: coords are changed eventually if $pixelmovement.loop_maps.include?($game_map.map_id) if x >= ($game_map.width * 32) x -= ($game_map.width * 32) elsif x < 0 x += ($game_map.width * 32) end if y >= ($game_map.height * 32) y -= ($game_map.height * 32) elsif y < 0 y += ($game_map.height * 32) end end layer = 0 # current layer passed = [] # saves which layers are passable empty = 0 # saves which layers do not contain a tile on this position type = 0 # saves which autotile set has to be saved (or normal tileset) x_s = x # sabes original x coord y_s = y # sabes original y coord #--------------------------------------------------------------------------- # checks every layer #--------------------------------------------------------------------------- while layer <= 2 pruefe = true x = x_s y = y_s pos = self.data[x / 32, y / 32, layer] pos = 0 if pos == nil #------------------------------------------------------------------------- # calculates position on collision map #------------------------------------------------------------------------- if pos >= 384 pos -= 384 sy = (pos / 8) * 32 sx = (pos % 8) * 32 x = sx + x % 32 y = sy + y % 32 type = 0 elsif pos >= 48 type = pos / 48 pos = pos % 48 sy = (pos / 8) * 32 sx = (pos % 8)* 32 x = sx + x % 32 y = sy + y % 32 else passed[layer] = 1 empty += 1 pruefe = false end #------------------------------------------------------------------------- # checks collision map and saves result into the collision table / checks # collision table (to check a table is faster!) #------------------------------------------------------------------------- if pruefe table = RPG::Cache.read_table(@collision_map[type], x, y) if table == 2 passed[layer] = 1 elsif table == 1 passed[layer] = 0 else if @collision_map[type].get_pixel(x, y) != Color.new(0, 0, 0) passed[layer] = 1 RPG::Cache.write_table(@collision_map[type], x, y, 2) else passed[layer] = 0 RPG::Cache.write_table(@collision_map[type], x, y, 1) end end end layer += 1 end #--------------------------------------------------------------------------- # 'Bridges' or free space = true #--------------------------------------------------------------------------- return ((passed[0] == 1 and passed[1] == 1 and passed[2] == 1) or (passed[0] == 0 and passed[1] == 1 and passed[2] == 1 and ((data[x_s / 32, y_s / 32, 1] != 0 and @priorities[data[x_s / 32, y_s / 32, 1]] == 0) or (data[x_s / 32, y_s / 32, 2] != 0 and @priorities[data[x_s / 32, y_s / 32, 2]] == 0)) and empty < 2)) end #----------------------------------------------------------------------------- # Checks passability if a Map Collision-Map is used #----------------------------------------------------------------------------- def pass_map(x, y) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # on looped maps: coords are changed eventually if $pixelmovement.loop_maps.include?($game_map.map_id) if x >= ($game_map.width * 32) x -= ($game_map.width * 32) elsif x < 0 x += ($game_map.width * 32) end if y >= ($game_map.height * 32) y -= ($game_map.height * 32) elsif y < 0 y += ($game_map.height * 32) end end #--------------------------------------------------------------------------- # checks collision map and saves result into the collision table / checks # collision table (to check a table is faster!) #--------------------------------------------------------------------------- table = RPG::Cache.read_table(@collision_map, x, y) if table == 2 return true elsif table == 1 return false else if @collision_map.get_pixel(x, y) != Color.new(0, 0, 0) RPG::Cache.write_table(@collision_map, x, y, 2) return true else RPG::Cache.write_table(@collision_map, x, y, 1) return false end end end #----------------------------------------------------------------------------- # bush? method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_bush? bush? if not $pixelmovement.pixel_aliasing def bush?(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_bush?(x, y) end #----------------------------------------------------------------------------- # counter? method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_counter? counter? if not $pixelmovement.pixel_aliasing def counter?(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_counter?(x, y) end #----------------------------------------------------------------------------- # terrain method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_terrain terrain_tag if not $pixelmovement.pixel_aliasing def terrain_tag(x, y) x = (x + 16) / 32 y = (y - 8) / 32 + 1 pixel_terrain(x, y) end #----------------------------------------------------------------------------- # returns the id on the position x,y #----------------------------------------------------------------------------- def tile_id(x, y, i = 0) x = (x + 16) / 32 y = (y - 8) / 32 + 1 return data[x, y, i] end #----------------------------------------------------------------------------- # check_event method, converts Px Coords to Tile Coords #----------------------------------------------------------------------------- alias pixel_check_event check_event if not $pixelmovement.pixel_aliasing def check_event(x, y) return pixel_check_event(x, y) if pixel_check_event != nil for event in $game_map.events.values if event.in_rect?(x, y, 32, 32) return event.id end end end #----------------------------------------------------------------------------- # map update #----------------------------------------------------------------------------- alias pixel_map_up update if not $pixelmovement.pixel_aliasing def update #--------------------------------------------------------------------------- # if an event changes its graphic the size will be calculated again #--------------------------------------------------------------------------- if @char_graphic_changing != [] if $scene.is_a?(Scene_Map) and $scene.spriteset != nil and $scene.spriteset.minimap != nil $scene.spriteset.minimap.set_chars($scene.spriteset) end do_it = 0 @events.keys.each do |id| if @char_graphic_changing.include?(id) and not @events[id].in_rect?($game_player.x, $game_player.y + @events[id].size['y'] / 2 - $game_player.size['y'] / 2, [$game_player.size['x'], @events[id].size['x']].max * 2, [$game_player.size['y'], @events[id].size['y']].max * 2) do_it += 1 end end if do_it == @char_graphic_changing.length self.event_sizes @char_graphic_changing = [] end else @events.keys.each do |id| if @events[id].character_name != @char_names[id] @char_graphic_changing += [id] end end if $game_player.character_name != @char_names[0] @char_graphic_changing += [0] end end #--------------------------------------------------------------------------- # normal update #--------------------------------------------------------------------------- pixel_map_up #--------------------------------------------------------------------------- # updates Caterpillars (and (de)activates them, if neccessary) #--------------------------------------------------------------------------- if @game_party_actors != [] @game_party_actors.each do |actor| actor.update end if not $pixelmovement.cater_activate for sprite in $scene.spriteset.game_party_actors_sprites sprite.dispose end $scene.spriteset.game_party_actors_sprites = [] @game_party_actors = [] end elsif $pixelmovement.cater_activate @game_party_actors = [] for i in 1..$game_party.actors.length @game_party_actors += [Game_Party_Actor.new(i)] end for i in 0..@game_party_actors.length - 1 sprite = Sprite_Character.new($scene.spriteset.viewport1, @game_party_actors[i]) $scene.spriteset.game_party_actors_sprites.push(sprite) end end end end #=============================================================================== # Game_Character Class #=============================================================================== class Game_Character attr_accessor :x attr_accessor :y attr_accessor :stop_count attr_accessor :direction attr_accessor :trigger_on attr_accessor :event attr_accessor :move_speed attr_accessor :opacity attr_accessor :walk_anime attr_accessor :size attr_accessor :step_anime attr_accessor :z attr_accessor :last_moving attr_accessor :way attr_accessor :path_steps attr_accessor :speed_factor attr_accessor :frame_number attr_accessor :direction_number attr_accessor :stand_frame #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- alias pixel_cha_init initialize if not $pixelmovement.pixel_aliasing def initialize pixel_cha_init @last_moving = false # saves if Character was moving at the last update @move_speed = @move_speed * 1.0 @walk = false # used to prevent sliding when the event starts walking @path_steps = 0 # saves step-size after pathfinding @trigger_on = 0 # used to prevent multi-event-activation @way = nil # saved Path found with pathfinding @speed_factor = 1.0 # for height/swamp maps @z = 0 # z-coordinate @size = { # Event-Size 'x' => 32, 'y' => 32 } @frame_number = $pixelmovement.frame_number @direction_number = $pixelmovement.direction_number @stand_frame = $pixelmovement.stand_frame 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) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- # for Isometric script if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end 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) return true if @through # help variables help_x = new_x help_y = new_y counter = 0 #--------------------------------------------------------------------------- # checks the way to the new position if it is passable #--------------------------------------------------------------------------- case d when 1 y+=1 x-=1 while (help_y >= y) and (help_x <= x) and ($game_map.passable?(help_x,help_y, 2, self)) and ($game_map.passable?(help_x,help_y, 4, self)) counter += 2 help_y -= 2 help_x += 2 end return false if counter < new_y - y + 1 and counter < x - new_x + 1 when 2 y += 1 while (help_y >= y) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_y -= 2 end return false if counter < new_y - y + 1 when 3 y += 1 x += 1 while (help_y >= y) and (help_x >= x) and ($game_map.passable?(help_x, help_y, 2, self)) and ($game_map.passable?(help_x, help_y, 6, self)) counter += 2 help_y -= 2 help_x -= 2 end return false if counter < new_y - y + 1 and counter < new_x - x + 1 when 4 x -= 1 while (help_x <= x) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_x += 2 end return false if counter < x - new_x + 1 when 6 x += 1 while (help_x >= x) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_x -= 2 end return false if counter < new_x - x + 1 when 7 y -= 1 x -= 1 while (help_y <= y) and (help_x <= x) and ($game_map.passable?(help_x, help_y, 8, self)) and ($game_map.passable?(help_x, help_y, 4, self)) counter += 2 help_y += 2 help_x += 2 end return false if counter < y - new_y + 1 and counter < x - new_x + 1 when 8 y -= 1 while (help_y <= y) and ($game_map.passable?(help_x, help_y, d, self)) counter += 2 help_y += 2 end return false if counter < y - new_y + 1 when 9 y -= 1 x += 1 while (help_y <= y) and (help_x >= x) and ($game_map.passable?(help_x, help_y, 8, self)) and ($game_map.passable?(help_x, help_y, 6, self)) counter += 2 help_y += 2 help_x -= 2 end return false if counter < y - new_y + 1 and counter < new_x - x + 1 end #--------------------------------------------------------------------------- # checks if an Event is on the same place #--------------------------------------------------------------------------- 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'], event.size['y'] + @size['y'], new_x, new_y) and event != self and not event.through and (event.character_name != '' or event.tile_id != 0) return false end end #--------------------------------------------------------------------------- # checks if the Player is on the same place #--------------------------------------------------------------------------- if self != $game_player and not $game_player.through and (@character_name != '' or $game_player.tile_id != 0) and self.in_rect?($game_player.x, $game_player.y - $game_player.size['y'] / 2 + @size['y'] / 2, $game_player.size['x'] + @size['x'], $game_player.size['y'] + @size['y'], new_x, new_y) return false end #--------------------------------------------------------------------------- # 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 #----------------------------------------------------------------------------- # update method, has been splitted to give an easier overview #----------------------------------------------------------------------------- def update #--------------------------------------------------------------------------- # updates #--------------------------------------------------------------------------- # update special for looped maps self.update_loop_map # checks for events self.check_event_trigger_touch if (self.moving? and not @through) # walks Pathfinding route self.go_path # checks if the move speed changes because of hills, swamps, etc. if not self.is_a?(Game_Party_Actor) @move_speed /= @speed_factor @speed_factor = [[0.1, self.move_speed_change].max, 2.0].min @move_speed *= @speed_factor end @last_moving = false if jumping? update_jump elsif moving? update_move @last_moving = true else update_stop end #--------------------------------------------------------------------------- # updates shown frame # has been improved, now the event doesnt slide at the beginning anymore #--------------------------------------------------------------------------- if @anime_count > (18 - @move_speed * 2) * 4 / @direction_number or (@pattern == 0 and not @walk) if not @step_anime and @stop_count > 0 @walk = false @pattern = @original_pattern else @walk = true @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 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 move_type_random when 2 move_type_toward_player when 3 move_type_custom end end end #----------------------------------------------------------------------------- # checks if the speed has to be changed because of the ground #----------------------------------------------------------------------------- def move_speed_change #--------------------------------------------------------------------------- # returns if nothing has to be checked #--------------------------------------------------------------------------- return 1.0 if ($game_map.swamp_map == nil and $game_map.height_map == nil) add = 1.0 # changing factor #--------------------------------------------------------------------------- # checks height-map #--------------------------------------------------------------------------- if $game_map.height_map != nil 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) x_su = @x + 16 y_su = @y + 32 xn_su = new_x + 16 yn_su = new_y + 32 @z = RPG::Cache.read_table($game_map.height_map, x_su - 1, y_su - 1) if @z == 0 @z = $game_map.height_map.get_pixel(x_su, y_su).red RPG::Cache.write_table($game_map.height_map, x_su - 1, y_su - 1, @z) end p = (@z - $game_map.height_map.get_pixel(xn_su, yn_su).red) * 2 if (xn_su >= $game_map.height_map.width or yn_su >= $game_map.height_map.height or x_su >= $game_map.height_map.width or y_su >= $game_map.height_map.height) p = 0 end if p > 0 p = p * 3 / 4 end add /= @move_speed / (@move_speed + p / 2) end #--------------------------------------------------------------------------- # checks swamp-map #--------------------------------------------------------------------------- if $game_map.swamp_map != nil x_sw = @x + 16 y_sw = @y + 32 - 1 if (x_sw >= $game_map.swamp_map.width or y_sw >= $game_map.swamp_map.height or x_sw < 0 or y_sw < 0) add *= 1.0 else px = RPG::Cache.read_table($game_map.swamp_map, x_sw, y_sw) if px == 0 px = $game_map.swamp_map.get_pixel(x_sw, y_sw).red RPG::Cache.write_table($game_map.swamp_map, x_sw, y_sw, px) end add *= px / 255.0 end end # returns speed return add end #----------------------------------------------------------------------------- #Loop Map Teleport when Event reached the border, etc. #----------------------------------------------------------------------------- def update_loop_map #--------------------------------------------------------------------------- # returns if map isnt looped (and changes coords of neccessary) #--------------------------------------------------------------------------- unless $pixelmovement.loop_maps.include?($game_map.map_id) @x = 0 if @x < 0 @y = 0 if @y < 0 return end #--------------------------------------------------------------------------- # returns if self is a caterpillar #--------------------------------------------------------------------------- return if self.is_a?(Game_Party_Actor) x_l = 0 # changing horizontal y_l = 0 # changing vertical #--------------------------------------------------------------------------- # teleports at the border #--------------------------------------------------------------------------- if @x > ($game_map.width * 32) x_l = - ($game_map.width * 32) @x += x_l @real_x = (@x) * 4 elsif @x < 0 x_l = ($game_map.width * 32) @x += x_l @real_x = (@x) * 4 end if @y > ($game_map.height * 32) y_l = - ($game_map.height * 32) @y += y_l @real_y = (@y) * 4 elsif @y < 0 y_l = ($game_map.height * 32) @y += y_l @real_y = (@y) * 4 end #--------------------------------------------------------------------------- # If the Player reached the border, the Caterpillars are teleported, too #--------------------------------------------------------------------------- return if not (self == $game_player and (x_l != 0 or y_l != 0)) $game_map.game_party_actors.each do |actor| actor.x += x_l actor.y += y_l actor.real_x = (actor.x) * 4 actor.real_y = (actor.y) * 4 actor.move_list.each do |ko| ko[0] += x_l ko[1] += y_l end 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 #----------------------------------------------------------------------------- def update_move distance = (2 ** @move_speed).round if @y * 4 < @real_y @real_y = [@real_y - distance, @y * 4].max elsif @y * 4 > @real_y @real_y = [@real_y + distance, @y * 4].min end if @x * 4 < @real_x if $pixelmovement.isometric @real_x = [@real_x - distance * 2, @x * 4].max else @real_x = [@real_x - distance, @x * 4].max end elsif @x * 4 > @real_x if $pixelmovement.isometric @real_x = [@real_x + distance * 2, @x * 4].min else @real_x = [@real_x + distance, @x * 4].min end end if @walk_anime @anime_count += 1.5 elsif @step_anime @anime_count += 1 end end #----------------------------------------------------------------------------- # New Move Random (more pixellike) #----------------------------------------------------------------------------- def move_type_random case rand(12) when 0..7 (rand(9) + 8).times do move_random(2) end when 8..9 (rand(9) + 8).times do move_forward(2) end end end #----------------------------------------------------------------------------- # New Move Toward Player (more pixellike) #----------------------------------------------------------------------------- def move_type_toward_player sx = @x - $game_player.x sy = @y - $game_player.y abs_sx = sx > 0 ? sx : -sx abs_sy = sy > 0 ? sy : -sy if sx.abs + sy.abs >= 32 * 20 8.times do move_random(4) end elsif sx.abs > 0 or sy.abs > 0 8.times do move_toward_player(4) end end end #----------------------------------------------------------------------------- # New Move Route (more pixellike) #----------------------------------------------------------------------------- def move_type_custom if jumping? or moving? return end #--------------------------------------------------------------------------- # commands #--------------------------------------------------------------------------- while @move_route_index < @move_route.list.size command = @move_route.list[@move_route_index] if command.code == 0 if @move_route.repeat @move_route_index = 0 end 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 end @stop_count = 0 end return end if command.code <= 14 case command.code when 1 16.times do move_down(2, true, false) end when 2 16.times do move_left(2, true, false) end when 3 16.times do move_right(2, true, false) end when 4 16.times do move_up(2, true, false) end when 5 16.times do move_lower_left(2,true,false) end when 6 16.times do move_lower_right(2, true, false) end when 7 16.times do move_upper_left(2, true, false) end when 8 16.times do move_upper_right(2, true, false) end when 9 16.times do move_random(2, true, false) end when 10 16.times do move_toward_player(2) end when 11 16.times do move_away_from_player(2) end when 12 16.times do move_forward(2) end when 13 16.times do move_backward(2) end when 14 jump(command.parameters[0] * 32, command.parameters[1] * 32) end if not @move_route.skippable and not moving? and not jumping? return end @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, again = true) if @no_slide != 2 @no_slide = 0 end if turn_enabled turn_down end if passable?(@x, @y, 2, steps) @y += steps increase_steps else if 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 end #----------------------------------------------------------------------------- # move_left, more pixellike #----------------------------------------------------------------------------- def move_left(steps = 32, turn_enabled = true, again = true) if @no_slide != 4 @no_slide = 0 end if turn_enabled turn_left end if passable?(@x, @y, 4, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end increase_steps else if 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 end #----------------------------------------------------------------------------- # move_right, more pixellike #----------------------------------------------------------------------------- def move_right(steps=32, turn_enabled = true, again = true) if @no_slide != 6 @no_slide = 0 end if turn_enabled turn_right end if passable?(@x, @y, 6, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end increase_steps else if 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 end #----------------------------------------------------------------------------- # move_up, more pixellike #----------------------------------------------------------------------------- def move_up(steps = 32, turn_enabled = true, again = true) if @no_slide != 8 @no_slide = 0 end if turn_enabled turn_up end if passable?(@x, @y, 8, steps) @y -= steps increase_steps else if 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 end #----------------------------------------------------------------------------- # move_lower_left, more pixellike #----------------------------------------------------------------------------- def move_lower_left (steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_lower_left end if passable?(@x, @y, 1, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end @y += steps increase_steps else if again and $pixelmovement.sliding move_down(steps, false, false) move_left(steps, false, false) end end end #----------------------------------------------------------------------------- # move_lower_right, more pixellike #----------------------------------------------------------------------------- def move_lower_right(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_lower_right end if passable?(@x, @y, 3, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end @y += steps increase_steps else if again and $pixelmovement.sliding move_down(steps, false, false) move_right(steps, false, false) end end end #----------------------------------------------------------------------------- # move_upper_left, more pixellike #----------------------------------------------------------------------------- def move_upper_left(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_upper_left end if passable?(@x, @y, 7, steps) if $pixelmovement.isometric @x -= steps * 2 else @x -= steps end @y -= steps increase_steps else if again and $pixelmovement.sliding move_up(steps, false, false) move_left(steps, false, false) end end end #----------------------------------------------------------------------------- # move_upper_right, more pixellike #----------------------------------------------------------------------------- def move_upper_right(steps = 32, turn_enabled = true, again = true) if again @no_slide = 0 end if turn_enabled turn_upper_right end if passable?(@x, @y, 9, steps) if $pixelmovement.isometric @x += steps * 2 else @x += steps end @y -= steps increase_steps else if again and $pixelmovement.sliding move_up(steps, false, false) move_right(steps, false, false) end end end #----------------------------------------------------------------------------- # move_random, more pixellike #----------------------------------------------------------------------------- def move_random(steps = 32, turn_enabled = true, again = true) case rand(12) when 0..1 move_down(steps, turn_enabled, again) when 2..3 move_left(steps, turn_enabled, again) when 4..5 move_right(steps, turn_enabled, again) when 6..7 move_up(steps, turn_enabled, again) when 8 move_lower_left(steps, turn_enabled, again) when 9 move_lower_right(steps, turn_enabled, again) when 10 move_upper_left(steps, turn_enabled, again) when 11 move_upper_right(steps, turn_enabled, again) end end #----------------------------------------------------------------------------- # move_toward_player, more pixellike #----------------------------------------------------------------------------- def move_toward_player(steps = 32) case rand(6) when 0..4 self.turn_toward_player self.move_forward(steps) when 5 if steps != 32 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) case rand(6) when 0..4 self.turn_away_from_player self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_toward_event, more pixellike #----------------------------------------------------------------------------- def move_toward_event(id, steps = 32) case rand(6) when 0..4 if id == 0 self.turn_toward_player else self.turn_toward_event(id) end self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_away_from_event, more pixellike #----------------------------------------------------------------------------- def move_away_from_event(id, steps = 32) case rand(6) when 0..4 if id == 0 self.turn_away_from_player else self.turn_away_from_event(id) end self.move_forward(steps) when 5 if steps != 32 self.move_random(steps * 2) else self.move_random(steps) end end end #----------------------------------------------------------------------------- # move_forward, more pixellike #----------------------------------------------------------------------------- def move_forward(steps = 32) case @direction when 1 move_lower_left(steps, false, false) when 2 move_down(steps, false, false) when 3 move_lower_right(steps, false, false) when 4 move_left(steps, false, false) when 6 move_right(steps, false, false) when 7 move_upper_left(steps, false, false) when 8 move_up(steps, false, false) when 9 move_upper_right(steps, false, 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, false) when 2 move_up(steps, false, false) when 3 move_upper_left(steps, false, false) when 4 move_right(steps, false, false) when 6 move_left(steps, false, false) when 7 move_lower_right(steps, false, false) when 8 move_down(steps, false, false) when 9 move_lower_left(steps, false, false) end @direction_fix = last_direction_fix end #----------------------------------------------------------------------------- # turn_lower_left #----------------------------------------------------------------------------- def turn_lower_left unless @direction_fix @direction = 1 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_lower_right #----------------------------------------------------------------------------- def turn_lower_right unless @direction_fix @direction = 3 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_upper_left #----------------------------------------------------------------------------- def turn_upper_left unless @direction_fix @direction = 7 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_upper_right #----------------------------------------------------------------------------- def turn_upper_right unless @direction_fix @direction = 9 @stop_count = 0 end end #----------------------------------------------------------------------------- # turn_right_90, for 8 directions #----------------------------------------------------------------------------- def turn_right_90 case @direction when 1 turn_upper_left when 2 turn_left when 3 turn_lower_left when 4 turn_up when 6 turn_down when 7 turn_upper_right when 8 turn_right when 9 turn_lower_right end end #----------------------------------------------------------------------------- # turn_left_90, for 8 directions #----------------------------------------------------------------------------- def turn_left_90 case @direction when 1 turn_lower_right when 2 turn_right when 3 turn_upper_right when 4 turn_down when 6 turn_up when 7 turn_lower_left when 8 turn_left when 9 turn_upper_left end end #----------------------------------------------------------------------------- # turn_180, for 8 directions #----------------------------------------------------------------------------- def turn_180 case @direction when 1 turn_upper_right when 2 turn_up when 3 turn_upper_left when 4 turn_right when 6 turn_left when 7 turn_lower_right when 8 turn_down when 9 turn_lower_left end end #----------------------------------------------------------------------------- # turn_random, for 8 directions #----------------------------------------------------------------------------- def turn_random case rand(12) 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 #----------------------------------------------------------------------------- # turn_toward_player, for 8 directions #----------------------------------------------------------------------------- def turn_toward_player vector = Math.atan2(($game_player.y - @y), ($game_player.x - @x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_toward_event, for 8 directions #----------------------------------------------------------------------------- def turn_toward_event(id) vector = Math.atan2(($game_map.events[id].y - @y), ($game_map.events[id].x - @x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_away_from_player, for 8 directions #----------------------------------------------------------------------------- def turn_away_from_player vector = Math.atan2((@y - $game_player.y), (@x - $game_player.x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 6 when 22.5..67.49 @direction = 3 when 67.5..112.49 @direction = 2 when 112.5..157.49 @direction = 1 when 157.5..180 @direction = 4 when -180..-157.5 @direction = 4 when -157.49..-112.5 @direction = 7 when -112.49..-67.5 @direction = 8 when -67.49..-22.5 @direction = 9 end end #----------------------------------------------------------------------------- # turn_away_from_event, for 8 directions #----------------------------------------------------------------------------- def turn_away_from_event(id) vector = Math.atan2((@y - $game_map.events[id].y), (@x - $game_map.events[id].x)) * 180 / Math::PI case vector when -22.49..22.49 @direction = 4 when 22.5..67.49 @direction = 7 when 67.5..112.49 @direction = 8 when 112.5..157.49 @direction = 9 when 157.5..180 @direction = 6 when -180..-157.5 @direction = 6 when -157.49..-112.5 @direction = 3 when -112.49..-67.5 @direction = 2 when -67.49..-22.5 @direction = 1 end 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] #----------------------------------------------------------------------------- def looks_at?(id) sx = @x - $game_map.events[id].x sy = @y - $game_map.events[id].y return true if (sx == 0 and sy == 0) if sx.abs > sy.abs if sx > 0 and (@direction == 4 or @direction == 1 or @direction == 7) return true elsif sx < 0 and (@direction == 6 or @direction == 3 or @direction == 9) return true end else if sy > 0 and (@direction == 8 or @direction == 7 or @direction == 9) return true elsif sy < 0 and (@direction == 2 or @direction == 1 or @direction == 3) return true end end return false end #----------------------------------------------------------------------------- # new jump, height added, for Pixel Coords #----------------------------------------------------------------------------- def jump(x_plus, y_plus, high=5) new_x = @x + x_plus new_y = @y + y_plus if (x_plus == 0 and y_plus == 0) or self.passable?(new_x, new_y, @direction, 1) if x_plus != 0 or y_plus != 0 if x_plus.abs > y_plus.abs x_plus < 0 ? turn_left : turn_right else y_plus < 0 ? turn_up : turn_down end end straighten @x = new_x @y = new_y high_2 = 40 / high x_plus /= high_2 y_plus /= high_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 #----------------------------------------------------------------------------- # checks if Player shall slide #----------------------------------------------------------------------------- def check_slide(dir) return if not ($pixelmovement.sliding and self.is_a?(Game_Player)) #--------------------------------------------------------------------------- # 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 + 2, 2) end c = @size['x'] for i in 0..c if $game_map.passable?(@x + (c - i), @y + 2, 2) r += 1 break if r > l end end if r > l and $game_map.passable?(@x + @size['x'], @y + 2, 2) return 6 elsif l > 0 and $game_map.passable?(@x - @size['x'], @y + 2, 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 - 2 - @size['x'] / 2, @y + i, 4) end c = @size['y'] for i in 0..c if $game_map.passable?(@x - 2 - @size['x'] / 2, @y + (c - i), 4) d += 1 break if d > u end end if u > d and $game_map.passable?(@x - 2 - @size['x'] / 2, @y - @size['y'] * 2, 4) return 8 elsif d > 0 and $game_map.passable?(@x - 2 - @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 + 2 + @size['x'] / 2, @y + i, 6) end c = @size['y'] for i in 0..c if $game_map.passable?(@x + 2 + @size['x'] / 2, @y + (c - i), 6) d += 1 break if d > u end end if u > d and $game_map.passable?(@x + 2 + @size['x'] / 2, @y - @size['y'] * 2, 6) return 8 elsif d > 0 and $game_map.passable?(@x + 2 + @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 - 2 - @size['y'], 8) end c = @size['x'] for i in 0..c if $game_map.passable?(@x + (c - i), @y - 2 - @size['y'], 8) r += 1 break if r > l end end if r > l and $game_map.passable?(@x + @size['x'], @y - 2, 8) return 6 elsif l > 0 and $game_map.passable?(@x - @size['x'], @y - 2, 8) return 4 else @no_slide = dir end end return 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) x_s = mx - r x_e = mx + r y_s = my - r y_e = my + r return (sx >= x_s and sx <= x_e and sy >= y_s and sy <= y_e) end #----------------------------------------------------------------------------- # returns of the event is inside the rectangle #----------------------------------------------------------------------------- def in_rect?(mx, my, width, height, sx = @x, sy = @y) x_s = mx - width / 2 x_e = mx + width / 2 y_s = my - height / 2 y_e = my + height / 2 return (sx >= x_s and sx <= x_e and sy >= y_s and sy <= y_e) end #----------------------------------------------------------------------------- # returns the distance to the event with id as its id, 0 means game_player #----------------------------------------------------------------------------- def distance_to_event(id) if id == 0 return Math.sqrt((@x - $game_player.x) * (@x - $game_player.x) + (@y - $game_player.y) * (@y - $game_player.y)) else return Math.sqrt((@x - $game_map.events[id].x) * (@x - $game_map.events[id].x) + (@y - $game_map.events[id].y) * (@y - $game_map.events[id].y)) end 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 id == 0 if self.dtp < d1 self.move_away_from_player elsif self.dtp > d2 self.move_toward_player end else if self.dtp < d1 self.move_away_from_event(id) elsif self.dtp > d2 self.move_toward_event(id) end end 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 #----------------------------------------------------------------------------- def in_range? return true if not self.is_a?(Game_Event) if ($game_map.ice_events.keys.include?(@id) or $game_map.jump_events.keys.include?(@id)) return false end if (@trigger == 3 or @trigger == 4 or (@list!=nil and @list[0].code == 108 and @list[0].parameters == [''])) return true end 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 return true if (@real_x > screne_x and @real_x < screne_width and @real_y > screne_y and @real_y < screne_height) if $pixelmovement.loop_maps.include?($game_map.map_id) o_x = @real_x o_y = @real_y if $game_player.x - 16 < 32 * 9 and @x - 16 > ($game_map.width * 32) - 32 * 11 #Left o_x -= ($game_map.width * 32) * 4 end if $game_player.x - 16 > ($game_map.width * 32) - 32 * 11 and @x - 16 < 32 * 9 #Right o_x += ($game_map.width * 32) * 4 end if $game_player.y + 32 < 32 * 8 and @y + 32 > ($game_map.height * 32) - 32 * 7 #Up o_y -= ($game_map.height*32)*4 end if $game_player.y + 32 > ($game_map.height * 32) - 32 * 7 and @y + 32 < 32 * 8 #Down 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 end return false end #----------------------------------------------------------------------------- # returns Sprite (ID) of the event #----------------------------------------------------------------------------- def char_sprite(id = false) return if self == nil $scene.spriteset.character_sprites.each do |sprite| if sprite.character == self if id return $scene.spriteset.character_sprites.index(sprite) else return sprite end end end return end end #=============================================================================== # Game_Event Class #=============================================================================== class Game_Event < Game_Character #----------------------------------------------------------------------------- # initialsing method, Event is teleported to Pixel Coords #----------------------------------------------------------------------------- alias pixel_event_init initialize if not $pixelmovement.pixel_aliasing def initialize(map_id, event) pixel_event_init(map_id, event) moveto(@event.x * 32, @event.y * 32) refresh end #----------------------------------------------------------------------------- # returns if the Event is passable #----------------------------------------------------------------------------- def over_trigger? return (@through or (@character_name == '' and (@tile_id == nil or @tile_id == 0))) end #----------------------------------------------------------------------------- # Collision, Not Passable #----------------------------------------------------------------------------- def check_event_trigger_touch(x = 0,y = 0) return if $game_system.map_interpreter.running? if @trigger == 2 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) or 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)) if not jumping? and not over_trigger? and @trigger_on == 0 @trigger_on = 3 start end else @trigger_on = 0 if @trigger_on == 3 end end #----------------------------------------------------------------------------- # Collision/Autostart, Passable #----------------------------------------------------------------------------- def check_event_trigger_auto if @trigger == 2 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']) or 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) or 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))) if not jumping? and over_trigger? and @trigger_on == 0 and Graphics.frame_count > 0 @trigger_on = 4 start end else @trigger_on = 0 if @trigger_on == 4 end start if @trigger == 3 end #----------------------------------------------------------------------------- # update method, changed for Anti-Lag-Script #----------------------------------------------------------------------------- alias pixel_ev_up update if not $pixelmovement.pixel_aliasing def update return if not self.in_range? pixel_ev_up end end #=============================================================================== # Game_Player Class #=============================================================================== class Game_Player < Game_Character attr_accessor :sprint alias pixel_player_init initialize if not $pixelmovement.pixel_aliasing def initialize pixel_player_init @steps_done = 0 # counts how many steps are done after standing @schritte_zaehl = 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 end #----------------------------------------------------------------------------- # new pasable method, for 8 directions, isometric and pixelmovement #----------------------------------------------------------------------------- def passable?(x, y, d, steps = 32) # for Isometric script if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end 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) return true if $DEBUG and Input.press?(Input::CTRL) 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) super(x, y) $game_map.game_party_actors.each do |actor| actor.moveto(x, y) actor.move_list = [] actor.way = [] actor.path_steps = 0 end center(x, y) make_encounter_count end #----------------------------------------------------------------------------- # increase_steps, improved for Pixelmovement #----------------------------------------------------------------------------- alias pixel_inc_s increase_steps if not $pixelmovement.pixel_aliasing def increase_steps if @schritte_zaehl >= 10 pixel_inc_s @schritte_zaehl = 0 else @schritte_zaehl +=1 end end #----------------------------------------------------------------------------- # 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 ((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']) or 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) or 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)))) and triggers.include?(event.trigger) if not event.jumping? and event.over_trigger? and event.trigger_on == 0 event.trigger_on = 1 event.start result = true end else event.trigger_on = 0 if event.trigger_on == 1 end end return result end #----------------------------------------------------------------------------- # 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 event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if (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) or 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)) and triggers.include?(event.trigger) and self.looks_at?(event.id) if not event.jumping? and not event.over_trigger? event.start result = true end end end #--------------------------------------------------------------------------- # counter top? #--------------------------------------------------------------------------- if not result new_x = @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 = @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) # 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) new_x += (@direction == 1 ? -32 : @direction == 3 ? 32 : @direction == 7 ? -32 : @direction == 9 ? 32 : @direction == 6 ? 32 : @direction == 4 ? -32 : 0) new_y += (@direction == 1 ? 32 : @direction == 3 ? 32 : @direction == 7 ? -32 : @direction == 9 ? -32 : @direction == 2 ? 32 : @direction == 8 ? -32 : 0) for event in $game_map.events.values if event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if 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) and triggers.include?(event.trigger) and self.looks_at?(event.id) if not event.jumping? and not event.over_trigger? event.start result = true end end end end end return result end #----------------------------------------------------------------------------- # Touch, not Passable #----------------------------------------------------------------------------- def check_event_trigger_touch(x = 0,y = 0) result = false return result if $game_system.map_interpreter.running? for event in $game_map.events.values if event.through or (event.character_name == '' and (event.tile_id == 0 or event.tile_id == nil)) next end if (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) or 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)) and [1, 2].include?(event.trigger) if not event.jumping? and not event.over_trigger? and event.trigger_on == 0 event.trigger_on = 2 event.start result = true end else event.trigger_on = 0 if event.trigger_on == 2 end end return result end #----------------------------------------------------------------------------- # update method, has been splitted #----------------------------------------------------------------------------- def update # updates movement and input self.update_movement last_real_x = @real_x last_real_y = @real_y # checks if sprint is activated self.check_sprint_input # checks if player shall jump self.check_jump_input if Input.trigger?(Input::C) check_event_trigger_here([0]) check_event_trigger_there([0, 1, 2]) end super # changes var for steps if last_real_x != @real_x or last_real_y != @real_y @steps_done += 1 else @steps_done = 0 end # updates encounter self.update_encounter(last_real_x, last_real_y) # updates scrolling self.update_scroll(last_real_x, last_real_y) # checks if the player stands on a jump tile self.check_jump end #----------------------------------------------------------------------------- # checks if Character is on a sliding tile #----------------------------------------------------------------------------- def check_ice return if $pixelmovement.ice_tiles == nil or $pixelmovement.ice_tiles == [] @walk_anime = true #--------------------------------------------------------------------------- # checks if an Event is on the same place #--------------------------------------------------------------------------- # more steps if player moves fast if @move_speed > 3 steps=2**(@move_speed.round-2) else steps=2 end for event in $game_map.ice_events.values if self.in_rect?(event.x, event.y - 11, 23, 23) 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?('ice:')) i += 1 next end ice = list.list[i].parameters[0].split(/: /)[1].downcase i += 1 #--------------------------------------------------------------------- # if ice type is face direction is changed #--------------------------------------------------------------------- if ice == 'face' case @direction when 1 ice = 'lower left' when 2 ice = 'down' when 3 ice = 'lower right' when 4 ice = 'left' when 6 ice = 'right' when 7 ice = 'upper left' when 8 ice = 'up' when 9 ice = 'upper right' end end #--------------------------------------------------------------------- # slides #--------------------------------------------------------------------- case ice when 'lower left' self.move_lower_left(steps) when 'down' self.move_down(steps) when 'lower right' self.move_lower_right(steps) when 'left' self.move_left(steps) when 'right' self.move_right(steps) when 'upper left' self.move_upper_left(steps) when 'up' self.move_up(steps) when 'upper right' self.move_upper_right(steps) end @walk_anime = false #--------------------------------------------------------------------- # caterpillars slide #--------------------------------------------------------------------- $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y,'sl']] if actor.id != 1 end return true end end end #--------------------------------------------------------------------------- # checks for tile ids #--------------------------------------------------------------------------- # more steps if player moves fast if @move_speed > 3 steps=2**(@move_speed.round-2) else steps=2 end if $pixelmovement.ice_tiles.include?($game_map.terrain_tag(@x, @y)) and self.passable?(@x, @y, @direction, 4) self.move_forward(steps) @walk_anime = false #--------------------------------------------------------------------- # caterpillars slide #--------------------------------------------------------------------- $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y,'sl']] if actor.id != 1 end return true end return false end #----------------------------------------------------------------------------- # checks if Character is on a jumping tile #----------------------------------------------------------------------------- def check_jump #--------------------------------------------------------------------------- # 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' x = -$pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'down' x = 0 y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'lower right' x = $pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 'left' x = -$pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 'right' x = $pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 'upper left' x = -$pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 'up' x = 0 y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 'upper right' x = $pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height end self.jump(x,y,h) #--------------------------------------------------------------------- # caterpillars jump #--------------------------------------------------------------------- if self.jumping? $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_list += [[@x, @y, h]] end end end return end end end end #----------------------------------------------------------------------------- # updates movement and input #----------------------------------------------------------------------------- def update_movement #--------------------------------------------------------------------------- # checks input + moves #--------------------------------------------------------------------------- # return if no update return if (moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing or @path_steps != 0) return if self.check_ice # more steps if player moves fast if @steps_done >= 2 and @move_speed > 3 steps=2 ** (@move_speed.round - 2) else steps = 2 end x = @x y = @y # Sprint fix? if @sprint and $pixelmovement.sprint_fix (steps / 2).times do move_forward(2) end else #input case Input.dir8 when 1 (steps / 2).times do move_lower_left(2) end when 2 (steps / 2).times do move_down(2) end when 3 (steps / 2).times do move_lower_right(2) end when 4 (steps / 2).times do move_left(2) end when 6 (steps / 2).times do move_right(2) end when 7 (steps / 2).times do move_upper_left(2) end when 8 (steps / 2).times do move_up(2) end when 9 (steps / 2).times do move_upper_right(2) end end end #--------------------------------------------------------------------------- # other things #--------------------------------------------------------------------------- # saves Caterpillar Route $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y]] if actor.id != 1 end #Sprint Script off return if not @sprint @move_speed -= $pixelmovement.sprint_speed @sprint = false # Sprint of for Caterpillar? $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_speed -= $pixelmovement.sprint_speed end end end #----------------------------------------------------------------------------- # checks input for sprinting #----------------------------------------------------------------------------- def check_sprint_input @sprint_time += 1 if @sprint_time < 0 return if not self.moving? result = check_event_trigger_here([1, 2]) #--------------------------------------------------------------------------- #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 # Sprint for Caterpillar $game_map.game_party_actors.each do |actor| if actor.id != 1 actor.move_speed += $pixelmovement.sprint_speed end end 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 x = -$pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 2 x = 0 y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 3 x = $pixelmovement.jump_length y = $pixelmovement.jump_length h = $pixelmovement.jump_height when 4 x = -$pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 6 x = $pixelmovement.jump_length y = 0 h = $pixelmovement.jump_height when 7 x = -$pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 8 x = 0 y = -$pixelmovement.jump_length h = $pixelmovement.jump_height when 9 x = $pixelmovement.jump_length y = -$pixelmovement.jump_length h = $pixelmovement.jump_height end self.jump(x,y,h) # jump for caterpillar return if not self.jumping? $game_map.game_party_actors.each do |actor| actor.move_list += [[@x, @y, h]] if actor.id != 1 end end #----------------------------------------------------------------------------- # updates encounter count #----------------------------------------------------------------------------- def update_encounter(last_real_x, last_real_y) # returns if no steps were made return if @steps_done == 0 if not (@encounter_count > 0 and not ($DEBUG and Input.press?(Input::CTRL))) return end # changes encounter count according to move_speed if @steps_done >= 2 and @move_speed >= 4 @encounter_count -= (2 ** (@move_speed - 2)) / 2 else @encounter_count -= 1 end end #----------------------------------------------------------------------------- # updates scrolling #----------------------------------------------------------------------------- def update_scroll(last_real_x, last_real_y) 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 end #=============================================================================== # Scene_Save Class, deletes bitmaps in $game_map #=============================================================================== class Scene_Save < Scene_File alias pixel_write_s write_save_data if not $pixelmovement.pixel_aliasing def write_save_data(file) $game_map.collision_map = nil $game_map.height_map = nil $game_map.swamp_map = nil pixel_write_s(file) Marshal.dump($events, file) $game_map.init_bitmaps end end #=============================================================================== # Scene_Load Class, loads deleted bitmaps again #=============================================================================== class Scene_Load < Scene_File alias pixel_read_s read_save_data if not $pixelmovement.pixel_aliasing def read_save_data(file) pixel_read_s(file) $game_map.init_bitmaps $events = Marshal.load(file) end end #=============================================================================== # Scene_Title Class #=============================================================================== class Scene_Title alias pixel_command_n command_new_game if not $pixelmovement.pixel_aliasing def command_new_game $events = {} # used later to save Events pixel_command_n # Pixel Coords $game_player.moveto($data_system.start_x * 32, $data_system.start_y * 32) end end #=============================================================================== # Sprite_Character Class #=============================================================================== class Sprite_Character < RPG::Sprite attr_accessor :direction attr_accessor :_loop_animation attr_accessor :_animation attr_accessor :_animation_hit #----------------------------------------------------------------------------- # initialise method #----------------------------------------------------------------------------- alias pixel_sp_cha_init initialize if not $pixelmovement.pixel_aliasing def initialize (viewport, character = nil) pixel_sp_cha_init (viewport, character) # saves the real face direction later (for 4dirs) @direction = @character.direction 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 return if not @character.in_range? and self.src_rect != Rect.new(0, 0, 0, 0) super() #--------------------------------------------------------------------------- # tile graphic #--------------------------------------------------------------------------- if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue 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 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 == [] sy = (@direction - 2) / 2 * @ch else sy = ($pixelmovement.direction_array[@direction/2 - 1]) * @ch end else sy = 0 end self.src_rect.set(sx, sy, @cw, @ch) end #--------------------------------------------------------------------------- # updates position, etc #--------------------------------------------------------------------------- self.x = @character.screen_x + x_add self.y = @character.screen_y + y_add 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_Map Class #=============================================================================== class Scene_Map attr_accessor :spriteset #----------------------------------------------------------------------------- # update method #----------------------------------------------------------------------------- alias pixel_sc_map_up update if not $pixelmovement.pixel_aliasing def update pixel_sc_map_up #--------------------------------------------------------------------------- # 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 $game_temp.player_transferring = false #--------------------------------------------------------------------------- # checks if map is changed / changes map #--------------------------------------------------------------------------- if $game_map.map_id != $game_temp.player_new_map_id id = true $game_map.events.values.each {|ev| ev.trigger_on = 0} $events[$game_map.map_id] = $game_map.events # saves Events of the old Map $game_map.setup($game_temp.player_new_map_id) # loads Events of the new Map if $events[$game_map.map_id] != nil $game_map.events = $events[$game_map.map_id] $game_map.events.values.each {|event| event.refresh} end end #--------------------------------------------------------------------------- # moves + turns player #--------------------------------------------------------------------------- $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y) case $game_temp.player_new_direction when 2 $game_player.turn_down when 4 $game_player.turn_left when 6 $game_player.turn_right when 8 $game_player.turn_up end $game_player.straighten $game_map.update #--------------------------------------------------------------------------- # draws a new minimap only if the map was changed #--------------------------------------------------------------------------- if id @spriteset.dispose @spriteset = Spriteset_Map.new else @spriteset.dispose(false) # false because the minimap mustnt # be disposed (to prevent lag) @spriteset = Spriteset_Map.new(@spriteset.minimap) end if $game_temp.transition_processing $game_temp.transition_processing = false Graphics.transition(20) end $game_map.autoplay Graphics.frame_reset Input.update 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(mimap = nil) @game_party_actors_sprites = [] @minimap_check = false #--------------------------------------------------------------------------- # Loop_Map #--------------------------------------------------------------------------- if $pixelmovement.loop_maps.include?($game_map.map_id) @character_sprites_2 = [[], [], [], [], [], [], [], []] end pixel_spriteset_init() #--------------------------------------------------------------------------- # Minimap #--------------------------------------------------------------------------- @minimap_check = true if $pixelmovement.minimap if mimap == nil @minimap = Spriteset_Minimap.new(self) else @minimap = mimap end @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]) sprite.z -= 1 @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(mimap = true) 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 do |sprites| sprites.each do |sprite| sprite.dispose end end end #--------------------------------------------------------------------------- # Minimap #--------------------------------------------------------------------------- if @minimap != nil if mimap @minimap.dispose end end 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 do |sp_s| sp_s.each do |sp| sp.dispose end end @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 - 16 < 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] != [] for sprite in @character_sprites_2[0] sprite.dispose end @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 - 16 > ($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] != [] for sprite in @character_sprites_2[1] sprite.dispose end @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 < 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] != [] for sprite in @character_sprites_2[2] sprite.dispose end @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 + 32 > ($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] != [] for sprite in @character_sprites_2[3] sprite.dispose end @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 - 16 < 32 * 9 or $game_player.y + 32 < 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] != [] for sprite in @character_sprites_2[4] sprite.dispose end @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 - 16 < 32 * 9 or $game_player.x - 16 > ($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] != [] for sprite in @character_sprites_2[5] sprite.dispose end @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 + 32 > ($game_map.height * 32) - 32 * 7 or $game_player.y + 32 < 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] != [] for sprite in @character_sprites_2[6] sprite.dispose end @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 + 32 > ($game_map.height * 32) - 32 * 7 or $game_player.x - 16 > ($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] != [] for sprite in @character_sprites_2[7] sprite.dispose end @character_sprites_2[7] = [] end return false 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 $game_temp.player_new_y = @parameters[3] * 32 $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, @parameters[3] * 32) 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 #=============================================================================== # RPG::Cache Module #=============================================================================== module RPG module Cache #--------------------------------------------------------------------------- # self.load_bitmap method, prevents errors when no file is found #--------------------------------------------------------------------------- def self.load_bitmap(folder_name, filename, hue = 0) path = folder_name + filename if not @cache.include?(path) or @cache[path].disposed? if filename != '' @cache[path] = Bitmap.new(path) else @cache[path] = Bitmap.new(32, 32) end 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) self.init_table($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) self.init_table($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) self.init_table($pixelmovement.swamp_folder, filename) return @cache[$pixelmovement.swamp_folder + filename] end #--------------------------------------------------------------------------- # new methods for tables, for every bitmap a table can be created which # can contain information for every pixel #--------------------------------------------------------------------------- @tables = {} #--------------------------------------------------------------------------- # creates a table #--------------------------------------------------------------------------- def self.init_table(folder_name, filename) path = folder_name + filename return if (@cache[path] == nil) @tables[@cache[path]] = Table.new(@cache[path].width, @cache[path].height) end #--------------------------------------------------------------------------- # reads a table #--------------------------------------------------------------------------- def self.read_table(bitmap, x, y) return 0 if (@tables[bitmap] == nil) return @tables[bitmap][x, y] end #--------------------------------------------------------------------------- # writes into a table #--------------------------------------------------------------------------- def self.write_table(bitmap, x, y, value) if (@tables[bitmap] == nil) @tables[bitmap] = Table.new(bitmap.width, bitmap.height) end @tables[bitmap][x, y] = value return @tables[bitmap][x, y] end end end #=============================================================================== # Game_Character Class #=============================================================================== class Game_Character attr_accessor :through #----------------------------------------------------------------------------- # Returns true if self reached the target #----------------------------------------------------------------------------- def reached_target? return (@way != nil and @way.length == 0) end #----------------------------------------------------------------------------- # walks Pathfinding route #----------------------------------------------------------------------------- def go_path # returns if self should not walk return if not (@path_steps > 0 and not self.moving? and not self.jumping?) # moves if @way.length > 0 if @move_speed >= 4 ((@path_steps ** (@move_speed.round - 2)) / @path_steps).times do if @way[0] != nil @direction = @way[0] @way.delete_at(0) self.move_forward(@path_steps) end end else @direction = @way[0] @way.delete_at(0) self.move_forward(@path_steps) end # target has been found else @way = nil @path_steps = 0 end end #----------------------------------------------------------------------------- # Path to a Place / Coords #----------------------------------------------------------------------------- def find_path (target_x, target_y, walk = true, fast = false) if $game_map.valid?(target_x, target_y) and $game_map.passable?(target_x, target_y, 0, self) return self.go_to_place(target_x, target_y, walk, fast) end end #----------------------------------------------------------------------------- # Path to an Event #----------------------------------------------------------------------------- def find_event (id, walk = true, fast = false) if id == 0 target = $game_player elsif id > 0 target = $game_map.events[id] end new_through = target.through target.through = true ret = self.go_to_place(target.x, target.y, walk, fast) target.through = new_through Graphics.update return ret end #----------------------------------------------------------------------------- # basic pathfinding method # fast pathfing: simply tries to find a direct way to connect to points # normal pf: tries to find waypoints between two points and connects these # waypoints with fast pf #----------------------------------------------------------------------------- def go_to_place (target_x, target_y, walk = true, fast = false) #--------------------------------------------------------------------------- # these variables should not be changed! #--------------------------------------------------------------------------- steps = 2 # steps for fast pathfinding raster = 32 # raster for normal pathfinding dist = 2 # the higher this value the more waypoints are ignored at # normal pathfinding time_start = Time.new # start time of pathfnding #--------------------------------------------------------------------------- # uses normal pathfinding #--------------------------------------------------------------------------- if not fast # creates waypoints way = self.path_a(target_x, target_y, raster) # deletes every second step, so the movement doesnt look that raster-like j = 0 for i in 1..(way.length - 2) if (i) % dist != 0 way.delete_at(i + j) j -= 1 end end # creates connections between the waypoints @way = [] for i in 0..way.length - 2 @way += self.path_fast(way[i][0], way[i][1], way[i+1][0], way[i+1][1], steps) end #--------------------------------------------------------------------------- # fast pathfinding #--------------------------------------------------------------------------- else @way = self.path_fast(@x, @y, target_x, target_y, steps) end @path_steps = steps if walk #--------------------------------------------------------------------------- # saves Caterpillar Route #--------------------------------------------------------------------------- if self == $game_player $game_map.game_party_actors.each do |actor| if actor.id != 1 way = [] for i in 0..(actor.move_list.length - 2) way += actor.path_fast(actor.move_list[i][0], actor.move_list[i][1], actor.move_list[i + 1][0], actor.move_list[i + 1][1], @path_steps) end actor.way = way + @way.clone actor.path_steps = @path_steps actor.start_time = Graphics.frame_count + (actor.id - 1) * $pixelmovement.cater_distance / $game_player.move_speed - way.length / @path_steps actor.move_list = [] end end end time_end = Time.new # Time when pathfinding has been finished #p time_end - time_start # prints duration of pathfinding return @way end #----------------------------------------------------------------------------- # basic A* Pathfinding # Note: This isnt a simple pathfinding, which finds a way from a to b # it tries to find a way from a to b AND from b to a, until the ways meet # each other in the middle of the way itself. #----------------------------------------------------------------------------- def path_a(target_x, target_y, raster) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- ende = false # path has been completed? coords_s = [] # used coords for the way from a to b coords_z = [] # used coords for the way from b to a target_x_o = target_x # original target x-coord target_y_o = target_y # original target y-coord target_x = target_x / raster * raster # target x-coord is rastered target_y = target_y / raster * raster # target y-coord is rastered x = @x / raster * raster # rastered start x-coord y = @y / raster * raster # rastered start y-coord way_s = [[[x, y]]] # waypoints for the way from a to b way_z = [[[target_x, target_y]]] # waypoints for the way from b to a # double x speed for isometric if $pixelmovement.isometric steps_x = raster * 2 else steps_x = raster end steps_y = raster #--------------------------------------------------------------------------- # searches the way, until its found #--------------------------------------------------------------------------- loop do # start at the start point # for every existing way way_s.each do |way| # tries every direction and adds the new position if useful for d in [2, 4, 6, 8] do new_x = way.last[0] + (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 = way.last[1] + (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) next if coords_s.include?([new_x, new_y]) coords_s += [[new_x, new_y]] next if not self.passable?(way.last[0], way.last[1], d, raster) way_s += [way + [[new_x, new_y]]] ende = true if coords_z.include?([new_x, new_y]) end end # only the newest ways will be used l = way_s.last.length way_s.each do |way| way_s -= [way] if way.length < l end break if ende # start at the target # for every existing way way_z.each do |way| # tries every direction and adds the new position if useful for d in [2, 4, 6, 8] do new_x = way.last[0] + (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 = way.last[1] + (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) next if coords_z.include?([new_x, new_y]) coords_z += [[new_x, new_y]] next if not self.passable?(way.last[0], way.last[1], d, raster) way_z += [way+[[new_x, new_y]]] ende = true if coords_s.include?([new_x, new_y]) end end # only the newest ways will be used l = way_z.last.length way_z.each do |way| way_z -= [way] if way.length < l end break if ende end #--------------------------------------------------------------------------- # puts both ways together #--------------------------------------------------------------------------- way_s.each do |s| way_z.each do |z| if s.include?(z.last) if $pixelmovement.isometric w_s = [[@x / 2 * 2, @y]] + s w_z = [[target_x_o / 2 * 2, target_y_o]] + z else w_s = [[@x, @y]] + s w_z = [[target_x_o, target_y_o]] + z end return w_s - [w_s.last] + w_z.reverse end end end end #----------------------------------------------------------------------------- # fast Pathfinding (see below to get how it works exactly) #----------------------------------------------------------------------------- def path_fast (start_x, start_y, target_x, target_y, steps) #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- @coords = [] # waypoint way_old = nil start_x = start_x / steps * steps start_y = start_y / steps * steps target_x = target_x / steps * steps target_y = target_y / steps * steps # creates way if $pixelmovement.isometric target_x = target_x / 2 * 2 @way = Path.new(start_x / 2 * 2, start_y, []) @coords += [[start_x / 2 * 2, start_y]] else @way = Path.new(start_x, start_y, []) @coords += [[start_x, start_y]] end #--------------------------------------------------------------------------- # Loops until target is found #--------------------------------------------------------------------------- counter = 0 loop do # adds a possible way way_old = @way self.add_ways(steps, target_x, target_y) counter += 1 if counter % 128 == 0 Graphics.update # deletes unusable things for i in 1..9 self.delete_unusable(i,10 - i, 8) end end # if no direction is possible anymore, one step back if way_old == @way if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps 1.times do case @way.path.last when 1 @way.x += steps_x @way.y -= steps_y when 2 @way.y -= steps_y when 3 @way.x -= steps_x @way.y -= steps_y when 4 @way.x += steps_x when 6 @way.x -= steps_x when 7 @way.x += steps_x @way.y += steps_y when 8 @way.y += steps_y when 9 @way.x -= steps_x @way.y += steps_y end @way.path.pop end end # If target is found if @coords.include?([target_x, target_y]) or counter == 512 return @way.path 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(steps, 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, steps) elsif self.go_right_down(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end elsif self.go_left_up(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end else self.go_right_up(target_x, target_y, steps) while (not self.go_left_down(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end end elsif @way.x < target_x # right/down if self.go_right_down(target_x, target_y, steps) elsif self.go_left_down(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end elsif self.go_right_up(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end else self.go_left_up(target_x, target_y, steps) while (not self.go_right_down(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end end else # down if self.go_down(target_x, target_y, steps) elsif self.go_left(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) do end elsif self.go_right(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end else self.go_up(target_x, target_y, steps) while (not self.go_down(target_x, target_y, steps)) and self.go_up(target_x, target_y, steps) 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, steps) elsif self.go_left_down(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end elsif self.go_right_up(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_right_up(target_x, target_y, steps) do end else self.go_right_down(target_x, target_y, steps) while (not self.go_left_up(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end end elsif @way.x < target_x # right/up if self.go_right_up(target_x, target_y, steps) elsif self.go_left_up(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_left_up(target_x, target_y, steps) do end elsif self.go_right_down(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_right_down(target_x, target_y, steps) do end else self.go_left_down(target_x, target_y, steps) while (not self.go_right_up(target_x, target_y, steps)) and self.go_left_down(target_x, target_y, steps) do end end else # up if self.go_up(target_x, target_y, steps) elsif self.go_right(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end elsif self.go_left(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) do end else self.go_down(target_x, target_y, steps) while (not self.go_up(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end end end elsif @way.x > target_x # left if self.go_left(target_x, target_y, steps) elsif self.go_up(target_x, target_y, steps) while (not self.go_left(target_x, target_y,steps)) and self.go_up(target_x, target_y, steps) do end elsif self.go_down(target_x, target_y, steps) while (not self.go_left(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end else self.go_right(target_x, target_y, steps) while (not self.go_left(target_x, target_y, steps)) and self.go_right(target_x, target_y, steps) do end end elsif @way.x < target_x # right if self.go_right(target_x, target_y, steps) elsif self.go_up(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_up(target_x, target_y, steps) do end elsif self.go_down(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_down(target_x, target_y, steps) do end else self.go_left(target_x, target_y, steps) while (not self.go_right(target_x, target_y, steps)) and self.go_left(target_x, target_y, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x, @way.y - steps_y, 8, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x, @way.y + steps_y, 2, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x, @way.y - steps_y, 8, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x, @way.y + steps_y, 2, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x - steps_x, @way.y, 4, steps) if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x + steps_x, @way.y, 6, steps) if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x, @way.y - steps_y, 8, steps) if not self.add_way(@way.x - steps_x, @way.y - steps_y, 7, steps) if not self.add_way(@way.x + steps_x, @way.y - steps_y, 9, steps) 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) if $pixelmovement.isometric steps_x = steps * 2 else steps_x = steps end steps_y = steps if not self.add_way(@way.x, @way.y + steps_y, 2, steps) if not self.add_way(@way.x - steps_x, @way.y + steps_y, 1, steps) if not self.add_way(@way.x + steps_x, @way.y + steps_y, 3, steps) 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, steps) if self.passable?(@way.x, @way.y, d, steps) and not @coords.include?([x, y]) @way = 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 Path attr_accessor :x attr_accessor :y attr_accessor :path def initialize (x, y, path) @x = x @y = y @path = path end end #=============================================================================== # Class for the Caterpillar Characters #=============================================================================== class Game_Party_Actor < Game_Character attr_accessor :sprite attr_accessor :real_x attr_accessor :real_y attr_accessor :move_list attr_accessor :start_time #----------------------------------------------------------------------------- # initialising method #----------------------------------------------------------------------------- def initialize(id) super() self.moveto($game_player.x, $game_player.y) @through = true @start_time = 0 @id = id @move_list = [] @character_name = $game_party.actors[id - 1].character_name if @id > 1 # sets size if @character_name != '' char_bit = Bitmap.new(name = 'Graphics/Characters/' + @character_name) bla = [char_bit.width / $game_player.frame_number / 4, char_bit.height / $game_player.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 $game_map.valid?(x, y) end #----------------------------------------------------------------------------- # update method #----------------------------------------------------------------------------- def update super @walk_anime = true # move speed is equal to players move speed @move_speed = $game_player.move_speed # first caterpillar is equal to the hero if @id > 1 # Moves if not self.moving? and not self.jumping? and @move_list.length > 0 and @start_time <= Graphics.frame_count if @move_list[0][2] != nil if @move_list[0][2] == 'sl' self.find_path (@move_list[0][0], @move_list[0][1], true, true) @walk_anime = false else self.jump(@move_list[0][0] - @x, @move_list[0][1] - @y, @move_list[0][2] / 2) end elsif @move_list[0][0] != @x or @move_list[0][1] != @y self.find_path (@move_list[0][0],@move_list[0][1], true, true) end @move_list.delete_at(0) end #stops if (@move_list == [] and $game_player.path_steps == 0) @start_time = Graphics.frame_count + (@id - 1) * $pixelmovement.cater_distance / @move_speed end else @x = $game_player.x @y = $game_player.y end end alias pixel_cater_go_path go_path if not $pixelmovement.pixel_aliasing def go_path if @start_time > Graphics.frame_count or (not $game_player.last_moving and @start_time != 0 and @start_time != (@id - 1) * $pixelmovement.cater_distance / @move_speed and not $pixelmovement.cater_overlap) return end pixel_cater_go_path 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) #--------------------------------------------------------------------------- # sets Corner + creates viewport #--------------------------------------------------------------------------- case $pixelmovement.minimap_pos when 1 #1 = upper left corner @viewport = Viewport.new(0, 0, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 2 #2 = upper right @viewport = Viewport.new(640 - $pixelmovement.minimap_width, 0, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 3 #3 = lower left @viewport = Viewport.new(0, 480 - $pixelmovement.minimap_height, $pixelmovement.minimap_width, $pixelmovement.minimap_height) when 4 #4 = lower right @viewport = Viewport.new(640 - $pixelmovement.minimap_width, 480 - $pixelmovement.minimap_height, $pixelmovement.minimap_width, $pixelmovement.minimap_height) end #--------------------------------------------------------------------------- # initialising #--------------------------------------------------------------------------- @minimap_collision = $pixelmovement.minimap_collision @viewport.z = 500 @map = RPG::Sprite.new(@viewport) @map.z = 2500 @cursor = RPG::Sprite.new(@viewport) @cursor.z = 2520 @rahmen = RPG::Sprite.new(@viewport) @rahmen.z = 2530 tiles = [] width = [$pixelmovement.minimap_width, ($game_map.width * 32) / $pixelmovement.minimap_scale].min height = [$pixelmovement.minimap_height, ($game_map.height * 32) / $pixelmovement.minimap_scale].min @rahmen.bitmap = Bitmap.new(width, height) @rahmen.x = 0 @rahmen.y = 0 @cursor_zoom = ($pixelmovement.minimap_scale + 1) / 2 # draws border for x in 0..(@rahmen.bitmap.width - 1) @rahmen.bitmap.set_pixel(x, 0, Color.new(0, 0, 0)) @rahmen.bitmap.set_pixel(x, @rahmen.bitmap.height - 1, Color.new(0, 0, 0)) end for y in 0..(@rahmen.bitmap.height - 1) @rahmen.bitmap.set_pixel(0, y, Color.new(0, 0, 0)) @rahmen.bitmap.set_pixel(@rahmen.bitmap.width - 1, y, Color.new(0, 0, 0)) end if @minimap != nil @map.bitmap = @minimap # Collsion Minimap from Map? elsif @minimap_collision @map.bitmap = RPG::Cache.collision_map($game_map.map_id.to_s) end #--------------------------------------------------------------------------- # creates minimap? #--------------------------------------------------------------------------- # Collision Minimap from Map! if @map.bitmap != nil bit = Bitmap.new(@map.bitmap.width / $pixelmovement.minimap_scale, @map.bitmap.height / $pixelmovement.minimap_scale) bit.stretch_blt(bit.rect, @map.bitmap, @map.bitmap.rect) @map.bitmap = bit # Else else @map.bitmap = Bitmap.new(($game_map.width * 32) / $pixelmovement.minimap_scale, ($game_map.height * 32) / $pixelmovement.minimap_scale) #Collision Minimap from Tileset? if @minimap_collision 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 #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 for y in 0..$game_map.height for layer in 0..2 pos = $game_map.data[x, y, layer] pos = 0 if pos == nil if pos >= 384 pos -= 384 sy = (pos / 8) * 32 sx = (pos % 8) * 32 src_rect = Rect.new(sx, sy, 32, 32) dest_rect = Rect.new(x * 32 / $pixelmovement.minimap_scale, y * 32/ $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale) if (not @minimap_collision) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) != Color.new(0, 0, 0) and $game_map.priorities[$game_map.data[x, y, layer]] == 0) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) == Color.new(0, 0, 0) and layer == 1 and $game_map.data[x, y, layer] != 0 and $game_map.priorities[$game_map.data[x, y, layer]] == 0) @map.bitmap.stretch_blt(dest_rect, tiles[0], src_rect) end elsif pos >= 48 nr = pos / 48 pos = pos % 48 sy = (pos / 8) * 32 sx = (pos % 8) * 32 src_rect = Rect.new(sx, sy, 32, 32) dest_rect = Rect.new(x * 32 / $pixelmovement.minimap_scale, y * 32/ $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale, 32 / $pixelmovement.minimap_scale) if (not @minimap_collision) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) != Color.new(0, 0, 0, 255) and $game_map.priorities[$game_map.data[x, y, layer]] == 0) or (@map.bitmap.get_pixel(dest_rect.x, dest_rect.y) == Color.new(0, 0, 0, 255) and layer == 1 and $game_map.data[x, y, layer] != 0 and $game_map.priorities[$game_map.data[x, y, layer]] == 0) @map.bitmap.stretch_blt(dest_rect, tiles[nr], src_rect) end end end end end end #--------------------------------------------------------------------------- # colours, etc. #--------------------------------------------------------------------------- @map.opacity = 0 @rahmen.opacity = 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 0..@map.bitmap.width for y in 0..@map.bitmap.height 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 self.set_chars(set) #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 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 end #----------------------------------------------------------------------------- # creates characters on minimap #----------------------------------------------------------------------------- def set_chars(set) #disposes chars, if they already exist @chars.each {|cha| cha.dispose} if @chars != nil @chars = [] # no chars on collision minimap return if @minimap_collision # draw Chars set.character_sprites.each do |char| #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(0,0,char.src_rect.width / $pixelmovement.minimap_scale * @cursor_zoom, char.src_rect.height / $pixelmovement.minimap_scale * @cursor_zoom) #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(0, 0, 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 do |char| char.dispose end @rahmen.dispose end #----------------------------------------------------------------------------- # updates minimap #----------------------------------------------------------------------------- def update #--------------------------------------------------------------------------- # 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 #--------------------------------------------------------------------------- # Map update #--------------------------------------------------------------------------- # horizontal movement of the minimap # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @map.x = 0 else @map.x = - $game_map.display_x / 4 / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width @map.x -= (304 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2)) / $pixelmovement.minimap_scale if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @map.x = 0 elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @map.x = - @map.bitmap.width + $pixelmovement.minimap_width end end end #vertical movement of the minimap # Map is smaller than Minimap if @map.bitmap.height <= $pixelmovement.minimap_height @map.y = 0 else @map.y = - $game_map.display_y / 4 / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height @map.y -= (224 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2))/ $pixelmovement.minimap_scale if $game_player.y <= 480 * ($pixelmovement.minimap_scale/ (480.0 / $pixelmovement.minimap_height) / 2) @map.y = 0 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @map.y = - @map.bitmap.height + $pixelmovement.minimap_height end end end # looped map if $pixelmovement.loop_maps.include?($game_map.map_id) @map.x -= @map.bitmap.width / 3 @map.y -= @map.bitmap.height / 3 end #--------------------------------------------------------------------------- # Cursor Update #--------------------------------------------------------------------------- # returns if no chararacter sprites are drawn on the map return if $scene.spriteset.character_sprites.last.disposed? # 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 # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @cursor.x = ($game_player.x + 16) / $pixelmovement.minimap_scale else @cursor.x = $game_player.screen_x/ (640 / $pixelmovement.minimap_width) unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @cursor.x = $game_player.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width)) elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @cursor.x = $pixelmovement.minimap_width - (@map.bitmap.width - $game_player.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width))) end end end #vertical # Map is smaller than minimap if @map.bitmap.height <= $pixelmovement.minimap_height @cursor.y = ($game_player.y + 32) / $pixelmovement.minimap_scale else @cursor.y = $game_player.screen_y / (480 / $pixelmovement.minimap_height) unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height if $game_player.y <= 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @cursor.y = $game_player.y / (480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height)) + @cursor.src_rect.height / 2 + 4 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale/ (480.0 / $pixelmovement.minimap_height) / 2) @cursor.y = $pixelmovement.minimap_height - (@map.bitmap.height - $game_player.y/(480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height))) + 6 end end 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 #--------------------------------------------------------------------------- # Chars are Updated #--------------------------------------------------------------------------- for i in 0..(@chars.length - 1) # sprite isnt update if character isnt on the screen next if not $scene.spriteset.character_sprites[i].character.in_range? # updates sprite @chars[i].src_rect.set($scene.spriteset.character_sprites[i].src_rect.x / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.y / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.width / $pixelmovement.minimap_scale, $scene.spriteset.character_sprites[i].src_rect.height / $pixelmovement.minimap_scale) char = $scene.spriteset.character_sprites[i] if char == nil next else char = char.character end # horizontal # Map is smaller than Minimap if @map.bitmap.width <= $pixelmovement.minimap_width @chars[i].x = (char.x + 16) / $pixelmovement.minimap_scale else @chars[i].x = char.screen_x / $pixelmovement.minimap_scale unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 640 / $pixelmovement.minimap_width @chars[i].x -= (304 - 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2))/ $pixelmovement.minimap_scale if $game_player.x <= 640 * ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width) / 2) @chars[i].x = char.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width)) + @chars[i].src_rect.width / 2 elsif $game_player.x >= $game_map.width * 32 - 640 * ($pixelmovement.minimap_scale/ (640.0 / $pixelmovement.minimap_width) / 2) @chars[i].x = $pixelmovement.minimap_width - (@map.bitmap.width - char.x / (640 / $pixelmovement.minimap_width) / ($pixelmovement.minimap_scale / (640.0 / $pixelmovement.minimap_width))) + @chars[i].src_rect.width / 2 end end end # vertical # Map is smaller than minimap if @map.bitmap.height <= $pixelmovement.minimap_height @chars[i].y = (char.y + 32) / $pixelmovement.minimap_scale else @chars[i].y = char.screen_y / $pixelmovement.minimap_scale # Normal unless $pixelmovement.loop_maps.include?($game_map.map_id) or $pixelmovement.minimap_scale == 480 / $pixelmovement.minimap_height @chars[i].y -= (224 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2)) / $pixelmovement.minimap_scale if $game_player.y <= 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @chars[i].y = char.y/(480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height)) + @chars[i].src_rect.height - 4 elsif $game_player.y >= $game_map.height * 32 - 480 * ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height) / 2) @chars[i].y = $pixelmovement.minimap_height - (@map.bitmap.height - char.y/ (480 / $pixelmovement.minimap_height) / ($pixelmovement.minimap_scale / (480.0 / $pixelmovement.minimap_height))) + @chars[i].src_rect.height - 4 end end 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 @chars[i].opacity = $pixelmovement.minimap_opacity end @map.opacity = $pixelmovement.minimap_opacity @rahmen.opacity = $pixelmovement.minimap_opacity @cursor.opacity = $pixelmovement.minimap_opacity 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 the directions (4/8): $pixelmovement.direction_number = 4 # Order+ Numbers of the directions: $pixelmovement.direction_array = [] # Number of Frames for the Player Sprite: $pixelmovement.player_frame_number = nil # Number of Directions for the Player Sprite: $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 #------------------------------------------------------------------------------- # Distance in Px: $pixelmovement.cater_distance = 32 # Switch for the Caterpillar Script: $pixelmovement.switch_caterpillar(true) # Switch for Caterpillar Overlapping: $pixelmovement.switch_cater_overlap(false) #------------------------------------------------------------------------------- # Size of Player Event: $pixelmovement.player_size = [12, 8] # Correction of the Event Sizes: $pixelmovement.event_size_add = 0 #------------------------------------------------------------------------------- # 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 # Scale: $pixelmovement.minimap_scale = 4.0 # Minimap Opacity: $pixelmovement.minimap_opacity = 0 # 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(true) # 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(false) #------------------------------------------------------------------------------- # dont change this, its used to prevent that methods are aliased more than once $pixelmovement.pixel_aliasing = true end #------------------------------------------------------------------------------- # End SDK Enabled Test #-------------------------------------------------------------------------------[/spoiler] That's the whole script I'm using now... I'm looking for anything that says update or party update or something. 1.6 of this script works flawlessly [i]but[/i] unfortunately I can't use this awesome side-view battle system. Unless someone has an updated one that works with Fotz!baerchen 1.6 pixelmovement+caterpillar script.
  7. http://www.youtube.com/watch?v=AS0b7ALXuL0 this video explains my problems. I want the caterpillar system to update on screen when I add/remove party members.
×
×
  • Create New...