设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 937|回复: 9
打印 上一主题 下一主题

有谁可以帮我把脚本汉(在外国拿来的)

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
跳转到指定楼层
1
发表于 2008-8-13 18:30:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
顺便把学脚本的地址给我

  1. class Game_Map
  2.   attr_accessor :tileset_name
  3.   attr_accessor :autotile_names
  4.   attr_accessor :panorama_name
  5.   attr_accessor :panorama_hue
  6.   attr_accessor :fog_name               
  7.   attr_accessor :fog_hue               
  8.   attr_accessor :fog_opacity            
  9.   attr_accessor :fog_blend_type         
  10.   attr_accessor :fog_zoom            
  11.   attr_accessor :fog_sx              
  12.   attr_accessor :fog_sy         
  13.   attr_accessor :battleback_name   
  14.   attr_accessor :display_x         
  15.   attr_accessor :display_y      
  16.   attr_accessor :need_refresh   
  17.   attr_reader   :passages      
  18.   attr_reader   :priorities      
  19.   attr_reader   :terrain_tags   
  20.   attr_reader   :events         
  21.   attr_reader   :fog_ox           
  22.   attr_reader   :fog_oy         
  23.   attr_reader   :fog_tone        
  24.   attr_reader   :mapsInRange
  25.   def initialize
  26.     @map_id = 0
  27.     @display_x = 0
  28.     @display_y = 0
  29.   end
  30.   def setup(map_id)
  31.     @map_id = map_id
  32.     @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
  33.     tileset = $data_tilesets[@map.tileset_id]
  34.     @tileset_name = tileset.tileset_name
  35.     @autotile_names = tileset.autotile_names
  36.     @panorama_name = tileset.panorama_name
  37.     @panorama_hue = tileset.panorama_hue
  38.     @fog_name = tileset.fog_name
  39.     @fog_hue = tileset.fog_hue
  40.     @fog_opacity = tileset.fog_opacity
  41.     @fog_blend_type = tileset.fog_blend_type
  42.     @fog_zoom = tileset.fog_zoom
  43.     @fog_sx = tileset.fog_sx
  44.     @fog_sy = tileset.fog_sy
  45.     @battleback_name = tileset.battleback_name
  46.     @passages = tileset.passages
  47.     @priorities = tileset.priorities
  48.     @terrain_tags = tileset.terrain_tags
  49.     self.display_x = 0
  50.     self.display_y = 0
  51.     @need_refresh = false
  52.     Events.onMapCreate.trigger(self,map_id, @map, tileset)
  53.     @events = {}
  54.     for i in @map.events.keys
  55.       @events[i] = Game_Event.new(@map_id, @map.events[i],self)
  56.     end
  57.     @common_events = {}
  58.     for i in 1...$data_common_events.size
  59.       @common_events[i] = Game_CommonEvent.new(i)
  60.     end
  61.     @fog_ox = 0
  62.     @fog_oy = 0
  63.     @fog_tone = Tone.new(0, 0, 0, 0)
  64.     @fog_tone_target = Tone.new(0, 0, 0, 0)
  65.     @fog_tone_duration = 0
  66.     @fog_opacity_duration = 0
  67.     @fog_opacity_target = 0
  68.     @scroll_direction = 2
  69.     @scroll_rest = 0
  70.     @scroll_speed = 4
  71.   end
  72.   def map_id
  73.     return @map_id
  74.   end
  75.   def width
  76.     return @map.width
  77.   end
  78.   def height
  79.     return @map.height
  80.   end
  81.   def encounter_list
  82.     return @map.encounter_list
  83.   end
  84.   def encounter_step
  85.     return @map.encounter_step
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● マップデータの取得
  89.   #--------------------------------------------------------------------------
  90.   def data
  91.     return @map.data
  92.   end
  93.   def autoplayAsCue
  94.     if @map.autoplay_bgm # Checks whether the map has an autoplay BGM
  95.       if (Time.now.hour<6||Time.now.hour>=20) &&  # Checks if it's night time - the values are editable
  96.             FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
  97.           # Checks whether a BGM file with the filename [normal BGM]n exists
  98.         pbCueBGM(
  99.           RPG::AudioFile.new(@map.bgm.name+"n",
  100.              @map.bgm.volume,@map.bgm.pitch),1.0) # Plays it
  101.       else
  102.         pbCueBGM(@map.bgm,1.0) # Plays the normal BGM
  103.       end
  104.     end
  105.     if @map.autoplay_bgs
  106.       $game_system.bgs_play(@map.bgs)
  107.     end
  108.   end
  109.   def autoplay
  110.     if @map.autoplay_bgm # Checks whether the map has an autoplay BGM
  111.       if (Time.now.hour<6||Time.now.hour>=20) &&  # Checks if it's night time - the values are editable
  112.             FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
  113.           # Checks whether a BGM file with the filename [normal BGM]n exists
  114.         $game_system.bgm_play(@map.bgm.name+"n",
  115.             @map.bgm.volume,@map.bgm.pitch) # Plays it
  116.       else
  117.         $game_system.bgm_play(@map.bgm) # Plays the normal BGM
  118.       end
  119.     end
  120.     if @map.autoplay_bgs
  121.       $game_system.bgs_play(@map.bgs)
  122.     end
  123.   end
  124.   def refresh
  125.     if @map_id > 0
  126.       for event in @events.values
  127.         event.refresh
  128.       end
  129.       for common_event in @common_events.values
  130.         common_event.refresh
  131.       end
  132.     end
  133.     @need_refresh = false
  134.   end
  135.   def scroll_down(distance)
  136.     @display_y = [@display_y + distance, (self.height - 15) * 128].min
  137.   end
  138.   def scroll_left(distance)
  139.     @display_x = [@display_x - distance, 0].max
  140.   end
  141.   def scroll_right(distance)
  142.     @display_x = [@display_x + distance, (self.width - 20) * 128].min
  143.   end
  144.   def scroll_up(distance)
  145.     @display_y = [@display_y - distance, 0].max
  146.   end
  147.   def valid?(x, y)
  148.      return (x >= 0 and x < width and y >= 0 and y < height)
  149.   end
  150.   def validLax?(x, y)
  151.     return (x >=-10 and x <= width+10 and y >=-10 and y <= height+10)
  152.   end
  153.   def passable?(x, y, d, self_event = nil)
  154.     return false if !valid?(x, y)
  155.     bit = (1 << (d / 2 - 1)) & 0x0f
  156.     for event in events.values
  157.       if event.tile_id >= 0 and event != self_event and
  158.          event.x == x and event.y == y and not event.through
  159.         return false if @passages[event.tile_id] & bit != 0
  160.         return false if @passages[event.tile_id] & 0x0f == 0x0f
  161.         return true if @priorities[event.tile_id] == 0
  162.       end
  163.     end
  164.     for i in [2, 1, 0]
  165.       tile_id = data[x, y, i]
  166.       if tile_id == nil
  167.         return false
  168.       # Make water tiles passable if player is surfing
  169.       elsif pbIsPassableWaterTag?(@terrain_tags[tile_id]) &&
  170.         $PokemonGlobal.surfing
  171.         return true
  172.       elsif @passages[tile_id] & bit != 0
  173.         return false
  174.       elsif @passages[tile_id] & 0x0f == 0x0f
  175.         return false
  176.       elsif @priorities[tile_id] == 0
  177.         return true
  178.       end
  179.     end
  180.     return true
  181.   end
  182.   def passableStrict?(x, y, d, self_event = nil)
  183.     return false if !valid?(x, y)
  184.     for event in events.values
  185.       if event.tile_id >= 0 and event != self_event and
  186.          event.x == x and event.y == y and not event.through
  187.         return false if @passages[event.tile_id] & 0x0f !=0
  188.         return true if @priorities[event.tile_id] == 0
  189.       end
  190.     end
  191.     for i in [2, 1, 0]
  192.       tile_id = data[x, y, i]
  193.       return false if tile_id == nil
  194.       return false if @passages[tile_id] & 0x0f !=0
  195.       return true if @priorities[tile_id] == 0
  196.     end
  197.     return true
  198.   end
  199.   def bush?(x, y)
  200.     if @map_id != 0
  201.       for i in [2, 1, 0]
  202.         tile_id = data[x, y, i]
  203.         if tile_id == nil
  204.           return false
  205.         elsif @passages[tile_id] & 0x40 == 0x40
  206.           return true
  207.         end
  208.       end
  209.     end
  210.     return false
  211.   end
  212.   def counter?(x, y)
  213.     if @map_id != 0
  214.       for i in [2, 1, 0]
  215.         tile_id = data[x, y, i]
  216.         if tile_id == nil
  217.           return false
  218.         elsif @passages[tile_id] && @passages[tile_id] & 0x80 == 0x80
  219.           return true
  220.         end
  221.       end
  222.     end
  223.     return false
  224.   end
  225.   def terrain_tag(x, y)
  226.     if @map_id != 0
  227.       for i in [2, 1, 0]
  228.         tile_id = data[x, y, i]
  229.         if tile_id == nil
  230.           return 0
  231.         elsif @terrain_tags[tile_id] && @terrain_tags[tile_id] > 0
  232.           return @terrain_tags[tile_id]
  233.         end
  234.       end
  235.     end
  236.     return 0
  237.   end
  238.   def check_event(x, y)
  239.     for event in self.events.values
  240.       if event.x == x and event.y == y
  241.         return event.id
  242.       end
  243.     end
  244.   end
  245.   def start_scroll(direction, distance, speed)
  246.     @scroll_direction = direction
  247.     @scroll_rest = distance * 128
  248.     @scroll_speed = speed
  249.   end
  250.   def scrolling?
  251.     return @scroll_rest > 0
  252.   end
  253.   def start_fog_tone_change(tone, duration)
  254.     @fog_tone_target = tone.clone
  255.     @fog_tone_duration = duration
  256.     if @fog_tone_duration == 0
  257.       @fog_tone = @fog_tone_target.clone
  258.     end
  259.   end
  260.   def start_fog_opacity_change(opacity, duration)
  261.     @fog_opacity_target = opacity * 1.0
  262.     @fog_opacity_duration = duration
  263.     if @fog_opacity_duration == 0
  264.       @fog_opacity = @fog_opacity_target
  265.     end
  266.   end
  267.   
  268.   def in_range?(object)
  269.     return true if $PokemonSystem.tilemap==2
  270.     screne_x = display_x
  271.     screne_x -= 256
  272.     screne_y = display_y
  273.     screne_y -= 256
  274.     screne_width = display_x
  275.     screne_width += Graphics.width*4+256 # 2816
  276.     screne_height = display_y
  277.     screne_height += Graphics.height*4+256 # 2176
  278.     return false if object.real_x <= screne_x
  279.     return false if object.real_x >= screne_width
  280.     return false if object.real_y <= screne_y
  281.     return false if object.real_y >= screne_height
  282.     return true
  283.   end
  284.   
  285.   def update
  286.     if $MapFactory
  287.       for i in $MapFactory.maps
  288.         i.refresh if i.need_refresh
  289.       end
  290.       $MapFactory.setCurrentMap
  291.     end
  292.     if @scroll_rest > 0
  293.       distance = 2 ** @scroll_speed
  294.       case @scroll_direction
  295.       when 2
  296.         scroll_down(distance)
  297.       when 4
  298.         scroll_left(distance)
  299.       when 6
  300.         scroll_right(distance)
  301.       when 8
  302.         scroll_up(distance)
  303.       end
  304.       @scroll_rest -= distance
  305.     end
  306.     for event in @events.values
  307.       if in_range?(event) or event.trigger == 3 or event.trigger == 4
  308.         event.update
  309.       end
  310.     end
  311.     for common_event in @common_events.values
  312.       common_event.update
  313.     end
  314.     @fog_ox -= @fog_sx / 8.0
  315.     @fog_oy -= @fog_sy / 8.0
  316.     if @fog_tone_duration >= 1
  317.       d = @fog_tone_duration
  318.       target = @fog_tone_target
  319.       @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
  320.       @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
  321.       @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
  322.       @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
  323.       @fog_tone_duration -= 1
  324.     end
  325.     if @fog_opacity_duration >= 1
  326.       d = @fog_opacity_duration
  327.       @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
  328.       @fog_opacity_duration -= 1
  329.     end
  330.   end
  331. end



  332. class Game_Map
  333.   def name
  334.     return pbGetMessage(MessageTypes::MapNames,self.map_id)
  335.   end
  336. end
复制代码

此贴于 2008-8-15 20:33:31 被版主darkten提醒,请楼主看到后对本贴做出回应。
本贴由论坛斑竹havealook结贴,如楼主认为问题未解决,请重新将此贴编辑为“有事请教”,并回帖叙述疑点即可~ ^-^

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
2
 楼主| 发表于 2008-8-13 18:31:15 | 只看该作者

  1. class Game_Character
  2.   def move_down(turn_enabled = true)
  3.     if turn_enabled
  4.       turn_down
  5.     end
  6.     if passable?(@x, @y, 2)
  7.       turn_down
  8.       @y += 1
  9.       increase_steps
  10.     else
  11.       check_event_trigger_touch(@x, @y+1)
  12.     end
  13.   end
  14.   def move_left(turn_enabled = true)
  15.     if turn_enabled
  16.       turn_left
  17.     end
  18.     if passable?(@x, @y, 4)
  19.       turn_left
  20.       @x -= 1
  21.       increase_steps
  22.     else
  23.       check_event_trigger_touch(@x-1, @y)
  24.     end
  25.   end
  26.   def move_right(turn_enabled = true)
  27.     if turn_enabled
  28.       turn_right
  29.     end
  30.     if passable?(@x, @y, 6)
  31.       turn_right
  32.       @x += 1
  33.       increase_steps
  34.     else
  35.       check_event_trigger_touch(@x+1, @y)
  36.     end
  37.   end
  38.   def move_up(turn_enabled = true)
  39.     if turn_enabled
  40.       turn_up
  41.     end
  42.     if passable?(@x, @y, 8)
  43.       turn_up
  44.       @y -= 1
  45.       increase_steps
  46.     else
  47.       check_event_trigger_touch(@x, @y-1)
  48.     end
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 左下に移動
  52.   #--------------------------------------------------------------------------
  53.   def move_lower_left
  54.     unless @direction_fix
  55.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  56.     end
  57.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  58.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  59.       @x -= 1
  60.       @y += 1
  61.       increase_steps
  62.     end
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● 右下に移動
  66.   #--------------------------------------------------------------------------
  67.   def move_lower_right
  68.     unless @direction_fix
  69.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  70.     end
  71.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  72.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  73.       @x += 1
  74.       @y += 1
  75.       increase_steps
  76.     end
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # ● 左上に移動
  80.   #--------------------------------------------------------------------------
  81.   def move_upper_left
  82.     # 向き固定でない場合
  83.     unless @direction_fix
  84.       # 右向きだった場合は左を、下向きだった場合は上を向く
  85.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  86.     end
  87.     # 上→左、左→上 のどちらかのコースが通行可能な場合
  88.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  89.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  90.       # 座標を更新
  91.       @x -= 1
  92.       @y -= 1
  93.       # 歩数増加
  94.       increase_steps
  95.     end
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 右上に移動
  99.   #--------------------------------------------------------------------------
  100.   def move_upper_right
  101.     # 向き固定でない場合
  102.     unless @direction_fix
  103.       # 左向きだった場合は右を、下向きだった場合は上を向く
  104.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  105.     end
  106.     # 上→右、右→上 のどちらかのコースが通行可能な場合
  107.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  108.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  109.       # 座標を更新
  110.       @x += 1
  111.       @y -= 1
  112.       # 歩数増加
  113.       increase_steps
  114.     end
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● ランダムに移動
  118.   #--------------------------------------------------------------------------
  119.   def move_random
  120.     case rand(4)
  121.     when 0  # 下に移動
  122.       move_down(false)
  123.     when 1  # 左に移動
  124.       move_left(false)
  125.     when 2  # 右に移動
  126.       move_right(false)
  127.     when 3  # 上に移動
  128.       move_up(false)
  129.     end
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● プレイヤーに近づく
  133.   #--------------------------------------------------------------------------
  134.   def move_toward_player
  135.     # プレイヤーの座標との差を求める
  136.     sx = @x - $game_player.x
  137.     sy = @y - $game_player.y
  138.     # 座標が等しい場合
  139.     if sx == 0 and sy == 0
  140.       return
  141.     end
  142.     # 差の絶対値を求める
  143.     abs_sx = sx.abs
  144.     abs_sy = sy.abs
  145.     # 横の距離と縦の距離が等しい場合
  146.     if abs_sx == abs_sy
  147.       # ランダムでどちらかを 1 増やす
  148.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  149.     end
  150.     # 横の距離のほうが長い場合
  151.     if abs_sx > abs_sy
  152.       # 左右方向を優先し、プレイヤーのいるほうへ移動
  153.       sx > 0 ? move_left : move_right
  154.       if not moving? and sy != 0
  155.         sy > 0 ? move_up : move_down
  156.       end
  157.     # 縦の距離のほうが長い場合
  158.     else
  159.       # 上下方向を優先し、プレイヤーのいるほうへ移動
  160.       sy > 0 ? move_up : move_down
  161.       if not moving? and sx != 0
  162.         sx > 0 ? move_left : move_right
  163.       end
  164.     end
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # ● プレイヤーから遠ざかる
  168.   #--------------------------------------------------------------------------
  169.   def move_away_from_player
  170.     # プレイヤーの座標との差を求める
  171.     sx = @x - $game_player.x
  172.     sy = @y - $game_player.y
  173.     # 座標が等しい場合
  174.     if sx == 0 and sy == 0
  175.       return
  176.     end
  177.     # 差の絶対値を求める
  178.     abs_sx = sx.abs
  179.     abs_sy = sy.abs
  180.     # 横の距離と縦の距離が等しい場合
  181.     if abs_sx == abs_sy
  182.       # ランダムでどちらかを 1 増やす
  183.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  184.     end
  185.     # 横の距離のほうが長い場合
  186.     if abs_sx > abs_sy
  187.       # 左右方向を優先し、プレイヤーのいないほうへ移動
  188.       sx > 0 ? move_right : move_left
  189.       if not moving? and sy != 0
  190.         sy > 0 ? move_down : move_up
  191.       end
  192.     # 縦の距離のほうが長い場合
  193.     else
  194.       # 上下方向を優先し、プレイヤーのいないほうへ移動
  195.       sy > 0 ? move_down : move_up
  196.       if not moving? and sx != 0
  197.         sx > 0 ? move_right : move_left
  198.       end
  199.     end
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # ● 一歩前進
  203.   #--------------------------------------------------------------------------
  204.   def move_forward
  205.     case @direction
  206.     when 2
  207.       move_down(false)
  208.     when 4
  209.       move_left(false)
  210.     when 6
  211.       move_right(false)
  212.     when 8
  213.       move_up(false)
  214.     end
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # ● 一歩後退
  218.   #--------------------------------------------------------------------------
  219.   def move_backward
  220.     # 向き固定の状態を記憶
  221.     last_direction_fix = @direction_fix
  222.     # 強制的に向き固定
  223.     @direction_fix = true
  224.     # 向きで分岐
  225.     case @direction
  226.     when 2  # 下
  227.       move_up(false)
  228.     when 4  # 左
  229.       move_right(false)
  230.     when 6  # 右
  231.       move_left(false)
  232.     when 8  # 上
  233.       move_down(false)
  234.     end
  235.     # 向き固定の状態を元に戻す
  236.     @direction_fix = last_direction_fix
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # ● ジャンプ
  240.   #     x_plus : X 座標加算値
  241.   #     y_plus : Y 座標加算値
  242.   #--------------------------------------------------------------------------
  243.   def jump(x_plus, y_plus)
  244.     # 加算値が (0,0) ではない場合
  245.     if x_plus != 0 or y_plus != 0
  246.       # 横の距離のほうが長い場合
  247.       if x_plus.abs > y_plus.abs
  248.         # 左右どちらかに向き変更
  249.         x_plus < 0 ? turn_left : turn_right
  250.       # 縦の距離のほうが長いか等しい場合
  251.       else
  252.         # 上下どちらかに向き変更
  253.         y_plus < 0 ? turn_up : turn_down
  254.       end
  255.     end
  256.     # 新しい座標を計算
  257.     new_x = @x + x_plus
  258.     new_y = @y + y_plus
  259.     # 加算値が (0,0) の場合か、ジャンプ先が通行可能な場合
  260.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  261.       # 姿勢を矯正
  262.       straighten
  263.       # 座標を更新
  264.       @x = new_x
  265.       @y = new_y
  266.       # 距離を計算
  267.       distance = x_plus * x_plus + y_plus * y_plus
  268.       # ジャンプカウントを設定
  269.       @jump_peak = 10 + distance - @move_speed
  270.       @jump_peak = @jump_peak.floor
  271.       @jump_count = @jump_peak * 2
  272.       # 停止カウントをクリア
  273.       @stop_count = 0
  274.       if self.is_a?(Game_Player)
  275.         self.pbJumpDependentEvents
  276.       end
  277.     end
  278.   end
  279.   def turnGeneric(dir)
  280.     unless @direction_fix
  281.       oldDirection=@direction
  282.       @direction=dir
  283.       @stop_count=0
  284.       if dir!=oldDirection
  285.         pbCheckEventTriggerAfterTurning
  286.       end
  287.     end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # ● 下を向く
  291.   #--------------------------------------------------------------------------
  292.   def turn_down; turnGeneric(2); end
  293.   def turn_left; turnGeneric(4); end
  294.   def turn_right; turnGeneric(6); end
  295.   def turn_up; turnGeneric(8); end
  296.   #--------------------------------------------------------------------------
  297.   # ● 右に 90 度回転
  298.   #--------------------------------------------------------------------------
  299.   def turn_right_90
  300.     case @direction
  301.     when 2
  302.       turn_left
  303.     when 4
  304.       turn_up
  305.     when 6
  306.       turn_down
  307.     when 8
  308.       turn_right
  309.     end
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # ● 左に 90 度回転
  313.   #--------------------------------------------------------------------------
  314.   def turn_left_90
  315.     case @direction
  316.     when 2
  317.       turn_right
  318.     when 4
  319.       turn_down
  320.     when 6
  321.       turn_up
  322.     when 8
  323.       turn_left
  324.     end
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # ● 180 度回転
  328.   #--------------------------------------------------------------------------
  329.   def turn_180
  330.     case @direction
  331.     when 2
  332.       turn_up
  333.     when 4
  334.       turn_right
  335.     when 6
  336.       turn_left
  337.     when 8
  338.       turn_down
  339.     end
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # ● 右か左に 90 度回転
  343.   #--------------------------------------------------------------------------
  344.   def turn_right_or_left_90
  345.     if rand(2) == 0
  346.       turn_right_90
  347.     else
  348.       turn_left_90
  349.     end
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # ● ランダムに方向転換
  353.   #--------------------------------------------------------------------------
  354.   def turn_random
  355.     case rand(4)
  356.     when 0
  357.       turn_up
  358.     when 1
  359.       turn_right
  360.     when 2
  361.       turn_left
  362.     when 3
  363.       turn_down
  364.     end
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ● プレイヤーの方を向く
  368.   #--------------------------------------------------------------------------
  369.   def turn_toward_player
  370.     # プレイヤーの座標との差を求める
  371.     sx = @x - $game_player.x
  372.     sy = @y - $game_player.y
  373.     # 座標が等しい場合
  374.     if sx == 0 and sy == 0
  375.       return
  376.     end
  377.     # 横の距離のほうが長い場合
  378.     if sx.abs > sy.abs
  379.       # 左右方向でプレイヤーのいるほうを向く
  380.       sx > 0 ? turn_left : turn_right
  381.     # 縦の距離のほうが長い場合
  382.     else
  383.       # 上下方向でプレイヤーのいるほうを向く
  384.       sy > 0 ? turn_up : turn_down
  385.     end
  386.   end
  387.   #--------------------------------------------------------------------------
  388.   # ● プレイヤーの逆を向く
  389.   #--------------------------------------------------------------------------
  390.   def turn_away_from_player
  391.     # プレイヤーの座標との差を求める
  392.     sx = @x - $game_player.x
  393.     sy = @y - $game_player.y
  394.     # 座標が等しい場合
  395.     if sx == 0 and sy == 0
  396.       return
  397.     end
  398.     # 横の距離のほうが長い場合
  399.     if sx.abs > sy.abs
  400.       # 左右方向でプレイヤーのいないほうを向く
  401.       sx > 0 ? turn_right : turn_left
  402.     # 縦の距離のほうが長い場合
  403.     else
  404.       # 上下方向でプレイヤーのいないほうを向く
  405.       sy > 0 ? turn_down : turn_up
  406.     end
  407.   end
  408. end
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
3
 楼主| 发表于 2008-8-13 18:31:36 | 只看该作者
  1. class Game_Event < Game_Character
  2.   attr_reader   :trigger               
  3.   attr_reader   :list                  
  4.   attr_reader   :starting               
  5.   attr_reader   :keypress  # Event triggered by a key press
  6.   attr_reader   :tempSwitches # Temporary self-switches
  7.   attr_accessor :need_refresh
  8.   def initialize(map_id, event, map=nil)
  9.     super(map)
  10.     @map_id = map_id
  11.     @event = event
  12.     @id = @event.id
  13.     @erased = false
  14.     @starting = false
  15.     @keypress=false
  16.     @need_refresh=false
  17.     @route_erased=false
  18.     @through = true
  19.     @tempSwitches={}
  20.     moveto(@event.x, @event.y) if map
  21.     refresh
  22.   end
  23.   def clear_starting
  24.     @starting = false
  25.   end
  26.   def over_trigger?
  27.     if @character_name != "" and not @through
  28.       return false
  29.     end
  30.     unless self.map.passable?(@x, @y, 0)
  31.       return false
  32.     end
  33.     return true
  34.   end
  35.   def start(keypress=false)
  36.     if @list.size > 1
  37.       @starting = true
  38.       @keypress=keypress
  39.     end
  40.   end
  41.   def erase
  42.     @erased = true
  43.     refresh
  44.   end
  45.   def erase_route
  46.     @route_erased=true
  47.     refresh
  48.   end
  49.   def name
  50.    return @event.name
  51.   end
  52.   def id
  53.    return @event.id
  54.   end
  55.   def pbCheckEventTriggerAfterTurning
  56.     if $game_system.map_interpreter.running?
  57.       return
  58.     end
  59.     if @event.name[/^Trainer\((\d+)\)$/]
  60.       distance=$~[1].to_i
  61.       if @trigger == 2 and pbEventCanReachPlayer?(self,$game_player,distance)
  62.          if not jumping? and not over_trigger?
  63.            start
  64.          end
  65.       end
  66.     end
  67.   end
  68.   def tsOn?(c)
  69.     return @tempSwitches && @tempSwitches[c]==true
  70.   end
  71.   def tsOff?(c)
  72.     return !@tempSwitches || !@tempSwitches[c]
  73.   end
  74.   def setTempSwitchOn(c)
  75.     @tempSwitches[c]=true   
  76.     refresh
  77.   end
  78.   def setTempSwitchOff(c)
  79.     @tempSwitches[c]=false
  80.     refresh
  81.   end
  82.   def variable
  83.     return nil if !$PokemonGlobal.eventvars
  84.     return $PokemonGlobal.eventvars[[@map_id,@event.id]]
  85.   end
  86.   def setVariable(variable)
  87.     $PokemonGlobal.eventvars[[@map_id,@event.id]]=variable
  88.   end
  89.   def varAsInt
  90.     return 0 if !$PokemonGlobal.eventvars
  91.     return $PokemonGlobal.eventvars[[@map_id,@event.id]].to_i
  92.   end
  93.   def expired?(secs=86400)
  94.     ontime=self.variable
  95.     return ontime && (Time.now.to_i>ontime+secs)
  96.   end
  97.   def onEvent?
  98.     return @map_id==$game_map.map_id &&
  99.        $game_player.x==self.x && $game_player.y==self.y
  100.   end
  101.   def isOff?(c)
  102.     return !$game_self_switches[[@map_id,@event.id,c]]
  103.   end
  104.   def switchIsOn?(id)
  105.     switchname=$data_system.switches[id]
  106.     return false if !switchname
  107.     if switchname[/^s\:/]
  108.       return eval($~.post_match)
  109.     else
  110.       return $game_switches[id]
  111.     end
  112.   end
  113.   def refresh
  114.     new_page = nil
  115.     unless @erased
  116.       for page in @event.pages.reverse
  117.         c = page.condition
  118.         if c.switch1_valid
  119.           if !switchIsOn?(c.switch1_id)
  120.             next
  121.           end
  122.         end
  123.         if c.switch2_valid
  124.           if !switchIsOn?(c.switch2_id)
  125.             next
  126.           end
  127.         end
  128.         if c.variable_valid
  129.           if $game_variables[c.variable_id] < c.variable_value
  130.             next
  131.           end
  132.         end
  133.         if c.self_switch_valid
  134.           key = [@map_id, @event.id, c.self_switch_ch]
  135.           if $game_self_switches[key] != true
  136.             next
  137.           end
  138.         end
  139.         new_page = page
  140.         break
  141.       end
  142.     end
  143.     if new_page == @page
  144.       return
  145.     end
  146.     @page = new_page
  147.     clear_starting
  148.     if @page == nil
  149.       @tile_id = 0
  150.       @character_name = ""
  151.       @character_hue = 0
  152.       @move_type = 0
  153.       @through = true
  154.       @trigger = nil
  155.       @list = nil
  156.       @interpreter = nil
  157.       return
  158.     end
  159.     @tile_id = @page.graphic.tile_id
  160.     @character_name = @page.graphic.character_name
  161.     @character_hue = @page.graphic.character_hue
  162.     if @original_direction != @page.graphic.direction
  163.       @direction = @page.graphic.direction
  164.       @original_direction = @direction
  165.       @prelock_direction = 0
  166.     end
  167.     if @original_pattern != @page.graphic.pattern
  168.       @pattern = @page.graphic.pattern
  169.       @original_pattern = @pattern
  170.     end
  171.     @opacity = @page.graphic.opacity
  172.     @blend_type = @page.graphic.blend_type
  173.     @move_type = @page.move_type
  174.     @move_speed = @page.move_speed * 1.25
  175.     @move_frequency = @page.move_frequency
  176.     @move_route = @route_erased ? RPG::MoveRoute.new : @page.move_route
  177.     @move_route_index = 0
  178.     @move_route_forcing = false
  179.     @walk_anime = @page.walk_anime
  180.     @step_anime = @page.step_anime
  181.     @direction_fix = @page.direction_fix
  182.     @through = @page.through
  183.     @always_on_top = @page.always_on_top
  184.     @trigger = @page.trigger
  185.     @list = @page.list
  186.     @interpreter = nil
  187.     if @trigger == 4
  188.       @interpreter = Interpreter.new
  189.     end
  190.     check_event_trigger_auto
  191.   end
  192.   def check_event_trigger_touch(x, y)
  193.     if $game_system.map_interpreter.running?
  194.       return
  195.     end
  196.     return if @trigger!=2
  197.     return if x != $game_player.x || y != $game_player.y
  198.     if not jumping? and not over_trigger?
  199.       start
  200.     end
  201.   end
  202.   def check_event_trigger_auto
  203.     if @trigger == 2 and @x == $game_player.x and @y == $game_player.y
  204.       if not jumping? and over_trigger?
  205.         start
  206.       end
  207.     end
  208.     if @trigger == 3
  209.       start
  210.     end
  211.   end
  212.   def update
  213.     last_moving=moving?
  214.     super
  215.     if !moving? && last_moving
  216.       $game_player.pbCheckEventTriggerFromDistance([2])
  217.     end
  218.     if @need_refresh
  219.       @need_refresh=false
  220.       refresh
  221.     end
  222.     check_event_trigger_auto
  223.     if @interpreter != nil
  224.       unless @interpreter.running?
  225.         @interpreter.setup(@list, @event.id)
  226.       end
  227.       @interpreter.update
  228.     end
  229.   end
  230. end
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
4
 楼主| 发表于 2008-8-13 18:32:16 | 只看该作者
  1. #==============================================================================
  2. # ** Game_Player
  3. #------------------------------------------------------------------------------
  4. #  This class handles the player. Its functions include event starting
  5. #  determinants and map scrolling. Refer to "$game_player" for the one
  6. #  instance of this class.
  7. #==============================================================================

  8. def pbAddDependency(event)
  9.   $game_player.addDependentEvent(event)
  10. end
  11. def pbRemoveDependency(event)
  12.   $game_player.removeDependentEvent(event)
  13. end

  14. def pbTurnTowardEvent(event,otherEvent)
  15. sx = event.x - otherEvent.x
  16. sy = event.y - otherEvent.y
  17. if sx == 0 and sy == 0
  18.   return
  19. end
  20. if sx.abs > sy.abs
  21.   sx > 0 ? event.turn_left : event.turn_right
  22. else
  23.   sy > 0 ? event.turn_up : event.turn_down
  24. end
  25. if event.is_a?(Game_Event)
  26.   $PokemonMap.addMovedEvent(event.id)
  27. end
  28. end

  29. def pbMoveBehindEvent(leader,follower)
  30.   d=leader.direction
  31.   newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
  32.   newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
  33.   if follower.x!=newX || follower.y!=newY
  34.    follower.moveto(newX,newY)
  35.   end
  36. case leader.direction
  37.   when 2 # down
  38.    follower.turn_down
  39.   when 4 # left
  40.    follower.turn_left
  41.   when 6 # right
  42.    follower.turn_right
  43.   when 8 # up
  44.    follower.turn_up
  45. end
  46. if follower.is_a?(Game_Event)
  47.   $PokemonMap.addMovedEvent(follower.id)
  48. end
  49. end

  50. def pbFollowEvent(leader,follower)
  51.   d=leader.direction
  52.   newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
  53.   newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
  54.   posX = newX + (d == 6 ? -1 : d == 4 ? 1 : 0)
  55.   posY = newY + (d == 2 ? -1 : d == 8 ? 1 : 0)
  56.   if follower.x-newX==-1 && follower.y==newY
  57.    follower.move_right
  58.   elsif follower.x-newX==1 && follower.y==newY
  59.    follower.move_left
  60.   elsif follower.y-newY==-1 && follower.x==newX
  61.    follower.move_down
  62.   elsif follower.y-newY==1 && follower.x==newX   
  63.    follower.move_up
  64.   elsif follower.x!=posX || follower.y!=posY
  65.    follower.moveto(posX,posY)
  66.    case leader.direction
  67.     when 2 # down
  68.      follower.move_down
  69.     when 4 # left
  70.      follower.move_left
  71.     when 6 # right
  72.      follower.move_right
  73.     when 8 # up
  74.      follower.move_up
  75.    end
  76.   end
  77. if follower.is_a?(Game_Event)
  78.   $PokemonMap.addMovedEvent(follower.id)
  79. end
  80. end

  81. def pbFollowEventJumping(leader,follower)
  82.   d=leader.direction
  83.   newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
  84.   newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
  85.   posX = newX + (d == 6 ? -1 : d == 4 ? 1 : 0)
  86.   posY = newY + (d == 2 ? -1 : d == 8 ? 1 : 0)
  87.   if follower.x-newX==-1 && follower.y==newY
  88.    follower.jump(1,0)
  89.    return
  90.   elsif follower.x-newX==1 && follower.y==newY
  91.    follower.jump(-1,0)
  92.    return
  93.   elsif follower.y-newY==-1 && follower.x==newX
  94.    follower.jump(0,1)
  95.    return
  96.   elsif follower.y-newY==1 && follower.x==newX   
  97.    follower.jump(0,-1)
  98.    return
  99.   elsif follower.x!=posX || follower.y!=posY
  100.    follower.moveto(posX,posY)
  101.   end
  102. case leader.direction
  103.   when 2 # down
  104.    follower.jump(0,1)
  105.   when 4 # left
  106.    follower.jump(-1,0)
  107.   when 6 # right
  108.    follower.jump(1,0)
  109.   when 8 # up
  110.    follower.jump(0,-1)
  111. end
  112. if follower.is_a?(Game_Event)
  113.   $PokemonMap.addMovedEvent(follower.id)
  114. end
  115. end


  116. class Game_Player < Game_Character
  117.   def map
  118.     @map=nil
  119.     return $game_map
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # * Invariables
  123.   #--------------------------------------------------------------------------
  124.   def initialize(*arg)
  125.     super(*arg)
  126.     @lastdir=0
  127.     @lastdirframe=0
  128.   end
  129.   def pbHasDependentEvents?
  130.     return @dependentEvents && (@dependentEvents.length>0)      
  131.   end
  132.   def addDependentEvent(event)
  133.     @dependentEvents=[] if !@dependentEvents
  134.     for i in [email protected]
  135.       if @dependentEvents[i][0]==$game_map.map_id&&
  136.          @dependentEvents[i][1]==event.id
  137.         # Already exists
  138.         return
  139.       end
  140.     end
  141.     @dependentEvents.push([$game_map.map_id,event.id,event.through])
  142.     event.through=true
  143.   end
  144.   def removeDependentEvent(event)
  145.     if @dependentEvents
  146.       mapid=$game_map.map_id
  147.       for i in [email protected]
  148.         if @dependentEvents[i][0]==mapid &&
  149.            @dependentEvents[i][1]==event.id
  150.          event.through=@dependentEvents[i][2]
  151.          @dependentEvents[i]=nil
  152.         end
  153.       end
  154.       @dependentEvents.compact!
  155.     end
  156.   end
  157.   def updateDependentEvents
  158.     if @dependentEvents
  159.       for i in [email protected]
  160.         @dependentEvents[i]=nil if @dependentEvents[i][0]!=$game_map.map_id
  161.       end
  162.       @dependentEvents.compact!
  163.     end   
  164.   end
  165.   def getDependentEvent(evt)
  166.    event=$game_map.events[evt[1]]
  167.    if event
  168.      event.through=true
  169.    end
  170.    return event
  171.   end
  172.   def move_down(turn_enabled = true)
  173.     if turn_enabled
  174.      turn_down
  175.     end
  176.     pbBridgeCheck(2)
  177.     if passable?(@x, @y, 2)
  178.       return if pbLedge(0,1)
  179.       return if pbEndSurf(0,1)
  180.       turn_down
  181.       @y += 1
  182.       pbMoveDependentEvents
  183.       increase_steps
  184.     else
  185.       if !check_event_trigger_touch(@x, @y+1)
  186.         Audio.se_play("Audio/SE/bump.wav")
  187.       end
  188.     end
  189.   end
  190.   def move_left(turn_enabled = true)
  191.     if turn_enabled
  192.       turn_left
  193.     end
  194.     pbBridgeCheck(4)
  195.     if passable?(@x, @y, 4)
  196.       return if pbLedge(-1,0)
  197.       return if pbEndSurf(-1,0)
  198.       turn_left
  199.       @x -= 1
  200.       pbMoveDependentEvents
  201.       increase_steps
  202.     else
  203.       if !check_event_trigger_touch(@x-1, @y)
  204.         Audio.se_play("Audio/SE/bump.wav")
  205.       end
  206.     end
  207.   end
  208.   def move_right(turn_enabled = true)
  209.     if turn_enabled
  210.       turn_right
  211.     end
  212.     pbBridgeCheck(6)
  213.     if passable?(@x, @y, 6)
  214.       return if pbLedge(1,0)
  215.       return if pbEndSurf(1,0)
  216.       turn_right
  217.       @x += 1
  218.       pbMoveDependentEvents
  219.       increase_steps
  220.     else
  221.       if !check_event_trigger_touch(@x+1, @y)
  222.         Audio.se_play("Audio/SE/bump.wav")
  223.       end
  224.     end
  225.   end
  226.   def move_up(turn_enabled = true)
  227.     if turn_enabled
  228.       turn_up
  229.     end
  230.     pbBridgeCheck(8)
  231.     if passable?(@x, @y, 8)
  232.       return if pbLedge(0,-1)
  233.       return if pbEndSurf(0,-1)
  234.       turn_up
  235.       @y -= 1
  236.       pbMoveDependentEvents
  237.       increase_steps
  238.     else
  239.       if !check_event_trigger_touch(@x, @y-1)
  240.         Audio.se_play("Audio/SE/bump.wav")
  241.       end
  242.     end
  243.   end
  244.   def pbMoveDependentEvents
  245.    return if !@dependentEvents
  246.    updateDependentEvents
  247.    leader=self
  248.    for evt in @dependentEvents
  249.     event=getDependentEvent(evt)
  250.     if event
  251.      pbFollowEvent(leader,event)
  252.      leader=event
  253.     end
  254.    end
  255.   end
  256.   def pbJumpDependentEvents
  257.    return if !@dependentEvents
  258.    updateDependentEvents
  259.    leader=self
  260.    for evt in @dependentEvents
  261.     event=getDependentEvent(evt)
  262.     if event
  263.      pbFollowEventJumping(leader,event)
  264.      leader=event
  265.     end
  266.    end
  267.   end
  268.   def pbTurnDependentEvents
  269.    return if !@dependentEvents
  270.    updateDependentEvents
  271.    leader=self
  272.    for evt in @dependentEvents
  273.     event=getDependentEvent(evt)
  274.     if event
  275.      pbTurnTowardEvent(event,leader)
  276.      leader=event
  277.     end
  278.    end
  279.   end
  280.   def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)
  281.     result = []
  282.     # If event is running
  283.     if checkIfRunning && $game_system.map_interpreter.running?
  284.       return result
  285.     end
  286.     # All event loops
  287.     for event in $game_map.events.values
  288.       next if !event.name[/^Trainer\((\d+)\)$/]
  289.       distance=$~[1].to_i
  290.       # If event coordinates and triggers are consistent
  291.       if pbEventCanReachPlayer?(event,self,distance) and triggers.include?(event.trigger)
  292.           # If starting determinant is front event (other than jumping)
  293.         if not event.jumping? and not event.over_trigger?
  294.           result.push(event)
  295.         end
  296.       end
  297.     end
  298.     return result
  299.   end
  300.   def pbTriggeredCounterEvents(triggers,checkIfRunning=true)
  301.     result = []
  302.     # If event is running
  303.     if checkIfRunning && $game_system.map_interpreter.running?
  304.       return result
  305.     end
  306.     # All event loops
  307.     for event in $game_map.events.values
  308.       next if !event.name[/^Counter\((\d+)\)$/]
  309.       distance=$~[1].to_i
  310.       # If event coordinates and triggers are consistent
  311.       if pbEventFacesPlayer?(event,self,distance) and triggers.include?(event.trigger)
  312.           # If starting determinant is front event (other than jumping)
  313.         if not event.jumping? and not event.over_trigger?
  314.           result.push(event)
  315.         end
  316.       end
  317.     end
  318.     return result
  319.   end
  320.   def pbCheckEventTriggerAfterTurning
  321.   end
  322.   def pbCheckEventTriggerFromDistance(triggers)
  323.     ret=pbTriggeredTrainerEvents(triggers)
  324.     ret.concat(pbTriggeredCounterEvents(triggers))
  325.     return false if ret.length==0
  326.     for event in ret
  327.       event.start
  328.     end
  329.     return true
  330.   end
  331.   def pbFacingEvent
  332.    if $game_system.map_interpreter.running?
  333.     return nil
  334.    end
  335.    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  336.    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  337.    for event in $game_map.events.values
  338.     if event.x == new_x and event.y == new_y
  339.      if not event.jumping? and not event.over_trigger?
  340.       return event
  341.      end
  342.     end
  343.    end
  344.    if $game_map.counter?(new_x, new_y)
  345.      new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  346.      new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  347.      for event in $game_map.events.values
  348.       if event.x == new_x and event.y == new_y
  349.        if not event.jumping? and not event.over_trigger?
  350.         return event
  351.        end
  352.       end
  353.      end
  354.    end
  355.    return nil
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * Passable Determinants
  359.   #     x : x-coordinate
  360.   #     y : y-coordinate
  361.   #     d : direction (0,2,4,6,8)
  362.   #         * 0 = Determines if all directions are impassable (for jumping)
  363.   #--------------------------------------------------------------------------
  364.   def passable?(x, y, d)
  365.     # Get new coordinates
  366.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  367.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  368.     # If coordinates are outside of map
  369.     unless $game_map.validLax?(new_x, new_y)
  370.       # Impassable
  371.       return false
  372.     end
  373.     if !$game_map.valid?(new_x, new_y)
  374.       return false if !$MapFactory
  375.       return $MapFactory.isPassableFromEdge?(new_x, new_y)
  376.     end
  377.     # If debug mode is ON and ctrl key was pressed
  378.     if $DEBUG and Input.press?(Input::CTRL)
  379.       # Passable
  380.       return true
  381.     end
  382.     super
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # * Set Map Display Position to Center of Screen
  386.   #--------------------------------------------------------------------------
  387.   def center(x, y)
  388.     center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4
  389.     center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4
  390.     max_x = ($game_map.width - Graphics.width/32.0) * 128
  391.     max_y = ($game_map.height - Graphics.height/32.0) * 128
  392.     $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max
  393.     $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max
  394.   end
  395.   #--------------------------------------------------------------------------
  396.   # * Move to Designated Position
  397.   #     x : x-coordinate
  398.   #     y : y-coordinate
  399.   #--------------------------------------------------------------------------
  400.   def moveto(x, y)
  401.     super
  402.     # Centering
  403.     center(x, y)
  404.     # Make encounter count
  405.     make_encounter_count
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # * Increase Steps
  409.   #--------------------------------------------------------------------------
  410.   def increase_steps
  411.     super
  412.   end
  413.   #--------------------------------------------------------------------------
  414.   # * Get Encounter Count
  415.   #--------------------------------------------------------------------------
  416.   def encounter_count
  417.     return @encounter_count
  418.   end
  419.   #--------------------------------------------------------------------------
  420.   # * Make Encounter Count
  421.   #--------------------------------------------------------------------------
  422.   def make_encounter_count
  423.     # Image of two dice rolling
  424.     if $game_map.map_id != 0
  425.       n = $game_map.encounter_step
  426.       @encounter_count = rand(n) + rand(n) + 1
  427.     end
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # * Refresh
  431.   #--------------------------------------------------------------------------
  432.   def refresh
  433.     @opacity = 255
  434.     @blend_type = 0
  435.   end
  436.   #--------------------------------------------------------------------------
  437.   # * Same Position Starting Determinant
  438.   #--------------------------------------------------------------------------
  439.   def check_event_trigger_here(triggers,keypress=false)
  440.     result = false
  441.     # If event is running
  442.     if $game_system.map_interpreter.running?
  443.       return result
  444.     end
  445.     # All event loops
  446.     for event in $game_map.events.values
  447.       # If event coordinates and triggers are consistent
  448.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  449.         # If starting determinant is same position event (other than jumping)
  450.         if not event.jumping? and event.over_trigger?
  451.           event.start(keypress)
  452.           result = true
  453.         end
  454.       end
  455.     end
  456.     return result
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Front Envent Starting Determinant
  460.   #--------------------------------------------------------------------------
  461.   def check_event_trigger_there(triggers,keypress=false)
  462.     result = false
  463.     # If event is running
  464.     if $game_system.map_interpreter.running?
  465.       return result
  466.     end
  467.     # Calculate front event coordinates
  468.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  469.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  470.     # All event loops
  471.     for event in $game_map.events.values
  472.       # If event coordinates and triggers are consistent
  473.       if event.x == new_x and event.y == new_y and
  474.          triggers.include?(event.trigger)
  475.         # If starting determinant is front event (other than jumping)
  476.         if not event.jumping? and (keypress || !event.over_trigger?)
  477.           event.start(keypress)
  478.           result = true
  479.         end
  480.       end
  481.     end
  482.     # If fitting event is not found
  483.     if result == false
  484.       # If front tile is a counter
  485.       if $game_map.counter?(new_x, new_y)
  486.         # Calculate 1 tile inside coordinates
  487.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  488.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  489.         # All event loops
  490.         for event in $game_map.events.values
  491.           # If event coordinates and triggers are consistent
  492.           if event.x == new_x and event.y == new_y and
  493.              triggers.include?(event.trigger)
  494.             # If starting determinant is front event (other than jumping)
  495.             if not event.jumping? and (keypress || !event.over_trigger?)
  496.               event.start
  497.               result = true
  498.             end
  499.           end
  500.         end
  501.       end
  502.     end
  503.     return result
  504.   end
  505.   #--------------------------------------------------------------------------
  506.   # * Touch Event Starting Determinant
  507.   #--------------------------------------------------------------------------
  508.   def check_event_trigger_touch(x, y)
  509.     result = false
  510.     # If event is running
  511.     if $game_system.map_interpreter.running?
  512.       return result
  513.     end
  514.     # All event loops
  515.     for event in $game_map.events.values
  516.       if event.name[/^Trainer\((\d+)\)$/]
  517.         distance=$~[1].to_i
  518.         next if !pbEventCanReachPlayer?(event,self,distance)
  519.       end
  520.       if event.name[/^Counter\((\d+)\)$/]
  521.         distance=$~[1].to_i
  522.         next if !pbEventFacesPlayer?(event,self,distance)
  523.       end
  524.       # If event coordinates and triggers are consistent
  525.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  526.         # If starting determinant is front event (other than jumping)
  527.         if not event.jumping? and not event.over_trigger?
  528.           event.start
  529.           result = true
  530.         end
  531.       end
  532.     end
  533.     return result
  534.   end
  535.   #--------------------------------------------------------------------------
  536.   # * Frame Update
  537.   #--------------------------------------------------------------------------
  538.   def update
  539.     updateDependentEvents
  540.     # Remember whether or not moving in local variables
  541.     last_moving = moving?
  542.     # If moving, event running, move route forcing, and message window
  543.     # display are all not occurring
  544.     dir=Input.dir4
  545.     unless moving? or $game_system.map_interpreter.running? or
  546.            @move_route_forcing or $game_temp.message_window_showing or
  547.            $PokemonTemp.miniupdate
  548.       # Move player in the direction the directional button is being pressed
  549.       if dir==@lastdir && Graphics.frame_count-@lastdirframe>2
  550.        case dir
  551.        when 2
  552.          move_down
  553.        when 4
  554.          move_left
  555.        when 6
  556.          move_right
  557.        when 8
  558.          move_up
  559.        end
  560.       elsif dir!=@lastdir
  561.        case dir
  562.        when 2
  563.          turn_down
  564.        when 4
  565.          turn_left
  566.        when 6
  567.          turn_right
  568.        when 8
  569.          turn_up
  570.        end
  571.       end
  572.     end
  573.     if dir!=@lastdir
  574.      @lastdirframe=Graphics.frame_count
  575.     end
  576.     @lastdir=dir
  577.     # Remember coordinates in local variables
  578.     last_real_x = @real_x
  579.     last_real_y = @real_y
  580.     super
  581.     center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4
  582.     center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4
  583.     # If character moves down and is positioned lower than the center
  584.     # of the screen
  585.     if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
  586.       # Scroll map down
  587.       $game_map.scroll_down(@real_y - last_real_y)
  588.     end
  589.     # If character moves left and is positioned more let on-screen than
  590.     # center
  591.     if @real_x < last_real_x and @real_x - $game_map.display_x < center_x
  592.       # Scroll map left
  593.       $game_map.scroll_left(last_real_x - @real_x)
  594.     end
  595.     # If character moves right and is positioned more right on-screen than
  596.     # center
  597.     if @real_x > last_real_x and @real_x - $game_map.display_x > center_x
  598.       # Scroll map right
  599.       $game_map.scroll_right(@real_x - last_real_x)
  600.     end
  601.     # If character moves up and is positioned higher than the center
  602.     # of the screen
  603.     if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
  604.       # Scroll map up
  605.       $game_map.scroll_up(last_real_y - @real_y)
  606.     end
  607.     # If not moving
  608.     unless moving?
  609.       # If player was moving last time
  610.       if last_moving
  611.         pbTurnDependentEvents
  612.         result = pbCheckEventTriggerFromDistance([2])
  613.         # Event determinant is via touch of same position event
  614.         result |= check_event_trigger_here([1,2])
  615.         # If event which started does not exist
  616.         Kernel.pbOnStepTaken(result) # *Added function call
  617.         if result == false
  618.           # Disregard if debug mode is ON and ctrl key was pressed
  619.           unless $DEBUG and Input.press?(Input::CTRL)
  620.             # Encounter countdown
  621.             if @encounter_count > 0
  622.               @encounter_count -= 1
  623.             end
  624.           end
  625.         end
  626.       end
  627.       # If C button was pressed
  628.       if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate
  629.         # Same position and front event determinant
  630.         check_event_trigger_here([0],true)
  631.         check_event_trigger_there([0,2],true) # *Modified to prevent unnecessary triggers
  632.       end
  633.     end
  634.   end
  635. end
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
5
 楼主| 发表于 2008-8-13 18:32:43 | 只看该作者
  1. class Win32API
  2. @@RGSSWINDOW=nil
  3. @@GetCurrentThreadId=Win32API.new('kernel32','GetCurrentThreadId', '%w()','l')
  4. @@GetWindowThreadProcessId=Win32API.new('user32','GetWindowThreadProcessId', '%w(l p)','l')
  5. @@FindWindowEx=Win32API.new('user32','FindWindowEx', '%w(l l p p)','l')
  6. def Win32API.SetWindowText(text)
  7.    hWnd =  pbFindRgssWindow
  8.    swp = Win32API.new('user32', 'SetWindowTextA', %(l, p), 'i')
  9.    swp.call(hWnd, text)
  10. end
  11. # Added by Peter O. as a more reliable way to get the RGSS window
  12. def Win32API.pbFindRgssWindow
  13.   return @@RGSSWINDOW if @@RGSSWINDOW
  14.   processid=[0].pack('l')
  15.   threadid=@@GetCurrentThreadId.call
  16.   nextwindow=0
  17.   begin
  18.    nextwindow=@@FindWindowEx.call(0,nextwindow,"RGSS Player",0)
  19.    if nextwindow
  20.      wndthreadid=@@GetWindowThreadProcessId.call(nextwindow,processid)
  21.      if wndthreadid==threadid
  22.       @@RGSSWINDOW=nextwindow
  23.       return @@RGSSWINDOW
  24.      end
  25.    end
  26.   end until nextwindow==0
  27.   raise "Can't find RGSS player window"
  28.   return 0
  29. end
  30. def Win32API.GetPrivateProfileString(section, key)
  31.    val = "\0"*256
  32.    gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l')
  33.    gps.call(section, key, "", val, 256, ".\\Game.ini")
  34.    val.delete!("\0")
  35.    return val
  36. end
  37. def Win32API.SetWindowPos(w, h)
  38.    hWnd =  pbFindRgssWindow
  39.    windowrect=Win32API.GetWindowRect
  40.    clientsize=Win32API.client_size
  41.    xExtra=windowrect.width-clientsize[0]
  42.    yExtra=windowrect.height-clientsize[1]
  43.    swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i')
  44.    win = swp.call(hWnd, 0, windowrect.x, windowrect.y,
  45.      w+xExtra,h+yExtra, 0)
  46.    return win
  47. end
  48. def Win32API.client_size
  49.    hWnd =  pbFindRgssWindow
  50.    rect = [0, 0, 0, 0].pack('l4')
  51.    Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect)
  52.    width, height = rect.unpack('l4')[2..3]
  53.    return width, height
  54. end
  55. def Win32API.GetWindowRect
  56.    hWnd =  pbFindRgssWindow
  57.    rect = [0, 0, 0, 0].pack('l4')
  58.    Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(hWnd, rect)
  59.    x,y,width, height = rect.unpack('l4')
  60.    return Rect.new(x,y,width-x,height-y)
  61. end
  62. end
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
6
 楼主| 发表于 2008-8-13 18:33:06 | 只看该作者

  1. class Game_Map
  2. TILEWIDTH = 32
  3. TILEHEIGHT = 32
  4. def self.realResX
  5.   return 4 * TILEWIDTH
  6. end
  7. def self.realResY
  8.   return 4 * TILEHEIGHT
  9. end
  10. def display_x=(value)
  11.   @display_x=value
  12.   $MapFactory.setMapsInRange if $MapFactory
  13. end
  14. def display_y=(value)
  15.   @display_y=value
  16.   $MapFactory.setMapsInRange if $MapFactory
  17. end
  18. def start_scroll(direction, distance, speed)
  19.     @scroll_direction = direction
  20.     if direction==2 || direction==8     
  21.        @scroll_rest = distance * Game_Map.realResY
  22.     else
  23.        @scroll_rest = distance * Game_Map.realResX
  24.     end
  25.     @scroll_speed = speed
  26. end
  27. def scroll_down(distance)
  28.   self.display_y+=distance
  29. end
  30. def scroll_left(distance)
  31. self.display_x-=distance
  32. end
  33. def scroll_right(distance)
  34.   self.display_x+=distance
  35. end
  36. def scroll_up(distance)
  37. self.display_y-=distance
  38. end
  39. end

  40. class Game_Player < Game_Character
  41. def center(x, y)
  42.     center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * 4    # X coordinate in the center of the screen
  43.     center_y = (Graphics.height/2 - Game_Map::TILEHEIGHT/2) * 4   # Y coordinate in the center of the screen
  44.     max_x = ($game_map.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX
  45.     max_y = ($game_map.height - Graphics.height*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY
  46.     dispx=x * Game_Map.realResX - center_x
  47.     dispy=y * Game_Map.realResY - center_y
  48.     $game_map.display_x = dispx#[0, [dispx, max_x].min].max
  49.     $game_map.display_y = dispy#[0, [dispy, max_y].min].max
  50. end
  51. end
复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
7
 楼主| 发表于 2008-8-13 18:33:49 | 只看该作者
我也知道很多............
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
3 小时
注册时间
2008-1-3
帖子
1312
8
发表于 2008-8-13 18:39:46 | 只看该作者
以下引用水の都于2008-8-13 10:33:49的发言:

我也知道很多............

{/gg}脚本多到是其次
连帖也太厉害了吧....一连连了7帖子{/gg}

学脚本地址:
http://rpg.blue/viewthread.php?tid=85511
专业潜水员+资深养手党
问我为什么万年不换头像?
存在感已经够稀薄了,再换个头像谁还记得你!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
49
在线时间
157 小时
注册时间
2007-12-16
帖子
3454
9
发表于 2008-8-13 18:43:25 | 只看该作者
以下引用苏菲娅于2008-8-13 10:39:46的发言:


以下引用水の都于2008-8-13 10:33:49的发言:

我也知道很多............


脚本多到是其次
连帖也太厉害了吧....一连连了7帖子

学脚本地址:
http://rpg.blue/viewthread.php?tid=85511

扣点分作为炼铁的惩罚吧
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2008-5-1
帖子
236
10
 楼主| 发表于 2008-8-13 18:54:10 | 只看该作者
因为我怕位置不够
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-7-27 12:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表